GRFLeadingEdger_Pivot_HTF

Author: Copyright © 2017, Nikolay Kositsin
Price Data Components
0 Views
0 Downloads
0 Favorites
GRFLeadingEdger_Pivot_HTF
ÿþ//+---------------------------------------------------------------------+

//|                                       GRFLeadingEdger_Pivot_HTF.mq5 |

//|                                  Copyright © 2017, Nikolay Kositsin | 

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

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

#property copyright "Copyright © 2017, Nikolay Kositsin"

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

#property description "GRFLeadingEdger Bands Pivot"

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

#property version   "1.60"

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

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

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

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

#property indicator_chart_window 

#property indicator_buffers 0

#property indicator_plots   0

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

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

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

#define INDICATOR_NAME      "GRFLeadingEdger_Pivot_HTF"     // <O 8=48:0B>@0

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

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

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

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

input ENUM_TIMEFRAMES TimeFrame=PERIOD_H4;              // 5@8>4 3@0D8:0

input string Symbols_Sirname="GRFLeadingEdger_Pivot_";  // 0720=85 4;O <5B>: 8=48:0B>@0

input uint Samples=60;

input int  LookAhead=0;

input double StdLevel1=2.0;

input double  StdLevel2=4.0;

input color Up_Color=clrSpringGreen;                    // &25B 25@E=59 ?>;>AK 8=48:0B>@0

input color Dn_Color=clrYellow;                         // &25B =86=59 ?>;>AK 8=48:0B>@0

input uint SignalBar=0;                                 // =><5@ 10@0 4;O ?>;CG5=8O 7=0G5=89 8=48:0B>@0

input uint SignalLen=40;                                // ;8=0 ?>;>A 8=48:0B>@0

//---- F25B0 F5=>2KE <5B>:

input color  Middle_color=clrBlue;

input color  Upper_color1=clrMediumSeaGreen;

input color  Lower_color1=clrRed;

input color  Upper_color2=clrDodgerBlue;

input color  Lower_color2=clrMagenta;

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

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

int min_rates_total,min_rates_1;

//---- >1JO2;5=85 3;>10;L=KE ?5@5<5==KE

string UpName,MiddleName,DnName;

//---- 1JO2;5=85 AB@8=3>2 4;O B5:AB>2KE <5B>:

string upper_name1,middle_name,lower_name1,upper_name2,lower_name2;

int PerSignalLen;

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

int Ind_Handle;

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

//| Custom indicator initialization function                         | 

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

int OnInit()

  {

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

   Ind_Handle=iCustom(Symbol(),TimeFrame,"GRFLeadingEdge",Samples,LookAhead,StdLevel1,StdLevel2,0,0);

   if(Ind_Handle==INVALID_HANDLE)

     {

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

      return(INIT_FAILED);

     }

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

   min_rates_total=int(SignalLen);



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

   UpName=Symbols_Sirname+"Upper Band";

   MiddleName=Symbols_Sirname+"Middle Band";

   DnName=Symbols_Sirname+"Lower Band";

   PerSignalLen=int(SignalLen)*PeriodSeconds();

//---- =8F80;870F8O AB@8=3>2

   upper_name1=Symbols_Sirname+" upper text lable 1";

   middle_name=Symbols_Sirname+" middle text lable";

   lower_name1=Symbols_Sirname+" lower text lable 1";

   upper_name2=Symbols_Sirname+" upper text lable 2";

   lower_name2=Symbols_Sirname+" lower text lable 2";



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

//--- >?@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 indicator deinitialization function                       |

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

void OnDeinit(const int reason)

  {

//----

   ObjectsDeleteAll(0,Symbols_Sirname,-1,-1);

//----

   ChartRedraw(0);

  }

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

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

   if(BarsCalculated(Ind_Handle)<Bars(Symbol(),TimeFrame)) return(prev_calculated);

//---- 1JO2;5=85 ?5@5<5==KE A ?;020NI59 B>G:>9  

   static double Up1[1],Up2[1],Middle[1],Dn1[1],Dn2[1];



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

   if(CopyBuffer(Ind_Handle,1,SignalBar,1,Up2)<=0) return(RESET);

   if(CopyBuffer(Ind_Handle,2,SignalBar,1,Up1)<=0) return(RESET);

   if(CopyBuffer(Ind_Handle,0,SignalBar,1,Middle)<=0) return(RESET);

   if(CopyBuffer(Ind_Handle,3,SignalBar,1,Dn1)<=0) return(RESET);

   if(CopyBuffer(Ind_Handle,4,SignalBar,1,Dn2)<=0) return(RESET);



   int bar0=rates_total-1;

   int bar1=rates_total-int(MathMax(SignalLen-1,0));

   datetime time0=time[bar0]+2*PeriodSeconds();

   datetime time1=time0-PerSignalLen;



//----  8AC5< =0 3@0D8:5 25@E=89 ?@O<>C3>;L=8: ?>;>AK

   SetRectangle(0,UpName,0,time1,Up1[0],time0,Up2[0],Up_Color,STYLE_SOLID,1,UpName);

//----  8AC5< =0 3@0D8:5 =86=89 ?@O<>C3>;L=8: ?>;>AK

   SetRectangle(0,DnName,0,time1,Dn1[0],time0,Dn2[0],Dn_Color,STYLE_SOLID,1,DnName);

//----  8AC5< =0 3@0D8:5 A@54=NN ;8=8N   

   SetTline(0,MiddleName,0,time1,Middle[0],time0,Middle[0],Middle_color,STYLE_SOLID,1,MiddleName);

//----  8AC5< =0 3@0D8:5 F5=>2K5 <5B:8   

   SetRightPrice(0,upper_name1,0,time[bar0],Up1[0],Upper_color1,"Georgia");

   SetRightPrice(0,lower_name1,0,time[bar0],Dn1[0],Lower_color1,"Georgia");

   SetRightPrice(0,middle_name,0,time[bar0],Middle[0],Middle_color,"Georgia");

   SetRightPrice(0,upper_name2,0,time[bar0],Up2[0],Upper_color2,"Georgia");

   SetRightPrice(0,lower_name2,0,time[bar0],Dn2[0],Lower_color2,"Georgia");

//----

   ChartRedraw(0);

   return(rates_total);

  }

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

//|  !>740=85 ?@O<>C3>;L=8:0                                         |

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

void CreateRectangle

(

 long     chart_id,      // 845=B8D8:0B>@ 3@0D8:0

 string   name,          // 8<O >1J5:B0

 int      nwin,          // 8=45:A >:=0

 datetime time1,         // 2@5<O 1 F5=>2>3> C@>2=O

 double   price1,        // 1 F5=>2>9 C@>25=L

 datetime time2,         // 2@5<O 2 F5=>2>3> C@>2=O

 double   price2,        // 2 F5=>2>9 C@>25=L

 color    Color,         // F25B ;8=88

 int      style,         // AB8;L ;8=88

 int      width,         // B>;I8=0 ;8=88

 string   text           // B5:AB

 )

//---- 

  {

//----

   ObjectCreate(chart_id,name,OBJ_RECTANGLE,nwin,time1,price1,time2,price2);

   ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

   ObjectSetInteger(chart_id,name,OBJPROP_STYLE,style);

   ObjectSetInteger(chart_id,name,OBJPROP_WIDTH,width);

   ObjectSetString(chart_id,name,OBJPROP_TEXT,text);

   ObjectSetInteger(chart_id,name,OBJPROP_BACK,true);

   ObjectSetInteger(chart_id,name,OBJPROP_SELECTED,true);

   ObjectSetInteger(chart_id,name,OBJPROP_SELECTABLE,true);

   ObjectSetInteger(chart_id,name,OBJPROP_ZORDER,true);

   ObjectSetInteger(chart_id,name,OBJPROP_FILL,true);

//----

  }

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

//|  5@5CAB0=>2:0  ?@O<>C3>;L=8:0                                   |

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

void SetRectangle

(

 long     chart_id,      // 845=B8D8:0B>@ 3@0D8:0

 string   name,          // 8<O >1J5:B0

 int      nwin,          // 8=45:A >:=0

 datetime time1,         // 2@5<O 1 F5=>2>3> C@>2=O

 double   price1,        // 1 F5=>2>9 C@>25=L

 datetime time2,         // 2@5<O 2 F5=>2>3> C@>2=O

 double   price2,        // 2 F5=>2>9 C@>25=L

 color    Color,         // F25B ;8=88

 int      style,         // AB8;L ;8=88

 int      width,         // B>;I8=0 ;8=88

 string   text           // B5:AB

 )

//---- 

  {

//----

   if(ObjectFind(chart_id,name)==-1) CreateRectangle(chart_id,name,nwin,time1,price1,time2,price2,Color,style,width,text);

   else

     {

      ObjectSetString(chart_id,name,OBJPROP_TEXT,text);

      ObjectMove(chart_id,name,0,time1,price1);

      ObjectMove(chart_id,name,1,time2,price2);

      ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

     }

//----

  }

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

//|  RightPrice creation                                             |

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

void CreateRightPrice(long chart_id,// chart ID

                      string   name,              // object name

                      int      nwin,              // window index

                      datetime time,              // price level time

                      double   price,             // price level

                      color    Color,             // Text color

                      string   Font               // Text font

                      )

//---- 

  {

//----

   ObjectCreate(chart_id,name,OBJ_ARROW_RIGHT_PRICE,nwin,time,price);

   ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

   ObjectSetString(chart_id,name,OBJPROP_FONT,Font);

   ObjectSetInteger(chart_id,name,OBJPROP_BACK,true);

   ObjectSetInteger(chart_id,name,OBJPROP_WIDTH,2);

//----

  }

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

//|  RightPrice reinstallation                                       |

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

void SetRightPrice(long chart_id,// chart ID

                   string   name,              // object name

                   int      nwin,              // window index

                   datetime time,              // price level time

                   double   price,             // price level

                   color    Color,             // Text color

                   string   Font               // Text font

                   )

//---- 

  {

//----

   if(ObjectFind(chart_id,name)==-1) CreateRightPrice(chart_id,name,nwin,time,price,Color,Font);

   else ObjectMove(chart_id,name,0,time,price);

//----

  }

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

//|  !>740=85 B@5=4>2>9 ;8=88                                        |

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

void CreateTline

(

 long     chart_id,      // 845=B8D8:0B>@ 3@0D8:0

 string   name,          // 8<O >1J5:B0

 int      nwin,          // 8=45:A >:=0

 datetime time1,         // 2@5<O 1 F5=>2>3> C@>2=O

 double   price1,        // 1 F5=>2>9 C@>25=L

 datetime time2,         // 2@5<O 2 F5=>2>3> C@>2=O

 double   price2,        // 2 F5=>2>9 C@>25=L

 color    Color,         // F25B ;8=88

 int      style,         // AB8;L ;8=88

 int      width,         // B>;I8=0 ;8=88

 string   text           // B5:AB

 )

//---- 

  {

//----

   ObjectCreate(chart_id,name,OBJ_TREND,nwin,time1,price1,time2,price2);

   ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

   ObjectSetInteger(chart_id,name,OBJPROP_STYLE,style);

   ObjectSetInteger(chart_id,name,OBJPROP_WIDTH,width);

   ObjectSetString(chart_id,name,OBJPROP_TEXT,text);

   ObjectSetInteger(chart_id,name,OBJPROP_BACK,false);

   ObjectSetInteger(chart_id,name,OBJPROP_RAY_RIGHT,false);

   ObjectSetInteger(chart_id,name,OBJPROP_RAY,false);

   ObjectSetInteger(chart_id,name,OBJPROP_SELECTED,true);

   ObjectSetInteger(chart_id,name,OBJPROP_SELECTABLE,true);

   ObjectSetInteger(chart_id,name,OBJPROP_ZORDER,true);

//----

  }

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

//|  5@5CAB0=>2:0 B@5=4>2>9 ;8=88                                   |

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

void SetTline

(

 long     chart_id,      // 845=B8D8:0B>@ 3@0D8:0

 string   name,          // 8<O >1J5:B0

 int      nwin,          // 8=45:A >:=0

 datetime time1,         // 2@5<O 1 F5=>2>3> C@>2=O

 double   price1,        // 1 F5=>2>9 C@>25=L

 datetime time2,         // 2@5<O 2 F5=>2>3> C@>2=O

 double   price2,        // 2 F5=>2>9 C@>25=L

 color    Color,         // F25B ;8=88

 int      style,         // AB8;L ;8=88

 int      width,         // B>;I8=0 ;8=88

 string   text           // B5:AB

 )

//---- 

  {

//----

   if(ObjectFind(chart_id,name)==-1) CreateTline(chart_id,name,nwin,time1,price1,time2,price2,Color,style,width,text);

   else

     {

      ObjectSetString(chart_id,name,OBJPROP_TEXT,text);

      ObjectMove(chart_id,name,0,time1,price1);

      ObjectMove(chart_id,name,1,time2,price2);

      ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

     }

//----

  }

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

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