Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strange behaviour when backtesting

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

    Strange behaviour when backtesting

    I don't know where to post this, feel free to move it if needed.

    I'm backtesting an strategy that uses 3 bar series, daily (to get the daily trend), 30min (to search for triggers) and 1min (to give granularity) in the same instrument.

    Stop entry orders are submitted when I have a trigger in the 30min chart (Barsinprogress==1) and are managed (stops, break even, close) in the 1min chart (Barsinprogress==2). There are some stop orders launched form the 30min bar too. It closes positions at end of session.

    When looking at the results, something strange appears. This is a fragment of the output window:

    Code:
    10/06/2013 0:00:00 Entered internal PlaceOrder() method at 10/06/2013 0:00:00: BarsInProgress=1 Action=Buy OrderType=Stop Quantity=0,1M LimitPrice=0 StopPrice=1,3201'7 SignalName='EntradaLargos' FromEntrySignal=''
    10/06/2013 0:00:00 Entered internal PlaceOrder() method at 10/06/2013 0:00:00: BarsInProgress=1 Action=Sell OrderType=Stop Quantity=0,1M LimitPrice=0 StopPrice=1,3180'2 SignalName='StopLargos' FromEntrySignal='EntradaLargos'
    10/06/2013 0:00:00 Entered internal PlaceOrder() method at 10/06/2013 0:00:00: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=0,1M LimitPrice=2,3201'7 StopPrice=0 SignalName='ObjetivoLargos' FromEntrySignal='EntradaLargos'
    10/06/2013 9:00:00 Cancelled pending exit order, since associated position is closed: Order='NT-00013/Backtest' Name='ObjetivoLargos' State=Working Instrument='$EURUSD' Action=Sell Limit price=2,32017 Stop price=0 Quantity=0,1M Strategy='SCSExtremos3sfh' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='e59e1e73b9f24b27ba284af6821901e8' Gtd='01/12/2099 0:00:00'
    24/06/2013 15:00:00 Entered internal PlaceOrder() method at 24/06/2013 15:00:00: BarsInProgress=1 Action=Buy OrderType=Stop Quantity=0,1M LimitPrice=0 StopPrice=1,3104'8 SignalName='EntradaLargos' FromEntrySignal=''
    24/06/2013 15:30:00 Entered internal PlaceOrder() method at 24/06/2013 15:30:00: BarsInProgress=1 Action=Sell OrderType=Stop Quantity=0,1M LimitPrice=0 StopPrice=1,3052'9 SignalName='StopLargos' FromEntrySignal='EntradaLargos'
    24/06/2013 15:30:00 Entered internal PlaceOrder() method at 24/06/2013 15:30:00: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=0,1M LimitPrice=2,3104'8 StopPrice=0 SignalName='ObjetivoLargos' FromEntrySignal='EntradaLargos'
    24/06/2013 21:00:00 Entered internal PlaceOrder() method at 24/06/2013 21:00:00: BarsInProgress=1 Action=Sell OrderType=Stop Quantity=0,1M LimitPrice=0 StopPrice=1,3118'8 SignalName='StopLargos' FromEntrySignal='EntradaLargos'
    24/06/2013 21:00:00 Amended open order: Action=Sell OrderType=Stop Quantity=100000 LimitPrice=0 StopPrice=1,3118'8 SignalName=StopLargos' FromEntrySignal='EntradaLargos'
    21/06/2013 23:00:00 Entered internal PlaceOrder() method at 21/06/2013 23:00:00: BarsInProgress=0 Action=Sell OrderType=Market Quantity=0,1M LimitPrice=0 StopPrice=0 SignalName='CierreLargos' FromEntrySignal='EntradaLargos'
    24/06/2013 21:00:00 Cancelled pending exit order, since associated position is closed: Order='NT-00016/Backtest' Name='ObjetivoLargos' State=Working Instrument='$EURUSD' Action=Sell Limit price=2,31048 Stop price=0 Quantity=0,1M Strategy='SCSExtremos3sfh' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='b6b40e29c7d6426aaf05278f670a64c7' Gtd='01/12/2099 0:00:00'
    24/06/2013 21:00:00 Cancelled pending exit order, since associated position is closed: Order='NT-00015/Backtest' Name='StopLargos' State=Working Instrument='$EURUSD' Action=Sell Limit price=0 Stop price=1,31188 Quantity=0,1M Strategy='SCSExtremos3sfh' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='6abe377a27b24681a3e2c841721ddd29' Gtd='01/12/2099 0:00:00'
    27/06/2013 21:30:00 Entered internal PlaceOrder() method at 27/06/2013 21:30:00: BarsInProgress=1 Action=SellShort OrderType=Stop Quantity=0,1M LimitPrice=0 StopPrice=1,3033'8 SignalName='EntradaCortos' FromEntrySignal=''
    28/06/2013 6:30:00 Entered internal PlaceOrder() method at 28/06/2013 6:30:00: BarsInProgress=1 Action=SellShort OrderType=Stop Quantity=0,1M LimitPrice=0 StopPrice=1,3060'4 SignalName='EntradaCortos' FromEntrySignal=''
    28/06/2013 7:00:00 Entered internal PlaceOrder() method at 28/06/2013 7:00:00: BarsInProgress=1 Action=BuyToCover OrderType=Stop Quantity=0,1M LimitPrice=0 StopPrice=1,3078'9 SignalName='StopCortos' FromEntrySignal='EntradaCortos'
    28/06/2013 7:00:00 Entered internal PlaceOrder() method at 28/06/2013 7:00:00: BarsInProgress=1 Action=BuyToCover OrderType=Limit Quantity=0,1M LimitPrice=0,3060'4 StopPrice=0 SignalName='ObjetivoCortos' FromEntrySignal='EntradaCortos'
    28/06/2013 14:00:00 Cancelled pending exit order, since associated position is closed: Order='NT-00022/Backtest' Name='ObjetivoCortos' State=Working Instrument='$EURUSD' Action=BuyToCover Limit price=0,30604 Stop price=0 Quantity=0,1M Strategy='SCSExtremos3sfh' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='69c91689359a4b539e0d9ee0a4055424' Gtd='01/12/2099 0:00:00'
    Some general thoughts:

    - orders are timestamped following the 30 min chart. The same version of the strategy without the daily trend filter have a resolution of 1 min.
    - all orders are with Barsinprogress =1.
    - I exit all positions when Time[0] reaches the 21:00, calling exit from the 1 min bar (Barsinprogress=2), so don't know why it closes at 23:00


    Let's focus in the 24/06/2014:

    - Appears an order marked with 21/06/2014 date. A bit strange.
    - What's the meaning of Amended open order?
    - It closes at 1,3084 (see screenshot), the first stop order, but that price is never touched since entry (see atached 1 min chart).

    I'm very confused.

    Thanks in advance,

    Sergio
    Attached Files

    #2
    sercava, thanks for the post here.

    Do you only have this strategy applied / working when you work with the output window? Daily would be the primary series in this setup?

    Amending would mean a resting order is updated, here your stop.

    For your entries and exits, do you only work with the dedicated Enter / Exit methods offering you to submit to a specific BarsInProgress? As in backtesting you would submit an order always for the next bar and then the submitted to series would determine the fill price in historical processing.

    Generally I would not work via the TraceOrders alone, but add debug prints in that could help better clarify what variable states you were seeing in your executions and which (bars) update event sequence your script ran through.

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post

      Do you only have this strategy applied / working when you work with the output window? Daily would be the primary series in this setup?
      I have no other strategies working, this is the only one. The primaty bar series is a daily chart (barsinprogress=0)

      Originally posted by NinjaTrader_Bertrand View Post
      For your entries and exits, do you only work with the dedicated Enter / Exit methods offering you to submit to a specific BarsInProgress? As in backtesting you would submit an order always for the next bar and then the submitted to series would determine the fill price in historical processing.
      Can you develop this part a bit more?

      Comment


        #4
        sercava, thanks. Backtesting generally is done using the OHLCV of the individual series only, thus you place an order on the bar where you condition triggered but effectively that's then the next bar, the first valid trade place after the trigger bar is closed. Which for your script would be the next bar in the series you submit to as determined by the BarsInProgress parameter in the order overload. I was asking about the methods used, since only the Enter() and Exit() methods would offer overloads that allowed for explicit submission to a series, the more basic Set() methods often used for stop / target exits would not allow this but only work off the primary series.

        Comment


          #5
          I was reviewing my code following a hint you gave me in last answer when I found the problem: I was sending the orders to [1] series, not to [2]. That's the problem when you reuse code from other scripts.

          Of course I use methods that allow sending orders to specific bars, like:

          Code:
          entryOrderLong=EnterLongStop(2,true,cantidad, PIVOTEL, "EntradaLargos");
          stopOrderLong=ExitLongStop(2,true,cantidad,STOPL, "StopLargos", "EntradaLargos");
          ExitLong(2,cantidad,"CierreLargos","EntradaLargos");
          Thanks again,

          Sergio

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          66 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          41 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          23 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          26 views
          0 likes
          Last Post TheRealMorford  
          Started by Mindset, 02-28-2026, 06:16 AM
          0 responses
          53 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Working...
          X