Advertisement
Guest User

SobhV7

a guest
Jan 12th, 2019
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.59 KB | None | 0 0
  1. const _ = require('lodash');
  2. const util = require('util');
  3. var tulind = require('tulind');
  4. const log = require('../core/log.js');
  5. const config = require ('../core/util.js').getConfig();
  6. const candleBatcher = require('../core/candleBatcher');
  7. const TULIPASYNC = require('../strategies/indicators/TulipAsync.js');
  8. const TALIBASYNC = require('../strategies/indicators/TalibAsync.js');
  9. const TEMA = require('../strategies/indicators/TEMA.js');
  10. var stratMain = {};
  11.  
  12.  
  13. stratMain.init = function () {
  14. this.name = 'SobhV7.js';
  15.  
  16. this.exposedMain = false;
  17. this.trendMain = {
  18. direction: 'none',
  19. duration: 0,
  20. persisted: false,
  21. adviced: false
  22. };
  23.  
  24.  
  25. this.cb1 = new candleBatcher(1);
  26. this.cb1.on('candle', this.onCandle1M);
  27.  
  28. this.cb5 = new candleBatcher(5);
  29. this.cb5.on('candle', this.onCandle5M);
  30.  
  31. this.cb15 = new candleBatcher(15);
  32. this.cb15.on('candle', this.onCandle15M);
  33.  
  34. this.cb240 = new candleBatcher(240);
  35. this.cb240.on('candle', this.onCandle240M);
  36.  
  37. this.requiredHistory = this.tradingAdvisor.historySize;
  38. this.count1M = 0;
  39.  
  40. const MACDSettings = this.settings.MACD;
  41. const RSISettings = this.settings.RSI;
  42. const MFISettings = this.settings.MFI;
  43.  
  44.  
  45. this.macd1M = new TULIPASYNC({ indicator: 'macd', length: 5000, candleinput: 'close', options:[ MACDSettings.optInFastPeriod, MACDSettings.optInSlowPeriod, MACDSettings.optInSignalPeriod ] });
  46. this.mfi1M = new TALIBASYNC({ indicator: 'mfi', length: 5000, options: { optInTimePeriod: 14 } });
  47. this.rsi1M = new TULIPASYNC({ indicator: 'rsi', length: 5000, candleinput: 'close', options:[ RSISettings.optInTimePeriod ] });
  48. this.rsi1TM = new TALIBASYNC({ indicator: 'rsi', length: 5000, options: { optInTimePeriod: 14 } });
  49.  
  50.  
  51.  
  52. this.macd5M = new TULIPASYNC({ indicator: 'macd', length: 5000, candleinput: 'close', options:[ MACDSettings.optInFastPeriod, MACDSettings.optInSlowPeriod, MACDSettings.optInSignalPeriod ] });
  53. //this.mfi5M = new TULIPASYNC({ indicator: 'mfi', length: 5000, candleinput: 'close', options:[ MFISettings.optInTimePeriod ] });
  54. this.mfi5M = new TALIBASYNC({ indicator: 'mfi', length: 5000, options: { optInTimePeriod: 14 } });
  55. this.rsi5M = new TULIPASYNC({ indicator: 'rsi', length: 5000, candleinput: 'close', options:[ RSISettings.optInTimePeriod ] });
  56. this.rsi5TM = new TALIBASYNC({ indicator: 'rsi', length: 5000, options: { optInTimePeriod: 14 } });
  57.  
  58. this.macd15M = new TULIPASYNC({ indicator: 'macd', length: 5000, candleinput: 'close', options:[ MACDSettings.optInFastPeriod, MACDSettings.optInSlowPeriod, MACDSettings.optInSignalPeriod ] });
  59. //this.mfi15M = new TULIPASYNC({ indicator: 'mfi', length: 5000, candleinput: 'close', options:[ MFISettings.optInTimePeriod ] });
  60. this.mfi15M = new TALIBASYNC({ indicator: 'mfi', length: 5000, options: { optInTimePeriod: 14 } });
  61. this.rsi15M = new TULIPASYNC({ indicator: 'rsi', length: 5000, candleinput: 'close', options:[ RSISettings.optInTimePeriod ] });
  62.  
  63. this.macd240M = new TULIPASYNC({ indicator: 'macd', length: 5000, candleinput: 'close', options:[ MACDSettings.optInFastPeriod, MACDSettings.optInSlowPeriod, MACDSettings.optInSignalPeriod ] });
  64. //this.mfi240M = new TULIPASYNC({ indicator: 'mfi', length: 5000, candleinput: 'close', options:[ MFISettings.optInTimePeriod ] });
  65. this.mfi240M = new TALIBASYNC({ indicator: 'mfi', length: 5000, options: { optInTimePeriod: 14 } });
  66. this.rsi240M = new TULIPASYNC({ indicator: 'rsi', length: 5000, candleinput: 'close', options:[ RSISettings.optInTimePeriod ] });
  67. }
  68.  
  69.  
  70. // ***************************************************************************
  71. // * 1 Min candles - candle batching
  72. stratMain.onCandle = async function (candle) {
  73. this.count1M++;
  74.  
  75. this.cb1.write([candle]);
  76. this.cb1.flush();
  77.  
  78. this.cb5.write([candle]);
  79. this.cb5.flush();
  80.  
  81. this.cb15.write([candle]);
  82. this.cb15.flush();
  83.  
  84. this.cb240.write([candle]);
  85. this.cb240.flush();
  86. }
  87.  
  88.  
  89. // ***************************************************************************
  90. // * 60 Min candles - strong market strat
  91. stratMain.onCandle1M = async function (candle) {
  92. await this.update1M(candle);
  93. this.check1M(candle);
  94. }
  95.  
  96.  
  97. stratMain.onCandle5M = async function (candle) {
  98. await this.update5M(candle);
  99. this.check5M(candle);
  100. }
  101.  
  102. stratMain.onCandle15M = async function (candle) {
  103. await this.update15M(candle);
  104. this.check15M(candle);
  105. }
  106.  
  107. stratMain.onCandle240M = async function (candle) {
  108. await this.update240M(candle);
  109. this.check240M(candle);
  110. }
  111.  
  112.  
  113. // ***************************************************************************
  114. //* 5-15-240 Min candles - check
  115.  
  116. stratMain.update1M = async function (candle) {
  117. this.macd1M.result = await this.macd1M.update(candle);
  118. this.macd1M.macd = this.macd1M.result[0];
  119. this.rsi1TM.result = (await this.rsi1TM.update(candle))[0];
  120. this.mfi1M.result = (await this.mfi1M.update(candle))[0];
  121. this.rsi1M.result = (await this.rsi1M.update(candle))[0];
  122. }
  123.  
  124. stratMain.update5M = async function (candle) {
  125. this.macd5M.result = await this.macd5M.update(candle);
  126. this.macd5M.macd = this.macd5M.result[0];
  127. //this.macd5M.macd = this.macd5M.result[0];
  128. this.rsi5TM.result = (await this.rsi5TM.update(candle))[0];
  129. this.mfi5M.result = (await this.mfi5M.update(candle))[0];
  130. this.rsi5M.result = (await this.rsi5M.update(candle))[0];
  131. }
  132.  
  133. stratMain.update15M = async function (candle) {
  134. this.macd15M.result = await this.macd15M.update(candle);
  135. this.macd15M.macd = this.macd15M.result[0];
  136. this.mfi15M.result = (await this.mfi15M.update(candle))[0];
  137. this.rsi15M.result = (await this.rsi15M.update(candle))[0];
  138. }
  139.  
  140. stratMain.update240M = async function (candle) {
  141. this.macd240M.result = await this.macd240M.update(candle);
  142. this.macd240M.macd = this.macd240M.result[0];
  143. this.mfi240M.result = (await this.mfi240M.update(candle))[0];
  144. this.rsi240M.result = (await this.rsi240M.update(candle))[0];
  145. }
  146.  
  147.  
  148. // ***************************************************************************
  149. //* 5-15-240 Min candles - check
  150.  
  151. stratMain.check1M = function(candle) {
  152. if (this.count1M <= this.requiredHistory) return;
  153. console.log (' 1M CANDLES:',candle.start.format(),candle.close,'macd 1 M ',this.macd1M.macd,"1 Min RSINew",this.rsi1M.result,"RSI1 T =",this.rsi1TM,"MFI",this.mfi1M);
  154. }
  155.  
  156.  
  157. stratMain.check5M = function(candle) {
  158. if (this.count1M <= this.requiredHistory) return;
  159. console.log (' 5M CANDLES:',candle.start.format(),candle.close,'macd',this.macd5M.macd,"RSINew",this.rsi5M.result,"RSI 5 T =",this.rsi5TM,"MFI",this.mfi5M);
  160. }
  161.  
  162. stratMain.check15M = function(candle) {
  163. if (this.count1M <= this.requiredHistory) return;
  164. console.log (' 15M CANDLES:',candle.start.format(),candle.close,'macd',this.macd15M.macd,"RSINew",this.rsi15M.result,"MFI",this.mfi15M);
  165. }
  166.  
  167. stratMain.check240M = function(candle) {
  168. if (this.count1M <= this.requiredHistory) {
  169. console.log('Warmup strategy with history data...');
  170. return;
  171. }
  172.  
  173. console.log ('240M CANDLES:',candle.start.format(),candle.close,'macd',this.macd240M.macd,"RSINew",this.rsi240M.result,"MFI",this.mfi240M);
  174. }
  175.  
  176.  
  177. stratMain.log = function () {
  178. }
  179.  
  180.  
  181. stratMain.update = function (candle) {
  182. //no need for strat update, we work with onCandle custom batching
  183. }
  184.  
  185.  
  186. stratMain.check = function (candle) {
  187. //no need for strat check, we work with onCandle custom batching and strat execution
  188. }
  189.  
  190.  
  191. module.exports = stratMain;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement