fiji_bb_alert

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
fiji_bb_alert
//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 White
#property indicator_color2 Lime
#property indicator_color3 Red
#property indicator_color4 White
#property indicator_color5 Blue
#property indicator_width1 1
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 3
#property indicator_width5 3
#property indicator_style1 STYLE_DOT
#property indicator_style2 STYLE_SOLID
#property indicator_style3 STYLE_SOLID

//---- input parameters
extern int eintBandsPeriod = 20;
extern double edblBandsDev = 2.0;
extern int eintMAMode=MODE_SMA;
extern int eintMAPrice = PRICE_CLOSE;
extern int eintMAShift = 0;
extern int eintBarsBack= 1;
extern int SIGNAL_BAR=1;

//---- indicator buffers
double gadblMid[];
double gadblUpper[];
double gadblLower[];
double gadblDiv[];
double gadblDiv2[];
//+------------------------------------------------------------------+
//| init()                                                           |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexBuffer(0,gadblMid);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexLabel(0,"BB-Mid");

   SetIndexBuffer(1,gadblUpper);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexLabel(1,"BB-Upper");

   SetIndexBuffer(2,gadblLower);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexLabel(2,"BB-Lower");

   SetIndexBuffer(3,gadblDiv);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,108);
   SetIndexLabel(3,NULL);
   SetIndexEmptyValue(3,0.0);

   SetIndexBuffer(4,gadblDiv2);
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexArrow(4,108);
   SetIndexLabel(4,NULL);
   SetIndexEmptyValue(4,0.0);

   IndicatorShortName("Fiji BB");
   IndicatorDigits(Digits);

   return( 0 );
  }
//+------------------------------------------------------------------+
//| deinit()                                                         |
//+------------------------------------------------------------------+
int deinit()
  {
   return( 0 );
  }
//+------------------------------------------------------------------+
//| start()                                                          |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();

   if(counted_bars < 0) return (-1);
   if(counted_bars>0) counted_bars--;
   int intLimit=Bars-counted_bars;

   int intTrueShift,inx,jnx;
   double dblSum,dblNewRes,dblDeviation,dblCurrMA;

   for(inx=intLimit-eintBandsPeriod; inx>=0; inx--)
     {
      intTrueShift=inx+eintMAShift;
      dblSum=0.0;
      dblCurrMA=iMA(Symbol(),Period(),eintBandsPeriod,0,eintMAMode,eintMAPrice,intTrueShift);

      for(jnx=intTrueShift+eintBandsPeriod-1; jnx>=intTrueShift; jnx--)
        {
         dblNewRes=Close[jnx]-dblCurrMA;
         dblSum+=(dblNewRes*dblNewRes);
        }

      dblDeviation=edblBandsDev*MathSqrt(dblSum/eintBandsPeriod);
      gadblMid[inx]=dblCurrMA;
      gadblUpper[inx] = dblCurrMA + dblDeviation;
      gadblLower[inx] = dblCurrMA - dblDeviation;
      gadblDiv[inx]=0.0;
      gadblDiv2[inx]=0.0;

      // Check for divergence of upper band
      if(( High[inx]>gadblUpper[inx]) && (High[inx+eintBarsBack]>gadblUpper[inx+eintBarsBack]))
        {
         if(High[inx]<High[inx+eintBarsBack])
           {
            if(gadblUpper[inx]>gadblUpper[inx+eintBarsBack]) gadblDiv[inx]=High[inx];
           }
        }

      // Check for divergence of lower band
      if(( Low[inx]<gadblLower[inx]) && (Low[inx+eintBarsBack]<gadblLower[inx+eintBarsBack]))
        {
         if(Low[inx]>Low[inx+eintBarsBack])
           {
            if(gadblLower[inx]<gadblLower[inx+eintBarsBack]) gadblDiv2[inx]=Low[inx];
           }
        }
     }
   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 ---