MaTMFI_Cloud

Author: Copyright © 2010, VladMsk, contact@mqlsoft.com
0 Views
0 Downloads
0 Favorites
MaTMFI_Cloud
ÿþ//+---------------------------------------------------------------------+

//|                                                    MaTMFI_Cloud.mq5 |

//|                    Copyright © 2010,   VladMsk, contact@mqlsoft.com |

//|                                             http://www.becemal.ru// |

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

//| ;O @01>BK  8=48:0B>@0  A;54C5B  ?>;>68BL D09; SmoothAlgorithms.mqh |

//| 2 ?0?:C (48@5:B>@8N): :0B0;>3_40==KE_B5@<8=0;0\\MQL5\Include        |

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



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

#property copyright "Copyright © 2010, VladMsk, contact@mqlsoft.com"

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

#property link      "http://www.becemal.ru/"

//---- >?8A0=85 8=48:0B>@0

#property description "True MFI. Based on code MFI.mq4"

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

#property indicator_separate_window

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

#property indicator_buffers 6

//---- 8A?>;L7>20=> B@8 3@0D8G5A:8E ?>AB@>5=8O

#property indicator_plots   3

//----

#property indicator_minimum 0

#property indicator_maximum 100

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

//| 0@0<5B@K >B@8A>2:8 25@E=53> >1;0:0          |

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

//---- >B@8A>2:0 8=48:0B>@0 2 2845 >1;0:0

#property indicator_type1   DRAW_FILLING

//---- 2 :0G5AB25 F25B0 ;8=88 8=48:0B>@0 8A?>;L7>20= F25B C'230,255,255'

#property indicator_color1 C'230,255,255'

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

#property indicator_label1  "Upper MaTMFI_Cloud"

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

//| 0@0<5B@K >B@8A>2:8 =86=53> >1;0:0           |

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

//---- >B@8A>2:0 8=48:0B>@0 2 2845 >1;0:0

#property indicator_type2   DRAW_FILLING

//---- 2 :0G5AB25 F25B0 ;8=88 8=48:0B>@0 8A?>;L7>20= F25B C'255,230,255'

#property indicator_color2 C'255,230,255'

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

#property indicator_label2  "Lower MaTMFI_Cloud"

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

//| 0@0<5B@K >B@8A>2:8 8=48:0B>@0 MaTMFI        |

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

//---- >B@8A>2:0 8=48:0B>@0 3 2 2845 F25B=>3> >1;0:0

#property indicator_type3   DRAW_FILLING

//---- 2 :0G5AB25 F25Bjd 8=48:0B>@0 8A?>;L7>20=K

#property indicator_color3  clrSpringGreen,clrMagenta

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

#property indicator_label3  "MaTMFI;Trigger"

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

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

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

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

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

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

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

#include <SmoothAlgorithms.mqh> 

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

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

CXMA XMA1,XMA2;

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

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

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

enum Applied_price_ //"8? :>=AB0=BK

  {

   PRICE_CLOSE_ = 1,     //Close

   PRICE_OPEN_,          //Open

   PRICE_HIGH_,          //High

   PRICE_LOW_,           //Low

   PRICE_MEDIAN_,        //Median Price (HL/2)

   PRICE_TYPICAL_,       //Typical Price (HLC/3)

   PRICE_WEIGHTED_,      //Weighted Close (HLCC/4)

   PRICE_SIMPL_,         //Simpl Price (OC/2)

   PRICE_QUARTER_,       //Quarted Price (HLOC/4) 

   PRICE_TRENDFOLLOW0_,  //TrendFollow_1 Price 

   PRICE_TRENDFOLLOW1_,  //TrendFollow_2 Price

   PRICE_DEMARK_         //Demark Price 

  };

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

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

  }; */

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

//|  %+  " + "                 |

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

input uint TMFIPeriod=10;                                //?5@8>4 TMFI

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

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

input int XPhase=15;                                     //?0@0<5B@ A3;06820=8O,

//---- 4;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 Applied_price_ IPC=PRICE_CLOSE_;                   //F5=>20O :>=AB0=B0

  input ENUM_APPLIED_VOLUME VolumeType=VOLUME_TICK;      //>1JQ<

input int Shift=0;                                       //A4283 8=48:0B>@0 ?> 3>@87>=B0;8 2 10@0E

input uint HighLevel=60;                                 //C@>25=L ?5@5:C?;5==>AB8

input uint MiddleLevel=50;                               //A5@5;8=0 480?07>=0

input uint LowLevel=40;                                  //C@>25=L ?5@5?@>40==>AB8

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

//---- >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 UpUpBuffer[],UpDnBuffer[],DnUpBuffer[],DnDnBuffer[];

double MaTMFIBuffer[],SignalBuffer[];

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

int min_rates_total;

//---- 1JO2;5=85 3;>10;L=KE ?5@5<5==KE

int Count[];

double Ma[];

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

//|  5@5AG5B ?>78F88 A0<>3> =>2>3> M;5<5=B0 2 <0AA825               |

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

void Recount_ArrayZeroPos(int &CoArr[],// >72@0B ?> AAK;:5 =><5@0 B5:CI53> 7=0G5=8O F5=>2>3> @O40

                          int Size)

  {

//----

   int numb,Max1,Max2;

   static int count=1;



   Max2=Size;

   Max1=Max2-1;



   count--;

   if(count<0) count=Max1;



   for(int iii=0; iii<Max2; iii++)

     {

      numb=iii+count;

      if(numb>Max1) numb-=Max2;

      CoArr[iii]=numb;

     }

//----

  }

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

//| Custom indicator initialization function                         |

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

void OnInit()

  {

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

   min_rates_total=int(XMA1.GetStartBars(XMA_Method,TMFIPeriod,XPhase)+XMA1.GetStartBars(XMA_Method,XLength,XPhase)+4);



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

   XMA1.XMALengthCheck("XLength", XLength);

   XMA1.XMAPhaseCheck("XPhase", XPhase, XMA_Method);

   

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

   ArrayResize(Count,4);

   ArrayResize(Ma,4);

   ArrayInitialize(Count,NULL);

   ArrayInitialize(Ma,NULL);



//--- 8=8F80;870F8O 8=48:0B>@=KE 1CD5@>2  

   IndInit(0,UpUpBuffer,INDICATOR_DATA);

   IndInit(1,UpDnBuffer,INDICATOR_DATA);

//--- 8=8F80;870F8O 8=48:0B>@>2

   PlotInit(0,EMPTY_VALUE,min_rates_total,Shift);

//--- 8=8F80;870F8O 8=48:0B>@=KE 1CD5@>2  

   IndInit(2,DnUpBuffer,INDICATOR_DATA);

   IndInit(3,DnDnBuffer,INDICATOR_DATA);

//--- 8=8F80;870F8O 8=48:0B>@>2

   PlotInit(1,EMPTY_VALUE,min_rates_total,Shift); 

//----

//--- 8=8F80;870F8O 8=48:0B>@=KE 1CD5@>2  

   IndInit(4,MaTMFIBuffer,INDICATOR_DATA);

   IndInit(5,SignalBuffer,INDICATOR_DATA);

//--- 8=8F80;870F8O 8=48:0B>@>2

   PlotInit(2,EMPTY_VALUE,min_rates_total,Shift); 



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

   string shortname;

   string Smooth=XMA1.GetString_MA_Method(XMA_Method);

   StringConcatenate(shortname,"MaTMFI_Cloud(",TMFIPeriod,", ",Smooth,", ",XLength,", ",XPhase,")");

//--- 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);

   

//---- ?0@0<5B@K >B@8A>2:8 C@>2=59 8=48:0B>@0

   IndicatorSetInteger(INDICATOR_LEVELS,3);

//---- 7=0G5=8O 3>@87>=B0;L=KE C@>2=59 8=48:0B>@0   

   IndicatorSetDouble(INDICATOR_LEVELVALUE,0,MathMax(MathMin(100,HighLevel),0));

   IndicatorSetDouble(INDICATOR_LEVELVALUE,1,MathMin(MathMax(0,MiddleLevel),100));

   IndicatorSetDouble(INDICATOR_LEVELVALUE,2,MathMin(MathMax(0,LowLevel),100));

//---- 2 :0G5AB25 F25B>2 ;8=89 3>@87>=B0;L=KE C@>2=59 8A?>;L7>20=K 

   IndicatorSetInteger(INDICATOR_LEVELCOLOR,0,clrBlue);

   IndicatorSetInteger(INDICATOR_LEVELCOLOR,1,clrGray);

   IndicatorSetInteger(INDICATOR_LEVELCOLOR,2,clrMagenta);

//---- 2 ;8=88 3>@87>=B0;L=>3> C@>2=O 8A?>;L7>20= :>@>B:89 HB@8E-?C=:B8@  

   IndicatorSetInteger(INDICATOR_LEVELSTYLE,0,STYLE_SOLID);

   IndicatorSetInteger(INDICATOR_LEVELSTYLE,1,STYLE_DASHDOTDOT);

   IndicatorSetInteger(INDICATOR_LEVELSTYLE,2,STYLE_SOLID);



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

   IndicatorSetInteger(INDICATOR_DIGITS,0);

//----

  }

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

//| =8F80;870F8O 8=48:0B>@=>3> 1CD5@0                               |

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

void IndInit(int Number,double &Buffer[],ENUM_INDEXBUFFER_TYPE Type)

  {

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

   SetIndexBuffer(Number,Buffer,Type);

//---

  }

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

//| =8F80;870F8O 8=48:0B>@0                                         |

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

void PlotInit(int Number,double Empty_Value,int Draw_Begin,int nShift)

  {

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

   PlotIndexSetInteger(Number,PLOT_DRAW_BEGIN,Draw_Begin);

//--- CAB0=>2:0 7=0G5=89 8=48:0B>@0, :>B>@K5 =5 1C4CB 2848<K =0 3@0D8:5

   PlotIndexSetDouble(Number,PLOT_EMPTY_VALUE,Empty_Value);

//--- >ACI5AB2;5=85 A42830 8=48:0B>@0 ?> 3>@87>=B0;8 =0 Shift

   PlotIndexSetInteger(Number,PLOT_SHIFT,nShift);

//---- 70?@5B =0 >B>1@065=85 7=0G5=89 8=48:0B>@0 2 ;52>< 25@E=5< C3;C >:=0 8=48:0B>@0

   PlotIndexSetInteger(Number,PLOT_SHOW_DATA,false);

//---

  }

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

//| 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 @0AGQB0 8=48:0B>@0

                const double& low[],      // F5=>2>9 <0AA82 <8=8<C<>2 F5=K  4;O @0AGQB0 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 @0AGQB0

   if(rates_total<min_rates_total) return(RESET);



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

   long Volume;

   int first,bar,bar1;

   double rel,negative,positive,sumn,sump,tmfi,price;

   static double negative_,positive_;



//---- @0AGQB AB0@B>2>3> =><5@0 first 4;O F8:;0 ?5@5AGQB0 10@>2

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

     {

      first=0; // AB0@B>2K9 =><5@ 4;O @0AGQB0 2A5E 10@>2

      negative_=50;

      positive_=50;

     }

   else first=prev_calculated-1; // AB0@B>2K9 =><5@ 4;O @0AGQB0 =>2KE 10@>2



//---- 2>AAB0=02;8205< 7=0G5=8O ?5@5<5==KE

   negative=negative_;

   positive=positive_;

   

   bar1=rates_total-2;



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

   for(bar=first; bar<rates_total && !IsStopped(); bar++)

     {

      price=PriceSeries(IPC,bar,open,low,high,close);

      Ma[Count[0]]=XMA1.XMASeries(0,prev_calculated,rates_total,XMA_Method,XPhase,TMFIPeriod,price,bar,false);

      

      if(bar<3){Recount_ArrayZeroPos(Count,4); continue;}

      

      sumn=0.0;

      sump=0.0;

      rel=Ma[Count[0]]-Ma[Count[3]]+8*Ma[Count[1]]-8*Ma[Count[2]];

      

       if(VolumeType==VOLUME_TICK) Volume=tick_volume[bar]+2*tick_volume[bar-1]+2*tick_volume[bar-2]+tick_volume[bar-3];

      else  Volume=volume[bar]+2*volume[bar-1]+2*volume[bar-2]+volume[bar-3];



      if(rel>0) sump+=double(Volume);

      else      sumn+=double(Volume);

      

      positive=(positive*(TMFIPeriod-1)+sump)/TMFIPeriod;

      negative=(negative*(TMFIPeriod-1)+sumn)/TMFIPeriod;



      if(negative) tmfi=100.0*(1.0-1.0/(1.0+positive/negative));

      else tmfi=50.0; 

      

      MaTMFIBuffer[bar]=tmfi;      

      SignalBuffer[bar]=XMA2.XMASeries(TMFIPeriod,prev_calculated,rates_total,XMA_Method,XPhase,XLength,tmfi,bar,false);

      

      UpUpBuffer[bar]=100;

      UpDnBuffer[bar]=double(HighLevel);

      //----      

      DnUpBuffer[bar]=double(LowLevel);

      DnDnBuffer[bar]=0;

      //---- 



      //---- 70?><8=05< 7=0G5=8O ?5@5<5==KE ?5@54 ?@>3>=0<8 =0 B5:CI5< 10@5

      if(bar==bar1)

        {

         negative_=negative;

         positive_=positive;

        }

        

      if(bar<rates_total-1) Recount_ArrayZeroPos(Count,4);

     }

//----     

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