How to code a user-configurable session indicator that draw a LINE (i.e. time/range bound)

被刻印的时光 ゝ 提交于 2020-06-17 16:24:34

问题


I started with a question on how to programmatically draw a time/range based box/rectangle to frame a trading session, but came to the realization that Pine is not capable of doing so...

However, I understand Pine v4 introduces the ability to draw line objects and wonder if anyone can point me in the right direction for code to draw session lines instead. By that I mean hi & Lo for the start/end time specified (i.e. highest & lowest value for the time period) would be much appreciated?


I am looking for the ability to draw a line/box as per the attached image taken from FXCM Tradestation session indicator, which includes session name, hi & lo price level and range. Note that the highest/lowest price level is displayed for the whole time period, not progressively 'grown' as price develops with each bar.

RVK Session Boxes


回答1:


Not sure exactly what you're looking for, so not so sure it's impossible in Pine.

Here it's keeping track of weekly hi/los as the week unfolds:

This code is a variation using a configurable session range, with a few different ways of highlighting the session:

//@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)

Here it's highlighting "1100-1500" sessions with one of 3 different methods:



来源:https://stackoverflow.com/questions/58334458/how-to-code-a-user-configurable-session-indicator-that-draw-a-line-i-e-time-ra

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!