金字塔决策交易系统

 找回密码
 

微信登录

微信扫一扫,快速登录

搜索
查看: 3600|回复: 3

编译错误,帮忙看下

[复制链接]

8

主题

21

帖子

21

积分

Rank: 1

等级: 新手上路

注册:
2021-9-1
曾用名:
发表于 2022-10-21 09:41 | 显示全部楼层 |阅读模式

from vnpy_ctastrategy import (    CtaTemplate,    StopOrder,    TickData,    BarData,    TradeData,    OrderData,    BarGenerator,    ArrayManager,)
from vnpy.trader.constant import Intervalclass TrendStrategy (CtaTemplate):  
    author = ""    am_daily = None    ema10 = 0.0    is_bull = None    is_bear = None    today_high = None    today_low = None    last_bar:BarData = None    daily_first_bar = None    last_open_interest = 0    def __init__(self, cta_engine, strategy_name, vt_symbol, setting):        """"""      
        super().__init__(cta_engine, strategy_name, vt_symbol, setting)        self.bg = BarGenerator(self.on_bar,interval=Interval.MINUTE)        self.am = ArrayManager()    def on_init(self):        """        Callback when strategy is inited.        """        self.write_log("策略初始化")        self.load_bar(20)    def on_start(self):        """        Callback when strategy is started.        """        self.write_log("策略启动")        self.put_event()    def on_stop(self):        """        Callback when strategy is stopped.        """        self.write_log("策略停止")        self.put_event()    def on_tick(self, tick: TickData):        """        Callback of new tick data update.        """        self.bg_daily.update_tick(tick)        self.bg.update_tick(tick)        def on_bar(self, bar: BarData):        """        Callback of new bar data update.        """        if self.last_bar is None:            # 第一次运行            self.daily_first_bar = bar            self.today_low = bar.low_price            self.today_high = bar.high_price            self.last_open_interest = bar.open_interest            self.last_bar = bar            return        elif bar.datetime.timestamp() - self.last_bar.datetime.timestamp() > 150:            # 当日第一条分钟线            # 处理前一日数据            self.today_high = max(self.today_high, bar.high_price)            self.today_low = min(self.today_low, bar.low_price)            self.last_open_interest = bar.open_interest            last_daily_bar = BarData(self.daily_first_bar.gateway_name,                                                             self.daily_first_bar.symbol,                                                             self.daily_first_bar.exchange,                                                             bar.datetime,                                                             Interval.DAILY,                                                             1.0,                                                             1.0,                                                             self.daily_first_bar.open_interest,                                                             self.daily_first_bar.open_price,                                                             self.today_high,
                                                                self.today_low,                                                             bar.close_price,)            self.am.update_bar(last_daily_bar)            self.ema10 = self.am.ema(10, False)            if bar.close_price > self.ema10: # 趋势处于多头                self.is_bull = True                self.is_bear = False            elif bar.close_price < self.ema10: # 趋势处于空头                self.is_bull = False                self.is_bear = True            else:                self.is_bull = False                self.is_bear = False            # 更新当日数据            self.daily_first_bar = bar            self.last_bar = bar            return        elif bar.datetime.timestamp() - self.daily_first_bar.datetime.timestamp() < 20: # 每日前20分钟不交易            self.last_bar = bar            return        else:            self.last_bar = bar        num_matched_buy = 0        num_matched_sell = 0        is_buy = False        is_sell = False        if self.is_bull: # 多头趋势            num_matched_buy = num_matched_buy + 1            if bar.close_price > self.daily_first_bar.open_price:                # 当前价高于开盘价                num_matched_buy = num_matched_buy + 1                    if bar.open_interest > self.last_open_interest:                num_matched_buy = num_matched_buy + 1            if num_matched_buy >= 3:                is_buy = True                is_sell = False        elif self.is_bear:            num_matched_sell = num_matched_sell + 1                    if bar.close_price < self.daily_first_bar.open_price:                # 当前价高于开盘价                num_matched_sell = num_matched_sell + 1                    if bar.open_interest < self.last_open_interest:                num_matched_sell = num_matched_sell + 1            if num_matched_sell >= 3:                is_buy = False                is_sell = True        else:            is_buy = False            is_sell = False        if self.pos == 0:            # 只有未持仓时才开仓            if is_buy:                self.buy(bar.close_price, 1)            elif is_sell:                self.short(bar.close_price, 1)        elif self.pos > 0:            # 判断是否平仓            if num_matched_buy < 3:                self.sell(bar.close_price, abs(self.pos))        elif self.pos < 0:            # 判断是否平仓            if num_matched_sell < 3:                self.cover(bar.close_price, abs(self.pos))        self.put_event()    def on_order(self, order: OrderData):        """        Callback of new order data update.        """        pass    def on_trade(self, trade: TradeData):        """        Callback of new trade data update.        """        self.put_event()    def on_stop_order(self, stop_order: StopOrder
):        """        Callback of stop order update.        """        pass


回复

使用道具 举报

21

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
FireScript
发表于 2022-10-21 09:47 | 显示全部楼层
本帖最后由 技术009 于 2022-10-21 09:49 编辑

请先处理能方便排查问题的格式,你这里所有缩进都没了。

另外 你这个在我们这也用不了 你这个库不是我们支持的。
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

37

主题

9972

帖子

6万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
wenarm
发表于 2022-10-21 09:51 | 显示全部楼层
本帖最后由 技术006 于 2022-10-21 13:31 编辑

抱歉,外部接口和PY基础语法等学习不在我们技术支持范畴内。技术支持只针对金字塔的py接口的相关问题,以及为相关接口应用时遇到的技术问题提供解决方案。

金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

8

主题

21

帖子

21

积分

Rank: 1

等级: 新手上路

注册:
2021-9-1
曾用名:
 楼主| 发表于 2022-10-21 10:09 | 显示全部楼层
技术006 发表于 2022-10-21 09:51
抱歉,外部接口不在我们技术支持范畴内。技术支持只针对金字塔的py接口的相关问题,以及为相关接口应用时遇 ...

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 微信登录

本版积分规则

手机版|小黑屋|上海金之塔信息技术有限公司 ( 沪ICP备13035422号 )

GMT+8, 2025-6-9 02:41 , Processed in 0.196423 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表