Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

IntraBarBackTest File Error ?

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

    IntraBarBackTest File Error ?

    All,

    I believe i found an error in the sampleintrabarbacktest.cs file.

    Code:
    When the OnBarUpdate() is called from the primary bar series (5min series in this example), do the following */
    			if (BarsInProgress == 1)
    			{
    				// When the fast EMA crosses above the slow EMA, enter long on the secondary (1min) bar series
    				if (CrossAbove(EMA(Closes[0], Fast), EMA(Closes[0], 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 (ORDER) bar series is determined is by the first parameter: 0 = primary bars,
    					1 = secondary bars, 2 = tertiary bars, etc. */
    					EnterLong(0, 1, "Long: 1min");<--------this should read EnterLong(1,1,"Long: 1min"); As You want to send the order to the 1 min bars, which is BIP==1, the primary bar is BIP==0 @ 5 min in this sample. 
    				}
    				
    				// When the fast EMA crosses below the slow EMA, enter short on the secondary (1min) bar series
    				else if (CrossBelow(EMA(Closes[0], Fast), EMA(Closes[0], 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(0, 1, "Short: 1min"); --- Same here
    				}
    			}
    I have been working a lot with MTF systems and have found a few other issues that are a bit complex.

    When working with a system like this its hard to configure an indicator to visually indicate the entry point. If you Select the indicator data feed to be 15 min and then try to plot to a secondary data feed of 1 minutes it will just plot the close price of the last 15 bar, 15 times. Once per 1 min bar- This is expected.

    However if you change the input series for the same indicator to 1 min and then try to plot the 15 min value every minute(such that it would print the 1 min increments of the 15 min bar as its built) this does not work - The Chart will only plot the 15 min price every 15 min bar. Well I have tried about every combination of BIP and input series and i cant get the strategy entrance time to match the indicator crossover point.

    To make a long story short i need to be able to visually check the strategy execution time to the indicator(I know i have to check the execution time as it will appear on the primary bars rather than secondary, this is ok) that the condition took place when i have a strategy entering on a bar other than the primary feed.

    #2
    neb1998, I'm not sure where you sample code comes from, but our reference one on the forum does submit to secondary series as needed - http://www.ninjatrader.com/support/f...ead.php?t=6652

    I'm not 100% sure I follow your other included question - the plots are tied to the primary series and for all bars values should be .Set() for it as otherwise exceptions could be the result when trying to access them.

    For the intrabar conditions, you need to reformulate them to work with lower series data as the 15 min bar data would still only have the OHLCV info and not the intrabar formation in a backtest.

    Comment


      #3
      Bertrand what i have been trying to do is code around the entry condition of:
      on 15 min bars
      If cond1=true at 10:03 am, close of next 15 min bar being 10:15. The soonest i can get filled is at 10:16 via backtesting.

      I tried to fix this by putting 1 min bars as my primary bar and 15 as a secondary, and then referencing the secondary bar in the order.

      If ( Closes[0][0] > Closes[0][1])
      Enter Long(1,1,"enter long primary series 1 min");

      I can understand how this would not work as the 15 min data only exists every 15 minutes, so its drawing the same price data each minute from the previous 15 min bar.

      I dont really see a way around this after trying this.

      I guess what i am trying to do is simulate the 15 min bar being created with 1 min data....So if the cross happens at 10:03 i enter at 10:04.

      Comment


        #4
        neb1998,

        You will need to closely follow the reference sample Bertrand linked you to. That example breaks down how you get intrabar granularity that you seek. It is important to fully understand the nature of a multi-time frame strategy and at what point in time the Bars objects update. You need to submit your orders to the 1min Bars object and not the 15min if you want 1min granularity. This means submitting to the correct BarsInProgress.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Right but isnt it correct that the soonest i can enter is after the condition is true and the 15 min bar closes.

          So condition is true at 10:27(visuall), thenext 15 min bar closes at 1030, the entry will be 1031 if i am submitting to 1 min bar series.

          There is no way to enter at 1028 as the 15 min bar has not closed yet at 1030 to confirm the condition. Correct? This is what the charts depict and what would make sense with the current BIP logic in the sample.

          Comment


            #6
            No, if your condition is true at 10:27 based on the 1min series, then you can get in at 10:28 based on the 1min series. There is no prerequisite that you have to wait for the 15min bar to close at 10:30 unless you specifically want it to wait for that to be the case.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              And this is true in backtesting? Or just RT?

              Comment


                #8
                True for both. It all depends on how you program it and how much granularity you have available. I suggest reading this article as it covers important ground footing for the multi-time frame concept. http://www.ninjatrader.com/support/h...nstruments.htm
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  I have been through the article and the forums extensively

                  Code:
                          {
                              //add(periodtype.minute,1);// index 0 
                        		Add(PeriodType.Minute,5); // index 1
                  			Add(PeriodType.Minute,1); // index 2 
                  			Unmanaged = true; 
                  			//TraceOrders=true;
                  			e1 = null;	mmStop=null;	trailStop=null; trailMarket = null; 
                  			MaxProcessedEvents=100; 
                  			ExitOnClose = false; 
                  			SyncAccountPosition =true; 
                  			CalculateOnBarClose = false;
                  			
                  		}
                  		#endregion
                  			
                          #region Entrance 
                          protected override void OnBarUpdate()
                          {
                      	if (ds1 == null) ds1 = new DataSeries(EMA(BarsArray[0],10)); 
                  		if (ds2 == null) ds2 = new DataSeries(EMA(BarsArray[0],10)); 
                  			
                  		if (BarsInProgress==2) // 1 minute 
                  		{
                  			ds1.Set(MACD(TFd1Ind(bkclosevar),macdFastLen,macdSlowLen,macdSmoothing)[0]); 	
                  			ds2.Set(WMA(MACD(TFd1Ind(bkclosevar),macdFastLen,macdSlowLen,macdSmoothing),macdAvgLen)[0]); 
                  		
                  		//PrintWithTimeStamp("Close --- " + Close[0].ToString ()); 
                  		//if (Historical) return; 
                  		if (CurrentBar < 2) return; 
                  			
                  			
                  		
                  		//double retrace = Math.Abs(ATR(BarsArray[0],retraceLen)[0] *retraceFac);
                  				
                  				if (e1 == null && mmStop == null && trailStop==null &&	ToTime(Time[0])  >= 84500 && ToTime(Time[0]) <= 144500 &&
                  				CrossBelow(ds1,ds2,1 )) 
                  					{
                  						e1 = SubmitOrder(2,OrderAction.SellShort,OrderType.Limit,1,GetCurrentBid(2),0,"Entry", "SS1"); 
                  						entryBar = CurrentBars[0]; 
                  					}
                  				#endregion

                  The Code waits for the 15 min bar to close during backtesting and my entrance is on the next bar. The crossover is the issue here i believe.


                  If what your saying is really possible i would appreciate any help, i have been working on this for a while with many different coding combinations.

                  Primary bar is 15 min FYI.

                  This i not the entire code but its the only section i can send. So you will need a manual exit but the exits work fine. The entrance has the delay.

                  Comment


                    #10
                    neb1998, your series are synched to the primary series here by default, even if you set them from the BIP2 - I suggest you print the Time, BarsInProgress and value available then from the series to see when you CrossBelow rule can be expected to trigger, the entry should be then 1 min later if you're submitting to the BIP2.

                    If you want to sync a dataseries to an added series, please see this sample here -

                    Note: In NinjaTrader 8 It is no longer needed to use an indicator to sync a secondary series. This can be done directly from the Series&lt;T&gt; (https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?seriest.htm) constructor. This post is left for historical purposes. Series objects are useful for

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    647 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    367 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    108 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    571 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    573 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X