Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 ageeholdings, Today, 07:43 AM
        0 responses
        7 views
        0 likes
        Last Post ageeholdings  
        Started by pibrew, Today, 06:37 AM
        0 responses
        4 views
        0 likes
        Last Post pibrew
        by pibrew
         
        Started by rbeckmann05, Yesterday, 06:48 PM
        1 response
        14 views
        0 likes
        Last Post bltdavid  
        Started by llanqui, Today, 03:53 AM
        0 responses
        6 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Started by burtoninlondon, Today, 12:38 AM
        0 responses
        12 views
        0 likes
        Last Post burtoninlondon  
        Working...
        X