Add("NQ 03-15", PeriodType.Minute, 1);
Add("NQ 03-15", PeriodType.Minute, 5);
Add(PeriodType.Minute, 3);
Add(PeriodType.Day, 1);
Add("^COMP", PeriodType.Day, 1);
Add("^COMP", PeriodType.Minute, 1);
What I'm trying to do is add a line to the code which compares the stock's performance relative to the Nasdaq Index. So for example if the strategy is to trigger a long trade I want the stock to be outperforming the market. To do this I created the following formula which will compare the stocks performance measured by its close the previous day to the Nassaq's performance measured by it's close the previous day. Both are measured in percentage
&& ((Close[0]-Closes[4][1])/Closes[4][1])*100>((Closes[6][0]-Closes[5][1])/Closes[5][1])*100
So for example let's assume it's today and the stock is trading at 30.50 at 9:35. Assume also that it closed yesterday at 30.00 The first half of the formula should yield the following:
(30.50 - 30)/30*100 =1.6667
Assume the nasdaq yesterday closed at 4937. It is currently at 4928.
the second half of the formula would yield as follows:
4928-4937/4937*100= -.18229
Since the first portion of the formula is greater than the second the statement would be true. When I enable the strategy though this line of code is not working. I have the strategy with and without this line and can compare the two and see when it should be working - and it is not.
The problem I'm getting is referencing the previous day's close for both the stock (I.E. "Closes[4][1]") and Nasdaq ("Closes[5][1]"). Apparenly when you add a dayperiod time frame, the current day is not "Bar[0]" until the day closes so a reference to Bar[1] during the day is invalid. If this is so, how do you ever reference the previous day's close in a formula during the day you are running the chart. So if it's Wednesday in the middle of the day, how do you ever refer to the Tuesday close since the Wednesday bar only becomes Bar[0] at Wednesday's close.
I don't know if that makes sense but it anyone can help I would appreciate it.
Comment