Author: Copyright � 2005, MetaQuotes Software Corp.
MFI-Alert
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
MFI-Alert
//+------------------------------------------------------------------+
//|                                             Money Flow Index.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 3
#property indicator_color1 DodgerBlue
#property indicator_color2 LightGray
#property indicator_color3 LightGray
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_style1 STYLE_SOLID
#property indicator_style2 STYLE_DOT
#property indicator_style3 STYLE_DOT
//---- input parameters
extern int MFIPeriod=12;
extern int ApplyTo=0;
extern bool AlertMode=true;
extern int OverBought=84;
extern int OverSold=16;
//---- buffers
double MFIBuffer[];
double MFIOBBuffer[];
double MFIOSBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string sShortName;
//---- indicator lines
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,MFIBuffer);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,MFIOBBuffer);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,MFIOSBuffer);
//---- name for DataWindow and indicator subwindow label
   sShortName="MFI-Alert("+MFIPeriod+")";
   IndicatorShortName(sShortName);
   SetIndexLabel(0,sShortName);
   SetIndexLabel(1,"OverBought");
   SetIndexLabel(2,"OverSold");
//---- first values aren't drawn
   SetIndexDrawBegin(0,MFIPeriod);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Money Flow Index                                                 |
//+------------------------------------------------------------------+
int start()
  {
   int    i,j,nCountedBars;
   double dPositiveMF,dNegativeMF,dCurrentTP,dPreviousTP;
//---- insufficient data
   if(Bars<=MFIPeriod) return(0);
//---- bars count that does not changed after last indicator launch.
   nCountedBars=IndicatorCounted();
//----
   i=Bars-MFIPeriod-1;
   if(nCountedBars>MFIPeriod) 
      i=Bars-nCountedBars-1;
   while(i>=0)
     {
      dPositiveMF=0.0;
      dNegativeMF=0.0;
      dCurrentTP=(High[i]+Low[i]+Close[i])/3;
      for(j=0; j<MFIPeriod; j++)
        {
         dPreviousTP=(High[i+j+1]+Low[i+j+1]+Close[i+j+1])/3;
         if(dCurrentTP>dPreviousTP)
            dPositiveMF+=Volume[i+j]*dCurrentTP;
         else
           {
            if(dCurrentTP<dPreviousTP)
                dNegativeMF+=Volume[i+j]*dCurrentTP;
           }
          dCurrentTP=dPreviousTP;      
        }
      //----
      if(dNegativeMF!=0.0)      
         MFIBuffer[i]=100-100/(1+dPositiveMF/dNegativeMF);
      else
         MFIBuffer[i]=100;
      //----
      i--;
     }
   if(AlertMode)
   {
      if(MFIBuffer[1]<OverBought && MFIBuffer[0]>=OverBought)
         Alert("MFI "+MFIPeriod+ ", Sell @ Level "+OverBought+" - "+Symbol()+" M"+Period()+" @ "+DoubleToStr(Bid,Digits)+"");
      else if(MFIBuffer[1]>OverSold && MFIBuffer[0]<=OverSold)
         Alert("MFI "+MFIPeriod+ ", Buy @ Level "+OverSold+" - "+Symbol()+" M"+Period()+" @ "+DoubleToStr(Bid,Digits)+"");
   }
//----
   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 ---