I don't know where you got this code, but that code is a mess...
Here is a solution:
#include <Arrays\\ArrayLong.mqh> CArrayLong ordersSent; void check_for_Position(const string symbol) { double MA200_previous = iMA(symbol,0,200,0,MODE_EMA,PRICE_CLOSE,1); //200 EMA double MA50_previous = iMA(symbol,0,50,0,MODE_EMA,PRICE_CLOSE,1); //50 EMA //--- Loop trough running orders for(int i = OrdersTotal()-1; i >= 0; i--) { if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { continue; } //Select Order if(OrderSymbol() != Symbol()) { continue; } //Only current Symbol if(OrderType() == OP_BUY && MA50_previous < MA200_previous) //Buy order check EMA cross { if(ordersSent.Search(OrderTicket() != -1)) { continue; } //Check if already sent if(SendMail("Close " + Symbol() + " Buy", "Time to close the Buy_5M @" + DoubleToString(Bid, (int)MarketInfo(symbol, MODE_DIGITS)))) //Send Mail { ordersSent.Add(OrderTicket()); } } else if(OrderType() == OP_SELL && MA50_previous > MA200_previous) //Sell order check EMA cross { if(ordersSent.Search(OrderTicket() != -1)) { continue; } //Check if already sent if(SendMail("Close " + Symbol() + " Sell", "Time to close the Sell_5M @" + DoubleToString(Bid, (int)MarketInfo(symbol, MODE_DIGITS)))) //Send Mail { ordersSent.Add(OrderTicket()); } } } //--- Delet closed orders from list for(int i = ordersSent.Total()-1; i >= 0; i--) { if(!OrderSelect((int)ordersSent.At(i), SELECT_BY_TICKET, MODE_TRADES)) { ordersSent.Delete(i); } } }//End of check_for_Position
CODE IS NOT TESTED!
It's just a quick solution!
Code can be improved more. (f.e. search for closed orders)
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
I am facing a difficulty in sending an alert mail when a certain condition is met.
I want it as an alert mail for the manual trading so that I am with the trend . This mail has to be only once when MA50 is above MA200 for sell position and viceversa.
I have done workaround with the Ordermodify ().
Can anyone suggest a modification to the Code?