如题,如果想分批离场,代码应该如何写?
我的代码如下,希望能帮到遇到相同问题的朋友。
If(MarketPosition == 1 )
{
//判断是否要主动止盈半仓
Numeric TakeProfitPrice = OpenPrice + 2*(Abs(OpenPrice - DayOpenPrice)); //计算止盈价位
if(High > TakeProfitPrice And TakeProfit == False)
{
//以开仓价与当天开盘价的幅度的2倍作为止盈位
CloseLot = Max(IntPart(Lots/2),1); //计算止盈仓位,至少1手
If(CloseLot > 0)
{
Sell(CloseLot,Max(TakeProfitPrice,Open));
TakeProfit = True; //标记止盈过,用于防止重复止盈
Commentary("平仓原因 :止盈");
}
}
If(CloseLongCondition == True)
{
Sell(0,Open); //平仓时,平仓手数是0,表示全部仓位平掉,就不需要是不是判断是否止盈过了
Commentary("平仓原因 :离场");
}
}
已经解决,感谢!
代码: https://bbs.tbquant.net/thread/20250828162849595705
讲解视频: https://video.tbquant.net/ 答疑板块 大概就这个代码日期附近的,你找找 网站又打不开了....
