How to bind a horizontal line (level) to the bar, the event is clicking the Start checkmark.
Posted: Mon Jan 24, 2022 11:18 am
And so that this line does not run away from the bar where it was drawn. So that the lines are rearranged only when the price crosses one of the levels opened by the start button. Because of the cyclicity, I can't do it in any way. tried 2 options:
1.Option: Using the functions barssince and valuewhen
//@version=4
study(title="Scalper bot", shorttitle="Scalper bot", overlay=true)
var start = input(true, title="Старт", group="Cетка ордеров")
retreat= input(0.25, title="Отступ от цены создания(%)",type=input.float,minval = 0.1,step=0.1,group="Cетка ордеров")
//******************************************************************************************************************
if start
since = barssince(start)
val = valuewhen(start, open, 0)
labell = label.new(bar_index, 0,"Array size: "+tostring(since)+", \open: "+tostring(val),yloc=yloc.abovebar, size = size.normal)
label.delete(labell[1])
//calculation of the position of the long line
ll1 = val/100*retreat+val
//calculation of the position of the short line
ls1 = val-val/100*retreat
ll_1 = line.new(bar_index,ll1,bar_index[1],ll1,xloc.bar_index,extend.both,color=color.green,style=line.style_solid)
line.delete(ll_1[1])
ls_1 = line.new(bar_index,ls1,bar_index[1],ls1,xloc.bar_index,extend.both,color=color.red,style=line.style_solid)
line.delete(ls_1[1])
2. Option C using an array:
//@version=4
study(title="987654", shorttitle="987654", overlay=true)
var start = input(true, title="Старт", group="Cетка ордеров")
retreat= input(0.25, title="Отступ от цены создания(%)",type=input.float,minval = 0.1,step=0.1,group="Cетка ордеров")
step = input(0.5, title="Шаг ордеров сетки(%)",type=input.float,minval = 0.1,step=0.1,group="Cетка ордеров")
//****************************************************************************************************************************************************************************
if start
prices = array.new_float(0,0)
array.push(prices, open)
labell = label.new(bar_index, 0,"Array size: "+tostring(array.size(prices))+", \open: "+tostring(array.get(prices, array.size(prices)-1)),yloc=yloc.abovebar, size = size.normal)
label.delete(labell[1])
//calculation of the position of the long line
ll1 = array.get(prices, array.size(prices)-1)/100*retreat+array.get(prices, 0)
//calculation of the position of the short line
ls1 = array.get(prices, array.size(prices)-1)-array.get(prices, array.size(prices)-1)/100*retreat
ll_1 = line.new(bar_index,ll1,bar_index[1],ll1,xloc.bar_index,extend.both,color=color.green,style=line.style_solid)
line.delete(ll_1[1])
ls_1 = line.new(bar_index,ls1,bar_index[1],ls1,xloc.bar_index,extend.both,color=color.red,style=line.style_solid)
line.delete(ls_1[1])
1.Option: Using the functions barssince and valuewhen
//@version=4
study(title="Scalper bot", shorttitle="Scalper bot", overlay=true)
var start = input(true, title="Старт", group="Cетка ордеров")
retreat= input(0.25, title="Отступ от цены создания(%)",type=input.float,minval = 0.1,step=0.1,group="Cетка ордеров")
//******************************************************************************************************************
if start
since = barssince(start)
val = valuewhen(start, open, 0)
labell = label.new(bar_index, 0,"Array size: "+tostring(since)+", \open: "+tostring(val),yloc=yloc.abovebar, size = size.normal)
label.delete(labell[1])
//calculation of the position of the long line
ll1 = val/100*retreat+val
//calculation of the position of the short line
ls1 = val-val/100*retreat
ll_1 = line.new(bar_index,ll1,bar_index[1],ll1,xloc.bar_index,extend.both,color=color.green,style=line.style_solid)
line.delete(ll_1[1])
ls_1 = line.new(bar_index,ls1,bar_index[1],ls1,xloc.bar_index,extend.both,color=color.red,style=line.style_solid)
line.delete(ls_1[1])
2. Option C using an array:
//@version=4
study(title="987654", shorttitle="987654", overlay=true)
var start = input(true, title="Старт", group="Cетка ордеров")
retreat= input(0.25, title="Отступ от цены создания(%)",type=input.float,minval = 0.1,step=0.1,group="Cетка ордеров")
step = input(0.5, title="Шаг ордеров сетки(%)",type=input.float,minval = 0.1,step=0.1,group="Cетка ордеров")
//****************************************************************************************************************************************************************************
if start
prices = array.new_float(0,0)
array.push(prices, open)
labell = label.new(bar_index, 0,"Array size: "+tostring(array.size(prices))+", \open: "+tostring(array.get(prices, array.size(prices)-1)),yloc=yloc.abovebar, size = size.normal)
label.delete(labell[1])
//calculation of the position of the long line
ll1 = array.get(prices, array.size(prices)-1)/100*retreat+array.get(prices, 0)
//calculation of the position of the short line
ls1 = array.get(prices, array.size(prices)-1)-array.get(prices, array.size(prices)-1)/100*retreat
ll_1 = line.new(bar_index,ll1,bar_index[1],ll1,xloc.bar_index,extend.both,color=color.green,style=line.style_solid)
line.delete(ll_1[1])
ls_1 = line.new(bar_index,ls1,bar_index[1],ls1,xloc.bar_index,extend.both,color=color.red,style=line.style_solid)
line.delete(ls_1[1])