SHARE
TWEET

SobhV5.js

a guest Jan 10th, 2019 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const _ = require('lodash');
  2. const util = require('util');
  3. const log = require('../core/log.js');
  4. const config = require ('../core/util.js').getConfig();
  5. const candleBatcher = require('../core/candleBatcher');
  6. const TULIPASYNC = require('../strategies/indicators/TulipAsync.js');
  7. const TALIBASYNC = require('../strategies/indicators/TalibAsync.js');
  8. const TEMA = require('../strategies/indicators/TEMA.js');
  9. var obj;
  10. var stratMain = {};
  11.  
  12.  
  13. stratMain.init = function (context) {
  14.     if(context === undefined) {
  15.         this.context = this;
  16.     } else {
  17.         this.context = context;
  18.     }
  19.  
  20.     obj = this;
  21.     this.name = 'SobhV5.js';
  22.    
  23.     this.context.exposedMain = false;
  24.     this.context.trendMain = {
  25.         direction: 'none',
  26.         duration: 0,
  27.         persisted: false,
  28.         adviced: false
  29.     };
  30.  
  31.     this.cb5 = new candleBatcher(5);
  32.     this.cb5.on('candle', this.onCandle5M);
  33.  
  34.     this.cb15 = new candleBatcher(15);
  35.     this.cb15.on('candle', this.onCandle15M);
  36.  
  37.     this.cb240 = new candleBatcher(240);
  38.     this.cb240.on('candle', this.onCandle240M);
  39.  
  40.  
  41.     this.requiredHistory = this.context.tradingAdvisor.historySize;
  42.     //this.intCandleSize = this.context.tradingAdvisor.candleSize;
  43.  
  44.  
  45.  
  46.     const MACDSettings = this.context.settings.MACD;
  47.     const STOCHSettings = this.context.settings.STOCH;
  48.     const RSISettings = this.context.settings.RSI;
  49.     const MFISettings = this.context.settings.MFI;
  50.  
  51.    
  52.     this.macd5M = new TULIPASYNC({ indicator: 'macd', length: 14, candleinput: 'close', options:[ MACDSettings.optInFastPeriod, MACDSettings.optInSlowPeriod, MACDSettings.optInSignalPeriod ] });
  53.     this.mfi5M = new TULIPASYNC({ indicator: 'mfi', length: 14, candleinput: 'close', options:[ MFISettings.optInTimePeriod ] });
  54.     this.rsi5M = new TULIPASYNC({ indicator: 'rsi', length: 14, candleinput: 'close', options:[ RSISettings.optInTimePeriod ] });
  55.  
  56.  
  57.     this.macd15M = new TULIPASYNC({ indicator: 'macd', length: 14, candleinput: 'close', options:[ MACDSettings.optInFastPeriod, MACDSettings.optInSlowPeriod, MACDSettings.optInSignalPeriod ] });
  58.     this.mfi15M = new TULIPASYNC({ indicator: 'mfi', length: 14, candleinput: 'close', options:[ MFISettings.optInTimePeriod ] });
  59.     this.rsi15M = new TULIPASYNC({ indicator: 'rsi', length: 14, candleinput: 'close', options:[ RSISettings.optInTimePeriod ] });
  60.  
  61.     this.macd240M = new TULIPASYNC({ indicator: 'macd', length: 14, candleinput: 'close', options:[ MACDSettings.optInFastPeriod, MACDSettings.optInSlowPeriod, MACDSettings.optInSignalPeriod ] });
  62.     this.mfi240M = new TULIPASYNC({ indicator: 'mfi', length: 14, candleinput: 'close', options:[ MFISettings.optInTimePeriod ] });
  63.     this.rsi240M = new TULIPASYNC({ indicator: 'rsi', length: 14, candleinput: 'close', options:[ RSISettings.optInTimePeriod ] });
  64.  
  65.  
  66. }
  67.  
  68.  
  69. // ***************************************************************************
  70. // * 1 Min candles - candle batching
  71. stratMain.onCandle = async function (candle) {
  72.      this.cb5.write([candle]);
  73.      this.cb5.flush();
  74.  
  75.      this.cb15.write([candle]);
  76.      this.cb15.flush();
  77.  
  78.      this.cb240.write([candle]);
  79.      this.cb240.flush();
  80. }
  81.  
  82.  
  83. // ***************************************************************************
  84. // * 60 Min candles - strong market strat
  85. stratMain.onCandle5M = async function (candle) {
  86.         await obj.update5M(candle);
  87.         obj.check5M(candle);      
  88. }
  89. stratMain.onCandle15M = async function (candle) {
  90.         await obj.update15M(candle);
  91.         obj.check15M(candle);
  92. }
  93. stratMain.onCandle240M = async function (candle) {
  94.         await obj.update240M(candle);
  95.         obj.check240M(candle);
  96. }
  97.  
  98. // ***************************************************************************
  99. //* 5-15-240 Min candles - check
  100. stratMain.update5M = async function (candle) {
  101.     this.macd5M.result = await this.macd5M.update(candle);
  102.     this.macd5M.macd = this.macd5M.result[0];
  103.     //this.mfi5M.result = (await this.mfi5M.update(candle))[0];
  104.     this.rsi5M.result = (await this.rsi5M.update(candle))[0];
  105. }
  106. stratMain.update15M = async function (candle) {
  107.     this.macd15M.result = await this.macd15M.update(candle);
  108.     this.macd15M.macd = this.macd15M.result[0];
  109.     this.mfi15M.result = (await this.mfi15M.update(candle))[0];
  110. }
  111. stratMain.update240M = async function (candle) {
  112.     this.macd240M.result = await this.macd240M.update(candle);
  113.     this.macd240M.macd = this.macd240M.result[0];
  114.     this.mfi240M.result = (await this.mfi240M.update(candle))[0];
  115. }
  116.  
  117. // ***************************************************************************
  118. //* 5-15-240 Min candles - check
  119. stratMain.check5M = function(candle) {
  120.     console.log ('5M CANDLES:',candle.start.format(),candle.close,'macd',this.macd5M.macd,"MFINew",this.mfi5M.result,"RSINew",this.rsi5M.result);
  121. }
  122. stratMain.check15M = function(candle) {
  123.     console.log ('15M CANDLES:',candle.start.format(),candle.close,'macd',this.macd15M.macd,"MFINew",this.mfi15M.result,"RSINew",this.rsi15M.result);
  124. }
  125. stratMain.check240M = function(candle) {
  126.     console.log ('240M CANDLES:',candle.start.format(),candle.close,'macd',this.macd240M.macd,"MFINew",this.mfi240M.resul,"RSINew",this.rsi240M.resultt);
  127. }
  128.  
  129.  
  130.  
  131. stratMain.log = function () {
  132. }
  133.  
  134.  
  135. stratMain.update = function (candle) {
  136.     //no need for strat update, we work with onCandle custom batching
  137. }
  138.  
  139.  
  140. stratMain.check = function (candle) {
  141.    //no need for strat check, we work with onCandle custom batching and strat execution
  142. }
  143.  
  144.  
  145. module.exports = stratMain;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top