7评论

1收藏

ADX_WildersDMI_v1.02 alerts

avatar admin | 1435 人阅读 | 7 人评论 | 2018-01-22

XAUUSDH1.png

  1. //+------------------------------------------------------------------+
  2. //|                                                WildersDMI_v1.mq4 |
  3. //|                           Copyright ?2007, TrendLaboratory Ltd. |
  4. //|            http://finance.groups.yahoo.com/group/TrendLaboratory |
  5. //|                                       E-mail: igorad2004@list.ru |
  6. //+------------------------------------------------------------------+
  7. #property copyright "Copyright ?2007, TrendLaboratory Ltd."
  8. #property link      "http://finance.groups.yahoo.com/group/TrendLaboratory"
  9. //----
  10. #property indicator_separate_window
  11. #property indicator_buffers   4
  12. #property indicator_color1    LightBlue
  13. #property indicator_width1    2
  14. #property indicator_color2    Blue
  15. #property indicator_width2    1
  16. #property indicator_style2    2
  17. #property indicator_color3    Black
  18. #property indicator_width3    1
  19. #property indicator_style3    2
  20. #property indicator_color4    Orange
  21. #property indicator_width4    2
  22. #property indicator_levelcolor Yellow
  23. //---- input parameters
  24. extern int       MA_Length  =13; // Period of additional smoothing
  25. extern int       DMI_Length  =13; // Period of DMI
  26. extern int       ADX_Length  =14; // Period of ADX
  27. extern int       ADXR_Length =14; // Period of ADXR
  28. extern int       UseADX     =0; // Use ADX: 0-off,1-on
  29. extern int       UseADXR    =0; // Use ADXR: 0-off,1-on

  30. extern double Level                      = 20.0;
  31. extern string note                       = "turn on Alert = true; turn off = false";
  32. extern bool   alertsOn                   = true;
  33. extern bool   alertsOnCurrent            = true;
  34. extern bool   alertsOnLevelCross         = true;
  35. extern bool   alertsOnDiPlusDiMinusCross = true;
  36. extern bool   alertsMessage              = true;
  37. extern bool   alertsSound                = true;
  38. extern bool   alertsNotify               = true;
  39. extern bool   alertsEmail                = false;
  40. extern string soundFile                  = "alert2.wav";

  41. //---- buffers
  42. double ADX[];
  43. double PDI[];
  44. double MDI[];
  45. double ADXR[];
  46. double sPDI[];
  47. double sMDI[];
  48. double STR[];
  49. double DX[];
  50. double trend[];
  51. double trend1[];
  52. //+------------------------------------------------------------------+
  53. //| Custom indicator initialization function                         |
  54. //+------------------------------------------------------------------+
  55. int init()
  56.   {
  57. //---- indicators
  58.    IndicatorBuffers(10);
  59.    SetIndexStyle(0,DRAW_LINE);
  60.    SetIndexBuffer(0,ADX);
  61.    SetIndexStyle(1,DRAW_LINE,0,2);
  62.    SetIndexBuffer(1,PDI);
  63.    SetIndexStyle(2,DRAW_LINE,0,2);
  64.    SetIndexBuffer(2,MDI);
  65.    SetIndexStyle(3,DRAW_LINE);
  66.    SetIndexBuffer(3,ADXR);
  67.    SetIndexBuffer(4,sPDI);
  68.    SetIndexBuffer(5,sMDI);
  69.    SetIndexBuffer(6,STR);
  70.    SetIndexBuffer(7,DX);
  71.    SetIndexBuffer(8,trend);
  72.    SetIndexBuffer(9,trend1);
  73.    SetLevelValue(0,Level);
  74. //---- name for DataWindow and indicator subwindow label
  75.    string short_name="WildersDMI("+MA_Length+","+DMI_Length+","+ADX_Length+","+ADXR_Length+")";
  76.    IndicatorShortName(short_name);
  77.    SetIndexLabel(0,"ADX");
  78.    SetIndexLabel(1,"+DI");
  79.    SetIndexLabel(2,"-DI");
  80.    SetIndexLabel(3,"ADXR");
  81. //----
  82.    SetIndexDrawBegin(0,DMI_Length+MA_Length);
  83.    SetIndexDrawBegin(1,DMI_Length+MA_Length);
  84.    SetIndexDrawBegin(2,DMI_Length+MA_Length);
  85.    SetIndexDrawBegin(3,DMI_Length+MA_Length);
  86.    SetIndexShift(3,2);
  87. //----
  88.    return(0);
  89.   }
  90. //+------------------------------------------------------------------+
  91. //| Custom indicator iteration function                              |
  92. //+------------------------------------------------------------------+
  93. int start()
  94.   {
  95.    int      shift, counted_bars=IndicatorCounted();
  96.    double alfa1=1.0/DMI_Length;
  97.    double alfa2=1.0/ADX_Length;
  98. //----
  99.    if (counted_bars < 0) return(-1);
  100.    if(counted_bars<1)
  101.       for(shift=1;shift<=MA_Length+DMI_Length;shift++)
  102.         {
  103.          PDI[Bars-shift]=0.0;MDI[Bars-shift]=0.0;ADX[Bars-shift]=0.0;
  104.          sPDI[Bars-shift]=0.0;sMDI[Bars-shift]=0.0;DX[Bars-shift]=0.0;
  105.          STR[Bars-shift]=0.0;ADXR[Bars-shift]=0.0;
  106.         }
  107.    shift=Bars-MA_Length-DMI_Length-1;
  108.    if(counted_bars>=DMI_Length+MA_Length) shift=Bars-counted_bars-1;
  109.    while(shift>=0)
  110.      {
  111.       double AvgHigh =iMA(NULL,0,MA_Length,0,1,PRICE_HIGH,shift);
  112.       double AvgHigh1=iMA(NULL,0,MA_Length,0,1,PRICE_HIGH,shift+1);
  113.       double AvgLow  =iMA(NULL,0,MA_Length,0,1,PRICE_LOW,shift);
  114.       double AvgLow1 =iMA(NULL,0,MA_Length,0,1,PRICE_LOW,shift+1);
  115.       double AvgClose1= iMA(NULL,0,MA_Length,0,1,PRICE_CLOSE,shift+1);
  116. //----
  117.       double Bulls=0.5*(MathAbs(AvgHigh-AvgHigh1)+(AvgHigh-AvgHigh1));
  118.       double Bears=0.5*(MathAbs(AvgLow1-AvgLow)+(AvgLow1-AvgLow));
  119.       if (Bulls > Bears) Bears=0;
  120.       else
  121.          if (Bulls < Bears) Bulls=0;
  122.          else
  123.             if (Bulls==Bears) {Bulls=0;Bears=0;}
  124. //----            
  125.       sPDI[shift]=sPDI[shift+1] + alfa1 * (Bulls - sPDI[shift+1]);
  126.       sMDI[shift]=sMDI[shift+1] + alfa1 * (Bears - sMDI[shift+1]);
  127. //----      
  128.       double   TR=MathMax(AvgHigh-AvgLow,AvgHigh-AvgClose1);
  129.       STR[shift] =STR[shift+1] + alfa1 * (TR - STR[shift+1]);
  130.       if(STR[shift]>0 )
  131.         {
  132.          PDI[shift]=100*sPDI[shift]/STR[shift];
  133.          MDI[shift]=100*sMDI[shift]/STR[shift];
  134.         }
  135.       if(UseADX > 0)
  136.         {
  137.          if((PDI[shift] + MDI[shift])>0)
  138.             DX[shift]=100*MathAbs(PDI[shift] - MDI[shift])/(PDI[shift] + MDI[shift]);
  139.          else DX[shift]=0;
  140. //----
  141.          ADX[shift]=ADX[shift+1] + alfa2 *(DX[shift] - ADX[shift+1]);
  142.          if(UseADXR >0) ADXR[shift]=0.5*(ADX[shift] + ADX[shift+ADXR_Length]);
  143.         }
  144.         trend[shift] = 0;
  145.         trend1[shift] = trend1[shift+1];
  146.         if (ADX[shift] > Level)      trend[shift]  = 1;
  147.         if (ADX[shift] < Level)      trend[shift]  =-1;
  148.         if (PDI[shift] > MDI[shift]) trend1[shift] = 1;
  149.         if (PDI[shift] < MDI[shift]) trend1[shift] =-1;
  150.         shift--;
  151.      }
  152.      
  153.      //
  154.      //
  155.      //
  156.      //
  157.      //
  158.             
  159.      if (alertsOn)
  160.       {
  161.         if (alertsOnCurrent)
  162.              int whichBar = 0;
  163.         else     whichBar = 1;
  164.    
  165.         //
  166.         //
  167.         //
  168.         //
  169.         //
  170.       
  171.         static datetime time1 = 0;
  172.         static string   mess1 = "";
  173.            if (alertsOnLevelCross && trend[whichBar] != trend[whichBar+1])
  174.            {
  175.               if (trend[whichBar] == 1) doAlert(time1,mess1,whichBar,"  up");
  176.               if (trend[whichBar] ==-1) doAlert(time1,mess1,whichBar,"  down");
  177.            }            
  178.         static datetime time2 = 0;
  179.         static string   mess2 = "";
  180.            if (alertsOnDiPlusDiMinusCross && trend1[whichBar] != trend1[whichBar+1])
  181.            {
  182.               if (trend1[whichBar] == 1) doAlert(time2,mess2,whichBar," DMI UP ");
  183.               if (trend1[whichBar] ==-1) doAlert(time2,mess2,whichBar," DMI DOWN");
  184.            }                        
  185. }
  186. return(0);
  187. }  
  188.   //
  189. //
  190. //
  191. //
  192. //

  193. void doAlert(datetime& previousTime, string& previousAlert, int forBar, string doWhat)
  194. {
  195.    string message;
  196.    
  197.       if (previousAlert != doWhat || previousTime != Time[forBar]) {
  198.           previousAlert  = doWhat;
  199.           previousTime   = Time[forBar];

  200.           //
  201.           //
  202.           //
  203.           //
  204.           //

  205.           message =  StringConcatenate(AccountNumber()," - ",Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS),"   ",doWhat);
  206.              if (alertsMessage) Alert(message);
  207.              if (alertsEmail)   SendMail(StringConcatenate(Symbol(),"   "),message);
  208.              if (alertsNotify)  SendNotification(message);
  209.              if (alertsSound)   PlaySound(soundFile);
  210.       }
  211. }
  212.       


复制代码



ADX_WildersDMI_v1.02 alerts.mq4
""
还没有人打赏,支持一下

评论|共 7 个

怨女

发表于 2020-6-20 14:39:39 | 显示全部楼层

我抢、我抢、我抢沙发~

文静

发表于 2020-7-17 16:31:08 | 显示全部楼层

帮你顶下哈!!

笑看风云

发表于 2020-8-9 12:50:52 | 显示全部楼层

帮你顶下哈!!

srdke

发表于 2020-8-28 14:44:24 | 显示全部楼层

学习了,不错

天眼

发表于 2020-11-7 21:45:48 | 显示全部楼层

tafeg8a

发表于 2020-11-25 21:33:19 | 显示全部楼层

谢谢

明注册韩国

发表于 2021-8-9 15:38:33 | 显示全部楼层

顶下

您需要登录后才可以回帖 登录 | 注册 微信登录

EA之家评论守则