Time: 2011-06-03 | Download file:Double_stochastic_-_Bressert_&_alerts.mq4
//+------------------------------------------------------------------+ //| bressert double stochastic.mq4 | //| mladen | //| made after the prorealtim formula | //+------------------------------------------------------------------+ #property copyright "www.forex-tsd.com" #property link "www.forex-tsd.com" #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 DeepSkyBlue #property indicator_width1 2 #property indicator_minimum 0 #property indicator_maximum 100 // // // // // extern int StochasticLength = 10; extern int SmoothEmaLength = 3; extern int RatioLong = 7; extern int RatioShort = 3; extern int RatioPrice = PRICE_CLOSE; extern int SellLine = 60; extern int BuyLine = 40; extern bool alertsOn = false; extern bool alertsOnCurrent = true; extern bool alertsMessage = true; extern bool alertsSound = false; extern bool alertsEmail = false; double dsBuffer[]; double state[]; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int init() { IndicatorBuffers(2); SetIndexBuffer(0,dsBuffer); SetIndexBuffer(1,state); StochasticLength = MathMax(1,StochasticLength); SmoothEmaLength = MathMax(1,SmoothEmaLength); SetLevelValue(0,SellLine); SetLevelValue(1,BuyLine); IndicatorShortName("Bressert double stochastic("+StochasticLength+","+SmoothEmaLength+")"); return(0); } int deinit(){ return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // double work[][3]; #define _st1 0 #define _ss1 1 #define _ratio 2 // // // // // int start() { int limit,i,r,counted_bars = IndicatorCounted(); if(counted_bars < 0) return(-1); if(counted_bars > 0) counted_bars--; limit = MathMin(Bars-counted_bars,Bars-1); if (ArrayRange(work,0)!=Bars) ArrayResize(work,Bars); // // // // // double alpha = 2.0 / (1.0+SmoothEmaLength); for(i = limit, r=Bars-i-1; i>=0; i--,r++) { work[r][_ratio] = iMA(NULL,0,RatioShort,0,MODE_EMA,RatioPrice,i)/iMA(NULL,0,RatioLong,0,MODE_EMA,RatioPrice,i); double min = work[r][_ratio]; double max = work[r][_ratio]; for (int k=1; k=0; k++) { min = MathMin(min,work[r-k][_ratio]); max = MathMax(max,work[r-k][_ratio]); } work[r][_st1] = 0; if (min!=max) work[r][_st1] = 100*(work[r][_ratio]-min)/(max-min); work[r][_ss1] = work[r-1][_ss1]+alpha*(work[r][_st1]-work[r-1][_ss1]); // // // // // min = work[r][_ss1]; max = work[r][_ss1]; for (k=1; k =0; k++) { min = MathMin(min,work[r-k][_ss1]); max = MathMax(max,work[r-k][_ss1]); } double stoch = 0; if (min!=max) stoch = 100*(work[r][_ss1]-min)/(max-min); dsBuffer[i] = dsBuffer[i+1]+alpha*(stoch-dsBuffer[i+1]); state[i] = state[i+1]; if (dsBuffer[i]>SellLine) state[i] = 1; if (dsBuffer[i] BuyLine) state[i] = 0; } manageAlerts(); return(0); } //------------------------------------------------------------------- // //------------------------------------------------------------------- // // // // // void manageAlerts() { if (alertsOn) { if (alertsOnCurrent) int whichBar = 0; else whichBar = 1; if (state[whichBar] != state[whichBar+1]) { if (state[whichBar] == 1 ) doAlert(whichBar,"crossed "+DoubleToStr(SellLine,2)+" up"); if (state[whichBar] == -1 ) doAlert(whichBar,"crossed "+DoubleToStr(BuyLine,2) +" down"); if (state[whichBar] == 0 && state[whichBar+1] == 1) doAlert(whichBar,"crossed "+DoubleToStr(SellLine,2)+" down"); if (state[whichBar] == 0 && state[whichBar+1] == -1) doAlert(whichBar,"crossed "+DoubleToStr(BuyLine,2) +" up"); } } } // // // // // void doAlert(int forBar, string doWhat) { static string previousAlert="nothing"; static datetime previousTime; string message; if (previousAlert != doWhat || previousTime != Time[forBar]) { previousAlert = doWhat; previousTime = Time[forBar]; // // // // // message = StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," dss ", doWhat); if (alertsMessage) Alert(message); if (alertsEmail) SendMail(StringConcatenate(Symbol(),"dss"),message); if (alertsSound) PlaySound("alert2.wav"); } }