Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (Edgar_Herrera, VoroneTZ, Akow), 973 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Zorro parallel trading @ multiple brokers #485910
05/08/22 14:57
05/08/22 14:57
Joined: Dec 2021
Posts: 12
Z
Zendrix Offline OP
Newbie
Zendrix  Offline OP
Newbie
Z

Joined: Dec 2021
Posts: 12
Hello everybody,

I am facing a problem to make Zorro trading in parallel (via MT4Bridges) on multiple accounts at the same time.

To point out the core problem : AT THE SAME TIME.

In my example, I connect one(1) Zorro to two(2) brokers via MT4 bridge: both demo accounts, FXpro and Roboforex.
All works great, Zorro handles the requested instruments, there is no problem to „fire and manage“ individual trades to a connected broker, enter, exit, managing stops, using TMF .. all good … but :

To have a trading system getting (nearly) the same results on different accounts, I am looking for entry and exit at nearly the same time … and here comes my problem, I am not able to tell Zorro to do that.

To have maximum „close controll“, I do not use TMF in this example. I use simple

enterLong()
enterShort()

exitLong()
exitShort()


commands. As I can understand the logic of Zorro by watching its behavior, it seems that Zorro is entering trade Nr.1 @Broker<A>, waits until all steps for this is done and booked, and then starts to work along trade Nr.2 @Broker<B>.
To proof that, I use (beside the Logs of both MT4 Terminals / Journal in Milliseconds ) the following code with some .txt logging addons:

algo("AB01");
asset(ASSET_A);

zeittext1 = strdate("%d.%m.%Y %a %H:%M",ldate(UTC,NOW) );
zeittext2 = strf("%06.3f",second(ldate(UTC,NOW)));
file_append("Data\\AAA-LOG\\Trades.txt",strf("\n%s:%s UTC |before sending enterLong() AA",zeittext1,zeittext2),0);

enterLong();

zeittext1 = strdate("%d.%m.%Y %a %H:%M",ldate(UTC,NOW) );
zeittext2 = strf("%06.3f",second(ldate(UTC,NOW)));
file_append("Data\\AAA-LOG\\Trades.txt",strf("\n%s:%s UTC |after sending enterLong() AA",zeittext1,zeittext2),0);


algo("AB01");
asset(ASSET_B);

zeittext1 = strdate("%d.%m.%Y %a %H:%M",ldate(UTC,NOW) );
zeittext2 = strf("%06.3f",second(ldate(UTC,NOW)));
file_append("Data\\AAA-LOG\\Trades.txt",strf("\n%s:%s UTC |before sending enterShort() BB",zeittext1,zeittext2),0);

enterShort();

zeittext1 = strdate("%d.%m.%Y %a %H:%M",ldate(UTC,NOW) );
zeittext2 = strf("%06.3f",second(ldate(UTC,NOW)));
file_append(„Data\\AAA-LOG\\Trades.txt",strf("\n%s:%s UTC |after sending enterShort() BB",zeittext1,zeittext2),0);



… and the same logic with exit commands…


The mouse-click-event triggering the actions has also been equipped with a timing log to file, similar to the enter/exit events.

The complete results look like this :

ZORRO:
05.05.2022 Thu 20:46:34.563 UTC |MouseClick ENTER command
05.05.2022 Thu 20:46:34.579 UTC |before sending enterLong() AA

// MT4 BrokerA opens trade
05.05.2022 Thu 20:46:34.784 UTC |after sending enterLong() AA
05.05.2022 Thu 20:46:34.790 UTC |before sending enterShort() BB

// MT4 BrokerA closes trade
05.05.2022 Thu 20:46:35.246 UTC |after sending enterShort() BB


05.05.2022 Thu 20:46:38.509 UTC |MouseClick EXIT command
05.05.2022 Thu 20:46:38.526 UTC |before sending exitLong() AA

// MT4 BrokerB opens trade
05.05.2022 Thu 20:46:38.798 UTC |after sending exitLong() AA
05.05.2022 Thu 20:46:38.804 UTC |before sending exitShort() BB

// MT4 BrokerB closes trade
05.05.2022 Thu 20:46:39.180 UTC |after sending exitShort() BB



…in addition to that, here the broker logs :

<MT4 Broker A>
2022.05.05 20:46:34.622 order buy market 0.01 EURUSD
2022.05.05 20:46:34.719 order was opened buy 0.01 EURUSD

2022.05.05 20:46:38.594 close order buy 0.01 EURUSD
2022.05.05 20:46:38.734 order buy 0.01 EURUSD closed




<MT4 Broker B>
2022.05.05 20:46:34.791 order sell market 0.01 EURUSD
2022.05.05 20:46:35.191 order was opened sell 0.01 EURUSD

2022.05.05 20:46:38.826 close order sell 0.01 EURUSD
2022.05.05 20:46:39.113 order sell 0.01 EURUSD closed




It is clearly visible that Zorro is waiting all the time, until brokerA operations is complete before going on to brokerB.
My desired behavior is, that the the ENTRY (and later EXIT) commands are sent to the brokers at the same time = both "leave" Zorro in parallel, not in sequence.
So both brokers would take care of their tasks to be done to have my trades booked into my accounts, there is no need that one broker is waiting until the other one is done.

But I am not able to generate the correct code for this in Zorro.
Maybe someone could give me an advise, how to use/produce better Zorro code to get rid of this problem above.


I also tried (maybe in the wrong way?):

1) to have TMF involved - hoping that the separated trade management would make have an „independent“ impact
…but no improvement

2) to manipulate Zorro by using the NOLOCK Flag : set(TICKS|LOGFILE,NOLOCK)
…but no improvement

3) to use (alltough shown in documentation its only for trade simulation)
Fill = 8;
…but no improvement

Is there a solution for that problem, what is my mistake ?

Regards
Hendrix

Re: Zorro parallel trading @ multiple brokers [Re: Zendrix] #485913
05/09/22 06:58
05/09/22 06:58
Joined: Apr 2008
Posts: 585
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 585
Austria
You want not wait for the order to be confirmed. Then you must use GTC trade mode and also the set_wait broker commande for reducing the wait time. After sending the order, set wait time back to normal.

Re: Zorro parallel trading @ multiple brokers [Re: Zendrix] #485923
05/11/22 19:55
05/11/22 19:55
Joined: Dec 2021
Posts: 12
Z
Zendrix Offline OP
Newbie
Zendrix  Offline OP
Newbie
Z

Joined: Dec 2021
Posts: 12
Hello Petra,
thank you for you help.

I added the two suggested changes to my code, and the result shows a very strong improvement in speed, very nicely - thank you.

I now use :

Code
...
setf(TradeMode,TR_GTC);									
brokerCommand(SET_WAIT,0);

enterLong();
...


But as expected, Zorro does not receive a trade confirmation, so Zorro does not know about the existance of the trade - although they are opened correctly by the brokers. This leads me to the problem, not being able to close or handle this trades any more after having opened them.

Solving that problem, I tried to use

Code

brokerCommand(GET_POSITION,“EURUSD“)




to get Zorro aligned with the actual broker account status. But although GET_POSITION giving back the correct TradeID in MT4 of the not confirmed+opened+active trade, Zorro is not able the handle the trades after receiving the TradeID.
I have not been able to get the brokerCommand GET_TRADES working via MT4bridge, it seems officially not being supported for the MT4bridge.

Is there any way, I can force Zorro to „read“ the broker account via MT4bride to pickup the knowledge of the active trades inside MT4 Terminal , so I will be able to manipulate the opened trades again ?

Regards
Hendrix

Re: Zorro parallel trading @ multiple brokers [Re: Zendrix] #485924
05/11/22 20:23
05/11/22 20:23
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
You can run a for(current_trades) loop to retrieve specific information about open trades.

https://zorro-project.com/manual/en/fortrades.htm
https://zorro-project.com/manual/en/trade.htm

Re: Zorro parallel trading @ multiple brokers [Re: Petra] #485927
05/12/22 17:49
05/12/22 17:49
Joined: Dec 2021
Posts: 12
Z
Zendrix Offline OP
Newbie
Zendrix  Offline OP
Newbie
Z

Joined: Dec 2021
Posts: 12
Hello Grant,
thank you for your help. Unfortunately your hint does not return the result I am looking for. I tested the use of

Code
var val = 0.0;										
for(all_trades) val += TradeProfit;
printf(„\n%06.3f",val);


Zorro shows (using this code) correctly all trades’ (profit) - but only of these trades which have been managed by Zorro before.

When I trigger trades with maximum reduced (waiting-) time to get minimum execution time

Code
brokerCommand(SET_WAIT,0);


then Zorro is reporting this TradeEntrys as failed …

Error 075 (EURUSD_A:ALGOabc:L) - can't open 1@264846185 at 16:30:10
Error 075 (EURUSD_B:ALGO123:S) - can't open 1@2.0002 at 16:30:10


… although the trades are opened as requested at the brokers’ accounts.

As I know about this behavior, I am looking for a command/code snippet, which „reads“ the broker account afterwards and aligns Zorro’s internal logs correctly, so that I can continue to handle these trades in Zorro as usual.

Regards
Hendrix

Re: Zorro parallel trading @ multiple brokers [Re: Zendrix] #485928
05/12/22 18:10
05/12/22 18:10
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
Originally Posted by Zendrix
Zorro shows (using this code) correctly all trades’ (profit) - but only of these trades which have been managed by Zorro before.


The manual states:

Quote
Zorro will then check if there were any open trades from the previous session. The session status was stored in a .trd file in the Data folder. If the broker API keeps a list of open trades, Zorro will try to match its session status with that list. If a trade from the previous session is not found anymore in the broker's open trade list, or appears in the broker's list of closed trades, Zorro will print a "closed" or "not found" message and cancel the trade. If the trade was an option that was meanwhile expired, Zorro will print an "expired" message and also cancel it. Otherwise the trade will be resumed.


(https://zorro-project.com/manual/en/trading.htm)

I use MT4 as well, but I never trade manually since I would expect issues like these. Check your MT4 log for the reason for those 075 errors.

Last edited by Grant; 05/12/22 18:19.
Re: Zorro parallel trading @ multiple brokers [Re: Zendrix] #485932
05/13/22 02:55
05/13/22 02:55
Joined: Dec 2021
Posts: 12
Z
Zendrix Offline OP
Newbie
Zendrix  Offline OP
Newbie
Z

Joined: Dec 2021
Posts: 12
Good morning Grant,

my MT4 Logs do not show any errors ( not in Expert / not in Journal ), the trade entrys are booked correctly.

The error only shows up on the Zorro side. I can stop it by using greater WAIT - times.

brokercomands with SET_WAIT below 200ms shows the Zorro errors, times above 200ms makes Zorro and MT4 work correctly.

Regards
Hendrik

Re: Zorro parallel trading @ multiple brokers [Re: Zendrix] #485933
05/13/22 07:05
05/13/22 07:05
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
Good morning as well,

That SET_WAIT command got me thinking, since I'm experiencing requote issues myself. It's not stated in the manual that SET_WAIT is able to prevent those from happening, but maybe they will(?)
Edit: never mind, I see that this brokerCommand isn't supported for MT4 access, see https://zorro-project.com/manual/en/mt4plugin.htm


Back to your issue, I hope that one of the Zorro vets can help you solving this.

Last edited by Grant; 05/13/22 15:08.
Re: Zorro parallel trading @ multiple brokers [Re: Zendrix] #485935
05/13/22 08:47
05/13/22 08:47
Joined: Apr 2008
Posts: 585
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 585
Austria
I think there is no real solution for MT4. You could use the TR_FILLED flag, but when the wait time is too short for MT4 to create the trade ID, Zorro cannot manage the trade further because it doesn't know its ID.

Even if you implement a function in the EA that returns the last trade ID, you have still the problem that one of the 2 trades might be requoted or not filled for other reasons, so you have then asymmetry in your trades. I think you must keep the wait time over 200 ms so that MT4 can return the ID.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1