/// <summary>
        /// Richard Todd www.movethemarkets.com efficiently tracks sorted input over a rolling window.
        /// </summary>
        /// <returns></returns>
        public Z20091120SortedWindow Z20091120SortedWindow(Data.IDataSeries input, int length)
        {
            checkZ20091120SortedWindow.Length = length;
            length = checkZ20091120SortedWindow.Length;

            if (cacheZ20091120SortedWindow != null)
            {
                for (int idx = 0; idx < cacheZ20091120SortedWindow.Length; idx++)
                {
                    if (cacheZ20091120SortedWindow[idx].Length == length && cacheZ20091120SortedWindow[idx].EqualsInput(input))
                    {
                        return(cacheZ20091120SortedWindow[idx]);
                    }
                }
            }

            Z20091120SortedWindow indicator = new Z20091120SortedWindow();

            indicator.BarsRequired        = BarsRequired;
            indicator.CalculateOnBarClose = CalculateOnBarClose;
            indicator.Input  = input;
            indicator.Length = length;
            indicator.SetUp();

            Z20091120SortedWindow[] tmp = new Z20091120SortedWindow[cacheZ20091120SortedWindow == null ? 1 : cacheZ20091120SortedWindow.Length + 1];
            if (cacheZ20091120SortedWindow != null)
            {
                cacheZ20091120SortedWindow.CopyTo(tmp, 0);
            }
            tmp[tmp.Length - 1]        = indicator;
            cacheZ20091120SortedWindow = tmp;
            Indicators.Add(indicator);

            return(indicator);
        }
Example #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, "ProxLine"));
     //CalculateOnBarClose	= true;
     Overlay            = true;
     PriceTypeSupported = false;
     dirup = new BoolSeries(this);
     Plots[0].Pen.Width = 3;
     med = null;
 }
Example #3
0
        protected override void OnStartUp()
        {
            _diff = new DataSeries(this);

            curL = new double[4];
            oldL = new double[4];

            sw   = Z20091120SortedWindow(_diff, 5);
            fmax = Z20100527FastMAX(_diff, period);
            fmin = Z20100527FastMIN(_diff, period);
        }
Example #4
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;
 }
Example #5
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (med == null)
            {
                med = Z20091120SortedWindow(Median, windowLength);
            }

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

            double slope = calcSlope(lookback);

            if ((med[0] > med[1]) &&
                (slope <= 0))
            {
                Value.Set(Value[1]);
            }
            else if ((med[0] < med[1]) &&
                     (slope >= 0))
            {
                Value.Set(Value[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)
                {
                    Value.Set(Math.Max(Value[1], med[0]));
                }
                else
                {
                    Value.Set(Math.Min(Value[1], med[0]));
                }

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

            if (Value[0] > Value[1])
            {
                dirup.Set(true);
            }
            else if (Value[0] < Value[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);
                Value.Set(Value[1]);
            }

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

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

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

            if ((Value[0] > Value[1]) && dnbar)
            {
                Value.Set(Value[1]);
            }
            if ((Value[0] < Value[1]) && upbar)
            {
                Value.Set(Value[1]);
            }
        }
Example #6
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);
        }