MTF Previous Candle

rwfarrell

Member
Looking to make this script MTF, just entering the aggregation period with an agg for OHLC isn't working.

Code:
### Previous Candle ###

def last = if isnan(close[-1]) and !isnan(close) then barnumber() else last[1];
def hilo = if hl2 then barnumber() else hilo[1];

def cond = if barNumber() == hilo then barNumber()-1 else double.nan;
def pbar = if barNumber() >= HighestAll(cond) and !last then 1 else double.nan;

input show50 = yes;
plot HalfBack = if show50 and !isnan(pbar) then hl2 else double.nan;
HalfBack.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HalfBack.SetDefaultColor(color.Yellow);
HalfBack.SetLineWeight(3);
def hbext = if isnan(halfback) then hbext[1] else halfback;
plot hbextline = hbext;
hbextline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hbextline.SetDefaultColor(color.Yellow);
hbextline.SetLineWeight(3);

input show75 = yes;
plot Back75 = if show75 and !isnan(pbar) then low+(high-low)*.75 else double.nan;
Back75.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Back75.SetDefaultColor(color.white);
Back75.SetLineWeight(1);

input show25 = yes;
plot Back25 = if show25 and !isnan(pbar) then low+(high-low)*.25 else double.nan;
Back25.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Back25.SetDefaultColor(color.white);
Back25.SetLineWeight(1);

input bubblemover = 1;
def n1 = bubblemover + 1;
input showbubble_candle = no;
input showbubble_expansion = no;
addchartBubble(showbubble_candle and barnumber()==highestall(last-1),high,"H: " +high,color.white,yes);
addchartBubble(showbubble_candle and barnumber()==highestall(last-1),low,"L: " +low,color.white,no);
addchartBubble(showbubble_expansion and isnan(close[bubblemover]) and !isnan(close[n1]),high[n1+1],"H: " +high[n1+1],color.white,yes);
addchartBubble(showbubble_expansion and isnan(close[bubblemover]) and !isnan(close[n1]),low[n1+1],"L: " +low[n1+1],color.white,no);
def h1 = if isnan(close) then h1[1] else high[1];
plot h1p = if barnumber()>=highestall(last) then h1 else double.nan;
h1p.setpaintingStrategy(PaintingStrategy.HORIZONTAL);
h1p.setdefaultColor(color.white);
input showcolor_light_gray = yes;
h1p.assignvalueColor(if showcolor_light_gray then color.Black else color.white);
def l1 = if isnan(close) then l1[1] else low[1];
plot l1p = if barnumber()>=highestall(last) then l1 else double.nan;
l1p.setpaintingStrategy(PaintingStrategy.HORIZONTAL);
l1p.setdefaultColor(color.white);
l1p.assignvalueColor(if showcolor_light_gray then color.Black else color.white);

[USER=3357]@MerryDay[/USER] I even added the entire MTF script you provided yesterday. Using the Four_Hours timeframe the 50% level does not appear in the correct location on a smaller TF (1m) any recommendations?

input agg = AggregationPeriod.FOUR_HOURS ;
def close = close(period = agg);
def open= open(period = agg);
def high= high(period = agg);
def low= low(period = agg);
def volume= volume(period = agg);
def hl2= hl2(period = agg);
def hlc3= hlc3(period = agg);
def ohlc4= ohlc4(period = agg);
 
Last edited:
Solution
Looking to make this script MTF, just entering the aggregation period with an agg for OHLC isn't working.

### Previous Candle ###

def last = if isnan(close[-1]) and !isnan(close) then barnumber() else last[1];
def hilo = if hl2 then barnumber() else hilo[1];

def cond = if barNumber() == hilo then barNumber()-1 else double.nan;
def pbar = if barNumber() >= HighestAll(cond) and !last then 1 else double.nan;

input show50 = yes;
plot HalfBack = if show50 and !isnan(pbar) then hl2 else double.nan;
HalfBack.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HalfBack.SetDefaultColor(color.Yellow);
HalfBack.SetLineWeight(3);
def hbext = if isnan(halfback) then hbext[1] else halfback;
plot hbextline = hbext...
Looking to make this script MTF, just entering the aggregation period with an agg for OHLC isn't working.

### Previous Candle ###

def last = if isnan(close[-1]) and !isnan(close) then barnumber() else last[1];
def hilo = if hl2 then barnumber() else hilo[1];

def cond = if barNumber() == hilo then barNumber()-1 else double.nan;
def pbar = if barNumber() >= HighestAll(cond) and !last then 1 else double.nan;

input show50 = yes;
plot HalfBack = if show50 and !isnan(pbar) then hl2 else double.nan;
HalfBack.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HalfBack.SetDefaultColor(color.Yellow);
HalfBack.SetLineWeight(3);
def hbext = if isnan(halfback) then hbext[1] else halfback;
plot hbextline = hbext;
hbextline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hbextline.SetDefaultColor(color.Yellow);
hbextline.SetLineWeight(3);

input show75 = yes;
plot Back75 = if show75 and !isnan(pbar) then low+(high-low)*.75 else double.nan;
Back75.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Back75.SetDefaultColor(color.white);
Back75.SetLineWeight(1);

input show25 = yes;
plot Back25 = if show25 and !isnan(pbar) then low+(high-low)*.25 else double.nan;
Back25.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Back25.SetDefaultColor(color.white);
Back25.SetLineWeight(1);

input bubblemover = 1;
def n1 = bubblemover + 1;
input showbubble_candle = no;
input showbubble_expansion = no;
addchartBubble(showbubble_candle and barnumber()==highestall(last-1),high,"H: " +high,color.white,yes);
addchartBubble(showbubble_candle and barnumber()==highestall(last-1),low,"L: " +low,color.white,no);
addchartBubble(showbubble_expansion and isnan(close[bubblemover]) and !isnan(close[n1]),high[n1+1],"H: " +high[n1+1],color.white,yes);
addchartBubble(showbubble_expansion and isnan(close[bubblemover]) and !isnan(close[n1]),low[n1+1],"L: " +low[n1+1],color.white,no);
def h1 = if isnan(close) then h1[1] else high[1];
plot h1p = if barnumber()>=highestall(last) then h1 else double.nan;
h1p.setpaintingStrategy(PaintingStrategy.HORIZONTAL);
h1p.setdefaultColor(color.white);
input showcolor_light_gray = yes;
h1p.assignvalueColor(if showcolor_light_gray then color.Black else color.white);
def l1 = if isnan(close) then l1[1] else low[1];
plot l1p = if barnumber()>=highestall(last) then l1 else double.nan;
l1p.setpaintingStrategy(PaintingStrategy.HORIZONTAL);
l1p.setdefaultColor(color.white);
l1p.assignvalueColor(if showcolor_light_gray then color.Black else color.white);

@MerryDay I even added the entire MTF script you provided yesterday. Using the Four_Hours timeframe the 50% level does not appear in the correct location on a smaller TF (1m) any recommendations?

input agg = AggregationPeriod.FOUR_HOURS ;
def close = close(period = agg);
def open= open(period = agg);
def high= high(period = agg);
def low= low(period = agg);
def volume= volume(period = agg);
def hl2= hl2(period = agg);
def hlc3= hlc3(period = agg);
def ohlc4= ohlc4(period = agg);

This should help with MTF

Screenshot-2023-03-11-074642.png
Code:
input agg      = AggregationPeriod.FOUR_HOURS ;
input displace = 1;

def c     = close;
def high  = if IsNaN(c) then high[1] else high(period = agg)[displace];
def low   = if IsNaN(c) then low[1] else low(period = agg)[displace];
def hl2   = if IsNaN(c) then hl2[1] else hl2(period = agg)[displace];

### Previous Candle ###

def last = if IsNaN(c[-1]) and !IsNaN(c) then BarNumber() else Double.NaN;

input show50 = yes;
plot HalfBack = if !show50 or !IsNaN(c) then Double.NaN else hl2;
HalfBack.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HalfBack.SetDefaultColor(Color.YELLOW);
HalfBack.SetLineWeight(3);

input show75 = yes;
plot Back75 = if !show75 or !IsNaN(c) then Double.NaN else low + (high - low) * .75;
Back75.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Back75.SetDefaultColor(Color.WHITE);
Back75.SetLineWeight(1);

input show25 = yes;
plot Back25 = if !show25 or !IsNaN(c) then Double.NaN else low + (high - low) * .25;
Back25.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Back25.SetDefaultColor(Color.WHITE);
Back25.SetLineWeight(1);

input bubblemover = 3;
def n  = bubblemover;
def n1 = n + 1;
input showbubble_candle    = no;
input showbubble_expansion = yes;
AddChartBubble(showbubble_candle and BarNumber() == HighestAll(last), high, "H: " + high, Color.WHITE, yes);
AddChartBubble(showbubble_candle and BarNumber() == HighestAll(last), low, "L: " + low, Color.WHITE, no);
AddChartBubble(showbubble_expansion and IsNaN(c[n]) and !IsNaN(c[n1]), high[n], "H: " + high[n1], Color.WHITE, yes);
AddChartBubble(showbubble_expansion and IsNaN(c[n]) and !IsNaN(c[n1]), low[n], "L: " + low[n], Color.WHITE, no);

plot h1p = if !IsNaN(c) then Double.NaN else high;
h1p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
h1p.SetDefaultColor(Color.WHITE);
input showcolor_light_gray = no;
h1p.AssignValueColor(if showcolor_light_gray then Color.BLACK else Color.WHITE);

plot l1p = if !IsNaN(c) then Double.NaN else low;
l1p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
l1p.SetDefaultColor(Color.WHITE);
l1p.AssignValueColor(if showcolor_light_gray then Color.BLACK else Color.WHITE);
 
Solution

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

Thread starter Similar threads Forum Replies Date
C Previous H/L MTF Questions 2
B MTF Stochastic Questions 1
E MTF Stacked Moving Averages Questions 3
M MTF AMA Questions 2
C MTF EMA cloud Questions 1

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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