Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Multi TimeFrame Question
Collapse
X
-
Before I put the Add statement in I was doing testing on Aug 2011. I was getting 124 trades. When I put in the Add statement the number of trades went to 15. So I put in a if(BarsInProgress != 0) return; statement in the OnBarsUpdate method. Still got only 15 trades. And actually those 15 trades are on Jul 31 and Sep 1. Is there a way to get access to the From and To dates so I can prevent processing the day before the From date and the day after the To date?Last edited by freeway; 10-28-2011, 10:44 AM.
Comment
-
When you implement additional TF, especially so big as Day, you must add your own StartDate variable, or calculate the value for "BarsRequired".
In your case you want a Daily ATR(10). That means that you need to load 10 days of data before you will have a reliable value.
To do it in your example:
private int StartDate = 20110801; //Aug 1, 2001
In OnBarsUpdate:
if (ToDay(Time[0]) < StartDate) return;
In backtest: From: 07/15/2011
You can add ToDate too, but its less important.
Baruch
Comment
-
I have to make the From date in Backtest 1 month before I want to start processing trades. This does work for what I want to do but I don't quite understand why I have to go a whole month before I want to process the trades in the To Date. e.g. to process trades in Aug 2011 I have to enter July 1 2011 as the start date. Also the daily ATR is not being calculated correctly. Here is a part of my code:
protected override void Initialize()
{
// ClearOutputWindow();
Add(PeriodType.Minute ,1);
Add(PeriodType.Day, 1);
sBeginHH = SessionBeginTime.ToString().Substring(0,2);
sBeginMM = SessionBeginTime.ToString().Substring(3,2);
sBeginSS = SessionBeginTime.ToString().Substring(6,2);
sBeginTime = sBeginHH + sBeginMM + sBeginSS;
beginTime = Convert.ToInt32(sBeginTime);
sEndHH = SessionEndTime.ToString().Substring(0,2);
sEndMM = SessionEndTime.ToString().Substring(3,2);
sEndSS = SessionEndTime.ToString().Substring(6,2);
sEndTime = sEndHH + sEndMM + sEndSS;
endTime = Convert.ToInt32(sEndTime);
Add(EMA(LittleMoPeriod));
Add(EMA(BigMoPeriod));
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
///
protected override void OnBarUpdate()
{
if(ToDay(Time[0]) < StartDate) return;
if (BarsInProgress == 1)
{
dailyATR = ATR(BarsArray[1],10)[1];
}
if (BarsInProgress != 0) return;
What do I have to do the calculate the dailyATR correctly?
Comment
-
freeway, the reason is the BarsRequired setting has to be fulfilled for all series, if you run with the default of 20, this would mean 20 daily bars have to be available as well before any OnBarUpdate() call is run. You can set this to a lower # but be aware the ATR would need 10 bars minimum (your period) to produce meaningful values.
Comment
-
Bertrand,
I know that I can verify it my self, but I'm too lazy.
So what is correct?
In help file it says that BarsRequared applies ONLY to primary BIP.
and you say the opposite
the reason is the BarsRequired setting has to be fulfilled for all series, if you run with the default of 20, this would mean 20 daily bars have to be available as well before any OnBarUpdate() call is run.
Comment
-
Here
Baruch
BarsRequired
Definition
The number of historical bars required before the strategy starts processing calls to the OnBarUpdate() method. This property is generally set via the UI when starting a strategy.
The OnBarUpdate() method is not triggered until CurrentBar >= BarsRequired. In a multi-series strategy this restriction applies only for the primary Bars object. Should your strategy logic intertwine calculations across different Bars objects please ensure all Bars objects have met the BarsRequired requirement before proceeding. This can be done via checks on the CurrentBars array.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
656 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
371 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
109 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
574 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
579 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment