如何设置具有特定小数位的交易视图警报?

How to setup tradingview alert with specific decimals?

我正在尝试在满足我的条件时在 tradingview 中设置警报。

我的问题是逗号后只有 2 个数字,我需要其中 3 个。

我已经尝试了一些东西,但我无法弄清楚它是否能正常工作。

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)
  1. 您需要为策略属性设置正确的精度(精度 = 3):
strategy(title="ScalpSMA30",shorttitle="ScalpSMA30", precision = 3, overlay=true, calc_on_every_tick=true)
  1. precision参数设置为2时,tostring()#.###修饰符将不会return close值大于2 位数。 此外,如果当前图表交易品种 close 值很大且 tick size 只有 2 个十进制值,则在串接该数字时您将不会获得第三个值。

所以:

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)

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)

就是你需要的。