【问题标题】:Problem calculating RSI from the Binance node API从币安节点 API 计算 RSI 的问题
【发布时间】:2020-10-07 15:24:24
【问题描述】:

我用 javascript (Node) 编写了一个程序,该程序应该使用 Binance api 计算 RSI。

唯一的问题是我的程序没有计算“真正的”RSI。例如,如果我将我的经期设置为 14 天,如公式所示 - 我得到的 RSI 值等于 ~28,而实际 RSI 为 38。

如果我更改周期并将其设置为 20,我会得到一个非常接近真实的 RSI,我的是 39,而真实的是 38。

我想不通。我做错了什么。有什么建议吗?

这是我的代码:

const binance = require('node-binance-api')().options({
        APIKEY: 'xxx',
        APISECRET: 'xxx',
        useServerTime: true,
        test: true // True = SandboxMode
    });

    /* VARIABLES */
    let listClose = [];
    let changeUp = 0;
    let changeDown = 0;
    let last_closeHigh = 0;
    let last_closeLow = 0;
    let current_time = Date.now();
    let period = 20;

    function calculateRSI() {
        console.log("Generating RSI");
        binance.candlesticks("ETHBTC", "1d", (error, ticks, symbol) => {
            for (i = 0; i < ticks.length; i++) {
                let last_tick = ticks[i];
                let [time, open, high, low, close, volume, closeTime, assetVolume, trades, buyBaseVolume, buyAssetVolume, ignored] = last_tick;
                listClose.push(close);
                if (i == ticks.length -1 ) {
                    for (x = 0; x < ticks.length; x++) {
                        previous_close = (parseFloat(listClose[x-1]));
                        current_close = (parseFloat(listClose[x]));
                        // HIGH
                        if (current_close > previous_close) {
                            upChange = current_close - previous_close;
                            changeUp += upChange;
                            if (x == ticks.length -1) {
                                last_closeHigh = current_close - previous_close;
                            }
                        }
                        // LOW
                        if (previous_close > current_close) {
                            downChange = previous_close - current_close;
                            changeDown += downChange;
                            if (x == ticks.length - 1) {
                                last_closeLow = previous_close - current_close;
                            }
                        }
                        if (x == ticks.length-1) {
                            AVGHigh = changeUp / period;
                            AVGLow = changeDown / period;
                            Upavg = (AVGHigh * (period -1) + last_closeHigh) / (period);
                            Downavg = (AVGLow * (period -1) + last_closeLow) / (period);
                            RS = Upavg / Downavg;
                            RSI = (100 - (100 / (1 + RS)));
                            console.log(RSI);
                            return RSI;
                        }
                    }
                }
            }
        }, {
            limit: period,
            endTime: current_time
        });
    }
calculateRSI();

【问题讨论】:

  • previous_close = (parseFloat(listClose[x-1])); 看起来很粗略,因为 x 可能是 0
  • 您将如何修复该功能?提前致谢
  • @DRus 兄弟你找到解决办法了吗?

标签: javascript node.js algorithm api binance


【解决方案1】:

很抱歉这么晚才跳...但是这样做的原因是使用沙盒。

Binance Sandbox 很糟糕,永远不应该使用,它会给出错误的值。

【讨论】:

    猜你喜欢
    • 2016-11-23
    • 2017-11-26
    • 2019-11-22
    • 1970-01-01
    • 2023-03-13
    • 2021-07-22
    • 1970-01-01
    • 2018-10-16
    • 2021-06-29
    相关资源
    最近更新 更多