//+---------------------------------------------------------------------+ //| UltraFatl_Candles.mq5 | //| Copyright © 2012, Nikolay Kositsin | //| Khabarovsk, farria@mail.redcom.ru | //+---------------------------------------------------------------------+ //| For the indicator to work, place the file SmoothAlgorithms.mqh | //| in the directory: terminal_data_folder\MQL5\Include | //+---------------------------------------------------------------------+ #property copyright "Copyright © 2012, Nikolay Kositsin" #property link "farria@mail.redcom.ru" //---- indicator version number #property version "1.01" //---- drawing the indicator in the main window #property indicator_chart_window //---- number of indicator buffers 5 #property indicator_buffers 5 //---- only one plot is used #property indicator_plots 1 //+-----------------------------------+ //| Declaration of constants | //+-----------------------------------+ #define RESET 0 // The constant for returning the indicator recalculation command to the terminal //+-----------------------------------+ //| Indicator drawing parameters | //+-----------------------------------+ //---- color candlesticks are used as an indicator #property indicator_type1 DRAW_COLOR_CANDLES #property indicator_color1 clrGray,clrMagenta,clrHotPink,clrRed,clrBrown,clrLimeGreen,clrTeal,clrLime,clrPaleGreen //---- displaying the indicator label #property indicator_label1 "UltraFatl Open";"UltraFatl High";"UltraFatl Low";"UltraFatl Close" //+-----------------------------------+ //| Averaging classes description | //+-----------------------------------+ #include //+-----------------------------------+ //| Declaration of enumerations | //+-----------------------------------+ /*enum Smooth_Method - enumeration is declared in SmoothAlgorithms.mqh { MODE_SMA_, //SMA MODE_EMA_, //EMA MODE_SMMA_, //SMMA MODE_LWMA_, //LWMA MODE_JJMA, //JJMA MODE_JurX, //JurX MODE_ParMA, //ParMA MODE_T3, //T3 MODE_VIDYA, //VIDYA MODE_AMA, //AMA }; */ //+-----------------------------------+ //| Declaration of enumerations | //+-----------------------------------+ enum Applied_price_ //Type od constant { PRICE_CLOSE_ = 1, //Close PRICE_OPEN_, //Open PRICE_HIGH_, //High PRICE_LOW_, //Low PRICE_MEDIAN_, //Median Price (HL/2) PRICE_TYPICAL_, //Typical Price (HLC/3) PRICE_WEIGHTED_, //Weighted Close (HLCC/4) PRICE_SIMPL_, //Simpl Price (OC/2) PRICE_QUARTER_, //Quarted Price (HLOC/4) PRICE_TRENDFOLLOW0_, //TrendFollow_1 Price PRICE_TRENDFOLLOW1_ //TrendFollow_2 Price }; //+-----------------------------------+ //| INDICATOR INPUT PARAMETERS | //+-----------------------------------+ input ENUM_APPLIED_PRICE Applied_price=PRICE_CLOSE; // Applied price //---- input Smooth_Method W_Method=MODE_JJMA; // Smoothing method input int StartLength=3; // Initial smoothing period input int WPhase=100; // Smoothing parameter //---- input uint Step=5; // Period change step input uint StepsTotal=10; // Number of period changes //---- input Smooth_Method SmoothMethod=MODE_JJMA; // Smoothing method input int SmoothLength=3; // Smoothing depth input int SmoothPhase=100; // Smoothing parameter input Applied_price_ IPC=PRICE_CLOSE_; //price constant //---- input uint UpLevel=80; // Overbought level, %% input uint DnLevel=20; // Oversold level, %% //+-----------------------------------+ //---- Declaration of integer variables of data starting point int min_rates_total; //---- declaration of dynamic arrays that will further be // used as indicator buffers double ExtOpenBuffer[]; double ExtHighBuffer[]; double ExtLowBuffer[]; double ExtCloseBuffer[]; double ExtColorBuffer[]; //---- Declaration of integer variables for the indicator handles int InpInd_Handle; //+------------------------------------------------------------------+ //| UltraFatl indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //---- Initialization of variables of the start of data calculation CXMA XMA; min_rates_total=40; min_rates_total+=XMA.GetStartBars(W_Method,StartLength+Step*StepsTotal,WPhase)+1; min_rates_total+=XMA.GetStartBars(SmoothMethod,SmoothLength,SmoothPhase)+1; //---- getting the UltraFatl indicator handle InpInd_Handle=iCustom(Symbol(),PERIOD_CURRENT,"UltraFatl",Applied_price,W_Method,StartLength, WPhase,Step,StepsTotal,SmoothMethod,SmoothLength,SmoothPhase,IPC,UpLevel,DnLevel,clrNONE,clrNONE,0,0); if(InpInd_Handle==INVALID_HANDLE) Print("Failed to get handle of UltraFatl indicator"); //---- setting dynamic arrays as indicator buffers SetIndexBuffer(0,ExtOpenBuffer,INDICATOR_DATA); SetIndexBuffer(1,ExtHighBuffer,INDICATOR_DATA); SetIndexBuffer(2,ExtLowBuffer,INDICATOR_DATA); SetIndexBuffer(3,ExtCloseBuffer,INDICATOR_DATA); //---- setting dynamic array as a color index buffer SetIndexBuffer(4,ExtColorBuffer,INDICATOR_COLOR_INDEX); //---- indexing elements in the buffer as time series ArraySetAsSeries(ExtOpenBuffer,true); ArraySetAsSeries(ExtHighBuffer,true); ArraySetAsSeries(ExtLowBuffer,true); ArraySetAsSeries(ExtCloseBuffer,true); ArraySetAsSeries(ExtColorBuffer,true); //---- shifting the start of drawing of the indicator 1 PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total); //--- creation of the name to be displayed in a separate sub-window and in a pop up help IndicatorSetString(INDICATOR_SHORTNAME,"UltraFatl Candles"); //--- determining the accuracy of displaying the indicator values IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1); //---- end of initialization } //+------------------------------------------------------------------+ //| UltraFatl 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[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[] ) { //---- Checking if the number of bars is sufficient for the calculation if(BarsCalculated(InpInd_Handle)rates_total || prev_calculated<=0)// checking for the first start of the indicator calculation { limit=rates_total-1-min_rates_total; // starting index for the calculation of all bars } else { limit=rates_total-prev_calculated; // starting index for the calculation of new bars } to_copy=limit+1; //---- copy newly appeared data into the arrays if(CopyBuffer(InpInd_Handle,2,0,to_copy,ExtColorBuffer)<=0) return(RESET); //---- indexing elements in arrays as timeseries ArraySetAsSeries(open,true); ArraySetAsSeries(high,true); ArraySetAsSeries(low,true); ArraySetAsSeries(close,true); //---- main indicator calculation loop for(bar=limit; bar>=0 && !IsStopped(); bar--) { //--- Initialization of candles ExtOpenBuffer[bar]=open[bar]; ExtCloseBuffer[bar]=close[bar]; ExtHighBuffer[bar]=high[bar]; ExtLowBuffer[bar]=low[bar]; } //---- return(rates_total); } //+------------------------------------------------------------------+