Trikortreat12
New member
I'm trying to write this script where I define 2 aggregation periods. 1 of them is daily, and other is hour/4 hour. My problem comes in when i want to define my 2nd aggregation period. I want to only have the aggregation period change if I have an ATR value greater than 3. I think it's a problem with the way integers/conditionals work in thinkscript, but am not sure.
Code:
input averagetype = AverageType.WILDERS;
input ATRlength = 10;
input Agg_1 = AggregationPeriod.Day;
def Agg_2;
def ATR = MovingAverage (averagetype, TrueRange(high(period = Agg_1)[1], close(period = Agg_1)[1], low(period = Agg_1)[1]), ATRlength);
if (ATR > 3) {
Agg_2 = AggregationPeriod.FOUR_HOURS;
}
else {
Agg_2 = AggregationPeriod.HOUR;
}