Advertisement
joaocarlosa

Indicador_BB+EMA

Feb 24th, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.68 KB | None | 0 0
  1. //+------------------------------------------------------------------+
  2. //|                                                        bbema.mq5 |
  3. //|                        Copyright 2020, MetaQuotes Software Corp. |
  4. //|                                             https://www.mql5.com |
  5. //+------------------------------------------------------------------+
  6. #property copyright "Copyright 2020, MetaQuotes Software Corp."
  7. #property link      "https://www.mql5.com"
  8. #property version   "1.00"
  9. #property indicator_chart_window
  10. #property indicator_buffers 7
  11. #property indicator_plots   7
  12. //--- plot call
  13. #property indicator_label1  "call"
  14. #property indicator_type1   DRAW_ARROW
  15. #property indicator_color1  clrLightSkyBlue
  16. #property indicator_style1  STYLE_SOLID
  17. #property indicator_width1  10
  18. //--- plot put
  19. #property indicator_label2  "put"
  20. #property indicator_type2   DRAW_ARROW
  21. #property indicator_color2  clrOrchid
  22. #property indicator_style2  STYLE_SOLID
  23. #property indicator_width2  10
  24. //--- plot signal
  25. #property indicator_label3  "signal"
  26. #property indicator_type3   DRAW_ARROW
  27. #property indicator_color3  clrPurple
  28. #property indicator_style3  STYLE_SOLID
  29. #property indicator_width3  10
  30. //--- plot ema
  31. #property indicator_label4  "ema"
  32. #property indicator_type4   DRAW_LINE
  33. #property indicator_color4  clrHotPink
  34. #property indicator_style4  STYLE_SOLID
  35. #property indicator_width4  1
  36. //--- plot upper
  37. #property indicator_label5  "upper"
  38. #property indicator_type5   DRAW_LINE
  39. #property indicator_color5  clrRed
  40. #property indicator_style5  STYLE_SOLID
  41. #property indicator_width5  1
  42. //--- plot mid
  43. #property indicator_label6  "mid"
  44. #property indicator_type6   DRAW_LINE
  45. #property indicator_color6  clrWhite
  46. #property indicator_style6  STYLE_SOLID
  47. #property indicator_width6  1
  48. //--- plot lower
  49. #property indicator_label7  "lower"
  50. #property indicator_type7   DRAW_LINE
  51. #property indicator_color7  clrPaleGreen
  52. #property indicator_style7  STYLE_SOLID
  53. #property indicator_width7  1
  54. //--- input parameters
  55. input int      Input1;
  56. input int      Input2;
  57. //--- indicator buffers
  58. double         callBuffer[];
  59. double         putBuffer[];
  60. double         signalBuffer[];
  61. double         emaBuffer[];
  62. double         upperBuffer[];
  63. double         midBuffer[];
  64. double         lowerBuffer[];
  65. //+------------------------------------------------------------------+
  66. //| Custom indicator initialization function                         |
  67. //+------------------------------------------------------------------+
  68. int OnInit()
  69.   {
  70. //--- indicator buffers mapping
  71.    SetIndexBuffer(0,callBuffer,INDICATOR_DATA);
  72.    SetIndexBuffer(1,putBuffer,INDICATOR_DATA);
  73.    SetIndexBuffer(2,signalBuffer,INDICATOR_DATA);
  74.    SetIndexBuffer(3,emaBuffer,INDICATOR_DATA);
  75.    SetIndexBuffer(4,upperBuffer,INDICATOR_DATA);
  76.    SetIndexBuffer(5,midBuffer,INDICATOR_DATA);
  77.    SetIndexBuffer(6,lowerBuffer,INDICATOR_DATA);
  78. //--- setting a code from the Wingdings charset as the property of PLOT_ARROW
  79.    PlotIndexSetInteger(0,PLOT_ARROW,159);
  80.    PlotIndexSetInteger(1,PLOT_ARROW,159);
  81.    PlotIndexSetInteger(2,PLOT_ARROW,159);
  82.    
  83. //---
  84.    return(INIT_SUCCEEDED);
  85.   }
  86. //+------------------------------------------------------------------+
  87. //| Custom indicator iteration function                              |
  88. //+------------------------------------------------------------------+
  89. int OnCalculate(const int rates_total,
  90.                 const int prev_calculated,
  91.                 const datetime &time[],
  92.                 const double &open[],
  93.                 const double &high[],
  94.                 const double &low[],
  95.                 const double &close[],
  96.                 const long &tick_volume[],
  97.                 const long &volume[],
  98.                 const int &spread[])
  99.   {
  100. //---
  101.    CopyBuffer(iMA(_Symbol,_Period,100,0,MODE_EMA,PRICE_OPEN) ,0,0,rates_total, emaBuffer);
  102.    
  103.    //CopyBuffer(iBands(_Symbol,_Period,20,0,2.5,PRICE_OPEN),0,0,rates_total, midBuffer);
  104.    CopyBuffer(iBands(_Symbol,_Period,20,0,2.5,PRICE_CLOSE),1,0,rates_total, upperBuffer);
  105.    CopyBuffer(iBands(_Symbol,_Period,20,0,2.5,PRICE_CLOSE),2,0,rates_total, lowerBuffer);
  106.    
  107.    for(int i=1; i<rates_total; i++){
  108.      
  109.         if(emaBuffer[i]>upperBuffer[i]){
  110.           putBuffer[i]= high[i] >= upperBuffer[i] ? high[i] : 0;
  111.         }
  112.         else{
  113.             putBuffer[i]=0;
  114.         }
  115.        
  116.        
  117.         if(emaBuffer[i]<lowerBuffer[i]){
  118.           callBuffer[i]= low[i] <= lowerBuffer[i] ? low[i] : 0;
  119.         }
  120.         else{
  121.             callBuffer[i]=0;
  122.         }
  123.    
  124.    
  125.    }
  126.    
  127. //--- return value of prev_calculated for next call
  128.    return(rates_total);
  129.   }
  130. //+------------------------------------------------------------------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement