Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Clearing orders EOD

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

    Clearing orders EOD

    Hi,

    I noticed some unexpected behavior in my strategy.

    It happens when in my strategy a order to buy/sell is generated on the last bar of the trading day. The trade is blocked by a ToTime(Time[0])< ...... timefilter in the same Enterlong/short statement (I don't enter new trades in the last half hour of the day).

    Now, when the next day starts, the trade of the previous day is executed on the close of the first bar of that day.

    It seems the trade of the previous day, which was blocked by the timefilter, was kept in some memory and executed when possible, being the next trading day.

    Is there any way to clear this 'memory' on the end of the day or beginning of the next day?

    Thanks!

    #2
    For clarification -

    On the last bar of the day, you do not call Enter() method since its filtered out, correct?

    If this is true, then this entry order can not be generated from this bar, it must be generated on a subsequent bar.

    You double check this by enabled TraceOrders and inspecting the Ouput window. There is a lot of information but it will show you the bar number/time the order was submitted on.
    RayNinjaTrader Customer Service

    Comment


      #3
      Hi Ray,

      It goes something like this:

      If Close[0]>Close[1] && ToTime(Time[0])< ToTime(15,30,00)
      {
      Enterlong();
      }

      The data I display in my chart is for instance of ES from 09:30 - 16:15, so only regular trading hours. Ofcourse there is additional data (pre/afterhours) coming in, but this is not shown in my chart.

      If Close[0]>Close[1] and Time= 16,15,00 the trade is blocked by the timefilter but executed the next day on the close of the first bar.

      I will look into the TraceOrder functionality. Maybe that will tell what's going on.

      Thanks

      Comment


        #4
        I suspect its not getting filtered out and you would need to take a look at your code and debug why.
        RayNinjaTrader Customer Service

        Comment


          #5
          Today I experienced another unexpected trade.

          I use a Strategy which is a simple crossover of Close with a shifted EMA to go long. The shifted EMA is also shown in my chart. There the Close was nowhere near the EMA when the longtrade was generated.

          When I backtest the Strategy and compare the entries and exits with the position of the shifted EMA, every trade is correct.

          This is the code to go long:

          protectedoverridevoid OnBarUpdate()
          {
          int LB=20;


          if (CurrentBar<LB) return;


          double Trend=EMA(Close,LB)[0];
          double Mom= EMA(Close,2)[0];

          if (CrossAbove(Close,1.1*Trend,1) && (ToTime(Time[0])<160000) && Close[0]>Mom)
          {
          EnterLong(
          1);
          }

          Does anyone see a mistake in my code which is responsible for the unexpected triggering of trades? I use this strategy also on other futures and noticed other unexpected behavior since a few days (see rest of thread). I'm still running on TWS 882, NT 6.5.1000.2

          Comment


            #6
            Are you using CalculateOnBarClose = false? Backtest results will differ from real-time trades. Please see this article: http://www.ninjatrader-support.com/H...sBacktest.html
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Hi Josh,

              Thank you for your response.

              Unfortunately CalculateOnBarClose= true in my Strategy, otherwise that would be a nice explanation.

              According to the backtest the Strategy seems to execute flawless. Yesterdays trade came totally 'out of the blue'. I understand your comment about difference between backtesting and actual trading. My problem however is not a case of unexpected slippage, it's a case of an unexpected trade.

              I will post if I have new information. Maybe it's not the Strategy which triggered the trade, but something else.

              Comment


                #8
                I recommend you use TraceOrders = true and watch the print logs. Try to match it with your mystery trade. If your strategy is actually placing a trade there has to be a reason it is placing it. Unfortunately we cannot assist you in the debugging process, but if there is an issue TraceOrders can generally find it.
                Josh P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by cls71, Today, 04:45 AM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by TradeForge, Today, 02:09 AM
                1 response
                22 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by elirion, Today, 01:36 AM
                2 responses
                14 views
                0 likes
                Last Post elirion
                by elirion
                 
                Started by DJ888, 04-16-2024, 06:09 PM
                5 responses
                14 views
                0 likes
                Last Post NinjaTrader_Erick  
                Started by samish18, Yesterday, 08:31 AM
                4 responses
                14 views
                0 likes
                Last Post elirion
                by elirion
                 
                Working...
                X