Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hi all,
I'm trying to get alert once 20SMA and 50SMA meet or crossover each other
and I modified existing code and applied it. I can get a "BUY" alert correctly, but "SELL" alert is not working.
I attached current my code here. Could you anyone help me why "SELL" alert is not triggered?
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int limit=Bars-counted_bars;
if (limit<0) limit=0;
// define MAs values
for (int i=limit; i>=0; i--)
{
Fast[i]=iMA(NULL, 0, Fast_MA_Period, Fast_MA_Shift, Fast_MA_Method, Fast_MA_Apply, i);
Slow[i]=iMA(NULL, 0, Slow_MA_Period, Slow_MA_Shift, Slow_MA_Method, Slow_MA_Apply, i);
}
// Alert
{
// buy alert
if ((New_Candle() && Fast[0] > Slow[0] && Fast[1] <= Slow[1]))
{
if (ScreenAlert) Alert("BUY - "+Symbol()," | ",TimeToStr(CurTime(),TIME_DATE)," | ",TimeHour(CurTime()),":",TimeMinute(CurTime())," | Period=",Period());
if (PushAlert) SendNotification("BUY -"+Symbol());
}
// sell alert
if ((New_Candle() && Fast[0] < Slow[0] && Fast[1] >= Slow[1]))
{
if (ScreenAlert) Alert("SELL - "+Symbol()," | ",TimeToStr(CurTime(),TIME_DATE)," | ",TimeHour(CurTime()),":",TimeMinute(CurTime())," | Period=",Period());
if (PushAlert) SendNotification("SELL - "+Symbol());
}
}
return(0);
}