Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Live execution and weird stop/target prices

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

    Live execution and weird stop/target prices

    Hi,

    I have a problem in my strategy live execution. It uses a simple EnterLong/Short order in OnBarUpdate and puts a stop loss and profit target in OnExecution when entry is executed.

    When position is flat I reset the stop and target. After entry and stop/target of one or two traders, when a new entry is executed the stop and target are rejected with prices I have not set.

    Please advise.
    W.

    Some code :

    OnBarUpdate
    Code:
    if ( Position.MarketPosition == MarketPosition.Flat ) 
    {
        // reset stoploss and profittarget.
        SetStopLoss(CalculationMode.Ticks, 2*BarsPeriod.Value + 2);
        SetProfitTarget(CalculationMode.Ticks, 2*BarsPeriod.Value + 2);
        
        if ( entry condition.... )
        {
            entryLongOrder = EnterLong(OrderQuantity, "LONG");
        }
        else if ( ... )
        {
            entryShortOrder = EnterShort(OrderQuantity, "SHORT");
        }
    }
    OnExecution
    Code:
    if ( execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || 
         (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0) )
    {
        double stopPrice = 0;
        double targetPrice = 0;
        
        if ( Position.MarketPosition == MarketPosition.Long )                    
        {
            targetPrice = execution.Order.AvgFillPrice + (2 * BarsPeriod.Value - 2) * TickSize;
            stopPrice = execution.Order.AvgFillPrice - (2 * BarsPeriod.Value + 2) * TickSize;                    
    
            SetStopLoss("LONG", CalculationMode.Price, stopPrice, false);
            SetProfitTarget("LONG", CalculationMode.Price, targetPrice);
            ECILogger("Stop at " + stopPrice + " and Target at " + targetPrice + " submitted");                    
        }

    #2
    Hello wingman,

    Thank you for your post.

    In your OnExecution code, you set stopPrice and targetPrice to 0, you can use Print() to make sure your values are as expected when you use SetStopLoss() and SetProfitTarget() on these values to make sure they are still not 0 or an invalid price.

    If you don't have any luck with debugging your values with Print(), the following sample is a little more involved but it covers how to monitor stop loss and profit targets. Please see the following forum post: http://www.ninjatrader.com/support/f...ead.php?t=5790

    Please give the above a try and let me know if you still experience issues.
    DexterNinjaTrader Customer Service

    Comment


      #3
      Thank you Dexter,

      The logs indicate the price is not 0. Here is a small log below.
      Strategy is launched and crashed after rejecting a stop order at 112,14.
      Logs indicate price submission at 111,82 (Stop) 111,98 (target).

      I need to understand what works wrong before going to more complicated solutions using arrays. I use only one contract.

      Please advise again.

      W.

      26/04/2011 16:41:53 Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='' Mode=Ticks Value=10 Currency=0 Simulated=False
      26/04/2011 16:41:53 Entered internal SetStopTarget() method: Type=Target FromEntrySignal='' Mode=Ticks Value=10 Currency=0 Simulated=False
      26/04/2011 16:41:55 CL 06-11 Green bar detected, in Flat strategy. Submit Long entry
      26/04/2011 16:41:53 Entered internal PlaceOrder() method at 26/04/2011 16:41:53: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='LONG' FromEntrySignal=''
      26/04/2011 16:41:55 CL 06-11 Long entry submitted
      26/04/2011 16:41:55 CL 06-11 LONG executed at 111,92
      26/04/2011 16:41:53 Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='LONG' Mode=Price Value=111,82 Currency=0 Simulated=False
      26/04/2011 16:41:53 Entered internal SetStopTarget() method: Type=Target FromEntrySignal='LONG' Mode=Price Value=111,98 Currency=0 Simulated=False
      26/04/2011 16:41:53 Amended target order: Order='cc6ad7abf93c48c2ae882b25504d5b84/Sim101' Name='Profit target' State=PendingSubmit Instrument='CL 06-11' Action=Sell Limit price=111,98 Stop price=0 Quantity=1 Strategy='ECIRenkoTest2' Type=Limit Tif=Gtc Oco='68db35aa0e444efea592f4a7f3ff24c6-1281' Filled=0 Fill price=0 Token='cc6ad7abf93c48c2ae882b25504d5b84' Gtd='01/12/2099 00:00:00'
      26/04/2011 16:41:55 CL 06-11 Stop at 111,82 and Target at 111,98 submitted
      **NT** Strategy 'ECIRenkoTest2/a336e14538274fa995dafbbabaafa909' submitted an order that generated the following error 'OrderRejected'. Strategy has sent cancel requests, attempted to close the position and terminated itself.
      26/04/2011 16:41:53 CancelAllOrders: BarsInProgress=0
      26/04/2011 16:41:55 CL 06-11 Profit target cancelled
      26/04/2011 16:41:54 Entered internal PlaceOrder() method at 26/04/2011 16:41:54: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Close' FromEntrySignal=''
      26/04/2011 16:41:55 CL 06-11 Close executed at 111,9
      26/04/2011 16:41:54 Disable() called: strategy disabled
      26/04/2011 16:41:54 CancelAllOrders: BarsInProgress=0
      **NT** Disabling NinjaScript strategy 'ECIRenkoTest2/a336e14538274fa995dafbbabaafa909'

      Comment


        #4
        Hi wingman,

        Thank you for clarifying,

        OrderRejected can occur for a handful of reasons. This is most commonly caused by submitting buy stop orders below the current price, stop orders above the current price (backwards stoplosses), not having enough available account balance, etc.

        So I am able to assist you further, please email your log and trace files to support at ninjatrader.com . This can be done from within NinjaTrader's control center, Help->Mail to Support, check "log and trace files" and put "ATTN: Dexter" in the subject.

        You can also manually email support at ninjatrader.com with your mail client and attach the files manually:

        You will find the log file in the Documents > NinjaTrader 7 > Log folder.
        The log file will be named ‘log.YYYYMMDD.txt’

        You will find the trace file in the Documents > NinjaTrader 7 > Trace folder.
        The trace file will be named ‘trace.YYYYMMDD.txt’

        Reference this post and I will follow up with you once I have this additional information.
        DexterNinjaTrader Customer Service

        Comment


          #5
          Hi Dexter,

          I am putting my answer here so everybody can share/comment.

          Again thank you for you help.

          I hardcoded the bars value but... no change.

          If of any use : my yesterday message sent on 10:53 shows the prices were set ok :

          OnExecution confirms a LONG execution at 16:41 at 111,92 .
          >26/04/2011 16:41:55 CL 06-11 LONG executed at 111,92
          Immediately in OnExecution we set Stop and Profit at 8 and -10 ticks : 111,82 and 111,98 : the print and calculation is ok
          >26/04/2011 16:41:53 Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='LONG' Mode=Price Value=111,82 Currency=0 Simulated=False
          >26/04/2011 16:41:53 Entered internal SetStopTarget() method: Type=Target FromEntrySignal='LONG' Mode=Price Value=111,98 Currency=0 Simulated=False
          >26/04/2011 16:41:53 Amended target order: Order='cc6ad7abf93c48c2ae882b25504d5b84/Sim101' Name='Profit target' State=PendingSubmit Instrument='CL 06-11' Action=Sell Limit price=111,98 Stop price=0 Quantity=1 Strategy='ECIRenkoTest2' Type=Limit Tif=Gtc Oco='68db35aa0e444efea592f4a7f3ff24c6-1281' Filled=0 Fill price=0 Token='cc6ad7abf93c48c2ae882b25504d5b84' Gtd='01/12/2099 00:00:00'
          >26/04/2011 16:41:55 CL 06-11 Stop at 111,82 and Target at 111,98 submitted
          Order is then rejected with *112,14* : very far from the 111,82 and 111,98 stop/profit set earlier.

          Where did this 112,14 came from ?

          Note : I use only one simulation account. I reset it completely before use, then flatten everything, then check there is no position open.

          W.

          Comment


            #6
            Hello wingman,

            I just followed up with you in the email you sent in, look for my response there. Thank you
            DexterNinjaTrader Customer Service

            Comment


              #7
              Thank you Dexter. I will look at that this WE.

              Meanwhile, I have reprogrammed exit orders (nothing else) to use Exit instead of the Set stop and profit orders. And it works fine.

              W.

              Comment


                #8
                Hello wingman,

                Sounds good, just let us know if we can assist any further.
                DexterNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Dexter View Post
                  OrderRejected can occur for a handful of reasons. This is most commonly caused by submitting buy stop orders below the current price, stop orders above the current price (backwards stoplosses), not having enough available account balance, etc.
                  Dexter,

                  Is there any way to get the detailed reason why a particular order has been rejected? Is there a Status field or Secondary Status field that's maintained anywhere that would contain this data, or is this information not reported by the exchange or just thrown away?

                  If not currently available, could this be added in future releases of NinjaTrader?

                  Thanks.

                  Comment


                    #10
                    Hi KBJ,

                    If order rejection information is available, it will be entered into the order's trace file entry.

                    For example, it is populated in Native error here:

                    2011-04-26 02:25:45:914 (ZenFire) Cbi.Connection.ProcessEventArgs.OrderStatusEventAr gs: Order='6539d5c2fc10426fae9194019f34a9e1/CLRenkoSimulation' Name='Stop loss' New state=Rejected Instrument='CL 06-11' Action=Sell Limit price=0 Stop price=112,08 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=OrderRejected Native error='Sell stop or sell stop limit orders can't be placed above the market.'
                    DexterNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    649 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    370 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    109 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    574 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    576 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X