//+------------------------------------------------------------------+ //| AutoDayFibs.mq5 | //| Copyright © 2005-2008, Jason Robinson (jnrtrading) | //| http://www.spreadtrade2win.com | //+------------------------------------------------------------------+ //---- author of the indicator #property copyright "Copyright © 2005-2008, Jason Robinson (jnrtrading)" //---- link to the website of the author #property link "http://www.spreadtrade2win.com" //---- indicator version number #property version "1.00" //---- drawing the indicator in the main window #property indicator_chart_window //---- no buffers are used for the calculation and drawing of the indicator #property indicator_buffers 0 //---- 0 graphical plots are used #property indicator_plots 0 //+----------------------------------------------+ //| declaration of enumerations | //+----------------------------------------------+ enum Hour //Type of constant { H00=0, //00 H01, //01 H02, //02 H03, //03 H04, //04 H05, //05 H06, //06 H07, //07 H08, //08 H09, //09 H10, //10 H11, //11 H12, //12 H13, //13 H14, //14 H15, //15 H16, //16 H17, //17 H18, //18 H19, //19 H20, //20 H21, //21 H22, //22 H23, //23 }; //+-----------------------------------+ //| enumeration declaration | //+-----------------------------------+ enum Number { Number_0, Number_1, Number_2, Number_3 }; //+-----------------------------------+ //| enumeration declaration | //+-----------------------------------+ enum Width { Width_1=1, //1 Width_2, //2 Width_3, //3 Width_4, //4 Width_5 //5 }; //+-----------------------------------+ //| enumeration declaration | //+-----------------------------------+ 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 bool AutomaticallyAdjustToToday = true; //adjustment under the current prices input Hour TimeToAdjust=H00; //the hour of shifting Fibo input uint iDaysBackForHigh=0; //number of days back to obtain low input uint iDaysBackForLow=0; //number of days back to obtain low input uint TextSize=10; //text font size //---- input color Color_fib000 = clrBlueViolet; //color for the fib000 level input STYLE Style_fib000 = SOLID_; //fib000 level style input Width Width_fib000 = Width_2; //fib000 level line width //---- input color Color_fib236 = clrBlueViolet; //color for the fib236 level input STYLE Style_fib236 = SOLID_; //fib236 level line style input Width Width_fib236 = Width_2; //fib236 level line width //---- input color Color_fib382 = clrBlueViolet; //color for the fib382 level input STYLE Style_fib382 = SOLID_; //fib382 level line style input Width Width_fib382 = Width_2; //fib382 level line width //---- input color Color_fib500 = clrBlueViolet; //color for the fib500 level input STYLE Style_fib500 = SOLID_; //fib500 level line style input Width Width_fib500 = Width_2; //fib500 level line width //---- input color Color_fib618 = clrBlueViolet; //color for the fib618 level input STYLE Style_fib618 = SOLID_; //fib618 level line style input Width Width_fib618 = Width_2; //fib618 level line width //---- input color Color_fib764 = clrBlueViolet; //color for the fib764 level input STYLE Style_fib764 = SOLID_; //fib764 level line style input Width Width_fib764 = Width_2; //fib764 level line width //---- input color Color_fib1000 = clrBlueViolet; //color for the fib1000 level input STYLE Style_fib1000 = SOLID_; //fib1000 level line style input Width Width_fib1000 = Width_2; //fib1000 level line width //---- input color Color_fib1618 = clrBlueViolet; //color for the fib1618 level input STYLE Style_fib1618 = SOLID_; //fib1618 level line style input Width Width_fib1618 = Width_2; //fib1618 level line width //---- input color Color_fib2618 = clrBlueViolet; //color for the fib2618 level input STYLE Style_fib2618 = SOLID_; //fib2618 level line style input Width Width_fib2618 = Width_1; //fib2618 level line width //---- input color Color_fib4236 = clrBlueViolet; //color for the fib4236 level input STYLE Style_fib4236 = SOLID_; //fib4236 level line style input Width Width_fib4236 = Width_2; //fib4236 level line width //+----------------------------------------------+ double fib000, fib236, fib382, fib500, fib618, fib764, fib1000, fib1618, fib2618, fib4236, range, prevRange; bool objectsExist,highFirst; //---- Declaration of integer variables of data starting point int min_rates_total,DaysBackForHigh,DaysBackForLow; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //---- Initialization of variables of data calculation starting point DaysBackForHigh=int(iDaysBackForHigh); DaysBackForLow=int(iDaysBackForLow); min_rates_total=int((1+MathMax(DaysBackForHigh,DaysBackForLow))*PeriodSeconds(PERIOD_D1)/PeriodSeconds(PERIOD_CURRENT)); prevRange=0; objectsExist=true; //---- determine the accuracy of displaying indicator values IndicatorSetInteger(INDICATOR_DIGITS,_Digits); //---- creating labels for displaying in DataWindow and the name for displaying in a separate sub-window and in a tooltip IndicatorSetString(INDICATOR_SHORTNAME,"AutoDayFibs"); //---- } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //---- ObjectDelete(0,"fib000"); ObjectDelete(0,"fib000_label"); ObjectDelete(0,"fib236"); ObjectDelete(0,"fib236_label"); ObjectDelete(0,"fib382"); ObjectDelete(0,"fib382_label"); ObjectDelete(0,"fib500"); ObjectDelete(0,"fib500_label"); ObjectDelete(0,"fib618"); ObjectDelete(0,"fib618_label"); ObjectDelete(0,"fib764"); ObjectDelete(0,"fib764_label"); ObjectDelete(0,"fib1000"); ObjectDelete(0,"fib1000_label"); ObjectDelete(0,"fib1618"); ObjectDelete(0,"fib1618_label"); ObjectDelete(0,"fib2618"); ObjectDelete(0,"fib2618_label"); ObjectDelete(0,"fib4236"); ObjectDelete(0,"fib4236_label"); //---- } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate( const int rates_total, // amount of history in bars 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 maximums of price for the calculation of indicator const double& low[], // price array of minimums of price for the calculation of indicator const double &close[], const long &tick_volume[], const long &volume[], const int &spread[] ) { //---- if(_Period>=PERIOD_D1 || rates_total=0 && tm.hour=DaysBackForLow && tm.hour<=H23) { DaysBackForHigh=H00; DaysBackForLow =H00; } } double iLow[1],iHigh[1]; if(CopyLow(NULL,PERIOD_D1,DaysBackForLow,1,iLow)<1)return(0); if(CopyHigh(NULL,PERIOD_D1,DaysBackForHigh,1,iHigh)<1)return(0); range=iHigh[0]-iLow[0]; for(int iii=0; iii