Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem in OnExecutionUpdate

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

    Problem in OnExecutionUpdate

    Hello,

    i set in "OnBarUpdate" a variable and want this use as my Stoploss in OnExecutionUpdate. Playback & SimTrades works fine, but Realtime i became following situation (Stoploss is always 0) Click image for larger version

Name:	2023-09-06_15h49_30.png
Views:	184
Size:	24.3 KB
ID:	1267727
    OnBarUpdate i set my Currentstop like this
    Code:
    if (isNQMomentumTradingAllowed && Position.MarketPosition == MarketPosition.Flat)
                                {
                                    if( (SignaleNQ.Setup0123MomentumLongBlue[0] || SignaleNQ.Setup0123MomentumLongGreen[0] || SignaleNQ.Setup0123MomentumLongBlack[0] || SignaleNQ.Setup0123MomentumLongYellow[0]) && Button_Long )
                                        {
                                            ProfitDistance1 = 28;        ProfitDistance2 = 32;    ProfitDistance3 = 32;        EntryDistance = 0;        TrailStopDistance    = 18;    TrailStopBegin = 18;
                                            ProfitTargetPrice1 = High[1] + (ProfitDistance1 * TickSize);    ProfitTargetPrice2 = High[1] + (ProfitDistance2 * TickSize);    ProfitTargetPrice3 = High[1] + (ProfitDistance3 * TickSize);
                                            CurrentTriggerPrice = High[1] + (TrailStopBegin * TickSize);    CurrentStopPrice = Low[1] - (1 * TickSize); AbsicherungsSL = Close[1];
                                            Print("SetupLong " + CurrentTriggerPrice + " " + CurrentStopPrice+ " H " + High[1] + " L " + Low[1]);
                                            if (isNQMomentumTradingeinfachALL)                                            {    BuyLong();    }                                
                                            else if (isNQMomentumTradingeinfachab1 && SignaleNQ.momzaehlung[0] == -1)    {    BuyLong();    }
                                            else if (isNQMomentumTradingeinfachab2 && SignaleNQ.isTradingSerie[0])        {    BuyLong();    }
                                            else if (isNQMomentumTradingeinfachab3 && SignaleNQ.momzaehlung[0] == -3)    {    BuyLong();    }
                                        }        
                                    else if ( (SignaleNQ.Setup0123MomentumShortBlue[0] || SignaleNQ.Setup0123MomentumShortRed[0] || SignaleNQ.Setup0123MomentumShortBlack[0] || SignaleNQ.Setup0123MomentumShortYellow[0]) && Button_Short )
                                        {
                                            ProfitDistance1 = 28;        ProfitDistance2 = 32;    ProfitDistance3 = 32;        EntryDistance = 0;        TrailStopDistance    = 18;    TrailStopBegin = 18;  
                                            ProfitTargetPrice1 = Low[1] - (ProfitDistance1 * TickSize);        ProfitTargetPrice2 = Low[1] - (ProfitDistance2 * TickSize);        ProfitTargetPrice3 = Low[1] - (ProfitDistance3 * TickSize);
                                            CurrentTriggerPrice = Low[1] - (TrailStopBegin * TickSize);    CurrentStopPrice = High[1] + (1 * TickSize); AbsicherungsSL = Close[1];
                                            Print("SetupShort " + CurrentTriggerPrice + " " + CurrentStopPrice+ " H " + High[1] + " L " + Low[1]);    
                                            if (isNQMomentumTradingeinfachALL)                                            {    BuyShort();    }
                                            else if (isNQMomentumTradingeinfachab1 && SignaleNQ.momzaehlung[0] == -1)    {    BuyShort();    }
                                            else if (isNQMomentumTradingeinfachab2 && SignaleNQ.isTradingSerie[0])        {    BuyShort();    }
                                            else if (isNQMomentumTradingeinfachab3 && SignaleNQ.momzaehlung[0] == -3)    {    BuyShort();    }
                                        }
                                }​
    But i loose the Currentstop (Value) in "OnExecutionUpdate"

    Code:
     if (longEntry != null && longEntry == execution.Order)
                {
                    Print("OnExecutionUpdate1 " + CurrentTriggerPrice + " " + CurrentStopPrice+ " H " + High[1] + " L " + Low[1]);
                    if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
                    {
                        // We sum the quantities of each execution making up the entry order
                        sumFilledLong += execution.Quantity;
    
                        if (State == State.Historical)
                            oco = DateTime.Now.ToString() + CurrentBar + "LongExits";
                        else
                            oco = GetAtmStrategyUniqueId() + "LongExits";
                        Print("OnExecutionUpdate2 " + CurrentTriggerPrice + " " + CurrentStopPrice+ " H " + High[1] + " L " + Low[1]);
                        if (stopLossLong == null && targetLong == null )
                        {
    //                        CurrentTriggerPrice = (Close[0] + (TrailStopBegin * TickSize)) ;
                            SubmitOrderUnmanaged(1, OrderAction.Sell, OrderType.StopMarket, KaufMengeoco, 0, CurrentStopPrice, oco, "StopLossLong");
                            SubmitOrderUnmanaged(1, OrderAction.Sell, OrderType.Limit, KaufMengeoco, ProfitTargetPrice1, 0, oco, "TargetLong");
                        }
                        else
                        {
                            // Submit exit orders for partial fills
                            if (execution.Order.OrderState == OrderState.PartFilled)
                            {
                                ChangeOrder(stopLossLong, KaufMengeoco, 0, CurrentStopPrice);
                                ChangeOrder(targetLong, KaufMengeoco, ProfitTargetPrice1, 0);
                            }
                            // Update our exit order quantities once orderstate turns to filled and we have seen execution quantities match order quantities
                            else if (execution.Order.OrderState == OrderState.Filled && sumFilledLong == execution.Order.Filled)
                            {
                                 //Stop-Loss order for OrderState.Filled
                                ChangeOrder(stopLossLong, KaufMengeoco, 0, CurrentStopPrice);
                                ChangeOrder(targetLong, KaufMengeoco, ProfitTargetPrice1, 0);
                            }
                        }
    
                        // Resets the entryOrder object and the sumFilled counter to null / 0 after the order has been filled
                        if (execution.Order.OrderState != OrderState.PartFilled && sumFilledLong == execution.Order.Filled)
                        {
                            longEntry = null;
                            sumFilledLong = 0;
                        }
                    }
                }  ​
    Have anyone a idea whats the problem?


    #2
    Hello Dirales,

    Thank you for your post.

    In order to understand your script's behavior and how the CurrentStopPrice could be a value of 0, you will need to add prints throughout your script. Every time you update CurrentStopPrice you should add a print that prints out the value of CurrentStopPrice to make sure it was updated as expected. Also, before submitting your stop loss, you should add a print with its value to see if it is set to the expected value. For example:

    Code:
    if (stopLossLong == null && targetLong == null )
    {
    // CurrentTriggerPrice = (Close[0] + (TrailStopBegin * TickSize)) ;
    Print(Time[0] + " Submitting stop loss.  CurrentStopPrice: " + CurrentStopPrice);
    SubmitOrderUnmanaged(1, OrderAction.Sell, OrderType.StopMarket, KaufMengeoco, 0, CurrentStopPrice, oco, "StopLossLong");
    SubmitOrderUnmanaged(1, OrderAction.Sell, OrderType.Limit, KaufMengeoco, ProfitTargetPrice1, 0, oco, "TargetLong");
    }​
    For more information on using prints to debug your script:


    Please let us know if we may be of further assistaince.

    Comment


      #3
      Hello Emily,

      i have done this i my first post.

      Both Value CurrenttriggerPrice & CurrentStopPrice i loose in "OnExecutionUpdate" Click image for larger version

Name:	2023-09-06_15h49_30.png
Views:	128
Size:	24.8 KB
ID:	1267740

      Comment


        #4
        Hello Dirales,

        It is helpful to add labels to every value and comparison operator in a print so that it's clear what is being printed in the output.

        That said, is CurrentTriggerPrice and CurrentStopPrice defined in the scope of the class or is this defined in a method (such as OnBarUpdate and OnExecutionUpdate())?

        Are there other lines of code that assign these variables a value?
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        44 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        124 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        65 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