路路发智能交易研发中心

 找回密码
 立即注册
查看: 2875|回复: 0

MT4智能交易编程示例AC指标

[复制链接]

管理员

MT4软件工程师

Rank: 9Rank: 9Rank: 9

积分
6521
帖子
2771
主题
2761
QQ
发表于 2014-4-4 14:32:07 | 显示全部楼层 |阅读模式
MT4智能交易编程示例AC指标

  1. #property copyright   "路路发智能交易研发中心"
  2. #property link        "http://www.ea668.com"
  3. #property description "Accelerator/Decelerator"
  4. #property strict

  5. #include <MovingAverages.mqh>

  6. //--- indicator settings
  7. #property  indicator_separate_window
  8. #property  indicator_buffers 3
  9. #property  indicator_color1  Black
  10. #property  indicator_color2  Green
  11. #property  indicator_color3  Red
  12. //--- indicator buffers
  13. double     ExtACBuffer[];
  14. double     ExtUpBuffer[];
  15. double     ExtDnBuffer[];
  16. double     ExtMacdBuffer[];
  17. double     ExtSignalBuffer[];
  18. //---
  19. #define PERIOD_FAST  5
  20. #define PERIOD_SLOW 34
  21. //--- bars minimum for calculation
  22. #define DATA_LIMIT  38
  23. //+------------------------------------------------------------------+
  24. //| Custom indicator initialization function                         |
  25. //+------------------------------------------------------------------+
  26. void OnInit(void)
  27.   {
  28.    IndicatorShortName("AC");
  29. //--- 2 additional buffers are used for counting.
  30.    IndicatorBuffers(5);
  31. //--- drawing settings
  32.    SetIndexStyle(0,DRAW_NONE);
  33.    SetIndexStyle(1,DRAW_HISTOGRAM);
  34.    SetIndexStyle(2,DRAW_HISTOGRAM);
  35.    IndicatorDigits(Digits+2);
  36.    SetIndexDrawBegin(0,DATA_LIMIT);
  37.    SetIndexDrawBegin(1,DATA_LIMIT);
  38.    SetIndexDrawBegin(2,DATA_LIMIT);
  39. //--- all indicator buffers mapping
  40.    SetIndexBuffer(0,ExtACBuffer);
  41.    SetIndexBuffer(1,ExtUpBuffer);
  42.    SetIndexBuffer(2,ExtDnBuffer);
  43.    SetIndexBuffer(3,ExtMacdBuffer);
  44.    SetIndexBuffer(4,ExtSignalBuffer);
  45. //--- name for DataWindow and indicator subwindow label
  46.    SetIndexLabel(1,NULL);
  47.    SetIndexLabel(2,NULL);
  48.   }
  49. //+------------------------------------------------------------------+
  50. //| Accelerator/Decelerator Oscillator                               |
  51. //+------------------------------------------------------------------+
  52. int OnCalculate (const int rates_total,
  53.                  const int prev_calculated,
  54.                  const datetime& time[],
  55.                  const double& open[],
  56.                  const double& high[],
  57.                  const double& low[],
  58.                  const double& close[],
  59.                  const long& tick_volume[],
  60.                  const long& volume[],
  61.                  const int& spread[])
  62.   {
  63.    int    i,limit;
  64.    double prev=0.0,current;
  65. //--- check for rates total
  66.    if(rates_total<=DATA_LIMIT)
  67.       return(0);
  68. //--- last counted bar will be recounted
  69.    limit=rates_total-prev_calculated;
  70.    if(prev_calculated>0)
  71.      {
  72.       limit++;
  73.       prev=ExtMacdBuffer[limit]-ExtSignalBuffer[limit];
  74.      }
  75. //--- macd counted in the 1-st additional buffer
  76.    for(i=0; i<limit; i++)
  77.       ExtMacdBuffer[i]=iMA(NULL,0,PERIOD_FAST,0,MODE_SMA,PRICE_MEDIAN,i)-
  78.                        iMA(NULL,0,PERIOD_SLOW,0,MODE_SMA,PRICE_MEDIAN,i);
  79. //--- signal line counted in the 2-nd additional buffer
  80.    SimpleMAOnBuffer(rates_total,prev_calculated,0,5,ExtMacdBuffer,ExtSignalBuffer);
  81. //--- dispatch values between 2 buffers
  82.    bool up=true;
  83.    for(i=limit-1; i>=0;)
  84.      {
  85.       current=ExtMacdBuffer[i]-ExtSignalBuffer[i];
  86.       if(current>prev)
  87.          up=true;
  88.       if(current<prev)
  89.          up=false;
  90.       if(!up)
  91.         {
  92.          ExtUpBuffer[i]=0.0;
  93.          ExtDnBuffer[i]=current;
  94.         }
  95.       else
  96.         {
  97.          ExtUpBuffer[i]=current;
  98.          ExtDnBuffer[i]=0.0;
  99.         }
  100.       ExtACBuffer[i]=current;
  101.       i--;
  102.       prev=ExtMacdBuffer[i+1]-ExtSignalBuffer[i+1];
  103.      }
  104. //--- done
  105.    return(rates_total);
  106.   }
  107. //+------------------------------------------------------------------+
复制代码




外汇智能交易,成就财富梦想!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则


MT4编程培训|EA定制开发|QQ在线咨询|路路发智能交易研发中心

GMT+8, 2024-12-22 11:12 , Processed in 0.154311 second(s), 27 queries .

© 2009-2022 520EA.com EA668.com

快速回复 返回顶部 返回列表