Pinescript - текущая [0] точка разворота точки в виде строки c? - PullRequest
0 голосов
/ 25 марта 2020

Я основываюсь на простом индикаторе точки разворота с использованием соснового скрипта, и я хотел, чтобы дневной текущий уровень закрытия, минимум и максимум вычислялся как один "stati c" объект "движущейся линии". Код ниже ведет себя как скользящая средняя сейчас, но показывает как точку разворота. Когда вы посмотрите предыдущие периоды, вы увидите сформированную линию. Но когда вы выбираете Bar Replay (ведущий себя как живой тест), он формирует линию «скользящего среднего». В общем, я хочу, чтобы это было больше похоже на точку опоры "stati c" plus, которая движется в соответствии с текущим ценовым движением. Таким образом, ПП будет двигаться вверх или вниз только на одну линию из-за движения цены.

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

1 Ответ

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

Может быть, это может помочь:

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