//+------------------------------------------------------------------+ //| ai_tester_strategy.mq4 | //| Aleksandr M | //| https://tmsrv.pw | //+------------------------------------------------------------------+ #property copyright "Aleksandr M" #property link "https://tmsrv.pw" #property version "1.01" #property strict //Do not forget to add url( https://tmsrv.pw/send ) to Allowed: //Metatrader->Tols->Options->Expert Advisors extern string _token = ""; 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 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("------------ CLOSE ORDER ------------\r\n%s OPEN %s @ %s\r\n\r\n CLOSE NOW @ %s \r\n Profit: %s PIPS \r\n--------------------------------------\r\n", OrderSymbol(), order_type(), DoubleToStr(OrderOpenPrice(),MarketInfo(OrderSymbol(),MODE_DIGITS)), DoubleToStr(OrderClosePrice(),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; }