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
2 registered members (AndrewAMD, VoroneTZ), 831 guests, and 5 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
Page 1 of 4 1 2 3 4
Some questions for BrokerAPI(1.96.4) #475575
12/26/18 10:15
12/26/18 10:15
Joined: Dec 2014
Posts: 56
I
ibne Offline OP
Junior Member
ibne  Offline OP
Junior Member
I

Joined: Dec 2014
Posts: 56
Hi,

I have some questions regarding the BrokerAPI for Zorro 1.96.4, while testing my plugin:

1) The TradeTest script seems broken. I can only open trades, but not closing them for a hedged account.
Zorro keeps on saying that one needs to check the NFA flag.
But NFA is set to Off and the hedge mode is set to 2.
The function "BrokerSell" gets never called.
Even when setting AUTO=on, Zorro opens some trades but can not close them, since the NFA is "wrong".
I remember that the TradeTest script was working fine in previous versions; would be very helpful if the developers could fix this.
Edit: I even created a dedicated Accounts.csv entry where NFA compliance is explicitly turned off(0) with no success.
Zorro still says "Closing prohibited - check NFA flag!"

2) Semantics of function brokerCommand (int nCommand, DWORD dwParameter) is sometimes unclear.
The manual says that "they return 0 when they are not supported or no broker connection is established", so returning 0 is for signaling error.
But what about commands which can return 0 as a value? Take GET_NTRADES as an example.
It should return the number of open trades...but what if there are no open trades currently? What does a return of 0 mean here, an error or zero trades?

3) Again regarding brokerCommand: it is unclear for some commands if the value should stay fix for the entire trading session.
Take SET_ORDERTEXT as an example. Should I set the orderText for the next trade which gets opened or should it be set to every upcoming orders?
Or what about SET_LIMIT? To me this makes only sense for the next trade related command and not for every other.
So, I invalidate the limit after applying it and the script has to set a new value again.
The documentation should make it clear on the lifetime of the command values.

Thx for help and have nice holidays laugh
Juergen

Last edited by ibne; 12/26/18 11:03.
Re: Some questions for BrokerAPI(1.96.4) [Re: ibne] #475576
12/26/18 11:16
12/26/18 11:16
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
I dont know why your Brokersell is not called, but when you set a variable or an ordertext it stays until you set another ordertext. It does not reset itself. NTRADES = 0 can mean not implemented or no trades, so use this command only when your broker plugin supports GET_NTRADES.

Re: Some questions for BrokerAPI(1.96.4) [Re: Spirit] #475579
12/26/18 11:37
12/26/18 11:37
Joined: Dec 2014
Posts: 56
I
ibne Offline OP
Junior Member
ibne  Offline OP
Junior Member
I

Joined: Dec 2014
Posts: 56
"NTRADES = 0 can mean not implemented or no trades"...yes it can mean both, which to me does not make much sense.
Anyway, then the script has to figure out if the comnmand is not supported or there are zero trades.
This is not very effictive nor clear I guess.
I already implemented this command and was wondering what the caller would expect here.

For not reseting values: this means that if the script user does not set a new value strange things can happen.
If SET_LIMIT is not set for every new order related command, then this limit price might stay for totally unrelated assets.
But Ok, if this is the desired behavior...

Re: Some questions for BrokerAPI(1.96.4) [Re: ibne] #475580
12/26/18 12:45
12/26/18 12:45
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
I was anyway wondering for what NTRADES is needed in a script. it can return any number when more than one Zorro is trading or when someone trades manually, so its rather meaningless. SET_LIMIT is AFAIK outdated and not used anymore.

Re: Some questions for BrokerAPI(1.96.4) [Re: Spirit] #475587
12/27/18 08:59
12/27/18 08:59
Joined: Dec 2014
Posts: 56
I
ibne Offline OP
Junior Member
ibne  Offline OP
Junior Member
I

Joined: Dec 2014
Posts: 56
Luckily, the problem with NFA was on my side laugh
In general, I think the entire specification of the Broker API needs an update, specifically the brokerCommand part.
Mixing error codes with values is bad programming style IMHO.

Re: Some questions for BrokerAPI(1.96.4) [Re: ibne] #475592
12/27/18 13:18
12/27/18 13:18
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
The documentation of any given plugin will clarify whether a certain broker command is supported. Thus, it is reasonable for any command to return zero, value or not.

Re: Some questions for BrokerAPI(1.96.4) [Re: AndrewAMD] #475604
12/27/18 21:12
12/27/18 21:12
Joined: Dec 2014
Posts: 56
I
ibne Offline OP
Junior Member
ibne  Offline OP
Junior Member
I

Joined: Dec 2014
Posts: 56
I disagree in a very general context.
Mixing different types of results is in general a bad programming style.
Btw, it would be very easy to change the API here with no drawbacks.

Further, returning 0 could also mean that the connection is lost.
So, one has to figure out if 0 means:
1) 0 open trades
2) Connection lost
3) Command not supported

Having to look up various other places what 0 could possibly mean defeates the purpose of pure function call.

Last edited by ibne; 12/27/18 21:17.
Re: Some questions for BrokerAPI(1.96.4) [Re: ibne] #475642
12/31/18 09:47
12/31/18 09:47
Joined: Dec 2014
Posts: 56
I
ibne Offline OP
Junior Member
ibne  Offline OP
Junior Member
I

Joined: Dec 2014
Posts: 56
Two more questions:
1) The testing script TradeTest.c does not show the button "Update Stop". Is there any setting in the script which makes this button appear again?
2) Regarding BrokerAsset call: if the asset data is available but the asset is currently not tradeable, which value should be returned? Docs say "1 when the asset is available and the returned data is valid", so does "available" mean "currently tradeable"?

Re: Some questions for BrokerAPI(1.96.4) [Re: ibne] #475645
12/31/18 11:32
12/31/18 11:32
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
No, 'available' basically means that you spelled the name correctly. For adding an update stop button, edit the panel definition in line 252 in the tradetest script and change "9" to "10".

Re: Some questions for BrokerAPI(1.96.4) [Re: ibne] #475647
12/31/18 11:39
12/31/18 11:39
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
2) Return 1 regardless of whether the asset is tradeable. You can optionally output asset tradability with GET_TRADEALLOWED.

Re: Some questions for BrokerAPI(1.96.4) [Re: jcl] #475648
12/31/18 11:44
12/31/18 11:44
Joined: Dec 2014
Posts: 56
I
ibne Offline OP
Junior Member
ibne  Offline OP
Junior Member
I

Joined: Dec 2014
Posts: 56
Thx, the update stop button is back laugh
Regarding BrokerAsset: so when the data for the asset is available, but the asset itself is currently not tradeable, then the plugin should return 1 anyway?
I think I will add additional checks for tradeability for all order related commands(BrokerBuy, BrokerStop, BrokerSell).
This is beneficial in giving back a more detailed failure description.

Re: Some questions for BrokerAPI(1.96.4) [Re: AndrewAMD] #475649
12/31/18 11:47
12/31/18 11:47
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
Originally Posted By: AndrewAMD
2) Return 1 regardless of whether the asset is tradeable. You can optionally output asset tradability with GET_TRADEALLOWED.

Re: Some questions for BrokerAPI(1.96.4) [Re: AndrewAMD] #475707
01/04/19 14:51
01/04/19 14:51
Joined: Dec 2014
Posts: 56
I
ibne Offline OP
Junior Member
ibne  Offline OP
Junior Member
I

Joined: Dec 2014
Posts: 56
While implementing the BrokerAsset function, I can see that only the price and spread pointers are valid.
I wonder under which conditions the other pointer outputs are ready to be written.
I opened a position, but still the pointers are not used by Zorro.
Are they obsolete or do I need to enable something?

Re: Some questions for BrokerAPI(1.96.4) [Re: ibne] #475709
01/04/19 15:28
01/04/19 15:28
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
I don't have my IDE open, so let me ask you:

1) Which pointers are valid during the asset subscription phase?
2) Which pointers are valid during the live trading phase?

Re: Some questions for BrokerAPI(1.96.4) [Re: AndrewAMD] #475711
01/04/19 16:13
01/04/19 16:13
Joined: Dec 2014
Posts: 56
I
ibne Offline OP
Junior Member
ibne  Offline OP
Junior Member
I

Joined: Dec 2014
Posts: 56
I have not checked it during the subscription phase, but I know for sure that the price pointer is NULL as I can subscribe the assets.
After subscription is done, I see that only price and spread pointers are valid.
All others are NULL.
After opening a trade, the situation does not change.
Maybe everything is OK, since I check for valid pointers anyway.
I'm just curious under which conditions the other pointers(besides price and spread) become valid.
It also makes sense to test these values when developing a plugin, so I need a way to tell Zorro to use these pointers.

Or it could be that the TradeTest.c script is the wrong tool for that.

Re: Some questions for BrokerAPI(1.96.4) [Re: ibne] #475712
01/04/19 16:21
01/04/19 16:21
Joined: Dec 2014
Posts: 56
I
ibne Offline OP
Junior Member
ibne  Offline OP
Junior Member
I

Joined: Dec 2014
Posts: 56
Ok, now I see in the log that the other pointers are valid only sometimes.
When looking at timestamps, I would guess that Zorro queries the other values only once per minute.
Now I can see that all values are set correct and everything works laugh

Re: Some questions for BrokerAPI(1.96.4) [Re: ibne] #475740
01/06/19 08:34
01/06/19 08:34
Joined: Dec 2014
Posts: 56
I
ibne Offline OP
Junior Member
ibne  Offline OP
Junior Member
I

Joined: Dec 2014
Posts: 56
Next questions arise for BrokerBuy2:
The manual says for the return value 0 that:
when the market or limit order was not filled within 30 seconds. Not or partially filled orders must be cancelled.
I'm not sure what that means.
Does Zorro support partially filled orders at all?
If you look at the output parameter pFill, then it seems that partial fills are allowed.
On the other hand, when the order was not filled within 30sec(does this mean fully filled?), partially filled ones must be closed.
So, partial fills are not allowed?!
The only scenario where pFill makes sense to me, is when after 30sec the order is still only partially filled.

Re: Some questions for BrokerAPI(1.96.4) [Re: ibne] #475769
01/07/19 16:42
01/07/19 16:42
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
This depends. Does the broker API use a high-level "trades" abstraction or does it only process "orders"?

Re: Some questions for BrokerAPI(1.96.4) [Re: AndrewAMD] #475782
01/07/19 19:49
01/07/19 19:49
Joined: Dec 2014
Posts: 56
I
ibne Offline OP
Junior Member
ibne  Offline OP
Junior Member
I

Joined: Dec 2014
Posts: 56
It's Dukascopy and I think they work only with orders.
But "that depends" should be clearly stated, such that a Broker plugin is fully compliant to the specification.
BrokerBuy2 is in general very unclear to me.
For example, if there is no connection to the broker for 30sec then there is also no order fill.
Should the plugin then return 0 or -2, because both conditions would be satisfied?
And what about the NFA closing way, when the order was rejected.
Then 0 and 1 would be candidates for the result.

In general it would be helpful if the documentation is very strict here, i.e. a boolean matrix with possible return codes, like this:

Order fully filled | Order partially filled(30sec) | Order not filled(30s) | No BrokerConnecition(30s) | NFA-Account =
1 0 0 0 0 Expected Result: TradeId
1 0 0 0 1 Expected Result: 1
0 1 0 0 0 Expected Result: ????
0 1 0 0 1 Expected Result: ????(maybe 1)
0 0 1 0 0 Expected Result: 0
0 0 1 0 1 Expected Result: ????(maybe 1)
0 0 1 1 0 Expected Result: 0 or -2
0 0 1 1 1 Expected Result: 0,-2 or 1

Re: Some questions for BrokerAPI(1.96.4) [Re: ibne] #475794
01/08/19 10:20
01/08/19 10:20
Joined: Jan 2017
Posts: 95
Bulgaria
kvm Offline
Junior Member
kvm  Offline
Junior Member

Joined: Jan 2017
Posts: 95
Bulgaria
I agree with you, that the API is not very well defined. For example, see the link below:

https://opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=473867#Post473867

But in case with Dukascopy you can port your strategy to Java and execute it directly inside the JForex environment.

Re: Some questions for BrokerAPI(1.96.4) [Re: kvm] #475795
01/08/19 11:44
01/08/19 11:44
Joined: Dec 2014
Posts: 56
I
ibne Offline OP
Junior Member
ibne  Offline OP
Junior Member
I

Joined: Dec 2014
Posts: 56
Hi kvm,

I just wanted to update the Dukascopy plugin, which I'm the author.
In order to provide a good compliance quality, I need to have a specification with as little ambiguaties as possible.
The BrokerBuy2 description raises too many of them.
There is also the issue of BrokerHistory2 for Dukascopy.
This broker sends ticks on a ask and bid basis, which means you can have multiple ticks in a row with the same ask price(but different spreads, vol, etc.)
Here I'm not sure if I have to filter these ticks out of the stream.

Re: Some questions for BrokerAPI(1.96.4) [Re: ibne] #475796
01/08/19 12:38
01/08/19 12:38
Joined: Jan 2017
Posts: 95
Bulgaria
kvm Offline
Junior Member
kvm  Offline
Junior Member

Joined: Jan 2017
Posts: 95
Bulgaria
Hi ibne,

What a coincidence laugh I'm the author of the Dukascopy plugin (yet another version)

I'm not filtering these ticks. Just returning the last one received.

Re: Some questions for BrokerAPI(1.96.4) [Re: kvm] #475798
01/08/19 13:16
01/08/19 13:16
Joined: Dec 2014
Posts: 56
I
ibne Offline OP
Junior Member
ibne  Offline OP
Junior Member
I

Joined: Dec 2014
Posts: 56
So we can join forces on trying to undertsand the Zoro API laugh

Not filtering these ticks might look very strange on a tick chart, with periods of a "flat" line.
I guess this defeates the purpose of a "tick", which to me means a price change.

Btw: when you also work with Dukascopy, you will agree that their API is even more broken...

Re: Some questions for BrokerAPI(1.96.4) [Re: ibne] #475800
01/08/19 14:25
01/08/19 14:25
Joined: Jan 2017
Posts: 95
Bulgaria
kvm Offline
Junior Member
kvm  Offline
Junior Member

Joined: Jan 2017
Posts: 95
Bulgaria
I'll be glad to collaborate with you!

I'm using these ticks coming from Strategy.onTick() method only to return the current price information via brokerAsset() method.

When Zorro calls brokerHistory2() then I'm using History.getTicks() to retrieve them.

In my opinion the Dukascopy API is too complicated but decent. However, the implementation is not the best one. What version do you use?

Re: Some questions for BrokerAPI(1.96.4) [Re: kvm] #475802
01/08/19 14:48
01/08/19 14:48
Joined: Dec 2014
Posts: 56
I
ibne Offline OP
Junior Member
ibne  Offline OP
Junior Member
I

Joined: Dec 2014
Posts: 56
The latest one:
DDS2-jClient-JForex 3.4.13
JForex-API 2.13.62

Their API is overloaded and not very user friendly.
Take for example the IEngine.executeTask() method.
Why should the user take care on which thread he is when executing order related tasks?
The API could handle this easily...
This is just one of the many shortcomings.

Ok, back to Zorro laugh
Here we urgently need some reply on how to correctly implement the API functions.
What is also not so good is that Zorro queries ticks, instead of getting them pushed by default.
This means that the tick history of Zorro is very different to the brokers history with many missed ticks.
That makes comparison of tick based backtests impossible.

Re: Some questions for BrokerAPI(1.96.4) [Re: ibne] #475803
01/08/19 15:02
01/08/19 15:02
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
Originally Posted By: ibne
What is also not so good is that Zorro queries ticks, instead of getting them pushed by default.
This means that the tick history of Zorro is very different to the brokers history with many missed ticks.
That makes comparison of tick based backtests impossible.
It is not impossible... in fact, I get every tick in my plugin:
https://github.com/AndrewAMD/SierraChartZorroPlugin

To get all ticks, you must implement SET_HWND. You must send a message to Zorro from another thread or process. Then Zorro will go ahead and collect that tick.

Re: Some questions for BrokerAPI(1.96.4) [Re: AndrewAMD] #475808
01/08/19 15:54
01/08/19 15:54
Joined: Dec 2014
Posts: 56
I
ibne Offline OP
Junior Member
ibne  Offline OP
Junior Member
I

Joined: Dec 2014
Posts: 56
Hi Andrew,

thanks for reminding me about the HWND function.
Am I right that when calling PostMessage(hWindow, WM_APP + 1, 0, 0) a BrokerAsset call is triggered?
But how does Zorro know which asset was updated with a new tick?
Will Zorro request all prices for all subscribed assets?
And what about the "normal" periodically price requests with BrokerAsset, are they then stopped?
If not, then ticks might fetched more then once which seems a bit of an overkill.
This is all very unclear to me...

Re: Some questions for BrokerAPI(1.96.4) [Re: ibne] #475809
01/08/19 16:09
01/08/19 16:09
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
Calling the windows handle will make zorro call all subscribed assets.

Perhaps it is overkill, but if you're streaming your data, then you already have the data in-memory.

For the other questions, ask jcl.

EDIT: Clarity and correctness

Last edited by AndrewAMD; 01/08/19 16:14.
Re: Some questions for BrokerAPI(1.96.4) [Re: AndrewAMD] #475810
01/08/19 16:22
01/08/19 16:22
Joined: Dec 2014
Posts: 56
I
ibne Offline OP
Junior Member
ibne  Offline OP
Junior Member
I

Joined: Dec 2014
Posts: 56
Andrew, your plugin is written in native C/C++, which is a big advantage over plugins which relay on JVM languages.
Dukascopy is using Java and so we end up with a very high latency regarding tick fetching, because we must use a Java to C/C++ bridge.
I think that the most useful solution would be that Zorro provides update methods which get called by the plugin.
Currently it is the other way round frown

Re: Some questions for BrokerAPI(1.96.4) [Re: ibne] #475811
01/08/19 16:32
01/08/19 16:32
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
You do also have the option of writing a bridge in Java, and have your plugin communicate with it. The java bridge would be a server to zorro and a client to the broker.

This way, you can:
* Have the Java bridge send PostMessage, and
* Both the plugin and the bridge can be single-threaded (usually ideal)
* Have a native C++ plugin.

If you're not sure which protocol to use between the two, just use the DTC protocol and recycle my plugin. laugh

Rationale is similar to what you see here:
https://www.sierrachart.com/index.php?page=doc/helpdetails76.html

(Mind you, these people have strong opinions, but I share some sentiment.)

Re: Some questions for BrokerAPI(1.96.4) [Re: AndrewAMD] #475812
01/08/19 16:37
01/08/19 16:37
Joined: Dec 2014
Posts: 56
I
ibne Offline OP
Junior Member
ibne  Offline OP
Junior Member
I

Joined: Dec 2014
Posts: 56
I can't follow you currently laugh
My plugin for Dukascopy was already bundled with Zorro in former versions.
I'm using JNI as the C++ bridge, quite normal when using Java with native code.

Re: Some questions for BrokerAPI(1.96.4) [Re: ibne] #475814
01/08/19 17:29
01/08/19 17:29
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
Are three Dukascopy plugins better than two? grin

Re: Some questions for BrokerAPI(1.96.4) [Re: AndrewAMD] #475819
01/08/19 19:05
01/08/19 19:05
Joined: Oct 2018
Posts: 90
Germanien
ags Offline
Junior Member
ags  Offline
Junior Member

Joined: Oct 2018
Posts: 90
Germanien
Hi there,

great to see some collaboration impulses here !

I trade with Dukascopy Bank because there you can avoid the ESMA limitations, on Forex you get till 200:1 and CFDs 100:1 leverage.

I tried ibnes' plugin but it is outdated and does not support CFDs. I understand ibne is working on it now.

The other one available is from kvm, this one handles all assets incl. CFDs and is working.

I'm "testing" it in two live accounts since November.

#1 in a M3.medium instance with a Z12 (still working on the traduction of my own system...) and just got some interruptions but the system reconnected succesfully all the times, so no problem here.

#2 in a T2.micro instance with a Z12 variation and 200:1 leverage. Here i got in the same period a fatal disconnection and an orphan trade.
The new version from kvm just released a few days ago should resolve the orphan trade. I'm already testing it here since yesterday.
Lets see. Apparently the T2.micro gives some troubles, in my experience.
jcl says Zorro has good experiences working in T2.micro environments, probably not with a Java based plugin as needed for Dukascopy...

If i can do something guys, just let me know. I'll test all versions you have LIVE ! (after some checks of course).

Re: Some questions for BrokerAPI(1.96.4) [Re: ags] #475852
01/10/19 08:43
01/10/19 08:43
Joined: Dec 2014
Posts: 56
I
ibne Offline OP
Junior Member
ibne  Offline OP
Junior Member
I

Joined: Dec 2014
Posts: 56
Hi,

I just created an early release and it would be great if there are some testers laugh
Project/Source code is here: DukascopyPluginProject
Distribution zip: PluginZip

Just download the zip file and extract into your zorro installation folder.

Page 1 of 4 1 2 3 4

Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1