策略.position_size与{{strategy. order.alert_message}}一起使用时提醒错误的值
是否有任何方法可以从pine脚本内部访问{{straging.market_position_size}}来生成策略警报以创建帖子消息? 我尝试使用pine脚本变量策略。position_size在脚本内部生成帖子消息,以便我可以在“创建警报”对话框的“消息”框中使用{{strategy.order.alert_message}},如下所示:
这是一个简单的示例策略,说明我试图将邮寄消息组装成警报:
//@version=5
// Webhook message test
strategy("Webhook test", overlay=true, initial_capital=1000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10)
alertID =""
// Limit processing time span
startDate = input.time(title="Start Date", defval=timestamp("30 Jun 2022 06:00:00 GMT-4"))
endDate = input.time(title="End Date", defval=timestamp("01 Jan 2024 06:00:00 GMT-4"))
BetweenDates = startDate <= time and time <= endDate
timeStamp = str.tostring(year, '0000')+str.tostring(month, '00')+str.tostring(dayofmonth, '00')+str.tostring(hour, '00')+str.tostring(minute, '00')
POSTmessage = '"Symbol": "'+syminfo.ticker+'", "timestamp": "'+timeStamp+'"'
EntryCondition = BetweenDates and ta.crossover(close, ta.sma(close,3))
ExitCondition = BetweenDates and ta.crossunder(close,ta.sma(close,3))
if EntryCondition
alertID := str.tostring(timeStamp+syminfo.ticker)
POSTmessage := POSTmessage +', "order_id": "'+alertID+', "order_action": "buy"'
if ExitCondition
POSTmessage := POSTmessage +', "order_id": "'+alertID+', "order_action": "sell"'
//Order execution and alert
strategy.entry(id=alertID, direction=strategy.long, when = EntryCondition, alert_message='{'+POSTmessage+', "order_contratcs": '+str.tostring(strategy.position_size)+'}')
strategy.close(id=alertID, when = ExitCondition, alert_message='{'+POSTmessage+', "order_contratcs": '+str.tostring(strategy.position_size)+'}')
//paste into in [ Creat Alert > Message ] box:
// {{strategy.order.alert_message}}
但是,当警报弹出时,它在“ order_contratcs”字段中显示了agation.tration.sectry executions中的零数量从以前的策略中固定。看来它实际上报告了{{strategy.prev_market_position_size}}}},而我希望它报告{{strategy.market_position_size}}。有什么方法可以从脚本内部执行此操作?
Is there any way to access {{strategy.market_position_size}} from inside pine script to generate a strategy alert in order to creat a POST message?
I tried using the pine script variable strategy.position_size inside the script to generate a POST message so that I can use {{strategy.order.alert_message}} in the Create Alert dialog's "Message" box as shown below:
This is a simple example strategy demonstrating how I'm trying to assemble the POST message as an alert:
//@version=5
// Webhook message test
strategy("Webhook test", overlay=true, initial_capital=1000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10)
alertID =""
// Limit processing time span
startDate = input.time(title="Start Date", defval=timestamp("30 Jun 2022 06:00:00 GMT-4"))
endDate = input.time(title="End Date", defval=timestamp("01 Jan 2024 06:00:00 GMT-4"))
BetweenDates = startDate <= time and time <= endDate
timeStamp = str.tostring(year, '0000')+str.tostring(month, '00')+str.tostring(dayofmonth, '00')+str.tostring(hour, '00')+str.tostring(minute, '00')
POSTmessage = '"Symbol": "'+syminfo.ticker+'", "timestamp": "'+timeStamp+'"'
EntryCondition = BetweenDates and ta.crossover(close, ta.sma(close,3))
ExitCondition = BetweenDates and ta.crossunder(close,ta.sma(close,3))
if EntryCondition
alertID := str.tostring(timeStamp+syminfo.ticker)
POSTmessage := POSTmessage +', "order_id": "'+alertID+', "order_action": "buy"'
if ExitCondition
POSTmessage := POSTmessage +', "order_id": "'+alertID+', "order_action": "sell"'
//Order execution and alert
strategy.entry(id=alertID, direction=strategy.long, when = EntryCondition, alert_message='{'+POSTmessage+', "order_contratcs": '+str.tostring(strategy.position_size)+'}')
strategy.close(id=alertID, when = ExitCondition, alert_message='{'+POSTmessage+', "order_contratcs": '+str.tostring(strategy.position_size)+'}')
//paste into in [ Creat Alert > Message ] box:
// {{strategy.order.alert_message}}
However, when the alert pops up it shows zero quantity in the "order_contratcs" field for strategy.entry executions since the position is flat from the previous strategy.close. It seems that it actually reports {{strategy.prev_market_position_size}} whereas I would like it to report {{strategy.market_position_size}}. Is there any way to do this from inside the script?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在警报消息中使用
{{strategy.position_size}}
占位符。You can use the
{{strategy.position_size}}
placeholder in your alert message.