Timeframe Deconstruction for Watchlist Column Multi Timeframes

greco26

Active member
As we know, TOS doesn't support multiple TF's in Watchlist columns. I was wondering if I could use Mobius timeframe deconstruction code to define custom timeframes which I could then use to define HLOC for each timeframe I build. Has anyone attempted to do this before? Do you see any reason this wouldn't work?

Code:
# 30 minute blocks of time based on 24hr clock

# Deconstruct getTime() function
# Mobius
# 06.06.2019 Chat Room Request Updated from prior start on same code

def time2 = GetTime();
def millSecDay = 24 * 60 * 60 * 1000;
def days = time2 / millSecDay;
def years = days / 365.228739;
def partOfYear = years % 1;
def DaysThisYear = 365.228739 * partOfYear;
def DOY = GetDay();
def TodayRemaining = 1 - (DaysThisYear % 1);
def TimeNow = 24 - (24 * TodayRemaining);
def MinPast = Round(60 * (TimeNow % 1), 0);
 
Solution
I've updated the code to correct a few bugs. Works perfectly during RTH as far as my testing shows.
Code:
#########################################

#WATCHLIST COLUMN FOR FTC
# Created by Tim G
#Version September 3, 2021
#Version September 4, 2021

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

# INCLUDES FTC FOR DAY, 60 (BOTTOM OF HOUR), 30, 15, 5

# IMPORTANT - WATCHLIST TIME MUST BE SET TO 5 MINUTES

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


def O = open;
def C = close;

#5 Min Bar Calcs
def B_5_Cndl = o[0] <=c;

#15 Min Bar Calcs
def B_15_Cndl_5 = o[0] <=c;
def B_15_Cndl_10 = o[1] <=c;
def B_15_Cndl_15 = o[2] <=c;

#30 Min Bar Cals
def B_30_Cndl_5 = o[0] <=c;
def B_30_Cndl_10 = o[1] <=c;
def B_30_Cndl_15 = o[2] <=c;
def B_30_Cndl_20 =...
@greco26 Give it a go and report back... I'm sure there are multiple members who would be interested in your findings... The only potential issue would be slowing your watchlist updates even further depending on its length...
 

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

Here's what I came up with for the watchlist column. It shows me timeframe continuity on the 5, 15, 30, 60, and Day. Testing this tomorrow during RTH but looks like its working after hours. We'll see how this does on the performance side of things too.
Code:
#########################################

#WATCHLIST COLUMN FOR FTC
# Created by Tim G
#Version September 3, 2021

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

# INCLUDES FTC FOR DAY, 60 (BOTTOM OF HOUR), 30, 15, 5

# IMPORTANT - WATCHLIST TIME MUST BE SET TO 5 MINUTES

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

def O = open;
def C = close;

#5 Min Bar Calcs
def B_5_Cndl = o[0] <c;

#15 Min Bar Calcs
def B_15_Cndl_5 = o[0] <c;
def B_15_Cndl_10 = o[1] <c;
def B_15_Cndl_15 = o[2] <c;

#30 Min Bar Cals
def B_30_Cndl_5 = o[0] <c;
def B_30_Cndl_10 = o[1] <c;
def B_30_Cndl_15 = o[2] <c;
def B_30_Cndl_20 = o[3] <c;
def B_30_Cndl_25 = o[4] <c;
def B_30_Cndl_30 = o[5] <c;

#60 Min Bar Calcs
def B_60_Cndl_5 = o[0] <c;
def B_60_Cndl_10 = o[1] <c;
def B_60_Cndl_15 = o[2] <c;
def B_60_Cndl_20 = o[3] <c;
def B_60_Cndl_25 = o[4] <c;
def B_60_Cndl_30 = o[5] <c;
def B_60_Cndl_35 = o[6] <c;
def B_60_Cndl_40 = o[7] <c;
def B_60_Cndl_45 = o[8] <c;
def B_60_Cndl_50 = o[9] <c;
def B_60_Cndl_55 = o[10] <c;
def B_60_Cndl_60 = o[11] <c;

#Day Bar Calcs
def ORActive1 = if secondstilltime (935) > 0 and secondsfromtime (930) >=0 then 1 else 0;
Rec T_DayOpen = if T_DayOpen[1]==0 or ORActive1[1]==0 AND ORActive1==1 then o else if ORActive1 AND o > T_DayOpen[1] then o else T_DayOpen[1];
def B_Day_Bar = T_DayOpen < c;


# Deconstruct getTime() function
# Mobius
def time2 = GetTime();
def millSecDay = 24 * 60 * 60 * 1000;
def days = time2 / millSecDay;
def years = days / 365.228739;
def partOfYear = years % 1;
def DaysThisYear = 365.228739 * partOfYear;
def DOY = GetDay();
def TodayRemaining = 1 - (DaysThisYear % 1);
def TimeNow = 24 - (24 * TodayRemaining);
def MinPast = Round(60 * (TimeNow % 1), 0);



#Defines the 5 minute blocks of time in 60 minutes
def Time_5 = minpast >=0 and minpast <5;
def Time_10 = minpast >=5 and minpast <10;
def Time_15 = minpast >=10 and minpast <15;
def Time_20 = minpast >=15 and minpast <20;
def Time_25 = minpast >=20 and minpast <25;
def Time_30 = minpast >=25 and minpast <30;
def Time_35 = minpast >=30 and minpast <35;
def Time_40 = minpast >=35 and minpast <40;
def Time_45 = minpast >=40 and minpast <45;
def Time_50 = minpast >=45 and minpast <50;
def Time_55 = minpast >=50 and minpast <55;
def Time_60 = minpast >=55 and minpast <60;

#15 Min Bars
def B_15_Bars  =
if Time_5 then B_15_Cndl_5 else if
Time_10 then B_15_Cndl_10 else if
Time_15 then B_15_Cndl_15 else if
Time_20 then B_15_Cndl_5 else if
Time_25 then B_15_Cndl_10 else if
Time_30 then B_15_Cndl_15 else if
Time_35 then B_15_Cndl_5 else if
Time_40 then B_15_Cndl_10 else if
Time_45 then B_15_Cndl_15 else if
Time_50 then B_15_Cndl_5 else if
Time_55 then B_15_Cndl_10 else if
Time_60 then B_15_Cndl_15 else double.nan;

#30 Min Bars
def B_30_Bars  =
if Time_5 then B_30_Cndl_5 else if
Time_10 then B_30_Cndl_10 else if
Time_15 then B_30_Cndl_15 else if
Time_20 then B_30_Cndl_20 else if
Time_25 then B_30_Cndl_25 else if
Time_30 then B_30_Cndl_30 else if
Time_35 then B_30_Cndl_5 else if
Time_40 then B_30_Cndl_10 else if
Time_45 then B_30_Cndl_15 else if
Time_50 then B_30_Cndl_20 else if
Time_55 then B_30_Cndl_25 else if
Time_60 then B_30_Cndl_30 else double.nan;

#60 Min Bars
def B_60_Bars  =
if Time_5 then B_60_Cndl_5 else if
Time_10 then B_60_Cndl_10 else if
Time_15 then B_60_Cndl_15 else if
Time_20 then B_60_Cndl_20 else if
Time_25 then B_60_Cndl_25 else if
Time_30 then B_60_Cndl_30 else if
Time_35 then B_60_Cndl_35 else if
Time_40 then B_60_Cndl_40 else if
Time_45 then B_60_Cndl_45 else if
Time_50 then B_60_Cndl_50 else if
Time_55 then B_60_Cndl_55 else if
Time_60 then B_60_Cndl_60 else double.nan;


plot FTC_UP = B_5_Cndl and B_15_Bars and B_30_Bars and B_60_Bars and B_Day_Bar;
plot FTC_DN = !B_5_Cndl and !B_15_Bars and !B_30_Bars and !B_60_Bars and !B_Day_Bar;
#------------------------------------
# LABEL SECTION
#------------------------------------
AddLabel(yes,(if
FTC_UP or FTC_DN then “FTC" else“-”), color.black);
 

#------------------------------------
# Background colors
#------------------------------------
assignbackgroundColor(if FTC_UP then color.green else if FTC_DN then color.red else color.black );
 
I've updated the code to correct a few bugs. Works perfectly during RTH as far as my testing shows.
Code:
#########################################

#WATCHLIST COLUMN FOR FTC
# Created by Tim G
#Version September 3, 2021
#Version September 4, 2021

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

# INCLUDES FTC FOR DAY, 60 (BOTTOM OF HOUR), 30, 15, 5

# IMPORTANT - WATCHLIST TIME MUST BE SET TO 5 MINUTES

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


def O = open;
def C = close;

#5 Min Bar Calcs
def B_5_Cndl = o[0] <=c;

#15 Min Bar Calcs
def B_15_Cndl_5 = o[0] <=c;
def B_15_Cndl_10 = o[1] <=c;
def B_15_Cndl_15 = o[2] <=c;

#30 Min Bar Cals
def B_30_Cndl_5 = o[0] <=c;
def B_30_Cndl_10 = o[1] <=c;
def B_30_Cndl_15 = o[2] <=c;
def B_30_Cndl_20 = o[3] <=c;
def B_30_Cndl_25 = o[4] <=c;
def B_30_Cndl_30 = o[5] <=c;

#60 Min Bar Calcs
def B_60_Cndl_5 = o[0] <=c;
def B_60_Cndl_10 = o[1] <=c;
def B_60_Cndl_15 = o[2] <=c;
def B_60_Cndl_20 = o[3] <=c;
def B_60_Cndl_25 = o[4] <=c;
def B_60_Cndl_30 = o[5] <=c;
#start here for bottom of hour candle
def B_60_Cndl_35 = o[6] <=c;
def B_60_Cndl_40 = o[7] <=c;
def B_60_Cndl_45 = o[8] <=c;
def B_60_Cndl_50 = o[9] <=c;
def B_60_Cndl_55 = o[10] <=c;
def B_60_Cndl_60 = o[11] <=c;

#Day Bar Calcs
def ORActive1 = if secondstilltime (935) > 0 and secondsfromtime (930) >=0 then 1 else 0;
Rec T_DayOpen = if T_DayOpen[1]==0 or ORActive1[1]==0 AND ORActive1==1 then o else if ORActive1 AND o > T_DayOpen[1] then o else T_DayOpen[1];
def B_Day_Bar = T_DayOpen <=c;


# Deconstruct getTime() function
# Mobius
def time2 = GetTime();
def millSecDay = 24 * 60 * 60 * 1000;
def days = time2 / millSecDay;
def years = days / 365.228739;
def partOfYear = years % 1;
def DaysThisYear = 365.228739 * partOfYear;
def DOY = GetDay();
def TodayRemaining = 1 - (DaysThisYear % 1);
def TimeNow = 24 - (24 * TodayRemaining);
def MinPast = Round(60 * (TimeNow % 1), 0);



#Defines the 5 minute blocks of time in 60 minutes
def Time_5 = minpast >=0 and minpast <5;
def Time_10 = minpast >=5 and minpast <10;
def Time_15 = minpast >=10 and minpast <15;
def Time_20 = minpast >=15 and minpast <20;
def Time_25 = minpast >=20 and minpast <25;
def Time_30 = minpast >=25 and minpast <30;
#start here for bottom of hour candle
def Time_35 = minpast >=30 and minpast <35;
def Time_40 = minpast >=35 and minpast <40;
def Time_45 = minpast >=40 and minpast <45;
def Time_50 = minpast >=45 and minpast <50;
def Time_55 = minpast >=50 and minpast <55;
def Time_60 = minpast >=55 and minpast <60;

#15 Min Bars
def B_15_Bars  =
if Time_5 then B_15_Cndl_5 else if
Time_10 then B_15_Cndl_10 else if
Time_15 then B_15_Cndl_15 else if
Time_20 then B_15_Cndl_5 else if
Time_25 then B_15_Cndl_10 else if
Time_30 then B_15_Cndl_15 else if
Time_35 then B_15_Cndl_5 else if
Time_40 then B_15_Cndl_10 else if
Time_45 then B_15_Cndl_15 else if
Time_50 then B_15_Cndl_5 else if
Time_55 then B_15_Cndl_10 else if
Time_60 then B_15_Cndl_15 else double.nan;

#30 Min Bars
def B_30_Bars  =
if Time_5 then B_30_Cndl_5 else if
Time_10 then B_30_Cndl_10 else if
Time_15 then B_30_Cndl_15 else if
Time_20 then B_30_Cndl_20 else if
Time_25 then B_30_Cndl_25 else if
Time_30 then B_30_Cndl_30 else if
Time_35 then B_30_Cndl_5 else if
Time_40 then B_30_Cndl_10 else if
Time_45 then B_30_Cndl_15 else if
Time_50 then B_30_Cndl_20 else if
Time_55 then B_30_Cndl_25 else if
Time_60 then B_30_Cndl_30 else double.nan;

#60 Min Bars
def B_60_Bars  =
if Time_35 then B_60_Cndl_5 else if
Time_40 then B_60_Cndl_10 else if
Time_45 then B_60_Cndl_15 else if
Time_50 then B_60_Cndl_20 else if
Time_55 then B_60_Cndl_25 else if
Time_60 then B_60_Cndl_30 else if
Time_5 then B_60_Cndl_35 else if
Time_10 then B_60_Cndl_40 else if
Time_15 then B_60_Cndl_45 else if
Time_20 then B_60_Cndl_50 else if
Time_25 then B_60_Cndl_55 else if
Time_30 then B_60_Cndl_60 else double.nan;


#def Show_All_FTC = show_5_and_up and ((B_5_Cndl and B_15_Bars and B_30_Bars and B_60_Bars and B_Day_Bar) or (!B_5_Cndl and !B_15_Bars and !B_30_Bars and !B_60_Bars and !B_Day_Bar));
#def Show_15_FTC = show_15_and_up and ((B_15_Bars and B_30_Bars and B_60_Bars and B_Day_Bar) or (!B_15_Bars and !B_30_Bars and !B_60_Bars and !B_Day_Bar));
#def Show_30_FTC = show_30_and_up and ((B_30_Bars and B_60_Bars and B_Day_Bar) or (!B_30_Bars and !B_60_Bars and !B_Day_Bar));
#def Show_60_FTC = show_60_and_up and (B_60_Bars and B_Day_Bar) or (!B_60_Bars and !B_Day_Bar);

#def show = if
#(show_5_and_up and
#(!show_15_and_up or !show_30_and_up or !show_60_and_up)) then show_all_FTC else if
#(show_15_and_up and
#(!show_5_and_up and !show_30_and_up and !show_60_and_up)) then show_15_FTC else if
#(show_30_and_up and
#(!show_5_and_up or !show_15_and_up or !show_60_and_up)) then show_30_FTC else if
#(show_60_and_up and
#(!show_5_and_up or !show_15_and_up or !show_30_and_up)) then show_60_FTC else
#double.nan;

plot FTC_UP = B_5_Cndl and B_15_Bars and B_30_Bars and B_60_Bars and B_Day_Bar;
plot FTC_DN = !B_5_Cndl and !B_15_Bars and !B_30_Bars and !B_60_Bars and !B_Day_Bar;
#------------------------------------
# LABEL SECTION
#------------------------------------
AddLabel(yes,(if
FTC_UP or FTC_DN then “FTC" else“-”), color.black);
 

#------------------------------------
# Background colors
#------------------------------------
assignbackgroundColor(if FTC_UP then color.green else if FTC_DN then color.red else color.black );

#addlabel (yes, "5:  "+B_5_Cndl   + "  ", Color.white );
#addlabel (yes, "15:  "+B_15_Bars   + "  ", Color.white );
#addlabel (yes, "30:  "+B_30_Bars   + "  ", Color.white );
#addlabel (yes, "60:  "+B_60_Bars   + "  ", Color.white );
#addlabel (yes, "Day:  "+B_Day_Bar   + "  ", Color.white );
#addlabel (yes, "FTC UP:  "+FTC_UP   + "  ", Color.white );
#addlabel (yes, "FTC DN:  "+FTC_DN   + "  ", Color.white );
 
Solution

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
471 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