例如 盈利达到5%之后,从最大值回撤2%就平仓的写法。
下面是 持有多头时候的写法,回测的结果不对,又没有找到问题在哪里,请大家指教,谢谢
percent = bar.close_price / self.buy_price - 1
if percent > self.win_stop and self.win_tag == 0:
self.win_price = bar.close_price
self.win_tag = 1
if self.win_tag == 1 and self.win_price < bar.close_price:
self.win_price = bar.close_price
if self.win_tag == 1 \
and (self.win_price - bar.close_price) / self.win_price > self.win_stop:
self.sell(bar.close_price, abs(self.pos))
self.win_tag = 0