• Get $40 off VIP by signing up for a free account! Sign Up

Way to make this 50% candle indicator multi-timeframe?

cappermac

New member
Hello, Is there anyway to make this multi-timeframe? Looking for a 1hr or 4hr agg on a lower timeframe chart. Thank you!

Code:
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(2);
def hbext    = if isnan(halfback) then hbext[1] else halfback;
plot hbextline = hbext;
hbextline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hbextline.SetDefaultColor(color.Yellow);
hbextline.SetLineWeight(2);

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_white = yes;
h1p.assignvalueColor(if showcolor_light_white then color.DARK_GRAY 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_white then color.DARK_GRAY else color.white);
 
Hello, Is there anyway to make this multi-timeframe? Looking for a 1hr or 4hr agg on a lower timeframe chart. Thank you!

Code:
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(2);
def hbext    = if isnan(halfback) then hbext[1] else halfback;
plot hbextline = hbext;
hbextline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hbextline.SetDefaultColor(color.Yellow);
hbextline.SetLineWeight(2);

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_white = yes;
h1p.assignvalueColor(if showcolor_light_white then color.DARK_GRAY 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_white then color.DARK_GRAY else color.white);
From lower timeframes (using the 30min on the 5min chart) or (using the Weekly on the Daily chart). I think this would be very helpful. :)
 
Hello, Is there anyway to make this multi-timeframe? Looking for a 1hr or 4hr agg on a lower timeframe chart. Thank you!

Code:
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(2);
def hbext    = if isnan(halfback) then hbext[1] else halfback;
plot hbextline = hbext;
hbextline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hbextline.SetDefaultColor(color.Yellow);
hbextline.SetLineWeight(2);

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_white = yes;
h1p.assignvalueColor(if showcolor_light_white then color.DARK_GRAY 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_white then color.DARK_GRAY else color.white);


comments
no reason to use highestall() , which makes it complex


def hilo = if hl2 then barnumber() else hilo[1];
hl2 is a price , not a boolean. it is always true


def pbar = if barNumber() >= HighestAll(cond) and !last then 1 else double.nan;
some odd way to pick the 2nd to last bar


plot HalfBack = if show50 and !isnan(pbar) then hl2 else double.nan;
plots a yellow line at mid point on 2nd to last bar
plot hbextline = hbext;
plots a yellow line at 0 before the bar and at mid point after the bar


-------------------------------

redo and fix most of it
change it to use MTF data


Code:
#candle_indic_50per_mtf

#https://usethinkscript.com/threads/way-to-make-this-50-candle-indicator-multi-timeframe.18259/
#Way to make this 50% candle indicator multi-timeframe?
#cappermac  Apr 3, 2024

# Is there anyway to make this multi-timeframe?
# Looking for a 1hr or 4hr agg on a lower timeframe chart. Thank you!


def na = double.nan;
def bn = barnumber();

#def lastbn = HighestAll(If(IsNaN(close), 0, bn));
#def lastbar = if (bn == lastbn) then 1 else 0;
def lastbar = !isnan(close[0]) and isnan(close[-1]);
#def last_close = highestall(if lastbar then close else 0);

input agg = aggregationperiod.hour;
def aggmin = agg/60000;
def chartagg = getaggregationperiod();
def chartmin = chartagg/60000;
def aggfactor = aggmin / chartmin;

def op = open(period = agg);
def hi = high(period = agg);
def lo = low(period = agg);
def cl = close(period = agg);

input bars_back_offset = 1;
addlabel(1, "bars back " + bars_back_offset ,color.yellow);
addlabel(1, " ", color.black);

addlabel(1, "MTF min " + aggmin, color.yellow);
addlabel(1, "chart min " + chartmin, color.yellow);
addlabel(1, "bars in agg time " + aggfactor, color.yellow);

input upper_per = 75;
input lower_per = 25;
def perupper = lo + ((hi - lo )*(upper_per/100));
def perlower = lo + ((hi - lo )*(lower_per/100));
def permid = (hi + lo )/2;

def bar = !isnan(close(period = agg)[-bars_back_offset]) and isnan(close(period = agg)[-(bars_back_offset+1)]);

def hilvl = if bn == 1 then na
 else if bar then hi
 else hilvl[1];

def lolvl = if bn == 1 then na
 else if bar then lo
 else lolvl[1];

def upperline = if bn == 1 then na
 else if bar then perupper
 else upperline[1];

def midline = if bn == 1 then na
 else if bar then permid
 else midline[1];

def lowerline = if bn == 1 then na
 else if bar then perlower
 else lowerline[1];

input show50 = yes;
plot zmid = if show50 and midline > 0 then midline else na;
zmid.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zmid.SetDefaultColor(color.Yellow);
zmid.SetLineWeight(2);

input show_upper_line = yes;
plot Back75 = if show_upper_line and bar then perupper else double.nan;
Back75.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Back75.SetDefaultColor(color.white);
Back75.SetLineWeight(1);

input show_lower_line = yes;
plot Back25 = if show_lower_line and bar then perlower else double.nan;
Back25.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Back25.SetDefaultColor(color.white);
Back25.SetLineWeight(1);

def bubble_pos1 = 1;
input showbubble_expansion = yes;
def bub = !isnan(close[bubble_pos1+1]) and isnan(close[(bubble_pos1+0)]);

addchartBubble(
 showbubble_expansion and bub,
 hilvl,
 ("H: " + hilvl),
 color.white,
 yes);

addchartBubble(
 showbubble_expansion and bub,
 lolvl,
 ("L: " + lolvl),
 color.white,
 no);

input show_hilo_lines = yes;
plot zhi = if show_hilo_lines then hilvl else na;
plot zlo = if show_hilo_lines then lolvl else na;
zhi.setdefaultColor(color.DARK_GRAY);
zlo.setdefaultColor(color.DARK_GRAY);

#---------------------------
input test1 = no;
addverticalline(test1 and bar,"-");
#
 

Attachments

  • 01b2.JPG
    01b2.JPG
    90.2 KB · Views: 64

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