Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Market Replay and Live Sim significantly different...

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

    #16
    BigDog008, each part plays an important role in your decision when a strategy has 'survived' enough stress tests to take it live...though from your last comment it seems it does not trigger / cancel your orders as you would expect it - did you notice any errors in the TraceOrders output you used? Did you debug your order placement conditions and cancellations with Print statements? Maybe it would be good to simplify the code first and then compare the results you get from placing for example one entry limit order only and then move on. This way you can get a feel how much of the dicrepancy is due to simulated fills or your code used.

    Comment


      #17
      Bertrand,

      I don't see any errors pop up in the replay thats the issue... I'm taking both long and shorts during replay...

      its when I do the live sim where I'm getting thrown off

      Comment


        #18
        I see BigDog and I guess you didn't spot any error in the Tracelog for the live simulation either? Is your strategy vs account position correctly in sync?

        Comment


          #19
          Bertrand,

          I broke it down into a one lot in each direction.....

          Again... even though conditions are met to go Long... it's only taking short orders....

          Code:
          {
              /// <summary>
              /// 
              /// </summary>
              [Description("LimitOrderTest")]
              public class LimitOrderTest : Strategy
              {
                  #region Variables
                  
                  private IOrder longentryOrderA          = null; 
                  private IOrder longstopOrderA          = null; 
                  private IOrder longtargetOrderA      = null;
                  
                  
                  private IOrder shortentryOrderA      = null;
                  private IOrder shortstopOrderA       = null;
                  private IOrder shorttargetOrderA     = null;
          
              
                  #endregion
          
                  /// <summary>
                  /// This method is used to configure the strategy and is called once before any strategy method is called.
                  /// </summary>
                  protected override void Initialize()
                  {
                      EntriesPerDirection = 1;
                      EntryHandling = EntryHandling.UniqueEntries; 
                      CalculateOnBarClose = false;
                      TraceOrders = false;
                  }
                  
                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>
                  protected override void OnBarUpdate()
                  {
                      if (Historical)
                          return;
                      
                      
                      // BUY MODE
                      if (longentryOrderA == null
                          && Position.MarketPosition == MarketPosition.Flat
                          && Low[1] > Low[2] 
                          && High[1] > High[2])
                      {
                          longentryOrderA = EnterLongLimit(0, true, DefaultQuantity, GetCurrentBid() - 1 * TickSize, "LongA");
                      }
                      
                      // LONG ORDER A CANCELLATION
                      if (longentryOrderA != null
                          && longentryOrderA.OrderState != OrderState.Filled
                          && longentryOrderA.LimitPrice < GetCurrentAsk() - 2 * TickSize)
                      {
                          CancelOrder(longentryOrderA);
                          longentryOrderA = null;
                      }
                      
                      
                      // SELL MODE
                      if (shortentryOrderA == null
                          && Position.MarketPosition == MarketPosition.Flat
                          && High[1] < High[2]
                          && Low[1] < Low[2])
                      {
                          shortentryOrderA = EnterShortLimit(0, true, DefaultQuantity, GetCurrentAsk() + 1 * TickSize, "ShortA");
                      }
                      
                      // SHORT ORDER A CANCELLATION
                      if (shortentryOrderA != null
                          && shortentryOrderA.OrderState != OrderState.Filled
                          && shortentryOrderA.LimitPrice > GetCurrentBid() + 2 * TickSize)
                      {
                          CancelOrder(shortentryOrderA);
                          shortentryOrderA = null;
                      }
                      
          
                      // LONG ORDER BREAKEVEN STOPLOSS
                          if (longentryOrderA != null
                              && longstopOrderA != null)    
                          {
                              if (longentryOrderA.AvgFillPrice + 3 * TickSize <= GetCurrentAsk() && longstopOrderA.StopPrice <= longentryOrderA.AvgFillPrice)
                              {
                                  longstopOrderA = ExitLongStop(0, true, longstopOrderA.Quantity, longentryOrderA.AvgFillPrice + 1 * TickSize, "LongStopA", "LongA");
                              }
                              if (longentryOrderA.AvgFillPrice + 5 * TickSize <= GetCurrentAsk() && longstopOrderA.StopPrice <= longentryOrderA.AvgFillPrice + 1 * TickSize)
                              {
                                  longstopOrderA = ExitLongStop(0, true, longstopOrderA.Quantity, longentryOrderA.AvgFillPrice + 3 * TickSize, "LongStopA", "LongA");
                              }
                          }                
          
                      // SHORT ORDER BREAKEVEN STOPLOSS
                          if (shortentryOrderA != null
                              && shortstopOrderA != null)
                          {
                              if (shortentryOrderA.AvgFillPrice - 3 * TickSize >= GetCurrentBid() && shortstopOrderA.StopPrice >= shortentryOrderA.AvgFillPrice)
                              {
                                  shortstopOrderA = ExitShortStop(0, true, shortstopOrderA.Quantity, shortentryOrderA.AvgFillPrice - 1 * TickSize, "ShortStopA", "ShortA");
                              }
                              if (shortentryOrderA.AvgFillPrice - 5 * TickSize >= GetCurrentBid() && shortstopOrderA.StopPrice >= shortentryOrderA.AvgFillPrice - 1 * TickSize)
                              {
                                  shortstopOrderA = ExitShortStop(0, true, shortstopOrderA.Quantity, shortentryOrderA.AvgFillPrice - 3 * TickSize, "ShortStopA", "ShortA");
                              }
                          }
                          
                          
                  }
          
                  /// <summary>
                  /// Called on each incoming order event
                  /// </summary>
                  protected override void OnOrderUpdate(IOrder order)
                  {
                      // HANDLE ORDER UPDATES FOR LONGA
                      // Entry
                      if (longentryOrderA != null && longentryOrderA.Token == order.Token)
                      {    
                          if (order.OrderState == OrderState.Cancelled)
                          {
                              longentryOrderA = null;
                              Print ("Entry Cancelled - LongEntryA Null");
                              Print ("");
                          }
                      }
                      
                      // Target
                      if (longtargetOrderA != null && longtargetOrderA.Token == order.Token)
                      {    
                          if (order.OrderState == OrderState.Filled
                              || order.OrderState == OrderState.Cancelled)
                          {
                              longtargetOrderA = null;
                              longentryOrderA = null;
                              Print ("LongEntryA and LongTargetA Null");
                              Print ("Target Filled, Stop Cancelled");
                              Print ("");
                              longstopOrderA = null;
                          }
                      }
                      
                      // Stop
                      if (longstopOrderA != null && longstopOrderA.Token == order.Token)
                      {    
                          if (order.OrderState == OrderState.Filled
                              || order.OrderState == OrderState.Cancelled)
                          {
                              longstopOrderA = null;
                              longstopOrderA = null;
                              Print ("LongEntryA and LongStopA Null");
                              Print ("Stop Filled, Target Cancelled");
                              Print ("");
                              longtargetOrderA = null;
                          }
                      }
                      
                      // HANDLE ORDER UPDATES FOR SHORT A
                      // Entry
                      if (shortentryOrderA != null && shortentryOrderA.Token == order.Token)
                      {    
                          if (order.OrderState == OrderState.Cancelled)
                          {
                              shortentryOrderA = null;
                              Print ("Entry Cancelled - ShortEntryA Null");
                              Print ("");
                          }
                      }
                      
                      // Target
                      if (shorttargetOrderA != null && shorttargetOrderA.Token == order.Token)
                      {    
                          if (order.OrderState == OrderState.Filled
                              || order.OrderState == OrderState.Cancelled)
                          {
                              shorttargetOrderA = null;
                              shortentryOrderA = null;
                              Print ("ShortEntryA and ShortTargetA Null");
                              Print ("Target Filled, Stop Cancelled");
                              Print ("");
                              shortstopOrderA = null;
                          }
                      }
                      
                      // Stop
                      if (shortstopOrderA != null && shortstopOrderA.Token == order.Token)
                      {    
                          if (order.OrderState == OrderState.Filled
                              || order.OrderState == OrderState.Cancelled)
                          {
                              shortstopOrderA = null;
                              shortentryOrderA = null;
                              Print ("ShortEntryA and ShortStopA Null");
                              Print ("Stop Filled, Target Cancelled");
                              Print ("");
                              shorttargetOrderA = null;
                          }
                      }
                  }
                  
                  /// <summary>
                  /// Called on each incoming execution
                  /// </summary>
                  protected override void OnExecution(IExecution execution)
                  {
                      // LONG ORDER A STOP AND TARGET
                      if (longentryOrderA != null && longentryOrderA.Token == execution.Order.Token)
                      {
                          if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
                          {
                              longstopOrderA     = ExitLongStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - 4 * TickSize, "LongStopA", "LongA");
                              longtargetOrderA = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + 6 * TickSize, "LongTargetA", "LongA");
                          }
                      }
                      
                      // SHORT ORDER A STOP AND TARGET
                      if (shortentryOrderA != null && shortentryOrderA.Token == execution.Order.Token)
                      {
                          if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
                          {
                              shortstopOrderA = ExitShortStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + 4 * TickSize, "ShortStopA", "ShortA");
                              shorttargetOrderA = ExitShortLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - 6 * TickSize, "ShortTargetA", "ShortA");
                          }
                      }
                  }
          
                  #region Properties
                  #endregion
              }
          }

          Comment


            #20
            and this is being tested with the ES 9-09 contract

            Comment


              #21
              BigDog,

              Code:
              if (longentryOrderA == null
                              && Position.MarketPosition == MarketPosition.Flat
                              && Low[1] > Low[2] 
                              && High[1] > High[2])
                          {
                              longentryOrderA = EnterLongLimit(0, true, DefaultQuantity, GetCurrentBid() - 1 * TickSize, "LongA");
                          }
              This might get you in a bar later than you would expect - have you tried changing this to -

              Code:
              if (longentryOrderA == null
                              && Position.MarketPosition == MarketPosition.Flat
                              && Low[0] > Low[1] 
                              && High[0] > High[1])
                          {
                              longentryOrderA = EnterLongLimit(0, true, DefaultQuantity, GetCurrentBid() - 1 * TickSize, "LongA");
                          }
              If you could attach or send me the strategy as a zip, I'll let it run on my ES 09-09 and check what I find...

              Comment


                #22
                email sent...

                for what its worth, I'm trying this on both 2Range and 89 tick

                Comment


                  #23
                  BigDog, just got a long trade generated from your strategy - here are a few things I noticed,

                  - TraceOrders were off > this omits valuable debug info, such running into the Internal Order Rules, which some of your orders hit

                  - RealTimeErrorHandling off > not recommended, if you set this to TakeNoAction you would have to code out your own order rejection handling and correct for occuring complications while running your strategy

                  - placed orders also get easily cancelled before having a change to execute as you cancel then if they move + - 2 ticks, so maybe add more cushion to see more trades filling

                  Comment


                    #24
                    Bertrand,

                    what bar size were you using?

                    Comment


                      #25
                      BigDog, tested it on 50 / 89 ticks on the ES 09-09.

                      Comment


                        #26
                        ok, I will make the adjustments you mentioned...

                        also, did you change from Low[1]>Low[2] to 0 and 1 respectively?

                        Comment


                          #27
                          No, I just ran the original code you send in...

                          Comment


                            #28
                            Still same problem...

                            again, clearly conditions are met for going Long, but no long trades...

                            i don't even see them working

                            see attached picture
                            Attached Files

                            Comment


                              #29
                              BigDog, when I tested this there were both long and short orders.

                              Please see attached.

                              EDIT: You may want to have something draw when your conditions are true. Maybe something like DrawDot right above/below the bar for long/short entries.
                              Attached Files
                              Last edited by NinjaTrader_Austin; 07-16-2009, 10:10 AM.
                              AustinNinjaTrader Customer Service

                              Comment


                                #30
                                Austin, was this in live sim or market replay?

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                647 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                367 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                108 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                571 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                573 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X