Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
Trix log + alert
//+------------------------------------------------------------------+
//| Trix of log of a price.mq4 |
//| |
//+------------------------------------------------------------------+
#property copyright "copyleft mladen"
#property link "mladenfx@gmail.com"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 DimGray
#property indicator_color2 Lime
#property indicator_color3 DarkOrange
#property indicator_style1 STYLE_DOT
#property indicator_style3 STYLE_DOT
//
//
//
//
//
extern int TrixPeriod = 9;
extern int TrixPrice = PRICE_CLOSE;
extern int SignalPeriod = 9;
extern int SignalMethod = 3;
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 SignBuffer[];
double ZeroBuffer[];
double EmaBuffer1[];
double EmaBuffer2[];
double EmaBuffer3[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(6);
SetIndexBuffer(0,ZeroBuffer);
SetIndexBuffer(1,TrixBuffer);
SetIndexBuffer(2,SignBuffer);
SetIndexBuffer(3,EmaBuffer1);
SetIndexBuffer(4,EmaBuffer2);
SetIndexBuffer(5,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;
}
for (i=limit;i>=0;i--) SignBuffer[i] = iMAOnArray(TrixBuffer,0,SignalPeriod,0,SignalMethod,i);
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");
}
}
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---