//+------------------------------------------------------------------+ //| MFI Count.mq4 | //| Copyright © 2015, Gehtsoft USA LLC | //| http://fxcodebase.com | //+------------------------------------------------------------------+ #property copyright "Copyright © 2015, Gehtsoft USA LLC" #property link "http://fxcodebase.com" #property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 DarkGreen #property indicator_color2 FireBrick //Red #property indicator_width1 2 #property indicator_width2 2 extern int Period = 8; extern bool alertsOn = false; // Turn alerts on extern bool alertsOnCurrent = true; // Alerts on currnt (still opened) bar extern bool alertsMessage = true; // Aleert should show pop-up message extern bool alertsSound = false; // Alerts should play alert sound extern bool alertsPushNotif = false; // Alerts should send push notification extern bool alertsEmail = false; // Alerts should send email double Up[], Dn[], trend[]; int init() { IndicatorBuffers(3); IndicatorDigits(Digits-3); SetIndexBuffer(0,Up); SetIndexBuffer(1,Dn); SetIndexBuffer(2,trend); SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexLabel(0,"TrendUP"); SetIndexLabel(1,"TrendDN"); IndicatorShortName("MFI Count ["+Period+"]"); return(0); } int deinit() { return(0); } int start() { if(Bars<=3) return(0); int ExtCountedBars=IndicatorCounted(); if (ExtCountedBars<0) return(-1); int limit=Bars-2; if(ExtCountedBars>2) limit=Bars-ExtCountedBars-1; int pos; double MA, Pr; double Sum; pos=limit; while(pos>=0) { if (pos==Bars-2) { Up[pos]=0; Dn[pos]=0; } else { Sum=Up[pos+1]+Dn[pos+1]; MA=1* (iMFI(NULL, 0, Period*4, pos) - iMFI(NULL, 0, Period, pos)); Pr=1* (iMFI(NULL, 0, Period/2, pos) - iMFI(NULL, 0, Period, pos)); if (Sum>=0) { if (Pr>MA) { Up[pos]=Up[pos+1]+1; Dn[pos]=0; } else { Up[pos]=0; Dn[pos]=-1; } } else { if (Pr 0) trend[pos]= 1; if (Dn[pos]< 0) trend[pos]= -1; pos--; } manageAlerts(); return(0); } //------------------------------------------------------------------- // //------------------------------------------------------------------- void manageAlerts() { if (alertsOn) { int whichBar = 1; if (alertsOnCurrent) whichBar = 0; if (trend[whichBar] != trend[whichBar+1]) { if (trend[whichBar] == 1) doAlert(whichBar,"up"); if (trend[whichBar] == -1) doAlert(whichBar,"down"); } } } // // 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 = Symbol()+" at "+TimeToStr(TimeLocal(),TIME_SECONDS)+" ma count trend changed to "+doWhat; if (alertsMessage) Alert(message); if (alertsEmail) SendMail(Symbol()+" ma count",message); if (alertsPushNotif) SendNotification(message); if (alertsSound) PlaySound("alert2.wav"); } }