Pine Script V1转V5蜡烛颜色计算错误,求技术协助
Pine Script V1转V5:蜡烛颜色计算结果不符问题求助
正在将《Volume Pressure Composite Average with Bands》的Pine Script从V1版本转换到V5版本,已完成大部分重构,但因不了解V1中函数内自引用未定义变量的机制,导致转换后的脚本蜡烛颜色计算结果与原版本不符。以下是当前转换后的V5代码,恳请技术协助:
//@version=5 indicator("VOLUME PRESSURE -COMPOSITE- WEIGHTED MOVING AVERAGE by @XeL_Arjona", shorttitle="VPMA_XeL", overlay=true) GROUP_VOLUME_OPTIONS = "Volume Pressure Options" i_p = input.int(21, "Lookback Periods", group = GROUP_VOLUME_OPTIONS ) i_bands = input.bool(false, "Show Pressure Band", group = GROUP_VOLUME_OPTIONS) i_colb = input.bool(true, "Color Trend on price bars", group = GROUP_VOLUME_OPTIONS) vol = volume > 0 ? volume : 1 var VMema = array.new_float() // Close Conditions for Pressure Algorithms cl = close op = open hi = high lo = low vema(arr,periods,K) => ret = 0.0 VolW = vol*arr VolK = K / ( periods + 1 ) VMsma = math.sum( ( VolW ), periods ) / math.sum( vol, periods ) if array.size(VMema) < 2 ret := ( VMsma * VolK ) else if array.size(VMema) >= 2 and na( array.get(VMema, array.size( VMema ) - 2) ) ret := ( VMsma * VolK ) else ret := ( ( ( VolW - array.get(VMema, array.size( VMema ) - 2 ) ) * VolK) + array.get(VMema, array.size( VMema ) - 2) ) ret // Bull And Bear "Power-Balance" by Vadim Gimelfarb Algorithm's BP = (cl<op ? (cl[1]<op ? math.max(hi-cl[1], cl-lo) : math.max(hi-op, cl-lo)) : (cl>op ? (cl[1]>op ? hi-lo: math.max(op-cl[1], hi-lo)) : (hi-cl>cl-lo ? (cl[1]<op ? math.max(hi-cl[1],cl-lo) : hi-op) : (hi-cl<cl-lo ? (cl[1]>op ? hi-lo : math.max(op-cl[1], hi-lo)) : (cl[1]>op ? math.max(hi-op, cl-lo) : (cl[1]<op ? math.max(op-cl[1], hi-lo) : hi-lo)))))) SP = (cl<op ? (cl[1]>op ? math.max(cl[1]-op, hi-lo) : hi-lo) : (cl>op ? (cl[1]>op ? math.max(cl[1]-lo, hi-cl) : math.max(op-lo, hi-cl)) : (hi-cl>cl-lo ? (cl[1]>op ? math.max(cl[1]-op, hi-lo) : hi-lo) : (hi-cl<cl-lo ? (cl[1]>op ? math.max(cl[1]-lo, hi-cl) : op-lo) : (cl[1]>op ? math.max(cl[1]-op, hi-lo) : (cl[1]<op ? math.max(op-lo, hi-cl) : hi-lo)))))) TP = BP+SP // GENERAL CALCULATION VARIABLES FOR STUDIES BPV = (BP/TP)*vol SPV = (SP/TP)*vol TPV = BPV+SPV TH = math.max(high, close[1]) TL = math.min(low, close[1]) BPP = (TL+close)/2 SPP = (TH+close)/2 // Volume Pressures Weighted Averages v1 = vema((BPV*BPP),i_p,3) array.push(VMema, v1) v2 = vema(TPV,i_p,3)*2 array.push(VMema, v2) bpMavg = v1 / v2 v3 = vema((SPV*SPP),i_p,3) array.push(VMema, v3) v4 = vema(TPV,i_p,3)*2 array.push(VMema, v4) spMavg = v3 / v4 VPMavg = (bpMavg+spMavg)/2 VPMAc = bpMavg > VPMavg ? color.green : color.red // PLOT DIRECTIVES //Cloud coloring method by @ChrisMoody BPAbove = bpMavg >= spMavg ? 1 : na SPBelow = bpMavg <= spMavg ? 1 : na BPplotU = BPAbove ? bpMavg : na SPplotU = BPAbove ? spMavg : na BPplotD = SPBelow ? bpMavg : na SPplotD = SPBelow ? spMavg : na // Standard Line Coloring CondCol = bpMavg > spMavg ? color.green : color.red //Center Avg Line plot(i_bands?na:VPMavg, color=CondCol, title='VPMA', style=plot.style_line, linewidth=2) //Cloud Lines Plot Statements - ***linebr to create rules for change in Shading p1 = plot(i_bands and BPplotU ? BPplotU : na, title = 'BP/SP', style=plot.style_linebr, linewidth=1, color=CondCol) p2 = plot(i_bands and SPplotU ? SPplotU : na, title = 'SP/BP', style=plot.style_linebr, linewidth=1, color=CondCol) p3 = plot(i_bands and BPplotD ? BPplotD : na, title = 'BP/SP', style=plot.style_linebr, linewidth=1, color=CondCol) p4 = plot(i_bands and SPplotD ? SPplotD : na, title = 'SP/BP', style=plot.style_linebr, linewidth=1, color=CondCol) //Fills that color cloud based on Trend. fill(p1, p2, color=color.green, transp=90, title='Cloud') fill(p3, p4, color=color.red, transp=90, title='Cloud') plot(i_bands and bpMavg ? bpMavg : na, title = 'BPavg', style=plot.style_line, linewidth=1, color=color.green) plot(i_bands and spMavg ? spMavg : na, title = 'SPavg', style=plot.style_line, linewidth=1, color=color.red) barcolor(i_colb?CondCol:na)
内容的提问来源于stack exchange,提问作者Zathrus Writer
相关产品推荐
相关产品推荐

