0
votes

I'm currently working on a script that calculates stuff based on predefined levels. So I'm tacking the price and divide it by a configurable value and I want to get the integer value for this division. In C-code it would look like this:

newValue = (int)( close / divValue )

In Pinescript it will just make a typecast to float and the modulo-operator will just give me the remains of the division. Is there some way to make a typecast from float to integer or something like a reverse modulo?

Thanks in advance :)

1

1 Answers

1
votes

You can use the int() function for that.
Here's an example.

//@version=4
study("My Script", overlay=true)

var float   myClose     = 130.98
var int     divValue    = 3

var int     newValue    = na
var float   remainder   = na

newValue    := int(myClose / divValue)
remainder   := myClose % divValue

plotchar(newValue,  "newValue",  "")
plotchar(remainder, "remainder", "")