Fib_SR_Full

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

//|                                                  Fib_SR_Full.mq5 | 

//|                               Copyright © 2018, Nikolay Kositsin | 

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

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

#property copyright "Copyright © 2018, Nikolay Kositsin"

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

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

#property version   "1.60"

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

#property indicator_chart_window

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

#property indicator_buffers 16 

//--- 8A?>;L7>20=> 2>A5<L 3@0D8G5A:8E ?>AB@>5=89

#property indicator_plots   8

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

//|  >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 EMPTYVALUE 0                                   // >=AB0=B0 4;O =5>B>1@0605<KE 7=0G5=89 8=48:0B>@0

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

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

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

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

#property indicator_type1   DRAW_FILLING

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

#property indicator_color1  clrGreen

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

#property indicator_label1  "Upper Fibo"

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

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

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

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

#property indicator_type2   DRAW_FILLING

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

#property indicator_color2  clrRed

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

#property indicator_label2  "Lower Fibo"

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

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

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

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

#property indicator_type3   DRAW_FILLING

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

#property indicator_color3  clrGreen

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

#property indicator_label3  "Upper Fibo"

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

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

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

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

#property indicator_type4   DRAW_FILLING

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

#property indicator_color4  clrRed

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

#property indicator_label4  "Lower Fibo"

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

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

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

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

#property indicator_type5   DRAW_FILLING

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

#property indicator_color5  clrLime

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

#property indicator_label5  "Upper Fibo"

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

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

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

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

#property indicator_type6   DRAW_FILLING

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

#property indicator_color6  clrMagenta

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

#property indicator_label6  "Lower Fibo"

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

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

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

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

#property indicator_type7   DRAW_FILLING

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

#property indicator_color7  clrLime

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

#property indicator_label7  "Upper Fibo"

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

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

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

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

#property indicator_type8   DRAW_FILLING

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

#property indicator_color8  clrMagenta

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

#property indicator_label8  "Lower Fibo"

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

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

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

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

input double Ratio1 = 0.618;                //?5@2>5 A>>B=>H5=85

input double Ratio2 = 1.382;                //2B>@>5 A>>B=>H5=85

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

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

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

double UpUpBuffer1[],UpDnBuffer1[],DnUpBuffer1[],DnDnBuffer1[];

double UpUpBuffer2[],UpDnBuffer2[],DnUpBuffer2[],DnDnBuffer2[];

double UpUpBuffer3[],UpDnBuffer3[],DnUpBuffer3[],DnDnBuffer3[];

double UpUpBuffer4[],UpDnBuffer4[],DnUpBuffer4[],DnDnBuffer4[];

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

int min_rates_total;

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

//| Custom indicator initialization function                         | 

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

int OnInit()

  {

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

   min_rates_total=2;

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

   ArrayInit(0,UpUpBuffer1);

   ArrayInit(1,UpDnBuffer1);

   ArrayInit(2,DnUpBuffer1);

   ArrayInit(3,DnDnBuffer1);

   ArrayInit(4,UpUpBuffer2);

   ArrayInit(5,UpDnBuffer2);

   ArrayInit(6,DnUpBuffer2);

   ArrayInit(7,DnDnBuffer2);

   ArrayInit(8,UpUpBuffer3);

   ArrayInit(9,UpDnBuffer3);

   ArrayInit(10,DnUpBuffer3);

   ArrayInit(11,DnDnBuffer3);

   ArrayInit(12,UpUpBuffer4);

   ArrayInit(13,UpDnBuffer4);

   ArrayInit(14,DnUpBuffer4);

   ArrayInit(15,DnDnBuffer4);



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

   PlotInit(0,EMPTYVALUE,2,Shift);

   PlotInit(1,EMPTYVALUE,2,Shift);

   PlotInit(2,EMPTYVALUE,2,Shift);

   PlotInit(3,EMPTYVALUE,2,Shift);

   PlotInit(4,EMPTYVALUE,2,Shift);

   PlotInit(5,EMPTYVALUE,2,Shift);

   PlotInit(6,EMPTYVALUE,2,Shift);

   PlotInit(7,EMPTYVALUE,2,Shift);

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

   string shortname="Fib_SR_Full";

//StringConcatenate(shortname,INDICATOR_NAME,"(",EnumToString(TimeFrame),")");

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

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

   return(INIT_SUCCEEDED);

  }

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

//| Custom 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 @0AG5B0

   if(rates_total<min_rates_total) return(RESET);



   static int Sign;

   static datetime LastTime;

   double dLow[2],dHigh[2],dClose[2];

   datetime nTime[1];

   int limit;

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

      LastTime=0;

      Sign=1;

     }

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



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

   ArraySetAsSeries(time,true);



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

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

     {

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

      if(CopyTime(Symbol(),Timeframe,time[bar],1,nTime)<=0) return(RESET);



      if(time[bar]>=nTime[0] && time[bar+1]<nTime[0])

        {

         if(nTime[0]!=LastTime)

           {

            LastTime=nTime[0];

            Sign*=(-1);

           }

         //----

         int to_copy=2;

         //----

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

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

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

         //----   

         double C=dClose[0];

         double H=dHigh[0];

         double L=dLow[0];

         double R=(H-L);

         //----

         C=(H+L+C)/3;

         double D=(R/2)+C;

         double B=C-(R/2);

         double E=R+C;

         double A=C-R;

         //----

         double R1=R*Ratio2;

         double R2=R*Ratio1;

         double B1=C-R2;

         double A1=C-R1;

         //----

         double D1=C+R2;

         double E1=C+R1;



         if(Sign>0)

           {

            UpUpBuffer1[bar]=D1;

            UpDnBuffer1[bar]=D;

            DnUpBuffer1[bar]=B;

            DnDnBuffer1[bar]=B1;

            UpUpBuffer3[bar]=E1;

            UpDnBuffer3[bar]=E;

            DnUpBuffer3[bar]=A;

            DnDnBuffer3[bar]=A1;

            

            UpUpBuffer2[bar]=EMPTYVALUE;

            UpDnBuffer2[bar]=EMPTYVALUE;

            DnUpBuffer2[bar]=EMPTYVALUE;

            DnDnBuffer2[bar]=EMPTYVALUE;

            UpUpBuffer4[bar]=EMPTYVALUE;

            UpDnBuffer4[bar]=EMPTYVALUE;

            DnUpBuffer4[bar]=EMPTYVALUE;

            DnDnBuffer4[bar]=EMPTYVALUE;

           }

         else

           {

            UpUpBuffer2[bar]=D1;

            UpDnBuffer2[bar]=D;

            DnUpBuffer2[bar]=B;

            DnDnBuffer2[bar]=B1;

            UpUpBuffer4[bar]=E1;

            UpDnBuffer4[bar]=E;

            DnUpBuffer4[bar]=A;

            DnDnBuffer4[bar]=A1; 

            

            UpUpBuffer1[bar]=EMPTYVALUE;

            UpDnBuffer1[bar]=EMPTYVALUE;

            DnUpBuffer1[bar]=EMPTYVALUE;

            DnDnBuffer1[bar]=EMPTYVALUE;

            UpUpBuffer3[bar]=EMPTYVALUE;

            UpDnBuffer3[bar]=EMPTYVALUE;

            DnUpBuffer3[bar]=EMPTYVALUE;

            DnDnBuffer3[bar]=EMPTYVALUE;

           }

        }

      else

        {

         UpUpBuffer1[bar]=UpUpBuffer1[bar+1];

         UpDnBuffer1[bar]=UpDnBuffer1[bar+1];

         DnUpBuffer1[bar]=DnUpBuffer1[bar+1];

         DnDnBuffer1[bar]=DnDnBuffer1[bar+1];

         UpUpBuffer2[bar]=UpUpBuffer2[bar+1];

         UpDnBuffer2[bar]=UpDnBuffer2[bar+1];

         DnUpBuffer2[bar]=DnUpBuffer2[bar+1];

         DnDnBuffer2[bar]=DnDnBuffer2[bar+1];

         UpUpBuffer3[bar]=UpUpBuffer3[bar+1];

         UpDnBuffer3[bar]=UpDnBuffer3[bar+1];

         DnUpBuffer3[bar]=DnUpBuffer3[bar+1];

         DnDnBuffer3[bar]=DnDnBuffer3[bar+1];

         UpUpBuffer4[bar]=UpUpBuffer4[bar+1];

         UpDnBuffer4[bar]=UpDnBuffer4[bar+1];

         DnUpBuffer4[bar]=DnUpBuffer4[bar+1];

         DnDnBuffer4[bar]=DnDnBuffer4[bar+1];

        }

     }

//---     

   return(rates_total);

  }

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

//| PlotInit()                                                       |

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

void PlotInit(uint PlotNumber,

              double EmptyValue,

              int DrawBegin,

              int PlotShift)

  {

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

   PlotIndexSetInteger(PlotNumber,PLOT_DRAW_BEGIN,DrawBegin);

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

   PlotIndexSetInteger(PlotNumber,PLOT_SHIFT,PlotShift);

//---

  }

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

//| ArrayInit()                                                      |

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

void ArrayInit(uint ArrNumber,

               double &Array[])

  {

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

   SetIndexBuffer(ArrNumber,Array,INDICATOR_DATA);

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

   ArraySetAsSeries(Array,true);

//---

  }

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

//| TimeFramesCheck()                                                |

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

bool TimeFramesCheck(string IndName,

                     ENUM_TIMEFRAMES TFrame) //5@8>4 3@0D8:0 8=48:0B>@0 1 (<;04H89 B09<D@59<)

  {

//--- ?@>25@:0 ?5@8>4>2 3@0D8:>2 =0 :>@@5:B=>ABL

   if(TFrame<Period() && TFrame!=PERIOD_CURRENT)

     {

      Print("5@8>4 3@0D8:0 4;O 8=48:0B>@0 "+IndName+" =5 <>65B 1KBL <5=LH5 ?5@8>40 B5:CI53> 3@0D8:0!");

      Print("!;54C5B 87<5=8BL 2E>4=K5 ?0@0<5B@K 8=48:0B>@0!");

      return(true);

     }

//---

   return(true);

  }

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

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