Price Data Components
Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
MA_Crossover_Alert2[1]
//+------------------------------------------------------------------+
//| MA-Crossover_Alert.mq4 |
//| Copyright © 2005, Jason Robinson (jnrtrading) |
//| http://www.jnrtading.co.uk |
//| Modified by Robert Hill to add LSMA and alert or send email |
//| Added Global LastAlert to try to have alert only on new cross |
//| but does not seem to work. So indicator does alert every bar |
//+------------------------------------------------------------------+
/*
+------------------------------------------------------------------+
| Allows you to enter two ma periods and it will then show you at |
| Which point they crossed over. It is more usful on the shorter |
| periods that get obscured by the bars / candlesticks and when |
| the zoom level is out. Also allows you then to remove the mas |
| from the chart. (emas are initially set at 5 and 6) |
+------------------------------------------------------------------+
*/
#property copyright "Copyright © 2005, Jason Robinson (jnrtrading)"
#property link "http://www.jnrtrading.co.uk"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 FireBrick
extern bool SoundON=true;
extern bool EmailON=false;
extern int FastMA_Mode = 1; //0=sma, 1=ema, 2=smma, 3=lwma, 4=lsma
extern int FastMA_Period = 5;
extern int FastPriceMode = 0;//0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2, 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4
extern int SlowMA_Mode = 1; //0=sma, 1=ema, 2=smma, 3=lwma, 4=lsma
extern int SlowMA_Period = 13;
extern int SlowPriceMode = 0;//0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2, 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4
double CrossUp[];
double CrossDown[];
int flagval1 = 0;
int flagval2 = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_ARROW, EMPTY, 1);
SetIndexArrow(0, 233);
SetIndexBuffer(0, CrossUp);
SetIndexStyle(1, DRAW_ARROW, EMPTY, 1);
SetIndexArrow(1, 234);
SetIndexBuffer(1, CrossDown);
GlobalVariableSet("AlertTime"+Symbol()+Period(),CurTime());
GlobalVariableSet("SignalType"+Symbol()+Period(),OP_SELLSTOP);
// GlobalVariableSet("LastAlert"+Symbol()+Period(),0);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
GlobalVariableDel("AlertTime"+Symbol()+Period());
GlobalVariableDel("SignalType"+Symbol()+Period());
// GlobalVariableDel("LastAlert"+Symbol()+Period());
//----
return(0);
}
//+------------------------------------------------------------------+
//| LSMA with PriceMode |
//| PrMode 0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2, |
//| 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4 |
//+------------------------------------------------------------------+
double LSMA(int Rperiod, int prMode, int shift)
{
int i;
double sum, pr;
int length;
double lengthvar;
double tmp;
double wt;
length = Rperiod;
sum = 0;
for(i = length; i >= 1 ; i--)
{
lengthvar = length + 1;
lengthvar /= 3;
tmp = 0;
switch (prMode)
{
case 0: pr = Close[length-i+shift];break;
case 1: pr = Open[length-i+shift];break;
case 2: pr = High[length-i+shift];break;
case 3: pr = Low[length-i+shift];break;
case 4: pr = (High[length-i+shift] + Low[length-i+shift])/2;break;
case 5: pr = (High[length-i+shift] + Low[length-i+shift] + Close[length-i+shift])/3;break;
case 6: pr = (High[length-i+shift] + Low[length-i+shift] + Close[length-i+shift] + Close[length-i+shift])/4;break;
}
tmp = ( i - lengthvar)*pr;
sum+=tmp;
}
wt = sum*6/(length*(length+1));
return(wt);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start() {
int limit, i, counter;
double tmp=0;
double fastMAnow, slowMAnow, fastMAprevious, slowMAprevious;
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;
for(i = 0; i <= limit; i++) {
counter=i;
Range=0;
AvgRange=0;
for (counter=i ;counter<=i+9;counter++)
{
AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
}
Range=AvgRange/10;
if (FastMA_Mode == 4)
{
fastMAnow = LSMA(FastMA_Period, FastPriceMode, i);
fastMAprevious = LSMA(FastMA_Period, FastPriceMode, i+1);
}
else
{
fastMAnow = iMA(NULL, 0, FastMA_Period, 0, FastMA_Mode, FastPriceMode, i);
fastMAprevious = iMA(NULL, 0, FastMA_Period, 0, FastMA_Mode, FastPriceMode, i+1);
}
if (SlowMA_Mode == 4)
{
slowMAnow = LSMA( SlowMA_Period, SlowPriceMode, i);
slowMAprevious = LSMA( SlowMA_Period, SlowPriceMode, i+1);
}
else
{
slowMAnow = iMA(NULL, 0, SlowMA_Period, 0, SlowMA_Mode, SlowPriceMode, i);
slowMAprevious = iMA(NULL, 0, SlowMA_Period, 0, SlowMA_Mode, SlowPriceMode, i+1);
}
if ((fastMAnow > slowMAnow) && (fastMAprevious < slowMAprevious))
{
if (i == 1 && flagval1==0){ flagval1=1; flagval2=0; }
CrossUp[i] = Low[i] - Range*0.75;
}
else if ((fastMAnow < slowMAnow) && (fastMAprevious > slowMAprevious))
{
if (i == 1 && flagval2==0) { flagval2=1; flagval1=0; }
CrossDown[i] = High[i] + Range*0.75;
}
}
if (flagval1==1 && CurTime() > GlobalVariableGet("AlertTime"+Symbol()+Period()) && GlobalVariableGet("SignalType"+Symbol()+Period())!=OP_BUY)
{
// if (GlobalVariableGet("LastAlert"+Symbol()+Period()) < 0.5)
// {
if (SoundON) Alert("BUY signal at Ask=",Ask,"\n Bid=",Bid,"\n Time=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
if (EmailON) SendMail("BUY signal alert","BUY signal at Ask="+DoubleToStr(Ask,4)+", Bid="+DoubleToStr(Bid,4)+", Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
// }
tmp = CurTime() + (Period()-MathMod(Minute(),Period()))*60;
GlobalVariableSet("AlertTime"+Symbol()+Period(),tmp);
GlobalVariableSet("SignalType"+Symbol()+Period(),OP_SELL);
// GlobalVariableSet("LastAlert"+Symbol()+Period(),1);
}
if (flagval2==1 && CurTime() > GlobalVariableGet("AlertTime"+Symbol()+Period()) && GlobalVariableGet("SignalType"+Symbol()+Period())!=OP_SELL) {
// if (GlobalVariableGet("LastAlert"+Symbol()+Period()) > -0.5)
// {
if (SoundON) Alert("SELL signal at Ask=",Ask,"\n Bid=",Bid,"\n Date=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
if (EmailON) SendMail("SELL signal alert","SELL signal at Ask="+DoubleToStr(Ask,4)+", Bid="+DoubleToStr(Bid,4)+", Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
// }
tmp = CurTime() + (Period()-MathMod(Minute(),Period()))*60;
GlobalVariableSet("AlertTime"+Symbol()+Period(),tmp);
GlobalVariableSet("SignalType"+Symbol()+Period(),OP_BUY);
// GlobalVariableSet("LastAlert"+Symbol()+Period(),-1);
}
return(0);
}
CÛ hëáxc osãlý5PÛ Ëa¬
h osãl=XÛ bìR³xc osãl÷³XÛ A'Y osãl6`Û <í0Ú¢ osãlcÛ °òäxc osãl~ÈvÛ *Ñ{¢ osãl!Û}Û dð*
h osãlI~Û #
Dxc osãl¿±Û µOZNxc osãl
Û ?×9 osãlM
Û f¢¯¨
h osãlxÛ {ÚGÕ9 osãlÒÛ
ôÂ` osãlÛ ßgÂ
h osãlý
¦Û z4©o osãl×«Û ±Úg!xc osãlÚÛ Äsn, osãly°®Û ç
xxc osãlv(ºÛ òt+·o osãlD]»Û
ör osãl&ÁÛ É9 osãlÝuÄÛ Ñ©9 osãlQnÈÛ Ù
h osãl1NÊÛ Ãÿ'¢ osãl]ÒÛ v:vo osãlGwÔÛ k Cxc osãlàÛ Ø"¯·
h osãl¡âÛ u¾
h osãl~ýãÛ =ubI< osãlºFéÛ üÉýpD osãlÛôÛ U[~xc osãlÜ ÒÂ` osãlµ¯Ü Èf'9 osãlÍÜ W1xc osãlELÜ @Gxc osãl¨dÜ f#j¢ osãl¿"Ü ¯§"Xxc osãl7$Ü [/
h osãl@&#Ü ºo*ïÂ` osãlq$Ü K¿ÎÉ9 osãlÜ$Ü x/
h osãlùÚ%Ü :¨?Â` osãlùÚ%Ü ¶ëOÂ` osãlL!*Ü LÃr osãlD ,Ü F`mxc osãl'6.Ü {~7xc osãl"3Ü Qè³>r osãlÌ<Ü ³)c0, osãlZn>Ü ¦¶Î:Â` osãlZ?Ü ¼åÿ1r osãlq_EÜ 3×â&
h osãlq_EÜ ;Ç
h osãlöVÜ L§/gÜ osãlÖXÜ úxc osãlÌ^Ü C=*÷¢ osãlýybÜ Ekéxc osãlXcÜ Ba e]f osãlõqÜ a¤ZÉ osãlõqÜ hÐBHÉ osãlqAsÜ J"¨r osãlEsÜ /Uxc osãlCsÜ ÖYxc osãlɸÜ
h|o osãlÜ ÃXxc osãlqNÜ 0¬4VÍP osãlÒ5Ü (<«o osãl¡FÜ ¤j²zxc osãlg¤Ü Uª¢ osãlª£Ü ¾*Îxc osãlǦÜ
¥½Á osãl)#§Ü ¿9 osãlA£®Ü Cëo osãl%K±Ü ÿÍ osãlç±Ü
ìVᢠosãl`ÖÆÜ v^Bl osãløùÇÜ PáÒD
h osãlÜÉÜ ª5èá9 osãl¥ÎÜ ö[{Û
h osãl§ØÜ m
Uo osãlôâÜ ¸&³
h osãlgçÜ ê:èr osãløèÜ BÏÊõxc osãlªíÜ !ÓBÚxc osãlìèîÜ ôÉxc osãlìèîÜ ù aïxc osãlUïÜ Çàxc osãlhöÜ ^þO&6_ osãlhöÜ ð¯6_ osãlhöÜ qÜ6_ osãlhöÜ Îú¹6_ osãlùùÜ yÔr osãl£úÜ «¤(xc osãlH Ý n8°9 osãl\NÝ Y«xc osãlÆÝ ä´o osãl;[ Ý í°Ýo osãl°Ý YûMxc osãlÃÝ oÐá osãlßÝ ÝN¢Èh osãlÇÝ
ðzúxc osãlÚvÝ B¤r osãlh´ Ý ÇC|Wo osãlf$Ý [ 9 osãlY'Ý äT øxc osãln(Ý ^¿½ÄÂ` osãl§á+Ý $Z8o osãlfe,Ý HÍôuxc osãlÕ6Ý T¯p5Â` osãl@Ý }K±xc osãlèÝJÝ ÂÔåIxc osãlåÏLÝ ¶@mxc osãlÐENÝ
àJ"xc osãl~SÝ ¹w¢ osãlÄÂWÝ c½xc osãlÜ¢ZÝ hÔÍo osãl_Ý »
9 osãlEqfÝ Þ'¶ÍP osãlÕlÝ óðâø¾ osãlnÝ &ëv+ osãl{Ý Ò6ôÀxc osãlÝ /äæë¢ osãlj3Ý !²Pþ
h osãl èÝ ¨ §
h osãlu²Ý ss
h osãlñ^ Ý »¤Bxc osãlê Ý æIr osãlæõ¢Ý !Ⱦ¢ osãlF"µÝ iDÐxc osãl¯Á·Ý 2oSxc osãl
í·Ý dzF¬
h osãlz8¼Ý ¥Ë1xc osãlÇs½Ý à¨|¬ osãlöÄÝ á2[ osãlVyÆÝ ; osãl
àÈÝ l'vaÂ` osãl«¨ÊÝ a¯ñxc osãl=ÌÝ MÚon
h osãlÞÝ ?"ä
h osãlVÕÞÝ î!ã2
h osãld éÝ Fxc osãlëíÝ Ë~ñExc osãl}ôùÝ wbdxc osãlû Þ @ <¢ osãløÆ
Þ ¼SHz
h osãl> Þ é~NÔX osãlÑÞ {cÖT9 osãl°qÞ Ï/;Èh osãlç Þ VÇÍP osãl,í#Þ ÷ÍÉ osãl,)-Þ Q
ª
h osãlJ0Þ ¹4zxc osãl
¡8Þ â3T osãlë;Þ bÙÅm
h osãlNYAÞ ÙoWxc osãlRÞ ã*ÓK osãl7°RÞ f>9 osãl0ðZÞ ,C2¯r osãl0ðZÞp Ѥßr osãl âeÞ 8Tç¬xc osãll*lÞ ~]¸
h osãl°mÞ óWöá osãluuÞ ,Û osãl=wÞ ô
ô}xc osãlvvÞ Ýp®
h osãlùÓÞ 8KÂ` osãlÕÞ Y×xc osãl"Þ n>Ho osãlÜÞ ¡;A®Â` osãl"Þ r1Õ9 osãlzªÞ _&úÛ osãlâBµÞ £+Á osãlý¸Þ 8fxc osãlÿaºÞ Ë#¶>¢ osãlw÷¾Þ o<4
h osãl3ÅÞ ô-á osãlÌÒÞ Y_+Èh osãl@kÔÞ ÷×EÓI osãlÿFÛÞ DØ
h osãlÝÛÞ
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
---