Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trades Not Executing On Secondary Series In Multi-Series Strategy

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

    Trades Not Executing On Secondary Series In Multi-Series Strategy

    Hi,

    I have a strategy that uses moving averages derived from a daily strategy, and looks at bars from an "Add"ed 1 minute series (on the same instrument) to make trading decisions and enter trades.

    When I execute trades from within the 1 minute bars, I use EnterLong or EnterShort with 1 as the BarsInProgress index.

    The problem is that during backtesting, the trades are not being executed until the next daily bar, rather than at the start of the next 1 minute bar as desired.

    I've looked at the SampleIntrabarBacktest strategty, and modifed it to do what I'm doing:

    // if (BarsInProgress == 0)
    if (BarsInProgress == 1)
    {
    // When the fast EMA crosses above the slow EMA, enter long on the secondary (1min) bar series
    if (CrossAbove(EMA(Fast), EMA(Slow), 1))
    {
    /* The entry condition is triggered on the primary bar series, but the order is sent and filled on the
    secondary bar series. The way the bar series is determined is by the first parameter: 0 = primary bars,
    1 = secondary bars, 2 = tertiary bars, etc. */
    EnterLong(1, 1, "Long: 1min");
    Print("Long at " + Time);
    }

    // When the fast EMA crosses below the slow EMA, enter short on the secondary (1min) bar series
    else if (CrossBelow(EMA(Fast), EMA(Slow), 1))
    {
    /* The entry condition is triggered on the primary bar series, but the order is sent and filled on the
    secondary bar series. The way the bar series is determined is by the first parameter: 0 = primary bars,
    1 = secondary bars, 2 = tertiary bars, etc. */
    EnterShort(1, 1, "Short: 1min");
    Print("Short at " + Time);
    }
    }

    // When the OnBarUpdate() is called from the secondary bar series, do nothing.
    else
    {
    return;
    }

    The debug printouts show that the trades are being entered on 1 minute intervals, but the trade log shows that the trades are executed at the start of the next primary bar (which I set to 5 minutes for this test).

    Help - how can I get my trades to execute at the start of the next 1 minute bar instead of at the start of the next primary bar ?

    Bob A.

    #2
    Bob, can you please post the full code you're using here? From what you've described, the order should be filled on the 1 minute series.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Bob, maybe you need specify the primary data series in the crossing methods ....

      ... CrossAbove(EMA(Fast,BarsArray[0]), EMA(Slow, BarsArray[0]), 1) ...

      I did not test it ... only the first rash thoughts ...

      Greets
      DT

      Comment


        #4
        Hi Austin,

        Attached is the following:

        1. My modified version of SampleIntrabarBacktest
        2. A .jpg screen shot of the trades generated
        3. A .jpg screen shot of the settings used for the script
        3. A .txt file containing the debug output

        The changes I made to SampleIntrabarBacktest are:

        1. Look for EMA crossovers and book trades when BarsInProgress == 1 (on the secondary 1 minute data series)

        2. Print out the time and Long/Short to the debug log when a trade is booked.

        The test output I've included was generated using 5 minute bars as the primary series, and 1 minute bars as the secondary series on CL 11-10.

        When you look at the trade log (in SampleIntrabarStrategy.xls), you will see that all entries and exits take place on 5 minute boundries. When you look at the debug log (in SampleIntrabarStrategy.txt), you will see that the trades are booked on 1 minute boundries.

        So what seems to be happening here is that although the script is booking the trades on the 1 minute bars, they are not getting filled until the start of the next 5 minute bar.

        One last comment - I did not include this here, but I found that if I "Add" a different futures contract for the 1 minute series the trades DO get booked on the 1 minute bars for that different futures contract.

        Please let me know if you need any more information.

        Thanks,

        Bob A.

        (Darth, my issue is related to trade execution, not the trading signal using the EMA's, but thanks for looking !)
        Attached Files

        Comment


          #5
          BAltman,

          Please first ensure you are on B22 as things have been fixed from earlier versions on B22.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            V22 seems to have fixed it !

            Thanks for the quick response - I'm going to do some more exhaustive testing, but it looks like the issue is resolved.

            Thanks !

            Bob A.

            Comment


              #7
              I've discovered another issue related to trades executing on the secondary series.

              It seems that stop loss orders are not getting executed on the secondary series, but rather on the primary series.

              I'm attaching another modified version of the SampleIntrabarBacktest strategy that demonstrates the problem.

              I'm also attaching a screen shot of the executions tab of the strategy analyzer after I ran a test using my modified version of SampleIntrabarBacktest.

              Please note how all the exits with a name of "stop loss" occur on 1 hour boundries - this is at the end of bar of the primary series of 60 minute bars.

              Please also note how the first 3 trades shown on the execution screen all start at different times (10/25 3:18, 10/25 3:27, 10/25 3:41) and all show exits at 4:00 yet the position never exceeded 1.

              Please let me know if I can provide any additional information.

              Thanks,

              Bob A.
              Attached Files

              Comment


                #8
                When you use Set() methods they are independent of BarsInProgress. All your BarsInProgress are of the same instrument so the Set() methods are evaluated in all of them. They will fill on the first BarsInProgress for that instrument that satisfies the condition.

                I suggest you print your BarsInProgress processing orders to see exactly the sequence of events.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks for the explanation, Josh - it makes sense now.

                  Am I correct in assuming that this is only an issue during backtesting, and that in real-time the profit target and stop loss will get executed against the 1 minute bars ?

                  Bob A.

                  Comment


                    #10
                    Originally posted by BAltman View Post
                    I've discovered another issue related to trades executing on the secondary series.

                    It seems that stop loss orders are not getting executed on the secondary series, but rather on the primary series.

                    Bob A.
                    This sounds like the same issue I have here http://www.ninjatrader.com/support/f...ad.php?t=34218

                    Comment


                      #11
                      Hi Dave,

                      I looked at you post and this does sound like the same issue.

                      As I understand it, the issue is that the methods that "set" attributes onto a trade (setProfitTarget, setStopLoss, etc...) are executed against ALL of the Bars objects for the same instrument, rather than against a specific Bars object. In my case, I'm subscribing for both daily and 1 minute bars for the same instrument, and my profit targets and stop losses are being executed against the daily bar instead of the 1 minute bar as I intended.

                      In my mind, this is clearly a BUG - I can think of no good reason why the current handling is desirable or makes sense.

                      The "set" methods should have a variation that allows the specification of which Bars object (using BarsInProgress) to apply the "set" to (just like every "enter" and "exit" method do for trade entry and exit).

                      Josh/Austin, would you please reconsider addressing this issue ?

                      Thanks,

                      Bob A.

                      Comment


                        #12
                        Originally posted by BAltman View Post

                        As I understand it, the issue is that the methods that "set" attributes onto a trade (setProfitTarget, setStopLoss, etc...) are executed against ALL of the Bars objects for the same instrument, rather than against a specific Bars object.
                        Not just that, but the way it manifests itself is a complete mess. In my case, my entry is at 13:44. My stop is then executed immediately, with a timestamp of 14:00 (the next primary bar), the order has a timestamp of 13:15 (the previous primary bar) and the price is a price that existed at 13:15.

                        Comment


                          #13
                          I suggest you print your sequence of event. You should never receive a 14:00 event when your time is still 13:15 on your minute series. It should never go 13:15 minute, 14:00 daily, 13:16 minute.

                          In real-time your order is submitted and gets filled whenever your brokerage decides to fill you. This timing is completely independent of any BarsInProgress. The order is submitted once and is left in the market till filled, cancelled, or any other terminal action.
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #14
                            I never said events were out of sequence, I said timestamps were odd.

                            Here is the sequence of events (although I would like to point out that I coded a strategy for you guys so you can reproduce this. A quick debug session would tell you what's going on)

                            The stop loss is executed immediately at 13:44 with a timestamp of 14:00, which it presumably got from the primary bar

                            Code:
                            08/10/2010 13:44:32 Entered internal PlaceOrder() method at 08/10/2010 13:44:32: BarsInProgress=1 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='entry' FromEntrySignal=''
                            08/10/2010 13:44:32 Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='entry' Mode=Ticks Value=32 Currency=0 Simulated=False
                            Order Update = Order='NT-00000/Backtest' Name='entry' State=PendingSubmit Instrument='6A 12-10' Action=Buy Limit price=0 Stop price=0 Quantity=1 Strategy='t1' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='5ad8876983e24a1e8dd34a69761e71b0' Gtd='01/12/2099 00:00:00'
                            Order Update = Order='NT-00000/Backtest' Name='entry' State=Accepted Instrument='6A 12-10' Action=Buy Limit price=0 Stop price=0 Quantity=1 Strategy='t1' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='5ad8876983e24a1e8dd34a69761e71b0' Gtd='01/12/2099 00:00:00'
                            Order Update = Order='NT-00000/Backtest' Name='entry' State=Working Instrument='6A 12-10' Action=Buy Limit price=0 Stop price=0 Quantity=1 Strategy='t1' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='5ad8876983e24a1e8dd34a69761e71b0' Gtd='01/12/2099 00:00:00'
                            Order Update = Order='NT-00001/Backtest' Name='Stop loss' State=PendingSubmit Instrument='6A 12-10' Action=Sell Limit price=0 Stop price=0.9693 Quantity=1 Strategy='t1' Type=Stop Tif=Gtc Oco='NT-00000-268' Filled=0 Fill price=0 Token='0b9388f2bd14492e99a42fccdf028522' Gtd='01/12/2099 00:00:00'
                            Order Update = Order='NT-00001/Backtest' Name='Stop loss' State=Accepted Instrument='6A 12-10' Action=Sell Limit price=0 Stop price=0.9693 Quantity=1 Strategy='t1' Type=Stop Tif=Gtc Oco='NT-00000-268' Filled=0 Fill price=0 Token='0b9388f2bd14492e99a42fccdf028522' Gtd='01/12/2099 00:00:00'
                            Order Update = Order='NT-00001/Backtest' Name='Stop loss' State=Working Instrument='6A 12-10' Action=Sell Limit price=0 Stop price=0.9693 Quantity=1 Strategy='t1' Type=Stop Tif=Gtc Oco='NT-00000-268' Filled=0 Fill price=0 Token='0b9388f2bd14492e99a42fccdf028522' Gtd='01/12/2099 00:00:00'
                            Order Update = Order='NT-00000/Backtest' Name='entry' State=Filled Instrument='6A 12-10' Action=Buy Limit price=0 Stop price=0 Quantity=1 Strategy='t1' Type=Market Tif=Gtc Oco='' Filled=1 Fill price=0.9725 Token='5ad8876983e24a1e8dd34a69761e71b0' Gtd='01/12/2099 00:00:00'
                            Execution = Execution='NT-00000' Instrument='6A 12-10' Account='Backtest' Name='entry' Exchange=Default Price=0.9725 Quantity=1 Market position=Long Commission=2.5 Order='NT-00000' Time='08/10/2010 13:44:32'
                            Order Update = Order='NT-00001/Backtest' Name='Stop loss' State=Filled Instrument='6A 12-10' Action=Sell Limit price=0 Stop price=0.9693 Quantity=1 Strategy='t1' Type=Stop Tif=Gtc Oco='NT-00000-268' Filled=1 Fill price=0.9659 Token='0b9388f2bd14492e99a42fccdf028522' Gtd='01/12/2099 00:00:00'
                            Execution = Execution='NT-00001' Instrument='6A 12-10' Account='Backtest' Name='Stop loss' Exchange=Default Price=0.9659 Quantity=1 Market position=Short Commission=2.5 Order='NT-00001' Time='08/10/2010 14:00:00'
                            08/10/2010 13:44:32  BIP = 1  Close = 0.9725

                            Comment


                              #15
                              What version of NT7 are you using?
                              Josh P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by TraderBCL, Today, 04:38 AM
                              2 responses
                              7 views
                              0 likes
                              Last Post TraderBCL  
                              Started by martin70, 03-24-2023, 04:58 AM
                              14 responses
                              105 views
                              0 likes
                              Last Post martin70  
                              Started by Radano, 06-10-2021, 01:40 AM
                              19 responses
                              606 views
                              0 likes
                              Last Post Radano
                              by Radano
                               
                              Started by KenneGaray, Today, 03:48 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post KenneGaray  
                              Started by thanajo, 05-04-2021, 02:11 AM
                              4 responses
                              471 views
                              0 likes
                              Last Post tradingnasdaqprueba  
                              Working...
                              X