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

disabling strategy after closed trade

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

    disabling strategy after closed trade

    I am building a strategy and would like for it to automatically 'disable' after a trade is closed.

    essentially, i would like to have it set up where i pick a stock, start the strategy on it (starting the strategy immediately opens a long or short), and then when the parameters are met to close the trade, the trade is closed and the strategy stops.

    I have achieved this thus far by having a bool flip on when i exit a long or short that prevents me from automatically entering another trade.

    However when testing applying the strategy on a chart, it never stays enabled because the strategy starts on past candles on the chart instead of the current one and closes the trade before the current candle starts. this causes the bool to flip on before my current trade is able to even play out.

    Is there a better way to achieve what i am trying to do? Or, is there a way to have the strategy not be applied to any of the prior data in a chart?

    #2
    Hello sra18376,

    Thanks for your post.

    You can disable the strategy with the Disable() method, please see: https://ninjatrader.com/support/help...7/?disable.htm

    You can "skip" historical trades by adding: if (Historical) return; at the top of OnBarUpdate(), this will prevent code below that line from processing until connected to live data.

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

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by judysamnt7, 03-13-2023, 09:11 AM
    4 responses
    59 views
    0 likes
    Last Post DynamicTest  
    Started by ScottWalsh, Today, 06:52 PM
    4 responses
    36 views
    0 likes
    Last Post ScottWalsh  
    Started by olisav57, Today, 07:39 PM
    0 responses
    7 views
    0 likes
    Last Post olisav57  
    Started by trilliantrader, Today, 03:01 PM
    2 responses
    21 views
    0 likes
    Last Post helpwanted  
    Started by cre8able, Today, 07:24 PM
    0 responses
    10 views
    0 likes
    Last Post cre8able  
    Working...
    X