Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
TRIX-with-alert
//+------------------------------------------------------------------+
//| TRIX.mq4 |
//| |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Lightning Signals"
#property link "http://www.metaquotes.net"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Crimson
#property indicator_width1 2
#property indicator_width2 2
//---- input parameters
extern int TRIXPeriod = 4;
extern int TRIXSignal = 4 ;
extern int MAAppliedPrice = 0;
extern bool Email=true;
extern bool Sound=true;
// PRICE_CLOSE 0 Close price.
// PRICE_OPEN 1 Open price.
// PRICE_HIGH 2 High price.
// PRICE_LOW 3 Low price.
// PRICE_MEDIAN 4 Median price, (high+low)/2.
// PRICE_TYPICAL 5 Typical price, (high+low+close)/3.
// PRICE_WEIGHTED 6 Weighted close price, (high+low+close+close)/4.
//extern int Desplazar = 1;
//---- buffers
double TRIX_Buffer[];
double Signal_Buffer[];
double EMA1_buffer[];
double EMA2_buffer[];
double EMA3_buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 3 additional buffers are used for counting.
IndicatorBuffers(5);
SetIndexBuffer(2,EMA1_buffer);
SetIndexBuffer(3,EMA2_buffer);
SetIndexBuffer(4,EMA3_buffer);
//---- indicators - drawing settings
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,TRIX_Buffer);
SetIndexStyle(1,DRAW_LINE);
SetIndexDrawBegin(1,TRIXSignal);
SetIndexBuffer(1,Signal_Buffer);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("TRIX("+TRIXPeriod+","+TRIXSignal+")");
SetIndexLabel(0,"Trix");
SetIndexLabel(1,"Signal");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i,limit;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
if(Bars<=TRIXPeriod) return(0);
//---- initial zero
if(counted_bars<1)
{
for(i=1;i<=TRIXPeriod;i++) TRIX_Buffer[Bars-i]=0.0;
for(i=1;i<=TRIXPeriod;i++) Signal_Buffer[Bars-i]=0.0;
for(i=1;i<=TRIXPeriod;i++) EMA1_buffer[Bars-i]=0.0;
for(i=1;i<=TRIXPeriod;i++) EMA2_buffer[Bars-i]=0.0;
for(i=1;i<=TRIXPeriod;i++) EMA3_buffer[Bars-i]=0.0;
}
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(i=0; i<limit; i++)
EMA1_buffer[i]=iMA(NULL,0,TRIXPeriod,0,MODE_EMA,PRICE_CLOSE,i);
for(i=0; i<limit; i++)
EMA2_buffer[i]=iMAOnArray(EMA1_buffer,Bars,TRIXPeriod,0,MODE_EMA,i);
for(i=0; i<limit; i++)
EMA3_buffer[i]=iMAOnArray(EMA2_buffer,Bars,TRIXPeriod,0,MODE_EMA,i);
for(i=0; i<limit-1; i++)
{
TRIX_Buffer[i] = (EMA3_buffer[i] - EMA3_buffer[i+1]) / EMA3_buffer[i+1] *100;
}
for(i=0; i<limit-1; i++)
{
Signal_Buffer[i]=iMAOnArray(TRIX_Buffer,Bars,TRIXSignal,0,MODE_SMA,i);
}
Print(Crossed (TRIX_Buffer[0],Signal_Buffer[0]));
//---- done
return(0);
}
bool Crossed (double line1 , double line2 )
{
static string last_direction = "";
string current_dirction = "";
if(line1>line2)current_dirction = "up";
if(line1<=line2)current_dirction = "down";
if(current_dirction != last_direction)
{
if (Sound)
{
Alert("TRIX Cross for "+Symbol()+" on the "+Period()+" minute chart.");
}
if (Email)
{
SendMail ("TRIX Alert","Check TRIX for "+Symbol()+" on the "+Period()+" minute chart.");
}
last_direction = current_dirction;
return (true);
}
else
{
return (false);
}
}
//+------------------------------------------------------------------+
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
---