Compiling Trading Strategies with C++

Posted By: pascalx

Compiling Trading Strategies with C++ - 08/19/17 11:01

Hello. I am new to this site.

I was wondering how the Zorro trading functionality is meant to be compiled against c++. I did not find information about that in the Zorro Manual. Only found this post that suggests it is possible:
Quote:
lite-C has a 'real' debugger, but it's not implemented in Zorro yet. However, you can alternatively write your strategies in a C++ DLL and use your C++ development system for debugging.

http://www.stevehopwoodforex.com/phpBB3/...start=60#p53792

I see the C headers in Zorro/include but I found no static or dynamic library to link against. I looked into the resources of Zorro.exe and SED.exe but could not find anything suspicious there either.

Also how do I register to the events in c++? Or do I need a proxy script that forwards the calls to dll exports?
http://manual.zorro-trader.com/functions.htm

Any help is much appreciated.
Thanks.
Posted By: Dalla

Re: Compiling Trading Strategies with C++ - 08/19/17 18:15

Perhaps you can find some help here?
http://www.zorro-trader.com/manual/en/litec_api.htm
Posted By: pascalx

Re: Compiling Trading Strategies with C++ - 08/20/17 10:18

Yes, but contrary to importing functionality to lite-c I would like to use the zorro trading framework in c++ natively. From what I read zorro was developed in C++, so technically it should be possible. I just did not find yet how this is exposed. The post from jcl suggests it is possible.
Posted By: pascalx

Re: Compiling Trading Strategies with C++ - 08/22/17 18:22

I have found no way yet to natively use Zorro in C++. Would be awesome to use it in Visual Studio. I have the impression the Zorro framework is really feature rich and purposefully organized.

However I am surprised that the Zorro lite-C Editor is intended to be used without Debugging functionality. How do you guys track down coding errors? By logging? I was disappointed by the MQL4 debugger and MQL4 restrictions, but lite-C appears to be worse in that regard.

The Gamestudio editor appears to have a debugger:
http://www.conitec.net/litec/work17.htm
But I assume it is not compatible with Zorro?

In the event C++ Zorro is not natively available, does anyone know of an existing C++ to lite-C bridge? If not, what do you think is the best approach to implement it? We could use a polling approach like the Zorro MT4/5 Bridge does, which will come with a hit on performance if we want to support the Zorro commands 1:1. Or we use a platform/language independent messaging like ZeroMQ. Maybe that would be the most elegant approach. Thus you could also write code in python or java or whatever.
Posted By: jcl

Re: Compiling Trading Strategies with C++ - 08/23/17 13:01

Although it is possible to code a strategy in a C++ Dll, it takes a bit more effort than writing it natively in C. You must write a C wrapper that acts as a Zorro strategy and calls your Dll via LoadLibrary() and GetProcAddress(). You also need to pass pointers to the indicators and trade functions that you want to use. The advantage of using the Visual Studio debugger is probably not worth the hassle.

Directly running strategies in Dlls is planned for a future Zorro version, but not yet available.
Posted By: pascalx

Re: Compiling Trading Strategies with C++ - 08/23/17 16:21

Originally Posted By: jcl
Although it is possible to code a strategy in a C++ Dll, it takes a bit more effort than writing it natively in C. You must write a C wrapper that acts as a Zorro strategy and calls your Dll via LoadLibrary() and GetProcAddress(). You also need to pass pointers to the indicators and trade functions that you want to use. The advantage of using the Visual Studio debugger is probably not worth the hassle.

Directly running strategies in Dlls is planned for a future Zorro version, but not yet available.

Hi bro. Good thinking there. Passing pointers of the functions and static variables to the DLL would save some headache. For the zorro events we can use exported functions. Shouldn't be a problem to implement (I think).

Well I guess it's just a matter of preference. I prefer C++ over C and feel more comfortable with it.

Are all System Variables (LookBack, Stop, PIP, etc) static at all times? And are they all already instanced when we enter main() ? Or are there some that reallocate or instantiate later?

And what is the calling convention of lite-c functions?

Btw may I suggest to rename "User Supplied" in the zorro manual to something like "Script event functions"?
Posted By: jcl

Re: Compiling Trading Strategies with C++ - 08/24/17 16:24

All system variables are in the "g" struct, so you only need to pass a pointer to that struct. The file "variables.h" contains the defines of all variables. The calling convention is __cdecl.
Posted By: jcl

Re: Compiling Trading Strategies with C++ - 08/29/17 16:26

We're looking for beta testers for the mentioned future interface for running strategies in DLLs. If you're interested, please contact support (at) opgroup.de.
Posted By: pascalx

Re: Compiling Trading Strategies with C++ - 08/30/17 07:42

Originally Posted By: jcl
We're looking for beta testers for the mentioned future interface for running strategies in DLLs. If you're interested, please contact support (at) opgroup.de.

Obsolutely Sir. Mail sent.

I had a go at implementing a pointer handover and it appears to be mostly no problem. I intent to use the headers from Zorro as-is without touching them. Thus I have to accompany the original function declarations with implementations, that in return call the function pointer given by lite-c. I created some simple macros that generate the required code from function definition list(s).

Unfortunately the function declarations show no information about optional parameter values. Thus I have to a) check the zorro manual manually if some arguments are optional and b) then guess what the default value could be. I assume the primitive data types and pointers have a default value of 0 (always?). Not sure about string (char*). Also 0 (NULL) or "" (empty string) ? Maybe there are special cases where it is different but not documented?

Finally I have to accompany those function declarations with an overload that specifies the optional argument values.

So original function (as in functions.h)
Code:
TRADE* enterLong(function f,var v0,var v1,var v2,var v3,var v4,var v5,var v6,var v7,...)
{
return bridge::enterLong_ptr(f,v0,v1,v2,v3,v4,v5,v6,v7);
}


is accompanied by
Code:
TRADE* enterLong(int Lots=0, var Entry=0, var Stop=0, var TakeProfit=0, var Trail=0, var TrailSlope=0, var TrailLock=0, var TrailStep=0)
{
return bridge::enterLong_ptr(Lots, Entry, Stop, TakeProfit, Trail, TrailSlope, TrailLock, TrailStep, 0);
}



What I am wondering about in the case of enterLong, enterShort is the behaviour you impose according to the manual.
http://www.zorro-trader.com/manual/en/buylong.htm

Assuming there is just one enterLong function (as indicated by functions.h), and int/long are both 4 bytes, how does this function know if the first parameter means lot size or function ptr?
Posted By: AndrewAMD

Re: Compiling Trading Strategies with C++ - 09/06/17 17:29

Oh hey, what's this? laugh



Attached picture Capture.JPG
Posted By: jcl

Re: Compiling Trading Strategies with C++ - 09/07/17 11:50

enterLong is not overloaded. I don't know how the first parameter type is checked, but probably it is compared to the DLL or lite-C address space. If it is below the address space, it is assumed a lot size.
Posted By: AndrewAMD

Re: Compiling Trading Strategies with C++ - 09/07/17 12:39

Ah, because...
Code:
typedef long function;


This seems to work correctly:
Code:
enterLong((function)tmfCallback);


Thanks!
Posted By: pascalx

Re: Compiling Trading Strategies with C++ - 09/07/17 14:00

Which is a reinterpret_cast. Ideally the cast should be hidden by a template function in zorro.h.
© 2024 lite-C Forums