前期指标的高点和低点,如何在最近期的图表上绘制?

时间:2020-05-29 15:40:05

标签: pine-script trading indicator

我有一个指标,可以在图表上使用折线,前期高点和低点进行绘制,它可以在每日和每周期间正常运行。
Screenshot of my working indicator

在图表上显示了每个上一个期间,而我只需要最后一个期间,例如,仅上周或最后一天。

    study(title="Previous Day High and Low + OPENS", shorttitle="HLO", overlay=true)

D_High = security(tickerid, 'D', high[1]) 
D_Low = security(tickerid, 'D', low[1]) 
D_Close =  security(tickerid, 'D', close[1]) 
D_Open =  security(tickerid, 'D', open[1]) 
W_High =  security(tickerid, 'W', high[1]) 
W_Low =  security(tickerid, 'W', low[1])


plot(isintraday ? D_High : na, title="Daily High",style=line, color=black,linewidth=1) 
plot(isintraday ? D_Low : na, title="Daily Low",style=line, color=black,linewidth=1) 

plot(isintraday ? W_High : na, title="Weekly High",style=line, color=black,linewidth=1) 
plot(isintraday ? W_Low : na, title="Weekly Low",style=line, color=black,linewidth=1) 

openPriceD = security(tickerid, 'D', open)

openPriceW = security(tickerid, 'W', open)

openPriceM = security(tickerid, 'M', open)

plot(openPriceD ? openPriceD : na, title="Daily Open", style=circles, linewidth=2, color=purple)

plot(openPriceW ? openPriceW : na, title="Weekly Open", style=circles, linewidth=2, color=green)

plot(openPriceM ? openPriceM : na, title="Monthly Open", style=circles, linewidth=2, color=red)

我试图将“ show_last =”函数添加到绘图字符串中,但是它不起作用。

任何帮助将不胜感激 谢谢!

1 个答案:

答案 0 :(得分:0)

这将在今天的蜡烛上画出前一日的高点。

//@version=4
study("Q62089672", overlay=true)

D_High = security(syminfo.tickerid, "D", high)

isSaturday = dayofweek(timenow) == dayofweek.saturday
isSunday   = dayofweek(timenow) == dayofweek.sunday
offSetDays = isSaturday ? 1 : isSunday ? 2 : 0

showFromDate = timestamp(year(timenow), month(timenow), dayofmonth(timenow)-offSetDays, 0, 0, 0)

canShow = timeframe.isintraday and time >= showFromDate

plot(canShow ? D_High[1] : na, title="Previous day high", style=plot.style_line, color=color.yellow, linewidth=1)

哪个会产生此输出

Previous day high

由于时区不同,线路开始的时间可能会关闭。
每个股票行情都有其自己的时区进行交易。

Symbol timezone

您还可以在security() function中指定时区。

有关更多详细信息和示例,请参见