/* * For the indicator to work, place the * SmoothAlgorithms.mqh * in the directory: MetaTrader\\MQL5\Include */ //+------------------------------------------------------------------+ //| SchaffTrendCycle.mq5 | //| Copyright © 2011, EarnForex.com | //| http://www.earnforex.com/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2011, EarnForex.com" #property link "http://www.earnforex.com" #property description "Schaff Trend Cycle - Cyclical Stoch over Stoch over XMACD." #property description "The code adapted by Nikolay Kositsin." //---- indicator version #property version "2.00" //---- drawing the indicator in a separate window #property indicator_separate_window //---- number of indicator buffers 1 #property indicator_buffers 1 //---- only one plot is used #property indicator_plots 1 //+-----------------------------------+ //| Indicator drawing parameters | //+-----------------------------------+ //---- drawing the indicator as a line #property indicator_type1 DRAW_LINE //---- dark orchid color is used as the color of the line #property indicator_color1 DarkOrchid //---- indicator line is a solid one #property indicator_style1 STYLE_SOLID //---- indicator line width is equal to 2 #property indicator_width1 2 //---- displaying the indicator label #property indicator_label1 "Schaff Trend Cycle" //+----------------------------------------------+ //| Horizontal levels display parameters | //+----------------------------------------------+ #property indicator_level1 80.0 #property indicator_level2 50.0 #property indicator_level3 20.0 #property indicator_levelcolor Red #property indicator_levelstyle STYLE_DASHDOTDOT //---- setting lower and upper borders of the indicator window #property indicator_minimum -10 #property indicator_maximum +110 //+-----------------------------------+ //| Smoothings classes description | //+-----------------------------------+ #include //+-----------------------------------+ //---- declaration of the CXMA class variables from the SmoothAlgorithms.mqh file CXMA XMA1,XMA2; //+-----------------------------------+ //| 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_SIMPLE_,//Simple Price (OC/2) PRICE_QUARTER_, //Quarted Price (HLOC/4) PRICE_TRENDFOLLOW0_, //TrendFollow_1 Price PRICE_TRENDFOLLOW1_ //TrendFollow_2 Price }; /*enum Smooth_Method - enumeration is declared in the SmoothAlgorithms.mqh file { 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 Smooth_Method MA_SMethod=MODE_EMA; //Histogram smoothing method input int Fast_XMA = 23; //Fast moving average period input int Slow_XMA = 50; //Slow moving average period input int SmPhase= 100; //Moving averages smoothing parameter //for JJMA that can change withing the range -100 ... +100. It impacts the quality of the intermediate process of smoothing; // for VIDIA it is a CMO period, for AMA it is a slow average period input Applied_price_ AppliedPrice=PRICE_CLOSE_;//Price constant /*---- used for the indicator calculation (1-CLOSE, 2-OPEN, 3-HIGH, 4-LOW, //---- 5-MEDIAN, 6-TYPICAL, 7-WEIGHTED, 8-SIMPLE, 9-QUARTER, 10-TRENDFOLLOW, 11-0.5 * TRENDFOLLOW.) */ input int Cycle=10; //Stochastic oscillator period //+-----------------------------------+ //---- declaration of a dynamic array that further //---- will be used an indicator buffer double STC_Buffer[]; int Count[]; bool st1_pass,st2_pass; double XMACD[],ST[],Factor; int StartBars,StartBars1,StartBars2; //+------------------------------------------------------------------+ //| Recalculation of position of the newest element in the array | //+------------------------------------------------------------------+ void Recount_ArrayZeroPos(int &CoArr[],// Return the current value of the price series by the link int Rates_total, int Bar) { //---- if(Bar>=Rates_total-1) return; int numb; static int count=1; count--; if(count<0) count=Cycle-1; for(int iii=0; iiiCycle-1) numb-=Cycle; CoArr[iii]=numb; } //---- } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //---- Initialization of variables of the start of data calculation StartBars1=MathMax(XMA1.GetStartBars(MA_SMethod,Fast_XMA,SmPhase), XMA1.GetStartBars(MA_SMethod,Slow_XMA,SmPhase)); StartBars2=StartBars1+Cycle; StartBars=StartBars2+Cycle; //---- memory distribution for variables' arrays if(ArrayResize(ST,Cycle)rates_total || prev_calculated<=0) // checking for the first start of the indicator calculation first=0; // starting index for calculation of all bars else first=prev_calculated-1; // starting index for calculation of new bars //---- Main indicator calculation loop for(bar=first; bar