Hello,
I have added a custom metric that gives me the correlation of monthly rolling annual backest returns with the S&P500 across the entire backtest period. To use the Correlation function I need to retrieve the total number of months. After searching around the only way I found was this one:
MonthCounter = 1;
Months = Month();
for( bar = 1; bar < BarCount; bar++ )
{
if ( Months[bar] != Months[bar-1] ) MonthCounter[bar] = MonthCounter[bar-1] + 1;
else MonthCounter[bar] = MonthCounter[bar-1];
}
I decided to do this because BarCount is not adjusted when I change timeframe. So, this does not give me the right result (still daily bar count):
TimeFrameSet(inMonthly);
_TRACE(NumToStr(BarCount,0));
TimeFrameRestore();
Just curious if I missed something. If not, and anybody else looks for this, here is the answer.
Thanks,
Robert