黄金
HeikenAshi.mq4
回复:0  浏览:367
  • 楼主admin 圈主
  • 2019-05-05 05:15
EURUSDM30.png

  1. //+------------------------------------------------------------------+
  2. //|                                                  Heiken Ashi.mq4 |
  3. //|                        Copyright 2004, metaQuotes Software Corp. |
  4. //|                                        http://www.metaquotes.net |
  5. //+------------------------------------------------------------------+
  6. //| For Heiken Ashi we recommend next chart settings ( press F8 or   |
  7. //| select on menu 'Charts'->'Properties...'):                       |
  8. //|  - On 'Color' Tab select 'Black' for 'Line Graph'                |
  9. //|  - On 'Common' Tab disable 'Chart on Foreground' checkbox and    |
  10. //|    select 'Line Chart' radiobutton                               |
  11. //+------------------------------------------------------------------+
  12. #property copyright "Copyright 2004, metaQuotes Software Corp."
  13. #property link      "http://www.metaquotes.net"

  14. #property indicator_chart_window
  15. #property indicator_buffers 4
  16. #property indicator_color1 Red
  17. #property indicator_color2 Blue
  18. #property indicator_color3 Red
  19. #property indicator_color4 Blue
  20. //---- buffers
  21. double ExtMapBuffer1[];
  22. double ExtMapBuffer2[];
  23. double ExtMapBuffer3[];
  24. double ExtMapBuffer4[];
  25. //----
  26. int ExtCountedBars=0;
  27. //+------------------------------------------------------------------+
  28. //| Custom indicator initialization function                         |
  29. //|------------------------------------------------------------------|
  30. int init()
  31.   {
  32. //---- indicators
  33.    SetIndexStyle(0,DRAW_HISTOGRAM, 0, 1, Red);
  34.    SetIndexBuffer(0, ExtMapBuffer1);
  35.    SetIndexStyle(1,DRAW_HISTOGRAM, 0, 1, Blue);
  36.    SetIndexBuffer(1, ExtMapBuffer2);
  37.    SetIndexStyle(2,DRAW_HISTOGRAM, 0, 3, Red);
  38.    SetIndexBuffer(2, ExtMapBuffer3);
  39.    SetIndexStyle(3,DRAW_HISTOGRAM, 0, 3, Blue);
  40.    SetIndexBuffer(3, ExtMapBuffer4);
  41. //----
  42.    SetIndexDrawBegin(0,10);
  43.    SetIndexDrawBegin(1,10);
  44.    SetIndexDrawBegin(2,10);
  45.    SetIndexDrawBegin(3,10);
  46. //---- indicator buffers mapping
  47.    SetIndexBuffer(0,ExtMapBuffer1);
  48.    SetIndexBuffer(1,ExtMapBuffer2);
  49.    SetIndexBuffer(2,ExtMapBuffer3);
  50.    SetIndexBuffer(3,ExtMapBuffer4);
  51. //---- initialization done
  52.    return(0);
  53.   }
  54. //+------------------------------------------------------------------+
  55. //| Custor indicator deinitialization function                       |
  56. //+------------------------------------------------------------------+
  57. int deinit()
  58.   {
  59. //---- TODO: add your code here
  60.    
  61. //----
  62.    return(0);
  63.   }
  64. //+------------------------------------------------------------------+
  65. //| Custom indicator iteration function                              |
  66. //+------------------------------------------------------------------+
  67. int start()
  68.   {
  69.    double haOpen, haHigh, haLow, haClose;
  70.    if(Bars<=10) return(0);
  71.    ExtCountedBars=IndicatorCounted();
  72. //---- check for possible errors
  73.    if (ExtCountedBars<0) return(-1);
  74. //---- last counted bar will be recounted
  75.    if (ExtCountedBars>0) ExtCountedBars--;
  76.    int pos=Bars-ExtCountedBars-1;
  77.    while(pos>=0)
  78.      {
  79.       haOpen=(ExtMapBuffer3[pos+1]+ExtMapBuffer4[pos+1])/2;
  80.       haClose=(Open[pos]+High[pos]+Low[pos]+Close[pos])/4;
  81.       haHigh=MathMax(High[pos], MathMax(haOpen, haClose));
  82.       haLow=MathMin(Low[pos], MathMin(haOpen, haClose));
  83.       if (haOpen<haClose)
  84.         {
  85.          ExtMapBuffer1[pos]=haLow;
  86.          ExtMapBuffer2[pos]=haHigh;
  87.         }
  88.       else
  89.         {
  90.          ExtMapBuffer1[pos]=haHigh;
  91.          ExtMapBuffer2[pos]=haLow;
  92.         }
  93.       ExtMapBuffer3[pos]=haOpen;
  94.       ExtMapBuffer4[pos]=haClose;
  95.            pos--;
  96.      }
  97. //----
  98.    return(0);
  99.   }
  100. //+------------------------------------------------------------------+