MurreyMathFixPeriod_Lv

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

//|                                       MurreyMathFixPeriod_Lv.mq5 |

//|                               Copyright © 2018, Nikolay Kositsin | 

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

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

/*

   --------------------------------------------------------------------------------------------

  * 8=88 8/8 8 0/8 (:>=G0B5;L=>5 A>?@>B82;5=85).

  * -B8 ;8=88 A0<K5 A8;L=K5 8 >:07K20NB A8;L=59H85 A>?@>B82;5=8O 8 ?>445@6:C.

   --------------------------------------------------------------------------------------------

  * 8=8O 7/8  (!;010O, <5AB> 4;O >AB0=>2:8 8 @072>@>B0). Weak, Stall and Reverse

  * -B0 ;8=8O A;010. A;8 F5=0 70H;0 A;8H:>< 40;5:> 8 A;8H:>< 1KAB@> 8 5A;8 >=0 >AB0=>28;0AL >:>;> MB>9 ;8=88, 

  * 7=0G8B >=0 @0725@=5BAO 1KAB@> 2=87. A;8 F5=0 =5 >AB0=>28;0AL >:>;> MB>9 ;8=88, >=0 ?@>4>;68B 42865=85 225@E : 8/8.

   --------------------------------------------------------------------------------------------

  * 8=8O 1/8  (!;010O, <5AB> 4;O >AB0=>2:8 8 @072>@>B0). Weak, Stall and Reverse

  * -B0 ;8=8O A;010. A;8 F5=0 70H;0 A;8H:>< 40;5:> 8 A;8H:>< 1KAB@> 8 5A;8 >=0 >AB0=>28;0AL >:>;> MB>9 ;8=88, 

  * 7=0G8B >=0 @0725@=5BAO 1KAB@> 225@E. A;8 F5=0 =5 >AB0=>28;0AL >:>;> MB>9 ;8=88, >=0 ?@>4>;68B 42865=85 2=87 : 0/8.

   --------------------------------------------------------------------------------------------

  * 8=88 6/8 8 2/8 (@0I5=85, @072>@>B). Pivot, Reverse

  * -B8 425 ;8=88 CABC?0NB 2 A2>59 A8;5 B>;L:> 4/8 2 A2>59 A?>A>1=>AB8 ?>;=>ABLN @0725@=CBL F5=>2>5 42865=85.

   --------------------------------------------------------------------------------------------

  * 8=8O 5/8 (5@E B>@3>2>3> 480?07>=0). Top of Trading Range

  * &5=K 2A5E @K=:>2 B@0BOB 40% 2@5<5=8, =0 42865=85 <564C 5/8 8 3/8 ;8=8O<8. 

  * A;8 F5=0 428305BAO >:>;> ;8=88 5/8 8 >AB05BAO >:>;> =55 2 B5G5=88 10-12 4=59, @K=>: A:070; GB> A;54C5B 

  * ?@>4020BL 2 MB>9 «?@5<80;L=>9 7>=5», GB> 8 45;0NB =5:>B>@K5 ;N48, => 5A;8 F5=0 A>E@0=O5B B5=45=F8N >AB020BLAO 

  * 2KH5 5/8, B> >=0 8 >AB0=5BAO 2KH5 =55. A;8, >4=0:>, F5=0 ?0405B =865 5/8, B> >=0 A:>@55 2A53> ?@>4>;68B 

  * ?040BL 40;55 4> A;54CNI53> C@>2=O A>?@>B82;5=8O.

   --------------------------------------------------------------------------------------------

  * 8=8O 3/8 (=> B>@3>2>3> 480?07>=0). Bottom of Trading Range

  * A;8 F5=K =865 MB>9 ;8=8 8 42830NBAO 225@E, B> F5=5 1C45B A;>6=> ?@>18BL MB>B C@>25=L. 

  * A;8 ?@>1820NB 225@E MBC ;8=8N 8 >AB0NBAO 2KH5 =55 2 B5G5=88 10-12 4=59, 7=0G8B F5=K >AB0=CBAO 2KH5 MB>9 ;8=88 

  * 8 ?>B@0BOB 40% 2@5<5=8 42830OAL <564C MB>9 ;8=859 8 5/8 ;8=859.

   --------------------------------------------------------------------------------------------

  * 8=8O 4/8 (;02=0O ;8=8O A>?@>B82;5=8O/?>445@6:8). Major Support/Resistance

  * -B0 ;8=8O >15A?5G8205B =081>;LH55 A>?@>B82;5=85/?>445@6:C. -B>B C@>25=L O2;O5BAO ;CGH8< 4;O =>2>9 ?>:C?:8 8;8 ?@>4068. 

  * A;8 F5=0 =0E>48BAO 2KH5 4/8, B> MB> A8;L=K9 C@>25=L ?>445@6:8. A;8 F5=0 =0E>48BAO =865 4/8, B> MB> ?@5:@0A=K9 C@>25=L 

  * A>?@>B82;5=8O.

   --------------------------------------------------------------------------------------------

  */

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

//|                                       MurreyMathFixPeriod_Lv.mq5 |

//|                               Copyright © 2018, Nikolay Kositsin | 

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

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

#property copyright "Copyright © 2018, Nikolay Kositsin"

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

#property version   "1.00"

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

#property indicator_chart_window

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

#property indicator_buffers 41

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

#property indicator_plots   40

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

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

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

#define  width_line          2 // >=AB0=B0 4;O B>;I8=K ;8=88 8=48:0B>@0

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

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

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

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

//--- plot buffer 1

//#property indicator_label1  "@0I5=85, @072>@>B [-2/8]" //"extremely overshoot [-2/8]"

#property indicator_type1   DRAW_LINE

#property indicator_color1  clrBlue

#property indicator_style1  STYLE_SOLID

#property indicator_width1  width_line

//--- plot buffer 2

//#property indicator_label2  "!;010O >AB0=>2:0 8 @072>@>B [-1/8]" // "overshoot [-1/8]"

#property indicator_type2   DRAW_LINE

#property indicator_color2  clrDarkViolet

#property indicator_style2  STYLE_SOLID

#property indicator_width2  width_line

//--- plot buffer 3

//#property indicator_label3  ":>=G0B5;L=>5 A>?@>B82;5=85 [0/8]" // "Ultimate Support - extremely oversold [0/8]"

#property indicator_type3   DRAW_LINE

#property indicator_color3  clrAqua

#property indicator_style3  STYLE_SOLID

#property indicator_width3  width_line

//--- plot buffer 4

//#property indicator_label4  "!;010O >AB0=>2:0 8 @072>@>B [1/8]" // "Weak, Stall and Reverse - [1/8]"

#property indicator_type4   DRAW_LINE

#property indicator_color4  clrPeru

#property indicator_style4  STYLE_SOLID

#property indicator_width4  width_line

//--- plot buffer 5

//#property indicator_label5  "@0I5=85, @072>@>B [2/8]" // "Pivot, Reverse - major [2/8]"

#property indicator_type5   DRAW_LINE

#property indicator_color5  clrRed

#property indicator_style5  STYLE_SOLID

#property indicator_width5  width_line

//--- plot buffer 6

//#property indicator_label6  "=> B>@3>2>3> 480?07>=0 [3/8]" // "Bottom of Trading Range - [3/8], if 10-12 bars then 40% Time. BUY Premium Zone"

#property indicator_type6   DRAW_LINE

#property indicator_color6  clrLime

#property indicator_style6  STYLE_SOLID

#property indicator_width6  width_line

//--- plot buffer 7

//#property indicator_label7  ";02=K5 A>?@>B82;5=85/?>445@6:0 [4/8]" // "Major Support/Resistance Pivotal Point [4/8]- Best New BUY or SELL level"

#property indicator_type7   DRAW_LINE

#property indicator_color7  clrDarkGray

#property indicator_style7  STYLE_SOLID

#property indicator_width7  width_line

//--- plot buffer 8

//#property indicator_label8  "5@E B>@3>2>3> 480?07>=0 [5/8]" // "Top of Trading Range - [5/8], if 10-12 bars then 40% Time. SELL Premium Zone"

#property indicator_type8   DRAW_LINE

#property indicator_color8  clrLime

#property indicator_style8  STYLE_SOLID

#property indicator_width8  width_line

//--- plot buffer 9

//#property indicator_label9  "@0I5=85, @072>@>B [6/8]" // "Pivot, Reverse - major [6/8]"

#property indicator_type9   DRAW_LINE

#property indicator_color9  clrRed

#property indicator_style9  STYLE_SOLID

#property indicator_width9  width_line

//--- plot buffer 10

//#property indicator_label10  "!;010O >AB0=>2:0 8 @072>@>B [7/8]" // "Weak, Stall and Reverse - [7/8]"

#property indicator_type10   DRAW_LINE

#property indicator_color10  clrPeru

#property indicator_style10  STYLE_SOLID

#property indicator_width10  width_line

//--- plot buffer 11

//#property indicator_label11  ":>=G0B5;L=>5 A>?@>B82;5=85 [8/8]" // "Ultimate Resistance - extremely overbought [8/8]"

#property indicator_type11   DRAW_LINE

#property indicator_color11  clrAqua

#property indicator_style11  STYLE_SOLID

#property indicator_width11  width_line

//--- plot buffer 12

//#property indicator_label12  "!;010O >AB0=>2:0 8 @072>@>B [+1/8]" // "overshoot [+1/8]"

#property indicator_type12   DRAW_LINE

#property indicator_color12  clrDarkViolet

#property indicator_style12  STYLE_SOLID

#property indicator_width12  width_line

//--- plot buffer 13

//#property indicator_label13  "@0I5=85, @072>@>B [+2/8]" // "extremely overshoot [+2/8]"

#property indicator_type13   DRAW_LINE

#property indicator_color13  clrBlue

#property indicator_style13  STYLE_SOLID

#property indicator_width13  width_line



//#property indicator_label40  "5@B8:0;L=K5 @0745;8B5;8 ?5@8>4>2"

#property indicator_type40   DRAW_HISTOGRAM2

#property indicator_color40  clrSilver

#property indicator_style40  STYLE_DASH

#property indicator_width40  1

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

#property indicator_label40  "5@B8:0;L=K9 @0745;8B5;L ?5@8>4>2 8=48:0B>@0"

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

// ?8A0=85 ?5@5G8A;5=8O type_font               |

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

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

#include <GetFontName.mqh>

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

//|  %+  " + "                 |

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

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

input int CalculationPeriod=64;              //5@8>4 @0AG5B0 P

input int StepBack=0;

input int    FontSize=8;                     //@07<5@ H@8DB0

input type_font FontType=Font7;              //B8? H@8DB0

input string  LableSirname="Murrey_Math_Lv"; //5@20O G0ABL 8<5=8 3@0D8G5A:8E >1J5:B>2

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

//---- 1JO2;5=85 <0AA820 4;O E@0=5=8O 8<Q= ;8=89

string LinesNames[13]=

  {

   "@0I5=85, @072>@>B [-2/8]",

   "!;010O >AB0=>2:0 8 @072>@>B [-1/8]",

   ":>=G0B5;L=>5 A>?@>B82;5=85 [0/8]",

   "!;010O >AB0=>2:0 8 @072>@>B [1/8]",

   "@0I5=85, @072>@>B [2/8]",

   "=> B>@3>2>3> 480?07>=0 [3/8]",

   ";02=K5 A>?@>B82;5=85/?>445@6:0 [4/8]",

   "5@E B>@3>2>3> 480?07>=0 [5/8]",

   "@0I5=85, @072>@>B [6/8]",

   "!;010O >AB0=>2:0 8 @072>@>B [7/8]",

   ":>=G0B5;L=>5 A>?@>B82;5=85 [8/8]",

   "!;010O >AB0=>2:0 8 @072>@>B [+1/8]",

   "@0I5=85, @072>@>B [+2/8]"

  };

//---- 1JO2;5=85 ?5@5<5==>9 4;O E@0=5=8O @57C;LB0B0 8=8F80;870F88 8=48:0B>@0

bool Init;

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

int ShiftBarsForward;

//---- 1JO2;5=85 F5;KE ?5@5<5==KE 4;O E5=4;>2 8=48:0B>@>2

int Murrey_Handle;

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

int min_rates_total,Murrey_Calculated;

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

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

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

class CIndicatorsBuffers

  {

public:

   double            IndBuffer[];

  };

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

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

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

CIndicatorsBuffers Ind[3][13];

CIndicatorsBuffers Ind1[2];

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

//| >;CG5=85 C@>2=59 N@@5O                                         |

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

bool GetMurreyLevels(double &Array[],datetime Time)

  {

//----

   double Murrey[1];

   for(int i=0; i<13; i++)

     {

      if(CopyBuffer(Murrey_Handle,i,Time,1,Murrey)<=0) return(RESET);

      Array[i]=Murrey[0];

     }

//----

   return(true);

  }

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

//| @>25@:0 C@>2=59 N@@5O =0 ?5@5AB0=>2:C                          |

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

bool CheckMurreyLevels(double &Array[])

  {

//----

   static double OldMurrey[13];



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

      if(Array[iii]!=OldMurrey[iii])

        {

         for(int kkk=0; kkk<13; kkk++) OldMurrey[kkk]=Array[kkk];

         return(true);

        }

//----

   return(false);

  }

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

//| Custom indicator initialization function                         |

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

void OnInit()

  {

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

   Murrey_Calculated=CalculationPeriod+StepBack+3;

   min_rates_total=Murrey_Calculated*PeriodSeconds(Timeframe)/PeriodSeconds(PERIOD_CURRENT);



   Init=true;

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

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

     {

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

      Init=false;

      return;

     }



//---- ?>;CG5=85 E5=4;0 8=48:0B>@0 MurreyMath_Lv

   Murrey_Handle=iCustom(NULL,Timeframe,"Murrey_Math_Lv",CalculationPeriod,StepBack,true,FontSize,FontType,LableSirname);

   if(Murrey_Handle==INVALID_HANDLE) Print(" 5 C40;>AL ?>;CG8BL E5=4; 8=48:0B>@0 MurreyMath_Lv");



   for(int kkk=0; kkk<3; kkk++)

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

        {

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

         SetIndexBuffer(13*kkk+iii,Ind[kkk][iii].IndBuffer,INDICATOR_DATA);



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

         PlotIndexSetDouble(13*kkk+iii,PLOT_EMPTY_VALUE,EMPTY_VALUE);



         //---- A>740=85 <5B:8 4;O >B>1@065=8O 2 DataWindow

         PlotIndexSetString(13*kkk+iii,PLOT_LABEL,LinesNames[iii]);

        }



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

   SetIndexBuffer(39,Ind1[0].IndBuffer,INDICATOR_DATA);

   SetIndexBuffer(40,Ind1[1].IndBuffer,INDICATOR_DATA);



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

   PlotIndexSetDouble(39,PLOT_EMPTY_VALUE,EMPTY_VALUE);



   for(int fff=1; fff<3; fff++)

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

        {

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

         PlotIndexSetInteger(13*fff+iii,PLOT_DRAW_TYPE,PlotIndexGetInteger(iii,PLOT_DRAW_TYPE));

         PlotIndexSetInteger(13*fff+iii,PLOT_LINE_STYLE,PlotIndexGetInteger(iii,PLOT_LINE_STYLE));

         PlotIndexSetInteger(13*fff+iii,PLOT_LINE_WIDTH,PlotIndexGetInteger(iii,PLOT_LINE_WIDTH));

         PlotIndexSetInteger(13*fff+iii,PLOT_LINE_COLOR,PlotIndexGetInteger(iii,PLOT_LINE_COLOR));

        }

//----   

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);

   IndicatorSetString(INDICATOR_SHORTNAME,"Murrey_LvMath_Lv("+EnumToString(Timeframe)+", "+string(CalculationPeriod)+", "+string(StepBack)+")");

//----

   return;

  }

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

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

  {

//---- ?@>25@:0 :>;8G5AB20 10@>2 =0 4>AB0B>G=>ABL 4;O @0AGQB0

   if(BarsCalculated(Murrey_Handle)<10*Murrey_Calculated || rates_total<min_rates_total || !Init) return(RESET);

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



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

   int first,oldcount;

   static int count,bar1;

   static double Murrey[13];

   double val[26];



//---- @0AGQB AB0@B>2>3> =><5@0 limit 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;

      bar1=first;



      for(int kkk=0; kkk<3; kkk++)

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

            for(int bar=0; bar<min_rates_total; bar++)



               count=0;

     }

   else first=prev_calculated-1;



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

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

     {

      if(!GetMurreyLevels(Murrey,time[bar]))return(RESET);

      if(CheckMurreyLevels(Murrey))

        {

         count++;

         if(count>2) count=0;



         bar1=bar-1;

         for(int iii=0; iii<13; iii++) Ind[count][iii].IndBuffer[bar1]=Murrey[iii];

        }



      for(int kkk=0; kkk<3; kkk++) for(int iii=0; iii<13; iii++) Ind[kkk][iii].IndBuffer[bar]=EMPTY_VALUE;

      for(int iii=0; iii<13; iii++) Ind[count][iii].IndBuffer[bar]=Murrey[iii];



      //----  0AGQB 8 >B@8A>2:0 25@B8:0;L=KE @0745;8B5;59 ?5@8>4>2

      Ind1[0].IndBuffer[bar]=EMPTY_VALUE;

      Ind1[1].IndBuffer[bar]=EMPTY_VALUE;

      ArrayInitialize(val,NULL);

      oldcount=count-1;

      if(oldcount<0) oldcount=2;



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

        {

         val[iii]=Ind[oldcount][iii].IndBuffer[bar1];

         val[iii+13]=Ind[count][iii].IndBuffer[bar];

        }

      Ind1[0].IndBuffer[bar1]=5*val[25-ArrayMaximum(val)];

      Ind1[1].IndBuffer[bar1]=val[25-ArrayMinimum(val)]/5;

     }

//----

   return(rates_total);

  }

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

Comments