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

Strategy Disable Killing Prior Order Executions

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

    Strategy Disable Killing Prior Order Executions

    Hello,

    I have an NT8 strategy that is intended to enter short a position and enter a stop market (buy to close) at the same time, then I enter a target close (limit order) manually after hours. On first trial, the strategy re-entered the position immediately upon hitting a stop, which could have caused an endless vicious cycle if I wasn't watching (it was painful enough watching the 1 minute loss I suffered after re-entry).

    My first solution was to disable the strategy immediately after the stop order to prevent re-entry from occurring, but it seems this disable command prevents the prior commands from being executed, at least during my over-the-weekend tests that I ran, which I performed with and without the termination command. Is there something I need to do to allow prior commands to execute first before terminating the strategy? I unchecked both entry and exit "Cancel orders when a strategy is disabled" under Tools>>Options>>Strategies, set EntriesPerDirection = 1, and set EntryHandling = AllEntries. Thanks

    Code:
    if (Condition == true) //entry condition is true 
    {
    	EnterShort(NumShares);
    	ExitShortStopMarket(NumShares, EntryPrice*1.1);
    	SetState(State.Terminated);
    }

    #2
    Hello dcschultz,

    Thank you for your note.

    Likely the issue is the initial condition is becoming true as soon as your exit order is filled, thus leading to the loop.

    What you could do if you’d only like the strategy to take 1 trade you could see the following reference example, which limits additional trades based on the trade counter.



    Below is another example of halting additional trading after certain conditions become true,


    You should never set the State as you did in the third line of your block, this could cause unexpected behavior.

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Thanks, I will implement the trade counter. Since tradeCounter is a private int, I assume it only counts trades for this one instrument (as I have this strategy enabled for separate instruments in a list in the Strategies tab of the Control Center). Correct?

      Comment


        #4
        Hello dcschultz,

        The counter will only count trades that instance of the strategy has made. If another instance of the strategy is applied to a different instrument, the two counters will be independent.

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Aviram Y, Today, 05:29 AM
        0 responses
        3 views
        0 likes
        Last Post Aviram Y  
        Started by quantismo, 04-17-2024, 05:13 PM
        3 responses
        27 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by ScottWalsh, 04-16-2024, 04:29 PM
        7 responses
        35 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
        218 views
        1 like
        Last Post PaulMohn  
        Working...
        X