Download MetaTrader 5

Latency check on Ea running on vps

To add comments, please log in or register
simoncs
324
simoncs  
Hi
I am running an ea on a vps. The trace from vps to the broker reports about 70ms.

I included the below code into my EA to check latency and slippage. The first time the ea traded it reported 375ms, which is about what I was getting at home, about 15000 km away from the brokers server.

Could this code not be reflecting what I am trying to check, or could it be an issue with the vps? I have spoken to the vps provider and they can't see any issue.
int OpenSellOrder(double LotSize,double SL,double TP,string commt="Sell Order")
{
while(IsTradeContextBusy()) Sleep(10);
double requestedPrice = MarketInfo(Symbol(), MODE_BID);
int orderStartPointInTime = GetTickCount();
RefreshRates();
// Place Buy Order
SellTicket=OrderSend(Symbol(),OP_SELL,LotSize,requestedPrice,Slippage*pips2points,(SL()+pips2dbl+Spread()),(TP()-pips2dbl-Spread()),commt+MagicNumber,MagicNumber,0,Red);
OrderOpened=true;
int orderExecutionDurationInMs = GetTickCount() - orderStartPointInTime;
if (OrderSelect(BuyTicket, SELECT_BY_TICKET)) {
double slippageIncurred = requestedPrice - OrderOpenPrice();

Print(StringConcatenate("Execution duration = ", orderExecutionDurationInMs, "ms,Slippage = ", DoubleToStr(slippageIncurred * 10000, 1), "pips"));
} 
Alain Verleyen
Moderator
32396
Alain Verleyen  

Hello,

Please use the SRC button when you post code. Thank you.



simoncs
324
simoncs  
angevoyageur:

Hello,

Please use the SRC button when you post code. Thank you.

sorry - originally posted via my phone, which doesn't have this option
Alain Verleyen
Moderator
32396
Alain Verleyen  
simoncs:
Hi
I am running an ea on a vps. The trace from vps to the broker reports about 70ms.

I included the below code into my EA to check latency and slippage. The first time the ea traded it reported 375ms, which is about what I was getting at home, about 15000 km away from the brokers server.

Could this code not be reflecting what I am trying to check, or could it be an issue with the vps? I have spoken to the vps provider and they can't see any issue.
Are you sure RefreshRates() is needed ? If yes, you have to execute it before your start counter. Not sure what can be the impact though.
simoncs
324
simoncs  
angevoyageur:
Are you sure RefreshRates() is needed ? If yes, you have to execute it before your start counter. Not sure what can be the impact though.


Possibly not. it was here before i added the latency check code. I will comment it out and see if that makes a difference.
eric
99
eric  

I use the code below, but I think the speed is the time for order to go, to be filled and to come back from broker

That's why I get between 300 and 3000ms results. My server is only at 1ms from broker server.

tick=GetTickCount();
ticket=OrderSend(Symbol(),OP_SELL,lotshort,BID,Slippage,stop,takeprofit,EANAME,MAGIC,0,Red);
speed=GetTickCount()-tick;
simoncs
324
simoncs  
kissandfly:

I use the code below, but I think the speed is the time for order to go, to be filled and to come back from broker

That's why I get between 300 and 3000ms results. My server is only at 1ms from broker server.


interesting, thanks.

my concern was also that i was getting the same times from home. If what you say is correct, then it almost looks like it vps has less impact from a slippage point of view, and is more to do with the brokers processing time.

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI  
Yes. It is brokers processing speed. If you don't notice, try doing trade 8 hours apart. You will see there are trades that opened real fast while there might be times when trades opened after quite some time.
To add comments, please log in or register