Using AlertIf function to launch external trading bots

Hi all.

I am new here, so, please, go easy. When I first bought Amibroker, I just understood that it could do pretty much everything I needed it to do, but I had no idea how. I'm also not a software engineer. I can code a little bit of TradingView native PineScript language and I'm learning python, but in all honestly, I'm learning by doing.

Anyway, one of the reasons I bought Amibroker was to improve the motivational side of my trading psychology and generate some EOD signals which I would then manually trade, and also some small position intraday forex or crypto scalp trades and I imagined that I could just plug in amibroker to the back end of my broker and away to go.

I'm a few weeks in to learning amibroker and it seems that it is not a case of pluging amibroker into the back end of my broker.

So I'm trying to identify a solution.

Is there a marketplace where people have developed plug-ins for any broker that you might imagine?
If not, I am wondering how other people use Amibroker (outside of backtesting, scanning and exploration)?

The solution I am currently imagining is, code up a bot in Python (once I have learned how to do that), and then use arrays to get buy and sell prices from my strategy, and into the bot I have written.

So, for example;

buysig = C >= 1200;
msg = "With any luck, you should have also opened firefox. This kind of combination of having 2 alertif conditions , one for opening an application and one for sending an email, is how you would set up an autotrading and alert system.";
website = "";
Buy = buysig;
AlertIf(Buy,"EMAIL",msg, 1,1,1);
AlertIf(Buy,"EXEC firefox.exe",website, 1,1,1);

I would use the AlertIf condition, but on line 4 above, where I have set the array is website= "" where barchart is a string, I might instead have website = float, where the float is a value I have derived elsewhere.

Also, if I am trying to attach bracket orders, I might want to have more than 1 float value. So, is there some kind of sequence in which to 'displayText', or would I have to write 1 bot for my buy order price and another for the stops, another to specify what type of order I want etc, so something like this....

OrderType = "limit"
OrderPrice = C - 0.5*ATR(14)
StopPrice = OrderPrice*0.98
Target = OrderPrice*1.04
AlertIf(Buy,"EXEC limitbot.exe",OrderType, 1,1,1);//Where limitbot.exe is a small application I have written in Python or another language to tell my broker what type of order I want
AlertIf(Buy,"EXEC tradeopenpricebot.exe",OrderPrice, 1,1,1);
AlertIf(Buy,"EXEC stoplossbot.exe",StopPrice, 1,1,1);
AlertIf(Buy,"EXEC targetbot.exe",Target, 1,1,1);

Am I going about this the right way, or am I trying to reinvent the wheel?

1 Like

@SpandexMan, I'm not sure if the AlertIf() is the best way to achieve your goal.
It is essential to properly understand how it works and, in particular the significance of the "flags" to enable or bypass the finite state machine logic used to avoid repeated alerts on some conditions.

Anyway, if you are going to experiment a bit, I suggest you write a single bot that will accept command line arguments.
Use some string manipulation functions to "parse" the input to output the orders requested according to the API provided by your broker.

For example you can do it sequencing predefined tokens and values in the passed argument:
"Action Ticker Quantity Units OrderType Price TimeInForce Force OrderId"
(in a way similar to what is doing this 3rd party software).
"BUY MSFT 100 SH MKT 0 GTC 123"
or for a bracket order:
"BUY MSFT 100 SH LBO 256.50 GTC 124|SELL MSFT 100 SH LSO 295.00 GTC 124|SELL MSFT 100 SH SSO 240.00 GTC 124"

Keep in mind that if you expect to handle some advanced orders, you will need to carefully plan the command line syntax, since it may soon become quite complex to parse and manage.
Either way, make sure you debug your bot well, ideally testing it using a "paper" account, since using this system you have no feedback in Amibroker regarding the actual execution of orders.

As you probably know, Amibroker offers a free open source order automation system for Interactive Brokers.

There is already a thread, where users using other brokers are hoping to get a native solution that is easily adaptable to their needs, but given its complexity and that there has been no recent feedback from @Tomasz, I'm afraid that's a feature that we will not see soon!

I hope that some other user, who may have already made something similar, will be able to give you a better and more practical suggestion!

P.S. "Learn by doing" is probably the best way to learn! :clap:


Thanks Beppe, that's really useful.
There's lots here for me to try. I certainly like your idea of manipulating string functions and I think I'm going to spend some time playing with that idea.

Thanks once again.


This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.