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

How to get a strategy to reset everytime?

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

    How to get a strategy to reset everytime?

    I have created a simple strategy with a simple IF and THEN statement. How do I get the strategy 'reset' every single time the THEN statement or Action is triggered? Currently if the IF Statement happens, it will do the action (THEN statement) multiple times without looking for the IF statement to happen again.

    Conclusion: IF Statement 1 happens, THEN Statement 1 occurs. THEN Statement 2 occurs as it is still looking at IF Statement 1 rather than looking another IF Statement 2.

    Thanks!

    #2
    Hello tradingbobby,

    Thanks for your post.

    You can use some kind of bool or other means in the code to prevent further iterations.

    Are you running your strategy with Calculate.OnEachTick or Calculate.OnPriceChange and the issue is placing multiple orders at once?

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_PaulH View Post
      Hello tradingbobby,

      Thanks for your post.

      You can use some kind of bool or other means in the code to prevent further iterations.

      Are you running your strategy with Calculate.OnEachTick or Calculate.OnPriceChange and the issue is placing multiple orders at once?
      Hi Paul,

      The issue is that I want the strategy to only place an order after the IF condition is met. In order for the strategy to place a second order, the IF condition must be met AGAIN, at a different instance. Right now, the IF condition is met, the strategy will enter and exit multiple positions (not at the same time)

      Comment


        #4
        Hello tradingbobby,

        Thanks for your reply.

        If the issue is that the strategy is placing multiple orders within the same bar and you are using Calculate.OnEachTick or Calculate.OnPriceChange then what you can do is to create an int variable that would allow you to save the current bar number when the if condition is true and in the if condition add a check to see that the current bar number is not the same as the saved bar number. This would allow the entry to occur the first time it is true in the bar and then by saving the current bar number the entry condition would no longer be true until the next bar at the earliest.

        I've attached an example of just this part which would need to be incorporated with your existing entry set(s).

        Click image for larger version

Name:	ExampleCurrentBarSaveBar.PNG
Views:	195
Size:	51.6 KB
ID:	1126761

        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by martin70, 03-24-2023, 04:58 AM
        15 responses
        114 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by The_Sec, Today, 02:29 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by jeronymite, 04-12-2024, 04:26 PM
        2 responses
        30 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by Mindset, 05-06-2023, 09:03 PM
        10 responses
        265 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by michi08, 10-05-2018, 09:31 AM
        5 responses
        743 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X