Trade execution during connection problems

Posted By: Grant

Trade execution during connection problems - 06/16/22 12:55

Sometimes an order is send right before or during a connection problem with my MT4 broker and therefore isn't executed (Warning 075).

To workaround this problem, I've placed the following simplified code in a tock() (not tick() since my strategy is multi-asset):

Code
Trade = enterLong();
ThisTrade = Trade;

if(Trade != 0)
	{
  //Trade has been executed
	}
else
	{
  //Trade hasn't been executed	
	}


This code gets repeated during every tock() call as long as the order hasn't been executed.

However, once the broker connection gets reestablished, two orders get filled right after each other, so I considered placing a wait() function after 'ThisTrade...', but according to the manual this freezes the order execution process. A call() function doesn't seem a solution either because it has no mode for opening a trade (only closing and a couple of others).

Any suggestions to workaround this issue? Thanks.


Posted By: jcl

Re: Trade execution during connection problems - 06/17/22 10:30

For repeatedly sending orders until one is executed, the normal way is virtual hedging combined with a tradeUpdate call in a tock function.

void tock() { tradeUpdate(); }
Posted By: Grant

Re: Trade execution during connection problems - 06/17/22 13:38

Thank you for your suggestion, JCL.

So when MaxLong is larger than 1, I should use the following?

NFA set on 0 in accounts.csv

Code
run()
{
Hedge = 5;
}

tock()
{
ThisTrade = enterLong();

tradeUpdate(ThisTrade,0,0,0,0);

if(ThisTrade != 0)
        {
     //Trade has been executed
        }
else
        {
     //Trade hasn't been executed	
        }
}
Posted By: jcl

Re: Trade execution during connection problems - 06/17/22 14:02

That would permanently open new trades. That is certainly not what you want.
Posted By: Grant

Re: Trade execution during connection problems - 06/17/22 14:28

Do you refer to the MaxLong setting? I did this because I have re-entry rules included.
I assume this has no effect on this exception handling procedure, correct?

The reason I mentioned this is to motivate my choice to set Hedge at 5, not 4.
Posted By: Grant

Re: Trade execution during connection problems - 06/17/22 14:42

Oh wait, you mean that I should run 'ThisTrade = enterLong();' only once and then checking it's status during every tock() call till it's filled?
Posted By: jcl

Re: Trade execution during connection problems - 06/17/22 15:32

Yes, I meant that trade, and no, you need no extra checking at all. Just set Hedge = 5 and add the tock function that I posted above.

Hedge = 5 prevents connection issues and tradeUpdate() permanently synchronizes your MT4 account with your Zorro trades.
Posted By: Grant

Re: Trade execution during connection problems - 06/17/22 15:56

OK, now I understand.

Thanks for your help JCL!
© 2024 lite-C Forums