0

我在实时市场中使用当日高点作为止损,它工作正常,但是当市场创出新高并重新启动图表时,它会为已经关闭的交易移动止损。所以使用 var 并制作计数器,但仍然会发生同样的事情,请指导 thx

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
 
//@version=4
strategy("new indicator",overlay=true,process_orders_on_close=true)
 
//Store last Daily high in a variable
var D_High=0.0
var shortTake=0.0
 
//ema input
ema_source=input(title="Ema Source",type=input.source,defval=close)
ema_len=input(title="Ema Length",type=input.integer,defval=5)
 
rsi_vlaue=rsi(close,14)
 
//input source
 
ema_value=ema(ema_source,ema_len)
 
//condition for sell 
 
 
sell=crossunder(close,ema_value) and rsi_vlaue>60
 
 
// Submit entry orders
if sell
    strategy.order(id="ES", long=false)
 
 
// Submit stops based on daily high
if strategy.position_size < 0
    strategy.exit(id="XS LL", stop=D_High ,limit=shortTake )
// market close 
strategy.close_all(when=hour==15 and minute==20)
 
//stop loss and take profit
D_High := security(syminfo.tickerid, 'D', high, lookahead=barmerge.lookahead_on)
shortTake := strategy.position_avg_price - ((D_High - strategy.position_avg_price) * 5)
//plot data
plot(series=strategy.position_size < 0 ? D_High : na, style=plot.style_circles, color=color.red, linewidth=2, title="Daily High Stop")
plot(strategy.position_size < 0 ? shortTake : na, style=plot.style_circles, color=color.green, linewidth=2, title="Short Take Profit")
plot(ema_value,color=color.new(color.blue,30),linewidth=2)

4

0 回答 0