用于加密货币交易的技术分析 (MACD)

时间:2021-02-09 00:55:41

标签: algorithmic-trading cryptocurrency technical-indicator

背景: 我写了一个加密交易机器人来获取乐趣和利润。 到目前为止,它连接到交易所并获取流媒体价格数据。 我正在使用此价格来创建技术指标 (MACD)。 一般对于MACD,建议使用26、12和9的收盘价。 但是,对于我的交易策略,我计划使用 26、12 和 9 分钟的数据。

问题: 我在一分钟内收到多个(比如 10 个)价格变动。 我是否只是简单地将它们平均并将时间四舍五入到下一分钟(因此它们都属于同一分钟)?或者有更好的方法来处理这个问题。

非常感谢!

2 个答案:

答案 0 :(得分:1)

我就是这样处理的。流数据以 < 1 秒的周期出现。代码在流期间检查新的低点和高点并构建蜡烛图。可能很难看,因为我不是受过训练的开发人员,但它确实有效。

根据您想要的蜡烛周期调整“...round('20s')”和“if dur > 15:”。

def on_message(self, msg):
   
        df = pd.json_normalize(msg, record_prefix=msg['type'])
        df['date'] = df['time']
        df['price'] = df['price'].astype(float)
        df['low'] = df['low'].astype(float)

           for i in range(0, len(self.df)):
            if i == (len(self.df) - 1):
                self.rounded_time = self.df['date'][i]
                self.rounded_time = pd.to_datetime(self.rounded_time).round('20s')
                self.lhigh = self.df['price'][i]
                self.lhighcandle = self.candle['high'][i]
                self.llow = self.df['price'][i]
                self.lowcandle = self.candle['low'][i]
                self.close = self.df['price'][i]

        if self.lhigh > self.lhighcandle:
            nhigh = self.lhigh

        else:
            nhigh = self.lhighcandle

        if self.llow < self.lowcandle:
            nlow = self.llow

        else:
            nlow = self.lowcandle

        newdata = pd.DataFrame.from_dict({
            'date': self.df['date'],
            'tkr': tkr,
            'open': self.df.price.iloc[0],
            'high': nhigh,
            'low': nlow,
            'close': self.close,
            'vol': self.df['last_size']})

        self.candle = self.candle.append(newdata, ignore_index=True).fillna(0)

        if ctime > self.rounded_time:
            closeit = True

        self.en = time.time()

        if closeit:
            dur = (self.en - self.st)
            if dur > 15:
                self.st = time.time()
                out = self.candle[-1:]
                out.to_sql(tkr, cnx, if_exists='append')

                dat = ['tkr', 0, 0, 100000, 0, 0]
                self.candle = pd.DataFrame([dat], columns=['tkr', 'open', 'high', 'low', 'close', 'vol'])

答案 1 :(得分:1)

据我所知,大多数或所有技术指标公式都依赖于相同大小的柱线来产生准确且有意义的结果。您必须进行一些数据转换。下面是一个 aggregation technique 示例,它使用量化将所有条形调整为统一大小。它将小条形尺寸转换为较大的条形尺寸;例如秒到分钟柱。

// C#, see link above for more info

quoteHistory
  .OrderBy(x => x.Date)
  .GroupBy(x => x.Date.RoundDown(newPeriod))
  .Select(x => new Quote
    {
       Date = x.Key,
       Open = x.First().Open,
       High = x.Max(t => t.High),
       Low = x.Min(t => t.Low),
       Close = x.Last().Close,
       Volume = x.Sum(t => t.Volume)
    });

有关指标和相关工具,请参阅 Stock.Indicators for .NET