SHARE
TWEET

Untitled

Nigeld Jul 27th, 2017 33 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //+------------------------------------------------------------------+
  2. //|                                                  Force_Index.mq5 |
  3. //|                   Copyright 2009-2017, MetaQuotes Software Corp. |
  4. //|                                              http://www.mql5.com |
  5. //+------------------------------------------------------------------+
  6. #property copyright "2009-2017, MetaQuotes Software Corp."
  7. #property link      "http://www.mql5.com"
  8. //--- indicator settings
  9. #property indicator_separate_window
  10. #property indicator_buffers 2
  11. #property indicator_plots   1
  12. #property indicator_type1   DRAW_LINE
  13. #property indicator_color1  DodgerBlue
  14. //--- input parameters
  15. input int                 InpForcePeriod=13;             // Period
  16. input ENUM_MA_METHOD      InpMAMethod=MODE_SMA;          // MA method
  17. input ENUM_APPLIED_PRICE  InpAppliedPrice=PRICE_CLOSE;   // Applied price
  18. input ENUM_APPLIED_VOLUME InpAppliedVolume=VOLUME_TICK;  // Volumes
  19. input int    TriggerCandle  = 1;
  20. input bool   EnableNativeAlerts = true;
  21. input bool   EnableSoundAlerts  = true;
  22. input bool   EnableEmailAlerts  = true;
  23. input string AlertEmailSubject  = "";
  24. input string AlertText      = "";
  25. input string SoundFileName  = "alert.wav";
  26.  
  27. datetime LastAlertTime = D'01.01.1970';
  28. int LastAlertDirection = 0;
  29. //--- indicator buffers
  30. double                    ExtForceBuffer[];
  31. double                    ExtMABuffer[];
  32. //--- MA handle
  33. int                       ExtMAHandle;
  34. //+------------------------------------------------------------------+
  35. //| Custom indicator initialization function                         |
  36. //+------------------------------------------------------------------+
  37. void OnInit()
  38.   {
  39. //--- indicator buffers mapping
  40.    SetIndexBuffer(0,ExtForceBuffer,INDICATOR_DATA);
  41.    SetIndexBuffer(1,ExtMABuffer,INDICATOR_CALCULATIONS);
  42. //--- sets first bar from what index will be drawn
  43.    PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpForcePeriod);
  44. //--- name for DataWindow and indicator subwindow label
  45.    IndicatorSetString(INDICATOR_SHORTNAME,"Force("+string(InpForcePeriod)+")");
  46. //--- get MA handle
  47.    ExtMAHandle=iMA(NULL,0,InpForcePeriod,0,InpMAMethod,InpAppliedPrice);
  48. //--- initialization done
  49.   }
  50. //+------------------------------------------------------------------+
  51. //| Force Index                                                      |
  52. //+------------------------------------------------------------------+
  53. int OnCalculate(const int rates_total,
  54.                 const int prev_calculated,
  55.                 const datetime &time[],
  56.                 const double &open[],
  57.                 const double &high[],
  58.                 const double &low[],
  59.                 const double &close[],
  60.                 const long &tick_volume[],
  61.                 const long &volume[],
  62.                 const int &spread[])
  63.   {
  64.    int i,limit;
  65. //--- check for rates total
  66.    if(rates_total<InpForcePeriod)
  67.       return(0);
  68. //---
  69.    int calculated=BarsCalculated(ExtMAHandle);
  70.    if(calculated<rates_total)
  71.      {
  72.       Print("Not all data of ExtMAHandle is calculated (",calculated,"bars ). Error",GetLastError());
  73.       return(0);
  74.      }
  75. //--- we can copy not all data
  76.    int to_copy;
  77.    if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
  78.    else
  79.      {
  80.       to_copy=rates_total-prev_calculated;
  81.       if(prev_calculated>0) to_copy++;
  82.      }
  83. //---- get ma buffer
  84.    if(IsStopped()) return(0); //Checking for stop flag
  85.    if(CopyBuffer(ExtMAHandle,0,0,to_copy,ExtMABuffer)<=0)
  86.      {
  87.       Print("Getting MA data is failed! Error",GetLastError());
  88.       return(0);
  89.      }
  90. //--- preliminary calculations
  91.    if(prev_calculated<InpForcePeriod)
  92.       limit=InpForcePeriod;
  93.    else limit=prev_calculated-1;
  94. //--- the main loop of calculations
  95.    if(InpAppliedVolume==VOLUME_TICK)
  96.      {
  97.       for(i=limit;i<rates_total && !IsStopped();i++)
  98.          ExtForceBuffer[i]=tick_volume[i]*(ExtMABuffer[i]-ExtMABuffer[i-1]);
  99.          if (((TriggerCandle > 0) && (time[rates_total - 1] > LastAlertTime)) || (TriggerCandle == 0))
  100. {
  101.     string Text;
  102.     // Above Zero Alert
  103.     if (((Coppock[TriggerCandle] > 0) && (Coppock[rates_total - 2 - TriggerCandle] <= 0)) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != 1))))
  104.     {
  105.         Text = AlertText + "Coppock: " + Symbol() + " - " + EnumToString(Period()) + " - Above Zero.";
  106.         if (EnableNativeAlerts) Alert(Text);
  107.         if (EnableEmailAlerts) SendMail(AlertEmailSubject + "Coppock Alert", Text);
  108.         if (EnableSoundAlerts) PlaySound(SoundFileName);
  109.         LastAlertTime = time[rates_total - 1];
  110.         LastAlertDirection = 1;
  111.     }
  112.     // Below Zero Alert
  113.     if (((Coppock[rates_total - 1 - TriggerCandle] < 0) && (Coppock[rates_total - 2 - TriggerCandle] >= 0)) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != -1))))
  114.     {
  115.         Text = AlertText + "Coppock: " + Symbol() + " - " + EnumToString(Period()) + " - Below Zero.";
  116.         if (EnableNativeAlerts) Alert(Text);
  117.         if (EnableEmailAlerts) SendMail(AlertEmailSubject + "Coppock Alert", Text);
  118.         if (EnableSoundAlerts) PlaySound(SoundFileName);
  119.         LastAlertTime = time[rates_total - 1];
  120.         LastAlertDirection = -1;
  121.     }
  122. }
  123.      }
  124.    else
  125.      {
  126.       for(i=limit;i<rates_total && !IsStopped();i++)
  127.          ExtForceBuffer[i]=volume[i]*(ExtMABuffer[i]-ExtMABuffer[i-1]);if (((TriggerCandle > 0) && (time[rates_total - 1] > LastAlertTime)) || (TriggerCandle == 0))
  128. {
  129.     string Text;
  130.     // Above Zero Alert
  131.     if (((Coppock[rates_total - 1 - TriggerCandle] > 0) && (Coppock[rates_total - 2 - TriggerCandle] <= 0)) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != 1))))
  132.     {
  133.         Text = AlertText + "Coppock: " + Symbol() + " - " + EnumToString(Period()) + " - Above Zero.";
  134.         if (EnableNativeAlerts) Alert(Text);
  135.         if (EnableEmailAlerts) SendMail(AlertEmailSubject + "Coppock Alert", Text);
  136.         if (EnableSoundAlerts) PlaySound(SoundFileName);
  137.         LastAlertTime = time[rates_total - 1];
  138.         LastAlertDirection = 1;
  139.     }
  140.     // Below Zero Alert
  141.     if (((Coppock[rates_total - 1 - TriggerCandle] < 0) && (Coppock[rates_total - 2 - TriggerCandle] >= 0)) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != -1))))
  142.     {
  143.         Text = AlertText + "Coppock: " + Symbol() + " - " + EnumToString(Period()) + " - Below Zero.";
  144.         if (EnableNativeAlerts) Alert(Text);
  145.         if (EnableEmailAlerts) SendMail(AlertEmailSubject + "Coppock Alert", Text);
  146.         if (EnableSoundAlerts) PlaySound(SoundFileName);
  147.         LastAlertTime = time[rates_total - 1];
  148.         LastAlertDirection = -1;
  149.     }
  150. }
  151.      }
  152. //--- OnCalculate done. Return new prev_calculated.
  153.    return(rates_total);
  154.   }
  155. //+------------------------------------------------------------------+
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
 
Top