策略.position_size与{{strategy. order.alert_message}}一起使用时提醒错误的值

发布于 2025-02-11 22:13:34 字数 2290 浏览 1 评论 0原文

是否有任何方法可以从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:

Create Alert dialog box

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?

Alert pop up on strategy.entry

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小草泠泠 2025-02-18 22:13:34

您可以在警报消息中使用{{strategy.position_size}}占位符。

//Order execution and alert
strategy.entry(id=alertID, direction=strategy.long, when = EntryCondition, alert_message='{'+POSTmessage+', "order_contratcs": '+ '{{strategy.position_size}}'+'}')
strategy.close(id=alertID, when = ExitCondition, alert_message='{'+POSTmessage+', "order_contratcs": '+'{{strategy.position_size}}'+'}')

You can use the {{strategy.position_size}} placeholder in your alert message.

//Order execution and alert
strategy.entry(id=alertID, direction=strategy.long, when = EntryCondition, alert_message='{'+POSTmessage+', "order_contratcs": '+ '{{strategy.position_size}}'+'}')
strategy.close(id=alertID, when = ExitCondition, alert_message='{'+POSTmessage+', "order_contratcs": '+'{{strategy.position_size}}'+'}')

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文