Delay Getting History Informations in OnTick() ?

 

Hi Folks,


It seems like sometimes my EA is taking a little more time to send an order. As I'm trading in a very short of time (Scalping), I'm loosing money sometimes.

So I'm trying to figure out if is there any part of my code is wasting time.

The part below was extracted form OnTick. 

Void OnTick()
 {

ulong ticketh;
   datetime last=0;
   HistorySelect(iTime(PERIOD_D1,1),TimeCurrent());
   for(int i=HistoryOrdersTotal()-1; i>=0; i--)
     {
      ticketh=HistoryOrderGetTicket(i);
      if(ticketh>0)
        {
         if(HistoryOrderGetString(ticketh,ORDER_SYMBOL)==Symbol())
           {
            datetime entry=HistoryOrderGetInteger(ticketh,ORDER_TIME_SETUP);
            if(entry>last)
               last=entry;
           }
           
         
        }
      }

 }


My first guess is because maybe my broker is spending some seconds to give the informations of orders history (HistorySelect).

What do you guys think about it? 

The purpose of this code is to receive the time of the last trade and wait some minutes to begin a new trade.

I don't know a better way (code) to "sleep" the EA some minutes after close a position.

 
Guilherme Mendonca:

Hi Folks,


It seems like sometimes my EA is taking a little more time to send an order. As I'm trading in a very short of time (Scalping), I'm loosing money sometimes.

So I'm trying to figure out if is there any part of my code is wasting time.

The part below was extracted form OnTick. 


My first guess is because maybe my broker is spending some seconds to give the informations of orders history (HistorySelect).

What do you guys think about it? 

The purpose of this code is to receive the time of the last trade and wait some minutes to begin a new trade.

I don't know a better way (code) to "sleep" the EA some minutes after close a position.

Is there a way to run these part of the code immediately when a position was closed instead of every tick? I would like to make sure this part is not delaying an order execution.

 
Guilherme Mendonca: Is there a way to run these part of the code immediately when a position was closed

Get a $million, buy a co-located server.

Or stop trying scalp.

 
William Roeder:

Get a $million, buy a co-located server.

Or stop trying scalp.

It's a different option.

But I think it's important to know what our limitations using trading systems.

If I know my problem, I can work to fix it or at least mitigate it.