ainongchang 发表于 2020-8-12 15:11:16

以固定的价差平仓代码怎么写?

老师,
如果我的平仓条件是 lastentryprice±50个点时平仓,这行代码怎么写啊?
也就是说我入场后,只要价差达到50个点(不管正向负向)就平仓,而不是等到下一根K线的open才平

ainongchang 发表于 2020-8-12 15:25:36

麻烦版主解答一下,谢谢

Yuen_Lee 发表于 2020-8-13 09:33:27

If(Close >= lastentryprice + 50 or Close <= lastentryprice - 50)
{
    // 为使用A函数,需要关联交易账号
    If(A_BuyPosition >= 1)
    {
        Sell(x,x);
    }
    Else If(A_SellPosition >= 1)
    {
        BuyToCover(x,x);
    }
}

ainongchang 发表于 2020-8-13 10:08:15

Yuen_Lee 发表于 2020-8-13 09:33 static/image/common/back.gif
If(Close >= lastentryprice + 50 or Close = 1)
    {
        Sell(x,x);


close不是未来函数吗?sell(x,y)中y是填close吗?

Yuen_Lee 发表于 2020-8-14 10:31:49

不知道你的策略是否会涉及当前K线开仓又平仓,如果不会涉及,可以不用Close,而改为If(High >= lastentryprice + 50 or Low<= lastentryprice - 50) {}。
当前K线的Close应该是最新价,但你可以验证看看。Sell(x,y)中的y要根据你的策略来定,比如使用对手价、超价、停板价,或使用K线的低点Low来设。一般为保证成交,不将y设为Close。
页: [1]
查看完整版本: 以固定的价差平仓代码怎么写?