Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 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. if (((TriggerCandle > 0) && (Time[0] > LastAlertTime)) || (TriggerCandle == 0))
  49. {
  50. string Text;
  51. // Bellow 15 Alert
  52. if (((BLGBuffer[TriggerCandle] < 15) && (BLGBuffer[TriggerCandle+ 1] <= 0)) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != 1))))
  53. {
  54. Text = AlertText + "BLGBuffer: " + Symbol() + " - " + EnumToString((ENUM_TIMEFRAMES)Period()) + " - Bellow 15.";
  55. if (EnableNativeAlerts) Alert(Text);
  56. if (EnableEmailAlerts) SendMail(AlertEmailSubject + "BLGBuffer Alert", Text);
  57. if (EnableSoundAlerts) PlaySound(SoundFileName);
  58. if (EnablePushAlerts) SendNotification(Text);
  59. LastAlertTime = Time[0];
  60. LastAlertDirection = 1;
  61. }
  62. // Bellow 8 Alert
  63. if (((BLGBuffer[TriggerCandle] < 8) && (BLGBuffer[TriggerCandle+ 1] >= 0)) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != -1))))
  64. {
  65. Text = AlertText + "BLGBuffer: " + Symbol() + " - " + EnumToString((ENUM_TIMEFRAMES)Period()) + " - Below 8.";
  66. if (EnableNativeAlerts) Alert(Text);
  67. if (EnableEmailAlerts) SendMail(AlertEmailSubject + "BLGBuffer Alert", Text);
  68. if (EnableSoundAlerts) PlaySound(SoundFileName);
  69. if (EnablePushAlerts) SendNotification(Text);
  70. LastAlertTime = Time[0];
  71. LastAlertDirection = -1;
  72. }
  73. }
  74. return(0);
  75. }
  76. //+------------------------------------------------------------------+
  77. //| Momentum |
  78. //+------------------------------------------------------------------+
  79. int start()
  80. {
  81. int i,counted_bars=IndicatorCounted();
  82. //----
  83. if(Bars<=BBPeriod) return(0);
  84. //---- initial zero
  85. if(counted_bars<1)
  86. for(i=1;i<=BBPeriod;i++) BLGBuffer[Bars-i]=0.0;
  87. //----
  88. i=Bars-BBPeriod-1;
  89. if(counted_bars>=BBPeriod) i=Bars-counted_bars-1;
  90. while(i>=0)
  91. {
  92. BLGBuffer[i]= (iBands(NULL,0,BBPeriod,StdDeviation,0,PRICE_CLOSE,MODE_UPPER,i) - iBands(NULL,0,BBPeriod,StdDeviation,0,PRICE_CLOSE,MODE_LOWER,i))
  93. /iMA(NULL,0,BBPeriod,0,MODE_SMA,PRICE_CLOSE,i);
  94. i--;
  95. }
  96. return(0);
  97. }
  98. //+------------------------------------------------------------------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement