//+---------------------------------------------------------------------+ //| BlauCMI_Signal.mq5 | //| Copyright © 2014, Nikolay Kositsin | //| Khabarovsk, farria@mail.redcom.ru | //+---------------------------------------------------------------------+ //| Place the SmoothAlgorithms.mqh file | //| in the directory: terminal_data_folder\MQL5\Include | //+---------------------------------------------------------------------+ #property copyright "Copyright © 2014, Nikolay Kositsin" #property link "farria@mail.redcom.ru" #property description "" //--- indicator version #property version "1.60" //--- drawing the indicator in a separate window #property indicator_separate_window //--- fixed height of the indicator subwindow in pixels #property indicator_height 20 //--- lower and upper scale limit of a separate indicator window #property indicator_maximum +1.9 #property indicator_minimum +0.3 //+----------------------------------------------+ //| declaration of constants | //+----------------------------------------------+ #define RESET 0 // A constant for returning the indicator recalculation command to the terminal #define INDTOTAL 1 // A constant for the number of displayed indicator #define INDICATOR_NAME "BlauCMI" // A constant for the indicator name //+----------------------------------------------+ //---- number of indicator buffers #property indicator_buffers 4 // INDTOTAL*4 //--- total plots used #property indicator_plots 2 // INDTOTAL*2 //+----------------------------------------------+ //| Indicator 1 drawing parameters | //+----------------------------------------------+ //--- drawing indicator 1 as a line #property indicator_type1 DRAW_COLOR_LINE //--- the following colors are used for the indicator line #property indicator_color1 clrDeepPink,clrOrange,clrGray,clrYellowGreen,clrTeal //--- the indicator line is dashed #property indicator_style1 STYLE_SOLID //--- indicator line width is 2 #property indicator_width1 2 //--- displaying the indicator label #property indicator_label1 "Signal line" //+----------------------------------------------+ //| Indicator 2 drawing parameters | //+----------------------------------------------+ //--- drawing the indicator as four-color labels #property indicator_type2 DRAW_COLOR_ARROW //--- colors of the five-color histogram are as follows #property indicator_color2 clrDeepPink,clrOrange,clrGray,clrYellowGreen,clrTeal //--- Indicator line is a solid one #property indicator_style2 STYLE_SOLID //--- indicator line width is 5 #property indicator_width2 5 //--- displaying the indicator label #property indicator_label2 "Signal Arrow" //+----------------------------------------------+ //| declaration of enumerations | //+----------------------------------------------+ enum Applied_price_ // type of 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_SIMPLE_, // Simple Price (OC/2) PRICE_QUARTER_, // Quarted Price (HLOC/4) PRICE_TRENDFOLLOW0_, // TrendFollow_1 Price PRICE_TRENDFOLLOW1_, // TrendFollow_2 Price PRICE_DEMARK_ // Demark Price }; //+----------------------------------------------+ //| declaration of enumerations | //+----------------------------------------------+ enum Smooth_Method { 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 }; //+----------------------------------------------+ //| Indicator input parameters | //+----------------------------------------------+ input ENUM_TIMEFRAMES TimeFrame=PERIOD_H4; // Chart period input Smooth_Method XMA_Method=MODE_EMA; // Method of averaging input uint XLength=1; // Momentum averaging depth input uint XLength1=20; // Depth of the first averaging input uint XLength2=5; // Depth of the second averaging input uint XLength3=3; // Depth of the third averaging input int XPhase=15; // Smoothing parameter //--- XPhase: for JJMA it varies within the range -100 ... +100 and influences the quality of the transient period; //--- XPhase: for VIDIA it is a CMO period, for AMA it is a slow average period input Applied_price_ IPC1=PRICE_CLOSE; // Price constant of closing input Applied_price_ IPC2=PRICE_OPEN; // Price constant of opening //+----------------------------------------------+ //--- declaration of integer variables for the start of data calculation int min_rates_total; //+------------------------------------------------------------------+ //| Getting a timeframe as a line | //+------------------------------------------------------------------+ string GetStringTimeframe(ENUM_TIMEFRAMES timeframe) {return(StringSubstr(EnumToString(timeframe),7,-1));} //+------------------------------------------------------------------+ //| Indicator buffer class | //+------------------------------------------------------------------+ class CIndBuffers { //--- public: double m_LineBuffer[]; double m_ColorLineBuffer[]; double m_ArrowBuffer[]; double m_ColorArrowBuffer[]; int m_Handle; ENUM_TIMEFRAMES m_TimeFrame; //--- }; //--- declaration of dynamic arrays that //--- will be used as indicator buffers CIndBuffers Ind[INDTOTAL]; //+------------------------------------------------------------------+ //| BlauCMI indicator initialization function | //+------------------------------------------------------------------+ bool IndInit(uint Number) { //--- checking correctness of the chart periods if(Ind[Number].m_TimeFrameRates_Total || Prev_Calculated<=0)// checking for the first start of the indicator calculation { limit_=Limit; LastCountBar[Number]=limit_; } else limit_=int(MathMin(LastCountBar[Number]+Limit,Rates_Total-2)); // starting index for calculating new bars //--- main indicator calculation loop for(int bar=int(limit_); bar>=0 && !IsStopped(); bar--) { //---- reset the contents of the indicator buffers for calculation Ind[Number].m_LineBuffer[bar]=Number+1.0; Ind[Number].m_ArrowBuffer[bar]=EMPTY_VALUE; Ind[Number].m_ColorLineBuffer[bar]=EMPTY_VALUE; //--- Time0=Time[bar]; //--- copy newly appeared data in the array if(CopyTime(Symbol(),Ind[Number].m_TimeFrame,Time0,1,Time_)<=0) return(RESET); if(Time0>=Time_[0] && Time[bar+1]rates_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=rates_total-prev_calculated; // Starting index for the calculation of new bars //--- apply timeseries indexing to array elements ArraySetAsSeries(time,true); for(int count=0; count