Exemplo n.º 1
0
        /// <summary>
        /// Checks if the price for this bar falls in a retracement price zone.
        /// </summary>
        /// <param name="currentBar">Bar to check</param>
        /// <returns>True if the price has touched one of the zones</returns>
        private bool IsBarInZone(int currentBar)
        {
            PriceRetracements retracements = (PriceRetracements)_dependents[1];

            // Get the retracement zones first.
            List <PriceZone> zones  = new List <PriceZone>();
            List <double>    points = new List <double>();

            points.Add(retracements.External[(int)PriceRetracements.ExternalType._127][currentBar]);
            points.Add(retracements.External[(int)PriceRetracements.ExternalType._162][currentBar]);
            points.Add(retracements.Alternate[(int)PriceRetracements.AlternateType._100Wave1][currentBar]);
            points.Add(retracements.Alternate[(int)PriceRetracements.AlternateType._100Wave3][currentBar]);
            points.Add(retracements.Alternate[(int)PriceRetracements.AlternateType._38][currentBar]);
            points.Add(retracements.Alternate[(int)PriceRetracements.AlternateType._62][currentBar]);

            ComboSet <double>     comboSet = new ComboSet <double>(points);
            List <List <double> > combos   = comboSet.GetSet(2);

            for (int i = 0; i < combos.Count; i++)
            {
                if (AreAllPointsClose(combos[i]) == true)
                {
                    double high = combos[i].Max();
                    double low  = combos[i].Min();
                    zones.Add(new PriceZone()
                    {
                        High = high, Low = low, NumberOfPoints = combos[i].Count
                    });
                }
            }

            // The one with the most similar points is the best. See if it lands there first.
            zones.Sort((a, b) => a.NumberOfPoints.CompareTo(b.NumberOfPoints));

            for (int i = 0; i < zones.Count; i++)
            {
                PriceZone zone = zones[i];
                if ((Data.High[currentBar] >= zone.High && Data.Low[currentBar] <= zone.Low) ||
                    (Data.High[currentBar] >= zone.Low && Data.Low[currentBar] <= zone.High))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Builds a list of all the possible combos found on this bar.
        /// </summary>
        /// <param name="currentBar">Current bar to search for combos</param>
        /// <param name="orderType">Type of strategies to combo together</param>
        /// <returns>List of all the combo lists for this bar</returns>
        private List <List <Strategy> > GetComboList(int currentBar, double orderType)
        {
            // Get all the strategies that were found on today.
            List <Strategy> foundStrategies = new List <Strategy>();

            for (int i = 0; i < Dependents.Count; i++)
            {
                if (Dependents[i] is Strategy)
                {
                    Strategy dependentStrategy = (Strategy)Dependents[i];

                    // Ensure each dependent has the same order type.
                    if (orderType != dependentStrategy.OrderType)
                    {
                        continue;
                    }

                    // The logic here that searches the current bar
                    // and back a few days to make the finding not so exact. It adds
                    // for some more leeway when finding combos as finding multiple
                    // strategies on exact bars doesn't happen as frequently.
                    for (int j = 0; j < _comboLeewayBars + 1; j++)
                    {
                        int comboBar = currentBar - j;
                        if (comboBar < 0)
                        {
                            comboBar = 0;
                        }

                        if (dependentStrategy.WasFound[comboBar])
                        {
                            foundStrategies.Add(dependentStrategy);
                            break;
                        }
                    }
                }
            }

            // Create all the possible combos of these strategies.
            // Min and max combo sizes are filtered elsewhere.
            ComboSet <Strategy>     comboSet = new ComboSet <Strategy>(foundStrategies);
            List <List <Strategy> > combos   = comboSet.GetSet(1);

            return(combos);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns a list of all the zones created by all the projections.
        /// </summary>
        /// <param name="barNum">Bar to get the zones for</param>
        /// <returns>See summary</returns>
        private List <PriceZone> GetZones(int barNum)
        {
            List <PriceZone> zones  = new List <PriceZone>();
            List <double>    points = new List <double>();

            AddPointToListIfValid(points, External[(int)ExternalType._127][barNum]);
            AddPointToListIfValid(points, External[(int)ExternalType._162][barNum]);
            AddPointToListIfValid(points, Alternate[(int)AlternateType._62][barNum]);
            AddPointToListIfValid(points, Alternate[(int)AlternateType._100][barNum]);
            AddPointToListIfValid(points, Alternate[(int)AlternateType._162][barNum]);
            AddPointToListIfValid(points, Internal[(int)InternalType._38][barNum]);
            AddPointToListIfValid(points, Internal[(int)InternalType._50][barNum]);
            AddPointToListIfValid(points, Internal[(int)InternalType._62][barNum]);
            AddPointToListIfValid(points, Internal[(int)InternalType._79][barNum]);

            ComboSet <double>     comboSet = new ComboSet <double>(points);
            List <List <double> > combos   = comboSet.GetSet(MinProjectionsForZone);

            for (int i = 0; i < combos.Count; i++)
            {
                if (AreAllPointsClose(combos[i]) == true)
                {
                    double high = combos[i].Max();
                    double low  = combos[i].Min();
                    zones.Add(new PriceZone()
                    {
                        High = high, Low = low, NumberOfPoints = combos[i].Count
                    });
                }
            }

            // The one with the most similar points is the best. See if it lands there first.
            zones.Sort((a, b) => a.NumberOfPoints.CompareTo(b.NumberOfPoints));

            return(zones);
        }