I'm trying to set up alerts in tradingview when my condition is met.
Hoewer my problem is that I get only 2 numbers after a comma and I need 3 of them.
I've tried a couple of things, but I cannot figure it out to work properly.
strategy(title="ScalpSMA30",shorttitle="ScalpSMA30",precision=3,overlay=true, calc_on_every_tick=true)
condition_long = close[1]>open[1] and close[0]>open[0] and crossover(close[1],sma1) and high[0]>=point
condition_short = crossunder(close[1],sma1) and close[1]<open[1] and low[0]<open[0] and low[0]<=point1
strategy.entry("Long Condition", strategy.long, 100, when=condition_long)
strategy.entry("Short Condition", strategy.short, 100, when=condition_short)
// Declaring alerts
if condition_long
alert("Go long (Entry is " + tostring(close, "#.###)"), alert.freq_once_per_bar)
if condition_short
alert("Go short (Entry is " + tostring(close, "#.###)"), alert.freq_once_per_bar)
strategy(title="ScalpSMA30",shorttitle="ScalpSMA30", precision = 3, overlay=true, calc_on_every_tick=true)
precision
parameter is set to 2
, then #.###
modifier of tostring()
will not return close
value with more than 2 digits. Also, if current chart symbol close
value is big and tick size
of is only 2 decimal values, you will not get 3rd value when tostringing that number.So:
strategy(title="ScalpSMA30",shorttitle="ScalpSMA30",precision=3,overlay=true, calc_on_every_tick=true)
/// ....
if condition_long
alert("Go long (Entry is " + tostring(close), alert.freq_once_per_bar)
if condition_short
alert("Go short (Entry is " + tostring(close), alert.freq_once_per_bar)
Or
strategy(title="ScalpSMA30",shorttitle="ScalpSMA30",precision=3,overlay=true, calc_on_every_tick=true)
/// ....
if condition_long
alert("Go long (Entry is " + tostring(close, '#.###'), alert.freq_once_per_bar)
if condition_short
alert("Go short (Entry is " + tostring(close, '#.###'), alert.freq_once_per_bar)
is what you need.
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加