Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in and Co-Creator of Algomojo (Algorithmic Trading Platform for DIY Traders)

Integrating Amibroker with Python COM Server

1 min read

Why Python?
To Create Complex Trading Systems we need to have a complex mathematical models and designing a highly complex mathematical models in amibroker is not so easy. However we can still build complex mathematical models with the help of Python. Python is a open source language similar to C,C++ and it has tons of open source their party modules for financial computings and implementing statistical models. Some of the third party modules use to build complex stuff are numPy,sciPy,pandas. You can google more to know about these statistical packages.

So if we are able to Integrate Amibroker with Python then probably it is like creating a gateway towards accessing complex mathematical models in Amibroker

[wp_ad_camp_5]

 

What is Python COM Server?

COM (Component Object model) is used to enable interprocess communication and dynamic object creation in a large range of programming languages. Using Python COM we can create a interface between Amibroker and Python where Amibroker passes the variable and the complex computation is done with the help of python programming. The Python COM Server communicates with the Amibroker OLE object for interprocess communication as shown below.

If you would like to know more about python COM server then access this python COM server tutorial for better explanation

Python Com Server

Installing Python
1)Download Python 2.7 Version for Windows and Install Python2.7
2)Set the Environmental Variable,Now Goto Start->My Computer ->Right Click and Select Properties->Advance Settings ->Goto Advance Tab and in System Variable enter the Variable Name : PYTHONPATH and variable value <strong>C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk;</strong>
Python Environmental Settings

Intetrating Amibroker with Python COM Sever

Here Iam going to demonstate the AFL code by Bruce Peterson on Integrating Amibroker with Python using IIR Filter example. IIR stands for Infinite impulse response (IIR) is a property applying to many linear time-invariant systems most commonly used in digital and electronic filters.

Steps to Follow

1)Download Python-AFL Set and Unzip it
2)Copy the file iir.py to \\python2.7\\bin\\ folder. And execute the file with the command python iir.py as shown below
Python Com File Execution
3)Copy the Python AFL.afl file and paste the file in \\Amibroker\\Formulas\\Basic Charts Folder
4)Open a New Blank Chart and apply Python AFL.afl to it. You should be able to see IIR(Infinite Impulse Response) and DEMA lines over the Candlesticks where the IIR is computed with the help of Python COM as shown below

Nifty IIR2

Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in and Co-Creator of Algomojo (Algorithmic Trading Platform for DIY Traders)

Plotting Day Wise Equity Curve using Amibroker

We know that Amibroker provides an equity curve for the whole strategy. Is there a way where we can build a simple Day Wise...
Rajandran R
1 min read

Simple Open Range Breakout Trading System with Exploration –…

Opening Range is very often a measure of security high and low generally monitored by breakout traders to gauge the sentiment of the market....
Rajandran R
5 min read

Range Filter – Trading Strategy – Amibroker – Better…

Range Filter is a non-ATR-based trend following strategy inspired by Tradingview Pinescript coder - DonovanWall. According to him, Range Filter is an experimental study...
Rajandran R
4 min read

28 Replies to “Integrating Amibroker with Python COM Server”

  1. Hi rajendran sir .I am u r big fan. Watching u r live chart for 1 year learnt lot from it. your free live site is not working today 10-04-2014.kindly resolve them sir…

  2. Hi, thanks for the post.

    I am only able to return string or number back to amibroker. Not able to return the list.

    Kindly help. Below is my python return function

    outlist = 140
    return outlist # it works

    outlist = [140,141]
    return outlist # Amibroker shows error

    I am plotting outlist[0] in both cases.

  3. Does this Python Integration thing Work with AmiBroker 5.6???? Looking for an affirmative reply!!!!!!!!!

  4. how do i copy that iir.py file into the Python bin folder pls? I can’t see a bin folder. Only Python27/ DLLS, DOX, Include, Lib, libs, scripts, tcl and Tools. Python2.7 is an application without a bin folder… thank you

        1. You need to Install the following Python Libraries.

          — numpy-MKL-1.8.2.win-amd64-py2.7.exe
          — statsmodels-0.7.0-4b55fa4.win-amd64-py2.7.exe
          — pandas-0.13.0.win-amd64-py2.7.exe
          — patsy-0.2.1-1_py27.exe
          — python-dateutil-1.5.win-amd64-py2.7.exe
          — scipy-0.14.0.win-amd64-py2.7.exe

          1. Now where do I get it? Would it be available as a single package, or each needs to be downloaded differently?

  5. May I use Anaconda Python Package instead of Python 2.7 for Windows?

    I am sorry. I am not familiar with Windows.

    In the code:
    _reg_clsid_=”{25F32489-9E84-4D9F-8AEB-44DC9B528405}”

    Where do I get this id?

    1. Havent tested with Anaconda Python but if it supports com server then possibly you can do that. I had choosen the id as random however you can use the function

      _reg_clsid_ = pythoncom.CreateGuid()

      so that the system chooses new GUID for you 🙂

  6. Hi Mr Rajendran

    Im getting Com/Handle object is null in the AFL at this line SmValue = MyObj.IIR2(Close,Coef0,Coef1,Coef2);

      1. Hi Rajendran,

        Even after registering python com server, I am still getting the error
        Com/Handle object is null in the AFL at this line SmValue = MyObj.IIR2(Close,Coef0,Coef1,Coef2); Please help.

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More