Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Builder functions

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

    Strategy Builder functions

    Hi All

    I have built some strategies in Ninja Trader which are showing excellent backtest results especially when walk forward optimised. However when I run them live over a certain period the results are very different to when I back test over the same period.

    1, One of the main problems is that when running the strategy live it will open multiple trades all at the same time. Is there a way to make sure the strategy only opens one trade per candle or only one trade at one time?

    Also can you think of a reason why the backtest would be so different to the live trading. The strategy is based around bollinger band range trading using the outer band to open trade and inner band to close trade on the 1min to 10min chart.?


    Also as a side question, is there a way to set the strategy so it only runs on certain days of the week. E.g Monday and Friday only?

    Many thanks for your support





    #2
    Hello pborg05,

    Thanks for your post.

    A difference between live trading and backtesting is that backtesting runs your strategy on the basis of once per bar (as if you had set Calculate.OnBarClose), this is because backtesting only uses the OHLC values of the bar and not all of the ticks that make up the bar. If you are using Calculate.OnPriceChange or Calculate.OnEachTick, then on live data your strategy will be executed far more often. If you want to replicate your backtesting results, you might try using the same mode of Calculate.OnBarClose. This would also fix the multiple orders per bar.

    Otherwise, if you want to continue to use Calculate.OnEachTick or Calculate.OnPriceChange, you can limit orders to once per bar by creating an int variable and saving the CurrentBar value, and as an extry condition to check that the saved bar is not equal to the current bar, for example (assume you created an int variable called savedBar):

    if (your entry conditions and CurrentBar != savedBar) // allow entry into this code if the current bar number is Not Equal to the savedBar number.
    {
    // entry order
    savedBar = CurrentBar; // Assign current bar number to savedBar the first time through
    }


    Reference: https://ninjatrader.com/support/help...currentbar.htm

    Here is a link to differences you can expect between live and backtesting: https://ninjatrader.com/support/help...ime_vs_bac.htm

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hello pborg05,

      I forgot to address your last question of, "Also as a side question, is there a way to set the strategy so it only runs on certain days of the week. E.g Monday and Friday only?"

      Yes, in the strategy builder, you can add to your entry sets, the condition of, left side select Time>Date value, in the center select Equals, on the right select Time>Day of week and select the specific day.

      To have it run on Monday OR Friday, you would need to create both of the day checks into a "group condition" and the group would need to be set to "If any". Here is a link to a condition builder example. The example is not the same as what you need but it shows the steps of creating a group if you are not familiar with that. https://ninjatrader.com/support/help...ateTimeFilters

      Paul H.NinjaTrader Customer Service

      Comment


        #4
        Thanks this is all really useful.

        The part about keeping it as calculating on each Tick but adding the extra the extra condition seems tricky but I will give it a go.

        Thanks

        Comment


          #5
          Hi Paul H

          Following on from this I am still having the same issue of many trades opening in the same bar when live trading using the Strategy.

          Perhaps I have made a fundamental mistake in the build...

          The strategy is simply to open a short trade when price is above the upper outer Bollinger Band and it crosses below the band. Then conversely open a long trade when price is below the lower B Band and it crosses up through it.
          I want to exit the trade when price crosses either the middle BB or the opposite BB. Chosen by the user.

          The only other input from the user will be the BB period and the BB Deviation.

          I would imagine this is a fairly common strategy, do you know of a guide anywhere on how to build this kind of strategy properly, or perhaps you can explain it as it relatively simple.

          Many thanks


          Comment


            #6
            Hello pborg05,

            Thanks for your reply.

            It sounds like you may not have added the condition to check to see if the entry bar is not the same as the current bar as this will prevent multiple orders on the same bar.

            I've created a short video to assist: https://Paul-ninjaTrader.tinytake.co...Nl8xNDc5OTg3Mg
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Hi Paul

              Thanks for this info it was very clear and I added this to the strategy but the strategy is still not functioning as it should.

              The strategy is actually very simple, perhaps you already have a video or blog for this kind of strategy or perhaps you could explain what conditions need to be added

              Functions

              2, Open a trade when price crosses through either one of the outer Bollinger Bands from outside to inside.
              3, Close the trade then when prices equals the opposite outer Bollinger Band.

              User inputs the time of the day the strategy is active. I think I have this working perfectly.
              User Inputs the Bollinger band Period and standard deviation. I think I have this working perfectly.

              Many thanks for your help

              Comment


                #8
                Hello pborg05,

                Thanks for your reply.

                For #2 If I understand correctly you want to look for a price crossbelow using the Upper band (going short) and a CrossAbove using the Lower band (going long). In order for these cross events to happen, in the case of a short condition price has to first cross above the Upper band to then be able to CrossBelow the upper band. Likewise, in the case of a long condition, the price must first have crossed below the Lower band to then be able to crossabove.

                For #3, based on #2, when in a short position look for price to CrossBelow of the lower band. When in a long position look for price to crossAbove of the Upper band.
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Paul

                  For #2 If I understand correctly you want to look for a price crossbelow using the Upper band (going short) and a CrossAbove using the Lower band (going long). YEs correct
                  In order for these cross events to happen, in the case of a short condition price has to first cross above the Upper band to then be able to CrossBelow the upper band. Likewise, in the case of a long condition, the price must first have crossed below the Lower band to then be able to crossabove. Well Price doesnt have to cross above the upper BB band for the short trade to execute but it would have to be above the upper BB band for it then be able to cross below the upper BB band for the short trade to execute. What i mean is Price may have been above the upper BB band before the Strat started. I hope that makes sense.

                  For #3, based on #2, when in a short position look for price to CrossBelow of the lower band. When in a long position look for price to crossAbove of the Upper band. Yes correct

                  Thanks

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by aa731, Today, 02:54 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post aa731
                  by aa731
                   
                  Started by thanajo, 05-04-2021, 02:11 AM
                  3 responses
                  470 views
                  0 likes
                  Last Post tradingnasdaqprueba  
                  Started by Christopher_R, Today, 12:29 AM
                  0 responses
                  10 views
                  0 likes
                  Last Post Christopher_R  
                  Started by sidlercom80, 10-28-2023, 08:49 AM
                  166 responses
                  2,237 views
                  0 likes
                  Last Post sidlercom80  
                  Started by thread, Yesterday, 11:58 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post thread
                  by thread
                   
                  Working...
                  X