如果我按照代码在同一天建仓,如何在一天结束时关闭交易? [英] How to close the trade at the end of the day if I took a position in the same day according to the code?

查看:62
本文介绍了如果我按照代码在同一天建仓,如何在一天结束时关闭交易?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码运行正常,但在一天结束时,即使 check1 = diplus >= 13 也必须平仓.意味着即使 +DMI 不小于 13,仓位也必须平仓

Code is working fine but at the end of the day, the position has to exit even though check1 = diplus >= 13. Means the position has to exit even though +DMI is not less than 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)

谢谢,等待回复.

推荐答案

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

Code looks fine but i suggest to add timezone to timestamp like this

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

这篇关于如果我按照代码在同一天建仓,如何在一天结束时关闭交易?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆