Pine не может определить длину ссылки серии - ошибка только на 30-минутном и 20-минутном таймфреймах. - PullRequest
0 голосов
/ 12 апреля 2020

Этот сценарий отлично работает на каждом таймфрейме, кроме 30 минут и 20 минут?

Я получаю сообщение об ошибке "Pine не может определить длину ссылки в серии"

Добавление max_bars_back не влияет на эту ошибку ... Я пытался это, и это не исправляет ошибку

Хотите знать, что может быть причиной этого?

Я также пытаюсь выяснить, как показать предыдущие сводки, есть флажок, чтобы показать или скрыть их.

//@version=4
//maxBarsBack = 200
//max_bars_back = maxBarsBack
study(title="Pivot Points Standard +", shorttitle="Pivot Points Standard +", overlay = true)
//hide_historical = input(false, title="Hide Historical?")
// 
// author: QuantNomad
// date: 2019-07-28
// Traditional Pivot Points Alerts
// https://www.tradingview.com/u/QuantNomad/
// https://t.me/quantnomad
//

// Function outputs 1 when it's the first bar of the D/W/M/Y
is_newbar(res) =>
    ch = 0
    if(res == 'Y')
        t  = year(time('D'))
        ch := change(t) != 0 ? 1 : 0
    else
        t = time(res)
        ch := change(t) != 0 ? 1 : 0
    ch

nround(x) => 
    n = x < 10 ? 3 : x < 100 ? 2 : x < 1000 ? 1 : 0
    round(x * pow(10, n)) / pow(10, n)

////////////
// INPUTS //
////////////
//
pp_period = input(title = "Period", type=input.string, defval="Auto", options = ['Day', 'Week', 'Month', 'Year', 'Auto'])

show_levels = input(true, type = input.bool, title = "Show Levels?")

pp_res = pp_period == 'Day' ? 'D' : pp_period == 'Week' ? 'W' : pp_period == 'Month' ? 'M' : pp_period == 'Auto' ? (timeframe.multiplier>=16 and timeframe.multiplier<=720?'W':timeframe.multiplier<=15?'D':timeframe.isdaily?'M':timeframe.isweekly?'Y':timeframe.ismonthly?'Y':'Y'):'Y' 

//pp_res1=timeframe.isintraday?'D':timeframe.isdaily?'W':timeframe.isweekly?'Y':timeframe.ismonthly?'Y':'Y'


/////////////////////
// Get HLC from HT //

// Calc High
high_cur = 0.0
high_cur := is_newbar(pp_res) ? high : max(high_cur[1], high)

phigh = 0.0
phigh := is_newbar(pp_res) ? high_cur[1] : phigh[1]

// Calc Low
low_cur = 0.0
low_cur := is_newbar(pp_res) ? low : min(low_cur[1], low)

plow = 0.0
plow := is_newbar(pp_res) ? low_cur[1] : plow[1]

// Calc Close
pclose = 0.0
pclose := is_newbar(pp_res) ? close[1] : pclose[1]

////////////////////////////////
// CALCULATE traditional pivots //

vPP = (phigh + plow + pclose) / 3
vR1 = vPP    + (vPP   - plow)
vS1 = vPP    - (phigh - vPP)
vR2 = vPP    + (phigh - plow)
vS2 = vPP    - (phigh - plow)
vR3 = phigh  + 2 * (vPP   - plow) 
vS3 = plow   - 2 * (phigh - vPP) 
plongstop=(vPP+vS1)/2
pshortstop=(vPP+vR1)/2 
//////////////
// PLOTTING //

bars_sinse = 0
bars_sinse := is_newbar(pp_res) ? 0 : bars_sinse[1] + 1

//plot(bars_sinse)

////////////////////////
// PLOT PIVOTS LEVELS //

vpp_p = line.new(bar_index[bars_sinse], vPP, bar_index, vPP, color=color.blue, style =  line.style_solid, extend = extend.right)
vs1_p = line.new(bar_index[bars_sinse], vS1, bar_index, vS1, color=color.gray, style =  line.style_solid, extend = extend.right)
vs2_p = line.new(bar_index[bars_sinse], vS2, bar_index, vS2, color=color.gray, style =  line.style_solid, extend = extend.right)
vs3_p = line.new(bar_index[bars_sinse], vS3, bar_index, vS3, color=color.gray, style =  line.style_solid, extend = extend.right)
vr1_p = line.new(bar_index[bars_sinse], vR1, bar_index, vR1, color=color.gray, style =  line.style_solid, extend = extend.right)
vr2_p = line.new(bar_index[bars_sinse], vR2, bar_index, vR2, color=color.gray, style =  line.style_solid, extend = extend.right)
vr3_p = line.new(bar_index[bars_sinse], vR3, bar_index, vR3, color=color.gray, style =  line.style_solid, extend = extend.right)
plongstop_p = line.new(bar_index[bars_sinse], plongstop, bar_index, plongstop, color=color.black, style =  line.style_dashed, extend = extend.right)
pshortstop_p = line.new(bar_index[bars_sinse], pshortstop, bar_index, pshortstop, color=color.black, style =  line.style_dashed, extend = extend.right)
// delete previous lines in the same period
if (not is_newbar(pp_res)) 
    line.delete(vpp_p[1])
    line.delete(vs1_p[1]) 
    line.delete(vs2_p[1])  
    line.delete(vs3_p[1])  
    line.delete(vr1_p[1]) 
    line.delete(vr2_p[1])  
    line.delete(vr3_p[1]) 

// delete entend for the old lines
if (is_newbar(pp_res))
    line.set_extend(vpp_p[1], extend.none)
    line.set_extend(vs1_p[1], extend.none) 
    line.set_extend(vs2_p[1], extend.none)  
    line.set_extend(vs3_p[1], extend.none)  
    line.set_extend(vr1_p[1], extend.none) 
    line.set_extend(vr2_p[1], extend.none)  
    line.set_extend(vr3_p[1], extend.none) 

// Add labels
if (is_newbar(pp_res))
    label_vpp = label.new(bar_index, vPP, text=show_levels ? ("P"  + " " + tostring(nround(vPP))) : "P",  style= label.style_none)
//    if (not is_newbar(pp_res)) 
    label.delete(label_vpp[1])
    label_vs1 = label.new(bar_index, vS1, text=show_levels ? ("S1" + " " + tostring(nround(vS1))) : "S1", style= label.style_none)
//    if (not is_newbar(pp_res)) 
    label.delete(label_vs1[1]) 
    label_vs2 = label.new(bar_index, vS2, text=show_levels ? ("S2" + " " + tostring(nround(vS2))) : "S2", style= label.style_none)
//    if (not is_newbar(pp_res)) 
    label.delete(label_vs2[1])  
    label_vs3 = label.new(bar_index, vS3, text=show_levels ? ("S3" + " " + tostring(nround(vS3))) : "S3", style= label.style_none)
//    if (not is_newbar(pp_res)) 
    label.delete(label_vs3[1])  
    label_vr1 = label.new(bar_index, vR1, text=show_levels ? ("R1" + " " + tostring(nround(vR1))) : "R1", style= label.style_none)
//    if (not is_newbar(pp_res)) 
    label.delete(label_vr1[1]) 
    label_vr2 = label.new(bar_index, vR2, text=show_levels ? ("R2" + " " + tostring(nround(vR2))) : "R2", style= label.style_none)
//    if (not is_newbar(pp_res)) 
    label.delete(label_vr2[1])  
    label_vr3 = label.new(bar_index, vR3, text=show_levels ? ("R3" + " " + tostring(nround(vR3))) : "R3", style= label.style_none)
//    if (is_newbar(pp_res))
    label.delete(label_vr3[1]) 

1 Ответ

0 голосов
/ 12 апреля 2020

Это должно это исправить. Не знаю почему, но Pine иногда не нравится использование оператора ссылки на историю с bar_index, который в любом случае является излишним:

//////////////
// PLOTTING //

var bars_sinse = 0
bars_sinse := is_newbar(pp_res) ? 0 : bars_sinse + 1

plotchar(bars_sinse, "bars_sinse", "", location.top)

// //////////////////////
// PLOT PIVOTS LEVELS //

vpp_p = line.new(bar_index - bars_sinse, vPP, bar_index, vPP, color=color.blue, style =  line.style_solid, extend = extend.right)
vs1_p = line.new(bar_index - bars_sinse, vS1, bar_index, vS1, color=color.gray, style =  line.style_solid, extend = extend.right)
vs2_p = line.new(bar_index - bars_sinse, vS2, bar_index, vS2, color=color.gray, style =  line.style_solid, extend = extend.right)
vs3_p = line.new(bar_index - bars_sinse, vS3, bar_index, vS3, color=color.gray, style =  line.style_solid, extend = extend.right)
vr1_p = line.new(bar_index - bars_sinse, vR1, bar_index, vR1, color=color.gray, style =  line.style_solid, extend = extend.right)
vr2_p = line.new(bar_index - bars_sinse, vR2, bar_index, vR2, color=color.gray, style =  line.style_solid, extend = extend.right)
vr3_p = line.new(bar_index - bars_sinse, vR3, bar_index, vR3, color=color.gray, style =  line.style_solid, extend = extend.right)
plongstop_p  = line.new(bar_index - bars_sinse, plongstop, bar_index, plongstop, color=color.black, style =  line.style_dashed, extend = extend.right)
pshortstop_p = line.new(bar_index - bars_sinse, pshortstop, bar_index, pshortstop, color=color.black, style =  line.style_dashed, extend = extend.right)

enter image description here

...