Сценарий Pine v4: проблема с диапазоном сеансов - PullRequest
0 голосов
/ 26 марта 2020

Я изучаю Pine-скрипт и сессию с этим оригинальным исходным кодом из TradingView: Сеанс и информация о времени

//@version=4
study("Opening high/low", overlay=true)
highTimeFrame = input("D", type=input.resolution)
sessSpec = input("0930-1600", type=input.session)
//---
is_newbar(res, sess) =>
   t = time(res, sess)
   na(t[1]) and not na(t) or t[1] < t
//---
newbar = is_newbar("1440", sessSpec)
//---
var float s1 = na
var float s2 = na
//---
if newbar
s1 := low
s2 := high
//---
plot(s1, style=plot.style_circles, linewidth=3, color=color.red)
plot(s2, style=plot.style_circles, linewidth=3, color=color.lime)

проблема в том, что он не показывает диапазон всей сессии ; он показывает только диапазон первого бара независимо от таймфрейма.

Мне нужен диапазон всей сессии. Как я могу это исправить, пожалуйста.

С уважением.

Ответы [ 2 ]

0 голосов
/ 27 марта 2020

@ PineCoders-LucF

Я нашел ваш источник. Это именно то, что я хочу, но опция: squareBox = boxType == Ошибки "Фиксированные уровни".

исходный код:

//@version=4
//@author=LucF, for PineCoders
study("Time Range", "", true)
sessionInfo = input("1100-1500", "Session")
boxType = input("Fixed levels", "Box Type", options = ["None", "Dynamic levels", "Fixed levels"])
showBg = input(false, "Show background")
squareBox = boxType == "Fixed levels"
dynamicBox = boxType == "Dynamic levels"
showBox = squareBox or dynamicBox

inSession = time(timeframe.period, sessionInfo)
invisible = #FFFFFF

loLevel = lowest(10)
hiLevel = highest(10)
var hi = 10e-10
var lo = 10e10
// When a new period begins, reset hi/lo.
if inSession and not inSession[1]
    hi := dynamicBox ? high : hiLevel
else
    if dynamicBox
        hi := max(high, hi)
if inSession and not inSession[1]
    lo := dynamicBox ? low : loLevel
else
    if dynamicBox
        lo := min(low, lo)

hiPlot = plot(showBox and inSession ? hi : na, "Highs", invisible)
loPlot = plot(showBox and inSession ? lo : na, "Lows", invisible)
fill(hiPlot, loPlot, color.navy)

// Plot background.
bgcolor(showBg and inSession ? color.blue : na)

РЕДАКТИРОВАТЬ: Ошибка опции вариант картина здесь

...