Author: Copyright © 2008, dm34@mail.ru
Indicators Used
Money flow index
0 Views
0 Downloads
0 Favorites
UltraMFI
ÿþ//+------------------------------------------------------------------+

//|                                                     UltraMFI.mq5 |

//|                                   Copyright © 2008, dm34@mail.ru | 

//|                                    http://www.fxexpert.ru/forum/ | 

//+------------------------------------------------------------------+

//---- 02B>@AB2> 8=48:0B>@0

#property copyright "Copyright © 2008, dm34@mail.ru"

//---- AAK;:0 =0 A09B 02B>@0

#property link "http://www.fxexpert.ru/forum/"

//---- =><5@ 25@A88 8=48:0B>@0

#property version   "1.00"

//---- >B@8A>2:0 8=48:0B>@0 2 >B45;L=>< >:=5

#property indicator_separate_window

//---- 4;O @0AG5B0 8 >B@8A>2:8 8=48:0B>@0 8A?>;L7>20=> 420 1CD5@0

#property indicator_buffers 2

//---- 8A?>;L7>20=> >4=> 3@0D8G5A:>5 ?>AB@>5=85

#property indicator_plots   1

//+-----------------------------------+ 

//|  >1JO2;5=85 :>=AB0=B              |

//+-----------------------------------+ 

#define RESET 0 // >=AB0=B0 4;O 2>72@0B0 B5@<8=0;C :><0=4K =0 ?5@5AG5B 8=48:0B>@0

//+-----------------------------------+

//|  0@0<5B@K >B@8A>2:8 70;82:8      |

//+-----------------------------------+

//---- >B@8A>2:0 8=48:0B>@0 2 2845 70;82:8 <564C 42C<O ;8=8O<8

#property indicator_type1   DRAW_FILLING

//---- 2 :0G5AB25 F25B>2 70;82:8 8=48:0B>@0 8A?>;L7>20=K 75;5=K9 F25B 8 >@0=652K9 F25B0

#property indicator_color1  clrLime, clrDarkOrange

//---- >B>1@065=85 <5B:8 8=48:0B>@0

#property indicator_label1 "Ultra MFI"

//+-----------------------------------+

//|  ?8A0=85 :;0AA0 CXMA             |

//+-----------------------------------+

#include <SmoothAlgorithms.mqh> 

//+-----------------------------------+



//---- >1JO2;5=85 ?5@5<5==KE :;0AA0 CXMA 87 D09;0 SmoothAlgorithms.mqh

CXMA XMA[];

//+-----------------------------------+

//|  >1JO2;5=85 ?5@5G8A;5=89          |

//+-----------------------------------+

/*enum Smooth_Method - ?5@5G8A;5=85 >1JO2;5=> 2 D09;5 SmoothAlgorithms.mqh

  {

   MODE_SMA_,  //SMA

   MODE_EMA_,  //EMA

   MODE_SMMA_, //SMMA

   MODE_LWMA_, //LWMA

   MODE_JJMA,  //JJMA

   MODE_JurX,  //JurX

   MODE_ParMA, //ParMA

   MODE_T3,    //T3

   MODE_VIDYA, //VIDYA

   MODE_AMA,   //AMA

  }; */

//+-----------------------------------+

//|  >1JO2;5=85 ?5@5G8A;5=8O          |

//+-----------------------------------+  

enum WIDTH

  {

   Width_1=1, //1

   Width_2,   //2

   Width_3,   //3

   Width_4,   //4

   Width_5    //5

  };

//+-----------------------------------+

//|  >1JO2;5=85 ?5@5G8A;5=8O          |

//+-----------------------------------+

enum STYLE

  {

   SOLID_,      // !?;>H=0O ;8=8O

   DASH_,       // (B@8E>20O ;8=8O

   DOT_,        // C=:B8@=0O ;8=8O

   DASHDOT_,    // (B@8E-?C=:B8@=0O ;8=8O

   DASHDOTDOT_  // (B@8E-?C=:B8@=0O ;8=8O A 42>9=K<8 B>G:0<8

  };

//+----------------------------------------------+

//| E>4=K5 ?0@0<5B@K 8=48:0B>@0                 |

//+----------------------------------------------+

input int MFI_Period=13;                            // 5@8>4 8=48:0B>@0 MFI

input ENUM_APPLIED_VOLUME VolumeType=VOLUME_TICK;   // 1J5< 8=48:0B>@0 MFI 

//----

input Smooth_Method W_Method=MODE_JJMA; // 5B>4 CA@54=5=8O

input int StartLength=3;                // !B0@B>2K9 ?5@8>4 CA@54=5=8O                    

input int WPhase=100;                   // 0@0<5B@ CA@54=5=8O

// ;O JJMA 87<5=ONI89AO 2 ?@545;0E -100 ... +100, 2;8O5B =0 :0G5AB2> ?5@5E>4=>3> ?@>F5AA0;

// ;O VIDIA MB> ?5@8>4 CMO, 4;O AMA MB> ?5@8>4 <54;5==>9 A:>;L7OI59

//----  

input uint Step=5;        // (03 87<5=5=8O ?5@8>40

input uint StepsTotal=10; // >;8G5AB2> 87<5=5=89 ?5@8>40

//----

input Smooth_Method SmoothMethod=MODE_JJMA; // 5B>4 A3;06820=8O

input int SmoothLength=3;                   // ;C18=0 A3;06820=8O                    

input int SmoothPhase=100;                  // 0@0<5B@ A3;06820=8O

// ;O JJMA 87<5=ONI89AO 2 ?@545;0E -100 ... +100, 2;8O5B =0 :0G5AB2> ?5@5E>4=>3> ?@>F5AA0;

//----                          

input uint UpLevel=80;            // #@>25=L ?5@5:C?;5==>AB8 2 %%

input uint DnLevel=20;            // #@>25=L ?5@5?@>40==>AB8 2 %%

input color UpLevelsColor=Blue;   // &25B C@>2=O ?5@5:C?;5==>AB8

input color DnLevelsColor=Blue;   // &25B C@>2=O ?5@5?@>40==>AB8

input STYLE Levelstyle=DASH_;     // !B8;L C@>2=59

input WIDTH  LevelsWidth=Width_1; // ">;I8=0 C@>2=59

//+----------------------------------------------+



//---- >1JO2;5=85 48=0<8G5A:8E <0AA82>2, :>B>@K5 1C4CB 2 40;L=59H5< 8A?>;L7>20=K 2 :0G5AB25 8=48:0B>@=KE 1CD5@>2

double BullsBuffer[];

double BearsBuffer[];

//---- 1JO2;5=85 <0AA820 ?5@5<5==KE 4;O E@0=5=8O ?5@8>4>2 A83=0;L=KE ;8=89 8=48:0B>@0 MFI

int period[];

//---- 1JO2;5=85 <0AA82>2 ?5@5<5==KE 4;O E@0=5=8O CA@54=5==KE 7=0G5=89 8=48:0B>@0 MFI

double xmfi0[],xmfi1[];

//---- 1JO2;5=85 F5;KE ?5@5<5==KE 4;O E5=4;>2 8=48:0B>@>2

int MFI_Handle;

//---- 1JO2;5=85 F5;KE ?5@5<5==KE =0G0;0 >BAG5B0 40==KE

uint StTot1,StTot2;

int min_rates_total,min_rates_mfi,min_rates_xma;

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+  

int OnInit()

  {

//---- @0A?@545;5=85 ?0<OB8 ?>4 <0AA82K ?5@5<5==KE

   int size=int(StepsTotal+3);

   if(ArrayResize(XMA,size)<size) Print("5 C40;>AL @0A?@545;8BL ?0<OBL ?>4 <0AA82 XMA[]");

   size-=2;

   if(ArrayResize(xmfi0,size)<size) Print("5 C40;>AL @0A?@545;8BL ?0<OBL ?>4 <0AA82 xmfi0[]");

   if(ArrayResize(xmfi1,size)<size) Print("5 C40;>AL @0A?@545;8BL ?0<OBL ?>4 <0AA82 xmfi1[]");

   if(ArrayResize(period,size)<size) Print("5 C40;>AL @0A?@545;8BL ?0<OBL ?>4 <0AA82 period[]");



//---- =8F80;870F8O ?5@5<5==KE

   for(int sm=int(StepsTotal); sm>=0 && !IsStopped(); sm--) period[sm]=int(StartLength+sm*Step);



//---- CAB0=>2:0 0;5@B>2 =0 =54>?CAB8<K5 7=0G5=8O 2=5H=8E ?5@5<5==KE

   XMA[0].XMALengthCheck("StartLength", StartLength);

   XMA[0].XMAPhaseCheck("WPhase", WPhase, W_Method);

   XMA[0].XMALengthCheck("SmoothLength", SmoothLength);

   XMA[0].XMAPhaseCheck("SmoothPhase", SmoothPhase, SmoothMethod);



//---- =8F80;870F8O ?5@5<5==KE =0G0;0 >BAG5B0 40==KE

   min_rates_mfi=MFI_Period;

   min_rates_xma=min_rates_mfi+XMA[0].GetStartBars(W_Method,StartLength+Step*StepsTotal,WPhase)+1;

   min_rates_total=min_rates_xma+XMA[0].GetStartBars(SmoothMethod,SmoothLength,SmoothPhase);

   StTot1=StepsTotal+1;

   StTot2=StepsTotal+2;



//---- ?>;CG5=85 E5=4;0 8=48:0B>@0 MFI

   MFI_Handle=iMFI(NULL,0,MFI_Period,VolumeType);

   if(MFI_Handle==INVALID_HANDLE)

     {

      Print(" 5 C40;>AL ?>;CG8BL E5=4; 8=48:0B>@0 MFI");

      return(INIT_FAILED);

     }



//---- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 BullsBuffer 2 8=48:0B>@=K9 1CD5@

   SetIndexBuffer(0,BullsBuffer,INDICATOR_DATA);

//---- >ACI5AB2;5=85 A42830 =0G0;0 >BAG5B0 >B@8A>2:8 8=48:0B>@0 1 =0 min_rates_total

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);

//---- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(BullsBuffer,true);



//---- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 BearsBuffer 2 8=48:0B>@=K9 1CD5@

   SetIndexBuffer(1,BearsBuffer,INDICATOR_DATA);

//---- >ACI5AB2;5=85 A42830 =0G0;0 >BAG5B0 >B@8A>2:8 8=48:0B>@0 2 =0 min_rates_total

   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);

//---- 8=45:A0F8O M;5<5=B>2 2 1CD5@5 :0: 2 B09<A5@88

   ArraySetAsSeries(BearsBuffer,true);



//---- 8=8F80;870F88 ?5@5<5==>9 4;O :>@>B:>3> 8<5=8 8=48:0B>@0

   string shortname="Ultra MFI";

//--- A>740=85 8<5=8 4;O >B>1@065=8O 2 >B45;L=>< ?>4>:=5 8 2> 2A?;K20NI59 ?>4A:07:5

   IndicatorSetString(INDICATOR_SHORTNAME,shortname);

//--- >?@545;5=85 B>G=>AB8 >B>1@065=8O 7=0G5=89 8=48:0B>@0

   IndicatorSetInteger(INDICATOR_DIGITS,2);



//---- ?0@0<5B@K >B@8A>2:8 ;8=89  

   IndicatorSetInteger(INDICATOR_LEVELS,2);



   IndicatorSetDouble(INDICATOR_LEVELVALUE,0,StepsTotal*UpLevel/100);

   IndicatorSetInteger(INDICATOR_LEVELCOLOR,0,UpLevelsColor);

   IndicatorSetInteger(INDICATOR_LEVELSTYLE,0,Levelstyle);

   IndicatorSetInteger(INDICATOR_LEVELWIDTH,0,LevelsWidth);



   IndicatorSetDouble(INDICATOR_LEVELVALUE,1,StepsTotal*DnLevel/100);

   IndicatorSetInteger(INDICATOR_LEVELCOLOR,1,DnLevelsColor);

   IndicatorSetInteger(INDICATOR_LEVELSTYLE,1,Levelstyle);

   IndicatorSetInteger(INDICATOR_LEVELWIDTH,1,LevelsWidth);

//---- 7025@H5=85 8=8F80;870F88

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int OnCalculate(

                const int rates_total,     // :>;8G5AB2> 8AB>@88 2 10@0E =0 B5:CI5< B8:5

                const int prev_calculated, // :>;8G5AB2> 8AB>@88 2 10@0E =0 ?@54K4CI5< B8:5

                const datetime &time[],

                const double &open[],

                const double& high[],      // F5=>2>9 <0AA82 <0:A8<C<>2 F5=K 4;O @0AG5B0 8=48:0B>@0

                const double& low[],       // F5=>2>9 <0AA82 <8=8<C<>2 F5=K  4;O @0AG5B0 8=48:0B>@0

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[]

                )

  {

//---- ?@>25@:0 :>;8G5AB20 10@>2 =0 4>AB0B>G=>ABL 4;O @0AG5B0

   if(BarsCalculated(MFI_Handle)<rates_total || rates_total<min_rates_total) return(RESET);



//---- >1JO2;5=8O ;>:0;L=KE ?5@5<5==KE 

   int to_copy,limit,bar,maxbar1,maxbar2;

   double MFI[],upsch,dnsch;



//---- @0AG5B AB0@B>2>3> =><5@0 maxbar 4;O DC=:F88 XMASeries()

   maxbar1=rates_total-1-min_rates_mfi;

   maxbar2=rates_total-1-min_rates_xma;



//---- @0AG5B AB0@B>2>3> =><5@0 limit 4;O F8:;0 ?5@5AG5B0 10@>2

   if(prev_calculated>rates_total || prev_calculated<=0)// ?@>25@:0 =0 ?5@2K9 AB0@B @0AG5B0 8=48:0B>@0

      limit=maxbar1; // AB0@B>2K9 =><5@ 4;O @0AG5B0 2A5E 10@>2

   else limit=rates_total-prev_calculated; // AB0@B>2K9 =><5@ 4;O @0AG5B0 =>2KE 10@>2

//----   

   to_copy=limit+2;

//---- :>?8@C5< 2=>2L ?>O282H85AO 40==K5 2 <0AA82K

   if(CopyBuffer(MFI_Handle,0,0,to_copy,MFI)<=0) return(RESET);



//---- 8=45:A0F8O M;5<5=B>2 2 <0AA820E :0: 2 B09<A5@8OE  

   ArraySetAsSeries(MFI,true);



//---- >A=>2=>9 F8:; @0AG5B0 8=48:0B>@0

   for(bar=limit; bar>=0 && !IsStopped(); bar--)

     {

      for(int sm=int(StepsTotal); sm>=0 && !IsStopped(); sm--)

         xmfi0[sm]=XMA[sm].XMASeries(maxbar1,prev_calculated,rates_total,W_Method,WPhase,period[sm],MFI[bar],bar,true);



      if(bar>maxbar2)

        {

         if(bar) ArrayCopy(xmfi1,xmfi0,0,0,WHOLE_ARRAY);

         continue;

        }



      upsch=0;

      dnsch=0;

      for(int sm=int(StepsTotal); sm>=0 && !IsStopped(); sm--) if(xmfi0[sm]>xmfi1[sm]) upsch++; else dnsch++;



      BullsBuffer[bar]=XMA[StTot1].XMASeries(maxbar2,prev_calculated,rates_total,SmoothMethod,SmoothPhase,SmoothLength,upsch,bar,true);

      BearsBuffer[bar]=XMA[StTot2].XMASeries(maxbar2,prev_calculated,rates_total,SmoothMethod,SmoothPhase,SmoothLength,dnsch,bar,true);



      if(bar) ArrayCopy(xmfi1,xmfi0,0,0,WHOLE_ARRAY);

     }

//----     

   return(rates_total);

  }

//+------------------------------------------------------------------+

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 ---