//+------------------------------------------------------------------+ //| KLines.mq5 | //| Copyright © 2005, Kalenzo | //| bartlomiej.gorski@gmail.com | //+------------------------------------------------------------------+ //--- Copyright #property copyright "Copyright © 2005, Kalenzo" //--- link to the website of the author #property link "bartlomiej.gorski@gmail.com" //--- Indicator version #property version "1.00" //--- drawing the indicator in the main window #property indicator_chart_window //--- buffers are not used for indicator calculation and drawing #property indicator_buffers 0 //--- graphical representations are not used #property indicator_plots 0 //+-----------------------------------+ //| Declaration of constants | //+-----------------------------------+ #define RESET 0 // The constant for getting the command for the indicator recalculation back to the terminal //+----------------------------------------------+ //| Indicator input parameters | //+----------------------------------------------+ input uint KLPeriod=14; // Period for extremums input uint TextSize=7; // Text size input color UpColor=clrGreen; // Color of resistance input color DnColor=clrRed; // Color of support input ENUM_TIMEFRAMES Timeframe1=PERIOD_D1; // Timeframe for calculation of 1 input ENUM_TIMEFRAMES Timeframe2=PERIOD_H4; // Timeframe for calculation of 2 input ENUM_TIMEFRAMES Timeframe3=PERIOD_H1; // Timeframe for calculation of 3 input ENUM_TIMEFRAMES Timeframe4=PERIOD_M30; // Timeframe for calculation of 4 input ENUM_TIMEFRAMES Timeframe5=PERIOD_M15; // Timeframe for calculation of 5 //+----------------------------------------------+ double iClose[]; string Lbh1,Lbh2,Lbh3,Lbh4,Lbh5,Lbl1,Lbl2,Lbl3,Lbl4,Lbl5; //+------------------------------------------------------------------+ //| Getting a timeframe as a line | //+------------------------------------------------------------------+ string GetStringTimeframe(ENUM_TIMEFRAMES timeframe) { return(StringSubstr(EnumToString(timeframe),7,-1)); } //+------------------------------------------------------------------+ //| Trend line creation | //+------------------------------------------------------------------+ void CreateTline(long chart_id, // Chart ID string name, // object name int nwin, // window index datetime time1, // price level time 1 double price1, // price level 1 datetime time2, // price level time 2 double price2, // price level 2 color Color, // line color int style, // line style int width, // line width string text) // text { //--- 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); //--- } //+------------------------------------------------------------------+ //| Resetting a trend line | //+------------------------------------------------------------------+ void SetTline(long chart_id, // Chart ID string name, // object name int nwin, // window index datetime time1, // price level time 1 double price1, // price level 1 datetime time2, // price level time 2 double price2, // price level 2 color Color, // line color int style, // line style int width, // line width string text) // text { //--- 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); } //--- } //+------------------------------------------------------------------+ //| Text Label creation | //+------------------------------------------------------------------+ void CreateText(long chart_id, // chart ID string name, // Object name int nwin, // Window index datetime time, // Time of the price level double price, // Price level string text, // Label text color Color, // Label color string Font, // Label font int Size, // Size ENUM_ANCHOR_POINT point) // Chart corner to position the label { //--- 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); //--- } //+------------------------------------------------------------------+ //| Text Label reinstallation | //+------------------------------------------------------------------+ void SetText(long chart_id, // Chart ID string name, // Object name int nwin, // Window index datetime time, // Time of the price level double price, // Price level string text, // Label text color Color, // Label color string Font, // Label font int Size, // Size ENUM_ANCHOR_POINT point) // Chart corner to position the label { //--- 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); } //--- } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- Determining the accuracy of displaying the indicator values IndicatorSetInteger(INDICATOR_DIGITS,_Digits); //--- Lbh1=GetStringTimeframe(Timeframe1)+" Bar Highest Close"; Lbh2=GetStringTimeframe(Timeframe2)+" Bar Highest Close"; Lbh3=GetStringTimeframe(Timeframe3)+" Bar Highest Close"; Lbh4=GetStringTimeframe(Timeframe4)+" Bar Highest Close"; Lbh5=GetStringTimeframe(Timeframe5)+" Bar Highest Close"; Lbl1=GetStringTimeframe(Timeframe1)+" Bar Lowest Close"; Lbl2=GetStringTimeframe(Timeframe2)+" Bar Lowest Close"; Lbl3=GetStringTimeframe(Timeframe3)+" Bar Lowest Close"; Lbl4=GetStringTimeframe(Timeframe4)+" Bar Lowest Close"; Lbl5=GetStringTimeframe(Timeframe5)+" Bar Lowest Close"; //--- memory allocation for the variable array if(ArrayResize(iClose,KLPeriod)!=KLPeriod) return(INIT_FAILED); //--- indexing elements in arrays as in timeseries ArraySetAsSeries(iClose,true); //--- initialization end ChartRedraw(0); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { ObjectDelete(0,"HH_1"); ObjectDelete(0,"HH_2"); ObjectDelete(0,"HH_3"); ObjectDelete(0,"HH_4"); ObjectDelete(0,"HH_5"); ObjectDelete(0,"HH_1r"); ObjectDelete(0,"HH_2r"); ObjectDelete(0,"HH_3r"); ObjectDelete(0,"HH_4r"); //--- ObjectDelete(0,"1 Bar Highest Close"); ObjectDelete(0,"2 Bar Highest Close"); ObjectDelete(0,"3 Bar Highest Close"); ObjectDelete(0,"4 Bar Highest Close"); ObjectDelete(0,"5 Bar Highest Close"); //--- ObjectDelete(0,"LL_1"); ObjectDelete(0,"LL_2"); ObjectDelete(0,"LL_3"); ObjectDelete(0,"LL_4"); ObjectDelete(0,"LL_5"); ObjectDelete(0,"LL_1r"); ObjectDelete(0,"LL_2r"); ObjectDelete(0,"LL_3r"); ObjectDelete(0,"LL_4r"); //--- ObjectDelete(0,"1 Bar Lowest Close"); ObjectDelete(0,"2 Bar Lowest Close"); ObjectDelete(0,"3 Bar Lowest Close"); ObjectDelete(0,"4 Bar Lwest Close"); ObjectDelete(0,"5 Bar Lowest Close"); //--- ChartRedraw(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, // number of bars in history at the current tick const int prev_calculated,// amount of history in bars at the previous tick const datetime &time[], const double &open[], const double& high[], // price array of price maximums for the indicator calculation const double& low[], // price array of minimums of price for the indicator calculation const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- if(rates_total