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

EntryOrders with CalculateOnBarClose set to false

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

    EntryOrders with CalculateOnBarClose set to false

    Hi folks,

    I'm testing two identical strategies, a part from the CalculateOnBarClose property. One is set to true and the second to false.

    The first strategy is working with Close[0] and the second with FirstTickOfBar check and Close[1] to determine the closure of the last bar.

    The problem is that the strategy with the CalculateOnBarClose set to false enter at market with one bar delay compared to the first one.

    Why this behaviour? I need to enter immediately after the closure of a bar if it satisfy some conditions. The first strategy is working well, but not the second.

    Please help me.

    Thanks,
    Marco

    #2
    Hello Marco,

    Thank you for your note.

    From your description is the following correct?
    • The strategy running with CalculateOnBarClose = False is checking FirstTickOfBar and Close[1].
    • The strategy running with CalculateOnBarClose = True is checking Close[0].
    • The strategy checking FirstTickOfBar is entering one bar late.


    If the above is correct, where is the condition checked to place the entry order? Is it in the FirstTickOfBar condition check? Can you provide the code for the condition that would need to return true to submit the order?

    Comment


      #3
      Originally posted by NinjaTrader_PatrickH View Post
      Hello Marco,

      Thank you for your note.

      From your description is the following correct?
      • The strategy running with CalculateOnBarClose = False is checking FirstTickOfBar and Close[1].
      • The strategy running with CalculateOnBarClose = True is checking Close[0].
      • The strategy checking FirstTickOfBar is entering one bar late.


      If the above is correct, where is the condition checked to place the entry order? Is it in the FirstTickOfBar condition check? Can you provide the code for the condition that would need to return true to submit the order?

      Hello Patrick,

      yes you are correct in all the points above.

      And I confirm also that the condition that place the entry order is in the FirstTickOfBar condition check.

      Comment


        #4
        Following two simple samples that represent the situation.

        CalculateOnBarClose set to TRUE:

        Code:
        protected override void OnBarUpdate()
        {
                     if(Close[0] > val)
                              entryOrder = EnterLong(LONG_ENTRY);
        }
        CalculateOnBarClose set to FALSE:

        Code:
        protected override void OnBarUpdate()
        {
                    if (FirstTickOfBar)
                    {
                        if(Close[1] > val)
                              entryOrder = EnterLong(LONG_ENTRY);
                    }
        }
        The second one enter with a delay of one bar.

        Thanks.

        Comment


          #5
          Hello mbk2787,

          Thank you for your response.

          I cannot reproduce this on my end. Can you provide a screenshot of each occurrence?

          To send a screenshot with Windows 7 or newer I would recommend using Window's Snipping Tool.

          Click here for instructions

          Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.

          Click here for detailed instruction

          Comment


            #6
            Thanks.

            I attached the screenshots. The first one is related to the CalculateOnBarClose = true scenario and the second one to the false. The vertical red line represent the time on which I call the EnterLong method.

            Thanks.
            Attached Files

            Comment


              #7
              Hello mbk2787,

              Thank you for the screenshots.

              Can you send over the strategy or a test strategy that reproduces the behavior?

              You can attach your strategy to your response by going to File > Utilities > Export NinjaScript > Export selected source files > select your strategy > select the right arrow > Export. The file will be located under (My) Documents\NinjaTrader 7\bin\Custom\ExportNinjaScript.

              You can send it to platformsupport[at]ninjatrader[dot]com with 'ATTN: Patrick H - 1498586' in the subject line if you prefer.

              Comment


                #8
                Originally posted by NinjaTrader_PatrickH View Post
                Hello mbk2787,

                Thank you for the screenshots.

                Can you send over the strategy or a test strategy that reproduces the behavior?

                You can attach your strategy to your response by going to File > Utilities > Export NinjaScript > Export selected source files > select your strategy > select the right arrow > Export. The file will be located under (My) Documents\NinjaTrader 7\bin\Custom\ExportNinjaScript.

                You can send it to platformsupport[at]ninjatrader[dot]com with 'ATTN: Patrick H - 1498586' in the subject line if you prefer.
                I'll send the script ASAP.

                In the meantime, I forgot to mention that I'm not on live market but I'm performing a backtest strategy.

                Probably is this the reason?

                Thanks

                Comment


                  #9
                  Originally posted by mbk2787 View Post
                  I'm not on live market but I'm performing a backtest strategy.

                  Probably is this the reason?
                  Yes, in backtesting we are on historical data and there fore CalculateOnBarClose is actually true even if set to false. This is due to there being no intra-bar ticks to build the bar and setting something to FirstTickOfBar and Close[1] will wait another bar.

                  You may wish to test in Market Replay instead.

                  Comment


                    #10
                    I have an indicator where I have two data series. I would like CalculateOnBarClose = true for the primary dataseries but intrabar calculation for the secondary datseries so ideally something like this:

                    If(BarsInProgress == 0)
                    {
                    CalculateOnBarClose = true

                    }
                    else if((BarsInProgress == 1)
                    {
                    CalculateOnBarClose = false
                    }

                    Is this possible?

                    Comment


                      #11
                      Hello,

                      It is not correct to toggle the CalculateOnBarClose setting after the script is started.

                      Instead likely what you would need to do is add a 1 tick series and utilize that BarsInProgress for any CalculateOnBarClose = false logic.

                      Using the example you had provided, assuming a 1 tick series is the only added series and CalculateOnBarClose is set to true, the logic would be as you have shown:

                      Code:
                      If(BarsInProgress == 0)
                      {
                      // this is executed on each CalculateOnBarClose for the primary
                      }
                      else if((BarsInProgress == 1)
                      {
                      // this is executed on each CalculateOnBarClose for the secondary or each 1 tick
                      }

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

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Brevo, Today, 01:45 AM
                      0 responses
                      4 views
                      0 likes
                      Last Post Brevo
                      by Brevo
                       
                      Started by aussugardefender, Today, 01:07 AM
                      0 responses
                      3 views
                      0 likes
                      Last Post aussugardefender  
                      Started by pvincent, 06-23-2022, 12:53 PM
                      14 responses
                      241 views
                      0 likes
                      Last Post Nyman
                      by Nyman
                       
                      Started by TraderG23, 12-08-2023, 07:56 AM
                      9 responses
                      384 views
                      1 like
                      Last Post Gavini
                      by Gavini
                       
                      Started by oviejo, Today, 12:28 AM
                      0 responses
                      6 views
                      0 likes
                      Last Post oviejo
                      by oviejo
                       
                      Working...
                      X