Pinescript Alert()策略问题

发布于 2025-01-23 13:38:28 字数 14 浏览 0 评论 0原文

hellow亲爱的脚本

Hellow dear scripters ????

i have a question.

in my custom strategy i am having issues with the closing trade condition alert. my current open trade allert is working ok but the exit strategy i am having issues with declaring a exit condition, because my exit conditions are inside the (strategy.exit and strategy.enter)

here is a part of my code:

// Specify Entry Conditions
longEntry = fanUpTrend and bullishPinBar and bullPierce
shortEntry = fanDnTrend and bearishPinBar and bearPierce

// Long Entry Function
enterlong() =>
    risk = usr_risk * 0.01 * strategy.equity
    stopLoss = low[1] - atr[1] * atr_mult
    entryPrice = high[1]
    units = risk / (entryPrice - stopLoss)
    strategy.entry('long', strategy.long, 2000, units, stop=entryPrice)
    strategy.exit('exit long', from_entry='long', trail_points=20, trail_offset=10)


// Short Entry Function
entershort() =>
    risk = usr_risk * 0.01 * strategy.equity
    stopLoss = high[1] + atr[1] * atr_mult
    entryPrice = low[1]
    units = risk / (stopLoss - entryPrice)
    strategy.entry('short', strategy.short, 2000, units, stop=entryPrice)
    strategy.exit('exit short', from_entry='short', trail_points=20, trail_offset=10)

long_open_message = input('Long Open Message')
short_open_message = input('Short Open Message')
long_close_message = input('Long Close Message')
short_close_message = input('Short Close Message')


// Execute Long Entry
if longEntry
    enterlong()
    alertsyntax_golong = long_open_message
    alert(message=alertsyntax_golong, freq=alert.freq_once_per_bar_close)

// Execute Short Entry
if shortEntry
    entershort()
    alertsyntax_goshort = short_open_message
    alert(message=alertsyntax_goshort, freq=alert.freq_once_per_bar_close)

so here i can easyly get an alert for the entry but my exit conditios are, inside the strat enter and strat exit how can i declare a variable or function to be able to send alert like :

if shortEntry
alert()......

type of code.

What i am trying to achieve is that i need to declare somekind of variable to be able get define the strategy.exit and also my "units" in the strategy.enter and also "stop=entryPrice"
thanks again

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

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

发布评论

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

评论(1

我的奇迹 2025-01-30 13:38:28

您可以将警报消息放置为参数:(请参阅Pinescript语言参考手册:straging.close.close(ID,何时,评论,QTY,QTY_PERCENT,alter_message)→void

我假设您想通过警报消息传递变量值?

为此,您将使用命令:str.tostring(变量)。
这是一个示例:
strategy.close('atv_le',alter_message ='“ pair”:“ ethusdt”,“ signalid”:“ long ethusdt”,“ exchange”:“ binance”,“ forceangeAgeAccount”长”,“类型”:“退出”,“ ordertype”:“市场”,“位置”:“ '+str.tostring(variable)+'”)

请参见Pine Script语言参考手册以获取有关str.tostring命令的更多详细信息。希望这有帮助!

You can place alert messages as a parameter: (See PineScript language reference manual: strategy.close(id, when, comment, qty, qty_percent, alert_message) → void

I assume you want to pass a variable value via the alert message?

For that, you would use the command: str.tostring(variable). You must place the argument in inverted commas and + signs in order for your code to compile.
Here is an example:
strategy.close('ATV_LE', alert_message='"pair":"ETHUSDT","signalId":"long-ETHUSDT","exchange":"binance","exchangeAccountType":"futures","side":"long","type":"exit","orderType":"market","positionSizePercentage":"'+str.tostring(variable)+'"')

See the Pine Script Language Reference Manual for more details on what str.tostring command is capable of. Hope this helps!

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