Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop returns to Initial Level After Target/Stop Hit on Partial

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

    Stop returns to Initial Level After Target/Stop Hit on Partial

    I'm entering 3 orders, each with entry signal and SetProfitTarget and SetStopLoss referencing each uniquely. I then have Stops move up level by level as price crosses over. I'm exiting two at the same level and leaving one to "run" with a wider stop. My issue is when the first two orders are filled (either by hitting target or stop) my remaining order gets "reset" back to the initial level (ZeroLevel) instead of holding the level I've tried to code (NineteenLevel or ThirtyEightLevel).

    I'm pretty new so sure the mistake is obvious, but not to me. I have order trace and prints enabled in OnOrderUpdate but I'm still not able to make sense of it.

    Initial stops set in OnExecutionUpdate:

    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    {
    SetStopLoss("19Long2", CalculationMode.Price, (ZeroLevel - 2 * TickSize), false);
    SetStopLoss("19Long", CalculationMode.Price, (ZeroLevel - 2 * TickSize), false);
    SetStopLoss("19Long1", CalculationMode.Price, (ZeroLevel - 2 * TickSize), false);
    }​
    Rest of code in OnBarUpdate:

    // Resets the stop loss to the original value when all positions are closed
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    SetStopLoss("19Long", CalculationMode.Price, (ZeroLevel - 2 * TickSize), false);
    SetStopLoss("19Long1", CalculationMode.Price, (ZeroLevel - 2 * TickSize), false);
    SetStopLoss("19Long2", CalculationMode.Price, (ZeroLevel - 2 * TickSize), false);
    }

    // Adjust stops up level by level
    if (Position.MarketPosition == MarketPosition.Long)
    {

    //Exit trade if price closes below 19 level 3 x after entry
    if ((Close[1] < NineteenLevel)
    && (Close[2] < NineteenLevel)
    && (Close[3] < NineteenLevel))
    {
    ExitLong("");
    Print("Exit long via 3x close below 19");
    }
    // if price crosses FiftyLevel, adjust stop to Nineteen Level on all 3 contracts
    else if (CrossAbove(Close, ThirtyEightLevel, 1))
    {
    SetStopLoss("19Long", CalculationMode.Price, (NineteenLevel - 2 * TickSize), false);
    SetStopLoss("19Long1", CalculationMode.Price, (NineteenLevel - 2 * TickSize), false);
    SetStopLoss("19Long2", CalculationMode.Price, (NineteenLevel - 2 * TickSize), false);
    }


    // if price crosses SixtyOneLevel, adjust stops to Fifty Level on 2 contracts targeting 80
    else if (CrossAbove(Close, SixtyOneLevel, 1))
    {
    SetStopLoss("19Long", CalculationMode.Price, (FiftyLevel - 2 * TickSize), false);
    SetStopLoss("19Long1", CalculationMode.Price, (FiftyLevel - 2 * TickSize), false);
    }


    // if price crosses EightyLevel, adjust stop to 38.2 level on last contract to give it room
    else if (CrossAbove(Close, EightyLevel, 1))
    {
    SetStopLoss("19Long2", CalculationMode.Price, (ThirtyEightLevel - 2 * TickSize), false);
    }



    // if price crosses 119, adjust stop to 100 level on last contract to tighten
    else if (CrossAbove(Close, OneNineteenLevel, 1))
    {
    SetStopLoss("19Long2", CalculationMode.Price, (OneHundredLevel - 2 * TickSize), false);
    }


    }

    Print(string.Format("{0} | DeltaHigh[0]: {1} > DeltaHigh[1] {2} ", Time[0], cumulativeDelta.DeltaHigh[0], cumulativeDelta.DeltaHigh[1] ));

    // Long Entry @ 19D Conditions
    // NoTrade entered if 3 closes below 19 level
    if ((Position.MarketPosition == MarketPosition.Flat) && (Close[1] < NineteenLevel)
    && (Close[2] < NineteenLevel)
    && (Close[3] < NineteenLevel))
    {
    NoTrade = 1;
    Print("NoTrade Long Triggered");
    }
    else if ((Position.MarketPosition == MarketPosition.Flat) && (CrossBelow(Close, NineteenLevel, 5))
    && (Close[1] > NineteenLevel)
    && (cumulativeDelta.DeltaHigh[0] > cumulativeDelta.DeltaHigh[1]))
    {
    EnterLong(DefaultQuantity, @"19Long");
    EnterLong(DefaultQuantity, @"19Long1");
    EnterLong(DefaultQuantity, @"19Long2");
    SetProfitTarget(@"19Long", CalculationMode.Price, (EightyLevel - 2 * TickSize), false);
    SetProfitTarget(@"19Long1", CalculationMode.Price, (EightyLevel - 2 * TickSize), false);
    SetProfitTarget(@"19Long2", CalculationMode.Price, (OneThirtyEightLevel - 2 * TickSize), false);

    }​

    #2
    Hello swjake,

    Reset Set methods with CalculationMode.Ticks one line before placing a new entry.

    Call the Set method with CalculationMode.Price after the position has changed to MarketPosition.Long.

    Use prints to determine which condition is calling the Set method again to the price you are not expecting.

    Provide the output saved to a text file if you want assistance analyzing the output.
    Chelsea B.NinjaTrader Customer Service

    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