//+------------------------------------------------------------------+ //| smHiLoOpen Lines_v1.2.mq4 //+------------------------------------------------------------------+ #property copyright "Copyright SwingMan, 02.06.2016" #property strict #property indicator_chart_window // /*------------------------------------------------------------------- 01.06.2016 v1.1 - Draw options 02.06.2016 v1.2 - Bug, H1 Higher/Lower Open values -------------------------------------------------------------------*/ //-- inputs //==================================================================== input bool Draw_Daily_Lines=true; input bool Draw_Hourly_Lines=true; input bool Show_Time_Infos=true; input string ____Shift_Factors____=""; input int Shift_H1_Labels=3; input int Shift_D1_Labels=14; input string s0=""; //______Previous Day_____ input bool Draw_OpenLine_Previous_Day=true; input bool Draw_HiLoLines_Previous_Day=true; input bool Draw_PriceBoxes_Previous_Day=true; input bool Draw_Texts_Previous_Day=true; input string s1=" "; //______Current Day_____ input bool Draw_OpenLine_Current_Day=true; input bool Draw_HiLoLines_Current_Day=true; input bool Draw_PriceBoxes_Current_Day=true; input bool Draw_Texts_Current_Day=true; input string s2=" "; //______Current H1_____ input bool Draw_OpenLine_Current_H1=true; input bool Draw_PriceBox_Current_H1=true; input bool Draw_Text_Current_H1=true; input string s3=" "; //____Extreme H1-Open of the Day___ input bool Draw_ExtremeOpenLines_Current_Day=true; input bool Draw_ExtremeOpen_PriceBoxes=true; input bool Draw_ExtremeOpen_Texts=true; input string ____Line_Colors____=""; input color clrOpen=clrSeaGreen; //Open Lines input color clrHigh=clrRed; //High Lines input color clrLow=clrDodgerBlue; //Low Lines //================================ // //---- constants string CR="\n"; string sObj="Hilo_"; //---- variables //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { IndicatorDigits(Digits); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { Comment(""); //-- delete objects long chartID=ChartID(); ObjectsDeleteAll(chartID,sObj); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, 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[]) { //--- //int i,limit; //--- if(Show_Time_Infos) Show_TimeInfos(); //--- if(Draw_Daily_Lines) Draw_D1_Lines(); if(Draw_Hourly_Lines) Draw_H1_Lines(); //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void Draw_D1_Lines() { string objectName; double open0,high0,low0; double open1,high1,low1; datetime time0pen0,timeOpen1,timeCurr; open0=iOpen(Symbol(),PERIOD_D1,0); high0=iHigh(Symbol(),PERIOD_D1,0); low0 =iLow(Symbol(),PERIOD_D1,0); open1=iOpen(Symbol(),PERIOD_D1,1); high1=iHigh(Symbol(),PERIOD_D1,1); low1 =iLow(Symbol(),PERIOD_D1,1); time0pen0=iTime(Symbol(),PERIOD_D1,0); timeOpen1=iTime(Symbol(),PERIOD_D1,1); timeCurr =iTime(Symbol(),Period(),0)+Period()*Shift_D1_Labels*60; //-- draw lines objectName=sObj+"D1_0open"; Draw_HorizontalLine(objectName,open0,time0pen0,timeCurr,"D1[0] Open",clrOpen); objectName=sObj+"D1_0high"; Draw_HorizontalLine(objectName,high0,time0pen0,timeCurr,"D1[0] High",clrHigh); objectName=sObj+"D1_0low"; Draw_HorizontalLine(objectName,low0,time0pen0,timeCurr, "D1[0] Low",clrLow); objectName=sObj+"D1_1open"; Draw_HorizontalLine(objectName,open1,timeOpen1,timeCurr,"D1[1] Open",clrOpen); objectName=sObj+"D1_1high"; Draw_HorizontalLine(objectName,high1,timeOpen1,timeCurr,"D1[1] High",clrHigh); objectName=sObj+"D1_1low"; Draw_HorizontalLine(objectName,low1,timeOpen1,timeCurr, "D1[1] Low",clrLow); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void Draw_H1_Lines() { string objectName; double open0,dHigherOpen,dLowerOpen; datetime time0pen0,timeHigherOpen,timeLower0pen,timeCurr; string sHigherOpen,sLowerOpen; //-- 1. current open --------------------------------------------------- open0=iOpen(Symbol(),PERIOD_H1,0); time0pen0=iTime(Symbol(),PERIOD_H1,0); timeCurr =iTime(Symbol(),Period(),0)+Period()*Shift_H1_Labels*60; //-- draw line objectName=sObj+"H1_0open"; Draw_HorizontalLine(objectName,open0,time0pen0,timeCurr,"H1[0] Open",clrOpen); //-- 2. highest daily H1 open ------------------------------------------ datetime timeDailyOpen=iTime(Symbol(),PERIOD_D1,0); int currentDailyBars=iBarShift(Symbol(),PERIOD_H1,timeDailyOpen,true); int iBarHigherOpen=iHighest(Symbol(),PERIOD_H1,MODE_OPEN,currentDailyBars+1,0); //-- on H1 dHigherOpen =iOpen(Symbol(),PERIOD_H1,iBarHigherOpen); timeHigherOpen =iTime(Symbol(),PERIOD_H1,iBarHigherOpen); iBarHigherOpen =iBarShift(Symbol(),Period(),timeHigherOpen,true); //-- on M15 //-- draw line sHigherOpen="H1["+(string)iBarHigherOpen+"] Higher Open"; objectName=sObj+"H1_HigherOpen"; Draw_HorizontalLine(objectName,dHigherOpen,timeHigherOpen,timeCurr,sHigherOpen,clrOpen); //-- 3. lovest daily H1 open ------------------------------------------- int iBarLowerOpen=iLowest(Symbol(),PERIOD_H1,MODE_OPEN,currentDailyBars+1,0); //-- on H1 dLowerOpen =iOpen(Symbol(),PERIOD_H1,iBarLowerOpen); timeLower0pen =iTime(Symbol(),PERIOD_H1,iBarLowerOpen); iBarLowerOpen =iBarShift(Symbol(),Period(),timeLower0pen,true); //-- on M15 sLowerOpen="H1["+(string)iBarLowerOpen+"] Lower Open"; objectName=sObj+"H1_LowerOpen"; Draw_HorizontalLine(objectName,dLowerOpen,timeLower0pen,timeCurr,sLowerOpen,clrOpen); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void Draw_HorizontalLine(string objNameX,double price1,datetime time1,datetime time2,string sText,color dColor) { string objName; int anchor=ANCHOR_LEFT; bool draw_DCurr_Open,draw_DCurr_Hilo,draw_DCurr_PBox,draw_DCurr_Text; bool draw_DPrev_Open,draw_DPrev_Hilo,draw_DPrev_PBox,draw_DPrev_Text; bool draw_HCurr_Open,draw_HCurr_PBox,draw_HCurr_Text; bool draw_Extr_Open,draw_Extr_PBox,draw_Extr_Text; //-- current daily draw_DCurr_Open=(sText =="D1[0] Open" && Draw_OpenLine_Current_Day); draw_DCurr_Hilo=((sText=="D1[0] High" || sText=="D1[0] Low") && Draw_HiLoLines_Current_Day); draw_DCurr_PBox=((sText=="D1[0] Open" || sText=="D1[0] High" || sText=="D1[0] Low") && Draw_PriceBoxes_Current_Day); draw_DCurr_Text=((sText=="D1[0] Open" || sText=="D1[0] High" || sText=="D1[0] Low") && Draw_Texts_Current_Day); //-- previous daily draw_DPrev_Open=(sText =="D1[1] Open" && Draw_OpenLine_Previous_Day); draw_DPrev_Hilo=((sText=="D1[1] High" || sText=="D1[1] Low") && Draw_HiLoLines_Previous_Day); draw_DPrev_PBox=((sText=="D1[1] Open" || sText=="D1[1] High" || sText=="D1[1] Low") && Draw_PriceBoxes_Previous_Day); draw_DPrev_Text=((sText=="D1[1] Open" || sText=="D1[1] High" || sText=="D1[1] Low") && Draw_Texts_Previous_Day); //-- H1 current Open draw_HCurr_Open=(sText=="H1[0] Open" && Draw_OpenLine_Current_H1); draw_HCurr_PBox=(sText=="H1[0] Open" && Draw_PriceBox_Current_H1); draw_HCurr_Text=(sText=="H1[0] Open" && Draw_Text_Current_H1); //-- H1 Extreme Open values draw_Extr_Open=((StringFind(sText,"Higher Open")>=0 || StringFind(sText,"Lower Open")>=0) && Draw_ExtremeOpenLines_Current_Day); draw_Extr_PBox=((StringFind(sText,"Higher Open")>=0 || StringFind(sText,"Lower Open")>=0) && Draw_ExtremeOpen_PriceBoxes); draw_Extr_Text=((StringFind(sText,"Higher Open")>=0 || StringFind(sText,"Lower Open")>=0) && Draw_ExtremeOpen_Texts); //-- draw lines if(draw_DCurr_Open || draw_DCurr_Hilo || draw_DPrev_Open || draw_DPrev_Hilo || draw_HCurr_Open || draw_Extr_Open) { objName=objNameX; ObjectDelete(objName); ObjectCreate(objName,OBJ_TREND,0,time1,price1,time2,price1); ObjectSet(objName,OBJPROP_COLOR,dColor); ObjectSet(objName,OBJPROP_STYLE,STYLE_SOLID); ObjectSet(objName,OBJPROP_RAY_RIGHT,false); } //-- draw values if(draw_DCurr_PBox || draw_DPrev_PBox || draw_HCurr_PBox || draw_Extr_PBox) { objName=objNameX+"Val"; ObjectDelete(objName); ObjectCreate(objName,OBJ_ARROW_RIGHT_PRICE,0,time2,price1); ObjectSet(objName,OBJPROP_COLOR,dColor); } //-- draw text datetime time3; if(draw_DCurr_Text || draw_DPrev_Text || draw_HCurr_Text || draw_Extr_Text) { if(draw_DCurr_PBox || draw_DPrev_PBox || draw_HCurr_PBox || draw_Extr_PBox) time3=time2+Period()*8*60; else time3=time2+Period()*1*60; objName=objNameX+"Txt"; ObjectDelete(objName); ObjectCreate(objName,OBJ_TEXT,0,time3,price1); ObjectSet(objName,OBJPROP_ANCHOR,anchor); ObjectSetText(objName,sText,8,"Arial",dColor); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void Show_TimeInfos() { datetime timeServer,timeLocal,timeGMT,timeBarHour; //datetime timeOpen; string sIndiName="=== "+WindowExpertName()+" ==="; timeServer=TimeCurrent(); timeLocal =TimeLocal(); timeGMT =TimeGMT(); //timeOpen =iTime(Symbol(),Period(),0); timeBarHour=iTime(Symbol(),PERIOD_H1,0); Comment("",CR,"",CR, sIndiName,CR, "Time Local......... ",TimeToString(timeLocal,TIME_DATE|TIME_MINUTES),CR, "Time Server...... ",TimeToString(timeServer,TIME_DATE|TIME_MINUTES),CR, "Time GMT........ ",TimeToString(timeGMT,TIME_DATE|TIME_MINUTES),CR, "Time BarHour.... ",TimeToString(timeBarHour,TIME_DATE|TIME_MINUTES) //"Time BarOpen... ",TimeToString(timeOpen,TIME_DATE|TIME_MINUTES) ); } //+------------------------------------------------------------------+