Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const _ = require('lodash');
- const util = require('util');
- const log = require('../core/log.js');
- const config = require ('../core/util.js').getConfig();
- const candleBatcher = require('../core/candleBatcher');
- const TULIPASYNC = require('../strategies/indicators/TulipAsync.js');
- const TALIBASYNC = require('../strategies/indicators/TalibAsync.js');
- const TEMA = require('../strategies/indicators/TEMA.js');
- var obj;
- var stratMain = {};
- stratMain.init = function (context) {
- if(context === undefined) {
- this.context = this;
- } else {
- this.context = context;
- }
- obj = this;
- this.name = 'SobhV5.js';
- this.context.exposedMain = false;
- this.context.trendMain = {
- direction: 'none',
- duration: 0,
- persisted: false,
- adviced: false
- };
- this.cb5 = new candleBatcher(5);
- this.cb5.on('candle', this.onCandle5M);
- this.cb15 = new candleBatcher(15);
- this.cb15.on('candle', this.onCandle15M);
- this.cb240 = new candleBatcher(240);
- this.cb240.on('candle', this.onCandle240M);
- this.requiredHistory = this.context.tradingAdvisor.historySize;
- //this.intCandleSize = this.context.tradingAdvisor.candleSize;
- const MACDSettings = this.context.settings.MACD;
- const STOCHSettings = this.context.settings.STOCH;
- const RSISettings = this.context.settings.RSI;
- const MFISettings = this.context.settings.MFI;
- this.macd5M = new TULIPASYNC({ indicator: 'macd', length: 14, candleinput: 'close', options:[ MACDSettings.optInFastPeriod, MACDSettings.optInSlowPeriod, MACDSettings.optInSignalPeriod ] });
- this.mfi5M = new TULIPASYNC({ indicator: 'mfi', length: 14, candleinput: 'close', options:[ MFISettings.optInTimePeriod ] });
- this.rsi5M = new TULIPASYNC({ indicator: 'rsi', length: 14, candleinput: 'close', options:[ RSISettings.optInTimePeriod ] });
- this.macd15M = new TULIPASYNC({ indicator: 'macd', length: 14, candleinput: 'close', options:[ MACDSettings.optInFastPeriod, MACDSettings.optInSlowPeriod, MACDSettings.optInSignalPeriod ] });
- this.mfi15M = new TULIPASYNC({ indicator: 'mfi', length: 14, candleinput: 'close', options:[ MFISettings.optInTimePeriod ] });
- this.rsi15M = new TULIPASYNC({ indicator: 'rsi', length: 14, candleinput: 'close', options:[ RSISettings.optInTimePeriod ] });
- this.macd240M = new TULIPASYNC({ indicator: 'macd', length: 14, candleinput: 'close', options:[ MACDSettings.optInFastPeriod, MACDSettings.optInSlowPeriod, MACDSettings.optInSignalPeriod ] });
- this.mfi240M = new TULIPASYNC({ indicator: 'mfi', length: 14, candleinput: 'close', options:[ MFISettings.optInTimePeriod ] });
- this.rsi240M = new TULIPASYNC({ indicator: 'rsi', length: 14, candleinput: 'close', options:[ RSISettings.optInTimePeriod ] });
- }
- // ***************************************************************************
- // * 1 Min candles - candle batching
- stratMain.onCandle = async function (candle) {
- this.cb5.write([candle]);
- this.cb5.flush();
- this.cb15.write([candle]);
- this.cb15.flush();
- this.cb240.write([candle]);
- this.cb240.flush();
- }
- // ***************************************************************************
- // * 60 Min candles - strong market strat
- stratMain.onCandle5M = async function (candle) {
- await obj.update5M(candle);
- obj.check5M(candle);
- }
- stratMain.onCandle15M = async function (candle) {
- await obj.update15M(candle);
- obj.check15M(candle);
- }
- stratMain.onCandle240M = async function (candle) {
- await obj.update240M(candle);
- obj.check240M(candle);
- }
- // ***************************************************************************
- //* 5-15-240 Min candles - check
- stratMain.update5M = async function (candle) {
- this.macd5M.result = await this.macd5M.update(candle);
- this.macd5M.macd = this.macd5M.result[0];
- //this.mfi5M.result = (await this.mfi5M.update(candle))[0];
- this.rsi5M.result = (await this.rsi5M.update(candle))[0];
- }
- stratMain.update15M = async function (candle) {
- this.macd15M.result = await this.macd15M.update(candle);
- this.macd15M.macd = this.macd15M.result[0];
- this.mfi15M.result = (await this.mfi15M.update(candle))[0];
- }
- stratMain.update240M = async function (candle) {
- this.macd240M.result = await this.macd240M.update(candle);
- this.macd240M.macd = this.macd240M.result[0];
- this.mfi240M.result = (await this.mfi240M.update(candle))[0];
- }
- // ***************************************************************************
- //* 5-15-240 Min candles - check
- stratMain.check5M = function(candle) {
- console.log ('5M CANDLES:',candle.start.format(),candle.close,'macd',this.macd5M.macd,"MFINew",this.mfi5M.result,"RSINew",this.rsi5M.result);
- }
- stratMain.check15M = function(candle) {
- console.log ('15M CANDLES:',candle.start.format(),candle.close,'macd',this.macd15M.macd,"MFINew",this.mfi15M.result,"RSINew",this.rsi15M.result);
- }
- stratMain.check240M = function(candle) {
- console.log ('240M CANDLES:',candle.start.format(),candle.close,'macd',this.macd240M.macd,"MFINew",this.mfi240M.resul,"RSINew",this.rsi240M.resultt);
- }
- stratMain.log = function () {
- }
- stratMain.update = function (candle) {
- //no need for strat update, we work with onCandle custom batching
- }
- stratMain.check = function (candle) {
- //no need for strat check, we work with onCandle custom batching and strat execution
- }
- module.exports = stratMain;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement