//+------------------------------------------------------------------+ //| Levels.mq5 | //| Copyright © 2007, Maks aka ug | //| | //+------------------------------------------------------------------+ //---- Copyright #property copyright "Copyright © 2007, Maks aka ug" //---- link to the website of the author #property link "" //---- Indicator version number #property version "1.00" //---- drawing the indicator in the main window #property indicator_chart_window //---- no buffers used for the calculation and drawing of the indicator #property indicator_buffers 0 //---- 0 graphical plots are used #property indicator_plots 0 //+-----------------------------------+ //| Declaration of enumeration | //+-----------------------------------+ enum Number { Number_0, Number_1, Number_2, Number_3 }; //+-----------------------------------+ //| Declaration of enumeration | //+-----------------------------------+ enum Width { Width_1=1, //1 Width_2, //2 Width_3, //3 Width_4, //4 Width_5 //5 }; //+-----------------------------------+ //| Declaration of enumeration | //+-----------------------------------+ enum STYLE { SOLID_,//Solid line DASH_,//Dashed line DOT_,//Dotted line DASHDOT_,//Dot-dash line DASHDOTDOT_ // Dot-dash line with double dots }; //+----------------------------------------------+ //| Indicator input parameters | //+----------------------------------------------+ input ENUM_TIMEFRAMES TimeFrame=PERIOD_D1; //Chart period input int high_diap = 2000; //Maximum range input int low_diap = 500; //Minimum range //---- input color Color_R5 = clrDodgerBlue; //Color of the R5 level input color Color_R4 = clrDodgerBlue; //Color of the R4 level input color Color_R3 = clrDodgerBlue; //Color of the R3 level input color Color_R2 = clrDodgerBlue; //Color of the R2 level input color Color_R1 = clrDodgerBlue; //Color of the R1 level input color Color_S1 = clrMagenta; //Color of the S1 level input color Color_S2 = clrMagenta; //Color of the S2 level input color Color_S3 = clrMagenta; //Color of the S3 level input color Color_S4 = clrMagenta; //Color of the S4 level input color Color_S5 = clrMagenta; //Color of the S5 level //---- input STYLE Style_R5 = SOLID_; //Line style of the R5 level input STYLE Style_R4 = SOLID_; //Line style of the R4 level input STYLE Style_R3 = SOLID_; //Line style of the R3 level input STYLE Style_R2 = SOLID_; //Line style of the R2 level input STYLE Style_R1 = SOLID_; //Line style of the R1 level input STYLE Style_S1 = SOLID_; //Line style of the S1 level input STYLE Style_S2 = SOLID_; //Line style of the S2 level input STYLE Style_S3 = SOLID_; //Line style of the S3 level input STYLE Style_S4 = SOLID_; //Line style of the S4 level input STYLE Style_S5 = SOLID_; //Line style of the S5 level //---- input Width Width_R5 = Width_2; //The width of the R5 level input Width Width_R4 = Width_2; //The width of the R4 level input Width Width_R3 = Width_2; //The width of the R3 level input Width Width_R2 = Width_2; //The width of the R2 level input Width Width_R1 = Width_2; //The width of the R1 level input Width Width_S1 = Width_2; //The width of the S1 level input Width Width_S2 = Width_2; //The width of the S2 level input Width Width_S3 = Width_2; //The width of the S3 level input Width Width_S4 = Width_2; //The width of the S4 level input Width Width_S5 = Width_2; //The width of the S5 level //---- input uint TextSize=8; //+----------------------------------------------+ //---- Declaration of integer variables of data starting point int min_rates_total; //+------------------------------------------------------------------+ //| creating a text label | //+------------------------------------------------------------------+ void CreateText(long chart_id,// chart ID string name, // object name int nwin, // window index datetime time, // price level time double price, // price level string text, // Labels text color Color, // Text color string Font, // Text font int Size, // Text size ENUM_ANCHOR_POINT point // The chart corner to Which the text is attached ) //---- { //---- ObjectCreate(chart_id,name,OBJ_TEXT,nwin,time,price); 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); ObjectSetInteger(chart_id,name,OBJPROP_BACK,false); ObjectSetInteger(chart_id,name,OBJPROP_ANCHOR,point); //---- } //+------------------------------------------------------------------+ //| changing a text label | //+------------------------------------------------------------------+ void SetText(long chart_id,// chart ID string name, // object name int nwin, // window index datetime time, // price level time double price, // price level string text, // Labels text color Color, // Text color string Font, // Text font int Size, // Text size ENUM_ANCHOR_POINT point // The chart corner to Which the text is attached ) //---- { //---- if(ObjectFind(chart_id,name)==-1) CreateText(chart_id,name,nwin,time,price,text,Color,Font,Size,point); else { ObjectSetString(chart_id,name,OBJPROP_TEXT,text); ObjectMove(chart_id,name,0,time,price); } //---- } //+------------------------------------------------------------------+ //| Creating horizontal price level | //+------------------------------------------------------------------+ void CreateHline ( long chart_id, // chart ID string name, // object name int nwin, // window index double price, // price level color Color, // line color int style, // line style int width, // line width string text // text ) //---- { //---- ObjectCreate(chart_id,name,OBJ_HLINE,0,0,price); 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); ObjectSetString(chart_id,name,OBJPROP_TOOLTIP,name); ObjectSetInteger(chart_id,name,OBJPROP_BACK,true); //---- } //+------------------------------------------------------------------+ //| Resetting the horizontal price level | //+------------------------------------------------------------------+ void SetHline ( long chart_id, // chart ID string name, // object name int nwin, // window index double price, // price level color Color, // line color int style, // line style int width, // line width string text // text ) //---- { //---- if(ObjectFind(chart_id,name)==-1) CreateHline(chart_id,name,nwin,price,Color,style,width,text); else { //ObjectSetDouble(chart_id,name,OBJPROP_PRICE,price); ObjectSetString(chart_id,name,OBJPROP_TEXT,text); ObjectMove(chart_id,name,0,0,price); } //---- } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //---- Initialization of variables of the start of data calculation min_rates_total=int(5*PeriodSeconds(TimeFrame)/PeriodSeconds(PERIOD_CURRENT))+1; //---- Checking correctness of the chart periods if(TimeFrame=TimeFrame) return(0); //---- declarations of static variables static double S1,R1,S2,R2,S3,R3,S4,R4,S5,R5; if(prev_calculated!=rates_total) { int copy=1; double iHigh[1],iLow[1],iClose[1]; if(CopyClose(NULL,TimeFrame,1,copy,iClose)high_diap) diap=1; if(Range