protectedoverridevoid Initialize() {
Add("VXX", PeriodType.Day, 1);
CalculateOnBarClose = true;
}
protectedoverridevoid OnBarUpdate() {
if (Time[0].Year < 2009) return;
if (Time[0].DayOfYear <= 34) return;
Print("");
if (BarsInProgress == 0) {
Print("BarsInProgress == 0");
Print(string.Format("Opens[0][0] = {0}", Opens[0][0]));
Print(string.Format("Opens[1][0] = {0}", Opens[1][0]));
Print(string.Format("Closes[0][0] = {0}", Closes[0][0]));
Print(string.Format("Closes[1][0] = {0}", Closes[1][0])); }
elseif (BarsInProgress == 1) {
Print("BarsInProgress == 1");
Print(string.Format("Opens[0][0] = {0}", Opens[0][0]));
Print(string.Format("Opens[1][0] = {0}", Opens[1][0]));
Print(string.Format("Closes[0][0] = {0}", Closes[0][0]));
Print(string.Format("Closes[1][0] = {0}", Closes[1][0])); }
}
I run the strategy in Strategy [FONT='Verdana','sans-serif']Analyzer[/font]. I choose Instrument=VXX, Type=Day, Value=1. This is the output I get:
BarsInProgress == 0
Opens[0][0] = 101.6
Opens[1][0] = 98.25
Closes[0][0] = 99.13
Closes[1][0] = 99.74
BarsInProgress == 1
Opens[0][0] = 101.6
Opens[1][0] = 101.6
Closes[0][0] = 99.13
Closes[1][0] = 99.13
BarsInProgress == 0
Opens[0][0] = 99
Opens[1][0] = 101.6
Closes[0][0] = 97.7
Closes[1][0] = 99.13
BarsInProgress == 1
Opens[0][0] = 99
Opens[1][0] = 99
Closes[0][0] = 97.7
Closes[1][0] = 97.7
I would like to simply add the VXX as a filter to some of my strategies, but the numbers for its open and close seem to be lagging by 1.
Is there no way to access the second bars Opens and Closes from the first bars OnBarUpdate? Or is there another way I can code my strategy so I can add an Instrument or two as filters?
Thanks,
Erik
Comment