簡體   English   中英

Pine Script Strategy Alert - 如何添加到我的腳本?

[英]Pine Script Strategy Alert - How to add to my script?

我想弄清楚如何在我的策略腳本中添加“買入”和“賣出”警報。 我希望能夠在警報 window 中進行 select 買賣。我需要使用消息區域向 3commas 機器人發送消息。 所以我無法使用警報 window 中的消息區域。有沒有一種方法可以在交易視圖警報彈出窗口中輸入警報以顯示買賣,而不使用消息區域? 如圖所示?

電視警報

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Hawkreign

//@version=5
strategy(title="SGA Alert", overlay=true, default_qty_type = strategy.cash, default_qty_value = 100)

// Input options
src = input.source(close, title = "SGA" )

// Long and Short Conditions on the SGA
long = ta.rising(src, 1)
short = ta.falling(src, 1)

// Long and Short Memory
longmem = false
shortmem = false

// Memory Conditions
longmem := long ? true : short ? false : longmem[1]
shortmem := short ? true : long ? false : shortmem[1]

// Entry and Exit Variables
buy = long and not (longmem[1])
sell = short and not (shortmem[1])

// Long and Short Background color
bgcolor(buy ? color(color.rgb(11, 238, 18)): na)
bgcolor(sell ? color(color.rgb(134, 7, 7)): na)

// Long Entry and Exit
if (buy)
    strategy.entry("buy", strategy.long)
    strategy.close("sell")

// Short Entry and Exit
if (sell)
    strategy.entry("sell", strategy.short)
    strategy.close("buy")

plot(src)

如果您想為不同的訂單編寫自己的消息,您有幾種選擇:

  • 使用訂單 function 的alert_message參數。這是一個可選參數,當它用於“創建警報”對話框的“消息”字段時,它會替換{{strategy.order.alert_message}}占位符。
  • 使用alert function。

以下是alert_message參數的示例:

// Long Entry and Exit
if (buy)
    strategy.entry("buy", strategy.long, alert_message = "Let's go long!!!")
    strategy.close("sell", alert_message = "Let's close short!!!")

// Short Entry and Exit
if (sell)
    strategy.entry("sell", strategy.short, alert_message = "Let's go Short!!!")
    strategy.close("buy", alert_message = "Let's close long!!!")

使用此方法時,不要忘記在“創建警報”對話框的消息字段中設置{{strategy.order.alert_message}}占位符。

以下是alert function 的示例:

if (buy)
    strategy.entry("buy", strategy.long)
    strategy.close("sell")
    alert("Close all shorts and buy long!!!")
    
// Short Entry and Exit
if (sell)
    strategy.entry("sell", strategy.short)
    strategy.close("buy")
    alert("Close all longs and buy short!!!")

使用此方法時,您需要在“創建警報”的“條件”框中更改您的策略,然后選擇“Order fills and alert() function calls”或“Alert() function calls only”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM