Sergeant

Trend Magic

Apr 15th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1.  
  2. //+------------------------------------------------------------------+
  3. //| TrendMagic.mq4 |
  4. //| Tidied up by TudorGirl 28 May 2009 |
  5. //| AnneTudor@ymail.com |
  6. //+------------------------------------------------------------------+
  7.  
  8. #property indicator_chart_window
  9. #property indicator_buffers 2
  10. #property indicator_color1 Blue
  11. #property indicator_width1 2
  12. #property indicator_color2 Red
  13. #property indicator_width2 2
  14.  
  15. //+------------------------------------------------------------------+
  16.  
  17. extern int CCI = 50;
  18. extern int ATR = 5;
  19.  
  20. //+------------------------------------------------------------------+
  21.  
  22. double bufferUp[];
  23. double bufferDn[];
  24.  
  25. //+------------------------------------------------------------------+
  26.  
  27. int init()
  28. {
  29. SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
  30. SetIndexBuffer(0, bufferUp);
  31. SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2);
  32. SetIndexBuffer(1, bufferDn);
  33. return (0);
  34. }
  35.  
  36. //+------------------------------------------------------------------+
  37.  
  38. int deinit()
  39. {
  40. return (0);
  41. }
  42.  
  43. //+------------------------------------------------------------------+
  44.  
  45. int start()
  46. {
  47. double thisCCI;
  48. double lastCCI;
  49.  
  50. int counted_bars = IndicatorCounted();
  51. if (counted_bars < 0) return (-1);
  52. if (counted_bars > 0) counted_bars--;
  53. int limit = Bars - counted_bars;
  54.  
  55. for (int shift = limit; shift >= 0; shift--)
  56. {
  57. thisCCI = iCCI(NULL, 0, CCI, PRICE_TYPICAL, shift);
  58. lastCCI = iCCI(NULL, 0, CCI, PRICE_TYPICAL, shift + 1);
  59.  
  60. if (thisCCI >= 0 && lastCCI < 0) bufferUp[shift + 1] = bufferDn[shift + 1];
  61. if (thisCCI <= 0 && lastCCI > 0) bufferDn[shift + 1] = bufferUp[shift + 1];
  62.  
  63. if (thisCCI >= 0)
  64. {
  65. bufferUp[shift] = Low[shift] - iATR(NULL, 0, ATR, shift);
  66. if (bufferUp[shift] < bufferUp[shift + 1])
  67. bufferUp[shift] = bufferUp[shift + 1];
  68. }
  69. else
  70. {
  71. if (thisCCI <= 0)
  72. {
  73. bufferDn[shift] = High[shift] + iATR(NULL, 0, ATR, shift);
  74. if (bufferDn[shift] > bufferDn[shift + 1])
  75. bufferDn[shift] = bufferDn[shift + 1];
  76. }
  77. }
  78. }
  79.  
  80. return (0);
  81. }
  82.  
  83. //+------------------------------------------------------------------+
  84. //+------------------------------------------------------------------+
Add Comment
Please, Sign In to add comment