Author: Copyright © 2004, MetaQuotes Software Corp.
0 Views
0 Downloads
0 Favorites
H_L_
ÿþ//+------------------------------------------------------------------+

//|                                                         H_L_.mq5 | 

//|                      Copyright © 2004, MetaQuotes Software Corp. | 

//|                                        http://www.metaquotes.net | 

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

#property copyright "Copyright © 2004, MetaQuotes Software Corp."

#property link "http://www.metaquotes.net"

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

#property indicator_buffers 4

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

#property indicator_plots   4

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

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

//---- 2 :0G5AB25 F25B0 ;8=88 8=48:0B>@0 8A?>;L7>20= 3>;C1>9 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 1

#property indicator_width1  1

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

#property indicator_label1  "High 2"

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

//| 0@0<5B@K >B@8A>2:8 25@E=59 ;8=88 1          |

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

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

#property indicator_type2   DRAW_LINE

//---- 2 :0G5AB25 F25B0 25@E=59 ;8=88 8=48:0B>@0 8A?>;L7>20= A8=89 F25B

#property indicator_color2  clrBlue

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

#property indicator_width2  1

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

#property indicator_label2  "High 1"

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

//| 0@0<5B@K >B@8A>2:8 =86=59 ;8=88 1           |

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

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

#property indicator_type3   DRAW_LINE

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

#property indicator_color3  clrRed

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

#property indicator_style3  STYLE_SOLID

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

#property indicator_width3 1 

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

#property indicator_label3  "Low 1"

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

//| 0@0<5B@K >B@8A>2:8 =86=59 ;8=88 2           |

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

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

#property indicator_type4   DRAW_LINE

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

#property indicator_color4  clrMagenta

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

#property indicator_style4  STYLE_SOLID

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

#property indicator_width4 1 

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

#property indicator_label4  "Low 2"

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

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

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

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

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

//|  %+  " + "                 |

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

input uint S=4;

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

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

//---- >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 Buffer_0[],Buffer_1[],Buffer_2[],Buffer_3[];

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

double MaRo;

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

int ATR_Handle;

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

int min_rates_total;

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

//| Custom indicator initialization function                         | 

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

void OnInit()

  {

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

   min_rates_total=int(S);



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

   SetIndexBuffer(0,Buffer_0,INDICATOR_DATA);

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

   PlotIndexSetInteger(0,PLOT_SHIFT,Shift);

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

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);

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



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

   SetIndexBuffer(1,Buffer_1,INDICATOR_DATA);

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

   PlotIndexSetInteger(1,PLOT_SHIFT,Shift);

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

   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);

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



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

   SetIndexBuffer(2,Buffer_2,INDICATOR_DATA);

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

   PlotIndexSetInteger(2,PLOT_SHIFT,Shift);

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

   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,min_rates_total);

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



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

   SetIndexBuffer(3,Buffer_3,INDICATOR_DATA);

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

   PlotIndexSetInteger(3,PLOT_SHIFT,Shift);

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

   PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,min_rates_total);

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

   PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,0);



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

   ArraySetAsSeries(Buffer_0,true);

   ArraySetAsSeries(Buffer_1,true);

   ArraySetAsSeries(Buffer_2,true);

   ArraySetAsSeries(Buffer_3,true);

   

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

   string shortname;

   StringConcatenate(shortname,"H_L_(",S,")");

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

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

  }

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

//| XMA 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(RESET);



//---- 1JO2;5=85 F5;KE ?5@5<5==KE

   int limit,bar;



//---- @0AGQB AB0@B>2>3> =><5@0 first 4;O F8:;0 ?5@5AGQB0 10@>2

   limit=rates_total-1-int(S); // AB0@B>2K9 =><5@ 4;O @0AGQB0 2A5E 10@>2



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

   ArraySetAsSeries(open,true);

   ArraySetAsSeries(high,true);

   ArraySetAsSeries(low,true);

   ArraySetAsSeries(close,true);

//----   

   int A1=0;int A1d=0;

   int A2=0;int A2d=0;

   int V1=0;int V1d=0;

   int V2=0;int V2d=0;

   int AX=0;int AXd=0;

   int BX=0;int BXd=0;

   int CX=0;int CXd=0;

   int DX=0;int DXd=0;

//----

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

     {

      Buffer_0[bar]=high[bar];

      Buffer_1[bar]=low[bar];

      Buffer_2[bar]=(open[bar]+close[bar])/2;

      Buffer_3[bar]=(open[bar]+close[bar])/2;

     }



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

   for(int cnt2=0; cnt2<int(S); cnt2++)

     {

      AX=0;BX=0;CX=0;DX=0;A1=0;A2=0;V1=0;V2=0;

      AXd=0;BXd=0;CXd=0;DXd=0;A1d=0;A2d=0;V1d=0;V2d=0;

      //----

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

        {

         //---------------------------------------------------

         if(bar>0 && Buffer_0[bar]<Buffer_0[bar-1])

           {

            AX=bar-1;

            BX=AX;

           }

         if(bar>0 && Buffer_0[bar]==Buffer_0[bar-1] && AX>0)

           {

            BX=bar-1;

           }

         if(bar>0 && Buffer_0[bar]>Buffer_0[bar-1] && AX>0) //

           {

            if(A1==0)

              {

               A1=(AX+BX)/2;

              }

            if(A1>0)

              {

               A2=(AX+BX)/2;

              }

            if(A1>0 && A2>0)

              {

               for(int cnt4=1; cnt4<=A1-A2; cnt4++)

                 {

                  Buffer_0[A2+cnt4]=Buffer_0[A2]+(((Buffer_0[A1]-Buffer_0[A2])*cnt4)/(A1-A2));

                 }

               A1=A2;

               A2=0;

              }

           }

         //-----------------------------------------------

         if(bar>0 && Buffer_1[bar]>Buffer_1[bar-1])

           {

            CX=bar-1;

            DX=CX;

           }

         if(bar>0 && Buffer_1[bar]==Buffer_1[bar-1] && CX>0)

           {

            DX=bar-1;

           }

         if(bar>0 && Buffer_1[bar]<Buffer_1[bar-1] && CX>0)

           {

            if(V1==0)

              {

               V1=(CX+DX)/2;

              }

            if(V1>0)

              {

               V2=(CX+DX)/2;

              }

            if(V1>0 && V2>0)

              {

               for(int cnt5=1;cnt5<=V1-V2;cnt5++)

                 {

                  Buffer_1[V2+cnt5]=Buffer_1[V2]+(((Buffer_1[V1]-Buffer_1[V2])*cnt5)/(V1-V2));

                 }

               V1=V2;

               V2=0;

              }

           }

         //---------------------------------------------------

         if(bar>0 && Buffer_2[bar]<Buffer_2[bar-1])

           {

            AXd=bar-1;

            BXd=AXd;

           }

         if(bar>0 && Buffer_2[bar]==Buffer_2[bar-1] && AXd>0)

           {

            BXd=bar-1;

           }

         if(bar>0 && Buffer_2[bar]>Buffer_2[bar-1] && AXd>0)

           {

            if(A1d==0)

              {

               A1d=(AXd+BXd)/2;

              }

            if(A1d>0)

              {

               A2d=(AXd+BXd)/2;

              }

            if(A1d>0 && A2d>0)

              {

               for(int cnt41=1; cnt41<=A1d-A2d; cnt41++)

                 {

                  Buffer_2[A2d+cnt41]=Buffer_2[A2d]+(((Buffer_2[A1d]-Buffer_2[A2d])*cnt41)/(A1d-A2d));

                 }

               A1d=A2d;

               A2d=0;

              }

           }

         //-----------------------------------------------

         if(bar>0 && Buffer_3[bar]>Buffer_3[bar-1])

           {

            CXd=bar-1;

            DXd=CXd;

           }

         if(bar>0 && Buffer_3[bar]==Buffer_3[bar-1] && CXd>0)

           {

            DXd=bar-1;

           }

         if(bar>0 && Buffer_3[bar]<Buffer_3[bar-1] && CXd>0)

           {

            if(V1d==0)

              {

               V1d=(CXd+DXd)/2;

              }

            if(V1d>0)

              {

               V2d=(CXd+DXd)/2;

              }

            if(V1d>0 && V2d>0)

              {

               for(int cnt51=1; cnt51<=V1d-V2d; cnt51++)

                 {

                  Buffer_3[V2d+cnt51]=Buffer_3[V2d]+(((Buffer_3[V1d]-Buffer_3[V2d])*cnt51)/(V1d-V2d));

                 }

               V1d=V2d;

               V2d=0;

              }

           }

        }

      //-----------------------------------------------------

     }

//----     

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