Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. //+-------------------------------------------------------------------+
  2. //| Bandswidth.mq4 |
  3. //| by Linuxser for Forex TSD |
  4. //| |
  5. //| John Bollinger original formula is: |
  6. //| (Upper BB - Lower BB)/middle BB |
  7. //+-------------------------------------------------------------------+
  8. #property copyright ""
  9. #property link ""
  10.  
  11. #property indicator_separate_window
  12. #property indicator_buffers 1
  13. #property indicator_color1 Yellow
  14.  
  15.  
  16. //---- input parameters
  17. extern int BBPeriod=20;
  18. extern int StdDeviation=2;
  19. input int TriggerCandle = 1;
  20. input bool EnableNativeAlerts = true;
  21. input bool EnableSoundAlerts = true;
  22. input bool EnableEmailAlerts = true;
  23. input bool EnablePushAlerts = true;
  24. input string AlertEmailSubject = "";
  25. input string AlertText = "";
  26. input string SoundFileName = "alert.wav";
  27.  
  28. datetime LastAlertTime = D'01.01.1970';
  29. int LastAlertDirection = 0;
  30. //---- buffers
  31. double BLGBuffer[];
  32. //+------------------------------------------------------------------+
  33. //| Custom indicator initialization function |
  34. //+------------------------------------------------------------------+
  35. int init()
  36. {
  37. string short_name;
  38. //---- indicator line
  39. SetIndexStyle(0,DRAW_LINE);
  40. SetIndexBuffer(0,BLGBuffer);
  41. //---- name for DataWindow and indicator subwindow label
  42. short_name="Bandswidth("+BBPeriod+","+StdDeviation+")";
  43. IndicatorShortName(short_name);
  44. SetIndexLabel(0,short_name);
  45. //----
  46. SetIndexDrawBegin(0,BBPeriod);
  47. //----
  48.  
  49. return(0);
  50. }
  51. //+------------------------------------------------------------------+
  52. //| Momentum |
  53. //+------------------------------------------------------------------+
  54. int start()
  55. {
  56. int i,counted_bars=IndicatorCounted();
  57. //----
  58. if(Bars<=BBPeriod) return(0);
  59. //---- initial zero
  60. if(counted_bars<1)
  61. for(i=1;i<=BBPeriod;i++) BLGBuffer[Bars-i]=0.0;
  62. //----
  63. i=Bars-BBPeriod-1;
  64. if(counted_bars>=BBPeriod) i=Bars-counted_bars-1;
  65. while(i>=0)
  66. {
  67. BLGBuffer[i]= (iBands(NULL,0,BBPeriod,StdDeviation,0,PRICE_CLOSE,MODE_UPPER,i) - iBands(NULL,0,BBPeriod,StdDeviation,0,PRICE_CLOSE,MODE_LOWER,i))
  68. /iMA(NULL,0,BBPeriod,0,MODE_SMA,PRICE_CLOSE,i);
  69. i--;
  70. }
  71. if (((TriggerCandle > 0) && (Time[0] > LastAlertTime)) || (TriggerCandle == 0))
  72. {
  73. string Text;
  74. // Bellow 0.0015 Alert
  75. if (((BLGBuffer[TriggerCandle] < 0.0015) && (BLGBuffer[TriggerCandle+ 1] >= 0)) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != -1))))
  76. {
  77. Text = AlertText + "BLGBuffer: " + Symbol() + " - " + EnumToString((ENUM_TIMEFRAMES)Period()) + " - Bellow 0.0015.";
  78. if (EnableNativeAlerts) Alert(Text);
  79. if (EnableEmailAlerts) SendMail(AlertEmailSubject + "BLGBuffer Alert", Text);
  80. if (EnableSoundAlerts) PlaySound(SoundFileName);
  81. if (EnablePushAlerts) SendNotification(Text);
  82. LastAlertTime = Time[0];
  83. LastAlertDirection = 1;
  84. }
  85. // Bellow 0.0008 Alert
  86. if (((BLGBuffer[TriggerCandle] < 0.0008) && (BLGBuffer[TriggerCandle+ 1] >= 0)) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != -1))))
  87. {
  88. Text = AlertText + "BLGBuffer: " + Symbol() + " - " + EnumToString((ENUM_TIMEFRAMES)Period()) + " - Below 0.0008.";
  89. if (EnableNativeAlerts) Alert(Text);
  90. if (EnableEmailAlerts) SendMail(AlertEmailSubject + "BLGBuffer Alert", Text);
  91. if (EnableSoundAlerts) PlaySound(SoundFileName);
  92. if (EnablePushAlerts) SendNotification(Text);
  93. LastAlertTime = Time[0];
  94. LastAlertDirection = -1;
  95. }
  96. }
  97. return(0);
  98. }
  99. //+------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement