Method to design real-time controller for cTrader c# application integration

1 次查看(过去 30 天)
Hi all,
I am just becoming familiar with MATLAB and Simulink and wanted to ask for advice on which development tools and techniques to use to achive my development task.
My goal is to use MATLAB to design a controller to commmand a cTrader expert advisor.
In a nutshell the specification for the MATLAB component comprises
  • receive price and volume information from cTrader. Frequency up to about 100Hz.
  • receive status information from the trading account.
  • analyse the data
  • derive state transsitions following statemachine logic
  • derive buy and sell decisions
  • send commands to cTrader c# interface and verify execution
  • inform the user about the state of trading
  • test the implemented strategies agains historic data
So what I am am looking for is a real time controller with a user interface running in MATLAB environment receiving and sending data to the c# expert advisor running in cTrader.
My current questions are:
How do I send data like price or status information from c# expert advisor to MATLAB most efficiently? UDP or TCP would be an option to send for example JSON formated datagrams, but maybe there is a better way?
If UDP/TCP is a good solution where do I place the receiver? It could be defined in a MATLAB script or a simulink instrument controll block, but how do I decode the JSON data an feed them in a buffer?
How do I setup Simulink to run as a controller in real time? I am aware of toolboxes like "simulink real-time", "instrument control toolbox", "Guide" is an unknown to me at this time, so I am not familiar which toolbox I need to be able to design a controller for example with stateflow and make a visual user interface to be able to interact. So I would be glad for some advice in which direction to work.
How to store historic data to backtest strategies? Another, not neccessarily real time task, would be to store historic data and check the controller against these to test for performance. Any advice on which database to use and how to efficently feed them to simulink for testruns?
These questions are very diverse. Since I am at the begining of this project directions to best practices would be of great value. Also more detailed solutions for individual problems that I may be able to adapt would help.
Thank you all for you assistance!
Cheers

回答(1 个)

Aditya Singh
Aditya Singh 2023-6-15
Hello,
To my understanding you are trying to develop an application and wants to get some resources to get started.
Communication between cTrader and MATLAB:
  • As you mentioned, UDP/TCP is a good option for sending data between cTrader and MATLAB. You can explore the UDP interface and the UDP send and receive block.
  • To decode the JSON data in MATLAB, you can either use built-in functions like “jsondecode”, or use open-source libraries like “jsonlab”.
Real-time control using Simulink:
  • Simulink Real-Time is the toolbox you need to run Simulink models in real-time on a Windows PC or real-time target machine. You can use it to design your controller with Stateflow.
  • To create a user interface for your controller, you can use MATLAB's App Designer which is included in MATLAB. You can create interactive apps with clickable buttons, input fields, sliders, and other features to interact with your controller.
Storing historic data for backtesting:
  • MATLAB has built-in functions like “xlsread” or “readtable” that can read data from Excel files or CSV files. You can use these functions to load your historic data into MATLAB for backtesting.
  • If you have a large amount of data, you may want to consider using a database like MySQL or SQLite. MATLAB has built-in functions like “sqlread” and “sqlwrite” to communicate with these databases.
For more information and examples, kindly refer to:
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Transaction Cost Analysis 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by