My first post on here and hopefully someone can help me out.
I'm trying to do some custom optimization by looping back through historical data and I've found that the values returned for TickQ and TrinQ are different based on whether they are called as OnBarUpdate is stepping through the historical data the first time, or when they are called at the end of the historical data updates.
You can see this from the output for exactly the same bars of DDD:
First you can see the data output when called on Bar[0] as it is being stepped through the first time as the strategy is enabled:
DateofBar 20120925 TimeofBar 0 is 140000 Close = 36.24 Open = 36.11
MACdiff of bar 0 is -0.00175320328820028 MACDdiff of bar 0 is -0.00175320328820028
MACD of bar 0 is 0.336213598844452 MACDAvg of bar 0 is 0.337966802132652
ADX of bar 0 is 27.1365507209919
Tick 264
Trin 1.58
Then when I find the exactly same bar when OnBarUpdate is pointing at the end of the historical data by looking back at bar 835, you can see the timestamp, MACD, and ADX values are exactly the same, but for some reason the Tick and Trin values are now different:
DateofBar 20120925 TimeofBar 835 is 140000 Close = 36.24 Open = 36.11
MACdiff of bar 835 is -0.00175320328820028 MACDdiff of bar 835 is -0.00175320328820028
MACD of bar 835 is 0.336213598844452 MACDAvg of bar 835 is 0.337966802132652
ADX of bar 835 is 27.1365507209919
Tick -119
Trin 1.35
So I checked the data in the Historical Data Manager to see which values are correct, and you can see the first step through values are correct:
Real Tick from Historical Data Manager = 264
Real Trin from Historical Data Manager = 1.58
I have no idea what's going. Tick and Trin values are wrong for all bars when looked at from the end of historical data. I'm using exactly the same code for each output. I can think of a work around by storing the real TickQ and TrinQ values in an array as OnBarUpdate is stepping through the data the first time, but I really want to understand what's going on here.
Here's the relevant code:
protected override void Initialize()
{
CalculateOnBarClose = true;
EntryHandling = EntryHandling.UniqueEntries;
Add ("^TICKQ", PeriodType.Minute, 30);
Add ("^TRINQ", PeriodType.Minute, 30);
Add (PeriodType.Minute, 5);
}
protected override void OnBarUpdate()
{
if (CurrentBars[0] <= BarsRequired ||
CurrentBars[1] <= BarsRequired || CurrentBars[2]
<= BarsRequired || CurrentBars[3]
<= BarsRequired)
return;
if (BarsInProgress == 0) // Print values as OnBarUpdate steps through on startup
{
Print("DateofBar "+ ToDay(Time[0]) + " TimeofBar " + 0 + " is " + ToTime(Time[0]) + " Close = " + Close[0] + " Open = " + Open[0]);
Print("MACdiff of bar " + 0 + " is " + MACD(12,26,9).Diff[0] + " MACDdiff of bar " + (0) + " is " + MACD(12,26,9).Diff[0]);
Print("MACD of bar " + 0 + " is " + MACD(12,26,9)[0] + " MACDAvg of bar " + (0) + " is " + MACD(12,26,9).Avg[0]);
Print("ADX of bar " + 0 + " is " + ADX(adxvalue)[0]);
Print("Tick " + (Closes[1][0]));
Print("Trin " + (Closes[2][0]));
Print("");
}
if (Historical == true
&& (Count - 2 == CurrentBar)) // Print values when OnBarUpdate has reached the end of historical data
{
if (BarsInProgress == 0)
{
int loopsbar2 = Count - 26;
for(int i = loopsbar2; i >= 0; i--)
{
Print("DateofBar "+ ToDay(Time[i]) + " TimeofBar " + i + " is " + ToTime(Time[i]) + " Close = " + Close[i] + " Open = " + Open[i]);
Print("MACdiff of bar " + i + " is " + MACD(12,26,9).Diff[i] + " MACDdiff of bar " + (i) + " is " + MACD(12,26,9).Diff[i]);
Print("MACD of bar " + i + " is " + MACD(12,26,9)[i] + " MACDAvg of bar " + (i) + " is " + MACD(12,26,9).Avg[i]);
Print("ADX of bar " + i + " is " + ADX(adxvalue)[i]);
Print("Tick " + (Closes[1][i]));
Print("Trin " + (Closes[2][i]));
Print("");
}
}
}
}
Comment