/// <summary>
        /// Richard Todd www.movethemarkets.com 3-color colorizer
        /// </summary>
        /// <returns></returns>
        public Z20091221Colorizer3 Z20091221Colorizer3(Data.IDataSeries input, Colorizer3Method colorMethod, double colorParam)
        {
            if (cacheZ20091221Colorizer3 != null)
            {
                for (int idx = 0; idx < cacheZ20091221Colorizer3.Length; idx++)
                {
                    if (cacheZ20091221Colorizer3[idx].ColorMethod == colorMethod && Math.Abs(cacheZ20091221Colorizer3[idx].ColorParam - colorParam) <= double.Epsilon && cacheZ20091221Colorizer3[idx].EqualsInput(input))
                    {
                        return(cacheZ20091221Colorizer3[idx]);
                    }
                }
            }

            lock (checkZ20091221Colorizer3)
            {
                checkZ20091221Colorizer3.ColorMethod = colorMethod;
                colorMethod = checkZ20091221Colorizer3.ColorMethod;
                checkZ20091221Colorizer3.ColorParam = colorParam;
                colorParam = checkZ20091221Colorizer3.ColorParam;

                if (cacheZ20091221Colorizer3 != null)
                {
                    for (int idx = 0; idx < cacheZ20091221Colorizer3.Length; idx++)
                    {
                        if (cacheZ20091221Colorizer3[idx].ColorMethod == colorMethod && Math.Abs(cacheZ20091221Colorizer3[idx].ColorParam - colorParam) <= double.Epsilon && cacheZ20091221Colorizer3[idx].EqualsInput(input))
                        {
                            return(cacheZ20091221Colorizer3[idx]);
                        }
                    }
                }

                Z20091221Colorizer3 indicator = new Z20091221Colorizer3();
                indicator.BarsRequired        = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack         = MaximumBarsLookBack;
#endif
                indicator.Input       = input;
                indicator.ColorMethod = colorMethod;
                indicator.ColorParam  = colorParam;
                Indicators.Add(indicator);
                indicator.SetUp();

                Z20091221Colorizer3[] tmp = new Z20091221Colorizer3[cacheZ20091221Colorizer3 == null ? 1 : cacheZ20091221Colorizer3.Length + 1];
                if (cacheZ20091221Colorizer3 != null)
                {
                    cacheZ20091221Colorizer3.CopyTo(tmp, 0);
                }
                tmp[tmp.Length - 1]      = indicator;
                cacheZ20091221Colorizer3 = tmp;
                return(indicator);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// This method is used to configure the indicator and is called once before any bar data is loaded.
 /// </summary>
 protected override void Initialize()
 {
     Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "UpLine"));
     Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "DnLine"));
     Add(new Plot(Color.FromKnownColor(KnownColor.Yellow), PlotStyle.Line, "NeutLine"));
     //CalculateOnBarClose	= true;
     Overlay            = true;
     PriceTypeSupported = false;
     maval = new DataSeries(this);
     dirup = new BoolSeries(this);
     Plots[0].Pen.Width = 3;
     Plots[1].Pen.Width = 3;
     Plots[2].Pen.Width = 3;
     colorizer          = null;
     med = null;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (colorizer == null)
            {
                colorizer = Z20091221Colorizer3(maval, colorMethod, colorParam);
                med       = Z20091120SortedWindow(Median, windowLength);
            }

            if (CurrentBar < (windowLength + 1))
            {
                maval.Set(Median[0]);
                dirup.Set(true);
                return;
            }

            double slope = calcSlope(lookback);

            if ((med[0] > med[1]) &&
                (slope <= 0))
            {
                maval.Set(maval[1]);
            }
            else if ((med[0] < med[1]) &&
                     (slope >= 0))
            {
                maval.Set(maval[1]);
            }
            else
            {
                // either everything is flat, or the
                // med and slope agree...
                bool assumeUp = (slope > 0);
                if (slope == 0)
                {
                    if (med[0] != med[1])
                    {
                        assumeUp = (med[0] > med[1]);
                    }
                    else
                    {
                        assumeUp = dirup[1];
                    }
                }

                if (assumeUp)
                {
                    maval.Set(Math.Max(maval[1], med[0]));
                }
                else
                {
                    maval.Set(Math.Min(maval[1], med[0]));
                }

                /* if( (maval[1] == maval[2]) &&
                 *      (med[1] != med[2]) ) {
                 *      maval.Set(Median[0]);
                 *      med.Set(Median[0]);
                 *    } */
            }

            if (maval[0] > maval[1])
            {
                dirup.Set(true);
            }
            else if (maval[0] < maval[1])
            {
                dirup.Set(false);
            }
            else
            {
                dirup.Set(dirup[1]);
            }

            bool upbar = ((Close[0] > Open[0]) || (Close[0] == High[0]));
            bool dnbar = ((Close[0] < Open[0]) || (Close[0] == Low[0]));

            if (!dirup[0] && dirup[1] && upbar)
            {
                dirup.Set(true);
                maval.Set(maval[1]);
            }

            if (dirup[0] && !dirup[1] && dnbar)
            {
                dirup.Set(false);
                maval.Set(maval[1]);
            }

            if (!dirup[0] && dirup[1] && (maval[1] <= (High[0] + tolerance * TickSize)))
            {
                dirup.Set(true);
                maval.Set(maval[1]);
            }

            if (dirup[0] && !dirup[1] && (maval[1] >= (Low[0] - tolerance * TickSize)))
            {
                dirup.Set(false);
                maval.Set(maval[1]);
            }

            if ((maval[0] > maval[1]) && dnbar)
            {
                maval.Set(maval[1]);
            }
            if ((maval[0] < maval[1]) && upbar)
            {
                maval.Set(maval[1]);
            }

            colorizer.drawColor(this, 0, 1, 2);
        }