I am looking to modify the code so the indicator plots open and close buy/sell at the start and end of then highlighted area. currently it plots buy and sell at the beginning and the end of the highlighted area instead of a open and a close. Whatever I tried has resulted the indicator issuing multiple buy and sell from the start till the end of the highlighted area.
Thanks
//@version=5
indicator("The ACOL P5", shorttitle="The ACOL P5", overlay=true)
harmonic = input(10)
buyBand = input(9)
sellBand = input(-9)
price = close
stl = math.round((harmonic * 2) - 1 - 0.5)
itl = math.round((stl * 2) - 1 - 0.5)
ltl = math.round((itl * 2) - 1 - 0.5)
hoff = math.round(harmonic / 2 - 0.5)
soff = math.round(stl / 2 - 0.5)
ioff = math.round(itl / 2 - 0.5)
xHavg = ta.sma(price, harmonic)
xSavg = ta.sma(price, stl)
xIavg = ta.sma(price, itl)
xLavg = ta.sma(price, ltl)
xvalue2 = xSavg - xHavg[hoff]
xvalue3 = xIavg - xSavg[soff]
xvalue12 = xLavg - xIavg[ioff]
xmomsig = xvalue2 + xvalue3 + xvalue12
xLavgOHLC = ta.sma(ohlc4, ltl - 1)
xH2 = ta.sma(price, harmonic - 1)
xS2 = ta.sma(price, stl - 1)
xI2 = ta.sma(price, itl - 1)
xL2 = ta.sma(price, ltl - 1)
derivH = (xHavg * 2) - xHavg[1]
derivS = (xSavg * 2) - xSavg[1]
derivI = (xIavg * 2) - xIavg[1]
derivL = (xLavg * 2) - xLavg[1]
sumDH = harmonic * derivH
sumDS = stl * derivS
sumDI = itl * derivI
sumDL = ltl * derivL
lengH = harmonic - 1
lengS = stl - 1
lengI = itl - 1
lengL = ltl - 1
N1H = xH2 * lengH
N1S = xS2 * lengS
N1I = xI2 * lengI
N1L = xL2 * lengL
DRH = sumDH - N1H
DRS = sumDS - N1S
DRI = sumDI - N1I
DRL = sumDL - N1L
SumH = xH2 * (harmonic - 1)
SumS = xS2 * (stl - 1)
SumI = xI2 * (itl - 1)
SumL = xLavgOHLC * (ltl - 1)
xvalue5 = (SumH + DRH) / harmonic
xvalue6 = (SumS + DRS) / stl
xvalue7 = (SumI + DRI) / itl
xvalue13 = (SumL + DRL) / ltl
value9 = xvalue6 - xvalue5[hoff]
value10 = xvalue7 - xvalue6[soff]
value14 = xvalue13 - xvalue7[ioff]
xmom = value9 + value10 + value14
HT = math.sin(xvalue5 * 2 * math.pi / 360) + math.cos(xvalue5 * 2 * math.pi / 360)
HTA = math.sin(xHavg * 2 * math.pi / 360) + math.cos(xHavg * 2 * math.pi / 360)
ST = math.sin(xvalue6 * 2 * math.pi / 360) + math.cos(xvalue6 * 2 * math.pi / 360)
STA = math.sin(xSavg * 2 * math.pi / 360) + math.cos(xSavg * 2 * math.pi / 360)
IT = math.sin(xvalue7 * 2 * math.pi / 360) + math.cos(xvalue7 * 2 * math.pi / 360)
ITA = math.sin(xIavg * 2 * math.pi / 360) + math.cos(xIavg * 2 * math.pi / 360)
xSum = HT + ST + IT
xErr = HTA + STA + ITA
Condition2 = (((xSum > xSum[soff]) and (xHavg < xHavg[soff])) or ((xSum < xSum[soff]) and (xHavg > xHavg[soff])))
phase = Condition2 ? -1 : 1
xErrSum = (xSum - xErr) * phase
xErrSig = ta.sma(xErrSum, soff)
xvalue70 = xvalue5 - xvalue13
xvalue71 = ta.sma(xvalue70, harmonic)
ErrNum = xErrSum > 0 and xErrSum < xErrSum[1] and xErrSum < xErrSig ? 1 :
xErrSum > 0 and xErrSum < xErrSum[1] and xErrSum > xErrSig ? 2 :
xErrSum > 0 and xErrSum > xErrSum[1] and xErrSum < xErrSig ? 2 :
xErrSum > 0 and xErrSum > xErrSum[1] and xErrSum > xErrSig ? 3 :
xErrSum < 0 and xErrSum > xErrSum[1] and xErrSum > xErrSig ? -1 :
xErrSum < 0 and xErrSum < xErrSum[1] and xErrSum > xErrSig ? -2 :
xErrSum < 0 and xErrSum > xErrSum[1] and xErrSum < xErrSig ? -2 :
xErrSum < 0 and xErrSum < xErrSum[1] and xErrSum < xErrSig ? -3 : 0
momNum = xmom > 0 and xmom < xmom[1] and xmom < xmomsig ? 1 :
xmom > 0 and xmom < xmom[1] and xmom > xmomsig ? 2 :
xmom > 0 and xmom > xmom[1] and xmom < xmomsig ? 2 :
xmom > 0 and xmom > xmom[1] and xmom > xmomsig ? 3 :
xmom < 0 and xmom > xmom[1] and xmom > xmomsig ? -1 :
xmom < 0 and xmom < xmom[1] and xmom > xmomsig ? -2 :
xmom < 0 and xmom > xmom[1] and xmom < xmomsig ? -2 :
xmom < 0 and xmom < xmom[1] and xmom < xmomsig ? -3 : 0
TCNum = 0
TCNum := xvalue70 > 0 and xvalue70 < xvalue70[1] and xvalue70 < xvalue71 ? 1 : TCNum
TCNum := xvalue70 > 0 and xvalue70 < xvalue70[1] and xvalue70 > xvalue71 ? 2 : TCNum
TCNum := xvalue70 > 0 and xvalue70 > xvalue70[1] and xvalue70 < xvalue71 ? 2 : TCNum
TCNum := xvalue70 > 0 and xvalue70 > xvalue70[1] and xvalue70 > xvalue71 ? 3 : TCNum
TCNum := xvalue70 < 0 and xvalue70 > xvalue70[1] and xvalue70 > xvalue71 ? -1 : TCNum
TCNum := xvalue70 < 0 and xvalue70 < xvalue70[1] and xvalue70 > xvalue71 ? -2 : TCNum
TCNum := xvalue70 < 0 and xvalue70 > xvalue70[1] and xvalue70 < xvalue71 ? -2 : TCNum
TCNum := xvalue70 < 0 and xvalue70 < xvalue70[1] and xvalue70 < xvalue71 ? -3 : TCNum
value42 = ErrNum + momNum + TCNum
confluence = value42 > 0 and xvalue70 > 0 ? value42 :
value42 < 0 and xvalue70 < 0 ? value42 :
(value42 > 0 and xvalue70 < 0) or (value42 < 0 and xvalue70 > 0) ? value42 / 10 : 0
res1 = confluence >= 1 ? confluence : 0
res2 = confluence <= -1 ? confluence : 0
res3 = confluence == 0 ? 0 : (confluence > -1 and confluence < 1 ? 10 * confluence : 0)
pos = res2 >= sellBand and res2 != 0 ? -1 :
res1 <= buyBand and res1 != 0 ? 1 :
res3 != 0 ? 2 :
na
bgcolorChanged = res1[1] != res1
bgcolorChangedB = res2[1] != res2
bgcolor(res1 ? color.new(color.lime, 85) : na, title="Buy Bars")
bgcolor(res2 ? color.new(color.red, 85) : na, title="Sell Bars")
var bool lastBuySignal = na
var bool lastSellSignal = na
var bool buySignalIssued = false
var bool sellSignalIssued = false
longSignal = res1 and bgcolorChanged and not buySignalIssued ? true : na
shortSignal = res2 and bgcolorChangedB and not sellSignalIssued ? true : na
plotshape(series=longSignal, title='Buy', style=shape.labelup, location=location.belowbar, size=size.small, color=color.new(color.green, 0))
plotshape(series=shortSignal, title='Sell', style=shape.labeldown, location=location.abovebar, size=size.small, color=color.new(color.red, 0))
lastBuySignal := longSignal or (lastBuySignal and not bgcolorChanged)
lastSellSignal := shortSignal or (lastSellSignal and not bgcolorChangedB)
buySignalIssued := buySignalIssued or longSignal
sellSignalIssued := sellSignalIssued or shortSignal
I am looking to modify the code so the indicator plots open and close buy/sell at the start and end of then highlighted area. currently it plots buy and sell at the beginning and the end of the highlighted area instead of a open and a close. Whatever I tried has resulted the indicator issuing multiple buy and sell from the start till the end of the highlighted area.
to avoid repeating signals, try this:
longSignal = Res1 and not Res1[1]
shortSignal = Res2 and not Res2[1]
plotshape(longSignal, title='Buy', style=shape.labelup, location=location.belowbar, size=size.small, color=color.new(color.green, 0))
plotshape(shortSignal, title='Sell', style=shape.labeldown, location=location.abovebar, size=size.small, color=color.new(color.red, 0))