SIGNAL TRANSFER

Created at 14 Mar 2022, 14:36
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
BJ

BJORNBERNAU

Joined 21.07.2020

SIGNAL TRANSFER
14 Mar 2022, 14:36


Hello dear All !

Stuck again despite excellent coaching from Panagiotis et al. The signals are alternating sell (lawngreen) and liquidation (violet) signals.

I don't get why the signals are not transferred from this IND to the following BOT. Trying to evoke the signal to 'overrun' any misses in the signals by a 

            var b_1 = S2.liq_sellONE.Last(-1);
            var b0 = S2.liq_sellONE.Last(0);
            var b1 = S2.liq_sellONE.Last(1);
            var b2 = S2.liq_sellONE.Last(2);
            var b3 = S2.liq_sellONE.Last(3);

Does not do it. 

Only one sell signal is relayed, despite it's being set to null in every round and the alternating sell ans liquidaiton, in the indicator runs like clockwork. 

The code 

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class COMPOSITEliveTEST_BBc_RED : Indicator
    {


        /////////////////////////////////////////////
        /////////////////////////////////////////////
        /////////////////////////////////////////////
        /////////////////////////////////////////////
        /////////////////////////////////////////////

        //////////////   22-02-11   /////////////////

        /////////////////////////////////////////////
        /////////////////////////////////////////////
        /////////////////////////////////////////////
        /////////////////////////////////////////////
        /////////////////////////////////////////////


        /////   big point 

        [Output("White", PlotType = PlotType.Points, LineColor = "#FFFFFF", Thickness = 12)]
        public IndicatorDataSeries White { get; set; }

        [Output("Yellow", PlotType = PlotType.Points, LineColor = "#FFFFFF00", Thickness = 12)]
        public IndicatorDataSeries Yellow { get; set; }

        [Output("LawnGreen", PlotType = PlotType.Points, LineColor = "#FF7CFC00", Thickness = 12)]
        public IndicatorDataSeries LawnGreen { get; set; }

        [Output("DarkViolet", PlotType = PlotType.Points, LineColor = "#FF9400D3", Thickness = 12)]
        public IndicatorDataSeries DarkViolet { get; set; }

        [Output("Red", PlotType = PlotType.Points, LineColor = "#FFFF0000", Thickness = 12)]
        public IndicatorDataSeries Red { get; set; }

        [Output("DarkRed", PlotType = PlotType.Points, LineColor = "#FF800001", Thickness = 10)]
        public IndicatorDataSeries DarkRed { get; set; }

        [Output("DarkSeagreen", PlotType = PlotType.Points, LineColor = "#FF8FBC8F", Thickness = 12)]
        public IndicatorDataSeries DarkSeagreen { get; set; }

        [Output("DimGray", PlotType = PlotType.Points, LineColor = "#FF696969", Thickness = 12)]
        public IndicatorDataSeries DimGray { get; set; }

        [Output("Gold", PlotType = PlotType.Points, LineColor = "#FFFFD700", Thickness = 12)]
        public IndicatorDataSeries Gold { get; set; }

        [Output("DarkGold", PlotType = PlotType.Points, LineColor = "#FF8C6C1F", Thickness = 12)]
        public IndicatorDataSeries DarkGold { get; set; }

        [Output("Torquoise", PlotType = PlotType.Points, LineColor = "#FF40E0D0", Thickness = 12)]
        public IndicatorDataSeries Torquoise { get; set; }


        /////   MEDIUM POINT    /////
        ////////////////////////////



        [Output("mediumGREYSAND", PlotType = PlotType.Points, LineColor = "#FFA6996E", Thickness = 6)]
        public IndicatorDataSeries mediumGREYSAND { get; set; }

        [Output("mediumYellow", PlotType = PlotType.Points, LineColor = "#FFFFFF00", Thickness = 6)]
        public IndicatorDataSeries mediumYellow { get; set; }

        [Output("mediumLawnGreen", PlotType = PlotType.Points, LineColor = "#FF7CFC00", Thickness = 6)]
        public IndicatorDataSeries mediumLawnGreen { get; set; }

        [Output("mediumDarkViolet", PlotType = PlotType.Points, LineColor = "#FF9400D3", Thickness = 5)]
        public IndicatorDataSeries mediumDarkViolet { get; set; }

        [Output("mediumRed", PlotType = PlotType.Points, LineColor = "#FFFF0000", Thickness = 6)]
        public IndicatorDataSeries mediumRed { get; set; }

        [Output("mediumBACKGROUND", PlotType = PlotType.Points, LineColor = "#FF1C1B21", Thickness = 10)]
        public IndicatorDataSeries mediumBACKGROUND { get; set; }

        [Output("mediumDimGray", PlotType = PlotType.Points, LineColor = "#FF373440", Thickness = 6)]
        public IndicatorDataSeries mediumDimGray { get; set; }

        [Output("mediumS_DimGray", PlotType = PlotType.Points, LineColor = "#FF262626", Thickness = 4)]
        public IndicatorDataSeries mediumS_DimGray { get; set; }

        [Output("mediumDarkSeagreen", PlotType = PlotType.Points, LineColor = "#FF8FBC8F", Thickness = 6)]
        public IndicatorDataSeries mediumDarkSeagreen { get; set; }

        [Output("mediumGold", PlotType = PlotType.Points, LineColor = "#FFFFD700", Thickness = 6)]
        public IndicatorDataSeries mediumGold { get; set; }

        [Output("mediumDarkGold", PlotType = PlotType.Points, LineColor = "#FF8C6C1F", Thickness = 6)]
        public IndicatorDataSeries mediumDarkGold { get; set; }

        [Output("mediumTorquoise", PlotType = PlotType.Points, LineColor = "#FF40E0D0", Thickness = 6)]
        public IndicatorDataSeries mediumTorquoise { get; set; }




        /////   SMALL POINT    /////
        ////////////////////////////

        [Output("Smallwhite3", PlotType = PlotType.Points, LineColor = "#FFFFFF", Thickness = 3)]
        public IndicatorDataSeries Smallwhite3 { get; set; }

        [Output("smallDimGray", PlotType = PlotType.Points, LineColor = "#FF262626", Thickness = 3)]
        public IndicatorDataSeries smallDimGray { get; set; }

        [Output("smallCERISE", PlotType = PlotType.Points, LineColor = "#FFEB12E1", Thickness = 4)]
        public IndicatorDataSeries smallCERISE { get; set; }

        [Output("smallLawnGreen", PlotType = PlotType.Points, LineColor = "#FF7CFC00", Thickness = 3)]
        public IndicatorDataSeries smallLawnGreen { get; set; }

        [Output("SmallRed", PlotType = PlotType.Points, LineColor = "#FFFF0000", Thickness = 3)]
        public IndicatorDataSeries SmallRed { get; set; }

        [Output("smallDarkViolet", PlotType = PlotType.Points, LineColor = "#FF9400D3", Thickness = 3)]
        public IndicatorDataSeries smallDarkViolet { get; set; }

        [Output("smallBACKGROUND", PlotType = PlotType.Points, LineColor = "#FF1C1B21", Thickness = 3)]
        public IndicatorDataSeries smallBACKGROUND { get; set; }

        [Output("smallGold", PlotType = PlotType.Points, LineColor = "#FFFFD700", Thickness = 4)]
        public IndicatorDataSeries smallGOLD { get; set; }

        [Output("smallGREYSAND", PlotType = PlotType.Points, LineColor = "#FFA6996E", Thickness = 3)]
        public IndicatorDataSeries smallGREYSAND { get; set; }

        [Output("smallDARKSLATEBLUE", PlotType = PlotType.Points, LineColor = "#FF2D2459", Thickness = 3)]
        public IndicatorDataSeries smallDARKSLATEBLUE { get; set; }

        [Output("mediumDARKSLATEBLUE", PlotType = PlotType.Points, LineColor = "#FF5444A2", Thickness = 4)]
        public IndicatorDataSeries mediumDARKSLATEBLUE { get; set; }

        /////   MICRO POINT    /////
        ////////////////////////////

        [Output("microWHITE", PlotType = PlotType.Points, LineColor = "#FFFFFF", Thickness = 1)]
        public IndicatorDataSeries microWHITE { get; set; }

        [Output("microSEAGREEN", PlotType = PlotType.Points, LineColor = "#FF21A94D", Thickness = 1)]
        public IndicatorDataSeries microSEAGREEN { get; set; }

        [Output("microCERISE", PlotType = PlotType.Points, LineColor = "#FFEB12E1", Thickness = 1)]
        public IndicatorDataSeries microCERISE { get; set; }

        [Output("microRED", PlotType = PlotType.Points, LineColor = "#FFFF0000", Thickness = 1)]
        public IndicatorDataSeries microRED { get; set; }

        [Output("microLawnGreen", PlotType = PlotType.Points, LineColor = "#FF7CFC00", Thickness = 1)]
        public IndicatorDataSeries microLawnGreen { get; set; }

        [Output("microDARKred", PlotType = PlotType.Points, LineColor = "#FF800001", Thickness = 1)]
        public IndicatorDataSeries microDARKred { get; set; }

        [Output("microViolet", PlotType = PlotType.Points, LineColor = "#FF9400D3", Thickness = 1)]
        public IndicatorDataSeries microViolet { get; set; }

        [Output("microBACKGROUND", PlotType = PlotType.Points, LineColor = "#FF1C1B21", Thickness = 1)]
        public IndicatorDataSeries microBACKGROUND { get; set; }

        /////   LINES    /////
        //////////////////////


        [Output("lineWHITE", PlotType = PlotType.DiscontinuousLine, LineColor = "#FFFFFF", Thickness = 1)]
        public IndicatorDataSeries lineWHITE { get; set; }

        [Output("lineFlashViolet", PlotType = PlotType.DiscontinuousLine, LineColor = "#B511F7", Thickness = 1)]
        public IndicatorDataSeries lineFlashViolet { get; set; }

        [Output("lineOLIVE", PlotType = PlotType.DiscontinuousLine, LineColor = "#FF344E1C", Thickness = 1)]
        public IndicatorDataSeries lineOLIVE { get; set; }

        [Output("lineDarkGold", PlotType = PlotType.DiscontinuousLine, LineColor = "#FF8C6C1F", Thickness = 1)]
        public IndicatorDataSeries lineDarkGold { get; set; }

        [Output("lineGold", PlotType = PlotType.DiscontinuousLine, LineColor = "#FFFFD700", Thickness = 1)]
        public IndicatorDataSeries lineGold { get; set; }

        [Output("lineDarkViolet", PlotType = PlotType.DiscontinuousLine, LineColor = "#FF9400D3", Thickness = 1)]
        public IndicatorDataSeries lineDarkViolet { get; set; }

        [Output("lineLawnGreen", PlotType = PlotType.DiscontinuousLine, LineColor = "#FF7CFC00", Thickness = 1)]
        public IndicatorDataSeries lineLawnGreen { get; set; }

        [Output("lineDARKred", PlotType = PlotType.DiscontinuousLine, LineColor = "#FF800001", Thickness = 1)]
        public IndicatorDataSeries lineDARKred { get; set; }



        ////   BOLLINGER    //// 



        //////////////////////////////
        ////       PARAMETERS      //// 

        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter("BandPeriods", DefaultValue = 16)]
        public int BandPeriod { get; set; }

        [Parameter("Std", DefaultValue = 1.6)]
        public double std { get; set; }

        [Parameter("MAType")]
        public MovingAverageType MAType { get; set; }

        [Parameter(DefaultValue = 100, MinValue = 50)]
        public int Period { get; set; }


        [Parameter("littFACTOR", DefaultValue = 1)]
        public double littFACTOR { get; set; }

        [Parameter("thresherValue", DefaultValue = 4)]
        public double thresherValue { get; set; }


        [Parameter("lastINDEX", DefaultValue = 4280)]
        public int lastINDEX { get; set; }

        [Parameter("zeroINDEX", DefaultValue = 2000)]
        public int zeroINDEX { get; set; }


        [Output("sell_ONE", PlotType = PlotType.Points, LineColor = "#FF7CFC00", Thickness = 4)]
        public IndicatorDataSeries sell_ONE { get; set; }

        [Output("liq_sellONE", PlotType = PlotType.Points, LineColor = "#B511F7", Thickness = 4)]
        public IndicatorDataSeries liq_sellONE { get; set; }



        // private bool isSell1 = false;

        //  private double d = double.NaN;

        private BollingerBands boll;

        protected override void Initialize()
        {
            boll = Indicators.BollingerBands(Source, BandPeriod, std, MAType);
        }





        int high = 0;
        int highCOUNTER_A = 0;
        int highCOUNTER_B = 0;

        int HIGHstartCountIndexZERO = 0;

        int retrace = 2;



        public override void Calculate(int index)
        {
            highMARKET(index, high, highCOUNTER_A, highCOUNTER_B);
        }



        protected internal void highMARKET(int index, int high, int highCOUNTER_A, int highCOUNTER_B)
        {
            high = 0;

            double high0 = Bars.HighPrices[index - 0];
            double high1 = Bars.HighPrices[index - 1];
            double high2 = Bars.HighPrices[index - 2];
            double high3 = Bars.HighPrices[index - 3];
            double high4 = Bars.HighPrices[index - 4];
            double close0 = Bars.ClosePrices[index - 0];

            var BBT1 = boll.Top[index - 1];
            var BBT2 = boll.Top[index - 2];
            var BBM1 = boll.Main[index - 1];


            if (high4 <= high2)
                if (high3 <= high2)
                    if (high2 > BBT2)
                        if (high2 >= high1)
                            if (high2 >= close0)
                            {
                                high = 1;
                                mediumDimGray[index - 2] = Bars.HighPrices[index - 2] + littFACTOR * 2E-06;
                            }


            if (high == 1)
            {
                HIGHstartCountIndexZERO += 1;
            }


            {
                if (high == 1)
                    if (HIGHstartCountIndexZERO % 2 != 0)
                    {
                        highCOUNTER_A = 1;
                    }



                if (high == 1)
                    if (HIGHstartCountIndexZERO % 2 == 0)
                    {
                        highCOUNTER_B = 1;
                    }

            }

            HIGHprimaryINDEX(index, high, highCOUNTER_A, highCOUNTER_B);
        }


        int highA1 = 0;
        int highB1 = 0;

        double initHA1 = 0;
        double initHB1 = 0;
        bool pingORDER_1H = false;

        protected internal void HIGHprimaryINDEX(int index, int high, int highCOUNTER_A, int highCOUNTER_B)
        {
            {

                ////   INITIATION SIGNALS   ////


                if (highCOUNTER_A == 1)
                {
                    highA1 = index - retrace;
                }

                if (highCOUNTER_B == 1)
                {
                    highB1 = index - retrace;
                }

                initHA1 = Bars.HighPrices[highA1];
                initHB1 = Bars.HighPrices[highB1];

                if (highA1 > highB1)
                {
                    pingORDER_1H = false;
                }

                if (highA1 < highB1)
                    if (initHA1 > initHB1)
                    {
                        pingORDER_1H = true;
                    }
                //
                //
                projDETECTOR_1H(index, highA1, highB1, pingORDER_1H);
            }
        }


        //////////////////////////////////////////
        //////////////////////////////////////////
        //////////////////////////////////////////
        //////////////////////////////////////////
        //////////////////////////////////////////
        //////////////////////////////////////////
        //////////////////////////////////////////


        //////////////////////////////////////////
        //////////////////////////////////////////
        //////////////////////////////////////////
        //////////////////////////////////////////
        //////////////////////////////////////////
        //////////////////////////////////////////
        //////////////////////////////////////////




        //  bool highchannel1 = false;
        bool NXTchan1H = false;
        double Gradient1H = 0;
        double prevGRAD1H = 0;
        double lastGRAD1H = 0;
        double chklastGRAD1H = 0;


        int R1H = 0;
        int S1H = 0;
        double HA1 = 0;
        double HB1 = 0;

        bool downTILT1 = false;

        int O1H = 0;
        double proj1H = double.NaN;

        string prevA1H = null;
        string prevB1H = null;
        int chkA1H = 0;
        int chkB1H = 0;

        int CHNcount1H = 0;
        string DRWchn1H = null;

        private DateTime _lastBarOpenTime1H;

        private bool isSell1 = false;

        double d = double.NaN;

        int N = 1;


        protected internal void projDETECTOR_1H(int index, int highA1, int highB1, bool pingORDER_1H)
        {
            {

                //////////////////////////////////////////
                /////   FIX SUPPORT POINTS A and B   /////
                //////////////////////////////////////////

                chkA1H = Convert.ToInt16(prevA1H);
                chkB1H = Convert.ToInt16(prevB1H);


                //////////////////////////////////////////
                ////////        NEW CHANNEL       ////////
                //////////////////////////////////////////

                if (pingORDER_1H == true)
                    if (highA1 > chkA1H)
                        if (highB1 > chkB1H)
                        {
                            NXTchan1H = true;
                            proj1H = 0;
                            O1H = 0;
                        }


                //////////////////////////////////////////
                ////////       DEFINE CHANNEL     ////////
                //////////////////////////////////////////


                if (pingORDER_1H == true)
                    if (NXTchan1H == true)
                    {
                        HA1 = Bars.HighPrices[highA1];
                        HB1 = Bars.HighPrices[highB1];

                        R1H = highA1;
                        S1H = highB1;

                        prevA1H = Convert.ToString(highA1);
                        prevB1H = Convert.ToString(highB1);

                        Gradient1H = (HB1 - HA1) / (S1H - R1H);

                        prevGRAD1H = Gradient1H;
                    }


                lastGRAD1H = prevGRAD1H;


                if (chklastGRAD1H <= lastGRAD1H)
                {
                    lastGRAD1H = chklastGRAD1H;
                }


                if (Gradient1H < 0)
                    if (Gradient1H <= lastGRAD1H)
                    {
                        downTILT1 = true;
                    }


                if (Gradient1H > lastGRAD1H)
                {
                    downTILT1 = false;
                }


                //////////////////////////////////////////////
                ////////        CONSTRUCT CHANNEL     ////////
                //////////////////////////////////////////////


                if (downTILT1 == true)
                {
                    CHNcount1H += 1;

                    DRWchn1H = "highChannel_1 " + CHNcount1H;
                    Chart.DrawTrendLine(DRWchn1H, R1H, HA1, S1H, HB1, Color.MediumSlateBlue);

                    O1H += 1;
                    proj1H = ((Gradient1H * (O1H - 1)) + HB1);
                    lineDARKred[index - 2] = proj1H;
                }


                //////////////////////////////////////////
                //////////////////////////////////////////
                //////////////////////////////////////////
                //////////////////////////////////////////
                //////////////////////////////////////////
                //////////////////////////////////////////
                //////////////////////////////////////////
                ////////        INT RETRACERS     ////////
                //////////////////////////////////////////
                //////////////////////////////////////////
                //////////////////////////////////////////
                //////////////////////////////////////////
                //////////////////////////////////////////
                //////////////////////////////////////////
                //////////////////////////////////////////

                int sellRETR = 0;
                int liqRETR = 0;




                /////////////////////////////////////////////////
                ////////       SIGNAL - ONCE ON BAR      ////////
                /////////////////////////////////////////////////


                if (Bars.OpenTimes[index] != _lastBarOpenTime1H)
                {
                    _lastBarOpenTime1H = Bars.OpenTimes[index];

                    if (!double.IsNaN(sell_ONE.Last(sellRETR)))
                    {
                        isSell1 = true;
                    }


                    if (!double.IsNaN(liq_sellONE.Last(sellRETR)))
                    {
                        isSell1 = false;
                    }
                }


                //////////////////////////////////////////
                ////////        NaN - SIGNAL      ////////
                //////////////////////////////////////////

                if (high == 0)
                {
                    sell_ONE[index - 0] = d;
                }

                if (high == 0)
                {
                    liq_sellONE[index - 0] = d;
                }





                //////////////////////////////////////////
                ////////       SELL - SIGNAL      ////////
                //////////////////////////////////////////

                if (!isSell1)
                    if (downTILT1 == true)
                    {
                        sell_ONE[index - sellRETR] = Bars.HighPrices[index - sellRETR];
                        Print("   INDICATOR SELL    ", index, "       ", sell_ONE, "       ", sell_ONE.Last(sellRETR));

                    }



                ///////////////////////////////////////////////
                ////////       CLOSE TRADE SIGNAL      ////////
                ///////////////////////////////////////////////

                var opencncl_1H = Bars.OpenPrices[index - 0];
                var closecncl_1H = Bars.ClosePrices[index - 0];

                if (isSell1)
                    if (proj1H > 0)
                        if (opencncl_1H < closecncl_1H)
                            if (closecncl_1H > proj1H)
                            {
                                liq_sellONE[index - liqRETR] = Bars.HighPrices[index - liqRETR];
                                Print("   INDICATOR LIQ    ", index, "         ", liq_sellONE, "     ", liq_sellONE.Last(liqRETR));


                                R1H = 0;
                                S1H = 0;
                                HA1 = 0;
                                HB1 = 0;

                                O1H = 0;
                                proj1H = 0;
                                Gradient1H = 0;

                                NXTchan1H = false;

                                downTILT1 = false;


                            }




            }
        }
    }
}





BOT 

 

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class SELL_LIQ_LIVEtest_forum : Robot
    {

        ////////////////////////////////////
        /////   TRADING PARAMETERS    //////
        ////////////////////////////////////

        [Parameter("Volume", DefaultValue = 1000)]
        public int Volume { get; set; }

        [Parameter("StopLoss", DefaultValue = 50)]
        public int StopLoss { get; set; }

        [Parameter("LIMIT", DefaultValue = 200)]
        public int LIMIT { get; set; }


        ////////////////////////////////////
        /////    SIGNAL PARAMETERS    //////
        ////////////////////////////////////


        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter("BandPeriods", DefaultValue = 16)]
        public int BandPeriod { get; set; }

        [Parameter("Std", DefaultValue = 1.6)]
        public double std { get; set; }

        [Parameter("MAType")]
        public MovingAverageType MAType { get; set; }

        [Parameter(DefaultValue = 100, MinValue = 50)]
        public int Period { get; set; }

        [Parameter("littFACTOR", DefaultValue = 1)]
        public double littFACTOR { get; set; }

        [Parameter("thresherValue", DefaultValue = 4)]
        public double thresherValue { get; set; }

        [Parameter("lastINDEX", DefaultValue = 1600)]
        public int lastINDEX { get; set; }

        [Parameter("zeroINDEX", DefaultValue = 1200)]
        public int zeroINDEX { get; set; }


        ////////////////////////////////////
        /////    OUTPUT PARAMETERS    //////
        ////////////////////////////////////

        [Output("sell_ONE", PlotType = PlotType.Points, LineColor = "#B511F7", Thickness = 4)]
        public IndicatorDataSeries sell_ONE { get; set; }

        [Output("liq_sellONE", PlotType = PlotType.Points, LineColor = "#FF7CFC00", Thickness = 4)]
        public IndicatorDataSeries liq_sellONE { get; set; }

        private COMPOSITEliveTEST_BBc_RED S2;

        protected override void OnStart()
        {
            S2 = Indicators.GetIndicator<COMPOSITEliveTEST_BBc_RED>(Source, BandPeriod, std, MAType, Period, littFACTOR, thresherValue, lastINDEX, zeroINDEX);
        }

        int S = 0;
        int L = 0;

        int m = 0;
        int n = 0;
        protected override void OnBar()
        {

            var a = S2.sell_ONE.Last(S);

            var bMIN1 = S2.liq_sellONE.Last(-1);
            var b0 = S2.liq_sellONE.Last(0);
            var b1 = S2.liq_sellONE.Last(1);
            var b2 = S2.liq_sellONE.Last(2);
            var b3 = S2.liq_sellONE.Last(3);


            Print(bMIN1, "    ", b0, "    ", b1, "    ", b2, "    ", b3);




            if (!double.IsNaN(S2.sell_ONE.Last(S)) == true)
            {
                m += 1;
                string POS = "POSITION  " + m;

                ExecuteMarketOrder(TradeType.Sell, Symbol.Name, 1000, POS, StopLoss, LIMIT);

                //     Print("ROBOT SELL    ", Bars.Count, "      ", S2.sell_ONE.Last(0), "    ", POS);

            }


            if (!double.IsNaN(S2.liq_sellONE.Last(L)) == true)
                foreach (var POS in Positions)
                {

                    n += 1;
                    string LIQ = "liquid no " + n;

                    ClosePosition(POS);
                    //    Print("ROBOT  LIQ    ", Bars.Count, "      ", S2.liq_sellONE.Last(0), "    ", LIQ);
                }

        }
    }
}

 

Sincerely, 

 

Björn Bernau 

 

 

 

 


@BJORNBERNAU
Replies

amusleh
15 Mar 2022, 09:26

Hi,

First of all there is a button on editor for posting code, please use it next time!

Your indicator is not consistent with it's output, if you give the same data twice it will return different outputs each time.

You are using OnBar method of cBot, and you are using Last value of indicator outputs, which are not complete and it will always return NAN inside OnBar.

Here are some recommendation for you:

  • If you have time and interest to continue writing C# code, then stop developing cBots/Indicators and instead put some time to learn C# and .NET basics, there are a ton of materials available for free on internet that you can use
  • In case you don't have time or the interest, you can contact one of our consultant companies or post a job request
  • Start small, if you copy some piece of code from one place and another from another place and put it inside a cTrader indicator it will not work
  • When asking help or support, be specific, you can't post 100s of lines of code and ask us to find the issue for you

 


@amusleh

BJORNBERNAU
15 Mar 2022, 09:41

RE:

amusleh said:

Hi,

First of all there is a button on editor for posting code, please use it next time!

Your indicator is not consistent with it's output, if you give the same data twice it will return different outputs each time.

You are using OnBar method of cBot, and you are using Last value of indicator outputs, which are not complete and it will always return NAN inside OnBar.

Here are some recommendation for you:

  • If you have time and interest to continue writing C# code, then stop developing cBots/Indicators and instead put some time to learn C# and .NET basics, there are a ton of materials available for free on internet that you can use
  • In case you don't have time or the interest, you can contact one of our consultant companies or post a job request
  • Start small, if you copy some piece of code from one place and another from another place and put it inside a cTrader indicator it will not work
  • When asking help or support, be specific, you can't post 100s of lines of code and ask us to find the issue for you

 

Thank you. 

Where is this posting button? I have a 'submit' button. 

Where do you explain in your manuals, that OnBar, is not in the use with Last value are not compatible? 

Panagiotis gave me this code blow, using OnBar and Last values for indicator and cbot. Amongst others some of you suggested that it was a case of lazy loading, which then was refuted by Panagiotis.

In my post I specifically ask for why the signals, in the indicator code, are not transferred to the cbot? Which is written on the forum “I don't get why the signals are not transferred from this IND to the following BOT. Trying to evoke the signal to 'overrun' any misses in the signals by a …

//Björn 

Panagiotis code found here 

https://ctrader.com/forum/cbot-support/37684?page=1#post-2

 


@BJORNBERNAU

amusleh
15 Mar 2022, 09:46

Hi,

The code post button:

Regarding OnBar issue, it depends on your indicator code, OnBar is called whenever a new bar opens, and access LastValue of your indicator means that you are trying to get the indicator output for newly created bar, which most probably will be NAN.

Test your indicator on cTrader Visual back test mode, you will see that your indicator only works properly for historical bars, not for newly created bars.


@amusleh

BJORNBERNAU
15 Mar 2022, 09:51 ( Updated at: 21 Dec 2023, 09:22 )

RE:

amusleh said:

Hi,

The code post button:

Regarding OnBar issue, it depends on your indicator code, OnBar is called whenever a new bar opens, and access LastValue of your indicator means that you are trying to get the indicator output for newly created bar, which most probably will be NAN.

Test your indicator on cTrader Visual back test mode, you will see that your indicator only works properly for historical bars, not for newly created bars.

 

Okay, so how can I access historical data with the onBar method in cBot? 


@BJORNBERNAU

amusleh
15 Mar 2022, 10:41 ( Updated at: 21 Dec 2023, 09:22 )

RE: RE:

BJORNBERNAU said:

amusleh said:

Hi,

The code post button:

Regarding OnBar issue, it depends on your indicator code, OnBar is called whenever a new bar opens, and access LastValue of your indicator means that you are trying to get the indicator output for newly created bar, which most probably will be NAN.

Test your indicator on cTrader Visual back test mode, you will see that your indicator only works properly for historical bars, not for newly created bars.

 

Okay, so how can I access historical data with the onBar method in cBot? 

Hi,

You can use any value of your indicator outputs inside OnBar, if you want to use historical values just pass the index of value to output Last method or with [].

The issue is not the cBot or OnBar, the issue is your indicator, fix your indicator first and then use it on a cBot.


@amusleh

BJORNBERNAU
15 Mar 2022, 11:12 ( Updated at: 21 Dec 2023, 09:22 )

RE: RE: RE:

amusleh said:

BJORNBERNAU said:

amusleh said:

Hi,

The code post button:

Regarding OnBar issue, it depends on your indicator code, OnBar is called whenever a new bar opens, and access LastValue of your indicator means that you are trying to get the indicator output for newly created bar, which most probably will be NAN.

Test your indicator on cTrader Visual back test mode, you will see that your indicator only works properly for historical bars, not for newly created bars.

 

Okay, so how can I access historical data with the onBar method in cBot? 

Hi,

You can use any value of your indicator outputs inside OnBar, if you want to use historical values just pass the index of value to output Last method or with [].

The issue is not the cBot or OnBar, the issue if your indicator, fix your indicator first and then use it on a cBot.

 

Hi

 

I really cannot see the problem with the Indicator.

It produces a perfect array of alternating sell and buy signal.

Using different indices for the Last bar just delays the signal to the cBot.

There is now only one sell and liquidation signal relayed to cBot, then it arrests.

Why does cBot not receive the following signals?

 

Here’s the code.

 

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class COMPOSITEliveTEST_BBc_RED : Indicator
    {


        /////////////////////////////////////////////
        /////////////////////////////////////////////
        /////////////////////////////////////////////
        /////////////////////////////////////////////
        /////////////////////////////////////////////

        //////////////   22-03-15   /////////////////

        /////////////////////////////////////////////
        /////////////////////////////////////////////
        /////////////////////////////////////////////
        /////////////////////////////////////////////
        /////////////////////////////////////////////

        [Output("lineDARKred", PlotType = PlotType.DiscontinuousLine, LineColor = "#FF800001", Thickness = 1)]
        public IndicatorDataSeries lineDARKred { get; set; }


        ////   BOLLINGER    //// 



        //////////////////////////////
        ////       PARAMETERS      //// 

        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter("BandPeriods", DefaultValue = 16)]
        public int BandPeriod { get; set; }

        [Parameter("Std", DefaultValue = 1.6)]
        public double std { get; set; }

        [Parameter("MAType")]
        public MovingAverageType MAType { get; set; }

        [Parameter(DefaultValue = 100, MinValue = 50)]
        public int Period { get; set; }


        [Parameter("littFACTOR", DefaultValue = 1)]
        public double littFACTOR { get; set; }

        [Parameter("thresherValue", DefaultValue = 4)]
        public double thresherValue { get; set; }


        [Parameter("lastINDEX", DefaultValue = 4280)]
        public int lastINDEX { get; set; }

        [Parameter("zeroINDEX", DefaultValue = 2000)]
        public int zeroINDEX { get; set; }


        [Output("sell_ONE", PlotType = PlotType.Points, LineColor = "#FF7CFC00", Thickness = 4)]
        public IndicatorDataSeries sell_ONE { get; set; }

        [Output("liq_sellONE", PlotType = PlotType.Points, LineColor = "#B511F7", Thickness = 4)]
        public IndicatorDataSeries liq_sellONE { get; set; }



        private BollingerBands boll;

        protected override void Initialize()
        {
            boll = Indicators.BollingerBands(Source, BandPeriod, std, MAType);
        }


        int high = 0;
        int highCOUNTER_A = 0;
        int highCOUNTER_B = 0;

        int HIGHstartCountIndexZERO = 0;

        int retrace = 2;


        public override void Calculate(int index)
        {
            highMARKET(index, high, highCOUNTER_A, highCOUNTER_B);
        }


        protected internal void highMARKET(int index, int high, int highCOUNTER_A, int highCOUNTER_B)
        {
            high = 0;

            double high0 = Bars.HighPrices[index - 0];
            double high1 = Bars.HighPrices[index - 1];
            double high2 = Bars.HighPrices[index - 2];
            double high3 = Bars.HighPrices[index - 3];
            double high4 = Bars.HighPrices[index - 4];
            double close0 = Bars.ClosePrices[index - 0];

            var BBT1 = boll.Top[index - 1];
            var BBT2 = boll.Top[index - 2];
            var BBM1 = boll.Main[index - 1];


            if (high4 <= high2)
                if (high3 <= high2)
                    if (high2 > BBT2)
                        if (high2 >= high1)
                            if (high2 >= close0)
                            {
                                high = 1;
                            }


            if (high == 1)
            {
                HIGHstartCountIndexZERO += 1;
            }


            {
                if (high == 1)
                    if (HIGHstartCountIndexZERO % 2 != 0)
                    {
                        highCOUNTER_A = 1;
                    }



                if (high == 1)
                    if (HIGHstartCountIndexZERO % 2 == 0)
                    {
                        highCOUNTER_B = 1;
                    }

            }

            HIGHprimaryINDEX(index, high, highCOUNTER_A, highCOUNTER_B);
        }


        int highA1 = 0;
        int highB1 = 0;

        double initHA1 = 0;
        double initHB1 = 0;
        bool pingORDER_1H = false;

        protected internal void HIGHprimaryINDEX(int index, int high, int highCOUNTER_A, int highCOUNTER_B)
        {
            {

                ////   INITIATION SIGNALS   ////


                if (highCOUNTER_A == 1)
                {
                    highA1 = index - retrace;
                }

                if (highCOUNTER_B == 1)
                {
                    highB1 = index - retrace;
                }

                initHA1 = Bars.HighPrices[highA1];
                initHB1 = Bars.HighPrices[highB1];

                if (highA1 > highB1)
                {
                    pingORDER_1H = false;
                }

                if (highA1 < highB1)
                    if (initHA1 > initHB1)
                    {
                        pingORDER_1H = true;
                    }
                //
                //
                projDETECTOR_1H(index, highA1, highB1, pingORDER_1H);
            }
        }


        //////////////////////////////////////////
        //////////////////////////////////////////
        //////////////////////////////////////////
        //////////////////////////////////////////
        //////////////////////////////////////////
        //////////////////////////////////////////
        //////////////////////////////////////////




        //  bool highchannel1 = false;
        bool NXTchan1H = false;
        double Gradient1H = 0;
        double prevGRAD1H = 0;
        double lastGRAD1H = 0;
        double chklastGRAD1H = 0;


        int R1H = 0;
        int S1H = 0;
        double HA1 = 0;
        double HB1 = 0;

        bool downTILT1 = false;

        int O1H = 0;
        double proj1H = double.NaN;

        string prevA1H = null;
        string prevB1H = null;
        int chkA1H = 0;
        int chkB1H = 0;

        int CHNcount1H = 0;
        string DRWchn1H = null;

        private DateTime _lastBarOpenTime1H;

        private bool isSell1 = false;

        double d = double.NaN;

        //   int N = 1;


        protected internal void projDETECTOR_1H(int index, int highA1, int highB1, bool pingORDER_1H)
        {
            {

                //////////////////////////////////////////
                /////   FIX SUPPORT POINTS A and B   /////
                //////////////////////////////////////////

                chkA1H = Convert.ToInt16(prevA1H);
                chkB1H = Convert.ToInt16(prevB1H);


                //////////////////////////////////////////
                ////////        NEW CHANNEL       ////////
                //////////////////////////////////////////

                if (pingORDER_1H == true)
                    if (highA1 > chkA1H)
                        if (highB1 > chkB1H)
                        {
                            NXTchan1H = true;
                            proj1H = 0;
                            O1H = 0;
                        }


                //////////////////////////////////////////
                ////////       DEFINE CHANNEL     ////////
                //////////////////////////////////////////


                if (pingORDER_1H == true)
                    if (NXTchan1H == true)
                    {
                        HA1 = Bars.HighPrices[highA1];
                        HB1 = Bars.HighPrices[highB1];

                        R1H = highA1;
                        S1H = highB1;

                        prevA1H = Convert.ToString(highA1);
                        prevB1H = Convert.ToString(highB1);

                        Gradient1H = (HB1 - HA1) / (S1H - R1H);

                        prevGRAD1H = Gradient1H;
                    }


                lastGRAD1H = prevGRAD1H;


                if (chklastGRAD1H <= lastGRAD1H)
                {
                    lastGRAD1H = chklastGRAD1H;
                }


                if (Gradient1H < 0)
                    if (Gradient1H <= lastGRAD1H)
                    {
                        downTILT1 = true;
                    }


                if (Gradient1H > lastGRAD1H)
                {
                    downTILT1 = false;
                }


                //////////////////////////////////////////////
                ////////        CONSTRUCT CHANNEL     ////////
                //////////////////////////////////////////////


                if (downTILT1 == true)
                {
                    CHNcount1H += 1;

                    DRWchn1H = "highChannel_1 " + CHNcount1H;
                    Chart.DrawTrendLine(DRWchn1H, R1H, HA1, S1H, HB1, Color.MediumSlateBlue);

                    O1H += 1;
                    proj1H = ((Gradient1H * (O1H - 1)) + HB1);
                    lineDARKred[index - 2] = proj1H;
                }


                //////////////////////////////////////////
                //////////////////////////////////////////
                //////////////////////////////////////////
                //////////////////////////////////////////
                //////////////////////////////////////////
                //////////////////////////////////////////
                //////////////////////////////////////////
                ////////        INT RETRACERS     ////////
                //////////////////////////////////////////
                //////////////////////////////////////////
                //////////////////////////////////////////
                //////////////////////////////////////////
                //////////////////////////////////////////
                //////////////////////////////////////////
                //////////////////////////////////////////

                int sellRETR = 2;
                int liqRETR = 1;




                /////////////////////////////////////////////////
                ////////       SIGNAL - ONCE ON BAR      ////////
                /////////////////////////////////////////////////


                if (Bars.OpenTimes[index] != _lastBarOpenTime1H)
                {
                    _lastBarOpenTime1H = Bars.OpenTimes[index];

                    if (!double.IsNaN(sell_ONE.Last(sellRETR)))
                    {
                        isSell1 = true;
                    }


                    if (!double.IsNaN(liq_sellONE.Last(sellRETR)))
                    {
                        isSell1 = false;
                    }
                }


                //////////////////////////////////////////
                ////////        NaN - SIGNAL      ////////
                //////////////////////////////////////////

                if (high == 0)
                {
                    sell_ONE[index - 0] = d;
                }

                if (high == 0)
                {
                    liq_sellONE[index - 0] = d;
                }





                //////////////////////////////////////////
                ////////       SELL - SIGNAL      ////////
                //////////////////////////////////////////

                if (!isSell1)
                    if (downTILT1 == true)
                    {
                        sell_ONE[index - sellRETR] = Bars.HighPrices[index - sellRETR];
                        Print("    SELL    ", index, "       ", sell_ONE, "       ", sell_ONE.Last(sellRETR));

                    }



                ///////////////////////////////////////////////
                ////////       CLOSE TRADE SIGNAL      ////////
                ///////////////////////////////////////////////

                var opencncl_1H = Bars.OpenPrices[index - 0];
                var closecncl_1H = Bars.ClosePrices[index - 0];

                if (isSell1)
                    if (proj1H > 0)
                        if (opencncl_1H < closecncl_1H)
                            if (closecncl_1H > proj1H)
                            {
                                liq_sellONE[index - liqRETR] = Bars.HighPrices[index - liqRETR];
                                Print("    LIQ    ", index, "         ", liq_sellONE, "     ", liq_sellONE.Last(liqRETR));


                                R1H = 0;
                                S1H = 0;
                                HA1 = 0;
                                HB1 = 0;

                                O1H = 0;
                                proj1H = 0;
                                Gradient1H = 0;

                                NXTchan1H = false;

                                downTILT1 = false;


                            }




            }
        }
    }
}





using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class SELL_LIQ_LIVEtest_BBC_RED : Robot
    {

        ////////////////////////////////////
        /////   TRADING PARAMETERS    //////
        ////////////////////////////////////

        [Parameter("Volume", DefaultValue = 1000)]
        public int Volume { get; set; }

        [Parameter("StopLoss", DefaultValue = 50)]
        public int StopLoss { get; set; }

        [Parameter("LIMIT", DefaultValue = 200)]
        public int LIMIT { get; set; }


        ////////////////////////////////////
        /////    SIGNAL PARAMETERS    //////
        ////////////////////////////////////


        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter("BandPeriods", DefaultValue = 16)]
        public int BandPeriod { get; set; }

        [Parameter("Std", DefaultValue = 1.6)]
        public double std { get; set; }

        [Parameter("MAType")]
        public MovingAverageType MAType { get; set; }

        [Parameter(DefaultValue = 100, MinValue = 50)]
        public int Period { get; set; }

        [Parameter("littFACTOR", DefaultValue = 1)]
        public double littFACTOR { get; set; }

        [Parameter("thresherValue", DefaultValue = 4)]
        public double thresherValue { get; set; }

        [Parameter("lastINDEX", DefaultValue = 1600)]
        public int lastINDEX { get; set; }

        [Parameter("zeroINDEX", DefaultValue = 1200)]
        public int zeroINDEX { get; set; }


        ////////////////////////////////////
        /////    OUTPUT PARAMETERS    //////
        ////////////////////////////////////

        [Output("sell_ONE", PlotType = PlotType.Points, LineColor = "#B511F7", Thickness = 4)]
        public IndicatorDataSeries sell_ONE { get; set; }

        [Output("liq_sellONE", PlotType = PlotType.Points, LineColor = "#FF7CFC00", Thickness = 4)]
        public IndicatorDataSeries liq_sellONE { get; set; }


        private COMPOSITEliveTEST_BBc_RED S2;

        protected override void OnStart()
        {
            S2 = Indicators.GetIndicator<COMPOSITEliveTEST_BBc_RED>(Source, BandPeriod, std, MAType, Period, littFACTOR, thresherValue, lastINDEX, zeroINDEX);
        }

        //    double d = double.NaN;

        int S = 2;
        int L = 2;

        int m = 0;
        int n = 0;
        protected override void OnBar()
        {

            var a = S2.sell_ONE.Last(S);
            var bMIN1 = S2.liq_sellONE.Last(-1);
            var b0 = S2.liq_sellONE.Last(0);
            var b1 = S2.liq_sellONE.Last(1);
            var b2 = S2.liq_sellONE.Last(2);
            var b3 = S2.liq_sellONE.Last(3);


            //   Print(Bars.Count, "    ", a, "    ", b1, "    ", b2, "    ", b3);


            if (!double.IsNaN(S2.sell_ONE.Last(S)) == true)
            {
                Print(Bars.Count, "   sell   ", a, "    ", b1, "    ", b2, "    ", b3);
                //     Print("    SELL    ", Bars.Count, "     ", S2.sell_ONE.Last(S));
            }

            if (!double.IsNaN(S2.liq_sellONE.Last(L)) == true)
            {
                Print(Bars.Count, "   liq   ", a, "    ", b1, "    ", b2, "    ", b3);
                //         Print("    LIQ     ", Bars.Count, "     ", S2.liq_sellONE.Last(1));
            }


            if (!double.IsNaN(S2.sell_ONE.Last(S)) == true)
            {
                m += 1;
                string POS = "POSITION  " + m;

                ExecuteMarketOrder(TradeType.Sell, Symbol.Name, 1000, POS, StopLoss, LIMIT);

                //    Print("ROBOT SELL    ", Bars.Count, "      ", S2.sell_ONE, "    ", POS);

            }


            if (!double.IsNaN(S2.liq_sellONE.Last(L)) == true)
                foreach (var POS in Positions)
                {

                    n += 1;
                    string LIQ = "liquid no " + n;

                    ClosePosition(POS);
                }

        }
    }
}



 


@BJORNBERNAU

PanagiotisCharalampous
15 Mar 2022, 11:36

Hi Bjorn,

Unfortunalely we cannot help you any further with your issue. We spent many hours in the past, pointing out coding inefficiencies in your programing and basic coding mistakes that are not related with the platform but to poor coding skills. The purpose of the community is to help you with technical questions related to the API and the platform. We cannot review hundreds of lines of code to find your mistakes and bugs or program your indicators. Especially when the code is a mess and does not adhere to any professional standard. If you feel that this is beyond your capabilities, I strongly advise you to hire a consultant. 

If you have a specific question about the inner workings of the platform and the API, feel free to ask specific questions and we will provide you with an explanation on how things work alongside with code examples wherever necessary. If you need an example on how to implement a specific scenario, we can also help. If you think something is not working as expected, please provide a short example code that demonstrates the problem and we will investigate. However we cannot fix your project's logic.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous