Beispiel #1
0
        /// <summary>
        /// richard todd www.movethemarkets.com for noticing periodic events
        /// </summary>
        /// <returns></returns>
        public Z20091203PeriodicEvent Z20091203PeriodicEvent(Data.IDataSeries input, EventGroupingMethod groupingBy, int groupingSize, int startTime)
        {
            if (cacheZ20091203PeriodicEvent != null)
            {
                for (int idx = 0; idx < cacheZ20091203PeriodicEvent.Length; idx++)
                {
                    if (cacheZ20091203PeriodicEvent[idx].GroupingBy == groupingBy && cacheZ20091203PeriodicEvent[idx].GroupingSize == groupingSize && cacheZ20091203PeriodicEvent[idx].StartTime == startTime && cacheZ20091203PeriodicEvent[idx].EqualsInput(input))
                    {
                        return(cacheZ20091203PeriodicEvent[idx]);
                    }
                }
            }

            lock (checkZ20091203PeriodicEvent)
            {
                checkZ20091203PeriodicEvent.GroupingBy = groupingBy;
                groupingBy = checkZ20091203PeriodicEvent.GroupingBy;
                checkZ20091203PeriodicEvent.GroupingSize = groupingSize;
                groupingSize = checkZ20091203PeriodicEvent.GroupingSize;
                checkZ20091203PeriodicEvent.StartTime = startTime;
                startTime = checkZ20091203PeriodicEvent.StartTime;

                if (cacheZ20091203PeriodicEvent != null)
                {
                    for (int idx = 0; idx < cacheZ20091203PeriodicEvent.Length; idx++)
                    {
                        if (cacheZ20091203PeriodicEvent[idx].GroupingBy == groupingBy && cacheZ20091203PeriodicEvent[idx].GroupingSize == groupingSize && cacheZ20091203PeriodicEvent[idx].StartTime == startTime && cacheZ20091203PeriodicEvent[idx].EqualsInput(input))
                        {
                            return(cacheZ20091203PeriodicEvent[idx]);
                        }
                    }
                }

                Z20091203PeriodicEvent indicator = new Z20091203PeriodicEvent();
                indicator.BarsRequired        = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack         = MaximumBarsLookBack;
#endif
                indicator.Input        = input;
                indicator.GroupingBy   = groupingBy;
                indicator.GroupingSize = groupingSize;
                indicator.StartTime    = startTime;
                Indicators.Add(indicator);
                indicator.SetUp();

                Z20091203PeriodicEvent[] tmp = new Z20091203PeriodicEvent[cacheZ20091203PeriodicEvent == null ? 1 : cacheZ20091203PeriodicEvent.Length + 1];
                if (cacheZ20091203PeriodicEvent != null)
                {
                    cacheZ20091203PeriodicEvent.CopyTo(tmp, 0);
                }
                tmp[tmp.Length - 1]         = indicator;
                cacheZ20091203PeriodicEvent = tmp;
                return(indicator);
            }
        }
Beispiel #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.Black), PlotStyle.Line, "Mean"));
            Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Line, "UpperSD"));
            Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Line, "LowerSD"));
            Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "UpperSD2"));
            Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "LowerSD2"));

            CalculateOnBarClose = true;
            Overlay             = true;
            pe     = null;
            oldest = 0;
            best   = 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()
        {
            CalculateOnBarClose = false;
            Overlay             = true;
            PriceTypeSupported  = false;
            mxSeen = new DataSeries(this, MaximumBarsLookBack.Infinite);
            mnSeen = new DataSeries(this, MaximumBarsLookBack.Infinite);
            opSeen = new DataSeries(this, MaximumBarsLookBack.Infinite);
            clSeen = new DataSeries(this, MaximumBarsLookBack.Infinite);

            bullBrush = new SolidBrush(Color.FromArgb(candleAlpha, colorBullish));
            bullPen   = new Pen(bullBrush, penWidth);
            bearBrush = new SolidBrush(Color.FromArgb(candleAlpha, colorBearish));
            bearPen   = new Pen(bearBrush, penWidth);
            pe        = null;
        }
Beispiel #4
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (pe == null)
            {
                pe = Z20091203PeriodicEvent(Input, groupMethod, grouping, startTime);
                initScoreMatrix();
            }
            //Print("New update"); // DEBUG
            updateVWAPS();

            updateScoreMatrix(Close[0]);
            chooseBest();

            if (pe.IsNewBar[0])
            {
                addNewCalc();
            }

            Mean.Set(calcs[best].Mean);
            UpperSD.Set(calcs[best].upperSD(numSDs1));
            LowerSD.Set(calcs[best].lowerSD(numSDs1));
            UpperSD2.Set(calcs[best].upperSD(numSDs2));
            LowerSD2.Set(calcs[best].lowerSD(numSDs2));
        }
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (pe == null)
            {
                pe = Z20091203PeriodicEvent(groupBy, grouping, startTime);
            }
            if (CurrentBar < 2)
            {
                mxSeen.Set(High[0]);
                mnSeen.Set(Low[0]);
                opSeen.Set(Open[0]);
                clSeen.Set(Close[0]);
                return;
            }

            // do book-keeping on new bars...
            if (CurrentBar != lastBarSeen)
            {
                lastBarSeen = CurrentBar;

                //Print("Bar: "+CurrentBar+" time: "+Time[0]+" tgt: "+tgtTime+ " sess: "+sessionTime);

                // determine if it's time for a new bar...
                bool barReset     = pe.IsNewBar[0];
                bool sessionStart = pe.IsNewSession[0];

                if (barReset || sessionStart)
                {
                    // we need to start fresh...
                    mxSeen.Set(High[0]);
                    mnSeen.Set(Low[0]);
                    opSeen.Set(Open[0]);

                    // for gapless bars at session start, you need to
                    // set the open to the previous close, just this one time
                    if (sessionStart && gapless)
                    {
                        opSeen.Set(Close[1]);
                        if (Close[1] < Low[0])
                        {
                            mnSeen.Set(Close[1]);
                        }
                        if (Close[1] > High[0])
                        {
                            mxSeen.Set(Close[1]);
                        }
                    }
                }
                else
                {
                    mxSeen.Set(mxSeen[1]);
                    mnSeen.Set(mnSeen[1]);
                    opSeen.Set(opSeen[1]);
                }
            }

            // update the max and min that we've seen so far...
            mxSeen.Set(Math.Max(mxSeen[0], High[0]));
            mnSeen.Set(Math.Min(mnSeen[0], Low[0]));

            // update the close
            clSeen.Set(Close[0]);
        }