4

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

what i get

How it must look

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

wuasile kerpici
  • 65
  • 1
  • 1
  • 6

2 Answers2

3

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

  • i tried to use the round function but it did not changed the final result , maybe i was wrong on syntax , i am new to this language . please paste the code with the round () function and i will try it in tradingview to see what the results look like , an approximation of the results i posted in the images attached – wuasile kerpici Apr 21 '20 at 21:49
  • Hi, the script is sound, except that I would replace the definitions of hx and lx by the one-line format, for instance: `hx= src>close[1] ? close[1] : src` When wrapping the whole definitions of `bgsv` and `sgsv` with `round()`, the result is an integer. Other than that, I can't help any further because it is not clear what you're trying to achieve. I suggest you debug your code by plotting each and every intermediate variable, so you'll find what's going wrong. – Glauco Esturilio Apr 23 '20 at 01:24
2

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)
wuasile kerpici
  • 65
  • 1
  • 1
  • 6