CPR 指示器中绘制水平的问题

问题描述 投票:0回答:2

大家

我需要有关我正在学习编码的 CPR 指示器的帮助。

问题:

  1. S/R 的点/圆圈应该在 9:15 开始绘制,但它们在 9:20 绘制(仅正确绘制前一天的高点/低点)。

  2. 如果我使用“线条”风格,那么一切都很好。但如果我使用“plot.style_circles”,它们会在 9:20 绘制。

其他人的参考指标一直运行良好。

我的不稳定版本,其中 PDH 和 PDL 工作正常。但是S/R延迟了。

如果我使用线条样式,一切都会完美运行。

代码如下:

//cenral pivot range
pivot = (high + low + close) /3 //Central Povit
BC = (high + low) / 2 //Below Central povit
TC = (pivot - BC) + pivot //Top Central povot

//3  support levels
S1 = (pivot * 2) - high
S2 = pivot - (high - low)
S3 = low - 2 * (high - pivot)
S4 = low - 3 * (high - pivot)

//3  resistance levels
R1 = (pivot * 2) - low
R2 = pivot + (high - low)
R3 = high + 2 * (pivot-low)
R4 = high + 3 * (pivot-low)

//Checkbox inputs
CPRPlot = input(title = "Show Daily CPR?", type=input.bool, defval=true)
DayS1R1 = input(title = "Show Daily S1/R1?", type=input.bool, defval=true)
DayS2R2 = input(title = "Show Daily S2/R2?", type=input.bool, defval=true)
DayS3R3 = input(title = "Show Daily S3/R3?", type=input.bool, defval=false)
DayS4R4 = input(title = "Show Daily S4/R4?", type=input.bool, defval=false)

WeeklyPivotInclude = input(title = "Show Weekly Pivot?", type=input.bool, defval=false)
WeeklyS1R1 = input(title = "Show Weekly S1/R1?", type=input.bool, defval=false)
WeeklyS2R2 = input(title = "Show Weekly S2/R2?", type=input.bool, defval=false)
WeeklyS3R3 = input(title = "Show Weekly S3/R3?", type=input.bool, defval=false)
WeeklyS4R4 = input(title = "Show Weekly S4/R4?", type=input.bool, defval=false)

MonthlyPivotInclude = input(title = "Show Monthly Pivot?", type=input.bool, defval=false)
MonthlyS1R1 = input(title = "Show Monthly S1/R1?", type=input.bool, defval=false)
MonthlyS2R2 = input(title = "Show Monthly S2/R2?", type=input.bool, defval=false)
MonthlyS3R3 = input(title = "Show Monthly S3/R3?", type=input.bool, defval=false)

//******************DAYWISE CPR & PIVOTS**************************
// Getting daywise CPR
DayPivot = security(syminfo.tickerid, "D", pivot[1], lookahead=barmerge.lookahead_on)
DayBC = security(syminfo.tickerid, "D", BC[1], lookahead=barmerge.lookahead_on)
DayTC = security(syminfo.tickerid, "D", TC[1], lookahead=barmerge.lookahead_on)

//Adding linebreaks daywse for CPR
CPColour = DayPivot != DayPivot[1] ? na : color.red
BCColour = DayBC != DayBC[1] ? na : color.blue
TCColour = DayTC != DayTC[1] ? na : color.blue

//Plotting daywise CPR
plot(DayPivot, title = "CP" , color = CPColour, style = plot.style_circles, linewidth =2)
plot(CPRPlot ? DayBC : na , title = "BC" , color = BCColour, style = plot.style_circles, linewidth =2)
plot(CPRPlot ? DayTC : na , title = "TC" , color = TCColour, style = plot.style_circles, linewidth =2)

// Getting daywise Support levels
DayS1 = security(syminfo.tickerid, "D", S1[1], barmerge.gaps_off, barmerge.lookahead_on)
DayS2 = security(syminfo.tickerid, "D", S2[1], barmerge.gaps_off, barmerge.lookahead_on)
DayS3 = security(syminfo.tickerid, "D", S3[1], barmerge.gaps_off, barmerge.lookahead_on)
DayS4 = security(syminfo.tickerid, "D", S4[1], barmerge.gaps_off, barmerge.lookahead_on)

//Adding linebreaks for daywise Support levels 
DayS1Color =DayS1 != DayS1[1] ? na : color.green
DayS2Color =DayS2 != DayS2[1] ? na : color.green
DayS3Color =DayS3 != DayS3[1] ? na : color.green
DayS4Color =DayS4 != DayS4[1] ? na : color.green

//Plotting daywise Support levels
plot(DayS1R1 ? DayS1 : na, title = "D-S1" , color = DayS1Color, style = plot.style_circles, linewidth =1)
plot(DayS2R2 ? DayS2 : na, title = "D-S2" , color = DayS2Color, style = plot.style_circles, linewidth =1)
plot(DayS3R3 ? DayS3 : na, title = "D-S3" , color = DayS3Color, style = plot.style_circles, linewidth =1)
plot(DayS4R4 ? DayS4 : na, title = "D-S4" , color = DayS4Color, style = plot.style_circles, linewidth =1)

// Getting daywise Resistance levels
DayR1 = security(syminfo.tickerid, "D", R1[1], barmerge.gaps_off, barmerge.lookahead_on)
DayR2 = security(syminfo.tickerid, "D", R2[1], barmerge.gaps_off, barmerge.lookahead_on)
DayR3 = security(syminfo.tickerid, "D", R3[1], barmerge.gaps_off, barmerge.lookahead_on)
DayR4 = security(syminfo.tickerid, "D", R4[1], barmerge.gaps_off, barmerge.lookahead_on)

//Adding linebreaks for daywise Support levels
DayR1Color =DayR1 != DayR1[1] ? na : color.red
DayR2Color =DayR2 != DayR2[1] ? na : color.red
DayR3Color =DayR3 != DayR3[1] ? na : color.red
DayR4Color =DayR4 != DayR4[1] ? na : color.red

//Plotting daywise Resistance levels
plot(DayS1R1 ? DayR1 : na, title = "D-R1" , color = DayR1Color, style = plot.style_circles, linewidth =1)
plot(DayS2R2 ? DayR2 : na, title = "D-R2" , color = DayR2Color, style = plot.style_circles, linewidth =1)
plot(DayS3R3 ? DayR3 : na, title = "D-R3" , color = DayR3Color, style = plot.style_circles, linewidth =1)
plot(DayS4R4 ? DayR4 : na, title = "D-R4" , color = DayR4Color, style = plot.style_circles, linewidth =1)

//******************WEEKLY PIVOTS**************************

// Getting Weekly Pivot
WPivot = security(syminfo.tickerid, "W", pivot[1], barmerge.gaps_off, barmerge.lookahead_on)

//Adding linebreaks for Weely Pivot 
WeeklyPivotColor =WPivot != WPivot[1] ? na : color.blue

//Plotting Weekly Pivot
plot(WeeklyPivotInclude ? WPivot:na, title = "W-P" , color = WeeklyPivotColor, style = plot.style_circles, linewidth =1)


// Getting Weekly Support levels
WS1 = security(syminfo.tickerid, "W", S1[1],barmerge.gaps_off, barmerge.lookahead_on)
WS2 = security(syminfo.tickerid, "W", S2[1],barmerge.gaps_off, barmerge.lookahead_on)
WS3 = security(syminfo.tickerid, "W", S3[1],barmerge.gaps_off, barmerge.lookahead_on)
WS4 = security(syminfo.tickerid, "W", S4[1],barmerge.gaps_off, barmerge.lookahead_on)

//Adding linebreaks for weekly Support levels
WS1Color =WS1 != WS1[1] ? na : color.green
WS2Color =WS2 != WS2[1] ? na : color.green
WS3Color =WS3 != WS3[1] ? na : color.green
WS4Color =WS4 != WS4[1] ? na : color.green

//Plotting Weely Support levels
plot(WeeklyS1R1 ? WS1 : na, title = "W-S1" , color = WS1Color, style = plot.style_cross, linewidth =1)
plot(WeeklyS2R2 ? WS2 : na, title = "W-S2" , color = WS2Color, style = plot.style_cross, linewidth =1)
plot(WeeklyS3R3 ? WS3 : na, title = "W-S3" , color = WS3Color, style = plot.style_cross, linewidth =1)
plot(WeeklyS4R4 ? WS4 : na, title = "W-S4" , color = WS3Color, style = plot.style_cross, linewidth =1)

// Getting Weekly Resistance levels
WR1 = security(syminfo.tickerid, "W", R1[1], barmerge.gaps_off, barmerge.lookahead_on)
WR2 = security(syminfo.tickerid, "W", R2[1], barmerge.gaps_off, barmerge.lookahead_on)
WR3 = security(syminfo.tickerid, "W", R3[1], barmerge.gaps_off, barmerge.lookahead_on)
WR4 = security(syminfo.tickerid, "W", R4[1], barmerge.gaps_off, barmerge.lookahead_on)

//Adding linebreaks for weekly Resistance levels
WR1Color = WR1 != WR1[1] ? na : color.red
WR2Color = WR2 != WR2[1] ? na : color.red
WR3Color = WR3 != WR3[1] ? na : color.red
WR4Color = WR4 != WR4[1] ? na : color.red

//Plotting Weely Resistance levels
plot(WeeklyS1R1 ? WR1 : na , title = "W-R1" , color = WR1Color, style = plot.style_cross, linewidth =1)
plot(WeeklyS2R2 ? WR2 : na , title = "W-R2" , color = WR2Color, style = plot.style_cross, linewidth =1)
plot(WeeklyS3R3 ? WR3 : na , title = "W-R3" , color = WR3Color, style = plot.style_cross, linewidth =1)
plot(WeeklyS4R4 ? WR4 : na , title = "W-R4" , color = WR4Color, style = plot.style_cross, linewidth =1)

//******************MONTHLY PIVOTS**************************

// Getting Monthly Pivot
MPivot = security(syminfo.tickerid, "M", pivot[1],barmerge.gaps_off, barmerge.lookahead_on)

//Adding linebreaks for Monthly Support levels 
MonthlyPivotColor =MPivot != MPivot[1] ? na : color.blue

//Plotting  Monhly Pivot
plot(MonthlyPivotInclude? MPivot:na, title = " M-P" , color = MonthlyPivotColor, style = plot.style_line, linewidth =1)

// Getting  Monthly Support levels
MS1 = security(syminfo.tickerid, "M", S1[1],barmerge.gaps_off, barmerge.lookahead_on)
MS2 = security(syminfo.tickerid, "M", S2[1],barmerge.gaps_off, barmerge.lookahead_on)
MS3 = security(syminfo.tickerid, "M", S3[1],barmerge.gaps_off, barmerge.lookahead_on)

//Adding linebreaks for Montly Support levels
MS1Color =MS1 != MS1[1] ? na : color.green
MS2Color =MS2 != MS2[1] ? na : color.green
MS3Color =MS3 != MS3[1] ? na : color.green

//Plotting  Monhly Support levels
plot(MonthlyS1R1 ? MS1 : na, title = "M-S1" , color = MS1Color, style = plot.style_circles, linewidth =1)
plot(MonthlyS2R2 ? MS2 : na, title = "M-S2" , color = MS2Color, style = plot.style_circles, linewidth =1)
plot(MonthlyS3R3 ? MS3 : na, title = "M-S3" , color = MS3Color, style = plot.style_circles, linewidth =1)


// Getting  Monthly Resistance levels
MR1 = security(syminfo.tickerid, "M", R1[1],barmerge.gaps_off, barmerge.lookahead_on)
MR2 = security(syminfo.tickerid, "M", R2[1],barmerge.gaps_off, barmerge.lookahead_on)
MR3 = security(syminfo.tickerid, "M", R3[1],barmerge.gaps_off, barmerge.lookahead_on)

MR1Color =MR1 != MR1[1] ? na : color.red
MR2Color =MR2 != MR2[1] ? na : color.red
MR3Color =MR3 != MR3[1] ? na : color.red


//Plotting  Monhly Resistance levels
plot(MonthlyS1R1 ? MR1 : na , title = "M-R1", color = MR1Color, style = plot.style_circles , linewidth =1)
plot(MonthlyS2R2 ? MR2 : na , title = "M-R2" , color = MR2Color, style = plot.style_circles, linewidth =1)
plot(MonthlyS3R3 ? MR3 : na, title = "M-R3" , color = MR3Color, style = plot.style_circles, linewidth =1)

//*****************************INDICATORS**************************

//SMA 1
PlotSMA1 = input(title = "Plot SMA 1?", type=input.bool, defval=true)
SMALength1 = input(title="SMA Length", type=input.integer, defval=20)
SMASource1 = input(title="SMA Source", type=input.source, defval=close)
SMAvg1 = sma (SMASource1, SMALength1)
plot(PlotSMA1 ? SMAvg1 : na,  color= color.green, title="SMA")

//SMA 2
PlotSMA2 = input(title = "Plot SMA 2?", type=input.bool, defval=true)
SMALength2 = input(title="SMA Length", type=input.integer, defval=50)
SMASource2 = input(title="SMA Source", type=input.source, defval=close)
SMAvg2 = sma (SMASource2, SMALength2)
plot(PlotSMA2 ? SMAvg2 : na,  color= color.blue, title="SMA")

//EMA 1
PlotEMA1 = input(title = "Plot EMA 1?", type=input.bool, defval=true)
EMALength1 = input(title="EMA Length", type=input.integer, defval=20)
EMASource1 = input(title="EMA Source", type=input.source, defval=close)
EMAvg1 = ema (EMASource1, EMALength1)
plot(PlotEMA1 ? EMAvg1 : na,  color= color.green, title="EMA")

//EMA 2
PlotEMA2 = input(title = "Plot EMA 2?", type=input.bool, defval=true)
EMALength2 = input(title="EMA Length", type=input.integer, defval=50)
EMASource2 = input(title="EMA Source", type=input.source, defval=close)
EMAvg2 = ema (EMASource2, EMALength2)
plot(PlotEMA2 ? EMAvg2 : na,  color= color.blue, title="EMA")

//VWAP
PlotVWAP = input(title = "Plot VWAP?", type=input.bool, defval=true)
VWAPSource = input(title="VWAP Source", type=input.source, defval=close)
VWAPrice = vwap (VWAPSource)
plot(PlotVWAP ? VWAPrice : na,  color= color.teal, title="VWAP")

//PDH and PDL
pdh = security(syminfo.tickerid, "D", high[0], barmerge.gaps_off, barmerge.lookahead_on)
pdl = security(syminfo.tickerid, "D", low[0], barmerge.gaps_off, barmerge.lookahead_on)

plot(pdh, "Previous Day High", color.black, linewidth = 1, style = plot.style_circles )
plot(pdl, "Previous Day Low", color.black, linewidth = 1, style = plot.style_circles )

Pastebin:https://pastebin.com/Usy3mp8J

如果有人可以纠正我的代码并帮助绘制“明天的心肺复苏”,我将非常感激。

谢谢你。

pine-script
2个回答
0
投票

@pilgrimofdelhi,您修复了报告的问题吗?你能分享一下解决方案吗?


-1
投票

上面的代码与点线完美配合,逻辑是每个每个点都表示 5 分钟蜡烛,所以当您使用 5 分钟时间范围时,一个点等于 5 分钟蜡烛,您可以在更改时间范围后检查差异

© www.soinside.com 2019 - 2024. All rights reserved.