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:	84
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 michelz, Yesterday, 08:30 AM
    6 responses
    36 views
    0 likes
    Last Post MiCe1999  
    Started by ntbone, Yesterday, 01:50 AM
    13 responses
    52 views
    0 likes
    Last Post MiCe1999  
    Started by gyilaoliver, Today, 10:30 AM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by Irukandji, Yesterday, 04:24 PM
    2 responses
    27 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by madankumars, 11-18-2019, 11:12 AM
    15 responses
    204 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X