Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Builder two instruments not work always

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Strategy Builder two instruments not work always

    Please i have a problem with my strategy. I dont know but in the behavior is irregular, not active always, sometimes stay in wait until flat.

    I try buy and sell ES 09-20 with indicators of the SPY (days and minutes)

    I think something in my code is wrong, please some advice on my error is appreciated. I use the strategy builder.

    }
    else if (State == State.Configure)
    {
    AddDataSeries("SPY", Data.BarsPeriodType.Day, 1, Data.MarketDataType.Last);
    AddDataSeries("SPY", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last);
    }
    else if (State == State.DataLoaded)
    {
    EMA1 = EMA(Closes[2], Convert.ToInt32(Emaperiod));
    RSI1 = RSI(Closes[1], 14, 3);
    ADX1 = ADX(Closes[2], Convert.ToInt32(ADXperiod1));
    SetProfitTarget("", CalculationMode.Percent, Profit1);
    SetStopLoss("", CalculationMode.Percent, Loss1, false);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1
    || CurrentBars[1] < 0
    || CurrentBars[2] < 1)
    return;

    // Set 1
    if ((CrossAbove(Closes[2], EMA1, 1))
    && (Times[0][0].TimeOfDay >= Timeopen.TimeOfDay)
    && (Times[0][0].TimeOfDay <= Timeclose.TimeOfDay)
    && (RSI1.Default[0] < RSIshort1)
    && (ADX1[0] < ADXup1))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }

    Regards

    #2
    Hello walter739,

    Thanks for the post.

    I see you mentioned wait until flat, the yellow state would be normal with that start behavior if your strategy entered a historical position but did not exit it before entering realtime. Your script processes the historical data when you enable it so its possible to wait to start. If your stoploss was waiting to be hit it would wait until flat.

    If you want it to only work in realtime you could add a State check to your condition to check if the state is realtime.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse thanks for answer, sorry i not explain well.

      My strategy is buy and sell ES 09-20 with all conditions and indicators of the SPY (days and minutes)

      But for some reason when the condition apply in the SPY, dont work in my strategy with ES. stay in wait until flat or activate one bar forward. Other times in the day work well, .

      The same strategy only with buy and sell SPY work correclty all day.

      I annex my Strategy parameters, i dont know is this affect:

      -Trading hours :US RTH equities ( i need this for EMA, all day in ES is different to SPY)
      -Bars requerid to trade: 47700 ( I need this for the RSI SPY daily, if i have less bars in minutes the RSI is not correct)
      -Maybe the code in strategy builder is not correct. I use the strategy builder


      Please if you can help me to find my error, i appreciated.

      Regards
      Attached Files

      Comment


        #4
        Hello walter739,

        If the strategy is waiting until flat that is specifically caused with WaitUntilFlat being the start behavior. That would be because it placed a historical order and it is waiting to exit that order. Did you intend for the strategy to work only in realtime as soon as you enable it?

        The picture you provided is not using WaitUntilFlat so I am unsure how that would be related. Are you seeing that the strategy is yellow after enabling it?

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello Jesse:

          Did you intend for the strategy to work only in realtime as soon as you enable it? I intend the strategy wait until flat, but when conditions in SPY are correct, begin in real time. That not happens in my stretegy with ES, only sometimes.. I dont understand why.

          The picture you provided is not using WaitUntilFlat so I am unsure how that would be related. Sorry only i wish you see this paramethers. I always use wait until flat.
          -Trading hours :US RTH equities ( i need this for EMA, all day in ES is different to SPY)
          -Bars requerid to trade: 47700 ( I need this for the RSI SPY daily, if i have less bars in minutes the RSI is not correct)

          Maybe this paramethers affect my strategy and i dont see how.

          I wish trade ES with conditions of the SPY, but only work sometimes, i have wrong something in my strategy.

          Regards


          Comment


            #6
            Hello walter739,


            I intend the strategy wait until flat, but when conditions in SPY are correct, begin in real time.
            These are conflicting ways to start. If you use historical data and wait until flat there is a chance the strategy will enter a historical position and then it will not start live. It will wait to exit that position and then start live after that. If the intention is to start immediately in live when you enable it you could use other start behaviors like immediately submit as you have selected. That also would generally entail your strategy either does not execute historical trades or if it does then it works with the start behavior being used so you can start in realtime. You generally need to read the start behavior descriptions to pair it with your strategy logic to see what would work best with what you made.
            https://ninjatrader.com/support/help...hlightsub=sync

            The picture you provided is not using WaitUntilFlat so I am unsure how that would be related. Sorry only i wish you see this parameters. I always use wait until flat.
            Thanks for clarifying that, in the future please take the screenshot with the settings you used to avoid any confusion.


            -Trading hours :US RTH equities ( i need this for EMA, all day in ES is different to SPY)
            -Bars required to trade: 47700 ( I need this for the RSI SPY daily, if i have less bars in minutes the RSI is not correct)
            These items are not necessarily relevant here. The amount of data will control the amount of times the straetgy can trade historically when you apply it, outside of that this does not affect the start behaviors.


            I look forward to being of further assistance.


            JesseNinjaTrader Customer Service

            Comment


              #7
              Helle Jesse thanks for answer.

              I have two strategys with same conditions.and both start wait until flat.

              The 1 strategy in SPY work good all day

              The 2 strategy in ES with conditions SPY not work fine, some times no entry the orders or entry one bar late.

              The 2 strategy when fail and not entry, i uncheck and check again int he control center and the position change and write the correct price of entry in past.

              For some reason not entry in the correct moment.

              Please help me with that error, maybe i this cannot work with that conditions in strategy builder.


              Regards


              Comment


                #8
                Hello walter739,

                It sounds like the problem is that the logic is working differently in realtime or that what you are comparing against is different. Are you using AddChartIndicator from the strategy to add the indicators it used or are you comparing manually applied indicators? That may be one area where you can see a difference. Otherwise it sounds like the strategy evaluated differently in realtime than historical, to know why you would need to debug the strategy to find what value was different for the condition to change.

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Hello Jesse, I build my strategy in builder, i write my strategy 2 unlocked in the first post, but i dont see AddChartindicator, do you think this can be the problem?

                  I run strategys in playback mode and work fine boths. But i dont find why reason the strategy 2 not work good in real time.


                  Regards

                  Comment


                    #10
                    Hello walter739,

                    If you are using the builder you can check the "Plot on chart" option when configuring the indicator in your conditions, that will automatically add the AddChartIndicator. It sounds like you are doing a manually added indicator comparison here so making sure the strategy instead adds its own indicator would be a good starting point.

                    You can see an example of adding an indicator in the help guide, I would suggest just make a simple condition in the builder and enable plot on chart, then click View Code. That will be a little more complete and easier to see what was added. https://ninjatrader.com/support/help...htsub=addchart

                    I look forward to being of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Hello Jesse, i cannot enable plot on chart in 2 Strategy ExitES. i think because have two instruments.

                      I annex both strategys, please help me why reason the Strategy ExitES entry in the position one bar late, it is the most frequently error. In the strategy ExitSPY entry in the right moment always. Both strategys have the same conditions in reference to SPY.

                      Regards
                      Attached Files

                      Comment


                        #12
                        Hello walter739,

                        Yes for the ExitES that uses multiple series so you would not be able to plot the indicators on the chart. You could instead use a set with a Print to output the indicator value to confirm when it becomes true or not. Comparing against a manually added indicator can have differences so it may not truly represent what the strategy is doing. The other strategy is using AddChartIndicator so that would represent what the strategy is seeing.

                        I look forward to being of further assistance.



                        JesseNinjaTrader Customer Service

                        Comment


                          #13
                          Hello Jesse, i add Print to see the ouput, and open one chart with SPY and ES 0920 below, Add both strategies to each symbol, and work perfect both, the ouput is the same in boths strategys. The same quantity of buy and sell in 200 days. All this in historical.

                          I dont understand why in real time the ExitES is late one bar sometimes.

                          I annex two strategys with Print command, you can see both work same bar in historical..

                          Please what is wrong in my code?

                          Regards
                          Attached Files

                          Comment


                            #14
                            Hello Jesse

                            This code work fine in realt time with SPY

                            }
                            else if (State == State.Configure)
                            {
                            AddDataSeries(Data.BarsPeriodType.Day, 1);
                            }
                            else if (State == State.DataLoaded)
                            {
                            EMA1 = EMA(Close, Convert.ToInt32(Emaperiod1));
                            RSI1 = RSI(Closes[1], 14, 3);
                            ADX1 = ADX(Close, Convert.ToInt32(ADXperiod1));
                            EMA1.Plots[0].Brush = Brushes.Goldenrod;
                            ADX1.Plots[0].Brush = Brushes.DarkCyan;
                            AddChartIndicator(EMA1);
                            AddChartIndicator(ADX1);
                            SetProfitTarget(@"long1", CalculationMode.Percent, Profit1);
                            SetStopLoss(@"long1", CalculationMode.Percent, Loss1, false);
                            SetProfitTarget(@"long2", CalculationMode.Currency, Profit1);
                            SetStopLoss(@"long2", CalculationMode.Percent, Loss1, false);
                            SetProfitTarget(@"short1", CalculationMode.Percent, Profit1);
                            SetStopLoss(@"short1", CalculationMode.Percent, Loss1, false);
                            }
                            }

                            protected override void OnBarUpdate()
                            {
                            if (BarsInProgress != 0)
                            return;

                            if (CurrentBars[0] < 1
                            || CurrentBars[1] < 1)
                            return;

                            // Set 1
                            if ((CrossAbove(Close, EMA1, 1))
                            && (Times[0][0].TimeOfDay >= Timeopen.TimeOfDay)
                            && (Times[0][0].TimeOfDay <= Timeclose.TimeOfDay)
                            && (RSI1.Default[0] < RSIshort1)
                            && (ADX1[0] < Adxup))
                            {
                            EnterLong(Convert.ToInt32(DefaultQuantity), @"long1");
                            Print(Convert.ToString(Times[0][0]) + @" ADX " + Convert.ToString(ADX1[0]) + @" RSI " + Convert.ToString(RSI1.Avg[0]) + @" EMA " + Convert.ToString(EMA1[0]) + @" Price " + Convert.ToString(Close[0]) + " " + Convert.ToString(Position.MarketPosition));
                            }




                            And this code work fine in market replay and historical, but not in real time Is the same but i use to entry in ES with conditions of SPY, in real time entry one bar late. Please do you see my mistake in the code.

                            }
                            else if (State == State.Configure)
                            {
                            AddDataSeries("SPY", Data.BarsPeriodType.Day, 1, Data.MarketDataType.Last);
                            AddDataSeries("SPY", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last);
                            }
                            else if (State == State.DataLoaded)
                            {
                            EMA1 = EMA(Closes[2], Convert.ToInt32(Emaperiod1));
                            RSI1 = RSI(Closes[1], 14, 3);
                            ADX1 = ADX(Closes[2], Convert.ToInt32(ADXperiod1));
                            SetProfitTarget(@"long1", CalculationMode.Percent, Profit1);
                            SetStopLoss(@"long1", CalculationMode.Percent, Loss1, false);
                            SetProfitTarget(@"long2", CalculationMode.Percent, Profit1);
                            SetStopLoss(@"long2", CalculationMode.Percent, Loss1, false);
                            SetProfitTarget(@"short1", CalculationMode.Percent, Profit1);
                            SetStopLoss(@"short1", CalculationMode.Percent, Loss1, false);
                            }
                            }

                            protected override void OnBarUpdate()
                            {
                            if (BarsInProgress != 0)
                            return;

                            if (CurrentBars[0] < 1
                            || CurrentBars[1] < 1
                            || CurrentBars[2] < 1)
                            return;

                            // Set 1
                            if ((CrossAbove(Closes[2], EMA1, 1))
                            && (Times[0][0].TimeOfDay >= Timeopen.TimeOfDay)
                            && (Times[0][0].TimeOfDay <= Timeclose.TimeOfDay)
                            && (RSI1.Default[0] < RSIshort1)
                            && (ADX1[0] < Adxup))
                            {
                            EnterLong(Convert.ToInt32(DefaultQuantity), @"long1");
                            Print(Convert.ToString(Times[0][0]) + @" ADX " + Convert.ToString(ADX1[0]) + @" RSI " + Convert.ToString(RSI1.Avg[0]) + @" EMA " + Convert.ToString(EMA1[0]) + @" Price " + Convert.ToString(Close[0]) + " " + Convert.ToString(Position.MarketPosition));
                            }

                            Comment


                              #15
                              Hello walter739,

                              I tried the script you provided however I was unable to see what I believe you had described here. Are you specifically expecting that the entry will happen on both instruments at the exact same time, one entry per script? If so I believe we would really only expect that in historical where the data is already known and everything is being processed in a fixed way. In realtime you may see that one instrument has slower or faster data which could result in different fills.

                              If I have not understood correctly can you tell me what primary series is being used for each strategy? Also if you have an image comparing one of the late fills vs your expectation that may help.

                              I look forward to being of further assistance.
                              JesseNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by fastnet, Yesterday, 10:58 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post fastnet
                              by fastnet
                               
                              Started by tradingbobby, Yesterday, 10:41 PM
                              1 response
                              11 views
                              0 likes
                              Last Post s.kinra
                              by s.kinra
                               
                              Started by bfalls, Yesterday, 10:38 PM
                              1 response
                              9 views
                              0 likes
                              Last Post s.kinra
                              by s.kinra
                               
                              Started by WHICKED, Yesterday, 09:05 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post WHICKED
                              by WHICKED
                               
                              Started by luislag14, Yesterday, 06:29 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post luislag14  
                              Working...
                              X