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

Run strategy then want to disable after exit

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

    Run strategy then want to disable after exit

    Hello I am having an issue:

    I want to run my strategy 1 time then it automatically disables after it exits until I re-enable the strategy. I don't need it to unclick the enable button or anything I really just need the strategy to not start again after the exit even when the conditions are met.

    I have tried from previous forums " If you are wanting to only allow one entry unless the strategy is disabled/re-enabled you can compare BarsSinceEntryExecution() to be greater than -1."

    The problem is my strategy will not enter long even if I set submit immediately and synchronize with the barssinceentryexecution. Is there another way to do this? I am using strategy builder and not as familiar with coding manually.

    Thanks in advance.

    #2
    Hello ecmazii,

    Thank you for your post.

    I'd suggest just using a bool to control the strategy entries.

    So for example, you could create a bool called TradeTaken and set that to false initially. Then, check that the bool is false in your entry conditions, place your entry and set the bool to true when the entry is placed. As long as you don't set the bool back to false, the strategy wouldn't be able to enter again until it is disabled and re-enabled.

    I've created a very simple example strategy using the Strategy Builder that illustrates this - note that since we're only wanting the strategy to enter once then not submit more entries that we check to make sure we're on real time data before entering. Otherwise, when the strategy calculates on historical data it would likely calculate it would have taken a trade already and not submit in real time.

    Please let us know if we may be of further assistance to you.
    Attached Files
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thank you for the reply,

      So I set the False bool in the inputs and variables section and the False in the entry conditions. But besides unlocking the code and manually entering the the bool to true once entry, is there another way in strategy builder to do this? I prefer not to unlock the code because I wont be able to make changes to the strategy in the builder afterwards.

      Also I have seen this on multiple forums but havent seen how to do it in strategy builder. How do you make sure that you are on real time data and not historical data? I have been stuck on this for some time and don't want to have to unlock all of my codes to make the changes.

      Thanks again

      Comment


        #4
        Hi Kate,

        I just wanted to know if you could assist me with the last reply?

        Thanks

        Comment


          #5
          Hello ecmazii,

          Thank you for your reply.

          The example I previously posted sets the bool to true when the strategy submits an order, and also checks if the strategy is running on real time data before entering, directly in the Strategy Builder strategy, without the need to unlock the code:

          Click image for larger version

Name:	2020-09-18_12-58-25.png
Views:	207
Size:	55.1 KB
ID:	1118889

          I would suggest reviewing the example to see how this works.

          Please let us know if we may be of further assistance to you.
          Kate W.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by GussJ, 03-04-2020, 03:11 PM
          11 responses
          3,221 views
          0 likes
          Last Post xiinteractive  
          Started by andrewtrades, Today, 04:57 PM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by chbruno, Today, 04:10 PM
          0 responses
          6 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          436 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          9 views
          0 likes
          Last Post FAQtrader  
          Working...
          X