FineTuningMACandle_Chl

Author: Copyright © 2018, gumgum
2 Views
0 Downloads
0 Favorites
FineTuningMACandle_Chl
ÿþ//+------------------------------------------------------------------+

//|                                       FineTuningMACandle_Chl.mq5 | 

//|                                         Copyright © 2018, gumgum |

//|                                                                  |

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

#property copyright "Copyright © 2018, gumgum"

#property link      ""

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

#property version   "1.00"

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

#property description "!25G=>9 3@0D8: =0 1>;55 B>=:>< CA@54=5=88 B09<A5@89"

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

#property indicator_chart_window 

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

#property indicator_buffers 9

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

#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 F25B=>3> >1;0:0

#property indicator_type1   DRAW_FILLING

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

#property indicator_color1  C'170,255,227'

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

#property indicator_label1  "Upper Signal Cloud"

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

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

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

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

#property indicator_type2   DRAW_FILLING

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

#property indicator_color2  C'255,255,187'

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

#property indicator_label2  "Lower Signal Cloud"

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

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

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

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

#property indicator_type3   DRAW_COLOR_CANDLES

#property indicator_color3   clrDeepPink,clrGray,clrCornflowerBlue

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

#property indicator_label3  "FineTuningMA Open;FineTuningMA High;FineTuningMA Low;FineTuningMA Close"

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

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

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

#include <SmoothAlgorithms.mqh> 

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

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

CStdDeviation STDh,STDl;

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

//|  %+  " + "                 |

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

input uint   FTMA=10;

input double rank1=2;

input double rank2=2;

input double rank3=2;

input double Shift1=1;

input double Shift2=1;

input double Shift3=1;

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

input uint Gap=10;                                     //@07<5@ =5CG8BK205<>3> 3M?0 2 ?C=:B0E

input uint BBLength=10;                                // ?5@8>4 >;;8=465@0                                                   

input double BandsDeviation=1.0;                       // 45280F8O

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

//---- >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 ExtOpenBuffer[];

double ExtHighBuffer[];

double ExtLowBuffer[];

double ExtCloseBuffer[];

double ExtColorBuffer[];

//----

double PM[];

//---- 1JO2;5=85 ?5@5<5==>9 7=0G5=8O 25@B8:0;L=>3> A42830 <C28=30

double dPriceShift;

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

int min_rates_total,min_rates_1;

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

//| FineTuningMA indicator initialization function                   | 

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

void OnInit()

  {

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

   dPriceShift=_Point*PriceShift;



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

   ArrayResize(PM,FTMA);



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

   double sum=0;

   for(int h=0; h<int(FTMA); h++)

     {

      PM[h]=Shift1+MathPow(h/(FTMA-1.0),rank1)*(1.0-Shift1);

      PM[h]=(Shift2+MathPow(1-(h/(FTMA-1.0)),rank2)*(1.0-Shift2))*PM[h];



      if((h/(FTMA-1.))<0.5) PM[h]=(Shift3+MathPow((1-(h/(FTMA-1.0))*2.0),rank3)*(1.0-Shift3))*PM[h];

      else PM[h]=(Shift3+MathPow((h/(FTMA-1.0))*2.0-1.0,rank3)*(1.0-Shift3))*PM[h];



      sum+=PM[h];

     }



   double sum1=0;

   for(int h=0; h<int(FTMA); h++)

     {

      PM[h]=PM[h]/sum;

      sum1+=PM[h];

     }



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

   min_rates_1=int(FTMA)+1;

   min_rates_total=min_rates_1+int(BBLength);

//--- 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,NULL,min_rates_total,0);

//--- 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,NULL,min_rates_total,0);

//---- ?@52@0I5=85 48=0<8G5A:8E <0AA82>2 2 8=48:0B>@=K5 1CD5@K

   SetIndexBuffer(4,ExtOpenBuffer,INDICATOR_DATA);

   SetIndexBuffer(5,ExtHighBuffer,INDICATOR_DATA);

   SetIndexBuffer(6,ExtLowBuffer,INDICATOR_DATA);

   SetIndexBuffer(7,ExtCloseBuffer,INDICATOR_DATA);

//---- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 2 F25B>2>9, 8=45:A=K9 1CD5@   

   SetIndexBuffer(8,ExtColorBuffer,INDICATOR_COLOR_INDEX);

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

   PlotInit(2,NULL,min_rates_1,0);

//--- 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,"FineTuningMACandle_Chl("+string(FTMA)+")");



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

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);

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

  }

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

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

//---

  }

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

//| FineTuningMA 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[],

                const double &low[],

                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 F5;KE ?5@5<5==KE 8 ?>;CG5=85 C65 ?>AG8B0==KE 10@>2

   int first,bar;

   double O,H,L,C,stdev;



//---- @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=min_rates_1; // AB0@B>2K9 =><5@ 4;O @0AGQB0 2A5E 10@>2

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

     {      

      O=NULL;

      for(int index=0; index<int(FTMA); index++) O+=PM[index]*open[bar-index];

      H=NULL;

      for(int index=0; index<int(FTMA); index++) H+=PM[index]*high[bar-index];

      L=NULL;

      for(int index=0; index<int(FTMA); index++) L+=PM[index]*low[bar-index];

      C=NULL;

      for(int index=0; index<int(FTMA); index++) C+=PM[index]*close[bar-index];

      

      //---- 8A?@02;O5< 7=0G5=8O ?>;CG5==KE A25G5:

      double Max=MathMax(O,C);

      Max=MathMax(Max,L);

      Max=MathMax(Max,H);

      double Min=MathMin(O,C);

      Min=MathMin(Min,L);

      Min=MathMin(Min,H);

      ExtOpenBuffer[bar]=O;

      ExtHighBuffer[bar]=Max;

      ExtLowBuffer[bar]=Min;

      ExtCloseBuffer[bar]=C;

      //---- C40;O5< =5ACI5AB2CNI85 35?K

      if(MathAbs(open[bar]-close[bar])<=Gap) ExtOpenBuffer[bar]=ExtCloseBuffer[MathMax(bar-1,0)];

      //---- :@0A8< A25G8

      if(ExtOpenBuffer[bar]<ExtCloseBuffer[bar]) ExtColorBuffer[bar]=2.0;

      else if(ExtOpenBuffer[bar]>ExtCloseBuffer[bar]) ExtColorBuffer[bar]=0.0;

      else ExtColorBuffer[bar]=1.0;      

      //---- A428305< A25G8 ?> 25@B8:0;8

      ExtOpenBuffer[bar]+=dPriceShift;

      ExtHighBuffer[bar]+=dPriceShift;

      ExtLowBuffer[bar]+=dPriceShift;

      ExtCloseBuffer[bar]+=dPriceShift;

      //----

      stdev=STDh.StdDevSeries(min_rates_1,prev_calculated,rates_total,BBLength,BandsDeviation,high[bar],ExtHighBuffer[bar],bar,false);

      UpUpBuffer[bar]=ExtHighBuffer[bar]+stdev;     

      UpDnBuffer[bar]=ExtHighBuffer[bar]; 

      DnUpBuffer[bar]=ExtLowBuffer[bar];

      stdev=STDl.StdDevSeries(min_rates_1,prev_calculated,rates_total,BBLength,BandsDeviation,low[bar],ExtLowBuffer[bar],bar,false);

      DnDnBuffer[bar]=ExtLowBuffer[bar]-stdev;

     }

//----     

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