Advertisement
Guest User

SM_MovingAverageLabels

a guest
Jun 28th, 2018
789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. #
  2. # SM_MovingAverageLabels
  3. #
  4. # version 1.0
  5. #
  6.  
  7.  
  8. #Default moving average values:
  9. #EXPO 9 OHLC
  10. #SIMP 20 OHLC
  11. #EXPO 49 OHLC
  12. #EXPO 99 OHLC
  13. #SIMP 200 OHLC
  14.  
  15. input MA_1_length = 9; #exponential
  16. input MA_2_length = 20; #simple
  17. input MA_3_length = 49; #exponential
  18. input MA_4_length = 99; #exponential
  19. input MA_5_length = 200; #simple
  20.  
  21. input MA_1_closeType = ohlc4;
  22. input MA_2_closeType = ohlc4;
  23. input MA_3_closeType = ohlc4;
  24. input MA_4_closeType = ohlc4;
  25. input MA_5_closeType = ohlc4;
  26.  
  27. def MA_1_avg = ExpAverage(MA_1_closeType, MA_1_length);
  28. def MA_2_avg = Average(MA_2_closeType, MA_2_length);
  29. def MA_3_avg = ExpAverage(MA_3_closeType, MA_3_length);
  30. def MA_4_avg = ExpAverage(MA_4_closeType, MA_4_length);
  31. def MA_5_avg = Average(MA_5_closeType, MA_5_length);
  32.  
  33. def currentPrice = close;
  34.  
  35. def MA_1_above = if currentPrice > MA_1_avg then 1 else 0;
  36. def MA_1_below = if currentPrice <= MA_1_avg then 1 else 0;
  37. AddLabel(MA_1_above, MA_1_length + " ema: " + MA_1_avg, COLOR.DARK_GREEN);
  38. AddLabel(MA_1_below, MA_1_length + " ema: " + MA_1_avg, COLOR.DARK_RED);
  39.  
  40. def MA_2_above = if currentPrice > MA_2_avg then 1 else 0;
  41. def MA_2_below = if currentPrice <= MA_2_avg then 1 else 0;
  42. AddLabel(MA_2_above, MA_2_length + " sma: " + MA_2_avg, COLOR.DARK_GREEN);
  43. AddLabel(MA_2_below, MA_2_length + " sma: " + MA_2_avg, COLOR.DARK_RED);
  44.  
  45. def MA_3_above = if currentPrice > MA_3_avg then 1 else 0;
  46. def MA_3_below = if currentPrice <= MA_3_avg then 1 else 0;
  47. AddLabel(MA_3_above, MA_3_length + " ema: " + MA_3_avg, COLOR.DARK_GREEN);
  48. AddLabel(MA_3_below, MA_3_length + " ema: " + MA_3_avg, COLOR.DARK_RED);
  49.  
  50. def MA_4_above = if currentPrice > MA_4_avg then 1 else 0;
  51. def MA_4_below = if currentPrice <= MA_4_avg then 1 else 0;
  52. AddLabel(MA_4_above, MA_4_length + " ema: " + MA_4_avg, COLOR.DARK_GREEN);
  53. AddLabel(MA_4_below, MA_4_length + " ema: " + MA_4_avg, COLOR.DARK_RED);
  54.  
  55. def MA_5_above = if currentPrice > MA_5_avg then 1 else 0;
  56. def MA_5_below = if currentPrice <= MA_5_avg then 1 else 0;
  57. AddLabel(MA_4_above, MA_5_length + " sma: " + MA_5_avg, COLOR.DARK_GREEN);
  58. AddLabel(MA_4_below, MA_5_length + " sma: " + MA_5_avg, COLOR.DARK_RED);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement