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

Identifying a bar close in an "On price change" strategy?

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

    Identifying a bar close in an "On price change" strategy?

    I know technically every price change the computer is registering that the previous bar has closed. But I have some bools and other functionality that need to be reset after the current bar officially closes. Is it possible to do that in an "On price change" strategy?

    #2
    Hello Plzwork123,

    Thanks for your post.

    You can use the system bool IsFirstTickOfBar which will be true on the first tick of the bar when using Calculate.OnPriceChange.

    Reference: https://ninjatrader.com/support/help...ttickofbar.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      I probably should have specified. I just want to confirm this is accessible from the strategy builder? That's what I'm working in. Having a hard time finding it.

      Comment


        #4
        Hello Plzwork123,

        Thanks for your reply.

        Yes, whenever you ask a strategy question it would be helpful to identify that you are using the strategy builder so we can provide an appropriate response.

        In the Strategy Builder, there is no IsFirstTickOfBar property available.

        However, you can still create such an event, here is how:

        1) In the Inputs and variables section create a bool called FirstTickOfBar and set it to false. Create an int type variable called "WorkingBar"
        2) In set 1 (the sequence is important), have no conditions. In the action section, set the FirstTickofBar bool to be false. The bool will be set false on every tick.
        3a) In Set 2, for a condition use UerVariables>Workingbar, Not Equal, Misc>Current bar.
        3b) In set 2, for action, Misc>Set WorkingBar and assign(click set in the field) to Misc>currentBar
        3c) In set 2, for action, Misc>Set FirstTickOfBar to true by checking the check box.

        Set 2 will check to see if the working bar is the same as the current bar and if it is not then that means we have a new bar. The action then is to assign the current bar to WorkingBar so that the condition is only true once per bar and that also means we are on the first tick of the bar. Because set 1 sets the bool false on every tick, that is why set 2 must be next to set the bool to true and subsequent use of the bool will be true, until the next tick.

        This will provide a bool FirstTickOfBar that you can then use throughout your strategy. Keep in mind that sets 1 and 2 must be sets 1 and 2 in your strategy whenever you need first tick of the bar,

        NOTE: If you apply this to bars that uses IsRemoveLastBarSupported, such as Renko bars, this method will not work correctly and would generate 3 FirstTickOfBar = true conditions.



        Attached Files
        Last edited by NinjaTrader_ChelseaB; 10-18-2021, 10:18 AM.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Ok yeah definitely wouldn't have thought to do that. Thank you kindly for the help.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Aviram Y, Today, 05:29 AM
          0 responses
          1 view
          0 likes
          Last Post Aviram Y  
          Started by quantismo, 04-17-2024, 05:13 PM
          3 responses
          25 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by ScottWalsh, 04-16-2024, 04:29 PM
          7 responses
          34 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by cls71, Today, 04:45 AM
          0 responses
          6 views
          0 likes
          Last Post cls71
          by cls71
           
          Started by mjairg, 07-20-2023, 11:57 PM
          3 responses
          216 views
          1 like
          Last Post PaulMohn  
          Working...
          X