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

Tick Replay in Strategy Analyser is skipping the candle shadows to fill an order

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

    Tick Replay in Strategy Analyser is skipping the candle shadows to fill an order

    I get an issue with incorrect orders filling if I use the "tick reply" in the strategy analyzer.
    The strategy set up a buy stop order at price 2913. The high of a candle is above 2913, but the order didn't fill. The order filled only after the close of a candle hit the order price. Why?

    The order fills correctly when I don't use a tick reply. See the pics. Thanks.

    Code:
            protected override void OnBarUpdate()
            {
                if( CurrentBar < 10 ) return;
    
                //if( IsFirstTickOfBar == false ) return;
                DateTime date1 = new DateTime(2018, 9, 20, 10, 15, 0);
    
                if ( /*CurrentBar == 110*/ Time[0] == date1  && IsFirstTickOfBar )
                {
    
                    double price = GetCurrentAsk()+10*TickSize;
                    Print(string.Format("{0},  bid: {1}, Ask: {2}, Entry At: {3}", Time[0], GetCurrentBid(), GetCurrentAsk(), price));
    
                    myOrder = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.StopMarket, 1, 0, price);            
                }
    
    
                if( myOrder != null )
                {
                     Print(string.Format("{0},  bid: {1}, Ask: {2}, Fill At: {3}, state: {4}", Time[0], GetCurrentBid(), GetCurrentAsk(), myOrder.AverageFillPrice,  myOrder.OrderState.ToString()));
                     if( ReasonToDeleteOrder(myOrder) > 0 )
                       myOrder = null;
                }
            }
    
    
    
            protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled,
              double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
            {
                  Print(string.Format("{0}  OnOrderUpdate(): {1} {2}, averageFillPrice: {3}, nativeError: {4}, state: {5}", Time[0], order.Name, order.OrderAction, averageFillPrice, nativeError, order.OrderState.ToString()));                                            
    
                  double pr = limitPrice != 0.0 ? limitPrice : stopPrice;
                  if( pr == 0.0 ) pr = GetCurrentBid();
                  Draw.Dot(this, "orderUpd" + CurrentBar + " " + order.OrderId, true, Time[0], pr, Brushes.Aqua);
            }

    #2
    Hello Lender,

    I would have to make modifications to the script to test and reproduce. I can't hit the exact case you are with the code provided.

    I do have some questions so we can troubleshoot further.

    Do you see this when submitting orders to a single tick data series? I've attached an example Unmanaged strategy with intrabar granularity added.

    Backtesting with intrabar granularity - https://ninjatrader.com/support/help...ipt_strate.htm

    Is there a more recent occurrence where this can be tested? I do not have access to Tick Replay for ES 09-18 going that far back. If we could test more recent dates on a recent contract month, I could test on my end as well.

    With more recent dates that we can test, could you include an export of the strategy so I can import and test without modification?

    I look forward to being of further assistance.
    Attached Files
    JimNinjaTrader Customer Service

    Comment


      #3
      I think the problem is because I don't use another DataSeries for intra bar filling.
      Maybe the strategy analyzer ignore the "Order fill resolution" when we check the "Tick replay"

      It is strange when you see upcoming ticks through OneMarketData() but the order does not fill.

      Thanks for the reply.
      Attached Files
      Last edited by Lender; 10-20-2018, 08:07 AM.

      Comment


        #4
        Hello Lender,

        I would ultimately recommend using intrabar granularity with a Tick Replay strategy so you can have order submissions simulated with the intrabar data. Tick Replay will effect how the strategy calculates, but this does not effect order fill simulation which uses historical OHLC values.

        The items that should be looked at when testing would be the OHLC values for when the order was placed and when that order has been filled. The bar in which the order is submitted will effect the bar that is used to fill the order.

        In your attached sample, the price is submitted at High[0]+3 * TickSize which would not be the same thing testing OnBarClose (Tick Replay off) or with OnPriceChange/OnEachTick (Tick Replay on.) Calculating on IsFirstTickOfBar will reference the iterating bar (just the opening tick) instead of the previous bar's high. Checking IsFirstTickOfBar with High[1] on a strategy with Calculate/OnEachTick/OnPriceChange will represent High[0] with Calculate.OnBarClose.

        I have included a demonstration to observe order submissions taken place at the same time/price, however we can still see that the bar where the execution marker is plotted is different due to how the bar develops with Tick Replay. This would be a visual difference using Tick Replay while the order fill would be associated with the data series it was filled against.

        Demo - https://drive.google.com/file/d/1E69...w?usp=drivesdk

        Please let us know if you have any additional questions.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ghoul, Today, 06:02 PM
        3 responses
        13 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        44 views
        0 likes
        Last Post jeronymite  
        Started by Barry Milan, Yesterday, 10:35 PM
        7 responses
        20 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by AttiM, 02-14-2024, 05:20 PM
        10 responses
        180 views
        0 likes
        Last Post jeronymite  
        Started by DanielSanMartin, Yesterday, 02:37 PM
        2 responses
        13 views
        0 likes
        Last Post DanielSanMartin  
        Working...
        X