Fahmi Eshaq
Fahmi Eshaq

Reputation: 378

Calculate Stoploss Percentage in Pinescript

I know how to get the calculate the stoploss 245.6 but I don't know how to get the percentage 2.08% ... Can someone please help me get the formula for the percentage?

enter image description here

I used the following formula to get the stoploss 245.6 pips

pips = (abs(1.18047 - 1.15591) / syminfo.mintick) / 10

Upvotes: 1

Views: 800

Answers (1)

e2e4
e2e4

Reputation: 3818

The percentage formula can be written in different forms, it is essentially an algebraic equation involving three values that you can turn into a function, for example:

//@version=5
indicator("", format = format.percent)

percent(value1, value2) => float(value1)/float(value2) * 100

val1 = 1.15591
val2 = 1.18047

percentChange = 100 - percent(val1, val2)

plot(percentChange) // 2.08

Upvotes: 1

Related Questions