EMAVFS_channel

Author: Copyright © 2018, Станислав Булашев
2 Views
0 Downloads
0 Favorites
EMAVFS_channel
ÿþ//+------------------------------------------------------------------+ 

//|                                               EMAVFS_channel.mq5 | 

//|                              Copyright © 2018, !B0=8A;02 C;0H52 |

//|                         http://stan.okis.ru/file/stan/EMAVFS.pdf | 

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

#property copyright "Copyright © 2018, !B0=8A;02 C;0H52"

#property link "http://stan.okis.ru/file/stan/EMAVFS.pdf" 

#property description "0=0; A 8A?>;L7>20=85< M:A?>=5=F80;L=>9 A:>;L7OI59 A@54=59 A ?5@5<5==K< D0:B>@>< A3;06820=8O"

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

#property version   "1.00"

//---- >B@8A>2:0 8=48:0B>@0 2 3;02=>< >:=5

#property indicator_chart_window 

//---- :>;8G5AB2> 8=48:0B>@=KE 1CD5@>2

#property indicator_buffers 3 

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

#property indicator_plots   3

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

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

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

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

#property indicator_type1   DRAW_LINE

//---- 2 :0G5AB25 F25B0 ;8=88 8=48:0B>@0 8A?>;L7>20= clrDodgerBlue F25B

#property indicator_color1 clrDodgerBlue

//---- ;8=8O 8=48:0B>@0 - =5?@5@K2=0O :@820O

#property indicator_style1  STYLE_SOLID

//---- B>;I8=0 ;8=88 8=48:0B>@0 @02=0 2

#property indicator_width1 2

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

#property indicator_label1  "EMAVFS Max"

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

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

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

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

#property indicator_type2   DRAW_LINE

//---- 2 :0G5AB25 F25B0 ;8=88 8=48:0B>@0 8A?>;L7>20= clrSlateGray F25B

#property indicator_color2 clrSlateGray

//---- ;8=8O 8=48:0B>@0 - =5?@5@K2=0O :@820O

#property indicator_style2  STYLE_DASHDOTDOT

//---- B>;I8=0 ;8=88 8=48:0B>@0 @02=0 1

#property indicator_width2 1

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

#property indicator_label2  "EMAVFS"

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

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

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

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

#property indicator_type3   DRAW_LINE

//---- 2 :0G5AB25 F25B0 ;8=88 8=48:0B>@0 8A?>;L7>20= clrDeepPink F25B

#property indicator_color3 clrDeepPink

//---- ;8=8O 8=48:0B>@0 - =5?@5@K2=0O :@820O

#property indicator_style3  STYLE_SOLID

//---- B>;I8=0 ;8=88 8=48:0B>@0 @02=0 2

#property indicator_width3 2

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

#property indicator_label3  "EMAVFS Min"

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

//|  >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_TRENDFOLdLow0_,  //TrendFoldLow_1 Price 

   PRICE_TRENDFOLdLow1_,  //TrendFoldLow_2 Price 

   PRICE_DEMARK_         //Demark Price

  };

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

//|  %+  " + "      |

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

input double Wmin=0;                      // <8=8<0;L=0O GC2AB28B5;L=>ABL  

input double Wmax=5;                      // <0:A8<0;L=0O GC2AB28B5;L=>ABL

input double Efactor=1.01;                // :>MDD8F85=B E (<5=OBL 7=0G5=85 >:>;> 548=8FK =0 45AOBK5 8 A>BK5 4>;8) 

input double Afactor=1.001;               // AB5?5=L A (<5=OBL 7=0G5=85 >:>;> 548=8FK =0 45AOBK5 8 A>BK5 4>;8)                   

input Applied_price_ IPC=PRICE_CLOSE_;    // F5=>20O :>=AB0=B0

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

input int PriceShift=0;                   // c4283 8=48:0B>@0 ?> 25@B8:0;8 2 ?C=:B0E

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

//---- >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 IndBuffer1[],IndBuffer2[],IndBuffer3[];

double dPriceShift;

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

int min_rates_total;

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

//| EMA indicator initialization function                            | 

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

void OnInit()

  {

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

   min_rates_total=2;



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

   SetIndexBuffer(0,IndBuffer1,INDICATOR_DATA);

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

   ArraySetAsSeries(IndBuffer1,false);

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

   PlotIndexSetInteger(0,PLOT_SHIFT,Shift);

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

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);

   

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

   SetIndexBuffer(1,IndBuffer2,INDICATOR_DATA);

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

   ArraySetAsSeries(IndBuffer2,false);

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

   PlotIndexSetInteger(1,PLOT_SHIFT,Shift);

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

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);

   

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

   SetIndexBuffer(2,IndBuffer3,INDICATOR_DATA);

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

   ArraySetAsSeries(IndBuffer3,false);

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

   PlotIndexSetInteger(2,PLOT_SHIFT,Shift);

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

   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE);   

   

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

   string shortname="EMAVFS_channel";

//--- 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,_Digits+1);

//---- =8F80;870F8O A42830 ?> 25@B8:0;8

   dPriceShift=_Point*PriceShift;

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

  }

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

//| EMA 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(0);



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

   int first,bar;

   double series,wema,w,eval,ERROR;

   static double wema_prew;

   

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

   ArraySetAsSeries(open,false);

   ArraySetAsSeries(high,false);

   ArraySetAsSeries(low,false);

   ArraySetAsSeries(close,false);



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

     {

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

      wema_prew=PriceSeries(IPC,first-1,open,low,high,close); 

     }

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



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

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

     {

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

      w=Wmin+(Wmax-Wmin)*(1.0-MathExp(-MathPow(MathAbs(series-wema_prew/Efactor),Afactor)));

      wema=wema_prew+w*(series-wema_prew);

      IndBuffer2[bar]=wema+dPriceShift;

      //----

      eval=series-wema;

      ERROR=wema*MathAbs(eval);

      IndBuffer1[bar]=IndBuffer2[bar]+ERROR;

      IndBuffer3[bar]=IndBuffer2[bar]-ERROR;

      //----

      if(bar<rates_total-1) wema_prew=wema;

     }

//----     

   return(rates_total);

  }

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

//| >;CG5=85 7=0G5=8O F5=>2>9 B09<A5@88                             |

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

double PriceSeries

(

 uint applied_price,// &5=>20O :>=AB0=B0

 uint   bar,// =45:A A42830 >B=>A8B5;L=> B5:CI53> 10@0 =0 C:070==>5 :>;8G5AB2> ?5@8>4>2 =0704 8;8 2?5@Q4).

 const double &dOpen[],

 const double &dLow[],

 const double &dHigh[],

 const double &dClose[]

 )

//PriceSeries(applied_price, bar, dOpen, dLow, dHigh, dClose)

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

  {

//----

   switch(applied_price)

     {

      //---- &5=>2K5 :>=AB0=BK 87 ?5@5G8A;5=8O ENUM_APPLIED_PRICE

      case  PRICE_CLOSE: return(dClose[bar]);

      case  PRICE_OPEN: return(dOpen [bar]);

      case  PRICE_HIGH: return(dHigh [bar]);

      case  PRICE_LOW: return(dLow[bar]);

      case  PRICE_MEDIAN: return((dHigh[bar]+dLow[bar])/2.0);

      case  PRICE_TYPICAL: return((dClose[bar]+dHigh[bar]+dLow[bar])/3.0);

      case  PRICE_WEIGHTED: return((2*dClose[bar]+dHigh[bar]+dLow[bar])/4.0);



      //----                            

      case  8: return((dOpen[bar] + dClose[bar])/2.0);

      case  9: return((dOpen[bar] + dClose[bar] + dHigh[bar] + dLow[bar])/4.0);

      //----                                

      case 10:

        {

         if(dClose[bar]>dOpen[bar])return(dHigh[bar]);

         else

           {

            if(dClose[bar]<dOpen[bar])

               return(dLow[bar]);

            else return(dClose[bar]);

           }

        }

      //----         

      case 11:

        {

         if(dClose[bar]>dOpen[bar])return((dHigh[bar]+dClose[bar])/2.0);

         else

           {

            if(dClose[bar]<dOpen[bar])

               return((dLow[bar]+dClose[bar])/2.0);

            else return(dClose[bar]);

           }

         break;

        }

      //----         

      case 12:

        {

         double res=dHigh[bar]+dLow[bar]+dClose[bar];

         if(dClose[bar]<dOpen[bar]) res=(res+dLow[bar])/2;

         if(dClose[bar]>dOpen[bar]) res=(res+dHigh[bar])/2;

         if(dClose[bar]==dOpen[bar]) res=(res+dClose[bar])/2;

         return(((res-dLow[bar])+(res-dHigh[bar]))/2);

        }

      //----

      default: return(dClose[bar]);

     }

//----

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