@backtest/command-line
Version:
This project is a CLI build around Backtest, a library for trading developers
39 lines • 1.84 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.properties = void 0;
exports.runStrategy = runStrategy;
const moving_averages_1 = require("../indicators/moving-averages");
exports.properties = {
params: ['lowSMA', 'highSMA'],
dynamicParams: false
};
function runStrategy(bth) {
return __awaiter(this, void 0, void 0, function* () {
const lowSMAInput = bth.params.lowSMA;
const highSMAInput = bth.params.highSMA;
// Get last candles
const lowSMACandles = yield bth.getCandles('close', lowSMAInput, 0);
const highSMACandles = yield bth.getCandles('close', highSMAInput, 0);
// Calculate low and high SMA
const lowSMA = yield (0, moving_averages_1.indicatorSMA)(lowSMACandles, lowSMAInput);
const highSMA = yield (0, moving_averages_1.indicatorSMA)(highSMACandles, highSMAInput);
// Buy if lowSMA crosses over the highSMA
if (lowSMA > highSMA) {
yield bth.buy();
}
// Sell if lowSMA crosses under the highSMA
else {
yield bth.sell();
}
});
}
//# sourceMappingURL=ex1SMA.js.map
;