Mida icon indicating copy to clipboard operation
Mida copied to clipboard

Is there any way to backtest strategies?

Open albizeka opened this issue 3 years ago • 1 comments
trafficstars

I'm playing around with this library and you've done a huge job here, is there any way i can backtest my strategy here?

albizeka avatar Apr 17 '22 15:04 albizeka

Hi, first of all thank you for the appreciation.

The short answer is YES, but. . . it's not ready yet: https://github.com/Reiryoku-Technologies/Mida-Playground This plugin is meant to add a local demo broker to Mida, which can be used to simulate trades and backtest EAs on historical data.

It's still work in progress, but it's one of my primary focus for the next steps. The API design looks like this, so let me know if you have any suggestion

// Use the Playground plugin
Mida.use(require("@reiryoku/mida-playground"));

// Login to the Playground broker account
const myAccount = await MidaBroker.login("Playground", { . . . });

// If you want to backtest on EURUSD or BTCUSD or any other symbol
// first you need to load the historical ticks/candlesticks of the symbol
await myAccount.loadTicks(. . .);

// Then you need to set the broker local date, let's suppose the loaded historical data starts from 2020
myAccount.localDate = new MidaDate("2020-01-01T00:00:00.000Z");

This is a basic setup, now for backtesting an existing EA we just create an instance of it with the playground broker account

const MyFirstExpertAdvisor = require("./my-first-ea");

const tradingBot = new MyFirstExpertAdvisor({ brokerAccount: myAccount, });

await tradingBot.start();

// Now to backtest the EA we just need to elapse time, this will trigger ticks and candlesticks
// so the EA will start placing orders and checking positions based on your strategy like on a live account
await myAccount.elapseTime(2628288); // 2628288 seconds = 1 month
// This will also update myAccount.localDate according to the elapsed time

Right now I don't have an ETA for the release of this plugin, but I will keep this issue open until the first version is done, thank you.

Vasile-Peste avatar Apr 18 '22 15:04 Vasile-Peste