Hi Respected Members I need a help ..... i am a trader and i have a Expert Advisor code actually its a code about trades signals for telegram if i plase a trade than my clints can follow them but i have a littile problem i apply this code to all my opende charts and when i take a trade than all chart sending msgs signals like bellow image i want it send only 1 msg signal thanx in advance
Here is the code
//+------------------------------------------------------------------+
//| ai_tester_strategy.mq4 |
//| Aleksandr M |
//| https://tmsrv.pw |
//+------------------------------------------------------------------+
#property copyright "Aleksandr M"
#property link "https://tmsrv.pw"
#property version "1.03"
#property strict
//Do not forget to add url( https://tmsrv.pw/send ) to Allowed:
//Metatrader->Tols->Options->Expert Advisors
extern string _token = "-10013588388a05b";
int OnInit(){
if(_token == "") {
MessageBox(" Set token ");
return(INIT_FAILED);
}
//int ticket = OrderSend(Symbol(),OP_SELL,0.01,Bid,3,Bid+50*Point,Bid-50*Point,"",0);// for testing
return(INIT_SUCCEEDED);
}
datetime _opened_last_time = TimeCurrent() ;
datetime _closed_last_time = TimeCurrent() ;
void OnTick(){
string message = "";
int total=OrdersTotal();
datetime max_time = 0;
double day_profit = 0;
for(int pos=0;pos<total;pos++){ // Current orders -----------------------
if(OrderSelect(pos,SELECT_BY_POS)==false) continue;
if(OrderOpenTime() <= _opened_last_time) continue;
message += StringFormat(
"----OPEN ORDER----\r\n%s %s lots \r\n%s @ %s \r\nTP - %s\r\n----------------------\r\n",
order_type(),
DoubleToStr(OrderLots(),2),
OrderSymbol(),
DoubleToStr(OrderOpenPrice(),MarketInfo(OrderSymbol(),MODE_DIGITS)),
DoubleToStr(OrderTakeProfit(),MarketInfo(OrderSymbol(),MODE_DIGITS))
);
max_time = MathMax(max_time,OrderOpenTime());
}
_opened_last_time = MathMax(max_time,_opened_last_time);
max_time = 0;
bool is_closed = false;
total = OrdersHistoryTotal();
for(int pos=0;pos<total;pos++) { // History orders-----------------------
if(OrderSelect(pos,SELECT_BY_POS,MODE_HISTORY)==false) continue;
if( OrderCloseTime() > iTime(NULL,1440,0)) { // PIPS profit for today
day_profit += order_pips();
}
if(OrderCloseTime() <= _closed_last_time) continue;
printf(OrderCloseTime());
is_closed = true;
message += StringFormat("",
order_type(),
DoubleToStr(OrderLots(),2),
OrderSymbol(),
DoubleToStr(OrderOpenPrice(),MarketInfo(OrderSymbol(),MODE_DIGITS)),
DoubleToStr(OrderClosePrice(),MarketInfo(OrderSymbol(),MODE_DIGITS)),
DoubleToStr(OrderTakeProfit(),MarketInfo(OrderSymbol(),MODE_DIGITS)),
DoubleToStr(order_pips(),1)
);
max_time = MathMax(max_time,OrderCloseTime());
}
_closed_last_time = MathMax(max_time,_closed_last_time);
if(StringLen(message) > 0) {
if(is_closed) message += StringFormat("Total Profit today: %s PIPS",DoubleToStr(day_profit,1));
printf(message);
if(!tms_send(message,_token) ) {
//error handling
}
}
}
double order_pips() {
double pips;
if(OrderType() == OP_BUY) {
pips = (OrderClosePrice()-OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT);
} else {
pips = (OrderOpenPrice()-OrderClosePrice())/MarketInfo(OrderSymbol(),MODE_POINT);
}
return pips/10;
}
string order_type_to_str(int type)
{
return StringSubstr(EnumToString((ENUM_ORDER_TYPE)type), 11);
}
string order_type () {
return order_type_to_str(OrderType());
if(OrderType() == OP_BUY) return "BUY";
if(OrderType() == OP_SELL) return "SELL";
if(OrderType() == OP_BUYLIMIT) return "BUYLIMIT";
if(OrderType() == OP_SELLLIMIT) return "SELLLIMIT";
if(OrderType() == OP_BUYSTOP) return "BUYSTOP";
if(OrderType() == OP_SELLSTOP) return "SELLSTOP";
return "{err}";
}
datetime _tms_last_time_messaged;
bool tms_send(string message, string token="{YOUR_TOKEN_HERE}"){ // You can set token here for simply usage tms_send("you message");
const string url = "https://tmsrv.pw/send/v1";
string response,headers;
int result;
char post[],res[];
if(IsTesting() || IsOptimization()) return true;
if(_tms_last_time_messaged > TimeCurrent()) return false; // do not send twice at the same candle;
string spost = StringFormat("message=%s&token=%s&code=MQL",message,token);
ArrayResize(post,StringToCharArray(spost,post,0,WHOLE_ARRAY,CP_UTF8)-1);
result = WebRequest("POST",url,"",NULL,3000,post,ArraySize(post),res,headers);
_tms_last_time_messaged = TimeCurrent() + 1;
if(result==-1) { // WebRequest filed
if(GetLastError() == 4060) {
printf("tms_send() | Add the address %s in the list of allowed URLs on tab 'Expert Advisors'",url);
} else {
printf("tms_send() | webrequest filed - error № %i", GetLastError());
}
return false;
} else {
response = CharArrayToString(res,0,WHOLE_ARRAY);
if(StringFind(response,""ok":true")==-1) { // check server response
printf("tms_send() return an error - %s",response);
return false;
}
}
Sleep(1000); //to prevent sending more than 1 message per seccond
return true;
}
and here is the image
Here is the code
//+------------------------------------------------------------------+
//| ai_tester_strategy.mq4 |
//| Aleksandr M |
//| https://tmsrv.pw |
//+------------------------------------------------------------------+
#property copyright "Aleksandr M"
#property link "https://tmsrv.pw"
#property version "1.03"
#property strict
//Do not forget to add url( https://tmsrv.pw/send ) to Allowed:
//Metatrader->Tols->Options->Expert Advisors
extern string _token = "-10013588388a05b";
int OnInit(){
if(_token == "") {
MessageBox(" Set token ");
return(INIT_FAILED);
}
//int ticket = OrderSend(Symbol(),OP_SELL,0.01,Bid,3,Bid+50*Point,Bid-50*Point,"",0);// for testing
return(INIT_SUCCEEDED);
}
datetime _opened_last_time = TimeCurrent() ;
datetime _closed_last_time = TimeCurrent() ;
void OnTick(){
string message = "";
int total=OrdersTotal();
datetime max_time = 0;
double day_profit = 0;
for(int pos=0;pos<total;pos++){ // Current orders -----------------------
if(OrderSelect(pos,SELECT_BY_POS)==false) continue;
if(OrderOpenTime() <= _opened_last_time) continue;
message += StringFormat(
"----OPEN ORDER----\r\n%s %s lots \r\n%s @ %s \r\nTP - %s\r\n----------------------\r\n",
order_type(),
DoubleToStr(OrderLots(),2),
OrderSymbol(),
DoubleToStr(OrderOpenPrice(),MarketInfo(OrderSymbol(),MODE_DIGITS)),
DoubleToStr(OrderTakeProfit(),MarketInfo(OrderSymbol(),MODE_DIGITS))
);
max_time = MathMax(max_time,OrderOpenTime());
}
_opened_last_time = MathMax(max_time,_opened_last_time);
max_time = 0;
bool is_closed = false;
total = OrdersHistoryTotal();
for(int pos=0;pos<total;pos++) { // History orders-----------------------
if(OrderSelect(pos,SELECT_BY_POS,MODE_HISTORY)==false) continue;
if( OrderCloseTime() > iTime(NULL,1440,0)) { // PIPS profit for today
day_profit += order_pips();
}
if(OrderCloseTime() <= _closed_last_time) continue;
printf(OrderCloseTime());
is_closed = true;
message += StringFormat("",
order_type(),
DoubleToStr(OrderLots(),2),
OrderSymbol(),
DoubleToStr(OrderOpenPrice(),MarketInfo(OrderSymbol(),MODE_DIGITS)),
DoubleToStr(OrderClosePrice(),MarketInfo(OrderSymbol(),MODE_DIGITS)),
DoubleToStr(OrderTakeProfit(),MarketInfo(OrderSymbol(),MODE_DIGITS)),
DoubleToStr(order_pips(),1)
);
max_time = MathMax(max_time,OrderCloseTime());
}
_closed_last_time = MathMax(max_time,_closed_last_time);
if(StringLen(message) > 0) {
if(is_closed) message += StringFormat("Total Profit today: %s PIPS",DoubleToStr(day_profit,1));
printf(message);
if(!tms_send(message,_token) ) {
//error handling
}
}
}
double order_pips() {
double pips;
if(OrderType() == OP_BUY) {
pips = (OrderClosePrice()-OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT);
} else {
pips = (OrderOpenPrice()-OrderClosePrice())/MarketInfo(OrderSymbol(),MODE_POINT);
}
return pips/10;
}
string order_type_to_str(int type)
{
return StringSubstr(EnumToString((ENUM_ORDER_TYPE)type), 11);
}
string order_type () {
return order_type_to_str(OrderType());
if(OrderType() == OP_BUY) return "BUY";
if(OrderType() == OP_SELL) return "SELL";
if(OrderType() == OP_BUYLIMIT) return "BUYLIMIT";
if(OrderType() == OP_SELLLIMIT) return "SELLLIMIT";
if(OrderType() == OP_BUYSTOP) return "BUYSTOP";
if(OrderType() == OP_SELLSTOP) return "SELLSTOP";
return "{err}";
}
datetime _tms_last_time_messaged;
bool tms_send(string message, string token="{YOUR_TOKEN_HERE}"){ // You can set token here for simply usage tms_send("you message");
const string url = "https://tmsrv.pw/send/v1";
string response,headers;
int result;
char post[],res[];
if(IsTesting() || IsOptimization()) return true;
if(_tms_last_time_messaged > TimeCurrent()) return false; // do not send twice at the same candle;
string spost = StringFormat("message=%s&token=%s&code=MQL",message,token);
ArrayResize(post,StringToCharArray(spost,post,0,WHOLE_ARRAY,CP_UTF8)-1);
result = WebRequest("POST",url,"",NULL,3000,post,ArraySize(post),res,headers);
_tms_last_time_messaged = TimeCurrent() + 1;
if(result==-1) { // WebRequest filed
if(GetLastError() == 4060) {
printf("tms_send() | Add the address %s in the list of allowed URLs on tab 'Expert Advisors'",url);
} else {
printf("tms_send() | webrequest filed - error № %i", GetLastError());
}
return false;
} else {
response = CharArrayToString(res,0,WHOLE_ARRAY);
if(StringFind(response,""ok":true")==-1) { // check server response
printf("tms_send() return an error - %s",response);
return false;
}
}
Sleep(1000); //to prevent sending more than 1 message per seccond
return true;
}
and here is the image
FX Trader