Please help. MQL5 EA sendmail function sends me repeat emails on every tick, how to make it send me an email only once per closed deal?
You can save your last deal time to a static datetime variable. Then you can check if your last order time should be greater than that time.
// In Global Scope static datetime lastdealtime = 0; if(deal_entry==DEAL_ENTRY_OUT && deal_time>lastdealtime){ counter++; string time=TimeToString((datetime)deal_time,TIME_DATE|TIME_MINUTES|TIME_SECONDS); SendMail(__FILE__, Symbol()+",OnTick $ "+DoubleToString(deal_commission+deal_swap+deal_profit,2)); lastdealtime = deal_time; if(counter==lastdeal){ m_from_date=(datetime)deal_time; break; }
Also you can do it in another way. Any Trade event happen it trigger OnTrade() function.
- www.mql5.com
You can save your last deal time to a static datetime variable. Then you can check if your last order time should be greater than that time.
Also you can do it in another way. Any Trade event happen it trigger OnTrade() function.
Thank you for the response, i will give this a try.
Also, how would i go about doing it using the OnTradeTransaction() function and would that be an easier way?
You can save your last deal time to a static datetime variable. Then you can check if your last order time should be greater than that time.
Also you can do it in another way. Any Trade event happen it trigger OnTrade() function.
I tried this and when compiled i have a warning that says "possible loss of data due to type conversion from 'long' to 'datetime'" and the warning is from: lastdealtime = deal_time;
would it be okay to run the EA with that warning?
You can save your last deal time to a static datetime variable. Then you can check if your last order time should be greater than that time.
Also you can do it in another way. Any Trade event happen it trigger OnTrade() function.
You can save your last deal time to a static datetime variable. Then you can check if your last order time should be greater than that time.
Also you can do it in another way. Any Trade event happen it trigger OnTrade() function.
Two lines later you force the cast of ling and datetime just do it again:
lastdealtime = (datetime) deal_time; if(counter==lastdeal){ m_from_date=(datetime)deal_time; break; }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey MQL5 community, i have a problem with my expert advisor as you have seen in my subject.
I put the sendmail function in the body of the ontick function to receive emails of the last deals symbol and profit/loss $ amount, but my problem is my EA sends me repeating emails on every new tick.
Can anyone help point me in the right direction on how to make my EA send me a email only once per closed deal?
Here is the code that i've placed in the body of the ontick function: