此脚本将指示高点,左栏位于较低位置,右栏位于较低位置。 我还希望该脚本能给我HighofHighs,而左高和右高要低。 我可以使用它,但是无法在正确的栏中显示标签。
如果我使用offset = -1,它将放置在最近的高点上方,如果我使用offset = -high_bars_back,则它根本不会偏移它。
(代码的默认值是在最新的最高价上显示“ HighofHighs”(使用offset = -1,但我需要它显示在第二高的最新价上)
//@version=3
strategy(title = "Trend_v1", shorttitle = "Thrend_v1", overlay = true,
pyramiding = 0, default_qty_type = strategy.percent_of_equity, default_qty_value = 100,
calc_on_every_tick=true, initial_capital=100000)//, calc_on_order_fills=true)
//Window of time
start = timestamp(1000, 01, 01, 00, 00) // backtest start window
finish = timestamp(3000, 10, 01, 00, 00) // backtest finish window
window() => time >= start and time <= finish ? true : false // create function "within window of time"
//Input
showLocalTrendHighLables = input(title="Show Local Trend High Labels", type=bool, defval=true)
showRealTrendHighLables = input(title="Show Real Trend High Labels", type=bool, defval=true)
//Initialize Variables
first_high = na
second_high = na
third_high = na
local_trend_highs = na
real_trend_highs = na
//Local Trend Highs
if(nz(high[2]) < nz(high[1]) and nz(high[1]) > high)
local_trend_highs := nz(high[1])
third_high := second_high[1]
second_high := first_high[1]
first_high := nz(high[1])
else
local_trend_highs := nz(local_trend_highs[1])
third_high := third_high[1]
second_high := second_high[1]
first_high := first_high[1]
//Real Trend Highs
if (third_high < second_high and second_high > first_high)
real_trend_highs := nz(local_trend_highs)
else
real_trend_highs := nz(real_trend_highs[1])
//Calculate how many high bars back to display HighofHighs
high_bars_back = 0
for i = 0 to 999
high_bars_back = i
if(high[i] == second_high)
break
else
continue
//Plots
plotshape((not (local_trend_highs == local_trend_highs[1])) and showLocalTrendHighLables, style=shape.arrowdown, location=location.abovebar, color=green, text='high', offset=-1)
//For some reason, offset=-high_bars_back doesn't shift at all
plotshape((not (real_trend_highs == real_trend_highs[1])) and showRealTrendHighLables, style=shape.arrowdown, location=location.top, color=green, text='HIGHofHIGHs', offset=-1)//offset=-high_bars_back)
plot(high_bars_back, color=blue, style=columns)
答案 0 :(得分:1)
不幸的是,这不能通过'plotshape'+'offset'实现。这样做的原因是,偏移量会在给定的条数下移动整个系列的形状。但是在您的任务中,每个HIGHofHIGH都需要一个不同的偏移值。
好消息是此功能或多或少将很快可用。它包含在Pine Script版本4公共草案中。该功能称为“标签”。了解更多https://docs.google.com/document/d/12ogvjzasBJSXerSOql4b9KwkE3wUlsc5HgA5qGhoYXk/edit#heading=h.uz6ftgjlvspe
答案 1 :(得分:0)
关于枢轴的枢轴,我也有同样的问题。经过一天又一遍的测试。当我看到vitvlkv用标签代替plotshape的要点后,我解决了它。共享我的部分代码。.
if h2>h1 and h2>h3 and h2>h4 and h2>h5
h1_1:=h2
ph2_1:=ph1_1
ph1_1:=ph2
else
h1_1:=h1_1[1]
ph1_1:=ph1_1[1]
ph2_1:=ph2_1[1]
var label pop=na
if h1_1!=h1_1[1]
pop:=label.new(ph1_1,h1_1,yloc=yloc.belowbar,style=label.style_diamond,color=color.lime,size=size.tiny)