英文:
extending pivot high and low lines in pine script
问题
//@version=5
indicator(title='s/r', shorttitle='s/r', overlay=true, max_bars_back=1000)
leftBars = input(10, title='左边柱数')
rightBars = input(10, title='右边柱数')
volumeThresh = input(20, title='成交量阈值')
highUsePivot = fixnan(ta.pivothigh(leftBars, rightBars)1)
lowUsePivot = fixnan(ta.pivotlow(leftBars, rightBars)1)
r1 = plot(highUsePivot, color=ta.change(highUsePivot) ? na : color.green, linewidth=1, offset=-(rightBars + 1), title='阻力')
s1 = plot(lowUsePivot, color=ta.change(lowUsePivot) ? na : color.green, linewidth=1, offset=-(rightBars + 1), title='支撑')
这段代码用于绘制枢轴高低支撑和阻力线。
如何将这些线延伸到右侧?
谢谢
英文:
//@version=5
indicator(title='s/r', shorttitle='s/r', overlay=true, max_bars_back=1000)
leftBars = input(10, title='Left Bars ')
rightBars = input(10, title='Right Bars')
volumeThresh = input(20, title='Volume Threshold')
highUsePivot = fixnan(ta.pivothigh(leftBars, rightBars)[1])
lowUsePivot = fixnan(ta.pivotlow(leftBars, rightBars)[1])
r1 = plot(highUsePivot, color=ta.change(highUsePivot) ? na : color.green, linewidth=1, offset=-(rightBars + 1), title='Resistance')
s1 = plot(lowUsePivot, color=ta.change(lowUsePivot) ? na : color.green, linewidth=1, offset=-(rightBars + 1), title='Support')
..................................................
This code draws pivot high and low support and resistance.
How can I extend these lines to the right?
Thank you
....................
答案1
得分: 1
请检查以下脚本。
情节不能扩展,您必须使用“line”对象和“var”数组来存储它们。
以下是要翻译的代码部分:
indicator(title='s/r', shorttitle='s/r', overlay=true, max_bars_back=1000)
leftBars = input(10, title='Left Bars ')
rightBars = input(10, title='Right Bars')
volumeThresh = input(20, title='Volume Threshold')
highUsePivot = fixnan(ta.pivothigh(leftBars, rightBars)[1])
lowUsePivot = fixnan(ta.pivotlow(leftBars, rightBars)[1])
var arPivotHighs = array.new<line>()
var arPivotLows = array.new<line>()
maxPivots = input.int(5, "How many last pivots to draw")
ph = ta.pivothigh(leftBars, rightBars)
pl = ta.pivotlow(leftBars, rightBars)
if ph
ln = line.new(bar_index-rightBars, ph, bar_index, ph, extend = extend.right, color = color.red, width = 2)
arPivotHighs.unshift(ln)
while arPivotHighs.size() > maxPivots
arPivotHighs.last().delete()
arPivotHighs.pop()
if pl
ln = line.new(bar_index-rightBars, pl, bar_index, pl, extend = extend.right, color = color.green, width = 2)
arPivotLows.unshift(ln)
while arPivotLows.size() > maxPivots
arPivotLows.last().delete()
arPivotLows.pop()
以下脚本绘制4小时分界点:
indicator(title='s/r', shorttitle='s/r', overlay=true, max_bars_back=1000)
leftBars = input(10, title='Left Bars ')
rightBars = input(10, title='Right Bars')
Tf1 = input.timeframe("240", "Higher timeframe")
[h, l, ph, pl, t1, t2, bi] = request.security(syminfo.tickerid, Tf1, [
high
, low
, ta.pivothigh(high, leftBars, rightBars)
, ta.pivotlow(low, leftBars, rightBars)
, time[math.min(bar_index, leftBars+rightBars+1)]
, time_close[1]
, bar_index
])
newHTFBar = ta.change(bi) // detect when data for new HTF bar becomes first available
var arPivotHighs = array.new<line>()
var arPivotLows = array.new<line>()
maxPivots = input.int(5, "How many last pivots to draw")
// we only draw lines on the first chart TF's bar of each HTF bar
if ph and newHTFBar
ln = line.new(t1, ph, t2, ph, extend = extend.none, color = color.red, width = 2, xloc = xloc.bar_time)
arPivotHighs.unshift(ln)
while arPivotHighs.size() > maxPivots
arPivotHighs.last().delete()
arPivotHighs.pop()
if pl and newHTFBar
ln = line.new(t1, pl, t2, pl, extend = extend.none, color = color.green, width = 2, xloc = xloc.bar_time)
arPivotLows.unshift(ln)
while arPivotLows.size() > maxPivots
arPivotLows.last().delete()
arPivotLows.pop()
英文:
Please check the script below.
The plot cannot be extended, you have to use line
objects and a var
array to store them.
//@version=5
indicator(title='s/r', shorttitle='s/r', overlay=true, max_bars_back=1000)
leftBars = input(10, title='Left Bars ')
rightBars = input(10, title='Right Bars')
volumeThresh = input(20, title='Volume Threshold')
highUsePivot = fixnan(ta.pivothigh(leftBars, rightBars)[1])
lowUsePivot = fixnan(ta.pivotlow(leftBars, rightBars)[1])
var arPivotHighs = array.new<line>()
var arPivotLows = array.new<line>()
maxPivots = input.int(5, "How many last pivots to draw")
ph = ta.pivothigh(leftBars, rightBars)
pl = ta.pivotlow(leftBars, rightBars)
if ph
ln = line.new(bar_index-rightBars, ph, bar_index, ph, extend = extend.right, color = color.red, width = 2)
arPivotHighs.unshift(ln)
while arPivotHighs.size() > maxPivots
arPivotHighs.last().delete()
arPivotHighs.pop()
if pl
ln = line.new(bar_index-rightBars, pl, bar_index, pl, extend = extend.right, color = color.green, width = 2)
arPivotLows.unshift(ln)
while arPivotLows.size() > maxPivots
arPivotLows.last().delete()
arPivotLows.pop()
// r1 = plot(highUsePivot, color=ta.change(highUsePivot) ? na : color.green, linewidth=1, offset=-(rightBars + 1), title='Resistance')
// s1 = plot(lowUsePivot, color=ta.change(lowUsePivot) ? na : color.green, linewidth=1, offset=-(rightBars + 1), title='Support')
The script below draws 4H pivots:
//@version=5
indicator(title='s/r', shorttitle='s/r', overlay=true, max_bars_back=1000)
leftBars = input(10, title='Left Bars ')
rightBars = input(10, title='Right Bars')
Tf1 = input.timeframe("240", "Higher timeframe")
[h, l, ph, pl, t1, t2, bi] = request.security(syminfo.tickerid, Tf1, [
high
, low
, ta.pivothigh(high, leftBars, rightBars)
, ta.pivotlow(low, leftBars, rightBars)
, time[math.min(bar_index, leftBars+rightBars+1)]
, time_close[1]
, bar_index
])
newHTFBar = ta.change(bi) // detect when data for new HTF bar becomes first available
var arPivotHighs = array.new<line>()
var arPivotLows = array.new<line>()
maxPivots = input.int(5, "How many last pivots to draw")
// we only draw lines on the first chart TF's bar of each HTF bar
if ph and newHTFBar
ln = line.new(t1, ph, t2, ph, extend = extend.none, color = color.red, width = 2, xloc = xloc.bar_time)
arPivotHighs.unshift(ln)
while arPivotHighs.size() > maxPivots
arPivotHighs.last().delete()
arPivotHighs.pop()
if pl and newHTFBar
ln = line.new(t1, pl, t2, pl, extend = extend.none, color = color.green, width = 2, xloc = xloc.bar_time)
arPivotLows.unshift(ln)
while arPivotLows.size() > maxPivots
arPivotLows.last().delete()
arPivotLows.pop()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论