//+------------------------------------------------------------------+ //| Trix of log of a price.mq4 | //| | //+------------------------------------------------------------------+ #property copyright "copyleft mladen" #property link "mladenfx@gmail.com" #property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 DimGray #property indicator_color2 DarkOrange #property indicator_style1 STYLE_DOT // // // // // extern int TrixPeriod = 9; extern int TrixPrice = PRICE_CLOSE; extern bool Alerts.On = false; extern bool Alerts.OnCurrent = false; extern bool Alerts.Message = true; extern bool Alerts.Sound = false; extern bool Alerts.Email = false; // // // // // double TrixBuffer[]; double ZeroBuffer[]; double EmaBuffer1[]; double EmaBuffer2[]; double EmaBuffer3[]; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int init() { IndicatorBuffers(5); SetIndexBuffer(0,ZeroBuffer); SetIndexBuffer(1,TrixBuffer); SetIndexBuffer(2,EmaBuffer1); SetIndexBuffer(3,EmaBuffer2); SetIndexBuffer(4,EmaBuffer3); IndicatorShortName("Trix ("+TrixPeriod+")"); return(0); } // // // // // int start() { double alpha = 2.0/(1.0+TrixPeriod); int counted_bars=IndicatorCounted(); if(counted_bars < 0) return(-1); if(counted_bars>0) counted_bars--; int limit = Bars-counted_bars; // // // // // for(int i=limit; i>=0; i--) { double price = MathLog(iMA(NULL,0,1,0,MODE_SMA,TrixPrice,i)); EmaBuffer1[i] = EmaBuffer1[i+1]+alpha*(price -EmaBuffer1[i+1]); EmaBuffer2[i] = EmaBuffer2[i+1]+alpha*(EmaBuffer1[i]-EmaBuffer2[i+1]); EmaBuffer3[i] = EmaBuffer3[i+1]+alpha*(EmaBuffer2[i]-EmaBuffer3[i+1]); TrixBuffer[i] = (EmaBuffer3[i]-EmaBuffer3[i+1])*10000; ZeroBuffer[i] = 0; } if (Alerts.On) { if (Alerts.OnCurrent) int forBar = 1; else forBar = 0; if (TrixBuffer[forBar]>0 && TrixBuffer[forBar+1]<0) doAlert("UP"); if (TrixBuffer[forBar]<0 && TrixBuffer[forBar+1]>0) doAlert("DOWN"); } return(0); } // // // // // void doAlert(string doWhat) { static string previousAlert="nothing"; static datetime previousTime; string message; if (previousAlert != doWhat || previousTime != Time[0]) { previousAlert = doWhat; previousTime = Time[0]; // // // // // message = StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," trix trend changed to ",doWhat); if (Alerts.Message) Alert(message); if (Alerts.Email) SendMail(doWhat,message); if (Alerts.Sound) PlaySound("alert2.wav"); } }
Sample
Analysis
Market Information Used:
Series array that contains open time of each bar
Indicator Curves created:
Indicators Used:
Moving average indicator
Custom Indicators Used:
Order Management characteristics:
Other Features:
It issuies visual alerts to the screen
It sends emails
It plays sound alerts