Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy is executing differently depending on the start date I choose.

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

    #16
    Originally posted by tgn55 View Post
    Hey Danilod,
    as Jesse noted in post #12, you should first resolve the issue re EntriesPerDirection exceeded on 3/1 at 6:30 AM.

    This could be simply increasing that value... but, since we don't know the details of your strategy, please confirm that your strategy really is expected to open a second position before the first position is closed... If the answer is "yes"... then increasing EntriesPerDirection above 1 should fix it. If the answer is "No"... then maybe your strategy logic has a problem.

    Next, your code is trying to exit a position when there is no position... so either you are flat, or, I think this error could also be triggered if you used method signatures with signal names... I see your exit orders have a signal name... do you also provide signal names with your entries? And if so do they always match up? By which I mean, you are requesting to exit a position with a matching entry signal. This seems a long shot... as sometimes trades happen... and sometimes not, so I'm guessing this code is kosher. But.. worth confirming.

    Which just leaves the question... can your code execute the exit logic when you are flat? Obviously... it shouldn't!

    Cheers,
    T.
    Thanks TGN55,
    I only have one Entry condition and the entry name is "EntryLong". Here what appears in strategy builder in the exit condition:

    Click image for larger version

Name:	Exit.png
Views:	78
Size:	11.2 KB
ID:	1165542

    I am aware about the Entries PerDirection configuration. But as far as I can see, in both cases there was an open order at 03/01/2021 12:05:PM , Why on one case it exited at that time and on the other didn't.. Take a look:

    This is the execution on the backtest with "Start date = 03/01/2021"
    Click image for larger version

Name:	03012021.png
Views:	74
Size:	885.7 KB
ID:	1165540

    This is the output log:
    Code:
    7/28/2021 11:42:44 AM Strategy 'RSIBollingerU/-1': Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='' Mode=Ticks Value=400 IsSimulatedStop=False IsMarketIfTouched=False
    7/28/2021 11:42:44 AM Strategy 'RSIBollingerU/-1': Entered internal SetStopTarget() method: Type=Target FromEntrySignal='' Mode=Ticks Value=600 IsSimulatedStop=False IsMarketIfTouched=False
    3/1/2021 12:00:00 AM Strategy 'RSIBollingerU/-1': Entered internal SubmitOrderManaged() method at 3/1/2021 12:00:00 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EntryLong' FromEntrySignal=''
    3/1/2021 6:30:00 AM Strategy 'RSIBollingerU/-1': Entered internal SubmitOrderManaged() method at 3/1/2021 6:30:00 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EntryLong' FromEntrySignal=''
    3/1/2021 6:30:00 AM Strategy 'RSIBollingerU/-1': Ignored SubmitOrderManaged() method at 3/1/2021 6:30:00 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EntryLong' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
    3/1/2021 8:10:00 AM Strategy 'RSIBollingerU/-1': Entered internal SubmitOrderManaged() method at 3/1/2021 8:10:00 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EntryLong' FromEntrySignal=''
    3/1/2021 8:10:00 AM Strategy 'RSIBollingerU/-1': Ignored SubmitOrderManaged() method at 3/1/2021 8:10:00 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EntryLong' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
    3/1/2021 12:00:00 PM Strategy 'RSIBollingerU/-1': Entered internal SubmitOrderManaged() method at 3/1/2021 12:00:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Exit_Long_RSI' FromEntrySignal=''
    3/1/2021 12:00:00 PM-76.137991129318
    3/1/2021 12:00:00 PM Strategy 'RSIBollingerU/-1: Cancelled pending exit order, since associated position is closed, orderId='NT-00002-288' account='Backtest' name='Profit target' orderState=Working instrument='YM 09-21' orderAction=Sell orderType='Limit' limitPrice=31498 stopPrice=0 quantity=1 tif=Gtc oco='NT-00000-288' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2021-03-01 00:00:00' gtd='2099-12-01' statementDate='2021-07-28'
    3/1/2021 12:00:00 PM Strategy 'RSIBollingerU/-1: Cancelled pending exit order, since associated position is closed, orderId='NT-00001-288' account='Backtest' name='Stop loss' orderState=Working instrument='YM 09-21' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=30498 quantity=1 tif=Gtc oco='NT-00000-288' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2021-03-01 00:00:00' gtd='2099-12-01' statementDate='2021-07-28'
    3/1/2021 12:05:00 PM Strategy 'RSIBollingerU/-1': Entered internal SubmitOrderManaged() method at 3/1/2021 12:05:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Exit_Long_RSI' FromEntrySignal=''
    3/1/2021 12:05:00 PM Strategy 'RSIBollingerU/-1': Ignored SubmitOrderManaged() method at 3/1/2021 12:05:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Exit_Long_RSI' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'
    3/1/2021 12:05:00 PM-76.137991129318
    3/1/2021 12:10:00 PM Strategy 'RSIBollingerU/-1': Entered internal SubmitOrderManaged() method at 3/1/2021 12:10:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Exit_Long_RSI' FromEntrySignal=''
    3/1/2021 12:10:00 PM Strategy 'RSIBollingerU/-1': Ignored SubmitOrderManaged() method at 3/1/2021 12:10:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Exit_Long_RSI' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'
    3/1/2021 12:10:00 PM-76.137991129318
    3/1/2021 12:15:00 PM Strategy 'RSIBollingerU/-1': Entered internal SubmitOrderManaged() method at 3/1/2021 12:15:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Exit_Long_RSI' FromEntrySignal=''
    3/1/2021 12:15:00 PM Strategy 'RSIBollingerU/-1': Ignored SubmitOrderManaged() method at 3/1/2021 12:15:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Exit_Long_RSI' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'
    3/1/2021 12:15:00 PM-76.137991129318
    3/1/2021 12:20:00 PM Strategy 'RSIBollingerU/-1': Entered internal SubmitOrderManaged() method at 3/1/2021 12:20:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Exit_Long_RSI' FromEntrySignal=''
    3/1/2021 12:20:00 PM Strategy 'RSIBollingerU/-1': Ignored SubmitOrderManaged() method at 3/1/2021 12:20:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Exit_Long_RSI' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'
    3/1/2021 12:20:00 PM-76.137991129318
    3/1/2021 12:25:00 PM Strategy 'RSIBollingerU/-1': Entered internal SubmitOrderManaged() method at 3/1/2021 12:25:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Exit_Long_RSI' FromEntrySignal=''
    3/1/2021 12:25:00 PM Strategy 'RSIBollingerU/-1': Ignored SubmitOrderManaged() method at 3/1/2021 12:25:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Exit_Long_RSI' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'
    3/1/2021 12:25:00 PM-76.137991129318
    3/1/2021 12:30:00 PM Strategy 'RSIBollingerU/-1': Entered internal SubmitOrderManaged() method at 3/1/2021 12:30:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Exit_Long_RSI' FromEntrySignal=''
    3/1/2021 12:30:00 PM Strategy 'RSIBollingerU/-1': Ignored SubmitOrderManaged() method at 3/1/2021 12:30:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Exit_Long_RSI' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'
    3/1/2021 12:30:00 PM-76.137991129318
    This is the execution on the backtest with start date 02/25/2021

    Click image for larger version

Name:	02252021.png
Views:	74
Size:	1.04 MB
ID:	1165541
    Let's take a look at the difrerences:

    Trade 1)
    - The first order (2/25) was not before (this is OK as the start date in the previous example was 3/31)

    Trade 2)
    - Entry: entry time is on 28/2, (instead of 3/1 as in the previous example. This is OK. It entered before because the earlier start date was letting this happen)
    - Exit: - This is what I don't understand- Why the exit in this case is on 3/4/2021 3:45pm while the exit in the previous example was 03/1 12:05pm? In both cases there was one order opened.

    Here is the output: ( I am adding it as a screenshot to avoid exceding number of characters in the post)

    Click image for larger version

Name:	Output.png
Views:	76
Size:	1.36 MB
ID:	1165543

    Thanks again to all of you,
    Attached Files

    Comment


      #17
      Danilod,
      I can now see something of concern... your backtest is on a 5 minute series starting on 3/1... and your first trade occurs at 12:05 AM on 3/1. That's the very first bar! So it seems you do not have anything in your code to address my previous point about ensuring all indicators have "settled down"... which is achieved by using the BarsRequiredToTrade parameter... which should be at least as large as the period parameter of your RSI (or any other indicator you include... which seems to be EMA). This can/should be set inside your strategy code, the "should" meaning, if you run with variable RSI periods... then your code needs to adjust BarsRequiredToTrade accordingly. Plus... you need a bit of code to skip if CurrentBar is less than BarsRequiredToTrade.

      First, add something like this in your State.SetDefaults or State.Configure:
      Code:
      BarsRequiredToTrade = EMA_Period;  // technically, should be the MAX of your EMA and RSI periods
      Then, ensure you have this bit of code in OnBarUpdate:
      Code:
       if (CurrentBar < BarsRequiredToTrade)
         return;
      You need to sort out basics like this... and also address the error message about max entries exceeded (if that still exists)... BEFORE moving on. Clean up what you can, then see what remains.

      FYI... if you do this correctly, your FIRST trade should not occur until AT LEAST 4:10 AM on the start date ... not 12:05 AM (if you are using 5 min bars) ;-)

      PS... Previous caution about EMA settle period in my post #3 clearly applies. EMA(50 period) uses data from bars prior to 50 bars back... so if you really want no surprises in your backtest results, best to increase BarsRequiredToTrade to something even larger.

      T.
      Last edited by tgn55; 07-28-2021, 09:44 PM.

      Comment


        #18
        Originally posted by tgn55 View Post
        Danilod,
        I can now see something of concern... your backtest is on a 5 minute series starting on 3/1... and your first trade occurs at 12:05 AM on 3/1. That's the very first bar! So it seems you do not have anything in your code to address my previous point about ensuring all indicators have "settled down"... which is achieved by using the BarsRequiredToTrade parameter... which should be at least as large as the period parameter of your RSI (or any other indicator you include... which seems to be EMA). This can/should be set inside your strategy code, the "should" meaning, if you run with variable RSI periods... then your code needs to adjust BarsRequiredToTrade accordingly. Plus... you need a bit of code to skip if CurrentBar is less than BarsRequiredToTrade.

        First, add something like this in your State.SetDefaults or State.Configure:
        Code:
        BarsRequiredToTrade = EMA_Period; // technically, should be the MAX of your EMA and RSI periods
        Then, ensure you have this bit of code in OnBarUpdate:
        Code:
         if (CurrentBar < BarsRequiredToTrade)
        return;
        You need to sort out basics like this... and also address the error message about max entries exceeded (if that still exists)... BEFORE moving on. Clean up what you can, then see what remains.

        FYI... if you do this correctly, your FIRST trade should not occur until AT LEAST 4:10 AM on the start date ... not 12:05 AM (if you are using 5 min bars) ;-)

        PS... Previous caution about EMA settle period in my post #3 clearly applies. EMA(50 period) uses data from bars prior to 50 bars back... so if you really want no surprises in your backtest results, best to increase BarsRequiredToTrade to something even larger.

        T.
        You've teached me several things with this post. It all makes sense now.
        Thank you very much.

        Comment


          #19
          Thankyou ! Feel free to hit the Like button !

          T.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by tkaboris, Today, 08:01 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by Lumbeezl, 01-11-2022, 06:50 PM
          31 responses
          817 views
          1 like
          Last Post NinjaTrader_Adrian  
          Started by xiinteractive, 04-09-2024, 08:08 AM
          5 responses
          15 views
          0 likes
          Last Post NinjaTrader_Erick  
          Started by swestendorf, Today, 11:14 AM
          2 responses
          6 views
          0 likes
          Last Post NinjaTrader_Kimberly  
          Started by Mupulen, Today, 11:26 AM
          0 responses
          7 views
          0 likes
          Last Post Mupulen
          by Mupulen
           
          Working...
          X