识别时间范围内的最低和最高价格

问题描述 投票:0回答:1

我目前正在制定 Pine 脚本策略。我需要帮助计算特定时间范围内的最低和最高价格,假设每天 12:00 到 14:00 之间。我开始编写下面的代码。

现在我想拉取 rangeHigh (rangeLow) 的最大(最小)值并将其绘制在整个 tsession 周期的图表上。

//@version=5
strategy("minimum and maximum prices within a specific time range", overlay = true)
//Variables
topening= time(timeframe.period,”1200-1300:1234567")
tsession = time(timeframe.period,"1300-1600:1234567")
tbis = time(timeframe.period,”1200-1400:1234567")
cond_tbis = not na(tbis)
// Calculate Price Range between 12:00 and 14:00
rangeHigh = (cond_tbis ? request.security(syminfo.tickerid, "60", high)[topening] : 0) 
rangeLow = (cond_tbis ? request.security(syminfo.tickerid, "60", low)[topening] : 70000) 
time pine-script pine-script-v5 price
1个回答
0
投票

我为此苦苦挣扎,然后我发现了这个

SessionHigh(sessionTime, sessionTimeZone=syminfo.timezone) =>
insideSession = not na(time(timeframe.period, sessionTime, sessionTimeZone))
var float sessionHighPrice = na

if insideSession and not insideSession[1]
    sessionHighPrice := high
else if insideSession
    sessionHighPrice := math.max(sessionHighPrice, high)

sessionTime = "1000-1530:23456"
timezone = "GMT+2"
highest = SessionHigh(sessionTime, timezone)

plot(highest, color=color.green, style=plot.style_circles, linewidth=2, title="Highest Price")

https://www.tradingcode.net/tradingview/session-highest-high/

© www.soinside.com 2019 - 2024. All rights reserved.