Move Indicator To Lower Timeframe

Ryguy

New member
This is a simple indicator that shows the previous Highs, Lows, and Opens EXCEPT the current day open.
https://docs.google.com/document/d/...D4rupT-K-gv6k8MJk/edit#heading=h.dvzfc72qzzjm

I use this to help me trade TheStrat method. Currently, it only works on the Higher Time Frames (Daily, Weekly, Monthly, and Quarterly.) I'm trying to make it work on intraday timeframes being 15min, 30min, 1hr, along with potentially the 2hr and 4hr. Can anyone help me with this? I went ahead and attached the code.

Code:
###############################################
#Strat Lines for the following:
#Prior Hi/Lo lines for Day, Week, Month, Quarter
#Line for All time high
#lines for SSS50PercentRule
#Lines for MotherBar problems

#Created by Tim G
#version 01/23/2022

#Calm Colors Updated by @Phaedos
###############################################

#Show/hide aggregation periods

input ShowAllTimeHigh = yes;
input ShowSSSLines = yes;
input Show50PctLine = yes;
input showbubbles = yes;
input showCloud = yes;
#input showMBproblems = yes;
input show1d  = yes;
input show1dOp = yes;
input show1w  = yes;
input show1WOp = no;
input show1mo = yes;
input show1MOp = no;
input show1q  = no;
def offset = 1;

# place bubbles after last bar, to id the lines
# prevday_levels_onalldays_01
# halcyonguy
# 21-08-12
def futurebar = 3;
def x = (!IsNaN(close[futurebar]) and IsNaN(close[futurebar - 1]));
def futurebary = -10;
def y = (!IsNaN(close[futurebary]) and IsNaN(close[futurebary - 1]));
def futurebarz = 3;
def z = (!IsNaN(close[futurebarz]) and IsNaN(close[futurebarz - 1]));



### 1d timeframe ###

def tf1d = AggregationPeriod.DAY;
def valid1d = GetAggregationPeriod() <= AggregationPeriod.DAY;
def h1d;
def l1d;
def l1dago;
def o1d;
def o1dc;
def c1d;


if valid1d and show1d {
    h1d = high (period = tf1d)[offset];
    ;
    l1d = low  (period = tf1d)[offset];
    l1dago = low  (period = tf1d)[1];
    o1d = open (period = tf1d);
    o1dc =  open (period = tf1d);
    c1d = close(period = tf1d);


} else {
    h1d = Double.NaN;
    l1d = Double.NaN;
    l1dago = Double.NaN;
    o1d = Double.NaN;
    o1dc = Double.NaN;
    c1d = Double.NaN;
}

def bn1d = HighestAll(if open == o1d then BarNumber() - 1  else Double.NaN);


def Post = GetTime() > RegularTradingEnd(GetYYYYMMDD());
def Pre = GetTime() < RegularTradingStart(GetYYYYMMDD());
def Closed  = Post or Pre;

plot daylow = if BarNumber() < bn1d then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then l1d else Double.NaN);
plot daylow2 = if BarNumber() < bn1d then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then l1d else Double.NaN);
plot dayhigh = if BarNumber() < bn1d then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then h1d else Double.NaN);

plot dayhigh2 = if BarNumber() < bn1d then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then h1d else Double.NaN);
plot dayopen = if BarNumber() < bn1d then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) and show1dOp then o1d else Double.NaN);
plot dayopen2 = if BarNumber() < bn1d then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) and show1dOp then o1dc else Double.NaN);

dayhigh.SetDefaultColor(CreateColor(133, 202, 91));
dayhigh.SetStyle(Curve.SHORT_DASH);
dayhigh.SetLineWeight(1);
dayhigh2.SetDefaultColor(CreateColor(133, 202, 91));
dayhigh2.SetLineWeight(1);

daylow.SetDefaultColor(CreateColor(252, 125, 127));
daylow.SetStyle(Curve.SHORT_DASH);
daylow.SetLineWeight(1);
daylow2.SetDefaultColor(CreateColor(252, 125, 127));
daylow2.SetLineWeight(1);


dayopen.SetDefaultColor(Color.WHITE);
dayopen.SetStyle(Curve.SHORT_DASH);
dayopen2.SetDefaultColor(Color.WHITE);
dayopen.SetLineWeight(1);
dayopen2.SetLineWeight(1);

AddChartBubble(showbubbles and x, daylow, "YDL", CreateColor(252, 125, 127), yes);
AddChartBubble(showbubbles and x, dayhigh, "YDH", CreateColor(133, 202, 91), yes);
AddChartBubble(showbubbles and x, dayopen, "DO", Color.WHITE, yes);

### 1w timeframe ###

def tf1w = AggregationPeriod.WEEK;
def valid1w = GetAggregationPeriod() <= AggregationPeriod.WEEK;
def h1w;
def l1w;
def o1w;
def o1wc;
def c1w;

def D1w = Round(c1w - o1w);

if valid1w and show1w {


    h1w = high (period = tf1w)[offset];
    l1w = low  (period = tf1w)[offset];
    o1w = open (period = tf1w);
    o1wc =  open (period = tf1w);
    c1w = close(period = tf1w);

} else {
    h1w = Double.NaN;
    l1w = Double.NaN;
    o1w = Double.NaN;
    o1wc = Double.NaN;
    c1w = Double.NaN;
}

def bn1w = HighestAll(if open == o1wc then BarNumber() - 2 else Double.NaN);

plot weeklow = if BarNumber() < bn1w then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then l1w else Double.NaN);
plot weekhigh = if BarNumber() < bn1w then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then h1w else Double.NaN);
plot weeklow2 = if BarNumber() < bn1w then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then l1w else Double.NaN);
plot weekhigh2 = if BarNumber() < bn1w then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then h1w else Double.NaN);
plot weekopen = if BarNumber() < bn1w then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) and show1WOp then o1wc[0] else Double.NaN);
plot weekopen2 = if BarNumber() < bn1w then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) and show1WOp then o1wc[0] else Double.NaN);

weekhigh.SetDefaultColor(CreateColor(133, 202, 91));
weekhigh.SetStyle(Curve.SHORT_DASH);
weekhigh.SetLineWeight(1);
weekhigh2.SetDefaultColor(CreateColor(133, 202, 91));
weekhigh2.SetLineWeight(1);

weeklow.SetDefaultColor(CreateColor(252, 125, 127));
weeklow.SetStyle(Curve.SHORT_DASH);
weeklow.SetLineWeight(1);
weeklow2.SetDefaultColor(CreateColor(252, 125, 127));
weeklow2.SetLineWeight(1);

weekopen.SetDefaultColor(Color.WHITE);
weekopen.SetStyle(Curve.SHORT_DASH);
weekopen2.SetDefaultColor(Color.WHITE);
weekopen.SetLineWeight(2);
weekopen2.SetLineWeight(2);

# place bubbles after last bar, to id the lines


AddChartBubble(showbubbles and x, weeklow, "LWL", CreateColor(252, 125, 127), yes);
AddChartBubble(showbubbles and x, weekhigh, "LWH", CreateColor(133, 202, 91), yes);
AddChartBubble(showbubbles and x, weekopen, "WO", Color.WHITE, yes);

### 1month timeframe ###

def tf1m = AggregationPeriod.MONTH;
def valid1m = GetAggregationPeriod() <= AggregationPeriod.MONTH;
def h1m;
def l1m;
def o1m;
def o1mc;
def c1m;

def D1m = Round(c1m - o1m);

if valid1m and show1mo {
    h1m = high (period = tf1m)[offset];
    l1m = low  (period = tf1m)[offset];
    o1m = open (period = tf1m)[offset];
    o1mc =  open (period = tf1m);
    c1m = close(period = tf1m)[offset];

} else {
    h1m = Double.NaN;
    l1m = Double.NaN;
    o1m = Double.NaN;
    o1mc = Double.NaN;
    c1m = Double.NaN;
}

def bn1m = HighestAll(if open == o1mc then BarNumber() - 3 else Double.NaN);


plot monthlow = if BarNumber() < bn1m then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then l1m[0] else Double.NaN);
plot monthhigh = if BarNumber() < bn1m then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then h1m[0] else Double.NaN);
plot monthlow2 = if BarNumber() < bn1m then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then l1m[0] else Double.NaN);
plot monthhigh2 = if BarNumber() < bn1m then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then h1m[0] else Double.NaN);

plot monthopen = if BarNumber() < bn1m then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) and show1MOp then o1mc else Double.NaN);
plot monthopen2 = if BarNumber() < bn1m then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) and show1MOp then o1mc else Double.NaN);
monthhigh.SetDefaultColor(CreateColor(133, 202, 91));
monthhigh.SetStyle(Curve.SHORT_DASH);
monthhigh.SetLineWeight(1);
monthhigh2.SetDefaultColor(CreateColor(133, 202, 91));
monthhigh2.SetLineWeight(1);


monthlow.SetDefaultColor(CreateColor(252, 125, 127));
monthlow.SetStyle(Curve.SHORT_DASH);
monthlow.SetLineWeight(1);
monthlow2.SetDefaultColor(CreateColor(252, 125, 127));
monthlow2.SetLineWeight(1);

monthopen.SetDefaultColor(CreateColor(133, 202, 91));
monthopen.SetStyle(Curve.SHORT_DASH);
monthopen2.SetDefaultColor(CreateColor(252, 125, 127));
monthopen.SetLineWeight(2);
monthopen2.SetLineWeight(2);
# place bubbles after last bar, to id the lines

AddChartBubble(showbubbles and x, monthlow, "PML", CreateColor(252, 125, 127), yes);
AddChartBubble(showbubbles and x, monthhigh, "PMH", CreateColor(133, 202, 91), yes);
AddChartBubble(showbubbles and x, monthopen, "MO", CreateColor(133, 202, 91), yes);

###############################################
#Code for Alltime High
###############################################


plot ATH = if ShowAllTimeHigh and GetAggregationPeriod() == AggregationPeriod.MONTH then HighestAll( high) else Double.NaN;
plot ATH2 = if ShowAllTimeHigh and GetAggregationPeriod() == AggregationPeriod.MONTH then HighestAll( high) else Double.NaN;
ATH.SetDefaultColor(Color.LIME);
ATH.SetStyle(Curve.MEDIUM_DASH);
ATH.SetLineWeight(2);
ATH2.SetDefaultColor(Color.MAGENTA);
ATH2.SetLineWeight(4);
AddChartBubble(ShowAllTimeHigh and showbubbles and y, ATH, "ATH", CreateColor(133, 202, 91), yes);

### 1quarter timeframe ###

def tf1q = AggregationPeriod.QUARTER;
def valid1q = GetAggregationPeriod() <= AggregationPeriod.QUARTER;
def h1q;
def l1q;
def o1q;
def o1qc;
def c1q;

def D1q = Round(c1q - o1q);

if valid1q and show1q {
    h1q = high (period = tf1q)[offset];
    l1q = low  (period = tf1q)[offset];
    o1q = open (period = tf1q)[offset];
    o1qc =  open (period = tf1q);
    c1q = close(period = tf1q)[offset];

} else {
    h1q = Double.NaN;
    l1q = Double.NaN;
    o1q = Double.NaN;
    o1qc = Double.NaN;
    c1q = Double.NaN;
}

def bn1q = HighestAll(if open == o1qc then BarNumber() - 4 else Double.NaN);

plot ql = if BarNumber() < bn1q then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then l1q[-1] else Double.NaN);
plot qh = if BarNumber() < bn1q then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then h1q[-1] else Double.NaN);
plot qo = if BarNumber() < bn1q then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then o1qc[-1] else Double.NaN);
plot qo2 = if BarNumber() < bn1q then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then o1qc[-1] else Double.NaN);
ql.SetDefaultColor(CreateColor(252, 125, 127));
qh.SetDefaultColor(CreateColor(133, 202, 91));
qo.SetDefaultColor(Color.WHITE);
qo.SetStyle(Curve.SHORT_DASH);
qo2.SetDefaultColor(Color.WHITE);
qo.SetLineWeight(2);
qo2.SetLineWeight(2);


# place bubbles after last bar, to id the lines
AddChartBubble(showbubbles and x, ql, "Q[" + offset + "]", CreateColor(252, 125, 127), yes);
AddChartBubble(showbubbles and x, qh, "Q[" + offset + "]", CreateColor(133, 202, 91), yes);
AddChartBubble(showbubbles and x, qo, "Q O", CreateColor(133, 202, 91), yes);

###############################################
#Code for SSS50PercentRule
###############################################

def bn = BarNumber();
def bar = if bn == bn - 1 then open else bar[1];
def sss = HighestAll(if open == open then bn - 1  else Double.NaN);

def fiftypct = (high[1] - low[1]) / 2 + low[1];
plot triggerlong = low < low[1] and high < high[1] and close >= fiftypct;
plot triggershort = high > high[1] and low > low[1] and close <= fiftypct;

plot LSSSlow = if BarNumber() < sss then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) and triggerlong and ShowSSSLines then low[1] else Double.NaN);
plot LSSShigh = if BarNumber() < sss then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) and triggerlong and ShowSSSLines then high[1] else Double.NaN);
plot LSSSlow2 = if BarNumber() < sss then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) and triggerlong and ShowSSSLines then low[1] else Double.NaN);
plot LSSShigh2 = if BarNumber() < sss then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) and triggerlong and ShowSSSLines then high[1] else Double.NaN);
plot LSSSFifty = if BarNumber() < sss then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) and Show50PctLine and triggerlong then fiftypct else Double.NaN);

LSSShigh.SetDefaultColor(Color.WHITE);
LSSShigh.SetStyle(Curve.SHORT_DASH);
LSSShigh.SetLineWeight(1);
LSSShigh2.SetDefaultColor(CreateColor(133, 202, 91));
LSSShigh2.SetLineWeight(1);

LSSSFifty.SetDefaultColor(Color.GRAY);
LSSSFifty.SetStyle(Curve.SHORT_DASH);
LSSSFifty.SetLineWeight(1);


LSSSlow.SetDefaultColor(Color.WHITE);
LSSSlow.SetStyle(Curve.SHORT_DASH);
LSSSlow.SetLineWeight(1);
LSSSlow2.SetDefaultColor(CreateColor(252, 125, 127));
LSSSlow2.SetLineWeight(1);

plot StSSSlow = if BarNumber() < sss then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1]))  and triggershort and ShowSSSLines then low[1] else Double.NaN);
plot StSSShigh = if BarNumber() < sss then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1]))  and triggershort and ShowSSSLines then high[1] else Double.NaN);
plot StSSSlow2 = if BarNumber() < sss then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1]))  and triggershort and ShowSSSLines then low[1] else Double.NaN);
plot StSSShigh2 = if BarNumber() < sss then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) and triggershort and ShowSSSLines then high[1] else Double.NaN);
plot StSSSFifty = if BarNumber() < sss then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) and Show50PctLine and triggershort  then fiftypct else Double.NaN);

StSSShigh.SetDefaultColor(Color.WHITE);
StSSShigh.SetStyle(Curve.SHORT_DASH);
StSSShigh.SetLineWeight(1);
StSSShigh2.SetDefaultColor(CreateColor(252, 125, 127));
StSSShigh2.SetLineWeight(1);


StSSSlow.SetDefaultColor(CreateColor(252, 125, 127));
StSSSlow.SetStyle(Curve.SHORT_DASH);
StSSSlow.SetLineWeight(1);
StSSSlow2.SetDefaultColor(Color.RED);
StSSSlow2.SetLineWeight(1);

StSSSFifty.SetDefaultColor(Color.WHITE);
StSSSFifty.SetStyle(Curve.SHORT_DASH);
StSSSFifty.SetLineWeight(1);

def sssmid = (StSSShigh - StSSSlow) / 2 + StSSSlow;
AddCloud(if showCloud then LSSShigh else Double.NaN, LSSSlow, CreateColor(50, 90, 59  ), CreateColor(50, 90, 59 ));
AddCloud(if showCloud then StSSShigh else Double.NaN, StSSSlow, CreateColor(110, 69, 60    ), CreateColor(110, 69, 60    ));
AddChartBubble(if showbubbles  and ShowSSSLines and bn == sss then 1 else 0 , sssmid, "50%", Color.YELLOW);
#Alert(triggerlong or triggershort, getunderlyingsymbol() + " IS GOING OUTSIDE!!", Alert.TICK, Sound.Ding);


###############################################
#Code for motherbar problems
###############################################


#def insideBar =  (high <= high[1] and low >= low[1]);
#def trigger = insideBar;
#def triggerbn = if trigger then bn else triggerbn[1];
#def triggerCount = if trigger then triggerCount[1] + 1 else triggerCount[1];
#def MBHigh = if insideBar  then high[1] else MBHigh[1];
#def MBLow = if insideBar then low[1] else MBLow[1];
#
## In trade manager
#def InMB = if trigger then 1 else if InMB[1] == 1 and (high > MBHigh or low < MBLow) then 0 else InMB[1];
#def MBProblems = if bn > triggerbn + 1 then InMB else 0;
#
#def linebn = HighestAll(if open == open then triggerbn - 1  else Double.NaN);
#plot MBLowLine = if BarNumber() < linebn then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) and MBProblems and showMBproblems then MBLow else Double.NaN);
#plot MBHighLine = if BarNumber() < linebn then Double.NaN else HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) and MBProblems and showMBproblems then MBHigh else Double.NaN);
#def mbmid = (MBHighLine - MBLowLine) / 2 + MBLowLine;
#MBLowLine.SetDefaultColor(Color.GRAY);
##MBLowLine.SetStyle(Curve.SHORT_DASH);
##MBLowLine.SetLineWeight(1);
#MBHighLine.SetDefaultColor(Color.GRAY);
##MBHighLine.SetStyle(Curve.SHORT_DASH);
##MBHighLine.SetLineWeight(1);
##AddLabel(yes, "    ", Color.BLACK);
#AddLabel(yes, if showMBproblems and MBProblems then "MB Issues" else "", Color.YELLOW);
#AddChartBubble(if showbubbles  and showMBproblems and bn == linebn then 1 else 0 , mbmid, "MB", Color.YELLOW);
#
#AddCloud(if showbubbles and showMBproblems then MBHighLine else Double.NaN, MBLowLine, Color.GRAY, Color.GRAY);
 
Last edited by a moderator:
Solution
the reason it was made with higher time frames is because Thinkorswim is limited as to how far back it will reach data from on the lower time frames. for instance ATH might be years back on some securities therefore it will return you inaccurate data if you were to put it on the 15m timeframe.
the reason it was made with higher time frames is because Thinkorswim is limited as to how far back it will reach data from on the lower time frames. for instance ATH might be years back on some securities therefore it will return you inaccurate data if you were to put it on the 15m timeframe.
 
Solution
the reason it was made with higher time frames is because Thinkorswim is limited as to how far back it will reach data from on the lower time frames. for instance ATH might be years back on some securities therefore it will return you inaccurate data if you were to put it on the 15m timeframe.
what if I were to get rid of the ATH/ATL and simply stick with the 5,15,30, and 60min timeframes? Just that without extended hours? Also thank you for your reply. :)
 
what if I were to get rid of the ATH/ATL and simply stick with the 5,15,30, and 60min timeframes? Just that without extended hours? Also thank you for your reply. :)
the indicator/study will only return/show/plot what is actually visible on your chart.
and your chart may or may not be showing the ATH depending how far back it was.
 

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