簡體   English   中英

關於 strategy.exit 的限制

[英]About limit of strategy.exit

我正在使用金字塔制定 DCA 策略。

到目前為止,我已經使用 strategy.close_all 命令平倉。

但這給我帶來了風險,因為信號的下一個蠟燭將被警告。

所以我使用 strategy.exit 命令。 這是一個問題。

因為我做的是金字塔策略,在一個事務中打開了多個訂單,所以當我使用 strategy.exit 命令時,會產生與打開的訂單數量一樣多的警報。

有沒有辦法在使用 strategy.exit 時達到與條件對應的限制值時只接收一次警報?

最近,我嘗試使用 plot 僅獲得一個警報,但出現了問題。

請指教。


// STOCHASTIC RSI //

src = input(close, title="RSI Source", group='RSI SETTINGS')
smoothK = input.int(3, "K", minval=1, group='RSI SETTINGS')
smoothD = input.int(3, "D", minval=1, group='RSI SETTINGS')
lengthRSI = input.int(14, "RSI Length", minval=1, group='RSI SETTINGS')
lengthStoch = input.int(14, "Stochastic Length", minval=1, group='RSI SETTINGS')
rsi1 = ta.rsi(src, lengthRSI)
OverBought = input.int(80, "OverBought", minval=1, group='RSI SETTINGS')
OverSold = input.int(20, "OverSold", minval=1, group='RSI SETTINGS')
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = ta.sma(k, smoothD)

co = ta.crossover(k,d)
cu = ta.crossunder(k,d)

r_close = request.security(syminfo.tickerid, str.tostring(tic), close, lookahead=barmerge.lookahead_off)

last_entry_price = strategy.opentrades.entry_price(strategy.opentrades - 1)
last_entry_size  = strategy.opentrades.size(strategy.opentrades - 1)

next_price_long  =  last_entry_price * (1 - min_step) 
next_price_size  =  last_entry_size * (1 + martingale)

TP               = strategy.position_avg_price * (1 + min_profit)

// STRATEGY ORDER //

if (afterStartDate)
    if (na(strategy.position_avg_price)) and (co and k < OverSold)
        strategy.order("Long", strategy.long, qty=base_order/r_close, limit=r_close, comment="Entry")
        
    if strategy.position_size > 0 and r_close < next_price_long and strategy.opentrades < max_order
        strategy.order("Long", strategy.long, qty=next_price_size, limit=r_close, comment="Step_" + str.tostring(strategy.opentrades + 1))
        
strategy.exit("Close Long", "Long", limit = TP, comment="close long")

plot(TP, style=plot.style_cross, linewidth=6, color=color.new(color.fuchsia, 0), editable=false)

你可以定制一個條件

var bool is_TP_reached = false

if high >= TP
   is_TP_reached := true

if ta.change(is_TP_reached)
   strategy.exit("Close Long", "Long", limit = TP, ...)

// If short or any other condition to reset is_TP_reached
if strategy.position_size == 0
   is_TP_reached := false

暫無
暫無

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

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