Multi Timeframe labels on different timeframe

serendipity2020

Member
Plus
I'm having hard time in positioning timeframe condition properly.
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.
 
Solution
I'm having hard time in positioning timeframe condition properly.
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...
I'm having hard time in positioning timeframe condition properly.
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.

take a look at this
https://usethinkscript.com/threads/mtf-arrows-choose-1-of-3-sets-of-5-periods.8959/
the first thing it does is compare aggregation times,
then it sets the agg time.
then it uses the agg time.

i think the way you have it, trying to use an agg time in the same formula as comparing the agg time, will result in errors.
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
614 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top