Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetStopLoss not resetting after partial profit

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

    SetStopLoss not resetting after partial profit

    Hello,

    I'm trying to go breakeven on runners after i hit the take profit on partial contracts , but for some reason SL is not reset to new price. Code below. i hope someone can assist me.

    if (Position.MarketPosition == MarketPosition.Short && Close[0] < shorttakeprice)
    {

    shortstopprice = Position.AveragePrice;//NEW PRICE
    SetStopLoss(CalculationMode.Price, shortstopprice);//set to breakeven on remaining positions

    }

    if (Position.MarketPosition == MarketPosition.Flat)
    {
    SetStopLoss(CalculationMode.Price, Close[0]-20);

    }


    if (SellCondition == true)
    {

    shorttakeprice = Close[0] - tps;
    shortstopprice = Close[0]+sls;
    SetProfitTarget("Short Set1", CalculationMode.Price, shorttakeprice);
    SetStopLoss(CalculationMode.Price, shortstopprice); // Original set to 14875
    EnterShort(PositionSize-1, "Short Set1");
    EnterShort("Short Set2");

    }

    i tried to set SL with "Short Set2" as well . see below, i wanted the "Short Set2" to close at 14733.

    Click image for larger version

Name:	image.png
Views:	111
Size:	7.4 KB
ID:	1274552​​

    #2
    Hello nagesh789,

    Thanks for your post.

    When you are in a Flat position the SetStopLoss() method would be reset to the Close[0] price minus 20. The Close[0] price of the bar when the condition becomes true (when your position is flat) would be used.

    If you are not in a Flat position then the condition would not be true and the stop loss would not reset to that value.

    To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar. Also, print out the price being passed into the SetStopLoss() methods. Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121

    Further, here is a reference sample from the help guide that demonstrates moving the stop to breakeven which you might find helpful: https://ninjatrader.com/support/help...of_stop_lo.htm
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    87 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    132 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    118 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    67 views
    0 likes
    Last Post PaulMohn  
    Working...
    X