Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bars Since Exit Using Strategy Wizard

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

    Bars Since Exit Using Strategy Wizard

    Hi everyone,

    First time poster, I am getting to grips with the Strategy Builder. Its a great tool.
    However I do not want my system to enter on a bar that it has stopped out on (to avoid whipsaws).

    When I do BarsSinceExit > 1 no trades appear. I understand why this is. Because there will always need to be a first trade for this logic to make sense if the system is looking for an exit 1 bar ago to start running.

    However, I do not want to have to play around with the C# code as I don't understand it and once I open it up I cannot carry on working on my Strategy Wizard for this EA I believe.

    Surely there must be a way to resolve this issue just using the Strategy Wizard otherwise why bother having the "BarsSinceExit" function in there?

    Many thanks

    #2
    Hi Tomhgriff1,

    Thanks for your post.

    Use a different condition for the initial entry order.

    Be sure this does not trigger if the other condition triggers.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks ChelseaB

      I think I understand what you are saying. How would I get another another condition to only trigger once and never again (which I assume is what would need to be done to create a "first trade" to set the main strategy in motion?)

      It would need to be the same entry criteria as the rest of my system surely or it would effect the backtest.

      So say my system is a simple MA cross.
      If BarsSinceExit > 1 and MA(15) > MA (20) buy High [1]

      Would I need to create another condition exactly the same without the BarsSinceExit ?

      Although that would surely carry on executing on its own and get in the way?

      Thanks

      Comment


        #4
        Hi Tomhgriff1,

        Use if BarsSinceEntry() == 0.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Ok I think I have done that and still not getting any trades.

          Ive attached an image for you to see.


          Thanks very much for the help
          Attached Files

          Comment


            #6
            Hi Tomhgriff1,

            Typically I would suggest adding Prints to your code to see which of these conditions is not evaluating to true on each bar, but this is not possible with the Strategy Wizard.

            Instead, I would suggest starting simple. Try using BarsSinceEntry() == 0 by itself. Does this allow for an entry?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Ok I tried just putting in BarsSinceEntry() == 0 by itself and I got a trade at the start of my back test period. Just one trade for the entire backtest period.

              Shall I keep that code and then add a "barssinceexit" code to solve the original problem of trading twice on the same bar?

              Thanks for the ongoing help.

              Comment


                #8
                Hi Tomhgriff1,

                The idea was for this to only enter once for the initial entry.

                I am unsure why you would need to check the BarsSinceExit() as this order will create an entry and not an exit.

                The next step would be to add the next line of your condition.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Sorry I will explain myself again.

                  The issue originally was I was having trades taken both long and short on the same bar. If I got stopped out on bar number 10 then I would want the system to not enter another trade until at least bar 11.

                  I assumed the way to solve this would be to have a condition saying BarsSinceExit()>1 meaning there must be at least one bar since exiting my last trade.

                  When I add this no trades take place.

                  I have been following your steps since.

                  As it stands I have the condition BarsSinceEntry() == 0 and then all my other conditions which results in only one trade over the entire backtest period. Obviously I want it to be making lots of trades. Just not on the same bar

                  Comment


                    #10
                    Hi Tomhgriff1,

                    The method is the same.

                    Place an initial order using BarsSinceEntry() == 0.

                    Then any subsequent orders can't be placed until this first order is closed by an exit as they are using BarsSinceExit() > 1.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Ah finally I get it.

                      I didnt realise I had to have two differently named systems. One system with the BarsSinceEntry() and another one with BarsSinceExit (0) and my required conditions there.

                      I just had all the conditions on one entry.

                      Thanks for your patience!

                      Comment


                        #12
                        Oh actually that hasnt fixed it

                        You will see in the attached image it is trading on the same bar
                        Attached Files
                        Last edited by Tomhgriff1; 10-17-2014, 10:18 AM. Reason: Other uploads

                        Comment


                          #13
                          Hi Tomhgriff1,

                          Your code is using SetStopLoss and SetProfitTarget.

                          These will fill in the same bar if the price hits the profit target or stop loss in that bar.

                          If you place an exit order at bar close, requiring that a position be open for the exit to be submitted, this would always be on the next bar or greater.

                          The BarsSinceEntry() == 0 check for the initial entry has nothing to do with your exits.

                          This is so that you can place the first order. The first order appears to be placing now.

                          If you want the exits to be on a separate bar, do not use SetStopLoss or SetProfitTarget and instead use an exit order and only submit the exit after the Position.MarketPosition is no longer MarketPosition.Flat.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Well done for figuring that. That makes sense.

                            The reason I had concerns about trading on the same bar is it looked like an error on the backtest.

                            So there is no error here and the backtest is realistic? The system would meet condition 1, get stopped out, wait for condition 2 to be met then enter in the correct order as it currently is setup?

                            Comment


                              #15
                              Hi Tomhgriff1,

                              As far as I can tell there is only 1 entry on the bars that have entries.

                              The exit is not a new trade. The exit is the exit of the trade opened by the entry.

                              If this is the behavior you are looking for then this is correct.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              574 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              333 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              101 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              553 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              551 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X