Time: 2011-10-01 | Download file:Schaff_Trend_Cycle_arrows_&_alerts_2_mtf.mq4
//+------------------------------------------------------------------+ //| Schaff Trend Cycle.mq4 | //| mladen | //+------------------------------------------------------------------+ #property copyright "mladen" #property link "mladenfx@gmail.com" #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Lime #property indicator_width1 2 #property indicator_color2 Red #property indicator_width2 2 // // // // // extern string TimeFrame = "Current time frame"; extern int STCPeriod = 10; extern int FastMAPeriod = 23; extern int SlowMAPeriod = 50; extern int LevelForUpArrow = 25; extern int LevelForDownArrow = 75; extern bool ShowArrowsOnLevelBreak = true; extern double arrowsUpperGap = 0.1; extern double arrowsLowerGap = 0.1; extern bool alertsOn = false; extern bool alertsOnCurrent = true; extern bool alertsMessage = true; extern bool alertsPushNotif = false; extern bool alertsSound = false; extern bool alertsEmail = false; extern bool ArrowOnFirstBar = false; // // // // // double upBuffer[]; double dnBuffer[]; double stcBuffer[]; double macdBuffer[]; double trendBuffer[]; double fastKBuffer[]; double fastDBuffer[]; double fastKKBuffer[]; // // // // // string indicatorFileName; bool returnBars; int timeFrame; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int init() { IndicatorBuffers(8); SetIndexBuffer(0,upBuffer); SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0,164);//108 SetIndexBuffer(1,dnBuffer); SetIndexStyle(1,DRAW_ARROW); SetIndexArrow(1,164); SetIndexBuffer(2,stcBuffer); SetIndexBuffer(3,macdBuffer); SetIndexBuffer(4,fastKBuffer); SetIndexBuffer(5,fastDBuffer); SetIndexBuffer(6,fastKKBuffer); SetIndexBuffer(7,trendBuffer); // // // // // indicatorFileName = WindowExpertName(); returnBars = TimeFrame == "returnBars"; if (returnBars) return(0); timeFrame = stringToTimeFrame(TimeFrame); // // // // // IndicatorShortName(timeFrameToString(timeFrame)+" Schaff Trend Cycle ("+STCPeriod+","+FastMAPeriod+","+SlowMAPeriod+")"); return(0); } int deinit() { return(0); } //+-----------------------------------------------------------------------------------------------+ //| | //+-----------------------------------------------------------------------------------------------+ // // // // // int start() { int counted_bars=IndicatorCounted(); if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; int limit=MathMin(Bars-counted_bars,Bars-1); if (returnBars) { upBuffer[0] = limit+1; return(0); } if (timeFrame!=Period()) { int shift = -1; if (ArrowOnFirstBar) shift=1; limit = MathMax(limit,MathMin(Bars-1,iCustom(NULL,timeFrame,indicatorFileName,"returnBars",0,0)*timeFrame/Period())); for (int i=limit; i>=0; i--) { int y = iBarShift(NULL,timeFrame,Time[i]); int x = iBarShift(NULL,timeFrame,Time[i+shift]); if (x!=y) { upBuffer[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",STCPeriod,FastMAPeriod,SlowMAPeriod,LevelForUpArrow,LevelForDownArrow,ShowArrowsOnLevelBreak,arrowsUpperGap,arrowsLowerGap,alertsOn,alertsOnCurrent,alertsMessage,alertsPushNotif,alertsSound,alertsEmail,0,y); dnBuffer[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",STCPeriod,FastMAPeriod,SlowMAPeriod,LevelForUpArrow,LevelForDownArrow,ShowArrowsOnLevelBreak,arrowsUpperGap,arrowsLowerGap,alertsOn,alertsOnCurrent,alertsMessage,alertsPushNotif,alertsSound,alertsEmail,1,y); } else { upBuffer[i] = EMPTY_VALUE; dnBuffer[i] = EMPTY_VALUE; } } return(0); } // // // // // double upZone = MathMax(LevelForDownArrow,LevelForUpArrow); double dnZone = MathMin(LevelForDownArrow,LevelForUpArrow); for(i = limit; i >= 0; i--) { macdBuffer[i] = iMA(NULL,0,FastMAPeriod,0,MODE_EMA,PRICE_CLOSE,i)- iMA(NULL,0,SlowMAPeriod,0,MODE_EMA,PRICE_CLOSE,i); // // // // // double lowMacd = minValue(macdBuffer,i); double highMacd = maxValue(macdBuffer,i)-lowMacd; if (highMacd > 0) fastKBuffer[i] = 100*((macdBuffer[i]-lowMacd)/highMacd); else fastKBuffer[i] = fastKBuffer[i+1]; fastDBuffer[i] = fastDBuffer[i+1]+0.5*(fastKBuffer[i]-fastDBuffer[i+1]); // // // // // double lowStoch = minValue(fastDBuffer,i); double highStoch = maxValue(fastDBuffer,i)-lowStoch; if (highStoch > 0) fastKKBuffer[i] = 100*((fastDBuffer[i]-lowStoch)/highStoch); else fastKKBuffer[i] = fastKKBuffer[i+1]; stcBuffer[i] = stcBuffer[i+1]+0.5*(fastKKBuffer[i]-stcBuffer[i+1]); // // // // // upBuffer[i] = EMPTY_VALUE; dnBuffer[i] = EMPTY_VALUE; double gap = iATR(NULL,0,20,i); if (ShowArrowsOnLevelBreak) { trendBuffer[i] = 0; if (stcBuffer[i] >= upZone) trendBuffer[i] = 1; if (stcBuffer[i] <= dnZone) trendBuffer[i] = -1; if (LevelForDownArrow>LevelForUpArrow) { if (trendBuffer[i] != 1 && trendBuffer[i+1] == 1) dnBuffer[i] = High[i]+arrowsUpperGap*gap; if (trendBuffer[i] != -1 && trendBuffer[i+1] == -1) upBuffer[i] = Low[i] -arrowsLowerGap*gap; } if (LevelForDownArrowstcBuffer[i+1]) trendBuffer[i] = 1; if (stcBuffer[i] =0; i--) if (tfs==sTfTable[i] || tfs==""+iTfTable[i]) return(MathMax(iTfTable[i],Period())); return(Period()); } string timeFrameToString(int tf) { for (int i=ArraySize(iTfTable)-1; i>=0; i--) if (tf==iTfTable[i]) return(sTfTable[i]); return(""); } // // // // // string stringUpperCase(string str) { string s = str; for (int length=StringLen(str)-1; length>=0; length--) { int tchar = StringGetChar(s, length); if((tchar > 96 && tchar < 123) || (tchar > 223 && tchar < 256)) s = StringSetChar(s, length, tchar - 32); else if(tchar > -33 && tchar < 0) s = StringSetChar(s, length, tchar + 224); } return(s); }