Guest User

SM_Impulse

a guest
Jun 29th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.42 KB | None | 0 0
  1. #
  2. # SM_Impulse
  3. #
  4. #
  5. # version 1.0
  6. #
  7.  
  8. input Show_Impulse_Extras = yes;
  9.  
  10. ####################################
  11. #
  12. # Exponential moving average
  13. #
  14. # Uses 13-period by default for "fast" EMA, and then a 65 period for slow EMA.
  15. # This replicates the Impulse System's requirement to use both the current
  16. # time-frame, and a time-frame 5x larger than the current one. (13x5 = 65)
  17. #
  18. ####################################
  19.  
  20. input EMA_Fast_Length = 13; #Impulse uses 13 EMA by default
  21. input EMA_Slow_Length = 65; #13 x (5 times larger time)
  22. def EMA_price = close;
  23. def EMA_calculation = ExpAverage(EMA_price, EMA_fast_Length);
  24. def EMA_slow = ExpAverage(EMA_price, EMA_slow_Length);
  25. def EMA_fast_above = if close > EMA_calculation then 1 else 0;
  26. def EMA_fast_below = if close <= EMA_calculation then 1 else 0;
  27.  
  28. def EMA_slow_above = if close > EMA_slow then 1 else 0;
  29. def EMA_slow_below = if close <= EMA_slow then 1 else 0;
  30.  
  31. ####################################
  32. #
  33. # MACD + MACD Histogram
  34. #
  35. ####################################
  36.  
  37. input MACD_fastLength = 12;
  38. input MACD_slowLength = 26;
  39. input MACDLength = 9;
  40. input MACD_averageType = AverageType.EXPONENTIAL;
  41. def MACD_Value = MovingAverage(MACD_averageType, close, MACD_fastLength) - MovingAverage(MACD_averageType, close, MACD_slowLength);
  42. def MACD_Avg = MovingAverage(MACD_averageType, MACD_Value, MACDLength);
  43. def MACD_Diff = MACD_Value - MACD_Avg;
  44. def ZeroLine = 0;
  45.  
  46. def MACD_PositiveAndUp;
  47. def MACD_PositiveAndDown;
  48. def MACD_NegativeAndDown;
  49. def MACD_NegativeAndUp;
  50. def MACD_GoingUp;
  51. def MACD_GoingDown;
  52. if MACD_Diff >= 0 {
  53. if MACD_Diff > MACD_Diff[1] {
  54. MACD_PositiveAndUp = 1;
  55. MACD_PositiveAndDown = 0;
  56. MACD_NegativeAndUp = 0;
  57. MACD_NegativeAndDown = 0;
  58. MACD_GoingUp = 1;
  59. MACD_GoingDown = 0;
  60. } else {
  61. MACD_PositiveAndUp = 0;
  62. MACD_PositiveAndDown = 1;
  63. MACD_NegativeAndUp = 0;
  64. MACD_NegativeAndDown = 0;
  65. MACD_GoingUp = 0;
  66. MACD_GoingDown = 1;
  67. }
  68. } else {
  69. if MACD_Diff < MACD_Diff[1] {
  70. MACD_PositiveAndUp = 0;
  71. MACD_PositiveAndDown = 0;
  72. MACD_NegativeAndUp = 0;
  73. MACD_NegativeAndDown = 1;
  74. MACD_GoingUp = 0;
  75. MACD_GoingDown = 1;
  76. } else {
  77. MACD_PositiveAndUp = 0;
  78. MACD_PositiveAndDown = 0;
  79. MACD_NegativeAndUp = 1;
  80. MACD_NegativeAndDown = 0;
  81. MACD_GoingUp = 1;
  82. MACD_GoingDown = 0;
  83. }
  84. }
  85.  
  86. ####################################
  87. #
  88. # Impulse
  89. #
  90. ####################################
  91.  
  92. def Impulse_Up;
  93. def Impulse_Down;
  94. def Impulse_Neutral;
  95.  
  96. def both_EMA_up = if EMA_fast_above == 1 and EMA_slow_above == 1 then 1 else 0;
  97. def both_EMA_down = if EMA_fast_below == 1 and EMA_slow_below == 1 then 1 else 0;
  98. def both_EMA_neutral = if both_EMA_up == 0 and both_EMA_down == 0 then 1 else 0;
  99.  
  100. if both_EMA_up == 1 {
  101. Impulse_Down = 0; # Impulse down requires EMA_Down
  102. Impulse_Up = if MACD_GoingUp == 1 then 1 else 0;
  103. Impulse_Neutral = if MACD_GoingDown == 1 then 1 else 0;
  104. } else if both_EMA_down == 1 {
  105. Impulse_Up = 0;
  106. Impulse_Down = if MACD_GoingDown == 1 then 1 else 0;
  107. Impulse_Neutral = if MACD_GoingUp == 1 then 1 else 0;
  108. } else {
  109. Impulse_Up = 0;
  110. Impulse_Down = 0;
  111. Impulse_Neutral = 1;
  112. }
  113. AddLabel(Impulse_Up, "IMPULSE", COLOR.DARK_GREEN);
  114. AddLabel(Impulse_Down, "IMPULSE", COLOR.DARK_RED);
  115. AddLabel(Impulse_Neutral, "IMPULSE", COLOR.GRAY);
  116.  
  117. #AddLabel(both_EMA_up, "EMA", COLOR.DARK_GREEN);
  118. #AddLabel(both_EMA_down, "EMA", COLOR.DARK_RED);
  119. #AddLabel(both_EMA_neutral, "EMA", COLOR.GRAY);
  120.  
  121.  
  122. ####################################
  123. # MACD Histogram label
  124. ####################################
  125.  
  126. def show_MACD_PU;
  127. def show_MACD_PD;
  128. def show_MACD_NU;
  129. def show_MACD_ND;
  130.  
  131. if Show_Impulse_Extras == yes {
  132. show_MACD_PU = if MACD_PositiveAndUp == 1 then 1 else 0;
  133. show_MACD_PD = if MACD_PositiveAndDown == 1 then 1 else 0;
  134. show_MACD_NU = if MACD_NegativeAndUp == 1 then 1 else 0;
  135. show_MACD_ND = if MACD_NegativeAndDown == 1 then 1 else 0;
  136. } else {
  137. show_MACD_PU = 0;
  138. show_MACD_PD = 0;
  139. show_MACD_NU = 0;
  140. show_MACD_ND = 0;
  141. }
  142.  
  143. AddLabel(show_MACD_PU, "MACD Histogram", COLOR.DARK_GREEN);
  144. AddLabel(show_MACD_PD, "MACD Histogram", COLOR.DARK_RED);
  145. AddLabel(show_MACD_NU, "MACD Histogram", COLOR.DARK_GREEN);
  146. AddLabel(show_MACD_ND, "MACD Histogram", COLOR.DARK_RED);
  147.  
  148.  
  149. ####################################
  150. #
  151. # EMA Label
  152. #
  153. ####################################
  154.  
  155. def show_fEMA_up;
  156. def show_fEMA_down;
  157. def show_sEMA_up;
  158. def show_sEMA_down;
  159.  
  160. if Show_Impulse_Extras == yes {
  161. show_fEMA_up = if EMA_fast_above == 1 then 1 else 0;
  162. show_fEMA_down = if EMA_fast_below == 1 then 1 else 0;
  163. show_sEMA_up = if EMA_slow_above == 1 then 1 else 0;
  164. show_sEMA_down = if EMA_slow_below == 1 then 1 else 0;
  165. } else {
  166. show_fEMA_up = 0;
  167. show_fEMA_down = 0;
  168. show_sEMA_up = 0;
  169. show_sEMA_down = 0;
  170. }
  171. #AddLabel(show_fEMA_up, "Fast EMA: " + EMA_calculation, COLOR.DARK_GREEN);
  172. #AddLabel(show_fEMA_down, "Fast EMA :" + EMA_calculation, COLOR.DARK_RED);
  173. AddLabel(show_fEMA_up, "Fast EMA", COLOR.DARK_GREEN);
  174. AddLabel(show_fEMA_down, "Fast EMA", COLOR.DARK_RED);
  175.  
  176. #AddLabel(show_sEMA_up, "Slow EMA: " + EMA_slow, COLOR.DARK_GREEN);
  177. #AddLabel(show_sEMA_down, "Slow EMA: " + EMA_slow, COLOR.DARK_RED);
  178. AddLabel(show_sEMA_up, "Slow EMA", COLOR.DARK_GREEN);
  179. AddLabel(show_sEMA_down, "Slow EMA", COLOR.DARK_RED);
Add Comment
Please, Sign In to add comment