//+------------------------------------------------------------------+ //| ai_tester_strategy.mq4 | //| Aleksandr M | //| https://tmsrv.pw | //+------------------------------------------------------------------+ #property copyright "Aleksandr M" #property link "https://tmsrv.pw" #property version "1.02" #property strict //Do not forget to add url( https://tmsrv.pw/send ) to Allowed: //Metatrader->Tols->Options->Expert Advisors //Demo for MrPhu from https://www.forexfactory.com/showthread.php?p=11523071#post11523071 extern string _token = ""; int OnInit(){ if(_token == "") { MessageBox(" Set token "); return(INIT_FAILED); } 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 iTime(NULL,1440,0)) { day_profit += order_pips(); } if(OrderSelect(pos,SELECT_BY_POS,MODE_HISTORY)==false) continue; if(OrderCloseTime() <= _closed_last_time) continue; printf(OrderCloseTime()); is_closed = true; message += StringFormat("----CLOSE PROFIT----\r\n%s %s lots\r\n%s @ %s\r\nCP - %s \r\nTP - %s \r\nProfit: %s PIPS \r\n--------------------------------\r\n", 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()/10,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/10,1)); printf(message); if(!tms_send(message,_token) ) { //error handling } } } double order_pips() { if(OrderType() == OP_BUY) { return (OrderClosePrice()-OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT); } else { return (OrderOpenPrice()-OrderClosePrice())/MarketInfo(OrderSymbol(),MODE_POINT); } } string order_type () { 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 ""; } 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; }