Price Data Components
Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
MA_Price_Cross1.1m_alert
//+------------------------------------------------------------------+
//| MA-Cross/Price Signal.mq4 |
//+------------------------------------------------------------------+
/* Copyright © 2008, GODFREYH
+------------------------------------------------------------------+
| Allows you to enter a ma period and it will then show you and |
| email you at which point price crossed the MA. |
+------------------------------------------------------------------+
*/
//mod2009fxtsd
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 DodgerBlue
#property indicator_color2 Red
double CrossUp[];
double CrossDown[];
extern string MA_Type_ = "0sma,1ema,2smma,3lwma";
extern int MA_Type_selected = 1; //0=sma, 1=ema, 2=smma,
extern int MA_Period =50;
double PRICECLOSE;
extern bool Alert_On_Crossing = true;
extern bool alertsDelay = 1;
extern bool POP_UP_ON = true;
extern bool EMAIL_ON = false;
extern string NameFileSound = "alert.wav";
string MAshort_name;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_ARROW);
SetIndexArrow(0, 233);
SetIndexBuffer(0, CrossUp);
SetIndexStyle(1, DRAW_ARROW);
SetIndexArrow(1, 234);
SetIndexBuffer(1, CrossDown);
SetIndexEmptyValue(0,EMPTY_VALUE);
SetIndexEmptyValue(1,EMPTY_VALUE);
//---- indicator short name
switch(MA_Type_selected)
{
case 1 : MAshort_name="EMA"; break;
case 2 : MAshort_name="SMMA"; break;
case 3 : MAshort_name="LWMA"; break;
default :
MA_Type_selected=0;
MAshort_name="SMA";
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start() {
static datetime dt = 0;
int limit, i, counter;
double MAnow, Pricenow, MAprevious, Priceprevious, MAafter, Priceafter;
double Range, AvgRange;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
static datetime cDT = 0;
for(i = 0; i <= limit; i++) {
counter=i;
Range=0;
AvgRange=0;
CrossUp[i] = 0; CrossDown[i] = 0;
for (counter=i ;counter<=i+9;counter++)
{
AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
}
Range=AvgRange/10;
MAnow = iMA(NULL, 0, MA_Period, 0, MA_Type_selected, PRICE_CLOSE, i+alertsDelay);
MAprevious = iMA(NULL, 0, MA_Period, 0, MA_Type_selected, PRICE_CLOSE, i+1+alertsDelay);
// MAafter = iMA(NULL, 0, MA_Period, 0, MA_Type_selected, PRICE_CLOSE, i-1);
Pricenow = iClose(NULL,0,i+alertsDelay);
Priceprevious = iClose(NULL,0,i+1+alertsDelay);
// Priceafter = iClose(NULL,0,i-1);
CrossUp[i] = EMPTY_VALUE; CrossDown[i] = EMPTY_VALUE;
if ((Pricenow > MAnow) && (Priceprevious < MAprevious) ) {
CrossUp[i] = Low[i] - Range*0.75;
if ((i < 2) && (dt != iTime(NULL,0,0)))
{
if (Alert_On_Crossing ==true)
{
if (POP_UP_ON ==true)
{
Alert(Symbol(), " M", Period(), " Price closed above moving average");
}
PlaySound(NameFileSound);
dt = iTime(NULL,0,0);
}
if (EMAIL_ON ==true)
{
SendMail("Price closed above MA"," Price closed above moving average");
dt = iTime(NULL,0,0);
}
}
}
else if ((Pricenow < MAnow) && (Priceprevious > MAprevious) ){
CrossDown[i] = High[i] + Range*0.75;
if ((i < 2) && (dt != iTime(NULL,0,0)))
{
if (Alert_On_Crossing ==true)
{
if (POP_UP_ON ==true)
{
Alert(Symbol(), " M", Period(), " Price closed below moving average");
}
PlaySound(NameFileSound);
dt = iTime(NULL,0,0);
}
if (EMAIL_ON ==true)
{
SendMail("Price closed below MA"," Price closed below moving average");
dt = iTime(NULL,0,0);
}
}}
}
return(0);
}
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
---