XMA_BB_Pivot_HTF

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

//|                                                XMA_BB_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 "XMA Bollinger 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      "XMA_BB_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

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

//|  ?8A0=85 :;0AA>2 CA@54=5=89               |

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

#include <SmoothAlgorithms.mqh> 

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

//---- >1JO2;5=85 ?5@5<5==KE :;0AA>2 CXMA 8 CStdDeviation 87 D09;0 SmoothAlgorithms.mqh

CXMA XMA1;

CStdDeviation STD1,STD2;

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

//|  >1JO2;5=85 ?5@5G8A;5=89                   |

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

enum Applied_price_ //"8? :>=AB0=BK

  {

   PRICE_CLOSE_ = 1,     //Close

   PRICE_OPEN_,          //Open

   PRICE_HIGH_,          //High

   PRICE_LOW_,           //Low

   PRICE_MEDIAN_,        //Median Price (HL/2)

   PRICE_TYPICAL_,       //Typical Price (HLC/3)

   PRICE_WEIGHTED_,      //Weighted Close (HLCC/4)

   PRICE_SIMPL_,         //Simpl Price (OC/2)

   PRICE_QUARTER_,       //Quarted Price (HLOC/4) 

   PRICE_TRENDFOLLOW0_,  //TrendFollow_1 Price 

   PRICE_TRENDFOLLOW1_,  //TrendFollow_2 Price

   PRICE_DEMARK_         //Demark Price 

  };

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

//|  >1JO2;5=85 ?5@5G8A;5=89                   |

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

/*enum Smooth_Method - ?5@5G8A;5=85 >1JO2;5=> 2 D09;5 SmoothAlgorithms.mqh

  {

   MODE_SMA_,  //SMA

   MODE_EMA_,  //EMA

   MODE_SMMA_, //SMMA

   MODE_LWMA_, //LWMA

   MODE_JJMA,  //JJMA

   MODE_JurX,  //JurX

   MODE_ParMA, //ParMA

   MODE_T3,    //T3

   MODE_VIDYA, //VIDYA

   MODE_AMA,   //AMA

  }; */

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

//|  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="XMA_BB_Pivot_";  // 0720=85 4;O <5B>: 8=48:0B>@0

input Smooth_Method XMA_Method=MODE_SMA_;      // <5B>4 CA@54=5=8O

input uint XLength=100;                        // 3;C18=0  CA@54=5=8O                    

input int XPhase=15;                           // ?0@0<5B@ ?5@2>3> CA@54=5=8O,

//---- 4;O JJMA 87<5=ONI89AO 2 ?@545;0E -100 ... +100, 2;8O5B =0 :0G5AB2> ?5@5E>4=>3> ?@>F5AA0;

//---- ;O VIDIA MB> ?5@8>4 CMO, 4;O AMA MB> ?5@8>4 <54;5==>9 A:>;L7OI59

input double BandsDeviation1=1.8;              // 45280F8O 1

input double BandsDeviation2=2.2;              // 45280F8O 2

input Applied_price_ IPC=PRICE_CLOSE_;         // F5=>20O :>=AB0=B0

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

input color Middle_Color=clrGray;              // &25B A@54=59 ;8=88 8=48:0B>@0

input color Dn_Color=clrPlum;                  // &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=clrGray;

input color  Upper_color1=clrDeepSkyBlue;

input color  Lower_color1=clrPlum;

input color  Upper_color2=clrDeepSkyBlue;

input color  Lower_color2=clrPlum;

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

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

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 XMA_BBx5_Cloud

   Ind_Handle=iCustom(Symbol(),TimeFrame,"XMA_BBx5_Cloud",XMA_Method,XLength,XPhase,BandsDeviation1,BandsDeviation2,IPC,

                      0,0,Middle_color,Upper_color1,Lower_color1,Upper_color2,Lower_color2);

   if(Ind_Handle==INVALID_HANDLE)

     {

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

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



//--- 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,0,SignalBar,1,Up2)<=0) return(RESET);

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

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

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

   if(CopyBuffer(Ind_Handle,6,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 >;;8=465@0

   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 >;;8=465@0

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

//----

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