Use python to compile C++ DLL that is usable by Multicharts

Questions about MultiCharts and user contributed studies.
rc76
Posts: 51
Joined: 14 Oct 2020
Has thanked: 17 times

Use python to compile C++ DLL that is usable by Multicharts

Postby rc76 » 17 Jan 2024

I am wondering whether it is possible to use python to create basic logics, and compile into C++ DLL (maybe using cython or something?) that is usable by Multicharts?

Because C++ is really hard to write code lol Python is a lot easier.

I am wondering whether anyone have used this approach and success?

Any share of experience or approach of using python to create DLL will be super appreciated

HellGhostEvocatorX
Posts: 80
Joined: 10 Feb 2022
Has thanked: 52 times
Been thanked: 11 times

Re: Use python to compile C++ DLL that is usable by Multicharts

Postby HellGhostEvocatorX » 17 Jan 2024

This will probably be possible in principle, but probably only in the multicharts.net application. But I'm wondering if you know Python why you don't use C# directly. C# is more complex but it has its limits. There should also be ironpython for the .net environment, which should offer integration with python. In principle, for performance reasons, it is better to stick with C#.
I only know one reason why I would use Python at all and that is the extensive libraries in the area of ​​machine learning, but Microsoft now offers ml.net there too.
All in all, I would advise against the project because of its complexity, but as you write, it is basically possible.

rc76
Posts: 51
Joined: 14 Oct 2020
Has thanked: 17 times

Re: Use python to compile C++ DLL that is usable by Multicharts

Postby rc76 » 17 Jan 2024

Hmmm, so you mean it is possible to use python to compile C++ DLL that is usable by Multicharts?

User avatar
TJ
Posts: 7743
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Use python to compile C++ DLL that is usable by Multicharts

Postby TJ » 18 Jan 2024

[Advanced Topic] MultiCharts 64 bit Resources (3rd Party)
viewtopic.php?t=10094

amw_775
Posts: 23
Joined: 19 Apr 2020
Has thanked: 1 time
Been thanked: 12 times

Re: Use python to compile C++ DLL that is usable by Multicharts

Postby amw_775 » 04 Feb 2024

Hi

If your using Multicharts.Net you can use the Python.NET package and call oythong code directly
from your scripts. However you will run into All sorts of Memory's type errors because multicharts
is mulithreaded app and python is single threaded. To over come those errors I wrote someC# classes
which handle those issues. Just Google calling Python .net from multithreaded C# app and you will find the results.

If your using Multicharts Powerlanguage version, I have written a Python DLL which basically allows you to
call almost any python function directly from Multicharts Powerlanguage. Im able to call Numpy, scikit learn tensorflow
SFTP uploads and many more python functions. It supports a variety of functions.
If you want to add a custom function to the DLl then it does require some programming knowledge.
PM me for more details.

HellGhostEvocatorX
Posts: 80
Joined: 10 Feb 2022
Has thanked: 52 times
Been thanked: 11 times

Re: Use python to compile C++ DLL that is usable by Multicharts

Postby HellGhostEvocatorX » 07 Feb 2024

Do you use tensorflows for multicharts.net and if so, for what? And in general, why did you do this, C# is already pretty powerful. Did you need any special Python libraries?

amw_775
Posts: 23
Joined: 19 Apr 2020
Has thanked: 1 time
Been thanked: 12 times

Re: Use python to compile C++ DLL that is usable by Multicharts

Postby amw_775 » 19 Feb 2024

Before I was using Powrlanguage a lot for all my strategies so the fastest way to call Python functions was to create a C++ DLL which opens a Python Interpretor and keeps the interpreter Open. MC sends Python functions to the Interpretor and returns the output back to MC. I am using most Python libraries in my functions such as pandas numpy keras tensorflow scikit learn etc.

All my research was done in python and execution on MC so in order to get the same results in live trading as my research I to integrate the two.

Regarding C#, C# is very powerful but MC is not. Most of the .net libraries which allow Python functions such as tensorflow.net, Python.net, Numpy.net, SciSharp.net have very limited features compared to the real Python versions amd their latest bug free versions of these libraries are not compaitble with MCs .net framework 3.5 and 4.0.
You can call the Python Functions directly in #C using Python.net but you need to create many custom C classes to start Python, change Environment Paths , Special code to exit Pythin and running Python.net with Multicharts.NET is a nightmare due to MC.net being Multithreaded so you need more code to make the app threasade. And due to the Interop between C# and Python the code becomes slow. However once you have done all the above its quite seamless to call pretty much any Python function even in .net but it is a slower than calling a function from the DLL designed for MC powerlanguage

amw_775
Posts: 23
Joined: 19 Apr 2020
Has thanked: 1 time
Been thanked: 12 times

Re: Use python to compile C++ DLL that is usable by Multicharts

Postby amw_775 » 19 Feb 2024

Basically there's a solution for both MC Powrlanguage and MC.net
With MC PL you need to be a bit familiar with C++ to call Python
With MC.net you need to be familiar with C# and be ok with slightly slower runtimes

HellGhostEvocatorX
Posts: 80
Joined: 10 Feb 2022
Has thanked: 52 times
Been thanked: 11 times

Re: Use python to compile C++ DLL that is usable by Multicharts

Postby HellGhostEvocatorX » 21 Feb 2024

thank you for the very comprehensive answer!!! But you haven't answered one question yet: what do you use tensorflows for? Because according to multicharts, optimizations due to the "data series" cannot be meaningfully implemented on the graphics card. (there is an extensive contribution to this)

If you have already dealt so extensively with the integration of Python and multicharts, why not make your code available to the developers of multicharts.net (possibly with a financial contribution?). maybe that would be a possible addon for multicharts. Python is a very popular programming language and this option would probably attract many more customers...

janus
Posts: 838
Joined: 25 May 2009
Has thanked: 64 times
Been thanked: 105 times

Re: Use python to compile C++ DLL that is usable by Multicharts

Postby janus » 21 Feb 2024

Also worth looking at Pytorch as well as TensorFlow. They each have their pros and cons, depending on what you want to do. People have used Pytorch with a variety of trading platforms, including MC.

amw_775
Posts: 23
Joined: 19 Apr 2020
Has thanked: 1 time
Been thanked: 12 times

Re: Use python to compile C++ DLL that is usable by Multicharts

Postby amw_775 » 13 Apr 2024

thank you for the very comprehensive answer!!! But you haven't answered one question yet: what do you use tensorflows for? Because according to multicharts, optimizations due to the "data series" cannot be meaningfully implemented on the graphics card. (there is an extensive contribution to this)

If you have already dealt so extensively with the integration of Python and multicharts, why not make your code available to the developers of multicharts.net (possibly with a financial contribution?). maybe that would be a possible addon for multicharts. Python is a very popular programming language and this option would probably attract many more customers...
thank you for the very comprehensive answer!!! But you haven't answered one question yet: what do you use tensorflows for? Because according to multicharts, optimizations due to the "data series" cannot be meaningfully implemented on the graphics card. (there is an extensive contribution to this)

If you have already dealt so extensively with the integration of Python and multicharts, why not make your code available to the developers of multicharts.net (possibly with a financial contribution?). maybe that would be a possible addon for multicharts. Python is a very popular programming language and this option would probably attract many more customers...
I have offered to share my code to Multicharts for their Powerlanguage version and for .net version but I dont' think Python is on hteir priority list so far.

You would use Tensorflow to train a DeepLearning Model using a variety of data ( can be Ooen, high , low,close, RSI, Moving AVerages,etc a bunch of features) to make a trading prediction. ie. ( Buy, Sell,Hold , or 1,-1, 0 )
Based on your prediction from Deeplearning model you decide in multicharts to buy, sell or dont trade.

Regarding Optimizations :
Optimizations can be a bit complicated using python and multicharts due to threading issues.

Also just to clarify, A Multicharts Optimization whereby Multicharts calculates the performance of your strategy based on the buy , sell, etc trading decisions in your multicharts srcipt cannot be run on a GPU. However any C++ Python DLL or Python C Classes can run Optimziations and Fitting of your desired Machine Learning or Deep learning models on a GPU directly from within a powerlanguage signal file. However, you need to have some progrmaming knowledge to get around the threading issues.

For Newby Programmers I would suggest for Opimizations, you should save your MC data series to csv files via your powerlanguage script.

Inside your powerlanguage signal file, you can write

Code: Select all

if barstatus=2 then { Some FileAppend functionality to write the ohlc and your features to a csv file. Take a note of the lcoation where you saved your csv file.}
Run the optimziations by triggering an external python script via powerlanguage or .net.
So you will run the tensorflow/Scikit learn optimization externally through another python script triggered within your powerlanguage signal file.

For example you can add this to your powerlanguage signal file

Code: Select all

if lastbaronchart then { trigger your extenal python script here for optimizations One of the inputs to the external file will be the location where you saved your csv file with the data from MC }
For Powerlanguage use Lua or my Python DLLto run the external script or for .Net use the functionality of "Process" and "ProcessStartInfo" to trigger an external python script optimizations.

If anyone needs help integrating Keras, Tensorflow, etc to MC please PM me.


Return to “MultiCharts”