Pine script Can';t向string-pine脚本添加值

Pine script Can';t向string-pine脚本添加值,pine-script,Pine Script,我试图向消息字符串中添加一些值,但使用tostring方法在第23行(buyMessage行)上出现错误。有人能帮我吗 错误: 无法使用参数(series[bool],title=literal字符串,message=series[string])调用“alertcondition”;可用重载:alertcondition(系列[bool],常量字符串,常量字符串,字符串)=>void;alertcondition(,常量字符串,常量字符串,字符串)=>void 代码: 研究(“研究1”) //

我试图向消息字符串中添加一些值,但使用tostring方法在第23行(buyMessage行)上出现错误。有人能帮我吗

错误:

无法使用参数(series[bool],title=literal字符串,message=series[string])调用“alertcondition”;可用重载:alertcondition(系列[bool],常量字符串,常量字符串,字符串)=>void;alertcondition(,常量字符串,常量字符串,字符串)=>void

代码:

研究(“研究1”)
//指标
ema200=ema(关闭,200)
atr=atr(14)
//密谋
绘图(atr,title='atr',color=color.red)
杠杆率=四舍五入(1/(atr/收盘*100*2))
金额=(杠杆*100)-100
buyMessage='binanceFutures(BTCUSD){exchangeSettings(杠杆='+tostring(杠杆)+');aggressive(边=买入,金额='+tostring(金额)+');stopOrTakeProfit(边=卖出,金额='+tostring(金额)+',tp='+tostring(atr*2)+',sl='+tostring(atr)+');'
sellMessage='binanceFutures(BTCUSD){exchangeSettings(杠杆='+tostring(杠杆)+';aggressive(边=卖出,金额='+tostring(金额)+');stopOrTakeProfit(边=买入,金额='+tostring(金额)+',tp='+tostring(atr*2)+',sl='+tostring(atr)+';}'
//警报
alertcondition(close>ema200,title='Buy',message=buyMessage)
alertcondition(关闭
消息参数必须是常量(固定文本)。
您可以在函数的描述中了解这一点

您的消息字符串不是常量。
它们是
系列
,因为它们包含变量
杠杆
,这是一个可变变量

当您使用固定文本时,它将编译,如下所示:

//@version=4
study("study1")

// Indicators
ema200 = ema(close, 200)
atr = atr(14)

// Plot
plot(atr, title='atr', color=color.red)

leverage = round(1 / (atr / close * 100 * 2))
amount = (leverage * 100) - 100


// buyMessage  = 'binanceFutures(BTCUSD) { exchangeSettings(leverage=' + tostring(leverage) + '); aggressive(side=buy, amount=' + tostring(amount) + '); stopOrTakeProfit(side=sell, amount=' + tostring(amount) +', tp=' + tostring(atr * 2) + ', sl=' + tostring(atr) +');}'
// sellMessage = 'binanceFutures(BTCUSD) { exchangeSettings(leverage=' + tostring(leverage) + '); aggressive(side=sell, amount=' + tostring(amount) + '); stopOrTakeProfit(side=buy, amount=' + tostring(amount) +', tp=' + tostring(atr * 2) + ', sl=' + tostring(atr) +');}'

buyMessage  = "buyMessage Fixed Text"
sellMessage = "sellMessage Fixed Text"

// Alerts
alertcondition(close > ema200, title='Buy', message=buyMessage)
alertcondition(close < ema200, title='Sell', message=sellMessage)
/@version=4
研究(“研究1”)
//指标
ema200=ema(关闭,200)
atr=atr(14)
//密谋
绘图(atr,title='atr',color=color.red)
杠杆率=四舍五入(1/(atr/收盘*100*2))
金额=(杠杆*100)-100
//buyMessage='binanceFutures(BTCUSD){exchangeSettings(杠杆='+tostring(杠杆)+');aggressive(边=买入,金额='+tostring(金额)+');stopOrTakeProfit(边=卖出,金额='+tostring(金额)+',tp='+tostring(atr*2)+',sl='+tostring(atr)+');'
//sellMessage='binanceFutures(BTCUSD){exchangeSettings(杠杆='+tostring(杠杆)+';aggressive(边=卖出,金额='+tostring(金额)+');stopOrTakeProfit(边=买入,金额='+tostring(金额)+',tp='+tostring(atr*2)+',sl='+tostring(atr)+';}'
buyMessage=“buyMessage固定文本”
sellMessage=“sellMessage固定文本”
//警报
alertcondition(close>ema200,title='Buy',message=buyMessage)
alertcondition(关闭
嗯。。。除了标准变量{{ticker}}{{close}}{{open}}等之外,实际上还可以动态使用您自己的变量。 有一个小的解决方法:)

您需要绘制您的值并将其用于alertcondition:{{plot_xx} 诀窍是在不破坏比例的情况下绘制值。这样做:

plotchar((isOk)?1234:na, "entry multiplier", "", location.top)
之后,您可以通过绘图编号对其进行引用,它将正常工作:)

编辑:2021年2月5日 现在甚至可以将警报与动态文本一起使用!有关更多详细信息,请查看此博客,它可能会解决所有警报问题:)

好的,谢谢,没有其他方法可以通过“alertcondition”发送可变标签消息?您只能在alerts中使用。自定义变量不可能。但是,可能有解决方案,但仅适用于数值。请参阅的答案中的链接。特别是第二个链接。很好的解决方法!:)
plotchar((isOk)?1234:na, "entry multiplier", "", location.top)