CandlesAutoFibo_Grand_x4_Full

Author: Copyright © 2018, Nikolay Kositsin
0 Views
0 Downloads
0 Favorites
CandlesAutoFibo_Grand_x4_Full
ÿþ//+------------------------------------------------------------------+

//|                                CandlesAutoFibo_Grand_x4_Full.mq5 |

//|                               Copyright © 2018, Nikolay Kositsin | 

//|                              Khabarovsk,   farria@mail.redcom.ru | 

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

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

#property copyright "Copyright © 2018, Nikolay Kositsin"

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

#property link      "farria@mail.redcom.ru"

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

#property indicator_chart_window

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

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

#define FIBO_LINES_TOTAL 7     // >=AB0=B0 4;O :>;8G5AB20 C@>2=59 D81> 2 >4=>< A53<5=B5 $81>

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

#define FiboTotal 4 // >=AB0=B0 4;O G8A;0 A53<5=B>2 $81> A25@EC 8;8 A=87C

#define FIBO_LINES_TOTAL_XN_FULL FIBO_LINES_TOTAL*(1+FiboTotal*2)-FiboTotal*2    // >=AB0=B0 4;O :>;8G5AB20 2A5E C@>2=59 D81>

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

#property indicator_buffers FIBO_LINES_TOTAL_XN_FULL

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

#property indicator_plots   FIBO_LINES_TOTAL_XN_FULL

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

//|  %+  " + "      |

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

input ENUM_TIMEFRAMES Timeframe=PERIOD_D1;          //"09<D@59< 8=48:0B>@0 4;O @0AG5B0 C@>2=59 $81>=0G8

input double  FiboRatio =1.000;                     //>MDD8F85=B 4><=>65=8O 2A5E D81>C@>2=59

input double  FiboLevelsShift=0.000;                //!4283 ?> 25@B8:0;8 2A5E D81>C@>2=59 2 $810E >B =C;52>3> C@>2=O

//----

input double  FiboLevel1 =0.000;                    //7=0G5=85 D81>C@>2=O 1

input ENUM_LINE_STYLE StyleLevel1=STYLE_SOLID;      //AB8;L ;8=88 D81>C@>2=O 1

input uint   WidthLevel1=4;                         //B>;I8=0 ;8=88 D81>C@>2=O 1

input color  Color_Level1 = clrLimeGreen;           //F25B D81>C@>2=O 1

//----

input double  FiboLevel2=0.236;                     //7=0G5=85 D81>C@>2=O 2

input ENUM_LINE_STYLE StyleLevel2=STYLE_SOLID;      //AB8;L ;8=88 D81>C@>2=O 2

input uint    WidthLevel2=1;                        //B>;I8=0 ;8=88 D81>C@>2=O 2

input color   Color_Level2= clrDarkViolet;          //F25B D81>C@>2=O 2

//----

input double  FiboLevel3 =0.382;                    //7=0G5=85 D81>C@>2=O 3

input ENUM_LINE_STYLE StyleLevel3=STYLE_DASH;       //AB8;L ;8=88 D81>C@>2=O 3

input uint    WidthLevel3=1;                        //B>;I8=0 ;8=88 D81>C@>2=O 3

input color   Color_Level3 = clrOrange;             //F25B D81>C@>2=O 3

//----

input double  FiboLevel4 =0.500;                    //7=0G5=85 D81>C@>2=O 4

input ENUM_LINE_STYLE StyleLevel4=STYLE_SOLID;      //AB8;L ;8=88 D81>C@>2=O 4

input uint    WidthLevel4=2;                        //B>;I8=0 ;8=88 D81>C@>2=O 4

input color   Color_Level4 = clrMagenta;            //F25B D81>C@>2=O 4

//----  

input double  FiboLevel5 =0.618;                    //7=0G5=85 D81>C@>2=O 5

input ENUM_LINE_STYLE StyleLevel5=STYLE_DASH;       //AB8;L ;8=88 D81>C@>2=O 5

input uint    WidthLevel5=1;                        //B>;I8=0 ;8=88 D81>C@>2=O 5

input color   Color_Level5 = clrBlue;               //F25B D81>C@>2=O 5

//----

input double  FiboLevel6=0.764;                     //7=0G5=85 D81>C@>2=O 6

input ENUM_LINE_STYLE StyleLevel6=STYLE_SOLID;      //AB8;L ;8=88 D81>C@>2=O 6

input uint    WidthLevel6=1;                        //B>;I8=0 ;8=88 D81>C@>2=O 6

input color   Color_Level6 = clrGray;               //F25B D81>C@>2=O 6

//----

input double  FiboLevel7 = 1.000;                   //7=0G5=85 D81>C@>2=O 7

input ENUM_LINE_STYLE StyleLevel7=STYLE_SOLID;      //AB8;L ;8=88 D81>C@>2=O 7

input uint    WidthLevel7=4;                        //B>;I8=0 ;8=88 D81>C@>2=O 7

input color   Color_Level7 = clrLimeGreen;          //F25B D81>C@>2=O 7

//----

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

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

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

int min_rates_total;

//---- <0AA82K ?5@5<5==KE 4;O ;8=89 $81>

double Values[];

color Colors[];

ENUM_LINE_STYLE Styles[];

uint Widths[];

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

//|  0AA82K ?5@5<5==KE 4;O A>740=8O 8=48:0B>@=KE 1CD5@>2            |

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

class CIndicatorsBuffers

  {

public: double    IndBuffer[];

  };

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

//| !>740=85 8=48:0B>@=KE 1CD5@>2                                    |

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

CIndicatorsBuffers Ind[FIBO_LINES_TOTAL_XN_FULL];

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

//| >;CG5=85 B09<D@59<0 2 2845 AB@>:8                               |

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

string GetStringTimeframe(ENUM_TIMEFRAMES timeframe)

  {return(StringSubstr(EnumToString(timeframe),7,-1));}

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

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

   min_rates_total=int(3*PeriodSeconds(Timeframe)/PeriodSeconds(PERIOD_CURRENT))+1;   

//----

   ArrayResize(Values,FIBO_LINES_TOTAL_XN_FULL);

   ArrayResize(Colors,FIBO_LINES_TOTAL_XN_FULL);

   ArrayResize(Styles,FIBO_LINES_TOTAL_XN_FULL);

   ArrayResize(Widths,FIBO_LINES_TOTAL_XN_FULL);

//----  

   Values[0]=FiboLevel1*FiboRatio;

   Values[1]=FiboLevel2*FiboRatio;

   Values[2]=FiboLevel3*FiboRatio;

   Values[3]=FiboLevel4*FiboRatio;

   Values[4]=FiboLevel5*FiboRatio;

   Values[5]=FiboLevel6*FiboRatio;

   Values[6]=FiboLevel7*FiboRatio;

//----   

   Colors[0]=Color_Level1;

   Colors[1]=Color_Level2;

   Colors[2]=Color_Level3;

   Colors[3]=Color_Level4;

   Colors[4]=Color_Level5;

   Colors[5]=Color_Level6;

   Colors[6]=Color_Level7;

//----   

   Styles[0]=StyleLevel1;

   Styles[1]=StyleLevel2;

   Styles[2]=StyleLevel3;

   Styles[3]=StyleLevel4;

   Styles[4]=StyleLevel5;

   Styles[5]=StyleLevel6;

   Styles[6]=StyleLevel7;

//----   

   Widths[0]=WidthLevel1;

   Widths[1]=WidthLevel2;

   Widths[2]=WidthLevel3;

   Widths[3]=WidthLevel4;

   Widths[4]=WidthLevel5;

   Widths[5]=WidthLevel6;

   Widths[6]=WidthLevel7;

//---- 

    

   for(int count=1; count<=int(FiboTotal); count++)

      for(int lev=1; lev<7; lev++)

        {

         int kkk=lev+6*(2*count-1);

         Values[kkk]=Values[lev]+count;

         Colors[kkk]=Colors[lev];

         Styles[kkk]=Styles[lev];

         Widths[kkk]=Widths[lev];

         //----

         kkk=lev+6*(2*count);

         Values[kkk]=-Values[7-lev]-count+1;

         Colors[kkk]=Colors[lev-1];

         Styles[kkk]=Styles[lev-1];

         Widths[kkk]=Widths[lev-1];

        }

        

//----

   for(int numb=0; numb<FIBO_LINES_TOTAL_XN_FULL; numb++)

     {

      string shortname="";

      StringConcatenate(shortname,"Level",numb," ",DoubleToString(Values[numb],3),")");    

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

      PlotIndexSetString(numb,PLOT_LABEL,shortname);

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

      PlotIndexSetDouble(numb,PLOT_EMPTY_VALUE,EMPTY_VALUE);

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

      PlotIndexSetInteger(numb,PLOT_DRAW_BEGIN,min_rates_total);

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

      SetIndexBuffer(numb,Ind[numb].IndBuffer,INDICATOR_DATA);

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

      ArraySetAsSeries(Ind[numb].IndBuffer,false);

      //---- :>?8@>20=85 A2>9AB2 ?5@2KE A5<8 ;8=89 8=48:0B>@0 4;O 2A5E >AB0;L=KE

      PlotIndexSetInteger(numb,PLOT_DRAW_TYPE,DRAW_LINE);

      PlotIndexSetInteger(numb,PLOT_LINE_STYLE,Styles[numb]);

      PlotIndexSetInteger(numb,PLOT_LINE_WIDTH,Widths[numb]);

      //---- 7040=85 F25B0 4;O ;8=88

      PlotIndexSetInteger(numb,PLOT_LINE_COLOR,Colors[numb]);

      //--- !4283 ;8=89 ?> >A8 2@5<5=8

      PlotIndexSetInteger(numb,PLOT_SHIFT,Shift);

     }

//---   

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);

   IndicatorSetString(INDICATOR_SHORTNAME,"CandlesAutoFibo_Grand_Full("+GetStringTimeframe(Timeframe)+")");

//---

   return(0);

  }

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

//| Custom indicator iteration function                              |

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

int OnCalculate(const int rates_total,

                const int prev_calculated,

                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[])

  {

//--- check for data

   if(rates_total<min_rates_total) return(0);

   if(prev_calculated==rates_total) return(rates_total);



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

   int first,bar;

   double P2;

   static double nOpen[2],nClose[2],nHigh[2],nLow[2];

   static datetime nTime[1],nTime_prev;



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

      nTime_prev=NULL;

     }

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

     {

      int to_copy=1;

      if(CopyTime(NULL,Timeframe,time[bar],to_copy,nTime)<to_copy)return(RESET);

      to_copy++;

      if(nTime[0]!=nTime_prev)

        {

         if(CopyOpen(NULL,Timeframe,time[bar],to_copy,nOpen)<to_copy)return(RESET);

         if(CopyHigh(NULL,Timeframe,time[bar],to_copy,nHigh)<to_copy)return(RESET);

         if(CopyLow(NULL,Timeframe,time[bar],to_copy,nLow)<to_copy)return(RESET);

         if(CopyClose(NULL,Timeframe,time[bar],to_copy,nClose)<to_copy)return(RESET);

         nTime_prev=nTime[0];

        }

      //----

      int trend=+1;

      if(nOpen[0]>nClose[0]) trend=-1;

      double range=nHigh[0]-nLow[0];

      if(trend>0) P2=nHigh[0];

      else P2=nLow[0];

      //---- 

      double vertSfift=range*FiboLevelsShift;

      P2+=vertSfift;

      //----

      

      for(int numb=0; numb<FIBO_LINES_TOTAL_XN_FULL; numb++) Ind[numb].IndBuffer[bar]=P2-range*Values[numb]*trend;



      int bar1=bar-1;

      //--- C40;5=85 ;8H=8E 7=0G5=89, ?>@BOI8E 284 3@0D8:0 8 <5H0NI8E 53> 2>A?@8OB8N

      for(int numb=0; numb<FIBO_LINES_TOTAL_XN_FULL; numb++) 

        if(Ind[numb].IndBuffer[bar]!=Ind[numb].IndBuffer[bar1])

        for(int count=0; count<FIBO_LINES_TOTAL_XN_FULL; count++)

          Ind[count].IndBuffer[bar1]=EMPTY_VALUE;

     }

//---

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