Advertisement
Guest User

Untitled

a guest
May 25th, 2018
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. //+------------------------------------------------------------------+
  2. //| Hi-LO.mq5 |
  3. //| Copyright 2018, MetaQuotes Software Corp. |
  4. //| https://www.mql5.com |
  5. //+------------------------------------------------------------------+
  6. #property copyright "Copyright 2018, MetaQuotes Software Corp."
  7. #property link "https://www.mql5.com"
  8. #property version "1.00"
  9. #property indicator_chart_window
  10. #property indicator_buffers 3
  11. #property indicator_plots 3
  12. //--- plot Media
  13. #property indicator_label1 "Media"
  14. #property indicator_type1 DRAW_LINE
  15. #property indicator_color1 clrOrange
  16. #property indicator_style1 STYLE_SOLID
  17. #property indicator_width1 2
  18. //--- plot Venda
  19. #property indicator_label2 "Venda"
  20. #property indicator_type2 DRAW_ARROW
  21. #property indicator_color2 clrRed
  22. #property indicator_style2 STYLE_SOLID
  23. #property indicator_width2 1
  24. //--- plot Compra
  25. #property indicator_label3 "Compra"
  26. #property indicator_type3 DRAW_ARROW
  27. #property indicator_color3 clrBlue
  28. #property indicator_style3 STYLE_SOLID
  29. #property indicator_width3 1
  30.  
  31. //--- input parameters
  32. input int Periodos=34;
  33. //--- indicator buffers
  34. double MediaBuffer[];
  35. double VendaBuffer[];
  36. double CompraBuffer[];
  37. //+------------------------------------------------------------------+
  38. //| Custom indicator initialization function |
  39. //+------------------------------------------------------------------+
  40. int OnInit()
  41. {
  42. //--- indicator buffers mapping
  43. SetIndexBuffer(0,MediaBuffer,INDICATOR_DATA);
  44. SetIndexBuffer(1,VendaBuffer,INDICATOR_DATA);
  45. SetIndexBuffer(2,CompraBuffer,INDICATOR_DATA);
  46.  
  47. PlotIndexSetInteger(1,PLOT_ARROW,234);
  48. PlotIndexSetInteger(2,PLOT_ARROW,233);
  49.  
  50. PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,0);
  51. PlotIndexSetInteger(2,PLOT_ARROW_SHIFT,0);
  52.  
  53. //---
  54. return(INIT_SUCCEEDED);
  55. }
  56. //+------------------------------------------------------------------+
  57. //| Custom indicator iteration function |
  58. //+------------------------------------------------------------------+
  59. int OnCalculate(const int rates_total,
  60. const int prev_calculated,
  61. const datetime &time[],
  62. const double &open[],
  63. const double &high[],
  64. const double &low[],
  65. const double &close[],
  66. const long &tick_volume[],
  67. const long &volume[],
  68. const int &spread[])
  69. {
  70. //---
  71.  
  72.  
  73. CopyBuffer(iMA(_Symbol,_Period,Periodos,0,MODE_EMA,PRICE_CLOSE),0,0,rates_total,MediaBuffer);
  74.  
  75. for(int i=Periodos; i<rates_total;i++)
  76. {
  77. if(open[i]>MediaBuffer[i] && close[i]>high[i-1])
  78. {
  79. CompraBuffer[i]=high[i-1];
  80. }
  81.  
  82. else if(open[i]<MediaBuffer[i] && close[i]<low[i-1])
  83. {
  84.  
  85. VendaBuffer[i]=low[i-1];
  86.  
  87. }
  88.  
  89. else
  90.  
  91. {
  92. VendaBuffer[i]=0;
  93. CompraBuffer[i]=0;
  94. }
  95.  
  96.  
  97. }
  98.  
  99. //--- return value of prev_calculated for next call
  100. return(rates_total);
  101. }
  102. //+------------------------------------------------------------------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement