Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

Pine script plottine lines to connect two lines

I have a code that draws line from high to low or low to high depending on the time when high or low formed during the day. I want to have a connecting line to lines of individual days. How to go about it.

study(title="Neely Charts", overlay=true)
//Define variables
string      res = input("D")
var float   h_price = na
var float   l_price = na
var int     h_date = na
var int     l_date = na
var float   h1_price = na
var float   l1_price = na
var int     h1_date = na
var int     l1_date = na



var line z = na
bool isnewtbar = change(time(res)) > 0

//getting lines
if isnewtbar and bar_index > 1 
    h_price := high
    l_price := low
    h_date := time
    l_date := time
   
    z := line.new(x1=h_date, y1=h_price, x2=l_date, y2=l_price, xloc=xloc.bar_time, extend=extend.none, color=color.black, style=line.style_solid, width=2)
    


if high > h_price
    h_price := high
    h_date := time 


if low < l_price
    l_price := low
    l_date := time
  

if h_date <= l_date
    // high to low
    line.set_xy1(id=z, x=h_date, y=h_price)
    line.set_xy2(id=z, x=l_date, y=l_price)
    line.set_color(id=z, color=color.red)
    
else
    // low to high
    line.set_xy1(id=z, x=l_date, y=l_price)
    line.set_xy2(id=z, x=h_date, y=h_price)
    line.set_color(id=z, color=color.lime)

i tried setting previous days price but unable to procede. Can anyboady help

question from:https://stackoverflow.com/questions/65713603/pine-script-plottine-lines-to-connect-two-lines

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
//@version=4

study(title="Neely Charts", overlay=true)
//Define variables
string      res = input("D")
var float   h_price = na
var float   l_price = na
var int     h_date = na
var int     l_date = na
var float   h1_price = na
var float   l1_price = na
var int     h1_date = na
var int     l1_date = na

var line z = na
var line w = na
bool isnewtbar = change(time(res)) > 0

//getting lines
if isnewtbar and bar_index > 1 
    h_price := high
    l_price := low
    h_date := time
    l_date := time
   
    z := line.new(x1=h_date, y1=h_price, x2=l_date, y2=l_price, xloc=xloc.bar_time, extend=extend.none, color=color.black, style=line.style_solid, width=2)
    w := line.new(x1=line.get_x2(z[1]), y1=line.get_y2(z[1]), x2=l_date, y2=l_price, xloc=xloc.bar_time, extend=extend.none, color=color.black, style=line.style_solid, width=2)
    
if high > h_price
    h_price := high
    h_date := time 


if low < l_price
    l_price := low
    l_date := time
  

if h_date <= l_date
    // high to low
    line.set_xy1(id=z, x=h_date, y=h_price)
    line.set_xy2(id=z, x=l_date, y=l_price)
    line.set_color(id=z, color=color.red)
else
    // low to high
    line.set_xy1(id=z, x=l_date, y=l_price)
    line.set_xy2(id=z, x=h_date, y=h_price)
    line.set_color(id=z, color=color.lime)

line.set_xy2(id=w, x=line.get_x1(z[0]), y=line.get_y1(z[0]))
line.set_color(id=w, color=color.blue)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...