How To Create MTF Labels

Mr_Wheeler

Active member
How do you assign a window of time to a label so it always has specific data no matter what chart time is currently display on a chart?

I would like to display some labels to not correspond to what time window that is currently displayed on a chart such as 1 minute or 1 hour, but based on hard coded time such as asigning 1 minute to one label, and 30 minutes to a another label. I got an idea to improve another user's custom study, but I'm stuck on some code.
 
Last edited by a moderator:
## Golden and Death Cross indicator
## Coded by Chemmy at usethinkscript.com

#input src = close;
input fast = 50;
input slow = 200;
input avgtype = AverageType.SIMPLE;
input color_bars = yes;
input show_bubbles = yes;
input show_arrows = yes;

input one_minute_label = yes;
input two_minute_label = yes;
input five_minute_label = yes;
input ten_minute_label = yes;
input fifteen_minute_label = yes;
input thirty_minute_label = yes;

input one_hour_label = yes;
input two_hour_label = yes;
input four_hour_label = yes;

input one_day_label = yes;
input five_day_label = yes;
input one_month_label = yes;
input one_year_label = yes;

def Ag_1_min = AggregationPeriod.MIN;
def Ag_1_min_close = close(period = Ag_1_min);

def Ag_2_min = AggregationPeriod.two_MIN;
def Ag_2_min_close = close(period = Ag_2_min);

def Ag_5_min = AggregationPeriod.FIVE_MIN;
def Ag_5_min_close = close(period = Ag_5_min);

def Ag_10_min = AggregationPeriod.ten_MIN;
def Ag_10_min_close = close(period = Ag_10_min);

def Ag_15_min = AggregationPeriod.FIFTEEN_MIN;
def Ag_15_min_close = close(period = Ag_15_min);

def Ag_30_min = AggregationPeriod.THIRTY_MIN;
def Ag_30_min_close = close(period = Ag_30_min);

def Ag_1hr = AggregationPeriod.HOUR;
def Ag_1hr_close = close(period = Ag_1hr);

def Ag_2_hr = AggregationPeriod.TWO_HOURS;
def Ag_2_hr_close = close(period = Ag_2_hr);

def Ag_4_hr = AggregationPeriod.four_HOURS;
def Ag_4_hr_close = close(period = Ag_4_hr);

def Ag_day = AggregationPeriod.day;
def Ag_day_close = close(period = Ag_day);

def Ag_week = AggregationPeriod.week;
def Ag_week_close = close(period = ag_week);

def Ag_month = AggregationPeriod.month;
def Ag_month_close = close(period = Ag_month);

def Ag_year = AggregationPeriod.year;
def Ag_year_close = close(period = Ag_year);

def bn = barnumber();

script barssince {
input Condition = 0;
def barssince = if Condition then 1 else barssince[1] + 1;
plot return = barssince;
}


###################################################################################################
###################################################################################################

plot fast_Plot_1_minute = MovingAverage(avgtype, Ag_1_min_close, fast);
fast_Plot_1_minute.Hide();

plot slow_Plot_1_minute = MovingAverage(avgtype, Ag_1_min_close, slow);
slow_Plot_1_minute.Hide();

plot fast_Plot_2_minute = MovingAverage(avgtype, Ag_2_min_close, fast);
fast_Plot_2_minute.Hide();

plot slow_Plot_2_minute = MovingAverage(avgtype, Ag_2_min_close, slow);
slow_Plot_2_minute.Hide();

plot fast_Plot_5_minute = MovingAverage(avgtype, Ag_5_min_close, fast);
fast_Plot_5_minute.Hide();

plot slow_Plot_5_minute = MovingAverage(avgtype, Ag_5_min_close, slow);
slow_Plot_5_minute.Hide();

plot fast_Plot_10_minute = MovingAverage(avgtype, Ag_10_min_close, fast);
fast_Plot_10_minute.Hide();

plot slow_Plot_10_minute = MovingAverage(avgtype, Ag_10_min_close, slow);
slow_Plot_10_minute.Hide();

plot fast_Plot_15_minute = MovingAverage(avgtype, Ag_15_min_close, fast);
fast_Plot_15_minute.Hide();

plot slow_Plot_15_minute = MovingAverage(avgtype, Ag_15_min_close, slow);
slow_Plot_15_minute.Hide();

plot fast_Plot_30_minute = MovingAverage(avgtype, Ag_30_min_close, fast);
fast_Plot_30_minute.Hide();

plot slow_Plot_30_minute = MovingAverage(avgtype, Ag_30_min_close, slow);
slow_Plot_30_minute.Hide();


plot fast_Plot_1_hr = MovingAverage(avgtype, Ag_1hr_close, fast);
fast_Plot_1_hr.Hide();

plot slow_Plot_1_hr = MovingAverage(avgtype, Ag_1hr_close, slow);
slow_Plot_1_hr.Hide();

plot fast_Plot_2_hr = MovingAverage(avgtype, Ag_2_hr_close, fast);
fast_Plot_2_hr.Hide();

plot slow_Plot_2_hr = MovingAverage(avgtype, Ag_2_hr_close, slow);
slow_Plot_2_hr.Hide();

plot fast_Plot_4_hr = MovingAverage(avgtype, Ag_4_hr_close, fast);
fast_Plot_4_hr.Hide();

plot slow_Plot_4_hr = MovingAverage(avgtype, Ag_4_hr_close, slow);
slow_Plot_4_hr.Hide();


plot fast_Plot_day = MovingAverage(avgtype, Ag_day, fast);
fast_Plot_day.Hide();

plot slow_Plot_day = MovingAverage(avgtype, Ag_day, slow);
slow_Plot_day.Hide();

plot fast_Plot_week = MovingAverage(avgtype, ag_week, fast);
fast_Plot_week .Hide();

plot slow_Plot_week = MovingAverage(avgtype, ag_week, slow);
slow_Plot_week.Hide();

plot fast_Plot_month = MovingAverage(avgtype, Ag_month, fast);
fast_Plot_month.Hide();

plot slow_Plot_month = MovingAverage(avgtype, Ag_month, slow);
slow_Plot_month.Hide();

plot fast_Plot_year = MovingAverage(avgtype, Ag_year, fast);
fast_Plot_year.Hide();

plot slow_Plot_year = MovingAverage(avgtype, Ag_year, slow);
slow_Plot_year.Hide();


#fast_Plot_1_minute.setdefaultcolor(color.light_green);
#slow_Plot_1_minute.setdefaultcolor(color.red);

assignpricecolor(if color_bars then (if fast_Plot_1_minute>=slow_Plot_1_minute then color.green else color.red) else color.current);

def crossup_1m = fast_Plot_1_minute crosses above slow_Plot_1_minute;
def crossdn_1m = fast_Plot_1_minute crosses below slow_Plot_1_minute;

def crossup_2m = fast_Plot_2_minute crosses above slow_Plot_2_minute;
def crossdn_2m = fast_Plot_2_minute crosses below slow_Plot_2_minute;

def crossup_5m = fast_Plot_5_minute crosses above slow_Plot_5_minute;
def crossdn_5m = fast_Plot_5_minute crosses below slow_Plot_5_minute;

def crossup_10m = fast_Plot_10_minute crosses above slow_Plot_10_minute;
def crossdn_10m = fast_Plot_10_minute crosses below slow_Plot_10_minute;

def crossup_15m = fast_Plot_15_minute crosses above slow_Plot_15_minute;
def crossdn_15m = fast_Plot_15_minute crosses below slow_Plot_15_minute;

def crossup_30m = fast_Plot_30_minute crosses above slow_Plot_30_minute;
def crossdn_30m = fast_Plot_30_minute crosses below slow_Plot_30_minute;



def crossup_1hr = fast_Plot_1_hr crosses above slow_Plot_1_hr;
def crossdn_1hr = fast_Plot_1_hr crosses below slow_Plot_1_hr;

def crossup_2hr = fast_Plot_2_hr crosses above slow_Plot_2_hr;
def crossdn_2hr = fast_Plot_2_hr crosses below slow_Plot_2_hr;

def crossup_4hr = fast_Plot_4_hr crosses above slow_Plot_4_hr;
def crossdn_4hr = fast_Plot_4_hr crosses below slow_Plot_4_hr;



def crossup_1day = fast_Plot_day crosses above slow_Plot_day;
def crossdn_1day = fast_Plot_day crosses below slow_Plot_day;

def crossup_1week = fast_Plot_week crosses above slow_Plot_week;
def crossdn_1week = fast_Plot_week crosses below slow_Plot_week;

def crossup_1month = fast_Plot_month crosses above slow_Plot_month;
def crossdn_1month = fast_Plot_month crosses below slow_Plot_month;

def crossup_1year = fast_Plot_year crosses above slow_Plot_year;
def crossdn_1year = fast_Plot_year crosses below slow_Plot_1_minute;



#def uplabel= if show_bubbles and crossup then slow_Plot_1_minute else double.nan;
#def dnlabel = if show_bubbles and crossdn then slow_Plot_1_minute else double.nan;



#plot up = show_arrows and crossup;
#plot dn = show_arrows and crossdn;
#up.Hide();
#dn.Hide();
#up.setpaintingstrategy(paintingstrategy.boolean_arrow_up);
#dn.setpaintingstrategy(paintingstrategy.boolean_arrow_down);
#up.setdefaultcolor(color.light_green);
#dn.setdefaultcolor(color.white);

AddLabel(one_minute_label, "1 minute", Color.orange);
addlabel(one_minute_label, if fast_Plot_1_minute>=slow_Plot_1_minute then "Golden Cross " + barssince(crossup_1m) + " bars ago" else if fast_Plot_1_minute<slow_Plot_1_minute then "Death Cross " + barssince(crossdn_1m) + " bars ago" else "", if fast_Plot_1_minute>=slow_Plot_1_minute then color.green else if fast_Plot_1_minute<slow_Plot_1_minute then color.white else color.gray);

AddLabel(two_minute_label, "2 minute", Color.orange);
addlabel(two_minute_label , if fast_Plot_2_minute>=slow_Plot_2_minute then "Golden Cross " + barssince(crossup_2m) + " bars ago" else if fast_Plot_2_minute<slow_Plot_2_minute then "Death Cross " + barssince(crossdn_2m) + " bars ago" else "", if fast_Plot_2_minute>=slow_Plot_2_minute then color.green else if fast_Plot_2_minute<slow_Plot_2_minute then color.white else color.gray);

AddLabel(five_minute_label, "5 minute", Color.orange);
addlabel(five_minute_label, if fast_Plot_5_minute>=slow_Plot_5_minute then "Golden Cross " + barssince(crossup_5m) + " bars ago" else if fast_Plot_5_minute<slow_Plot_5_minute then "Death Cross " + barssince(crossdn_5m) + " bars ago" else "", if fast_Plot_5_minute>=slow_Plot_5_minute then color.green else if fast_Plot_5_minute<slow_Plot_5_minute then color.white else color.gray);

AddLabel(ten_minute_label, "10 minute", Color.orange);
addlabel(ten_minute_label, if fast_Plot_10_minute>=slow_Plot_10_minute then "Golden Cross " + barssince(crossup_10m) + " bars ago" else if fast_Plot_10_minute<slow_Plot_10_minute then "Death Cross " + barssince(crossdn_10m) + " bars ago" else "", if fast_Plot_10_minute>=slow_Plot_10_minute then color.green else if fast_Plot_10_minute<slow_Plot_10_minute then color.white else color.gray);

AddLabel(fifteen_minute_label, "15 minute", Color.orange);
addlabel(fifteen_minute_label, if fast_Plot_15_minute>=slow_Plot_15_minute then "Golden Cross " + barssince(crossup_15m) + " bars ago" else if fast_Plot_15_minute<slow_Plot_15_minute then "Death Cross " + barssince(crossdn_15m) + " bars ago" else "", if fast_Plot_15_minute>=slow_Plot_15_minute then color.green else if fast_Plot_15_minute<slow_Plot_15_minute then color.white else color.gray);

AddLabel(thirty_minute_label, "30 minute", Color.orange);
addlabel(thirty_minute_label, if fast_Plot_30_minute>=slow_Plot_30_minute then "Golden Cross " + barssince(crossup_30m) + " bars ago" else if fast_Plot_30_minute<slow_Plot_30_minute then "Death Cross " + barssince(crossdn_30m) + " bars ago" else "", if fast_Plot_30_minute>=slow_Plot_30_minute then color.green else if fast_Plot_30_minute<slow_Plot_30_minute then color.white else color.gray);

AddLabel(one_hour_label, "1 hour", Color.orange);
addlabel(one_hour_label, if fast_Plot_1_hr>=slow_Plot_1_hr then "Golden Cross " + barssince(crossup_1hr) + " bars ago" else if fast_Plot_1_hr<slow_Plot_1_hr then "Death Cross " + barssince(crossdn_1hr) + " bars ago" else "", if fast_Plot_1_hr>=slow_Plot_1_hr then color.green else if fast_Plot_1_hr<slow_Plot_1_hr then color.white else color.gray);

AddLabel(two_hour_label, "2 hour", Color.orange);
addlabel(two_hour_label, if fast_Plot_2_hr>=slow_Plot_2_hr then "Golden Cross " + barssince(crossup_2hr) + " bars ago" else if fast_Plot_2_hr<slow_Plot_2_hr then "Death Cross " + barssince(crossdn_2hr) + " bars ago" else "", if fast_Plot_2_hr>=slow_Plot_2_hr then color.green else if fast_Plot_2_hr<slow_Plot_2_hr then color.white else color.gray);

AddLabel(four_hour_label, "4 hour", Color.orange);
addlabel(four_hour_label, if fast_Plot_4_hr>=slow_Plot_4_hr then "Golden Cross " + barssince(crossup_4hr) + " bars ago" else if fast_Plot_4_hr<slow_Plot_4_hr then "Death Cross " + barssince(crossdn_4hr) + " bars ago" else "", if fast_Plot_4_hr>=slow_Plot_4_hr then color.green else if fast_Plot_4_hr<slow_Plot_4_hr then color.white else color.gray);

AddLabel(one_day_label, "1 day", Color.orange);
addlabel(one_day_label, if fast_Plot_day>=slow_Plot_day then "Golden Cross " + barssince(crossup_1day) + " bars ago" else if fast_Plot_day<slow_Plot_day then "Death Cross " + barssince(crossdn_1day) + " bars ago" else "", if fast_Plot_day>=slow_Plot_day then color.green else if fast_Plot_day<slow_Plot_day then color.white else color.gray);

AddLabel(five_day_label, "1 week", Color.orange);
addlabel(five_day_label, if fast_Plot_week>=slow_Plot_week then "Golden Cross " + barssince(crossup_1week) + " bars ago" else if fast_Plot_week<slow_Plot_week then "Death Cross " + barssince(crossdn_1week) + " bars ago" else "", if fast_Plot_week>=slow_Plot_week then color.green else if fast_Plot_week<slow_Plot_week then color.white else color.gray);

AddLabel(one_month_label, "1 month", Color.orange);
addlabel(one_month_label, if fast_Plot_month>=slow_Plot_month then "Golden Cross " + barssince(crossup_1month) + " bars ago" else if fast_Plot_month<slow_Plot_month then "Death Cross " + barssince(crossdn_1month) + " bars ago" else "", if fast_Plot_month>=slow_Plot_month then color.green else if fast_Plot_month<slow_Plot_month then color.white else color.gray);

AddLabel(one_year_label, "1 year", Color.orange);
addlabel(one_year_label, if fast_Plot_year>=slow_Plot_year then "Golden Cross " + barssince(crossup_1year) + " bars ago" else if fast_Plot_year<slow_Plot_year then "Death Cross " + barssince(crossdn_1year) + " bars ago" else "", if fast_Plot_year>=slow_Plot_year then color.green else if fast_Plot_year<slow_Plot_year then color.white else color.gray);
 

Attachments

  • xzcxzcz.png
    xzcxzcz.png
    17.4 KB · Views: 112
Last edited:
I was apparently wrong, the script works but the way TOS renders data not all aggregation periods work on the 1 minute charts. The final code is updated.
 

Attachments

  • dfsdfds.png
    dfsdfds.png
    16.4 KB · Views: 96

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
514 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