Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Float into Int values Pine-script

Tags:

pine-script

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

like image 564
wuasile kerpici Avatar asked Oct 17 '25 18:10

wuasile kerpici


2 Answers

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

like image 55
Glauco Esturilio Avatar answered Oct 22 '25 07:10

Glauco Esturilio


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)
like image 43
wuasile kerpici Avatar answered Oct 22 '25 07:10

wuasile kerpici



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!