You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Thanks guys,
Sorry for all the trouble. Really know nuts about programming and I took it at face value that CONDITION MEANT CONDITION
'alert.allowed' - variable not defined C:\Program Files\MetaTrader 4 at FOREX.com - Copy\experts\indicators\###Price Crosses MA (Alert).mq4 (98, 81)
I got this
How would I define the variable?
Should I add:
int alert.allowed=0;
??
I tried adding this at the beginning:
But i still get alerts every touch
int alert.allowed;
and at the alert portion I changed it to this:
ma = iMA(Symbol(), Period(), MA_Period, 0, MA_Type, PRICE_CLOSE, 0);
if (Close[0] >= ma + (Crossed_Pips * Point) && state != 1 && CurTime() >= alert.allowed) {
alert.allowed = Time[0] + Period(); // No more alerts this bar
//alert.allowed = CurTime() + 5*60; // No more alerts for 5 minutes
Alert("150EMA Touched " + Symbol() + " TF " + Period() + " Date " + TimeToStr(iTime(NULL, 0, 0) | 2));
SendMail("150EMA Touched " + Symbol() + " TF " + Period() + " Date " + TimeToStr(iTime(NULL, 0, 0) | 2),"H: " + iHigh(NULL, 0, 0) + " L: " + iLow(NULL, 0, 0) + " C: " + iClose(NULL, 0, 0));
}else if (Close[0] <= ma - (Crossed_Pips * Point) && state != -1 && CurTime() >= alert.allowed) {
alert.allowed = Time[0] + Period(); // No more alerts this bar
//alert.allowed = CurTime() + 5*60; // No more alerts for 5 minutes
Alert("150EMA Touched " + Symbol() + " TF " + Period() + " Date " + TimeToStr(iTime(NULL, 0, 0) | 2));
SendMail("150EMA Touched " + Symbol() + " TF " + Period() + " Date " + TimeToStr(iTime(NULL, 0, 0) | 2),"H: " + iHigh(NULL, 0, 0) + " L: " + iLow(NULL, 0, 0) + " C: " + iClose(NULL, 0, 0));
}
return(0);
}
Err as you guys suggested: I put in some leg work but did not get it working.
I tried this code but when I add the indicator to the chart, it alerts me immediately no matter whether price has hit the EMA or not and following that it never alerts again.
How can I make it not alert me everytime I add it to a new chart or change the time frame and alert only once and once it alerts, it will stop alerting till I delete and re add the indicator back to the chart?
Please assist:
//+------------------------------------------------------------------+
//| MA Cross Arrows.mq4 |
//| Copyright © 2006 Scorpion@fxfisherman.com |
//+------------------------------------------------------------------+
#property copyright "FxFisherman.com"
#property link "http://www.fxfisherman.com"
//Crossed_Pips: If you want to delay until price has crossed x pips from MA, set it to x. Set to 0 for instant alert.
//MA_Type: Moving Average Type. 0 = Simple, 1 = Exponential, 2 = Smooth, 3 = Weighted
//MA_Period: Moving Average Period (bars).
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Wheat
#property indicator_color2 White
#property indicator_color3 Red
extern int Crossed_Pips = 0;
extern int MA_Period = 5;
extern int MA_Type = 1;
extern int Shift_Bars=0;
extern int Bars_Count= 1000;
int state;
//---- buffers
double v1[];
double v2[];
double v3[];
int AlreadyAlertedFlag = false;
int init()
{
IndicatorBuffers(3);
SetIndexArrow(0,217);
SetIndexStyle(0,DRAW_ARROW,STYLE_SOLID,1);
SetIndexDrawBegin(1,MA_Period * 2);
SetIndexBuffer(0, v1);
SetIndexLabel(0,"Buy");
SetIndexArrow(1,218);
SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID,1);
SetIndexDrawBegin(1,MA_Period * 2);
SetIndexBuffer(1, v2);
SetIndexLabel(1,"Sell");
SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1);
SetIndexDrawBegin(1,MA_Period * 2);
SetIndexBuffer(2, v3);
SetIndexLabel(2,"MA");
watermark();
return(0);
}
int start()
{
double ma;
int previous;
int i;
int shift;
bool crossed_up, crossed_down;
int totalBars = Bars - (MA_Period * 2);
if (Bars_Count > 0 && Bars_Count <= totalBars)
{
i = Bars_Count;
}else if(totalBars <= 0 ) {
return(0);
}else{
i = totalBars;
}
while(i>=0)
{
shift = i + Shift_Bars;
ma = iMA(Symbol(), Period(), MA_Period, 0, MA_Type, PRICE_CLOSE, shift);
crossed_up = High[shift] >= (ma + (Crossed_Pips * Point));
crossed_down = Low[shift] <= (ma - (Crossed_Pips * Point));
v1[i] = NULL;
v2[i] = NULL;
v3[i] = ma;
if (crossed_up && previous != 1) {
v1[i] = ma + (Crossed_Pips * Point);
previous = 1;
}else if(crossed_down && previous != 2){
v2[i] = ma - (Crossed_Pips * Point);
previous = 2;
}
i--;
}
ma = iMA(Symbol(), Period(), MA_Period, 0, MA_Type, PRICE_CLOSE, 0);
if (Close[0] >= ma + (Crossed_Pips * Point) && state != 1 && AlreadyAlertedFlag == false){
Alert("150EMA Touched " + Symbol() + " TF " + Period() + " Date " + TimeToStr(iTime(NULL, 0, 0) | 2));
SendMail("150EMA Touched " + Symbol() + " TF " + Period() + " Date " + TimeToStr(iTime(NULL, 0, 0) | 2),"H: " + iHigh(NULL, 0, 0) + " L: " + iLow(NULL, 0, 0) + " C: " + iClose(NULL, 0, 0));
AlreadyAlertedFlag = true;
}else if (Close[0] <= ma - (Crossed_Pips * Point) && state != -1 && AlreadyAlertedFlag == false){
Alert("150EMA Touched " + Symbol() + " TF " + Period() + " Date " + TimeToStr(iTime(NULL, 0, 0) | 2));
SendMail("150EMA Touched " + Symbol() + " TF " + Period() + " Date " + TimeToStr(iTime(NULL, 0, 0) | 2),"H: " + iHigh(NULL, 0, 0) + " L: " + iLow(NULL, 0, 0) + " C: " + iClose(NULL, 0, 0));
AlreadyAlertedFlag = true;
}
return(0);
}
//+------------------------------------------------------------------+
void watermark()
{
ObjectCreate("fxfisherman", OBJ_LABEL, 0, 0, 0);
ObjectSetText("fxfisherman", "fxfisherman.com", 11, "Lucida Handwriting", RoyalBlue);
ObjectSet("fxfisherman", OBJPROP_CORNER, 2);
ObjectSet("fxfisherman", OBJPROP_XDISTANCE, 5);
ObjectSet("fxfisherman", OBJPROP_YDISTANCE, 10);
return(0);
}
Anyone can help on this instead as the coding I tried to do screws up the signals .. not too sure why ...
ma = iMA(Symbol(), Period(), MA_Period, 0, MA_Type, PRICE_CLOSE, 0);
if (Close[0] >= ma + (Crossed_Pips * Point) && state != 1 && AlreadyAlertedFlag == false){
//Alert("150EMA Touched " + Symbol() + " TF " + Period() + " Date " + TimeToStr(iTime(NULL, 0, 0) | 2));
//SendMail("150EMA Touched " + Symbol() + " TF " + Period() + " Date " + TimeToStr(iTime(NULL, 0, 0) | 2),"H: " + iHigh(NULL, 0, 0) + " L: " + iLow(NULL, 0, 0) + " C: " + iClose(NULL, 0, 0));
AlreadyAlertedFlag = true;
}else if (Close[0] <= ma - (Crossed_Pips * Point) && state != -1 && AlreadyAlertedFlag == false){
//Alert("150EMA Touched " + Symbol() + " TF " + Period() + " Date " + TimeToStr(iTime(NULL, 0, 0) | 2));
//SendMail("150EMA Touched " + Symbol() + " TF " + Period() + " Date " + TimeToStr(iTime(NULL, 0, 0) | 2),"H: " + iHigh(NULL, 0, 0) + " L: " + iLow(NULL, 0, 0) + " C: " + iClose(NULL, 0, 0));
AlreadyAlertedFlag = true;
put // before (Alert) and if u want also before (SendMail)
that's all
Errr I want it to alert me on first touch of the EMA.
If I put // before the alert and sendmail, it will not have any alerts right?
But the problem is that it keeps alerting me every pip it touches the EMA.
Can I make it so that it alerts only once?
I tried using Already alerted flag = true but I am not sure why when I attached the indicator to the chart, it immediately alerts once even if price is 10000 pips away from the EMA
Anyone?