Guest User

Untitled

a guest
Jun 23rd, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. var _ = require('lodash');
  2. var log = require('../core/log.js');
  3. var watchPrice = 0.0;
  4. var lowestPrice = 0.0;
  5. var sellPrice = 0.0;
  6. var adviced = false;
  7.  
  8.  
  9. // Let's create our own buy and sell strategy
  10. var strat = {};
  11.  
  12. // Prepare everything our strat needs
  13. strat.init = function() {
  14. // setting buy price
  15.  
  16. this.requiredHistory = this.tradingAdvisor.historySize;
  17. }
  18.  
  19. // What happens on every new candle?
  20. strat.update = function(candle) {
  21. log.debug('candle time', candle.start);
  22. log.debug('candle close price', candle.close);
  23. }
  24.  
  25. // For debugging purposes.
  26. strat.log = function() {
  27. // your code!
  28. }
  29.  
  30. // Based on the newly calculated
  31. // information, check if we should
  32. // update or not.
  33. strat.check = function(candle) {
  34.  
  35.  
  36. if(watchPrice == 0) {
  37. watchPrice = candle.close * 0.98;
  38. }
  39.  
  40. if(candle.close <= watchPrice){
  41. lowestPrice = candle.close;
  42. }
  43.  
  44. if(candle.close > lowestPrice && !advised){
  45. this.advice("long")
  46. log.debug('Buying at', candle.close);
  47. sellPrice = candle.close * 1.03;
  48. advised = true;
  49. }
  50.  
  51. if(candle.close > sellPrice && watchPrice != 0 && lowestPrice !=0){
  52. this.advice("short")
  53. log.debug('Selling at', candle.close);
  54. watchPrice = 0;
  55. lowestPrice = 0;
  56. buyPrice = 0;
  57. sellPrice = 0;
  58. advised = false;
  59. }
  60.  
  61. }
  62.  
  63. module.exports = strat;
Add Comment
Please, Sign In to add comment