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

OnExecution event jumping back in time

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

    OnExecution event jumping back in time

    Hi,
    I'm loading a 1 minute DataSeries to a strategy running on 5 minute chart. I am submitting unmanaged orders to that 1 minute DataSeries within OnExecution when a trade entry execution occurs.
    I have been experiencing "stop order has been ignored" problems, and you can see from the debugging info below that while the trade entry fill has occurred at 13:04:00 (it was a working stop entry order), and the order is submitted to the DataSeries 'mbip' which is set to 1 to be the 1 Minute bars, and it shows a timestamp 1 minute earlier at 13:03:00. Then there is an 'ignore' error 4 minutes earlier at 1PM. You can see the stoploss order was placed 2 ticks below the latest known price on the 1 Minute DataSeries, so it should be cool.

    EXECUTION: execution='NT-00002-186' instrument='AUDUSD' account='Sim101' exchange=Default price=0.72037 quantity=1 marketPosition=Long orderId='NT-00018-186' time='2018-09-18 13:04:00' sod=False statementDate='0001-01-01'
    Fill Long at 0.72037, calculating initial StopLoss 0.71948 and final Profit Target 0.72067, latest minute Close is 0.7195
    18/09/2018 1:03:00 PM Strategy 'tzHighLow1/148934005': Entered internal SubmitOrderUnmanaged() method at 18/09/2018 1:03:00 PM: BarsInProgress=1 Action=Sell OrderType=StopLimit Quantity=1 LimitPrice=0.7194'8 StopPrice=0.7194'8 SignalName='LS'
    Strategy 'tzHighLow1/148934005': A Sell stop order placed at '18/09/2018 1:00:00 PM' has been ignored since the stop price is greater than or equal to the close price of the current bar. This is an invalid order and subsequent orders may also be ignored. Please fix your strategy.

    Is this behaviour from Ninja correct in your opinion?

    Thanks,
    saltminer

    #2
    Hello saltminer,
    Thanks for your post.

    This error basically means that something in your logic needs to be fixed. In real-time the order would have been rejected.This message is also pretty straight forward in telling you what you need to do to fix this. An idea on how to validate the stop prices was shared in this thread where the same topic was discussed.



    Please let me know if you have any questions.
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Hi,
      I respectfully disagree. This is in OnExecution event, and the order has just been filled and the code is taking action immediately. The stoploss is being set 89 ticks away from the fill price (which is the vicinity of where the bid/ask would be). This would not be rejected in realtime.

      saltminer

      Comment


        #4
        I've simplified the strategy, now it is using ONLY chart 1 minute bars. The entry is a stop order to go Long.
        Please refer to the screenshot. The working order is shown as cyan triangles, and it gets filled during the wicky bar that ends at 13:04.
        The stoploss is sent from OnExecution, 2 ticks below the last known price, which is the Close of the prior bar, but even that is not sufficient to evade the "ignore" error from NT8.
        I have shown the stoploss price that is attempted as a solid blue line.
        As far as I can see this is perfectly valid, but it is thwarted by Ninja for reasons I can't figure out.

        Cheers,
        saltminer

        EXECUTION: execution='NT-00002-193' instrument='AUDUSD' account='Sim101' exchange=Default price=0.72037 quantity=1 marketPosition=Long orderId='NT-00016-193' time='2018-09-18 13:04:00' sod=False statementDate='0001-01-01'
        Fill Long at 0.72037, calculating initial StopLoss 0.71947 and final Profit Target 0.72067, latest minute Close is 0.7195
        18/09/2018 1:03:00 PM Strategy 'tzHighLow1/148934005': Entered internal SubmitOrderUnmanaged() method at 18/09/2018 1:03:00 PM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0.7194'7 StopPrice=0.7194'7 SignalName='LS'
        Strategy 'tzHighLow1/148934005': A Sell stop order placed at '18/09/2018 1:03:00 PM' has been ignored since the stop price is greater than or equal to the close price of the current bar. This is an invalid order and subsequent orders may also be ignored. Please fix your strategy.
        18/09/2018 1:03:00 PM Strategy 'tzHighLow1/148934005': Ignored SubmitOrderUnmanaged() method at 18/09/2018 1:03:00 PM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0.7194'7 StopPrice=0.7194'7 SignalName='LS' FromEntrySignal='' Reason='Invalid order price, please see log tab'
        Attached Files

        Comment


          #5
          Can you please show your code that prevents your stop price from being greater than or equal to the close price of the current bar?

          In historical data the order's in the backtest are submitted to the next bar. Because of this you will need to verify that your order's price would not be invalid based on the current bar (0) and the next bar (-1). Please check the High and Low of those bars to be certain you are submitting your order at the price you believe you are.
          Last edited by NinjaTrader_JoshG; 10-03-2018, 08:19 AM.
          Josh G.NinjaTrader Customer Service

          Comment


            #6
            Hi,
            normally I just use GetLatestBid()-TickSize, or GetLatestAsk()+TickSize, and that acts as a proxy for the latest known Close price during Historical Bars, and works nicely in realtime.

            However because of the issues in this strategy I've changed it to check the next bar Open.


            double latestKnownBid = (State==State.Realtime || CurrentBars[0] == BarsArray[0].Count-1) ? GetCurrentBid() : BarsArray[0].GetOpen(CurrentBars[0]+1);
            double latestKnownAsk = (State==State.Realtime || CurrentBars[0] == BarsArray[0].Count-1) ? GetCurrentAsk() : BarsArray[0].GetOpen(CurrentBars[0]+1);


            double sl = rnd(Math.Min(latestKnownBid-TickSize*2,o.AverageFillPrice - measure*InitialStopLoss));
            However, although this is a relevant discussion, you can see from the log output I included in my prior email and the screenshot that the stoploss was correctly placed below the previous bar Close and below the next bar Open. So the real point to address is why did it trigger the 'ignored' error?

            You've mentioned to test the High and Low of the bar. Why?

            Although I'm not doing it at the moment, if I was getting filled on a high granularity bar (e.g. 1 minute) in BarsArray[1], and submitting the stoploss on the same, do I do the checks of the bar prices on BarsArray[1] or are the chart bars also a concern? (These may be much larger and slower)

            cheers,
            saltminer

            Comment


              #7
              why did it trigger the 'ignored' error?
              The order is at an invalid price, since a SellStop order can't be placed above the close of the bar or higher. That is the only reason for the ignored message.

              I suggest adding some Prints where you are setting the price so that you can see when the value is something you are not expecting. The following post has more information on debugging your NinjaScript with Print()



              You are correct that GetCurrentAsk/GetCurrentBid would work nicely in real time, but to use that in historical you will need to develop your script for Tick Replay. Otherwise the Close value will be substituted for the ask and bid, resulting in unexpected values in your logic.

              Help Guide - GetCurrentAsk()
              Help Guide - GetCurrentBid()
              Help Guide - Developing for Tick Replay

              double latestKnownBid = (State==State.Realtime || CurrentBars[0] == BarsArray[0].Count-1) ? GetCurrentBid() : BarsArray[0].GetOpen(CurrentBars[0]+1);
              double latestKnownAsk = (State==State.Realtime || CurrentBars[0] == BarsArray[0].Count-1) ? GetCurrentAsk() : BarsArray[0].GetOpen(CurrentBars[0]+1);
              Are you using this snippet in OnRender? Just curious why you chose to use GetOpen instead of just Open.

              Are you trying to get the current ask/bid for the 5 minute series or the 1 minute series?
              Josh G.NinjaTrader Customer Service

              Comment


                #8
                Hi,
                we're not on the same page. Please reread the initial post. I am placing a Sell Stop order BELOW the market.

                - entry fill (from a Buy Stop order) at 0.72037
                - latest bar close is found (within OnExecution) as 0.71950
                - Sell stop (for a stoploss) placed at 0.71947 and ignored

                EXECUTION: execution='NT-00002-193' instrument='AUDUSD' account='Sim101' exchange=Default price=0.72037 quantity=1 marketPosition=Long orderId='NT-00016-193' time='2018-09-18 13:04:00' sod=False statementDate='0001-01-01'
                Fill Long at 0.72037, calculating initial StopLoss 0.71947 and final Profit Target 0.72067, latest minute Close is 0.7195
                18/09/2018 1:03:00 PM Strategy 'tzHighLow1/148934005': Entered internal SubmitOrderUnmanaged() method at 18/09/2018 1:03:00 PM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0.7194'7 StopPrice=0.7194'7 SignalName='LS'

                I am using GetOpen for safety because I am in doing this in OnExecution(). In this version of the strategy there are only 1 minute chart bars and nothing else.

                cheers,
                saltminer

                Comment


                  #9
                  we're not on the same page. Please reread the initial post. I am placing a Sell Stop order BELOW the market.
                  Your intent is to place your stop loss at that price, but that is not what is occurring. This error message simply does not occur when the stop loss price is valid.

                  Have you verified that all of the variables inside latestKnownBid/latestKnownAsk are the value you believe they are? For one BarsArray[0].Count-1 will vary based on what Calculate setting you are using.
                  Can I please see your Print() where you are printing this information?

                  Also I noticed you are using some Math functions. What happens when you do not use the Math functions to round the number or Min the number. Have you printed both the rounded and unrounded version of that number?

                  Does the Print include what you have inside your rnd() method?

                  Code:
                  double sl = rnd(Math.Min(latestKnownBid-TickSize*2,o.AverageFillPrice - measure*InitialStopLoss));
                  Josh G.NinjaTrader Customer Service

                  Comment


                    #10
                    Hi Josh,
                    TraceOrder output confirms I am indeed placing the stoploss at a valid price (not just "intending" to).
                    • 18/09/2018 1:03:00 PM Strategy 'tzHighLow1/148934005': Entered internal SubmitOrderUnmanaged() method at 18/09/2018 1:03:00 PM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0.7194'7 StopPrice=0.7194'7 SignalName='LS'
                    This price is visible in the screenshot I provided, which is clearly BELOW any bar Close price in the price action.

                    rnd() is simply Instrument.MasterInstrument.RoundToTick, but in any case we don't have to diagnose this particular line to death. Let us simply discuss the stoploss price, submitted within OnExecution() and provably at 0.7194'7, which you can see in the screenshot in post #4 IS BELOW any bar Close.

                    I feel we are getting nowhere slowly. Please can you properly review this simple data. Why is a stoploss correctly below the bar Closes being ignored?

                    thank you,
                    ​​​​​​​saltminer

                    Comment


                      #11
                      Hello? This post still requires a response, based properly on the data within it. Please respond.

                      saltminer

                      Comment


                        #12
                        Hello saltminer,

                        Thank you for your patience.

                        I would ask that you provide a test strategy that reproduces the behavior. Please send a note to platformsupport[at]ninjatrader[dot]com with 'ATTN: Patrick H' in the subject line and reference to this thread in the body of the email. Please attach a strategy that reproduces this behavior to your response.

                        You can export your strategy by going to Tools > Export > NinjaScript Add On > Add > select your strategy > OK > Export > name the file 'NTsupport' > Save.

                        The file will be located under Documents\NinjaTrader 8\bin\Custom\ExportNinjaScript. Please attach the file to your response.

                        I look forward to assisting you further.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by bortz, 11-06-2023, 08:04 AM
                        47 responses
                        1,602 views
                        0 likes
                        Last Post aligator  
                        Started by jaybedreamin, Today, 05:56 PM
                        0 responses
                        8 views
                        0 likes
                        Last Post jaybedreamin  
                        Started by DJ888, 04-16-2024, 06:09 PM
                        6 responses
                        18 views
                        0 likes
                        Last Post DJ888
                        by DJ888
                         
                        Started by Jon17, Today, 04:33 PM
                        0 responses
                        4 views
                        0 likes
                        Last Post Jon17
                        by Jon17
                         
                        Started by Javierw.ok, Today, 04:12 PM
                        0 responses
                        12 views
                        0 likes
                        Last Post Javierw.ok  
                        Working...
                        X