I am trying to write a program which will find the total # of pips (price gained) with a strategy.
Basically, the strategy is whenever the stock price is 5
, and we will start trading and we will continue trading as long as the stock price is higher than 2
and lower than 9
, meaning in the range (2,9)
. When the price hits 2
or 9
, we stop trading.
When I run the program it doesn't execute correctly, it does not enter the second while loop . What is missing?
% total : the total # of pips gained with a strategy % diff: the difference of the stock price btw 2 consecutive dates % Sheet1: a data matrix loaded from excel, where the first column is date and second one is stock stock price
total = 0;
diff = 0;
i =1;
j = 1;
while i <= length(Sheet1)
i
if Sheet1(i,2)==5
while Sheet1(j,2) > 2
j
diff = Sheet1(j+1,2) - Sheet1(j,2);
total = total + diff;
j = j + 1 ;
total
diff
end
end
i = i+ 1 ;
end