Is it possible to redraw k-line based on High/Low only?

Seagull21

New member
I am new here and want to know if it is possible to redraw k-line in TOS based on
1. High/Low
2. Combine multiple K lines into one if they exist the engulfing pattern.
 

Attachments

  • Simplify the consecutive k-line chart with the engulfing pattern based on high-low prices.docx
    184.2 KB · Views: 202
I am new here and want to know if it is possible to redraw k-line in TOS based on
1. High/Low
2. Combine multiple K lines into one if they exist the engulfing pattern.

hello and welcome.
can you provide more info on k lines ?
i looked at your attachnent, and i'm still confused. it seems to talk about k lines, but doesn't define how to calculate them.
 

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

hello and welcome.
can you provide more info on k lines ?
i looked at your attachment, and i'm still confused. it seems to talk about k lines, but doesn't define how to calculate them.
Use High and Low and remove the engulfing patterns. The 2.1 defines Up-/down-trend using high and low only.
2.2 and 2.3 show how to calculate high/low for each k-line. If they exist the engulfing patterns, remove the engulfing patterns.
 
Use High and Low and remove the engulfing patterns. The 2.1 defines Up-/down-trend using high and low only.
2.2 and 2.3 show how to calculate high/low for each k-line. If they exist the engulfing patterns, remove the engulfing patterns.

i admit sometimes i'm slow to understand.... i think i'm getting it.

you want 2 engulfing bars replaced with 1 bar.

i will start with the simplist version, 2.2b and 2.3b , draw a blue bar on top of the small bar.

the examples don't show candle wicks, so i'm not sure if you want (blue) rectangles drawn or a candle that has a body size derived from the 2 engulfing candles.
 
i admit sometimes i'm slow to understand.... i think i'm getting it.

you want 2 engulfing bars replaced with 1 bar.

i will start with the simplist version, 2.2b and 2.3b , draw a blue bar on top of the small bar.

the examples don't show candle wicks, so i'm not sure if you want (blue) rectangles drawn or a candle that has a body size derived from the 2 engulfing candles.
I am sorry I did not state clearly. For each bar, only use high(est) and low(est) with no wicks. if a newly-generated bar with previous bar still contains the engulfing pattern, remove it until no engulfing pattern. Same treatment with downtrend. Thanks for your assistance.
 
I am sorry I did not state clearly. For each bar, only use high(est) and low(est) with no wicks. if a newly-generated bar with previous bar still contains the engulfing pattern, remove it until no engulfing pattern. Same treatment with downtrend. Thanks for your assistance.

this is a simple version of k-line rules, to verify the engulfing rules before going further.

sequential engulfing patterns are not combined.
2 consecutive engulfing patterns will have 2 blue bars, not 1.
if 3 bars make up 2 engulfing patterns, the 1st pair is ignored.

this version will find an engulfing pattern and,
. draw either a hollow or solid blue bar over the small candle.
. can choose to black out the big engulfing candle.

does not look for reversal patterns

Ruby:
# k_line_bars_01

#https://usethinkscript.com/threads/is-it-possible-to-redraw-k-line-based-on-high-low-only.9761/
#Is it possible to redraw k-line based on High/Low only?

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

# look for engulfing
# check if big bar is up or down
def bardir = if close > open then 1 else if open > close then -1 else 0;
def engulf2 = if (high > high[-1] and low < low[-1]) then 1 else 0;
# if 3 bars make up 2 engulfing patterns, disable the 1st pair
def engulf = if engulf2[-1] then 0 else engulf2;

# k bar , combine hi and low from 2 engulfing bars,
# if up engulf , big bar high and small bar low
# if down engulf , big bar low and small bar high

# calc a new bar to draw over the small bar
# it will extend in the direction of big bar
def smalltop = if (engulf[1] and bardir[1] == 1) then high[1] 
  else if (engulf[1] and bardir[1] == -1) then high
  else na; 

def smallbot = if (engulf[1] and bardir[1] == 1) then low 
  else if (engulf[1] and bardir[1] == -1) then low[1]
  else na; 

input show_solid_blue_bars = yes;
def kh = smalltop;
def kl = smallbot;

# hollow blue bars
#def ko = kl;
#def kc = kh;
# solid blue bars
#def ko = kh;
#def kc = kl;

def ko = if show_solid_blue_bars then kh else kl;
def kc = if show_solid_blue_bars then kl else kh;

#------------------------------

#  draw blue bar over the small enguled candle
def o;
def h;
def l;
def c;
o = ko;
h = kh;
l = kl;
c = kc;

AddChart(high = h, low = l, open = o, close = c, growcolor = color.cyan, fallcolor = color.yellow, type = ChartType.CANDLE);

#------------------------------
#  draw a black bar over big engulfing bar , to make it disappear

input black_out_big_engulfing_bar = yes;

def bh;
def bl;
def bo;
def bc;
if black_out_big_engulfing_bar and engulf then {
 bh = high;
 bl = low;
 bo = high;
 bc = low;
} else {
 bh = na;
 bl = na;
 bo = na;
 bc = na;
}

AddChart(high = bh, low = bl, open = bo, close = bc, growcolor = color.black, fallcolor = color.yellow, type = ChartType.CANDLE);


#------------------------------
# test stuff

input show_engulfing_arrows1 = no;
# put arrow on small bar of engulfing
plot smallup = if (show_engulfing_arrows1 and engulf[1] and bardir[1] == 1) then low*0.994 else na;
smallup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
smallup.SetDefaultColor(Color.white);
# x.setlineweight(1);
smallup.hidebubble();

plot smalldwn = if (show_engulfing_arrows1 and engulf[1] and bardir[1] == -1) then high*1.006 else na;
smalldwn.SetPaintingStrategy(PaintingStrategy.ARROW_down);
smalldwn.SetDefaultColor(Color.white);
# x.setlineweight(1);
smalldwn.hidebubble();

#------------------------------
# 
# hide the default candles
# HidePricePlot();
# input hide_candles = yes;
# HidePricePlot(hide_candles);
#

img1 - big engulfing candles blacked out. solid blue bar drawn over small engulfed candle.
Tqhmhd4.jpg


img2 - big engulfing candles visible. solid blue bar drawn over small engulfed candle.
pulKMvE.jpg


img3 - big engulfing candles visible. hollow blue bar drawn over small engulfed candle.
QxDEwzn.jpg
 
Great Job! But for each bar, only use high(est) and Low(est) with no wicks. e.g.:
def close = if open <= close and close <= high then high
else if open > close and close >= low then low
else close;
def open = if open >= close and open <= high then high
else if open < close and open > low then low
else open;

For (up/down)trend determination, two consecutive bars are used for comparison.
 
Last edited:

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
261 Online
Create Post

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