//+------------------------------------------------------------------+ //| Fine_Fractals_MTF.mq5 | //| Copyright © 2011, Nikolay Kositsin | //| Khabarovsk, farria@mail.redcom.ru | //+------------------------------------------------------------------+ #property copyright "Copyright © 2011, Nikolay Kositsin" #property link "farria@mail.redcom.ru" //--- indicator version #property version "1.00" //--- drawing the indicator in the main window #property indicator_chart_window //--- two buffers are used for calculation and drawing the indicator #property indicator_buffers 2 //--- only two plots are used #property indicator_plots 2 //+----------------------------------------------+ //| Declaration of constants | //+----------------------------------------------+ #define RESET 0 // the constant for getting the command for the indicator recalculation back to the terminal #define INDICATOR_NAME "Fine_Fractals MTF" // the constant for the indicator name //+----------------------------------------------+ //| Upper indicator drawing parameters | //+----------------------------------------------+ //--- drawing the indicator 1 as a symbol #property indicator_type1 DRAW_ARROW //--- magenta color is used for the indicator #property indicator_color1 Magenta //--- indicator 1 line width is equal to 1 #property indicator_width1 1 //--- displaying the indicator label #property indicator_label1 "Up "+INDICATOR_NAME //+----------------------------------------------+ //| Lower indicator drawing parameters | //+----------------------------------------------+ //--- drawing the indicator 2 as a line #property indicator_type2 DRAW_ARROW //--- blue color is used for the indicator #property indicator_color2 Blue //--- indicator 2 line width is equal to 1 #property indicator_width2 1 //--- displaying the indicator label #property indicator_label2 "Down "+INDICATOR_NAME //+----------------------------------------------+ //| Indicator input parameters | //+----------------------------------------------+ input ENUM_TIMEFRAMES TimeFrame=PERIOD_H4;// Chart period input bool Fine=true; // Sensibility input bool FlatShift=true; // Shift input int UpLable=164; // Upper fractal symbol code input int DnLable=164; // Lower fractal symbol code //+----------------------------------------------+ //--- declaration of dynamic arrays that //--- will be used as indicator buffers double HighBuffer[]; double LowBuffer[]; //--- declaration of global variables bool Init; //--- declaration of the integer variables for the start of data calculation int min_rates_total,LimitShift; //--- declaration of integer variables for the indicators handles int FRA_Handle; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { Init=true; //--- checking correctness of the chart periods if(TimeFrame=end; bar--) if(Array[bar]>=Velue)return(bar); //--- return(ArrayMaximum(Array,end,start-end)); } //+--------------------------------------------------------------------+ //| Searching for the first extremum according to its time series value| //+--------------------------------------------------------------------+ int FindMin(double Velue,int start,int end,const double &Array[]) { //--- for(int bar=start; bar>=end; bar--) if(Array[bar]<=Velue)return(bar); //--- return(ArrayMinimum(Array,end,start-end)); } //+------------------------------------------------------------------+ //| Custom iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, // number of bars in history at the current tick const int prev_calculated,// number of bars calculated at previous call 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[]) { //--- checking the number of bars to be enough for the calculation if(rates_totalrates_total || prev_calculated<=0)// checking for the first start of the indicator calculation { limit=rates_total-min_rates_total-1; // starting index for calculation of all bars } else limit=LimitShift+rates_total-prev_calculated; // starting index for calculation of new bars //--- indexing elements in arrays as time series ArraySetAsSeries(time,true); ArraySetAsSeries(high,true); ArraySetAsSeries(low,true); //--- zero out the contents of the indicator buffers for calculation for(bar=limit; bar>=0 && !IsStopped(); bar--) { LowBuffer[bar]=0.0; HighBuffer[bar]=0.0; } //--- main indicator calculation loop for(bar=limit; bar>=0 && !IsStopped(); bar--) { //--- copy newly appeared data in the arrays if(CopyTime(NULL,TimeFrame,time[bar],1,FracTime)<=0) return(RESET); if(time[bar]>=FracTime[0] && time[bar+1]