Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
3MA_Cross_AlertWarnSigL_NegShift
//+--------------------------------------------------------------------------+
//| 3 MA Cross with alert.mq4 |
//| mladen |
//+--------------------------------------------------------------------------+
#property copyright "mladen"
#property link "mladenfx@gmail.com"
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 DodgerBlue
#property indicator_color2 Red
#property indicator_color3 Gold
#property indicator_color4 Gold
#property indicator_color5 Lime
#property indicator_color6 YellowGreen
#property indicator_color7 CadetBlue
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1
//
//
//
//
//
extern int FasterMA = 5;
extern int FasterShift = 0;
extern int FasterMode = 1;
extern int MediumMA = 21;
extern int MediumShift = 0;
extern int MediumMode = 1;
extern int SlowerMA = 34;
extern int SlowerShift = 0;
extern int SlowerMode = 1;
extern bool showMAs = true;
extern bool crossesOnCurrent = true;
extern bool alertsOn = false;
extern bool alertsMessage = true;
extern bool alertsSound = false;
extern bool alertsEmail = false;
//
//
//
//
//
double CrossUp[];
double CrossDown[];
double CrossWUp[];
double CrossWDown[];
double ma1[];
double ma2[];
double ma3[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int init()
{
SetIndexBuffer(0, CrossUp); SetIndexStyle(0, DRAW_ARROW); SetIndexArrow(0, 233);
SetIndexBuffer(1, CrossDown); SetIndexStyle(1, DRAW_ARROW); SetIndexArrow(1, 234);
SetIndexBuffer(2, CrossWUp); SetIndexStyle(2, DRAW_ARROW); SetIndexArrow(2, 233);
SetIndexBuffer(3, CrossWDown); SetIndexStyle(3, DRAW_ARROW); SetIndexArrow(3, 234);
SetIndexBuffer(4,ma1);
SetIndexBuffer(5,ma2);
SetIndexBuffer(6,ma3);
if (showMAs)
{
SetIndexStyle(4,DRAW_LINE);
SetIndexStyle(5,DRAW_LINE);
SetIndexStyle(6,DRAW_LINE);
SetIndexEmptyValue(4,0.00);
SetIndexEmptyValue(5,0.00);
SetIndexEmptyValue(6,0.00);
}
else
{
SetIndexStyle(4,DRAW_NONE);
SetIndexStyle(5,DRAW_NONE);
SetIndexStyle(6,DRAW_NONE);
}
return(0);
}
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int start()
{
int limit, i;
int counted_bars=IndicatorCounted();
double fasterMAnow, fasterMAprevious;
double mediumMAnow, mediumMAprevious;
double slowerMAnow, slowerMAprevious;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
if (FasterShift < 0) limit = MathMax(limit,-FasterShift);
if (MediumShift < 0) limit = MathMax(limit,-MediumShift);
if (SlowerShift < 0) limit = MathMax(limit,-SlowerShift);
//
//
//
//
//
//
for(i = limit; i >=0; i--)
{
ma1[i] = iMA(NULL, 0, FasterMA, FasterShift, FasterMode, PRICE_CLOSE, i);
ma2[i] = iMA(NULL, 0, MediumMA, MediumShift, MediumMode, PRICE_CLOSE, i);
ma3[i] = iMA(NULL, 0, SlowerMA, SlowerShift, SlowerMode, PRICE_CLOSE, i);
if (crossesOnCurrent==false && i==0) continue;
//
//
//
//
//
fasterMAnow = ma1[i];
fasterMAprevious = ma1[i+1];
mediumMAnow = ma2[i];
mediumMAprevious = ma2[i+1];
slowerMAnow = ma3[i];
slowerMAprevious = ma3[i+1];
//
//
//
//
//
int crossID=0;
double curr;
double prev;
double point;
while (true)
{
if (fasterMAnow > 0 && mediumMAnow > 0)
{
curr = fasterMAnow - mediumMAnow;
prev = fasterMAprevious - mediumMAprevious;
point = (fasterMAnow + fasterMAprevious)/2;
if (curr*prev<=0) { crossID=1; break; }
}
if (fasterMAnow > 0 && slowerMAnow > 0)
{
curr = fasterMAnow - slowerMAnow;
prev = fasterMAprevious - slowerMAprevious;
point = (fasterMAnow + fasterMAprevious)/2;
if (curr*prev<=0) { crossID=2; break; }
}
if (mediumMAnow > 0 && slowerMAnow > 0)
{
curr = mediumMAnow - slowerMAnow;
prev = mediumMAprevious - slowerMAprevious;
point = (mediumMAnow + mediumMAprevious)/2;
if (curr*prev<=0) { crossID=3; break; }
}
break;
}
//
//
//
//
//
CrossUp[i] = EMPTY_VALUE;
CrossDown[i] = EMPTY_VALUE;
CrossWUp[i] = EMPTY_VALUE;
CrossWDown[i] = EMPTY_VALUE;
if (crossID>0)
{
if (alertsOn)
if ((i==0 && crossesOnCurrent==true) || (i==1 && crossesOnCurrent==false))
{
switch (crossID)
{
case 1:
if(curr>0) doAlert("Fast MA crossed Medium MA UP");
else doAlert("Fast MA crossed Medium MA DOWN");
break;
case 2:
if(curr>0) doAlert("Fast MA crossed Slow MA UP");
else doAlert("Fast MA crossed Slow MA DOWN");
break;
case 3:
if(curr>0) doAlert("Medium MA crossed Slow MA UP");
else doAlert("Medium MA crossed Slow MA DOWN");
break;
}
}
//
//
//
//
//
double Range = 0.0;
for (int counter=i ;counter<=i+9;counter++) Range += MathAbs(High[counter]-Low[counter]);
Range /= 10;
//
//
//
//
//
if (i==0)
{
if (curr>0)
CrossWUp[i] = point - Range*0.5;
else CrossWDown[i] = point + Range*0.5;
}
else
{
if (curr>0)
CrossUp[i] = point - Range*0.5;
else CrossDown[i] = point + Range*0.5;
}
}
}
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)," ",doWhat);
if (alertsMessage) Alert(message);
if (alertsEmail) SendMail(StringConcatenate(Symbol(),"3 MA line crossing"),message);
if (alertsSound) 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
---