Beispiel #1
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (CurrentBar < 1)
            {
                OscillatorLine.Set(0);
                SignalLine.Set(0);
                Oscillator.Set(0);
                return;
            }

            oscillatorValue = fastSMA[0] - slowSMA[0];
            if (ShowLines)
            {
                OscillatorLine.Set(oscillatorValue);
                SignalLine.Set(SMA(OscillatorLine, Smooth)[0]);
            }
            else
            {
                OscillatorLine.Reset();
                SignalLine.Reset();
            }
            Oscillator.Set(oscillatorValue);
            if (Rising(Oscillator))
            {
                PlotColors[0][0] = UpColor;
                PlotColors[2][0] = UpColor;
            }
            else
            {
                PlotColors[0][0] = DownColor;
                PlotColors[2][0] = DownColor;
            }
        }
Beispiel #2
0
 protected override void OnBarUpdate()
 {
     avg         = DYNAverage[0];
     stdDevValue = SDBB[0];
     PriceLine.Set(DYNPrice[0]);
     SignalLine.Set(DYNSignal[0]);
     Average.Set(avg);
     Upper.Set(avg + stdDevNumber * stdDevValue);
     Lower.Set(avg - stdDevNumber * stdDevValue);
 }
        protected override void OnCalculate()
        {
            ADX adx = ADX(14);
            EMA ema = EMA(20);
            RSI rsi = RSI(14, 3);

            double singnaldata = 0;


            if (adx[0] > 30 && adx[0] > adx[1] && InSeries[0] <= ema[0])
            {
                Color color = Color.Green;
                if (rsi[0] <= 30)
                {
                    color       = Color.LightGreen;
                    singnaldata = 1;
                }
                else
                {
                    singnaldata = 0.5;
                }
                AddChartArrowUp("ArrowLong_Entry" + +Bars[0].Time.Ticks, this.IsAutoAdjustableScale, 0, Bars[0].Low, color);
            }

            //ADX adx = ADX(14);
            //EMA ema = EMA(20);

            //double singnaldata = 0;


            //if (adx[0] > 30 && adx[0] > adx[1] && InSeries[0] <= ema[0])
            //{
            //    singnaldata = 1;
            //    AddChartArrowUp("ArrowLong_Entry" + +Bars[0].Time.Ticks, this.IsAutoAdjustableScale, 0, Bars[0].Low, Color.Green);
            //}


            SignalLine.Set(singnaldata);
            PlotLine_ADX.Set(adx[0]);
            PlotLine_XMA.Set(ema[0]);



            PlotColors[0][0] = this.Plot0Color;
            OutputDescriptors[0].PenStyle  = this.Dash0Style;
            OutputDescriptors[0].Pen.Width = this.Plot0Width;

            PlotColors[1][0] = this.Plot1Color;
            OutputDescriptors[1].PenStyle  = this.Dash1Style;
            OutputDescriptors[1].Pen.Width = this.Plot1Width;

            PlotColors[2][0] = this.Plot1Color;
            OutputDescriptors[2].PenStyle  = this.Dash1Style;
            OutputDescriptors[2].Pen.Width = this.Plot1Width;
        }
Beispiel #4
0
        protected override void OnBarUpdate()
        {
            double RSI_value = RSI(this.RSIPeriod, 1)[0];

            this._RSI_List.Set(RSI_value);

            double PRICE_value = SMA(this._RSI_List, this.PricePeriod)[0];

            PriceLine.Set(PRICE_value);

            double SIGNAL_value = SMA(this._RSI_List, this.SignalPeriod)[0];

            SignalLine.Set(SIGNAL_value);

            double AVG_value = SMA(this._RSI_List, this.BandPeriod)[0];

            Average.Set(AVG_value);
            MidLine.Set(50);

            double stdDevValue = StdDev(this._RSI_List, this.BandPeriod)[0];

            Upper.Set(AVG_value + this.StdDevNumber * stdDevValue);
            Lower.Set(AVG_value - this.StdDevNumber * stdDevValue);

            PlotColors[0][0] = this.Main;
            PlotColors[1][0] = this.Signal;
            PlotColors[2][0] = this.BBAverage;
            PlotColors[3][0] = this.BBUpper;
            PlotColors[4][0] = this.BBLower;

            if (AVG_value > 50)
            {
                PlotColors[5][0] = this.MidPositive;
            }
            else
            {
                PlotColors[5][0] = this.MidNegative;
            }

            Plots[0].PenStyle  = this.Dash0Style;
            Plots[0].Pen.Width = this.Plot0Width;
            Plots[1].PenStyle  = this.Dash1Style;
            Plots[1].Pen.Width = this.Plot1Width;
            Plots[2].PenStyle  = this.Dash2Style;
            Plots[2].Pen.Width = this.Plot2Width;

            Plots[3].PenStyle  = this.Dash3Style;
            Plots[3].Pen.Width = this.Plot3Width;
            Plots[4].PenStyle  = this.Dash3Style;
            Plots[4].Pen.Width = this.Plot3Width;
            Plots[5].PenStyle  = this.Dash3Style;
            Plots[5].Pen.Width = this.Plot3Width;
        }
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnCalculate()
        {
            int temp_signal_value = 0;

            double actualhigh = High[0];
            double actuallow  = Low[0];

            if (this.Type == enum_swingray_type.open)
            {
                actualhigh = Open[0];
                actuallow  = Open[0];
            }
            else if (this.Type == enum_swingray_type.close)
            {
                actualhigh = Close[0];
                actuallow  = Close[0];
            }


            // build up cache of recent High and Low values
            // code devised from default Swing Indicator by marqui@BMT, 10-NOV-2010
            lastHighCache.Add(actualhigh);
            if (lastHighCache.Count > (2 * strength) + 1)
            {
                lastHighCache.RemoveAt(0); // if cache is filled, drop the oldest value
            }
            lastLowCache.Add(actuallow);
            if (lastLowCache.Count > (2 * strength) + 1)
            {
                lastLowCache.RemoveAt(0);
            }
            //
            if (lastHighCache.Count == (2 * strength) + 1) // wait for cache of Highs to be filled
            {
                // test for swing high
                bool   isSwingHigh             = true;
                double swingHighCandidateValue = (double)lastHighCache[strength];
                for (int i = 0; i < strength; i++)
                {
                    if ((double)lastHighCache[i] >= swingHighCandidateValue - double.Epsilon)
                    {
                        isSwingHigh = false; // bar(s) to right of candidate were higher
                    }
                }
                for (int i = strength + 1; i < lastHighCache.Count; i++)
                {
                    if ((double)lastHighCache[i] > swingHighCandidateValue - double.Epsilon)
                    {
                        isSwingHigh = false; // bar(s) to left of candidate were higher
                    }
                }
                // end of test

                if (isSwingHigh)
                {
                    lastSwingHighValue = swingHighCandidateValue;
                }

                if (isSwingHigh) // if we have a new swing high then we draw a ray line on the chart
                {
                    AddChartRay("highRay" + (ProcessingBarIndex - strength), false, strength, lastSwingHighValue, 0, lastSwingHighValue, swingHighColor, DashStyle.Solid, 1);
                    RayObject newRayObject = new RayObject("highRay" + (ProcessingBarIndex - strength), strength, lastSwingHighValue, 0, lastSwingHighValue);
                    swingHighRays.Push(newRayObject);     // store a reference so we can remove it from the chart later
                }
                else if (actualhigh > lastSwingHighValue) // otherwise, we test to see if price has broken through prior swing high
                {
                    if (swingHighRays.Count > 0)          // just to be safe
                    {
                        //IRay currentRay = (IRay)swingHighRays.Pop(); // pull current ray from stack
                        RayObject currentRay = (RayObject)swingHighRays.Pop(); // pull current ray from stack
                        if (currentRay != null)
                        {
                            if (enableAlerts)
                            {
                                ShowAlert("Swing High at " + currentRay.Y1 + " broken", GlobalUtilities.GetSoundfile(this.Soundfile));
                            }
                            temp_signal_value = 1;

                            if (keepBrokenLines) // draw a line between swing point and break bar
                            {
                                int        barsAgo = currentRay.BarsAgo1;
                                ITrendLine newLine = AddChartLine("highLine" + (ProcessingBarIndex - barsAgo), false, barsAgo, currentRay.Y1, 0, currentRay.Y1, swingHighColor, DashStyle.Dot, 2);
                            }
                            RemoveChartDrawing(currentRay.Tag);
                            if (swingHighRays.Count > 0)
                            {
                                //IRay priorRay = (IRay)swingHighRays.Peek();
                                RayObject priorRay = (RayObject)swingHighRays.Peek();
                                lastSwingHighValue = priorRay.Y1; // needed when testing the break of the next swing high
                            }
                            else
                            {
                                lastSwingHighValue = double.MaxValue; // there are no higher swings on the chart; reset to default
                            }
                        }
                    }
                }
            }

            if (lastLowCache.Count == (2 * strength) + 1) // repeat the above for the swing lows
            {
                // test for swing low
                bool   isSwingLow             = true;
                double swingLowCandidateValue = (double)lastLowCache[strength];
                for (int i = 0; i < strength; i++)
                {
                    if ((double)lastLowCache[i] <= swingLowCandidateValue + double.Epsilon)
                    {
                        isSwingLow = false; // bar(s) to right of candidate were lower
                    }
                }
                for (int i = strength + 1; i < lastLowCache.Count; i++)
                {
                    if ((double)lastLowCache[i] < swingLowCandidateValue + double.Epsilon)
                    {
                        isSwingLow = false; // bar(s) to left of candidate were lower
                    }
                }
                // end of test for low

                if (isSwingLow)
                {
                    lastSwingLowValue = swingLowCandidateValue;
                }

                if (isSwingLow) // found a new swing low; draw it on the chart
                {
                    AddChartRay("lowRay" + (ProcessingBarIndex - strength), false, strength, lastSwingLowValue, 0, lastSwingLowValue, swingLowColor, DashStyle.Solid, 1);
                    RayObject newRayObject = new RayObject("lowRay" + (ProcessingBarIndex - strength), strength, lastSwingLowValue, 0, lastSwingLowValue);
                    swingLowRays.Push(newRayObject);
                }
                else if (actuallow < lastSwingLowValue) // otherwise test to see if price has broken through prior swing low
                {
                    if (swingLowRays.Count > 0)
                    {
                        //IRay currentRay = (IRay)swingLowRays.Pop();
                        RayObject currentRay = (RayObject)swingLowRays.Pop();
                        if (currentRay != null)
                        {
                            if (enableAlerts)
                            {
                                ShowAlert("Swing Low at " + currentRay.Y1 + " broken", GlobalUtilities.GetSoundfile(this.Soundfile));
                            }
                            temp_signal_value = -1;

                            if (keepBrokenLines) // draw a line between swing point and break bar
                            {
                                int        barsAgo = currentRay.BarsAgo1;
                                ITrendLine newLine = AddChartLine("highLine" + (ProcessingBarIndex - barsAgo), false, barsAgo, currentRay.Y1, 0, currentRay.Y1, swingLowColor, DashStyle.Dot, 2);
                            }
                            RemoveChartDrawing(currentRay.Tag);

                            if (swingLowRays.Count > 0)
                            {
                                //IRay priorRay = (IRay)swingLowRays.Peek();
                                RayObject priorRay = (RayObject)swingLowRays.Peek();
                                lastSwingLowValue = priorRay.Y1; // price level of the prior swing low
                            }
                            else
                            {
                                lastSwingLowValue = double.MinValue; // no swing lows present; set this to default value
                            }
                        }
                    }
                }
            }

            if (enablesignalline)
            {
                SignalLine.Set(temp_signal_value);
            }
            else
            {
                this.SwingHighs.Set(lastSwingHighValue);
                this.SwingLows.Set(lastSwingLowValue);

                this.PriceLines.Set(InSeries[0]);
            }


            //Set the color
            PlotColors[0][0] = this.Signal;
            OutputDescriptors[0].PenStyle  = DashStyle.Solid;
            OutputDescriptors[0].Pen.Width = this.Plot0Width;
            PlotColors[1][0] = this.swingHighColor;
            OutputDescriptors[1].PenStyle  = DashStyle.Solid;
            OutputDescriptors[1].Pen.Width = this.Plot0Width;
            PlotColors[2][0] = this.swingLowColor;
            OutputDescriptors[2].PenStyle  = DashStyle.Solid;
            OutputDescriptors[2].Pen.Width = this.Plot0Width;
            PlotColors[3][0] = this.Signal;
            OutputDescriptors[3].PenStyle  = DashStyle.Solid;
            OutputDescriptors[3].Pen.Width = this.Plot0Width;
        }