vn.py量化社区
By Traders, For Traders.
Member
avatar
加入于:
帖子: 10
声望: 0

统计开仓后的最高低最低价
(
intra_trade_hight
intra_trade_low
)
源码的写法是不是有误
统计范围包括了成交前那一根k线了

def on_15min_bar(self, bar: BarData):
""""""
self.cancel_all()

    am = self.am
    am.update_bar(bar)
    if not am.inited:
        return

    self.boll_up, self.boll_down = am.boll(self.boll_window, self.boll_dev)
    self.boll_mid = am.sma(self.boll_window)
    self.atr_value = am.atr(self.atr_window)

    if self.pos == 0:
        self.buy(self.boll_up, self.fixed_size, True)
        self.short(self.boll_down, self.fixed_size, True)

        self.intra_trade_high = bar.high_price
        self.intra_trade_low = bar.low_price

    elif self.pos > 0:
        if bar.close_price <= self.boll_mid:
            self.sell(bar.close_price - 5, abs(self.pos))

        self.intra_trade_high = max(self.intra_trade_high, bar.high_price)
        self.intra_trade_low = bar.low_price

        self.long_sl = self.intra_trade_high - self.atr_value * self.atr_multiplier
        self.sell(self.long_sl, abs(self.pos), True)

    elif self.pos < 0:
        if bar.close_price >= self.boll_mid:
            self.cover(bar.close_price + 5, abs(self.pos))

        self.intra_trade_low = min(self.intra_trade_low, bar.low_price)
        self.intra_trade_high = bar.high_price

        self.short_sl = self.intra_trade_low + self.atr_value * self.atr_multiplier
        self.cover(self.short_sl, abs(self.pos), True)

    self.put_event()
Administrator
avatar
加入于:
帖子: 2609
声望: 113

是包含的,因为你无法确认这跟K线发出去的停止单,在下一根是否一定会触发

© 2015-2019 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3