To further illustrate my point, let's say you want to manually calculate the correlation value for YM and ES, and therefore you need values from both data series to compute different parts of the formula. This include calculating the standard deviations for both YM and ES. To do this, we can use a for-loop sampling 20 data points of Close values to calculate the mean first
total = 0
for (int x = 0, x < 20, x++) // calculate mean for YM
{
total = Close[0] + total;
}
YMmean = total / 20;
total = 0
for (int x = 0, x < 20, x++) // calculate mean for ES
{
total = Closes[1] + total;
}
ESmean = total / 20;
I see that the above does not recognize the ES data series even though it is written as "Closes[1]".
So I tried re-writing it based on BarsInProgress as such:
if (BarsInProgress == 0)
{
total = 0
for (int x = 0, x < 20, x++) // calculate mean for YM
{
total = Close[0] + total;
}
YMmean = total / 20;
}
if (BarsInProgress == 1)
{
total = 0
for (int x = 0, x < 20, x++) // calculate mean for ES
{
total = Closes[1] + total;
}
ESmean = total / 20;
}
then it reads the values for ES. So does this mean that whenever we need values for the secondary data, we have to put in if (BarsInProgress == 1) every time? does a typical strategy only have the different sections once? like above, or does it have multiple sections of the same secondary index? For example
if (BarsInProgress == 0)
{
do some calculation here for primary data series
}
if (BarsInProgress == 1)
{
do some calculation here for secondary data series
}
if (BarsInProgress == 0)
{
do some calculation here for primary data series AGAIN
}
Comment