Hi, I am trying to write an indicator that starts by getting the max volume over a user specified lookback period. Sometimes the lookback period is beyond the point where the stock started trading. So first I determine the actual lookback period if the stock has traded for less time than the user specified lookback. Then I use this lookback for my computations.
## Highest Volume day in the lookback period
input lookbackDays = 500;
def agDay = AggregationPeriod.DAY;
def actualLookback = fold i1 = 1 to lookbackDays while !IsNaN(close(period = agDay)[i1]) do i1;
AddLabel(yes, "actualLookBack" + actualLookback);
def lookback = actualLookback;
def vol = volume(period = agDay);
AddLabel(yes, "Volume on lookback Day " + GetValue(vol, lookback));
def volum1 = fold i = 1 to lookback with h=0 do if GetValue(vol, i) > h then GetValue(vol, i) else h ;
AddLabel(yes, "Max Volume " + volum1);
THe fold statement seems to fail. Any suggestions how to fix this?
If however the lookback period was constant and vol is used instead then everything works fine but that is not what I am looking for.
Thanks!
## Highest Volume day in the lookback period
input lookbackDays = 500;
def agDay = AggregationPeriod.DAY;
def actualLookback = fold i1 = 1 to lookbackDays while !IsNaN(close(period = agDay)[i1]) do i1;
AddLabel(yes, "actualLookBack" + actualLookback);
def lookback = actualLookback;
def vol = volume(period = agDay);
AddLabel(yes, "Volume on lookback Day " + GetValue(vol, lookback));
def volum1 = fold i = 1 to lookback with h=0 do if GetValue(vol, i) > h then GetValue(vol, i) else h ;
AddLabel(yes, "Max Volume " + volum1);
THe fold statement seems to fail. Any suggestions how to fix this?
If however the lookback period was constant and vol is used instead then everything works fine but that is not what I am looking for.
Thanks!