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

Execute Strategy Once and disable in NT8

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

    Execute Strategy Once and disable in NT8

    Is it possible to setup a strategy in NT8 so that it executes only once and stops executing Until I enable it again. for example I want to implement a strategy that enters an order at a certain price then disables after that order is placed and triggers.
    Regards
    G Hastings

    #2
    Welcome to the forums g_hastings!

    Yes, this would be possible. A strategy can check for the execution of an order in OnExecutionUpdate and then call CloseStrategy() to disable the strategy.

    OnExecutionUpdate - https://ninjatrader.com/support/help...tionupdate.htm

    CloseStrategy - https://ninjatrader.com/support/help...sestrategy.htm

    Also note, if you want the strategy to only work with realtime data, and skip historical processing, you can add the following to the top of the OnBarUpdate() method.

    if (State == State.Historical) return;

    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      From Strategy wizard? or I have to enter the code.

      Comment


        #4
        Hello g_hastings,

        In the Strategy Builder, You could use a bool to control actions so they only happen once, but we cannot programmatically disable the strategy.

        You could, for example, create a bool in Inputs and Variables that is initialized as true. You can then check if that bool is true, Misc > Current State is State.Realtime, and then your entry condition. When all are true, call EnterLong/EnterShort to enter, and also set the bool to false.

        The condition to enter will no longer become true until the strategy is disabled and re-enabled.

        We look forward to assisting.
        JimNinjaTrader Customer Service

        Comment


          #5
          Thank you! I believe the second approach where one uses a bool to evaluate a true/ false to stop the strategy would be more than sufficient. So if you could point me to a sample of such a setup would be highly appreciated.

          Comment


            #6
            Hello g_hastings,

            To visualize a bool in use, I have attached a strategy that uses a bool to control when an initial stop loss should be used or if the stop loss should be moved to breakeven. The stop loss is controlled with ExitLongStopMarket in Conditions and Actions so the strategy logic can control where the order gets placed.

            You would need to set up a condition as described in post #4 to accomplish your goal.

            We look forward to assisting.
            Attached Files
            JimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by drewski1980, Today, 08:24 AM
            0 responses
            3 views
            0 likes
            Last Post drewski1980  
            Started by rdtdale, Yesterday, 01:02 PM
            2 responses
            16 views
            0 likes
            Last Post rdtdale
            by rdtdale
             
            Started by TradeSaber, Today, 07:18 AM
            0 responses
            7 views
            0 likes
            Last Post TradeSaber  
            Started by PaulMohn, Today, 05:00 AM
            0 responses
            10 views
            0 likes
            Last Post PaulMohn  
            Started by ZenCortexAuCost, Today, 04:24 AM
            0 responses
            6 views
            0 likes
            Last Post ZenCortexAuCost  
            Working...
            X