//+--------------------------------------------------------------------------+ //| 2008forextsd mladen MA_Cross_3MACross_AlertWarningSig | //+--------------------------------------------------------------------------+ #property copyright "" #property link "" #property indicator_chart_window #property indicator_buffers 4 #property indicator_color1 LawnGreen #property indicator_color2 Magenta #property indicator_color3 Yellow #property indicator_color4 Gold #property indicator_width1 2 #property indicator_width2 2 #property indicator_width3 1 #property indicator_width4 1 #import "SpeechDude.dll" int MT_SpeechText(string text, int async); #include #import // // // // // extern string MA_Mode = "SMA0 EMA1 SMMA2 LWMA3"; extern string Price1 = "0-Close 1-Open 2-High 3-Low"; extern string Price2 = "4-Median/2 5-Typical/3 6-Weighted/4"; extern int FasterMA = 6; extern int FasterMode = 1; // 0 = sma, 1 = ema, 2 = smma, 3 = lwma extern int FasterPrice = 6; // 0 = Close, 1 = Open, 2= High, 3 = Low, 4 = Median(high+low)/2, 5 = Typical (high+low+close)/3, 6 = Weighted close price, (high+low+close+close)/4 extern int FasterShift = 0; extern int MediumMA = 200; extern int MediumMode = 0; // 0 = sma, 1 = ema, 2 = smma, 3 = lwma extern int MediumPrice = 6; // 0 = Close, 1 = Open, 2= High, 3 = Low, 4 = Median(high+low)/2, 5 = Typical (high+low+close)/3, 6 = Weighted close price, (high+low+close+close)/4 extern int MediumShift = 0; extern int SlowerMA = 25; extern int SlowerMode = 0; // 0 = sma, 1 = ema, 2 = smma, 3 = lwma extern int SlowerPrice = 1; // 0 = Close, 1 = Open, 2= High, 3 = Low, 4 = Median(high+low)/2, 5 = Typical (high+low+close)/3, 6 = Weighted close price, (high+low+close+close)/4 extern int SlowerShift = 0; extern bool crossesOnCurrent = false; extern bool ShowCrossOnSlow = false; extern bool alertsOn = true; extern bool alertsMessage = false; extern bool alertsSound = false; extern bool alertsEmail = false; extern bool FullVoiceSupport = true; extern double Offset = 2.0; // // // // // double CrossUp[]; double CrossDown[]; double CrossWUp[]; double CrossWDown[]; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int init() { SetIndexBuffer(0, CrossUp); SetIndexStyle(0, DRAW_ARROW); SetIndexArrow(0, 233); SetIndexBuffer(1, CrossDown); SetIndexStyle(1, DRAW_ARROW); SetIndexArrow(1, 234); SetIndexBuffer(2, CrossWUp); SetIndexStyle(2, DRAW_ARROW); SetIndexArrow(2, 233); SetIndexBuffer(3, CrossWDown); SetIndexStyle(3, DRAW_ARROW); SetIndexArrow(3, 234); return(0); } int deinit() { return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int start() { int limit, i; int counted_bars=IndicatorCounted(); double fasterMAnow, fasterMAprevious, fasterMAafter; double mediumMAnow, mediumMAprevious, mediumMAafter; double slowerMAnow, slowerMAprevious, slowerMAafter; if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; // // // // // // for(i = limit; i >=0; i--) { double Range = 0.0; for (int counter=i ;counter<=i+9;counter++) Range += MathAbs(High[counter]-Low[counter]); Range /= 10; // // // // // fasterMAnow = iMA(NULL, 0, FasterMA, FasterShift, FasterMode, FasterPrice, i); fasterMAprevious = iMA(NULL, 0, FasterMA, FasterShift, FasterMode, FasterPrice, i+1); mediumMAnow = iMA(NULL, 0, MediumMA, MediumShift, MediumMode, MediumPrice, i); mediumMAprevious = iMA(NULL, 0, MediumMA, MediumShift, MediumMode, MediumPrice, i+1); slowerMAnow = iMA(NULL, 0, SlowerMA, SlowerShift, SlowerMode, SlowerPrice, i); slowerMAprevious = iMA(NULL, 0, SlowerMA, SlowerShift, SlowerMode, SlowerPrice, i+1); //iMA( // // avoid current bar if not allowed to check crosses on current (i==0) // // if (crossesOnCurrent==false && i==0) continue; // // // // // int crossID=0; double curr; double prev; double point; while (true) { curr = fasterMAnow - mediumMAnow; prev = fasterMAprevious - mediumMAprevious; point = (fasterMAnow + fasterMAprevious)/2; if (curr*prev<=0) { crossID=1; break; } if (ShowCrossOnSlow) { curr = fasterMAnow - slowerMAnow; prev = fasterMAprevious - slowerMAprevious; if (curr*prev<=0) { crossID=2; break; } curr = mediumMAnow - slowerMAnow; prev = mediumMAprevious - slowerMAprevious; point = (mediumMAnow + mediumMAprevious)/2; if (curr*prev<=0) { crossID=3; break; } } break; } // // // the interesting thing is the direction of the crossing // which MA is the primary and which one the secondary // if you do not know that you can not determine the "direction" // of the cross // // // CrossUp[i] = EMPTY_VALUE; CrossDown[i] = EMPTY_VALUE; CrossWUp[i] = EMPTY_VALUE; CrossWDown[i] = EMPTY_VALUE; if (crossID>0) { if (alertsOn) if ((i==0 && crossesOnCurrent==true) || (i==1 && crossesOnCurrent==false)) { switch (crossID) { case 1: if(curr>0) { doAlert(" 3MACross: Fast MA crossed Medium MA UP"); DoAlertAudible("Average cross long"); } else { doAlert(" 3MACross: Fast MA crossed Medium MA DOWN"); DoAlertAudible("Average cross short"); } break; case 2: if(curr>0) { doAlert(" 3MACross: Fast MA crossed Slow MA UP"); DoAlertAudible("Average cross long"); } else { doAlert(" 3MACross: Fast MA crossed Slow MA DOWN"); DoAlertAudible("Average cross short"); } break; case 3: if(curr>0) { doAlert(" 3MACross: Medium MA crossed Slow MA UP"); DoAlertAudible("Average cross long"); } else { doAlert(" 3MACross: Medium MA crossed Slow MA DOWN"); DoAlertAudible("Average cross short"); } break; } } // // // // // if (i==0) { if (curr>0) CrossWUp[i] = point - Range*Offset; else CrossWDown[i] = point + Range*Offset; } else { if (curr>0) CrossUp[i] = point - Range*Offset; else CrossDown[i] = point + Range*Offset; } } } return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // void DoAlertAudible(string str) { static string previousVoiceAlert="nothing"; static datetime previousVoiceTime; //string message; if (previousVoiceAlert != str || previousVoiceTime != Time[0]) { previousVoiceAlert = str; previousVoiceTime = Time[0]; if (FullVoiceSupport) MT_SpeechText(Symbol2LongName() + ", " + TimeFrame2LongName(Period()) + ", " + str, 1); } } void doAlert(string doWhat) { static string previousAlert="nothing"; static datetime previousTime; string message; if (previousAlert != doWhat || previousTime != Time[0]) { previousAlert = doWhat; previousTime = Time[0]; // // // // // // if time needed : // message = StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," @",Bid," ", doWhat); // message = StringConcatenate(Symbol()," at ",Bid," ", doWhat); if (alertsMessage) Alert(message); if (alertsEmail) SendMail(StringConcatenate(Symbol()," 3MACross:"," M",Period()),message); if (alertsSound) PlaySound("alert2.wav"); } }