Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. //+------------------------------------------------------------------+
  2. //| ROC.mq4 |
  3. //| Copyright © 2006, Robert Hill |
  4. //+------------------------------------------------------------------+
  5.  
  6. #property copyright "Copyright © 2006, Robert Hill"
  7. //---- indicator settings
  8. #property indicator_separate_window
  9. #property indicator_buffers 1
  10. #property indicator_color1 Red
  11. //---- indicator parameters
  12. extern int RPeriod = 10;
  13. extern bool UsePercent = false;
  14. //---- indicator buffers
  15. double RateOfChange[];
  16. //+------------------------------------------------------------------+
  17. //| Custom indicator initialization function |
  18. //+------------------------------------------------------------------+
  19. int init()
  20. {
  21. //---- drawing settings
  22. SetIndexStyle(0, DRAW_LINE);
  23. SetIndexDrawBegin(0, RPeriod);
  24. IndicatorDigits(Digits + 1);
  25. //---- indicator buffers mapping
  26. if(!SetIndexBuffer(0, RateOfChange))
  27. Print("cannot set indicator buffers!");
  28. //---- name for DataWindow and indicator subwindow label
  29. IndicatorShortName("ROC(" + RPeriod + ")");
  30. //---- initialization done
  31. return(0);
  32. }
  33. //+------------------------------------------------------------------+
  34. //| Moving Averages Convergence/Divergence |
  35. //+------------------------------------------------------------------+
  36. int start()
  37. {
  38. int limit;
  39. double ROC, CurrentClose, PrevClose;
  40. int counted_bars = IndicatorCounted();
  41. //---- check for possible errors
  42. if(counted_bars < 0)
  43. return(-1);
  44. //---- last counted bar will be recounted
  45. if(counted_bars > 0)
  46. counted_bars--;
  47. limit = MathMin(Bars - counted_bars,Bars-1);
  48. //---- ROC calculation
  49. for(int i = 0; i < limit; i++)
  50. {
  51. CurrentClose = iClose(NULL, 0, i);
  52. PrevClose = iClose(NULL, 0, i + RPeriod);
  53. ROC = CurrentClose - PrevClose;
  54. //----
  55. if(UsePercent)
  56. {
  57. if(PrevClose != 0)
  58. RateOfChange[i] = 100 * ROC / PrevClose;
  59. }
  60. else
  61. RateOfChange[i] = ROC;
  62. }
  63. //---- done
  64. return(0);
  65. }
  66. //+------------------------------------------------------------------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement