Reputation: 65
Hello i am trying to include this type of moving average(elastic volume weighted moving average)
evwma = 0.0
evwma := ((volumeSum - volume) * nz(evwma[1]) + volume * src) / volumeSum
into my indicator (VWGSV) where the upper forumula must replace vwma function
//@version=4
study(shorttitle="VWGSV", title="Greatest swing value",overlay=true)
src = input(open)
lenght = input(4, minval=1 ,title="lenght")
multi = input (1.8,title="multiplier")
hx= if src>close[1]
close[1]
else
src
lx= if src<close[1]
close[1]
else
src
hg= (high-hx)
lg= (lx-low)
bgsv = (vwma(hg,lenght))*multi+hx
sgsv= lx-(vwma(lg,lenght))*multi
plot(bgsv,offset=1, color=color.green)
plot(sgsv,offset=1, color=color.red)
what i tried is something like this (sorry no coding experience at all...)
//@version=4
study(shorttitle="VWGSV", title="Greatest swing value",overlay=true)
src = input(open)
lenght = input(4, minval=1 ,title="lenght")
multi = input (1.8,title="multiplier")
volumeSum = sum(volume, lenght)
hx= if src>close[1]
close[1]
else
src
lx= if src<close[1]
close[1]
else
src
hg= (high-hx)
lg= (lx-low)
hevwma = 0.0
levwma = 0.0
hevwma := ((volumeSum - volume) * nz(hevwma[1]) + volume * hx) / volumeSum
levwma := ((volumeSum - volume) * nz(levwma[1]) + volume * lx) / volumeSum
bgsv = hevwma*multi+hx
sgsv= lx-levwma*multi
plot(series=bgsv,offset=1, color=color.green)
plot(series=sgsv,offset=1, color=color.red)
this is what i tried
hevwma = 0.0
levwma = 0.0
hevwma := ((volumeSum - volume) * nz(hevwma[1]) + volume * hx) / volumeSum
levwma := ((volumeSum - volume) * nz(levwma[1]) + volume * lx) / volumeSum
bgsv = round(hevwma)*multi+hx
sgsv= lx-round(levwma)*multi
I think is because the formula i am trying to integrate gives me a float value but i need it to be integer and i tried to convert it to integer somehow but with no success. Please help me , i need the somehow to get a result like in the picture attached
Upvotes: 4
Views: 18879
Reputation: 65
used round function and everything's good
//@version=4
study(shorttitle="EVWGSV", title="Greatest swing value elastic volume weighted version by BackPackRack",overlay=true)
src = input(open)
lenght = input(4, minval=1 ,title="lenght")
multi = input (1.8,title="multiplier")
volumeSum = sum(volume, lenght)
hx= src>close[1] ? close[1] : src
lx= src<close[1] ? close[1] : src
hg= (high-hx)
lg= (lx-low)
hevwma = 0.0
levwma = 0.0
hevwma := ((volumeSum - volume) * nz(hevwma[1]) + volume * hg) / volumeSum
levwma := ((volumeSum - volume) * nz(levwma[1]) + volume * lg) / volumeSum
rhevwma=round(hevwma)
rlevwma=round(levwma)
mrlevwma=rhevwma*multi
mrhevwma=rlevwma*multi
bgsv = mrhevwma+hx
sgsv= lx-mrlevwma
plot(bgsv,offset=1, color=color.green)
plot(sgsv,offset=1, color=color.red)
Upvotes: 2
Reputation: 383
I'm not sure I understand your question, as integer numbers per definition do not have decimals. If you want something where the results are for instance shown as 2.00, you can first convert to integer, then back to float and express the number with 2 decimals. But obviously the number is float again.
For getting intergers out of floats, have you tried the round()
function?
Round function on Pine reference
Upvotes: 3