Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entry and exit on the same day backtest

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

    Entry and exit on the same day backtest

    Hi all,

    I would be interested in backtesting a very simple strategy consisting in taking the trade at the open and exiting at close on daily bars.

    I had a look to this thread:



    and it looks like it is possible to enter and exit the same day by using the unmanaged approach in NinjaTrader 7.

    I have tried to follow the same method in NinjaTrader 8 with unmanaged strategy but I didn't get the expected results.The exit is always at next day open.

    I know that it is needed to add intraday bar granularity to implement it properly but as preliminary test I would like to have a rough idea if it worths to implement the strategy or not.

    Do we have something similar in NinjaTrader 8? Or the only way is to use SetStopLoss or SetProfitTarget?

    Thanks and Regards.

    #2
    Hello Peppo,

    Thanks for your post.

    This gets into unsupported area since we are looking ahead of prices with a backtest, but when I test on my end, I see the enter occur at the next bar's open, and the exit occurring on the close of the same bar. (I am using GetValueAt to avoid negative Series references.)

    Click image for larger version

Name:	NinjaTrader_2022-07-06_10-33-56.png
Views:	342
Size:	57.1 KB
ID:	1207605

    Code:
    if (CrossAbove(SMA(7),SMA(14),1) && State == State.Historical)
    {
        SubmitOrderUnmanaged(0,OrderAction.Buy, OrderType.Market,1,0,0,"","Long");
    
        //Make sure there is a bar to see the close price of
        if(CurrentBar < BarsArray[0].Count)
        {
            SubmitOrderUnmanaged(0,OrderAction.Sell,OrderType. Limit, 1,Close.GetValueAt(CurrentBar+1),0,"","Exit Long");
        }
    }
    I hope this helps.
    Last edited by NinjaTrader_Jim; 07-06-2022, 10:34 AM.

    Comment


      #3
      Hi Jim,

      Perfect. This is exactly what I was looking for.

      Thanks a lot!

      Regards.

      Comment


        #4
        Hi Jim,

        sorry to come back on this topic but I found a weird problem when applying the same strategy on the 1440 minute chart instead of daily.

        With this configuration no one order is executed. Do I need to use a different configuration? Is that expected?

        Thanks.

        Comment


          #5
          Hello Peppo,

          Thanks for your note.

          This likely has to do with how the end-of-session handling is done for 1440-Minute bars compared to Daily bars. Daily bars do not have the granularity to support Exit On Session Close behavior for Historical data.

          1440-Minute bars do have the granularity to support Exit On Session Close and the orders are ignored because the 1440-Min is the entire session. If you say 1300-Minute bars instead, the orders would be placed because that interval allows the Exit On Session Close to trigger. Or, you could disable the Exit On Session Close property when testing the strategy.

          Let me know if I may assist further.
          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment


            #6
            Hi BrandonH,

            thank you.

            It worked by disabling the Exit On Session Close.

            Regards.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by CarlTrading, 03-31-2026, 09:41 PM
            1 response
            79 views
            1 like
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            40 views
            0 likes
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            63 views
            2 likes
            Last Post CaptainJack  
            Started by CarlTrading, 03-30-2026, 11:51 AM
            0 responses
            63 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 03-30-2026, 11:48 AM
            0 responses
            54 views
            0 likes
            Last Post CarlTrading  
            Working...
            X