Hi, I am looking for some advice from you guys or even an appointment to a convention that I am not aware.
Actually, I work with 2 different brokers (probably 3 in the future) and each one has its own trading platform. As Amibroker and AFL are becoming an essential tool for my trading strategies I want to focus my efforts in Amibroker to study, create strategies and process buy/sell signals and send it to the trading platform.
About this last part. What has been the most effective solution for you?
I already saw a topic about MT4, but this question goes far beyond. As suggested, I also thought to write a csv file and read from the brokers platform. Therefore, it seems to be a very fragile solution. Anyway. Is there any convention to do this? What does the developer suggest?
This topic can benefit anyone but to elucidate my particular matter, I trade only futures. The platforms are Metatrader 5 (Brazil and US) and TWS (US). I use IQFeed (very consistent and rich database by the way).
There are probably hundreds of posts, you need to go through a majority of them.
Also cite the thread/post you visited and what you found unanswered so that specific point can be discussed further rather than generalizations.
Actually, I got the quotations. I tried COM solution and have success at comparing IQFeed quotation to the broker's platform. The documentation is easy to understand and it is fast to implement. Therefore, my problem is that I can't find how to get the real time buy/sell signals from Amibroker. Is there any object that carries this information? Am I missing anything?
DDE can't solve my problem. Can DLL?
I had seen the MT4 post. In my point of view a poor solution (create a text file on communication), but maybe the only one I have.
Well, as I got no solution here. I payed a coder. For future reference are two very useful libraries called Redis and ZeroMQ. They make the implementation of a bridge very fast and easy. You can use in your DLL and share data to C++, Python and Mql (Metatrader 4 and 5) and other many languages supported. Who knows AFL in the future? Would be a simple way to communicate Amibroker with everything else. If anyone is interested. I am creating an order manager in Python that will receive the buy/sell signals from Amibroker (by a .csv I need to implement) and send it to TWS, Metatrader 5, and many others by socket (those libraries I quoted).
Actually, I payed to connect Python to Metatrader via socket (the libraries above). The point was "how to connect Amibroker to Metatrader, Saxo Bank, etc.". After all, my solution was Amibroker talks to Python app and Python app talks to the broker's platform. This Python app will provide connection consistency and gather the daily result. Python app will be a kind of "order, position and result manager".
The AFL code I agree with you I already got some formulas that I am editing. I am studying just how to implement it to be more consistent and trustful.
About its delay:
Sending orders manually from Python...
Time to the Broker receive the order: 0.25 milliseconds to 3.51 milliseconds
Get the order ID in Python (market order executed): 0.73 seconds to 2.23 seconds
Automated from Amibroker:
Well. As we know r/w files is not the fastest solution. And the type of storage you are using (HD or SSD) needs to be considered. I have chosen this option because my strategies don't demand timing.
Anyway. Setting the thread to wait 1 second it takes 3 to 7 seconds from the time of buy/sell signal written by Amibroker till Python gets the order's ID. I need to adjust the time units to provide a more precise result.
Well, works for me.
This test above was made for Metatrater 5.
For timming you really should code a DLL to do this. ZeroMQ and Redis will be very useful to Metatrader. For TWS you can use either ibcontroller in AFL or their C++ API (very intuitive) in DLL. It would allow you to do more things such as draw your daily results from many brokers.
Off course, this is just my opinion based on my searches until now.
What? I don't know who wrote you those "python" parts, but anything that runs locally (not over the Internet) even when using ordinary files should be working well below 1 second (I mean less than blink of an eye).
The only thing that will take time is to having your broker to accept and fill the order. Actually if that is limit order it may not be filled at all for long time (limit not reached or lack of liquidity). And no you don't need DLLs for auto-trading. And you don't need waiting. If you are using any kind of Sleep() in the formula you are doing it wrong.
And to the original poster: I don't know exactly what problem you have. You can have data from IQFeed using official plugin and trade using Interactive Broker interface. Automated trading and quote feed are independent. Data are delivered by data plugins (DLLs). Automated trading is handled by OLE/COM (see IBController publicly released sources to see how it is done). It can also be done via REST APIs if your broker allows that.
The original problem is how to integrate Amibroker to any broker's accredited platform. Not all brokers provide REST APIs, specially in Brazil and other emerging countries that I am investing. Usually what happens is a brokers accredit an existing platform to work as a mediator (IE. Metatrader). My goal is to build a solution to talk to those mediators. Via baskets, sockets, etc.
So, the solution I propose is to have a forwarder (Python, C++ whatever) between Amibroker and those platforms which receives the Amibroker buy/sell signals and send it to the broker. The idea behind this forwarder is having an administrator to assure the connection quality and also get order status and display real time result charts. Think is a bad idea?
The 1 second wait was just for a silly delay test. But, yes, there is a sleep() function inside a loop waiting for the file to be completely used for Amibroker. My concern is reading a file while Amibroker is still writting into it. Is it wrong?
Finally and the most important. I got very curious about OLE/COM solution. Would be perfect. What object manages buy/sell signals? How can I get them?
I think you might have mixed up two things here. Atleast from what I read. Corrcet me if I'm wrong.
Firstly, COM/OLE model works in Server - Client way, so in very few words, one should be prudent in its application.
It is very simple to write your COM object, register it and call it from AB whenever a signal is generated.
This way there is no delay, your program will get signals and then you can pass them to the Trading Platform.
In this scenario, AB is the client and your Program acts as server.
The role of server and client can't be reversed, it will then pile up on flaws.
Incase you to interact with AB, say, you want to run all active explorations from your program,
at that time create an object of AB and invoke relevant methods.
AB = new ActiveXObject( "Broker.Application" ); // creates AmiBroker object
NewA = AB.AnalysisDocs.Open( "C:\\analysis1.apx" ); // opens previously saved analysis project file
if ( NewA )
NewA.Run( 2 ); // start backtest asynchronously
while ( NewA.IsBusy ) WScript.Sleep( 500 ); // check IsBusy every 0.5 second
NewA.Export( "test.html" ); // export result list to HTML file
WScript.echo( "Completed" );
NewA.Close(); // close new Analysis
catch ( err )
WScript.echo( "Exception: " + err.message ); // display error that may occur
This makes sense having AB as the server and your program as the client.
Both can work together, that is each running application, instantiating the others object and invoking functions, provided the role for each object is well thought out.
At First. Thank you for taking your time in this topic. Things started to make sense.
You are right! I completely misunderstood it. Studying a little of the IBController code I got what you are talking about.
It is exactly what I need to do. I need no csv as I could do this way.
But one thing is not clear yet. If a have many other formulas working at the same time and same COM communication. How exactly it will be managed? Is there any risk to lose information from and buy/sell signals?
Study IBController. It handles multiple orders. You should just use kind of "OrderID" so you can keep track of different orders from different formulas. COM/OLE is serialized so there is no re-entrancy risk (one call to COM/OLE would need to be completed before next one is handled)