Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue using getXMinuteMA as custom indicator #106

Open
rabinage opened this issue Mar 13, 2021 · 3 comments
Open

Issue using getXMinuteMA as custom indicator #106

rabinage opened this issue Mar 13, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@rabinage
Copy link
Contributor

When using a custom indicator with getXMinuteMA() I get some weird results.

// Config
{
    "data": [
        {
            "exchanges": [
                "Poloniex"
            ],
            "tradeTotalBtc": 1,
            "warmUpMin": 0,
            "strategies": {
                "SMATest": {
                    "interval": 5,
                    "pair": "USDC_USDT",
                    "candleSize": 5
                }
            }
        }
    ]
}

// Indicator
import { TechnicalStrategy, TechnicalStrategyAction } from "./TechnicalStrategy";

export default class SMATest extends TechnicalStrategy {
    constructor(options) {
        super(options)
        this.addIndicator("sma40", "SMA", { short: 40, long: 41 } as TechnicalStrategyAction)
    }

    protected checkIndicators() {
        this.computeCustomIndicator("custom-sma40", this.getXMinuteMA(5, 40, 0)).then((data) => {
            const sma = this.indicators.get("sma40").getShortLineValue()

            if (data !== -1) {
                const custom_sma = this.customIndicators.get("custom-sma40")
                this.plotData.plotMark({
                    "custom_sma": custom_sma
                })
            }
            this.plotData.plotMark({
                "sma": sma,
            })
        })
    }
}

wb_custom_sma

@Ekliptor
Copy link
Owner

Ekliptor commented Mar 13, 2021

How did you import your backtesting candles? From Poloniex trades manually? Do they have correct timestamps in MongoDB? In most cases it's a timestamp issue. If not a bug in getXMinuteMA() for me to fix

Also did you enable serverConfig:backtest:cacheCandleswhich can distort the results?

edit for reference: try to log valuesInand valueinside the function for a few candles and see if passed in candles are correct https://github.com/Ekliptor/WolfBot/blob/master/src/Strategies/Mixins/TechnicalAnalysis.ts#L243

@rabinage
Copy link
Contributor Author

rabinage commented Mar 14, 2021

How did you import your backtesting candles? From Poloniex trades manually? Do they have correct timestamps in MongoDB? In most cases it's a timestamp issue. If not a bug in getXMinuteMA() for me to fix

I'm using the Backtesting UI so the candle data is imported automatically. I guess the candle data should be the same then?

Also did you enable serverConfig:backtest:cacheCandleswhich can distort the results?

No it's not enabled. I disable it just in case.

edit for reference: try to log valuesInand valueinside the function for a few candles and see if passed in candles are correct https://github.com/Ekliptor/WolfBot/blob/master/src/Strategies/Mixins/TechnicalAnalysis.ts#L243

SMA and getXMinuteMA is getting it's candle data in two different ways. The latter is using the CandleBatcher which returns a slightly different set of candles on each addCandle iteration vs AbstractIndicator.addCandle. Check the comparison below. NOTE, I had to revert the candles coming from the CandleBatcher.

Thank you for the taking the time!

EDIT: Left side is the SMA (the working one)
candles_compare

@Ekliptor Ekliptor added the bug Something isn't working label Mar 16, 2021
@Ekliptor
Copy link
Owner

its definitely a bug. I won't have time to look into it until at least next week though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants