Advertisement
Guest User

FTNP alerts

a guest
Nov 17th, 2019
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.54 KB | None | 0 0
  1. //+------------------------------------------------------------------+
  2. //| FTNP.mq5 |
  3. //| Copyright 2018, MetaQuotes Software Corp. |
  4. //| https://mql5.com |
  5. //+------------------------------------------------------------------+
  6. #property copyright "Copyright 2018, MetaQuotes Software Corp."
  7. #property link "https://mql5.com"
  8. #property version "1.00"
  9. #property description "Fisher Transform of Normalized Prices indicator"
  10. #property indicator_separate_window
  11. #property indicator_buffers 4
  12. #property indicator_plots 2
  13. //--- plot Fisher
  14. #property indicator_label1 "Fisher"
  15. #property indicator_type1 DRAW_LINE
  16. #property indicator_color1 clrLimeGreen
  17. #property indicator_style1 STYLE_SOLID
  18. #property indicator_width1 1
  19. //--- plot Trigger
  20. #property indicator_label2 "Trigger"
  21. #property indicator_type2 DRAW_LINE
  22. #property indicator_color2 clrRed
  23. #property indicator_style2 STYLE_SOLID
  24. #property indicator_width2 1
  25. //--- input parameters
  26. input uint InpPeriod = 10; // Period
  27. input ENUM_APPLIED_PRICE InpAppliedPrice = PRICE_CLOSE; // Applied price
  28. input int TriggerCandle = 1;
  29. input bool EnableNativeAlerts = true;
  30. input bool EnableSoundAlerts = true;
  31. input bool EnableEmailAlerts = true;
  32. input bool EnablePushAlerts = true;
  33. input string AlertEmailSubject = "";
  34. input string AlertText = "";
  35. input string SoundFileName = "alert.wav";
  36.  
  37. datetime LastAlertTime = D'01.01.1970';
  38. int LastAlertDirection = 0;
  39. //--- indicator buffers
  40. double BufferFisher[];
  41. double BufferTrigger[];
  42. double BufferMA[];
  43. double BufferV[];
  44. //--- global variables
  45. int period;
  46. int handle_ma;
  47. //+------------------------------------------------------------------+
  48. //| Custom indicator initialization function |
  49. //+------------------------------------------------------------------+
  50. int OnInit()
  51. {
  52. //--- set global variables
  53. period=int(InpPeriod<1 ? 1 : InpPeriod);
  54. //--- indicator buffers mapping
  55. SetIndexBuffer(0,BufferFisher,INDICATOR_DATA);
  56. SetIndexBuffer(1,BufferTrigger,INDICATOR_DATA);
  57. SetIndexBuffer(2,BufferMA,INDICATOR_CALCULATIONS);
  58. SetIndexBuffer(3,BufferV,INDICATOR_CALCULATIONS);
  59. //--- setting indicator parameters
  60. IndicatorSetString(INDICATOR_SHORTNAME,"Fisher Transform of Normalized Prices ("+(string)period+")");
  61. IndicatorSetInteger(INDICATOR_DIGITS,Digits());
  62. //--- setting buffer arrays as timeseries
  63. ArraySetAsSeries(BufferFisher,true);
  64. ArraySetAsSeries(BufferTrigger,true);
  65. ArraySetAsSeries(BufferMA,true);
  66. ArraySetAsSeries(BufferV,true);
  67. //--- create MA's handles
  68. ResetLastError();
  69. handle_ma=iMA(NULL,PERIOD_CURRENT,1,0,MODE_SMA,InpAppliedPrice);
  70. if(handle_ma==INVALID_HANDLE)
  71. {
  72. Print("The iMA(1) object was not created: Error ",GetLastError());
  73. return INIT_FAILED;
  74. }
  75. //---
  76. return(INIT_SUCCEEDED);
  77. }
  78. //+------------------------------------------------------------------+
  79. //| Custom indicator iteration function |
  80. //+------------------------------------------------------------------+
  81. int OnCalculate(const int rates_total,
  82. const int prev_calculated,
  83. const datetime &time[],
  84. const double &open[],
  85. const double &high[],
  86. const double &low[],
  87. const double &close[],
  88. const long &tick_volume[],
  89. const long &volume[],
  90. const int &spread[])
  91. {
  92. //--- Проверка и расчёт количества просчитываемых баров
  93. if(rates_total<4) return 0;
  94. //--- Проверка и расчёт количества просчитываемых баров
  95. int limit=rates_total-prev_calculated;
  96. if(limit>1)
  97. {
  98. limit=rates_total-2;
  99. ArrayInitialize(BufferFisher,0);
  100. ArrayInitialize(BufferTrigger,0);
  101. ArrayInitialize(BufferMA,0);
  102. ArrayInitialize(BufferV,0);
  103. }
  104. //--- Подготовка данных
  105. int count=(limit>1 ? rates_total : 1),copied=0;
  106. copied=CopyBuffer(handle_ma,0,0,count,BufferMA);
  107. if(copied!=count) return 0;
  108. //--- Расчёт индикатора
  109. for(int i=limit; i>=0 && !IsStopped(); i--)
  110. {
  111. int bl=ArrayMinimum(BufferMA,i,period);
  112. int bh=ArrayMaximum(BufferMA,i,period);
  113. if(bl==WRONG_VALUE || bh==WRONG_VALUE)
  114. continue;
  115. double MinPr=BufferMA[bl];
  116. double MaxPr=BufferMA[bh];
  117. if(MaxPr!=MinPr)
  118. {
  119. BufferV[i]=0.667*((BufferMA[i]-MinPr)/(MaxPr-MinPr)-0.5+BufferV[i+1]);
  120. BufferV[i]=fmin(BufferV[i], 0.999);
  121. BufferV[i]=fmax(BufferV[i],-0.999);
  122. BufferFisher[i]=0.5*(log((1.0+BufferV[i])/(1.0-BufferV[i]))+BufferFisher[i+1]);
  123. BufferTrigger[i]=BufferFisher[i+1];
  124. }
  125. }
  126. if (((TriggerCandle > 0) && (time[0] > LastAlertTime)) || (TriggerCandle == 0))
  127. {
  128. string Text;
  129. // Up-Line Crosses Down-Line from Below
  130. if (((BufferFisher[TriggerCandle] > BufferTrigger[TriggerCandle]) && (BufferFisher[TriggerCandle+ 1] <= BufferTrigger[TriggerCandle+ 1])) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != 1))))
  131. {
  132. Text = AlertText + "FTNP: " + Symbol() + " - " + EnumToString(Period()) + " - FTNP Crosses SIGNAL from Below.";
  133. if (EnableNativeAlerts) Alert(Text);
  134. if (EnableEmailAlerts) SendMail(AlertEmailSubject + "Aroon Up & Down Alert", Text);
  135. if (EnableSoundAlerts) PlaySound(SoundFileName);
  136. if (EnablePushAlerts) SendNotification(Text);
  137. LastAlertTime = time[0];
  138. LastAlertDirection = 1;
  139. }
  140. // Up-Line Crosses Down-Line from Above
  141. if (((BufferFisher[TriggerCandle] < BufferTrigger[TriggerCandle]) && (BufferFisher[TriggerCandle+ 1] >= BufferTrigger[TriggerCandle+ 1])) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != -1))))
  142. {
  143. Text = AlertText + "FTNP: " + Symbol() + " - " + EnumToString(Period()) + " - FTNP Crosses SIGNAL from Above.";
  144. if (EnableNativeAlerts) Alert(Text);
  145. if (EnableEmailAlerts) SendMail(AlertEmailSubject + "Aroon Up & Down Alert", Text);
  146. if (EnableSoundAlerts) PlaySound(SoundFileName);
  147. if (EnablePushAlerts) SendNotification(Text);
  148. LastAlertTime = time[0];
  149. LastAlertDirection = -1;
  150. }
  151. }
  152. //--- return value of prev_calculated for next call
  153. return(rates_total);
  154. }
  155. //+------------------------------------------------------------------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement