Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

In OnStateChange() State == State.Configure Vs. DataLoaded for SetTrailStop()?

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

    In OnStateChange() State == State.Configure Vs. DataLoaded for SetTrailStop()?

    Hello,

    Question #1: Should the SetTrailStop(), SetStopLoss(), SetParabolicStop(), and SetProfitTarget() methods be called in the "OnStateChange()" when "State == State.Configure" or "State == State.DataLoaded"?

    Question #2: ​Are one of these two places a bad, dangerous place to insert these methods, is one a little better than the other, or are they both just as good as locations for these 4 methods to be inserted?

    I ask this question because I noticed a difference between where the NinjaTrader Strategy Builder inserts the "Stops and targets" methods (SetTrailStop(), SetStopLoss(), SetParabolicStop(), and SetProfitTarget()) and where the examples in the official NinjaTrader help docs for these 4 methods insert these methods.

    When I use the Strategy Builder in the newest NinjaTrader Desktop version (8.1.2.1) and add any of these 4 methods (including both of the variants for the 3 methods that have them, for a total of 7 possible choices) from the "Stops and Targets" tab, it inserts these methods in "OnStateChange()" when "State == State.DataLoaded", like this:

    Code:
    else if (State == State.DataLoaded)
    {
        SetProfitTarget(CalculationMode.Currency, 0);
        SetTrailStop("", CalculationMode.Percent, 0, false);
    }


    However, on the 4 official NinjaTrader help docs for these 4 methods, the examples show these methods being inserted in "OnStateChange()" when "State == State.Configure", like this:

    SetStopLoss() official help doc: https://ninjatrader.com/support/help...etstoploss.htm

    Code:
    protected override void OnStateChange()
    {
        if (State == State.Configure)
        {
            // Submits a stop loss of $500
            SetStopLoss(CalculationMode.Currency, 500);
        }
    }


    SetTrailStop() official help doc: https://ninjatrader.com/support/help...ttrailstop.htm

    Code:
    protected override void OnStateChange()
    {
        if (State == State.Configure)
        {
            // Sets a trail stop of 12 ticks
            SetTrailStop(CalculationMode.Ticks, 12);
        }
    }​
    SetParabolicStop() official help doc: https://ninjatrader.com/support/help...abolicstop.htm

    Code:
    protected override void OnStateChange()
    {
        if (State == State.Configure)
        {
            // Sets a parabolic stop using default acceleration (0.02), accelerationMax (0.2), accelerationStep (0.02) settings and a floor value of 12 ticks
            SetParabolicStop(CalculationMode.Ticks, 12);
    
            // Sets a parabolic stop of with a currency floor of 500
    
            SetParabolicStop("MyLongEntry", CalculationMode.Currency, 500, false, 0.03, 0.3, 0.01);
        }
    }


    SetProfitTarget() official help doc: https://ninjatrader.com/support/help...ofittarget.htm

    Code:
    protected override void OnStateChange()
    {
        if (State == State.Configure)
        {
            // Submits a profit target order 10 ticks away from the avg entry price
            SetProfitTarget(CalculationMode.Ticks, 10);
        }
    }​
    Thank you very much in advance,

    EquityTrader​

    #2
    Hi NinjaTrader support,

    Could one of you please respond to my post? I posted it almost two full business days ago.

    I am sure your answer will be worth the wait and I am very appreciative for the extremely high level of your answers to my posts in years past.

    Thank you very much in advance!

    EquityTrader

    Comment


      #3
      Hello EquityTrader,

      For Set methods specifically, State.Configure and State.DataLoaded would not make any difference. In both states, this would be calling the method before data starts being processed in OnBarUpdate().
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Thank you, NinjaTrader_ChelseaB! I really appreciate this answer and your previous excellent answers over the years.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        50 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        126 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        69 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X