Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stoploss or trailstop is not placing when order is placed from onExecutionUpdate

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

    Stoploss or trailstop is not placing when order is placed from onExecutionUpdate


    Hi,


    1. when order is placed at OnExecutionUpdate Stoploss or trailstop is not placing for new order ?

    2. When new order is placed quatity is getting doubled .Please let me know why it is doubled.?
    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    {

    Print("OnExecutionUpdate="+execution.Name+"executi onId="+executionId+"price="+price+"time="+time);
    if(execution.Name=="Buy"){
    Print("normal buy");
    isNormalBuy=true;
    isNormalShort=false;
    }
    if(execution.Name=="Sell short"){
    Print("normal Short");
    isNormalShort=true;
    isNormalBuy=false;
    }


    if((execution.Name=="Stop loss") || ("Trail stop"==execution.Name)){
    Print("normal Stop loss");
    if(isNormalBuy) { Print(" BUY SL Executed so enter new SHORT");
    EnterShort(Convert.ToInt32(DefaultQuantity));
    SetTrailStop(CalculationMode.Percent, 0.0003);
    isNormalShort=true;
    isNormalBuy=false;
    }
    if(isNormalShort){ Print(" Short SL Executed so enter new LONG");
    EnterLong(Convert.ToInt32(DefaultQuantity));
    SetTrailStop(CalculationMode.Percent, 0.0003);
    isNormalBuy=true;
    isNormalShort=false;
    }
    }


    }​

    #2
    Hello shankar.deshapande,

    Set methods should be called before the entry method is called.

    Below is a link to an example.
    https://ninjatrader.com/support/foru...269#post802269

    To reverse a position, call the entry in the opposite direction without using an exit order.
    If an entry and exit are called at the same time, the position will not have updated yet, resulting in the exit order, the Close position order, and then entry order all filling causing the position to be double in the reverse direction.

    This is detailed in the post below.
    https://ninjatrader.com/support/foru...16#post1036616

    Provide output from Prints and TraceOrders if you would like assistance analyzing the behavior.
    https://ninjatrader.com/support/foru...121#post791121
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi,
      Quantity issue is fixed but on reversalin onExecutionUpdate stoploss/Trail is not placing

      Comment


        #4
        Hello shankar.deshapande,

        Debug the script using TraceOrders and Print().

        For the condition that should be calling the SetTrailStop() method, add a print with the time of the bar to confirm this is evaluating as true when expected.

        Save the output to a text file and include this with your next post.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        56 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        132 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        73 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X