【发布时间】:2022-12-14 05:01:14
【问题描述】:
我正在尝试获取最接近当前价格、高于当前价格且在最后 15 根蜡烛内的峰值价格
例如,最后 15 根蜡烛中可能有 3 个峰值。我试图对它们进行排序以获得最接近最近蜡烛价格的峰值价格,并且高于最近蜡烛的价格,无论最近发生哪个峰值
我试着设置它,但目前它正在绘制图表的收盘价而不是目标价
--
如何获取最接近当前价格、高于当前价格且在最近 15 根蜡烛内的峰值价格?
--
到目前为止的代码:
//@version=5
indicator(title="peak", overlay = true)
peak = close[0] < close[1] and close[1] > close[2]
////previouscandle = ta.valuewhen(peak, close[1], 0)
////barssince_last_peak = ta.barssince(peak)
////targetPrice = barssince_last_peak <= 15 and barssince_last_peak > 0 ? previouscandle : na
startprice = close
targetprice = close
//loop through the last 15 candles
for i=0 to 15-1
//if a peak price is greater than the start price set its peak price to the targetpricenew variable
targetpricenew = ta.valuewhen(peak and close[1] > startprice, close[1], 0)
// if the distance between targetpricenew's peak is less than the distance between the current targetprices's peak
if ( targetpricenew - startprice ) < ( targetprice - startprice )
//Set the targetpricenew peak as the targetprice
targetprice = targetpricenew
//plot the targetprice
plot(targetprice, style = plot.style_linebr)
【问题讨论】:
标签: pine-script pinescript-v5 pine-script-v4