[英]About limit of strategy.exit
I'm making a DCA strategy using pyramids.我正在使用金字塔制定 DCA 策略。
I have used strategy.close_all command to close positions so far.到目前为止,我已经使用 strategy.close_all 命令平仓。
But this brings me a risk as the next candle of the signal will be alerted.但这给我带来了风险,因为信号的下一个蜡烛将被警告。
So I use strategy.exit command.所以我使用 strategy.exit 命令。 Here's a problem.
这是一个问题。
Because I make a pyramiding strategy, multiple orders are opened in one transaction, so when I use the strategy.exit command, an alert is generated as much as the number of opened orders.因为我做的是金字塔策略,在一个事务中打开了多个订单,所以当我使用 strategy.exit 命令时,会产生与打开的订单数量一样多的警报。
Is there a way to receive an alert only once when the limit value corresponding to the condition is reached while using strategy.exit?有没有办法在使用 strategy.exit 时达到与条件对应的限制值时只接收一次警报?
Recently, I tried to get only one alert using plot, but there was a problem.最近,我尝试使用 plot 仅获得一个警报,但出现了问题。
Please advise.请指教。
// 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)
You could make custom a condition你可以定制一个条件
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.