繁体   English   中英

Pinescript - 当前 [0] 周期枢轴点作为静态线?

[英]Pinescript - current [0] period pivot point as static line?

我正在使用松树脚本构建一个简单的枢轴点指标,我希望将每日当前收盘价、最低价和最高价计算为一个“静态”移动线“对象”。 下面的代码现在表现得像一个移动平均线,但显示得像一个支点。 当您查看以前的周期时,您会看到形成了一条线。 但是当您选择 Bar Replay(表现得像现场测试)时,它正在形成一条“移动平均线”。 所以总的来说,我希望它更像是一个“静态”枢轴点,加上由于当前的价格走势而移动。 因此,由于价格行为,PP 只会作为一条线向上或向下移动。

//@version=2
strategy(title="Pivot", shorttitle="Pivot", overlay = true)
xHigh  = security(tickerid,"D", high[0])
xLow   = security(tickerid,"D", low[0])
xClose = security(tickerid,"D", close[0])
PP = (xHigh+xLow+xClose) / 3

width = input(1, minval=1)
plot(PP, color=#FFFFFF, title="PP", style = line, linewidth = width)

这可能吗? 我认为在 MetaTrader4 中,当您选择当前 ([0]) 周期时,它会自动像这样。

----------------------------- 更新:遇到了这个,但是 [0] 枢轴线从它的开始“挂起”指向终点,而不是像应该从中间那样。 因为如果它从中心悬挂,它会根据需要作为一条线移动。 想法?

//@version=4
study("Periodic lines", "", true)
htf = input("D", type = input.resolution)

// Returns the average number of current chart bars in the given target HTF resolution (this reflects the dataset's history).
f_avgDilationOf(_res) =>
    // _res: resolution of any TF (in "timeframe.period" string format).
    b = barssince(change(time(_res)))
    cumTotal = cum(b == 0 ? b[1] + 1 : 0)
    cumCount = cum(b == 0 ? 1 : 0)
    cumTotal / cumCount

// Period change detection.
pChange(res) =>
    change(time(res == 'Y' ? 'D' : res))

xHigh = security(syminfo.tickerid,"D", high[0])
xLow  = security(syminfo.tickerid,"D", low[0])
xClose = security(syminfo.tickerid,"D", close[0])
cvPP = (xHigh+xLow+xClose) / 3

// Get some previous value from last HTF period.
pHi = security(syminfo.tickerid, htf, cvPP, lookahead = barmerge.lookahead_on)
// Verify if current charts bars are part of the last dilation of HTF.
lastPBar = security(syminfo.tickerid, htf, barstate.islast, lookahead = barmerge.lookahead_on)
// Get avg no of chart bars in one dilation of HTF.
dilation = round(f_avgDilationOf(htf))
timeDelta = time - time[1]

var line pHiLine = na
// Holds bar index where a new line is created.
var pHiBar = 0
if pChange(htf)
    // Extend old line for the last bar before creating a new one.
    line.set_xy2(pHiLine, time, pHi[1])
    // Save bar index on transition.
    pHiBar := bar_index
    // Create new line.
    pHiLine := line.new(time, pHi, time + timeDelta, pHi, xloc.bar_time, color = color.white, width = 2)
    // Make type of the 2 `if` blocks the same.
    float(na)
else
    // We are not on a transition; prolong line until next transition.
    line.set_xy2(pHiLine, time, pHi)
    float(na)

// If we are in the last bars of the HTF resolution's dilation, project line into the future with remaining bars in average no of bars in dilation.
if lastPBar
    line.set_xy2(pHiLine, time + (timeDelta * (dilation - (bar_index - pHiBar))), pHi)

也许这可以帮助:

//@version=2
strategy(title="Pivot", shorttitle="Pivot", overlay = true)
xHigh  = security(tickerid,"D", high[1])
xLow   = security(tickerid,"D", low[1])
xClose = security(tickerid,"D", close[1])
PP = (xHigh+xLow+xClose) / 3

width = input(1, minval=1)
plot(PP, color=#FFFFFF, title="PP", style = line, linewidth = width)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM