【问题标题】:Technical Analyis (MACD) for crpto trading加密交易的技术分析 (MACD)
【发布时间】:2021-05-12 15:24:23
【问题描述】:

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

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

非常感谢!

【问题讨论】:

    标签: algorithmic-trading cryptocurrency technical-indicator


    【解决方案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'])
    

    【讨论】:

      【解决方案2】:

      据我所知,大多数或所有技术指标公式都依赖于相同大小的条形来产生准确且有意义的结果。您必须进行一些数据转换。这是一个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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-06
        • 2022-06-23
        相关资源
        最近更新 更多