I m using this alertcondition
to ask the value from a plot, but the returned value has more than 3 decimal places.
Can I format it to make the output only display precision until 3 decimals only?
alertcondition(crossover(d2,d3), title="monitor", message='🎯{{ticker}}🎯 Monitor If price above Current Price={{close}} PIVOT = {{plot("Pivot")}} SUPPORT = {{plot("S1")}} RESISTANCE = {{plot("R1")}}
If you need to format a string to display only three decimal values, then the format string param of the tostring()
function will help you.
If you need to plot the value with precision of three decimal values, then you might just set the study's param precision
to 3.
An example of using those params is below:
//@version=4
study("My Script", precision=3) // precision gives three decimal values in the plot-functions
// the format '#.###' gives three decimal values in a string
val = open / close
s = tostring(val, '#.###')
label.new(bar_index, high, s)
// this plots only three decimal values, because of the study's param 'precision=3'
plot(val)
You will need to round your plotted value:
//@version=4
study("")
f_round( _val, _decimals) =>
// Rounds _val to _decimals places.
_p = pow(10,_decimals)
round(abs(_val)*_p)/_p*sign(_val)
plot(close, "CloseP")
plot(f_round(close, 3), "CloseR")
alertcondition(true, "A", 'Unrounded: {{plot("CloseP")}}, Rounded:{{plot("CloseR")}}')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With