I need a function to calculate the daily Average True Range, when testing on 5 minute data in TradeStation.
The following code doesn't generate the correct ATR. Any thoughts on how I can fix this?
Inputs: Length(NumericSimple);
Vars: DTHigh(0), DTLow(0), DTR(0);
if CloseD(1) > HighD(0) then
DTHigh = CloseD(1)
else
DTHigh = HighD(0);
if CloseD(1) < LowD(0) then
DTLow = CloseD(1)
else
DTLow = LowD(0);
DTR = DTHigh - DTLow;
DATR=Average(DTR, Length);
The following code doesn't generate the correct ATR. Any thoughts on how I can fix this?
Inputs: Length(NumericSimple);
Vars: DTHigh(0), DTLow(0), DTR(0);
if CloseD(1) > HighD(0) then
DTHigh = CloseD(1)
else
DTHigh = HighD(0);
if CloseD(1) < LowD(0) then
DTLow = CloseD(1)
else
DTLow = LowD(0);
DTR = DTHigh - DTLow;
DATR=Average(DTR, Length);