XMA_BB_Pivot

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

//|                                                    XMA_BB_Pivot.mq5 |

//|                                  Copyright © 2017, Nikolay Kositsin | 

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

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

//| ;O @01>BK  8=48:0B>@0  A;54C5B  ?>;>68BL D09; SmoothAlgorithms.mqh |

//| 2 ?0?:C (48@5:B>@8N): :0B0;>3_40==KE_B5@<8=0;0\\MQL5\Include        |

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

#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"     // <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 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=2.0;              // 45280F8O 1

input double BandsDeviation2=4.0;              // 45280F8O 2

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

input color Up_Color=clrAquamarine;            // &25B 25@E=59 ?>;>AK 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

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

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

int PerSignalLen;

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

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

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

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 B@5=4>2>9 ;8=88                                   |

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

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

     }

//----

  }

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

//| Custom indicator initialization function                         | 

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

void OnInit()

  {

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

   min_rates_1=GetStartBars(XMA_Method,XLength,XPhase)+1;

   min_rates_total=min_rates_1+int(XLength);



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

   UpName=Symbols_Sirname+"Upper 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

  }

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

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

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

   double price,line,stdev;

   static double Up1,Up2,Dn1,Dn2;

//---- 1JO2;5=85 F5;KE ?5@5<5==KE 8 ?>;CG5=85 C65 ?>AG8B0==KE 10@>2

   int first,bar;



//---- @0AGQB AB0@B>2>3> =><5@0 first 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=0; // AB0@B>2K9 =><5@ 4;O @0AGQB0 2A5E 10@>2

   else first=prev_calculated-1; // AB0@B>2K9 =><5@ 4;O @0AGQB0 =>2KE 10@>2



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

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

     {

      price=PriceSeries(IPC,bar,open,low,high,close);

      line=XMA1.XMASeries(0,prev_calculated,rates_total,XMA_Method,XPhase,XLength,price,bar,false);

      //----

      stdev=STD1.StdDevSeries(min_rates_1,prev_calculated,rates_total,XLength,BandsDeviation1,price,line,bar,false);

      Up1=line+stdev;

      Dn1=line-stdev;

      //----

      stdev=STD2.StdDevSeries(min_rates_1,prev_calculated,rates_total,XLength,BandsDeviation2,price,line,bar,false);

      Up2=line+stdev;

      Dn2=line-stdev;

     }

    

   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,time0,Up2,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,time0,Dn2,Dn_Color,STYLE_SOLID,1,DnName);

//----

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