如果我根据代码在同一天持仓,如何在当天结束交易



代码运行良好,但在一天结束时,即使check1=dipls>=13.意味着即使+DMI不小于13 ,该位置也必须退出

//@version=4
strategy("My Script", overlay = true)
ema20 = ema(close, 20) 
ema200 = ema(close, 200)
len = input(14, minval=1, title="DI Length")
lensig = input(14, title="ADX Smoothing", minval=1, maxval=50)
[diplus, diminus, adx] = dmi(len, lensig)
plot(diplus, color=color.blue, title="+DI")
check = diplus > 13
check1 = diplus < 13
ema200_long = ema200 < close
ema200_short = ema200 > close
startTime = timestamp(2021, 03, 11, 09, 15)
endTime = timestamp(2021, 05, 25, 12, 30)

//long
if time >= startTime and time <=endTime and ema200_long
strategy.entry("long", strategy.long, 100.0, when = check)

strategy.close("long", qty_percent = 100, when = check1)    


plot(ema200)
plot(ema20)

谢谢,等待答复。

代码看起来不错,但我建议像这个一样将时区添加到时间戳中

timestamp("GMT+1", 2021, 05, 25, 12, 30)

这样的东西可以在中工作

strategy.close("short" )
strategy.close("long" )

最新更新