Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //+-------------------------------------------------------------------+
- //| Bandswidth.mq4 |
- //| by Linuxser for Forex TSD |
- //| |
- //| John Bollinger original formula is: |
- //| (Upper BB - Lower BB)/middle BB |
- //+-------------------------------------------------------------------+
- #property copyright ""
- #property link ""
- #property indicator_separate_window
- #property indicator_buffers 1
- #property indicator_color1 Yellow
- //---- input parameters
- extern int BBPeriod=20;
- extern int StdDeviation=2;
- input int TriggerCandle = 1;
- input bool EnableNativeAlerts = true;
- input bool EnableSoundAlerts = true;
- input bool EnableEmailAlerts = true;
- input bool EnablePushAlerts = true;
- input string AlertEmailSubject = "";
- input string AlertText = "";
- input string SoundFileName = "alert.wav";
- datetime LastAlertTime = D'01.01.1970';
- int LastAlertDirection = 0;
- //---- buffers
- double BLGBuffer[];
- //+------------------------------------------------------------------+
- //| Custom indicator initialization function |
- //+------------------------------------------------------------------+
- int init()
- {
- string short_name;
- //---- indicator line
- SetIndexStyle(0,DRAW_LINE);
- SetIndexBuffer(0,BLGBuffer);
- //---- name for DataWindow and indicator subwindow label
- short_name="Bandswidth("+BBPeriod+","+StdDeviation+")";
- IndicatorShortName(short_name);
- SetIndexLabel(0,short_name);
- //----
- SetIndexDrawBegin(0,BBPeriod);
- //----
- if (((TriggerCandle > 0) && (Time[0] > LastAlertTime)) || (TriggerCandle == 0))
- {
- string Text;
- // Bellow 15 Alert
- if (((BLGBuffer[TriggerCandle] < 15) && (BLGBuffer[TriggerCandle+ 1] <= 0)) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != 1))))
- {
- Text = AlertText + "BLGBuffer: " + Symbol() + " - " + EnumToString((ENUM_TIMEFRAMES)Period()) + " - Bellow 15.";
- if (EnableNativeAlerts) Alert(Text);
- if (EnableEmailAlerts) SendMail(AlertEmailSubject + "BLGBuffer Alert", Text);
- if (EnableSoundAlerts) PlaySound(SoundFileName);
- if (EnablePushAlerts) SendNotification(Text);
- LastAlertTime = Time[0];
- LastAlertDirection = 1;
- }
- // Bellow 8 Alert
- if (((BLGBuffer[TriggerCandle] < 8) && (BLGBuffer[TriggerCandle+ 1] >= 0)) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != -1))))
- {
- Text = AlertText + "BLGBuffer: " + Symbol() + " - " + EnumToString((ENUM_TIMEFRAMES)Period()) + " - Below 8.";
- if (EnableNativeAlerts) Alert(Text);
- if (EnableEmailAlerts) SendMail(AlertEmailSubject + "BLGBuffer Alert", Text);
- if (EnableSoundAlerts) PlaySound(SoundFileName);
- if (EnablePushAlerts) SendNotification(Text);
- LastAlertTime = Time[0];
- LastAlertDirection = -1;
- }
- }
- return(0);
- }
- //+------------------------------------------------------------------+
- //| Momentum |
- //+------------------------------------------------------------------+
- int start()
- {
- int i,counted_bars=IndicatorCounted();
- //----
- if(Bars<=BBPeriod) return(0);
- //---- initial zero
- if(counted_bars<1)
- for(i=1;i<=BBPeriod;i++) BLGBuffer[Bars-i]=0.0;
- //----
- i=Bars-BBPeriod-1;
- if(counted_bars>=BBPeriod) i=Bars-counted_bars-1;
- while(i>=0)
- {
- BLGBuffer[i]= (iBands(NULL,0,BBPeriod,StdDeviation,0,PRICE_CLOSE,MODE_UPPER,i) - iBands(NULL,0,BBPeriod,StdDeviation,0,PRICE_CLOSE,MODE_LOWER,i))
- /iMA(NULL,0,BBPeriod,0,MODE_SMA,PRICE_CLOSE,i);
- i--;
- }
- return(0);
- }
- //+------------------------------------------------------------------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement