SHARE
TWEET

Untitled

fx_rising007 Dec 27th, 2018 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //+------------------------------------------------------------------+
  2. //|                                                   ADXcrosses.mq4 |
  3. //|                      Copyright © 2004, MetaQuotes Software Corp. |
  4. //|                                        http://www.metaquotes.net |
  5. //+------------------------------------------------------------------+
  6. #property copyright "Copyright © 2004, MetaQuotes Software Corp."
  7. #property link "http://www.metaquotes.net"
  8.  
  9. #property indicator_chart_window
  10. #property indicator_buffers 2
  11. #property indicator_color1 Blue
  12. #property indicator_color2 Red
  13. //---- input parameters
  14. extern int ADXcrossesPeriod = 14;
  15. //---- Alert Parameters
  16. input int    TriggerCandle  = 1;
  17. input bool   EnableNativeAlerts = true;
  18. input bool   EnableSoundAlerts  = true;
  19. input bool   EnableEmailAlerts  = true;
  20. input bool   EnablePushAlerts  = true;
  21. input string AlertEmailSubject  = "";
  22. input string AlertText      = "";
  23. input string SoundFileName  = "alert.wav";
  24.  
  25. datetime LastAlertTime = D'01.01.1970';
  26. int LastAlertDirection = 0;
  27. //---- buffers
  28. double ExtMapBuffer1[];
  29. double ExtMapBuffer2[];
  30. //----
  31. double b4plusdi, b4minusdi, nowplusdi, nowminusdi;
  32. int    nShift;  
  33. //+------------------------------------------------------------------+
  34. //| Custom indicator initialization function                         |
  35. //+------------------------------------------------------------------+
  36. int init()
  37.   {
  38. //---- indicators
  39.     SetIndexStyle(0, DRAW_ARROW, 0, 1);
  40.     SetIndexArrow(0, 233);
  41.     SetIndexBuffer(0, ExtMapBuffer1);
  42. //----
  43.     SetIndexStyle(1, DRAW_ARROW, 0, 1);
  44.     SetIndexArrow(1, 234);
  45.     SetIndexBuffer(1, ExtMapBuffer2);
  46. //---- name for DataWindow and indicator subwindow label
  47.     IndicatorShortName("ADXcrosses(" + ADXcrossesPeriod + ")");
  48.     SetIndexLabel(0, "ADXcrUp");
  49.     SetIndexLabel(1, "ADXcrDn");
  50. //----
  51.     switch(Period())
  52.       {
  53.         case     1: nShift = 1;   break;    
  54.         case     5: nShift = 3;   break;
  55.         case    15: nShift = 5;   break;
  56.         case    30: nShift = 10;  break;
  57.         case    60: nShift = 15;  break;
  58.         case   240: nShift = 20;  break;
  59.         case  1440: nShift = 80;  break;
  60.         case 10080: nShift = 100; break;
  61.         case 43200: nShift = 200; break;              
  62.       }
  63. //----
  64.     return(0);
  65.   }
  66. //+------------------------------------------------------------------+
  67. //| Custor indicator deinitialization function                       |
  68. //+------------------------------------------------------------------+
  69. int deinit()
  70.   {
  71. //----
  72.     return(0);
  73.   }
  74. //+------------------------------------------------------------------+
  75. //| Custom indicator iteration function                              |
  76. //+------------------------------------------------------------------+
  77. int start()
  78.   {
  79.     int limit;
  80.     int counted_bars = IndicatorCounted();
  81. //---- check for possible errors
  82.     if(counted_bars < 0)
  83.         return(-1);
  84. //---- last counted bar will be recounted
  85.     if(counted_bars > 0)
  86.         counted_bars--;
  87.     limit = Bars - counted_bars;
  88. //----
  89.     for(int i = 0; i < limit; i++)
  90.       {
  91.         b4plusdi = iADX(NULL, 0, ADXcrossesPeriod, PRICE_CLOSE, MODE_PLUSDI, i + 1);
  92.         nowplusdi = iADX(NULL, 0, ADXcrossesPeriod, PRICE_CLOSE, MODE_PLUSDI, i);
  93.         b4minusdi = iADX(NULL, 0, ADXcrossesPeriod, PRICE_CLOSE, MODE_MINUSDI, i + 1);
  94.         nowminusdi = iADX(NULL, 0, ADXcrossesPeriod, PRICE_CLOSE, MODE_MINUSDI, i);  
  95.         //----
  96.         if(b4plusdi < b4minusdi && nowplusdi > nowminusdi)
  97.             ExtMapBuffer1[i] = Low[i] - nShift*Point;
  98.         //----
  99.         if(b4plusdi > b4minusdi && nowplusdi < nowminusdi)
  100.             ExtMapBuffer2[i] = High[i] + nShift*Point;
  101.       }
  102. //----
  103.  
  104.       if (((TriggerCandle > 0) && (Time[0] > LastAlertTime)) || (TriggerCandle == 0))
  105. {
  106.     string Text;
  107.     // Up Arrow Alert
  108.     if ((ExtMapBuffer1[TriggerCandle] > 0) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != 1))))
  109.     {
  110.         Text = AlertText + "ADX_Cross Arrows: " + Symbol() + " - " + EnumToString((ENUM_TIMEFRAMES)Period()) + " - Up.";
  111.         if (EnableNativeAlerts) Alert(Text);
  112.         if (EnableEmailAlerts) SendMail(AlertEmailSubject + "ADX_Cross Arrows Alert", Text);
  113.         if (EnableSoundAlerts) PlaySound(SoundFileName);
  114.         if (EnablePushAlerts) SendNotification(Text);
  115.         LastAlertTime = Time[0];
  116.         LastAlertDirection = 1;
  117.     }
  118.     // Down Arrow Alert
  119.     if ((ExtMapBuffer2[TriggerCandle] > 0) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != -1))))
  120.     {
  121.         Text = AlertText + "ADX_Cross Arrows: " + Symbol() + " - " + EnumToString((ENUM_TIMEFRAMES)Period()) + " - Down.";
  122.         if (EnableNativeAlerts) Alert(Text);
  123.         if (EnableEmailAlerts) SendMail(AlertEmailSubject + "ADX_Cross Arrows Alert", Text);
  124.         if (EnableSoundAlerts) PlaySound(SoundFileName);
  125.         if (EnablePushAlerts) SendNotification(Text);
  126.         LastAlertTime = Time[0];
  127.         LastAlertDirection = -1;
  128.     }
  129.    
  130.     //----
  131.      
  132.     return(0);
  133.   }
  134. //+------------------------------------------------------------------+
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top