Author: Copyright 2015, Mohit Marwaha
Price Data Components
Indicators Used
Indicator of the average true range
0 Views
0 Downloads
0 Favorites
AtrValues
ÿþ//+------------------------------------------------------------------+

//|                                                    AtrValues.mq5 |

//|                                    Copyright 2015, Mohit Marwaha |

//|                                               marwaha1@gmail.com |

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

#property copyright "Copyright 2015, Mohit Marwaha"

#property link      "marwaha1@gmail.com"

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

#property version   "1.00"

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

//|  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      "AtrValues"         // <O 8=48:0B>@0

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

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

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

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

#include <GetFontName.mqh>

CFontName FONT;

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

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

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

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



//---- =0AB@>9:8 4;O B09<D@59<0 1

input bool ShowTimeframe1=true;                         //1 B>1@065=85 B09<D@59<0

input ENUM_TIMEFRAMES Timeframe1=PERIOD_M1;             //1 "09<D@59< 8=48:0B>@0 4;O @0AG5B0 8=48:0B>@0

input uint iPeriod1=10;                                 //1 5@8>4 8=48:0B>@0



//---- =0AB@>9:8 4;O B09<D@59<0 2

input bool ShowTimeframe2=true;                         //2 B>1@065=85 B09<D@59<0

input ENUM_TIMEFRAMES Timeframe2=PERIOD_M5;             //2 "09<D@59< 8=48:0B>@0 4;O @0AG5B0 8=48:0B>@0

input uint iPeriod2=10;                                 //2 5@8>4 8=48:0B>@0



//---- =0AB@>9:8 4;O B09<D@59<0 3

input bool ShowTimeframe3=true;                         //3 B>1@065=85 B09<D@59<0

input ENUM_TIMEFRAMES Timeframe3=PERIOD_M15;            //3 "09<D@59< 8=48:0B>@0 4;O @0AG5B0 8=48:0B>@0

input uint iPeriod3=10;                                 //3 5@8>4 8=48:0B>@0



//---- =0AB@>9:8 4;O B09<D@59<0 4

input bool ShowTimeframe4=true;                         //4 B>1@065=85 B09<D@59<0

input ENUM_TIMEFRAMES Timeframe4=PERIOD_M30;            //4 "09<D@59< 8=48:0B>@0 4;O @0AG5B0 8=48:0B>@0

input uint iPeriod4=10;                                 //4 5@8>4 8=48:0B>@0 4;O @0AG5B0 8=48:0B>@0



//---- =0AB@>9:8 4;O B09<D@59<0 5

input bool ShowTimeframe5=true;                         //5 B>1@065=85 B09<D@59<0

input ENUM_TIMEFRAMES Timeframe5=PERIOD_H1;             //5 "09<D@59< 8=48:0B>@0 4;O @0AG5B0 8=48:0B>@0

input uint iPeriod5=10;                                 //5 5@8>4 8=48:0B>@0 4;O @0AG5B0 8=48:0B>@0



//---- =0AB@>9:8 4;O B09<D@59<0 6

input bool ShowTimeframe6=true;                         //6 B>1@065=85 B09<D@59<0

input ENUM_TIMEFRAMES Timeframe6=PERIOD_H2;             //6 "09<D@59< 8=48:0B>@0 4;O @0AG5B0 8=48:0B>@0

input uint iPeriod6=10;                                 //6 5@8>4 8=48:0B>@0 4;O @0AG5B0 8=48:0B>@0



//---- =0AB@>9:8 4;O B09<D@59<0 7

input bool ShowTimeframe7=true;                         //7 B>1@065=85 B09<D@59<0

input ENUM_TIMEFRAMES Timeframe7=PERIOD_H4;             //7 "09<D@59< 8=48:0B>@0 4;O @0AG5B0 8=48:0B>@0

input uint iPeriod7=10;                                 //7 5@8>4 8=48:0B>@0 4;O @0AG5B0 8=48:0B>@0



//---- =0AB@>9:8 4;O B09<D@59<0 8

input bool ShowTimeframe8=true;                         //8 B>1@065=85 B09<D@59<0

input ENUM_TIMEFRAMES Timeframe8=PERIOD_H12;            //8 "09<D@59< 8=48:0B>@0 4;O @0AG5B0 8=48:0B>@0

input uint iPeriod8=10;                                 //8 5@8>4 8=48:0B>@0 4;O @0AG5B0 8=48:0B>@0



//---- =0AB@>9:8 4;O B09<D@59<0 9

input bool ShowTimeframe9=true;                         //9 B>1@065=85 B09<D@59<0

input ENUM_TIMEFRAMES Timeframe9=PERIOD_D1;             //9 "09<D@59< 8=48:0B>@0 4;O @0AG5B0 8=48:0B>@0

input uint iPeriod9=10;                                 //9 5@8>4 8=48:0B>@0 4;O @0AG5B0 8=48:0B>@0



//---- =0AB@>9:8 4;O B09<D@59<0 10

input bool ShowTimeframe10=true;                        //10 B>1@065=85 B09<D@59<0

input ENUM_TIMEFRAMES Timeframe10=PERIOD_W1;            //10 "09<D@59< 8=48:0B>@0 4;O @0AG5B0 8=48:0B>@0

input uint iPeriod10=10;                                //10 5@8>4 8=48:0B>@0 4;O @0AG5B0 8=48:0B>@0

//---- =0AB@>9:8 287C0;L=>3> >B>1@065=8O 8=48:0B>@0

input uint SignalBar=0;                                 // ><5@ 10@0 4;O ?>;CG5=8O A83=0;0 (0 - B5:CI89 10@)

input ENUM_BASE_CORNER  WhatCorner=CORNER_LEFT_UPPER;   // #3>; @0A?>;>65=8O 8=48:0B>@0

input uint X_=10;                                       // !<5I5=85 ?> 3>@87>=B0;8 8=48:0B>@0

input uint Y_=25;                                       // !<5I5=85 ?> 25@B8:0;8 8=48:0B>@0

//---- =0AB@>9:8 H@8DB0

input type_font Font_Type=Font14;                       // (@8DB >B>1@065=8O 8=48:0B>@0

input uint Font_Size=13;                                //  07<5@ H@8DB0

input color Font_Color=clrBlue;                         // &25B H@8DB0

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

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

int Atr_Handle[10];

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

int min_rates_total[10];

//---- >1JO2;5=85 ?5@5<5==KE 4;O 8<5= <5B>:

string Name[10];

//---- >1JO2;5=85 ?5@5<5==KE 4;O B5:AB0

string Text[10];

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

bool ShowTimeframe[10];

ENUM_TIMEFRAMES Timeframe[10];

uint iPeriod[10];

uint iX[10];

uint iY[10];

string sFontType;

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

//|  >;CG5=85 B09<D@59<0 2 2845 AB@>:8                              |

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

string GetStringTimeframe(ENUM_TIMEFRAMES timeframe)

  {return(StringSubstr(EnumToString(timeframe),7,-1));}

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

//|  !>740=85 B5:AB>2>9 <5B:8                                        |

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

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

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

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

                  ENUM_BASE_CORNER corner, // ?>;>65=85 C3;0 ?@82O7:8

                  ENUM_ANCHOR_POINT point, // ?>;>65=85 B>G:8 ?@82O7:8

                  int    X,                // 48AB0=F8O 2 ?8:A5;OE ?> >A8 X >B C3;0 ?@82O7:8

                  int    Y,                // 48AB0=F8O 2 ?8:A5;OE ?> >A8 Y >B C3;0 ?@82O7:8

                  string text,             // B5:AB

                  string textTT,           // B5:AB 2A?;K20NI59 ?>4A:07:8

                  color  Color,            // F25B B5:AB0

                  string Font,             // H@8DB B5:AB0

                  int    Size)             // @07<5@ H@8DB0

  {

//----

   ObjectCreate(chart_id,name,OBJ_LABEL,0,0,0);

   ObjectSetInteger(chart_id,name,OBJPROP_CORNER,corner);

   ObjectSetInteger(chart_id,name,OBJPROP_ANCHOR,point);

   ObjectSetInteger(chart_id,name,OBJPROP_XDISTANCE,X);

   ObjectSetInteger(chart_id,name,OBJPROP_YDISTANCE,Y);

   ObjectSetString(chart_id,name,OBJPROP_TEXT,text);

   ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

   ObjectSetString(chart_id,name,OBJPROP_FONT,Font);

   ObjectSetInteger(chart_id,name,OBJPROP_FONTSIZE,Size);

   ObjectSetString(chart_id,name,OBJPROP_TOOLTIP,textTT);

   ObjectSetInteger(chart_id,name,OBJPROP_BACK,false); //>1J5:B =0 704=5< ?;0=5

//----

  }

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

//|  5@5CAB0=>2:0 B5:AB>2>9 <5B:8                                   |

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

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

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

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

               ENUM_BASE_CORNER corner, // ?>;>65=85 C3;0 ?@82O7:8

               ENUM_ANCHOR_POINT point, // ?>;>65=85 B>G:8 ?@82O7:8

               int    X,                // 48AB0=F8O 2 ?8:A5;OE ?> >A8 X >B C3;0 ?@82O7:8

               int    Y,                // 48AB0=F8O 2 ?8:A5;OE ?> >A8 Y >B C3;0 ?@82O7:8

               string text,             // B5:AB

               string textTT,           // B5:AB 2A?;K20NI59 ?>4A:07:8

               color  Color,            // F25B B5:AB0

               string Font,             // H@8DB B5:AB0

               int    Size)             // @07<5@ H@8DB0

  {

//----

   if(ObjectFind(chart_id,name)==-1)

     {

      CreateTLabel(chart_id,name,nwin,corner,point,X,Y,text,textTT,Color,Font,Size);

     }

   else

     {

      ObjectSetString(chart_id,name,OBJPROP_TEXT,text);

      ObjectSetInteger(chart_id,name,OBJPROP_XDISTANCE,X);

      ObjectSetInteger(chart_id,name,OBJPROP_YDISTANCE,Y);

      ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

      ObjectSetInteger(chart_id,name,OBJPROP_FONTSIZE,Size);

     }

//----

  }

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

//| Custom indicator initialization function                         | 

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

int OnInit()

  {

//---- =8F80;870F8O <0AA82>2 ?5@5<5==KE 4;O 8=48:0B>@>2

   ArrayInitialize(iX,X_);

//----  

   ShowTimeframe[0]=ShowTimeframe1;

   Timeframe[0]=Timeframe1;

   iPeriod[0]=iPeriod1;

   iY[0]=Y_;

//----

   ShowTimeframe[1]=ShowTimeframe2;

   Timeframe[1]=Timeframe2;

   iPeriod[1]=iPeriod2;

   if(ShowTimeframe[1]) iY[1]=iY[0]+20;

   else iY[1]=iY[0];

//----

   ShowTimeframe[2]=ShowTimeframe3;

   Timeframe[2]=Timeframe3;

   iPeriod[2]=iPeriod3;

   if(ShowTimeframe[2]) iY[2]=iY[1]+20;

   else iY[2]=iY[1];

//----

   ShowTimeframe[3]=ShowTimeframe4;

   Timeframe[3]=Timeframe4;

   iPeriod[3]=iPeriod4;

   if(ShowTimeframe[3]) iY[3]=iY[2]+20;

   else iY[3]=iY[2];

//----

   ShowTimeframe[4]=ShowTimeframe5;

   Timeframe[4]=Timeframe5;

   iPeriod[4]=iPeriod5;

   if(ShowTimeframe[4]) iY[4]=iY[3]+20;

   else iY[4]=iY[3];

//----

   ShowTimeframe[5]=ShowTimeframe6;

   Timeframe[5]=Timeframe6;

   iPeriod[5]=iPeriod6;

   if(ShowTimeframe[5]) iY[5]=iY[4]+20;

   else iY[5]=iY[4];

//----

   ShowTimeframe[6]=ShowTimeframe7;

   Timeframe[6]=Timeframe7;

   iPeriod[6]=iPeriod7;

   if(ShowTimeframe[6]) iY[6]=iY[5]+20;

   else iY[6]=iY[5];

//----

   ShowTimeframe[7]=ShowTimeframe8;

   Timeframe[7]=Timeframe8;

   iPeriod[7]=iPeriod8;

   if(ShowTimeframe[7]) iY[7]=iY[6]+20;

   else iY[7]=iY[6];

//----

   ShowTimeframe[8]=ShowTimeframe9;

   Timeframe[8]=Timeframe9;

   iPeriod[8]=iPeriod9;

   if(ShowTimeframe[8]) iY[8]=iY[7]+20;

   else iY[8]=iY[7];

//----

   ShowTimeframe[9]=ShowTimeframe10;

   Timeframe[9]=Timeframe10;

   iPeriod[9]=iPeriod10;

   if(ShowTimeframe[9]) iY[9]=iY[8]+20;

   else iY[9]=iY[8];

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

   for(int count=0; count<10; count++)

     {

      if(!ShowTimeframe[count]) continue;

      Atr_Handle[count]=iATR(Symbol(),Timeframe[count],iPeriod[count]);

      if(Atr_Handle[count]==INVALID_HANDLE)

        {

         Print(" 5 C40;>AL ?>;CG8BL E5=4; 8=48:0B>@0 ATR "+string(count+1));

         return(INIT_FAILED);

        }

     }



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

   for(int count=0; count<10; count++) if(ShowTimeframe[count]) min_rates_total[count]=int(iPeriod[count])+int(SignalBar);

   for(int count=0; count<10; count++) if(ShowTimeframe[count]) Name[count]=Symbols_Sirname+" "+string(count+1);

   for(int count=0; count<10; count++) if(ShowTimeframe[count]) Text[count]="ATR("+GetStringTimeframe(Timeframe[count])+","+string(iPeriod[count])+")"+"=";

   sFontType=FONT.GetFontName(Font_Type);

//--- >?@545;5=85 B>G=>AB8 >B>1@065=8O 7=0G5=89 8=48:0B>@0

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);

//--- 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 @0AG5B0

   for(int count=0; count<10; count++) if(ShowTimeframe[count])

     {

      if(BarsCalculated(Atr_Handle[count])<min_rates_total[count]) return(prev_calculated);

      if(BarsCalculated(Atr_Handle[count])<Bars(Symbol(),Timeframe[count])) return(prev_calculated);

     }

     

//---- 

   for(int count=0; count<10; count++) if(ShowTimeframe[count])

     {

      double ATR[1];

      if(CopyBuffer(Atr_Handle[count],0,SignalBar,1,ATR)<=0) return(prev_calculated);

      string info=Text[count]+DoubleToString(ATR[0],3);

      SetTLabel(0,Name[count],0,WhatCorner,ENUM_ANCHOR_POINT(2*WhatCorner),iX[count],iY[count],info,info,Font_Color,sFontType,Font_Size);

     }

//----

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