I'm having hard time in positioning timeframe condition properly.
Below is my code:
As soon as I try to access values of these variables that start with TF, it gives same error that 2ndary timeframe is not allowed on lower tf which I'm aware of. And thats why I'm setting them to nan by checking periodMin so that when I'll access it in the label, it should not give me error but I'm not able to get it to work.
All I want to do is to add label as shown below for the TF thats higher and applicable.
However, whenever I open it on say 3 min timeframe, the error of 2ndary timeframe pops up from 1 min variable that I declared.
How should one proceed in this case assuming we need to add label of higher timeframes if you're on lower timeframe? Say, I'm on 2 min timeframe, then it should add label for 3 and 5 min and hide for 1 min as ToS does not support it.
Below is my code:
Code:
def nan = Double.NaN;
def currentTimeframe = GetAggregationPeriod();
def periodMin = currentTimeframe / 1000 / 60;
def TF1Bull = if periodMin <= 1 then close(period = AggregationPeriod.MIN) > MovAvgExponential(close(period = AggregationPeriod.MIN), 200) else nan;
def TF3Bull = if periodMin <= 3 then close(period = AggregationPeriod.THREE_MIN) > MovAvgExponential(close(period = AggregationPeriod.THREE_MIN), 200) else nan;
def TF5Bull = if periodMin <= 5 then close(period = AggregationPeriod.FIVE_MIN) > MovAvgExponential(close(period = AggregationPeriod.FIVE_MIN), 200) else nan;
As soon as I try to access values of these variables that start with TF, it gives same error that 2ndary timeframe is not allowed on lower tf which I'm aware of. And thats why I'm setting them to nan by checking periodMin so that when I'll access it in the label, it should not give me error but I'm not able to get it to work.
All I want to do is to add label as shown below for the TF thats higher and applicable.
Code:
AddLabel(!isNaN(TF1Bull), if TF1Bull then "1 Min: Bullish" else "1 Min: Bearish", if TF1Bull then Color.GREEN else Color.RED);
AddLabel(!isNaN(TF3Bull), if TF3Bull then "3 Min: Bullish" else "3 Min: Bearish", if TF3Bull then Color.GREEN else Color.RED);
AddLabel(!isNaN(TF5Bull), if TF5Bull then "5 Min: Bullish" else "5 Min: Bearish", if TF5Bull then Color.GREEN else Color.RED);
However, whenever I open it on say 3 min timeframe, the error of 2ndary timeframe pops up from 1 min variable that I declared.
How should one proceed in this case assuming we need to add label of higher timeframes if you're on lower timeframe? Say, I'm on 2 min timeframe, then it should add label for 3 and 5 min and hide for 1 min as ToS does not support it.