Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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:	257
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.
    JimNinjaTrader Customer Service

    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.
          Brandon H.NinjaTrader Customer Service

          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 nicthe, Today, 07:38 AM
            1 response
            12 views
            0 likes
            Last Post bltdavid  
            Started by michi08, Today, 08:51 AM
            0 responses
            3 views
            0 likes
            Last Post michi08
            by michi08
             
            Started by algospoke, 02-19-2024, 03:25 PM
            4 responses
            36 views
            0 likes
            Last Post gummybar  
            Started by gummybar, 02-14-2024, 03:22 PM
            2 responses
            35 views
            0 likes
            Last Post gummybar  
            Started by burtoninlondon, 04-28-2024, 12:38 AM
            3 responses
            36 views
            0 likes
            Last Post burtoninlondon  
            Working...
            X