Indicators Used
Bollinger bands indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
GT_BB
//+------------------------------------------------------------------+
//|                                                        GT BB.mq4 |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red

extern bool Allert = True;
//+------------------------------------------------------------------+
extern int BBPeriod    = 20;
extern int BBDeviation = 2;
extern int BBPrice     = 0;
//-------------------------------------------------------------------+
extern int MA          = 20; //
extern int Mode        = 0; // 0=SMA,1=EMA,2=SSMA,3=LWMA
extern int Price       = 0; // 0=Close,1=Open,2=High,3=Low,4=Median,5=Typical,6=Weighted
//-------------------------------------------------------------------+
double BuyBuffer[],SellBuffer[];
int pre_signal = 0;
//+------------------------------------------------------------------+
int init()
  {
      IndicatorShortName("GT BB");
//----
      SetIndexBuffer(0, BuyBuffer);
      SetIndexLabel(0, "Buy");
      SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID, 2);
      SetIndexArrow(0, 241);
//----
      SetIndexBuffer(1, SellBuffer);
      SetIndexLabel(1, "Sell");
      SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID, 2);
      SetIndexArrow(1, 242);
//----
      return(0);
  }
//+------------------------------------------------------------------+
int deinit()
  {
      return(0);
  }
//+------------------------------------------------------------------+
int start()
  {
      int counted_bars = IndicatorCounted();
//----
      if(counted_bars < 0) 
        { 
          Print("Indicator Error (Counted bars < 0)!"); 
          return(-1); 
        }
//----
      if(Bars < 17) 
        { 
          Print("Indicator Error (Bars < 12)!" ); 
          return(-1); 
        }
   int limit = Bars - 17;
//----
   if(counted_bars > 17) 
     { 
       limit = Bars - counted_bars; 
     }
//+------------------------------------------------------------------+
      for(int i = limit; i >= 0; i --)
        {
             BuyBuffer[i] = EMPTY_VALUE;
             SellBuffer[i] = EMPTY_VALUE;       
//--------------------------------------------------------------------+
      double BBup = iBands(NULL,0,BBPeriod,BBDeviation,0,BBPrice, MODE_UPPER,i+1);
      double BBlo = iBands(NULL,0,BBPeriod,BBDeviation,0,BBPrice, MODE_LOWER,i+1);
      double MAnow = iMA(NULL,0,MA,0,Mode,Price,i);
      double MApre = iMA(NULL,0,MA,0,Mode,Price,i+1);    
//--------------------------------------------------------------------+
      if(Low[i+1] < BBlo && MAnow > MApre)
               {
               BuyBuffer[i] = Low[i];
               }
      if(High[i+1] > BBup && MAnow < MApre)
               {
               SellBuffer[i] = High[i];
               }
        }         
//--------------------------------------------------------------------+        
      if(Allert)
        {
             if(pre_signal <= 0 && BuyBuffer [i+1] != EMPTY_VALUE) 
               { 
                 Alert("GT BB","  BUY! ",Symbol()," ", Period());
                 pre_signal =  1; 
               }
             if(pre_signal >= 0 && SellBuffer[i+1] != EMPTY_VALUE) 
               { 
                 Alert("GT BB","  SELL! ",Symbol()," ", Period());
                 pre_signal = -1; 
               }               
        }
      return(0);
  }
//+------------------------------------------------------------------+


Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---