Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtest data is different from live data

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

    #46
    overfills

    Originally posted by NinjaTrader_Matthew View Post
    No, you can work within the managed approach.

    If you switched the unmanaged approach, you would no longer receive these errors, however you can still find yourself in a situation where you have two orders which are attempting to fill at the same time. You would need to program your own order handling rules to prevent these situations from occurring with the unmanaged reproach and this is reserved for advanced programmers only.

    What would happen if I set the entries per direction to 2?

    Comment


      #47
      overfills

      Would setting Entries Per Direction to 2 possibly solve the issue?

      Jamie Hendrix

      Comment


        #48
        Hello,

        No, the entries per direction would not apply in this case.
        MatthewNinjaTrader Product Management

        Comment


          #49
          I just checked the Time Stamp (time and sales) and this computers' internal clock is a full 8 seconds behind the time stamps from the data provider (CQG) ... would this be the reason for the overfill condition?

          Comment


            #50
            Originally posted by JamieHendrix View Post
            I just checked the Time Stamp (time and sales) and this computers' internal clock is a full 8 seconds behind the time stamps from the data provider (CQG) ... would this be the reason for the overfill condition?
            Update your system clock.

            Double click the clock, look for internet time, change settings,

            windows.com never appears to work, time-a.nist.gov looks like it worked

            Comment


              #51
              Yeah I got the time all worked out and it is right on with the time stamps coming from the broker. I guess I will know if this fixed the problem tomorrow morning..... Just wanted to know if anyone had any insight as to whether this discrepancy would cause my overfill problem.

              Jamie Hendrix

              Comment


                #52
                Hello,

                I dont believe it would resolve it as reading matts analysis below you have two orders in the market filling at the same time to get to an overfill. You say however that the stop loss and profit target are the only thing you submit however there is an issue here with the orders. If the time does not resolve please send us your code to support at ninjatrader dot com and reference this forum post. We can take a quick look at the code to see what might be the overfill condition and offer correct advice on that code.

                -Brett
                BrettNinjaTrader Product Management

                Comment


                  #53
                  Here is a copy and paste of my code....

                  SetProfitTarget("", CalculationMode.Ticks, 1);
                  SetStopLoss("", CalculationMode.Ticks, 6, false);

                  CalculateOnBarClose = true;


                  }

                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>
                  protected override void OnBarUpdate()
                  {

                  // Prevents the strategy from executing on historical data.
                  if (Historical)
                  return;

                  // Stops trading when a specified profit target has been reached.
                  if (Performance.AllTrades.TradesPerformance.Points.Cu mProfit >= 40)
                  return;


                  // Stops trading when a specified loss target has been reached.
                  if (Performance.AllTrades.TradesPerformance.Points.Cu mProfit <= -9)
                  return;

                  // Exits an open Long position 60 seconds before market close.
                  if (Position.MarketPosition == MarketPosition.Long
                  && ToTime (Time [0]) >= 131400)
                  {
                  ExitLong();
                  }

                  // Exits an open Short position 60 seconds before market close.
                  if (Position.MarketPosition == MarketPosition.Short
                  && ToTime (Time [0]) >= 131400)
                  {
                  ExitShort();
                  }




                  // Condition set 1
                  if ( Rising (SMA (14))
                  && ToTime(Time[0]) >= 63000 && ToTime(Time[0]) <= 131000)
                  {
                  EnterLongLimit(1, Close [0] -1 *TickSize, "");
                  //PlaySound(@"C:\Program Files\NinjaTrader 7\sounds\Alert3.wav");
                  }

                  //if (Position.MarketPosition == MarketPosition.Long
                  // && Falling (SMA (14)))
                  //{
                  // ExitLong();
                  //}





                  // Condition set 2
                  if ( Falling (SMA (14))
                  && ToTime(Time[0]) >= 63000 && ToTime(Time[0]) <= 131000)
                  {
                  EnterShortLimit(Close [0] +1 *TickSize, "");
                  //PlaySound(@"C:\Program Files\NinjaTrader 7\sounds\Alert4.wav");
                  }

                  //if (Position.MarketPosition == MarketPosition.Short
                  // && Rising (SMA (14)))
                  //{
                  // ExitShort();
                  //}



                  // Plays alert when a profit target has been reached.
                  if (Performance.AllTrades.TradesPerformance.Points.Cu mProfit >=8)
                  {

                  PlaySound(@"C:\Program Files\NinjaTrader 7\sounds\AutoBreakEven.wav");
                  }

                  Thanks for your help. Jamie Hendrix

                  Comment


                    #54
                    Hello,

                    Thanks for supplying us with your code.

                    This is due to the limit order you have working near the market using SetProfitTarget("", CalculationMode.Ticks, 1);

                    What is occurring is when your exit signals are triggering, this profit target is very close to the market price which is causing both the exit and the profit target to fill around the same time.
                    MatthewNinjaTrader Product Management

                    Comment


                      #55
                      Matthew, I don't understand. When my entry is filled, I only have one working order to exit and that is the 1 tick "Profit Target" there are no other conflicting orders. The ExitLong and ExitShort are ignored with the "// "" I can delete those altogether, they are not used but the program should be ignoring them anyway.

                      Comment


                        #56
                        What about the condition set 2 where you have another limit order with EnterShortLimit(Close [0] +1 *TickSize, "");

                        If you comment this entry order out, do you still receive the over fill?
                        MatthewNinjaTrader Product Management

                        Comment


                          #57
                          Actually the condition sets are like this:

                          // Condition set 1
                          if ( Position.MarketPosition == MarketPosition.Flat
                          && Rising (SMA (14))
                          && ToTime(Time[0]) >= 63000 && ToTime(Time[0]) <= 131000)
                          {
                          EnterLongLimit(1, Close [0] -1 *TickSize, "");
                          //PlaySound(@"C:\Program Files\NinjaTrader 7\sounds\Alert3.wav");
                          }

                          //if (Position.MarketPosition == MarketPosition.Long
                          // && Close [0] < Position.AvgPrice -6 *TickSize)
                          //{
                          // ExitLong();
                          //}





                          // Condition set 2
                          if ( Position.MarketPosition == MarketPosition.flat
                          && Falling (SMA (14))
                          && ToTime(Time[0]) >= 63000 && ToTime(Time[0]) <= 131000)
                          {
                          EnterShortLimit(Close [0] +1 *TickSize, "");
                          //PlaySound(@"C:\Program Files\NinjaTrader 7\sounds\Alert4.wav");
                          }

                          //if (Position.MarketPosition == MarketPosition.Short
                          // && Close [0] > Position.AvgPrice +6 *TickSize)
                          //{
                          // ExitShort();
                          //}

                          The condition of if marketposition is flat should tell it not to place the order unless the position is flat... if I am long , the short signal in condition 2 should be ignored because I am not "flat"..... AM I right?

                          Comment


                            #58
                            Yes, if that is what is reflected in the OnBarUpdate event. However you should double check that this is where the account position actually is at this time. Since you're using COBC = true, the position will not be returned as flat/long/short until the next bar closes.
                            MatthewNinjaTrader Product Management

                            Comment


                              #59
                              OK. That makes more sense. I still don't understand why it only happens on one computer and not the other one but Oh Well anything that will fix the problem is fine with me.
                              So should I put the Position Flat statement in position update or order update or what? And would this solve the overfill problem?

                              Jamie Hendrix

                              Comment


                                #60
                                I don't believe it would completely prevent the overfills. The main issue is that you have orders being placed very close to market (1 tick). You should widen your stops and targets to prevent these overfills from occurring.
                                MatthewNinjaTrader Product Management

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by argusthome, 03-08-2026, 10:06 AM
                                0 responses
                                58 views
                                0 likes
                                Last Post argusthome  
                                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                                0 responses
                                39 views
                                0 likes
                                Last Post NabilKhattabi  
                                Started by Deep42, 03-06-2026, 12:28 AM
                                0 responses
                                19 views
                                0 likes
                                Last Post Deep42
                                by Deep42
                                 
                                Started by TheRealMorford, 03-05-2026, 06:15 PM
                                0 responses
                                21 views
                                0 likes
                                Last Post TheRealMorford  
                                Started by Mindset, 02-28-2026, 06:16 AM
                                0 responses
                                51 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Working...
                                X