WatchList w/ Mobius Deconstructed Timeframes

greco26

Active member
Hi All, I created this watchlist column so that I can see the open and close of multiple timeframes in 1 column for viewing full timeframe continuity. Now I would like to be able to calculate which timeframe has the highest difference from the open and plot that amount. I cannot figure out how to get the actual open and close values from my custom expressions though. Does anyone know if this is possible and if so, how? I tried to 'getvalue' but its not pulling the correct open/close timeframe based on my expectation. Also, this code should be loaded on a 5 minute watchlist/chart. Thanks as always!!

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 FTC_UP = B_5_Cndl and B_15_Bars and B_30_Bars and B_60_Bars and B_Day_Bar;
def FTC_DN = !B_5_Cndl and !B_15_Bars and !B_30_Bars and !B_60_Bars and !B_Day_Bar;




def fifteenOp = GetValue(open, B_15_Bars);
def fifteenCL = GetValue(close, B_15_Bars);
def ThirtyOp = GetValue(open, B_30_Bars);
def ThirtyCl = GetValue(close, B_30_Bars);
def SixtyOp = GetValue(open, B_60_Bars);
def SixtyCl = GetValue(close, B_60_Bars);
#------------------------------------
# LABEL SECTION
#------------------------------------
AddLabel(yes, (if
FTC_UP or FTC_DN then “FTC" else “-”), Color.BLACK);
 
Last edited by a moderator:
I think you should be able to to it as a scan but I don't think code would be necessary. While I don't have a full understanding of what you are looking to accomplish, in theory you should be able to create each requirement on each timeframe and set them as must include all within the scan. Again, not sure if that's what you're looking for though.
Actually, I want to get the MA's value from different timeframes and get an average of them. Can such a thing be done via a scan?
 
Actually, I want to get the MA's value from different timeframes and get an average of them. Can such a thing be done via a scan?
Yes, I think so. You can build it as chart study then reference the study’s plot in the scanner. Doing it this way, I don’t think there would be the multi timeframe error the scanner would normally throw with multiple timeframes.
 
Yes, I think so. You can build it as chart study then reference the study’s plot in the scanner. Doing it this way, I don’t think there would be the multi timeframe error the scanner would normally throw with multiple timeframes.
Seriously?! 😲 I thought the need to specify a timeframe for a chart study prevented such a thing. Will be testing this out soon!
 
Tried using multiple secondsFromTime/secondsTillTime in a study. While it didn't produce the dreaded "toocomplexexception", it produced results that were very different from a study using multiple aggregations. And I still can't use the deconstructed code for higher intraday timeframes as I don't understand it.
 

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