protected override void OnCalculate()
        {
            //we need more contrast
            if (this.UseWhiteCandles)
            {
                this.BarColor = Color.White;
            }

            //calculate data
            OrderDirection_Enum?resultdata = this.calculate(InSeries, this.MA_Selected, this.MA_Fast, this.MA_Medium, this.MA_Slow);

            //draw indicator lines
            Plot_1.Set(this._mafast[0]);
            Plot_2.Set(this._mamedium[0]);
            Plot_3.Set(this._maslow[0]);

            //todo set the additional indicator values


            //draw other things
            if (resultdata.HasValue)
            {
                switch (resultdata)
                {
                case OrderDirection_Enum.OpenLong:
                    AddChartDot("ArrowLong_Entry" + Bars[0].Time.Ticks, true, Bars[0].Time, Bars[0].Open, Color.LightGreen);
                    break;

                case OrderDirection_Enum.OpenShort:
                    AddChartDiamond("ArrowShort_Entry" + Bars[0].Time.Ticks, true, Bars[0].Time, Bars[0].Open, Color.LightGreen);
                    break;

                case OrderDirection_Enum.CloseShort:
                    AddChartDiamond("ArrowShort_Exit" + Bars[0].Time.Ticks, true, Bars[0].Time, Bars[0].Open, Color.Red);
                    break;

                case OrderDirection_Enum.CloseLong:
                    AddChartDot("ArrowLong_Exit" + Bars[0].Time.Ticks, true, Bars[0].Time, Bars[0].Open, Color.Red);
                    break;

                default:
                    break;
                }
            }
            else
            {
                //value was null
            }
        }
Exemple #2
0
        protected override void OnBarUpdate()
        {
            //we need more contrast
            this.BarColor = Color.White;

            //calculate data
            OrderAction?resultdata = this.calculate(Input);

            //draw indicator lines
            Plot_1.Set(this._sma20[0]);
            Plot_2.Set(this._sma50[0]);
            Plot_3.Set(this._sma200[0]);

            //Plot_1.Set(this._slow[0]);
            //Plot_2.Set(this._fast[0]);


            //draw other things
            if (resultdata.HasValue)
            {
                switch (resultdata)
                {
                case OrderAction.Buy:
                    DrawDot("ArrowLong_Entry" + Bars[0].Time.Ticks, true, Bars[0].Time, Bars[0].Open, Color.LightGreen);
                    break;

                case OrderAction.SellShort:
                    DrawDiamond("ArrowShort_Entry" + Bars[0].Time.Ticks, true, Bars[0].Time, Bars[0].Open, Color.LightGreen);
                    break;

                case OrderAction.BuyToCover:
                    DrawDiamond("ArrowShort_Exit" + Bars[0].Time.Ticks, true, Bars[0].Time, Bars[0].Open, Color.Red);
                    break;

                case OrderAction.Sell:
                    DrawDot("ArrowLong_Exit" + Bars[0].Time.Ticks, true, Bars[0].Time, Bars[0].Open, Color.Red);
                    break;

                default:
                    break;
                }
            }
            else
            {
                //value was null
            }
        }
Exemple #3
0
        protected override void OnBarUpdate()
        {
            ////we need more contrast
            //this.BarColor = Color.White;

            //calculate data
            OrderAction?resultdata = this.calculate(Input, Open, High, null, null, this.Bollinger_Period, this.Bollinger_Standard_Deviation, this.Momentum_Period, this.RSI_Period, this.RSI_Smooth, this.RSI_Level_Low, this.RSI_Level_High, this.Momentum_Level_Low, this.Momentum_Level_High);

            Plot_1.Set(bb_upper);
            Plot_2.Set(bb_middle);
            Plot_3.Set(bb_lower);

            //draw other things
            if (resultdata.HasValue)
            {
                switch (resultdata)
                {
                case OrderAction.Buy:
                    DrawDot("ArrowLong_Entry" + Bars[0].Time.Ticks, true, Bars[0].Time, Bars[0].Open, Color.LightGreen);
                    break;

                case OrderAction.SellShort:
                    DrawDiamond("ArrowShort_Entry" + Bars[0].Time.Ticks, true, Bars[0].Time, Bars[0].Open, Color.LightGreen);
                    break;

                case OrderAction.BuyToCover:
                    //DrawDiamond("ArrowShort_Exit" + Bars[0].Time.Ticks, true, Bars[0].Time, Bars[0].Open, Color.Red);
                    break;

                case OrderAction.Sell:
                    //DrawDot("ArrowLong_Exit" + Bars[0].Time.Ticks, true, Bars[0].Time, Bars[0].Open, Color.Red);
                    break;

                default:
                    break;
                }
            }
            else
            {
                //value was null
            }
        }
Exemple #4
0
        protected override void OnCalculate()
        {
            ////we need more contrast
            //this.BarColor = Color.White;

            //calculate data
            ResultValue returnvalue = this.calculate(InSeries, Open, High, null, null, this.Bollinger_Period, this.Bollinger_Standard_Deviation, this.Momentum_Period, this.RSI_Period, this.RSI_Smooth, this.RSI_Level_Low, this.RSI_Level_High, this.Momentum_Level_Low, this.Momentum_Level_High);

            //If the calculate method was not finished we need to stop and show an alert message to the user.
            if (returnvalue.ErrorOccured)
            {
                //Display error just one time
                if (!this.ErrorOccured)
                {
                    GlobalUtilities.DrawAlertTextOnChart(this, Const.DefaultStringErrorDuringCalculation);
                    this.ErrorOccured = true;
                }
                return;
            }

            Plot_1.Set(bb_upper);
            Plot_2.Set(bb_middle);
            Plot_3.Set(bb_lower);

            //Entry
            if (returnvalue.Entry.HasValue)
            {
                switch (returnvalue.Entry)
                {
                case OrderDirection.Buy:
                    AddChartDot("ArrowLong_Entry" + Bars[0].Time.Ticks, true, Bars[0].Time, Bars[0].Open, Color.LightGreen);
                    //this.Indicator_Curve_Entry.Set(1);
                    break;

                case OrderDirection.Sell:
                    AddChartDiamond("ArrowShort_Entry" + Bars[0].Time.Ticks, true, Bars[0].Time, Bars[0].Open, Color.LightGreen);
                    //this.Indicator_Curve_Entry.Set(-1);
                    break;
                }
            }
            //else
            //{
            //    //Value was null so nothing to do.
            //    this.Indicator_Curve_Entry.Set(0);
            //}

            //Exit
            if (returnvalue.Exit.HasValue)
            {
                switch (returnvalue.Exit)
                {
                case OrderDirection.Buy:
                    AddChartDiamond("ArrowShort_Exit" + Bars[0].Time.Ticks, true, Bars[0].Time, Bars[0].Open, Color.Red);
                    //this.Indicator_Curve_Exit.Set(0.5);
                    break;

                case OrderDirection.Sell:
                    AddChartDot("ArrowLong_Exit" + Bars[0].Time.Ticks, true, Bars[0].Time, Bars[0].Open, Color.Red);
                    //this.Indicator_Curve_Exit.Set(-0.5);
                    break;
                }
            }
            //else
            //{
            //    //Value was null so nothing to do.
            //    this.Indicator_Curve_Exit.Set(0);
            //}
        }
Exemple #5
0
        protected override void OnCalculate()
        {
            if (this.MA_1 != 0 && this.MA_1 > this.RequiredBarsCount ||
                this.MA_2 != 0 && this.MA_2 > this.RequiredBarsCount ||
                this.MA_3 != 0 && this.MA_3 > this.RequiredBarsCount ||
                this.MA_4 != 0 && this.MA_4 > this.RequiredBarsCount ||
                this.MA_5 != 0 && this.MA_5 > this.RequiredBarsCount ||
                this.MA_6 != 0 && this.MA_6 > this.RequiredBarsCount)
            {
                AddChartTextFixed("AlertText", "Required bars must be at least as high as the largest moving average period.", TextPosition.Center, Color.Red, new Font("Arial", 30), Color.Red, Color.Red, 20);
            }

            int _signal_value = 0;
            int _enabled_ifs  = 0;

            if (this.MA_1 != 0)
            {
                Plot_1.Set(this.GetValue(this.MA_1_Selected, this.MA_1));
            }
            if (this.MA_2 != 0)
            {
                Plot_2.Set(this.GetValue(this.MA_2_Selected, this.MA_2));
            }
            if (this.MA_3 != 0)
            {
                Plot_3.Set(this.GetValue(this.MA_3_Selected, this.MA_3));
            }
            if (this.MA_4 != 0)
            {
                Plot_4.Set(this.GetValue(this.MA_4_Selected, this.MA_4));
            }
            if (this.MA_5 != 0)
            {
                Plot_5.Set(this.GetValue(this.MA_5_Selected, this.MA_5));
            }
            if (this.MA_6 != 0)
            {
                Plot_6.Set(this.GetValue(this.MA_6_Selected, this.MA_6));
            }

            //Signals
            if (this.If_1_over_2)
            {
                _enabled_ifs++;
                if (this.MA_1 != 0 && this.MA_2 != 0 && Plot_1.Last() > Plot_2.Last())
                {
                    _signal_value++;
                }
                else if (this.MA_1 != 0 && this.MA_2 != 0 && Plot_1.Last() < Plot_2.Last())
                {
                    _signal_value--;
                }
            }

            if (this.If_2_over_3)
            {
                _enabled_ifs++;
                if (this.MA_2 != 0 && this.MA_3 != 0 && Plot_2.Last() > Plot_3.Last())
                {
                    _signal_value++;
                }
                else if (this.MA_2 != 0 && this.MA_3 != 0 && Plot_2.Last() < Plot_3.Last())
                {
                    _signal_value--;
                }
            }

            if (this.If_3_over_4)
            {
                _enabled_ifs++;
                if (this.MA_3 != 0 && this.MA_4 != 0 && Plot_3.Last() > Plot_4.Last())
                {
                    _signal_value++;
                }
                else if (this.MA_3 != 0 && this.MA_4 != 0 && Plot_3.Last() < Plot_4.Last())
                {
                    _signal_value--;
                }
            }

            if (this.If_4_over_5)
            {
                _enabled_ifs++;
                if (this.MA_4 != 0 && this.MA_5 != 0 && Plot_4.Last() > Plot_5.Last())
                {
                    _signal_value++;
                }
                else if (this.MA_4 != 0 && this.MA_5 != 0 && Plot_4.Last() < Plot_5.Last())
                {
                    _signal_value--;
                }
            }

            if (this.If_5_over_6)
            {
                _enabled_ifs++;
                if (this.MA_5 != 0 && this.MA_6 != 0 && Plot_5.Last() > Plot_6.Last())
                {
                    _signal_value++;
                }
                else if (this.MA_5 != 0 && this.MA_6 != 0 && Plot_5.Last() < Plot_6.Last())
                {
                    _signal_value--;
                }
            }


            //signal
            if (_signal_value == _enabled_ifs)
            {
                _signals.Set(1);
            }
            else if (_signal_value == _enabled_ifs * -1)
            {
                _signals.Set(-1);
            }
            else
            {
                _signals.Set(0);
            }

            //days
            if (_signals[0] == 0)
            {
                _days.Set(0);
            }
            else
            {
                if (_signals[0] == 1 && _signals[1] == 1)
                {
                    _days.Set(_days[1] + 1);
                }
                else if (_signals[0] == -1 && _signals[1] == -1)
                {
                    _days.Set(_days[1] - 1);
                }
                else
                {
                    if (_signals[0] == 1 && _signals[1] == 0 ||
                        _signals[0] == 1 && _signals[1] == -1)
                    {
                        _days.Set(1);
                    }
                    else
                    {
                        _days.Set(-1);
                    }
                }
            }


            if (ShowSignalOnChartBackground)
            {
                //color an background
                if (_signals[0] == 1)
                {
                    this.BackColor = GlobalUtilities.AdjustOpacity(this.ColorLongSignalBackground, this.OpacityLongSignal / 100.0);
                }
                else if (_signals[0] == -1)
                {
                    this.BackColor = GlobalUtilities.AdjustOpacity(this.ColorShortSignalBackground, this.OpacityShortSignal / 100.0);
                }
            }

            //if (this.ShowSignalOnChartPercent)
            //{
            //    //percent on all signals with more _enabled_ifs
            //    if (_signals[0] == 0 && _signals[1] != 0)
            //    {
            //        this.drawpercentlines(1, this.DashStyleLine, this.PlotWidthLine);
            //    }
            //    else if (_signals[0] == 1 && _signals[1] == -1)
            //    {
            //        this.drawpercentlines(1, this.DashStyleLine, this.PlotWidthLine);
            //    }
            //    else if (_signals[0] == -1 && _signals[1] == 1)
            //    {
            //        this.drawpercentlines(1, this.DashStyleLine, this.PlotWidthLine);
            //    }

            //    //percent on last candle
            //    if (_signals[0] != 0 && IsProcessingBarIndexLast)
            //    {
            //        this.drawpercentlines(0, this.DashStyleLineLast, this.PlotWidthLineLast);
            //    }
            //}

            //percent
            //percent on all signals with more _enabled_ifs
            if (_signals[0] == 0 && _signals[1] != 0)
            {
                _percent.Set(this.getpercent(1));
                if (this.ShowSignalOnChartPercent)
                {
                    this.drawpercentlines(1, this.DashStyleLine, this.PlotWidthLine);
                }
            }
            else if (_signals[0] == 1 && _signals[1] == -1)
            {
                _percent.Set(this.getpercent(1));
                if (this.ShowSignalOnChartPercent)
                {
                    this.drawpercentlines(1, this.DashStyleLine, this.PlotWidthLine);
                }
            }
            else if (_signals[0] == -1 && _signals[1] == 1)
            {
                _percent.Set(this.getpercent(1));
                if (this.ShowSignalOnChartPercent)
                {
                    this.drawpercentlines(1, this.DashStyleLine, this.PlotWidthLine);
                }
            }

            //percent on last candle
            if (_signals[0] != 0 && IsProcessingBarIndexLast)
            {
                _percent.Set(this.getpercent(0));
                if (this.ShowSignalOnChartPercent)
                {
                    this.drawpercentlines(0, this.DashStyleLineLast, this.PlotWidthLineLast);
                }
            }


            if (this.ShowSignalOnChartArrow)
            {
                if (_signals[0] == 1 && _signals[1] != 1)
                {
                    AddChartArrowUp("ArrowLong_MA" + +Bars[0].Time.Ticks, this.IsAutoAdjustableScale, 0, Bars[0].Low, this.ColorLongSignalArrow);
                }
                else if (_signals[0] == -1 && _signals[1] != -1)
                {
                    AddChartArrowDown("ArrowShort_MA" + +Bars[0].Time.Ticks, this.IsAutoAdjustableScale, 0, Bars[0].High, this.ColorShortSignalArrow);
                }
            }


            //Set the color
            PlotColors[0][0] = this.Color_1;
            OutputDescriptors[0].PenStyle  = this.DashStyle_1;
            OutputDescriptors[0].Pen.Width = this.LineWidth_1;
            PlotColors[1][0] = this.Color_2;
            OutputDescriptors[1].PenStyle  = this.DashStyle_2;
            OutputDescriptors[1].Pen.Width = this.LineWidth_2;
            PlotColors[2][0] = this.Color_3;
            OutputDescriptors[2].PenStyle  = this.DashStyle_3;
            OutputDescriptors[2].Pen.Width = this.LineWidth_3;
            PlotColors[3][0] = this.Color_4;
            OutputDescriptors[3].PenStyle  = this.DashStyle_4;
            OutputDescriptors[3].Pen.Width = this.LineWidth_4;
            PlotColors[4][0] = this.Color_5;
            OutputDescriptors[4].PenStyle  = this.DashStyle_5;
            OutputDescriptors[4].Pen.Width = this.LineWidth_5;
            PlotColors[5][0] = this.Color_6;
            OutputDescriptors[5].PenStyle  = this.DashStyle_6;
            OutputDescriptors[5].Pen.Width = this.LineWidth_6;
        }