Advertisement
Guest User

Untitled

a guest
Jan 10th, 2019
483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.55 KB | None | 0 0
  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 stratMain = {};
  10.  
  11.  
  12. stratMain.init = function () {
  13. this.name = 'SobhV5.js';
  14.  
  15. this.exposedMain = false;
  16. this.trendMain = {
  17. direction: 'none',
  18. duration: 0,
  19. persisted: false,
  20. adviced: false
  21. };
  22.  
  23. this.cb5 = new candleBatcher(5);
  24. this.cb5.on('candle', this.onCandle5M);
  25.  
  26. this.cb15 = new candleBatcher(15);
  27. this.cb15.on('candle', this.onCandle15M);
  28.  
  29. this.cb240 = new candleBatcher(240);
  30. this.cb240.on('candle', this.onCandle240M);
  31.  
  32. this.requiredHistory = this.tradingAdvisor.historySize;
  33. this.count1M = 0;
  34.  
  35. const MACDSettings = this.settings.MACD;
  36. const RSISettings = this.settings.RSI;
  37. //const MFISettings = this.settings.MFI;
  38.  
  39. this.macd5M = new TULIPASYNC({ indicator: 'macd', length: 5000, candleinput: 'close', options:[ MACDSettings.optInFastPeriod, MACDSettings.optInSlowPeriod, MACDSettings.optInSignalPeriod ] });
  40. //this.mfi5M = new TULIPASYNC({ indicator: 'mfi', length: 5000, candleinput: 'close', options:[ MFISettings.optInTimePeriod ] });
  41. this.rsi5M = new TULIPASYNC({ indicator: 'rsi', length: 5000, candleinput: 'close', options:[ RSISettings.optInTimePeriod ] });
  42.  
  43.  
  44. this.macd15M = new TULIPASYNC({ indicator: 'macd', length: 5000, candleinput: 'close', options:[ MACDSettings.optInFastPeriod, MACDSettings.optInSlowPeriod, MACDSettings.optInSignalPeriod ] });
  45. //this.mfi15M = new TULIPASYNC({ indicator: 'mfi', length: 5000, candleinput: 'close', options:[ MFISettings.optInTimePeriod ] });
  46. this.rsi15M = new TULIPASYNC({ indicator: 'rsi', length: 5000, candleinput: 'close', options:[ RSISettings.optInTimePeriod ] });
  47.  
  48. this.macd240M = new TULIPASYNC({ indicator: 'macd', length: 5000, candleinput: 'close', options:[ MACDSettings.optInFastPeriod, MACDSettings.optInSlowPeriod, MACDSettings.optInSignalPeriod ] });
  49. //this.mfi240M = new TULIPASYNC({ indicator: 'mfi', length: 5000, candleinput: 'close', options:[ MFISettings.optInTimePeriod ] });
  50. this.rsi240M = new TULIPASYNC({ indicator: 'rsi', length: 5000, candleinput: 'close', options:[ RSISettings.optInTimePeriod ] });
  51. }
  52.  
  53.  
  54. // ***************************************************************************
  55. // * 1 Min candles - candle batching
  56. stratMain.onCandle = async function (candle) {
  57. this.count1M++;
  58.  
  59. this.cb5.write([candle]);
  60. this.cb5.flush();
  61.  
  62. this.cb15.write([candle]);
  63. this.cb15.flush();
  64.  
  65. this.cb240.write([candle]);
  66. this.cb240.flush();
  67. }
  68.  
  69.  
  70. // ***************************************************************************
  71. // * 60 Min candles - strong market strat
  72. stratMain.onCandle5M = async function (candle) {
  73. await this.update5M(candle);
  74. this.check5M(candle);
  75. }
  76.  
  77. stratMain.onCandle15M = async function (candle) {
  78. await this.update15M(candle);
  79. this.check15M(candle);
  80. }
  81.  
  82. stratMain.onCandle240M = async function (candle) {
  83. await this.update240M(candle);
  84. this.check240M(candle);
  85. }
  86.  
  87.  
  88. // ***************************************************************************
  89. //* 5-15-240 Min candles - check
  90. stratMain.update5M = async function (candle) {
  91. this.macd5M.result = await this.macd5M.update(candle);
  92. this.macd5M.macd = this.macd5M.result[0];
  93. //this.mfi5M.result = (await this.mfi5M.update(candle))[0];
  94. this.rsi5M.result = (await this.rsi5M.update(candle))[0];
  95. }
  96.  
  97. stratMain.update15M = async function (candle) {
  98. this.macd15M.result = await this.macd15M.update(candle);
  99. this.macd15M.macd = this.macd15M.result[0];
  100. //this.mfi15M.result = (await this.mfi15M.update(candle))[0];
  101. this.rsi15M.result = (await this.rsi15M.update(candle))[0];
  102. }
  103.  
  104. stratMain.update240M = async function (candle) {
  105. this.macd240M.result = await this.macd240M.update(candle);
  106. this.macd240M.macd = this.macd240M.result[0];
  107. //this.mfi240M.result = (await this.mfi240M.update(candle))[0];
  108. this.rsi240M.result = (await this.rsi240M.update(candle))[0];
  109. }
  110.  
  111.  
  112. // ***************************************************************************
  113. //* 5-15-240 Min candles - check
  114. stratMain.check5M = function(candle) {
  115. if (this.count1M <= this.requiredHistory) return;
  116. console.log (' 5M CANDLES:',candle.start.format(),candle.close,'macd',this.macd5M.macd,"RSINew",this.rsi5M.result);
  117. }
  118.  
  119. stratMain.check15M = function(candle) {
  120. if (this.count1M <= this.requiredHistory) return;
  121. console.log (' 15M CANDLES:',candle.start.format(),candle.close,'macd',this.macd15M.macd,"RSINew",this.rsi15M.result);
  122. }
  123.  
  124. stratMain.check240M = function(candle) {
  125. if (this.count1M <= this.requiredHistory) {
  126. console.log('Warmup strategy with history data...');
  127. return;
  128. }
  129.  
  130. console.log ('240M CANDLES:',candle.start.format(),candle.close,'macd',this.macd240M.macd,"RSINew",this.rsi240M.result);
  131. }
  132.  
  133.  
  134. stratMain.log = function () {
  135. }
  136.  
  137.  
  138. stratMain.update = function (candle) {
  139. //no need for strat update, we work with onCandle custom batching
  140. }
  141.  
  142.  
  143. stratMain.check = function (candle) {
  144. //no need for strat check, we work with onCandle custom batching and strat execution
  145. }
  146.  
  147.  
  148. module.exports = stratMain;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement