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.
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Use High and Low and remove the engulfing patterns. The 2.1 defines Up-/down-trend using high and low only.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.
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 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.
# 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);
#
Start a new thread and receive assistance from our community.
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.
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.