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)

Two Pole Butterworth Filter – Amibroker AFL code

46 sec read

Two Pole Butterworth Filter is one of the common topics found in Digital Signal Processing(DSP). Two Pole Butterworth Filter is used to design a Low Pass Filter with bettter smoothing response. And it is also discussed in Cybernetic Analysis for Stocks and Futures in Chapter 13 – SuperSmoother P.No 191

Here is the Easy Language code from TradeStation. And I had attempted to code the same in Amibroker AFL code.

{2 Pole Butterworth Filter – //// From ‘Cybernetic Analysis for Stocks and Futures’ by John Ehlers //// code compiled by dn
} // plot on a subgraph separate from the price region.

Input: Price((H+L)/2), Period(15);
Var: a1(0), b1(0), coef1(0), coef2(0), coef3(0), Butter(0);

a1=expvalue(-1.414*3.14159/Period);
b1=2*a1*Cosine(1.414*180/Period);
coef2=b1;
coef3=-a1*a1;
coef1=(1-b1+a1*a1)/4;
Butter = coef1*(Price+2*Price[1]+Price[2])+ coef2*Butter[1] + coef3*Butter[2];
If CurrentBar<3 then Butter=Price; Plot1(Butter,"Butter");

Nifty 15min charts – Two Pole Butterworth Filter

[wp_ad_camp_5]

 
In the above charts Two Pole Butterworth Filter is applied and it shows how smooth the butterworth filter is. To check how smooth the filter is you can try and compare with other traditional moving averages like EMA, MA, WMA.

AFL Formula for Plotting Two Pole Butterworth Filter

CutoffPeriod=15;
Shift=0;
coef1=coef2=coef3=coef4=0;

tempReal= atan(1.0);
rad2Deg = 45/tempReal;
deg2Rad = 1.0/ rad2Deg;
pi = atan(1.0)* 4;
a1 = exp(-sqrt(2) * pi / CutoffPeriod);
b1 = 2 * a1 * cos(deg2Rad * sqrt(2) * 180 / CutoffPeriod);

coef2 = b1;
coef3 = -a1 * a1;
coef1 = (1 – b1 + a1 * a1) / 4;
mean=C;

TPBFilter[0]=Null;
up[0]=Null;
down[0]=Null;

for(i = 1; i 3){
TBFilter[i]=coef1 *(mean[i]+2.0*mean[i-1] +mean[i-2])+coef2*TBFilter[i-1]+coef3*TBFilter[i-2];
}else{
TBFilter[i]=mean[i];
}
if(TBFilter[i]>TBFilter[i-1]){
up[i]=TBFilter[i];
up[i-1]=TBFilter[i-1];
}else{
down[i]=TBFilter[i];
down[i-1]=TBFilter[i-1];
}
}

Plot(TBFilter,”TBFilter”,IIf(down==0,colorGreen,colorRed));

Download Two Pole Butterworth Filter AFL Code for Amibroker

Disclaimer : It is just a indicator and not a trading system the Buy and Sell Signals are added for the purpose of identifying turn in the filter.

Here is the video preview of upcoming Super Trend AFL code in Marketcalls
httpv://www.youtube.com/watch?v=WGSBAsGNGnM

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)

Stoploss, Multi Target, and Trailing Stoploss Module – Amibroker…

After Intraday V2.0 Amibroker Module - a readymade drag and drop module to convert any trading strategy into the intraday trading system with alerts,...
Rajandran R
6 min read

Line Trading – Algomojo Automation Module for Amibroker Users

The line Trading Automation tool is designed for Manual traders who want to perform level-based trade execution faster and also bring some advanced trade...
Rajandran R
58 sec read

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

23 Replies to “Two Pole Butterworth Filter – Amibroker AFL code”

  1. What is the procedure of adding AFL code in Amibroker ? Or Where can I found its procedure ?

  2. Hi
    can u please share the corresponding mql4 for gcimt4 for the same indicator……………

  3. Hello sir … which is the best Intraday trading Formula use in intraday trader… i m new in charting…

  4. Sir,
    I am using Amibroker 5.1 Ver. I have Downloaded your Two Pole-Butterworth-Filter-Amibroker-Afl-Code, but it is showing error 29. Pls rectify and give it at your earliest will make many of them with a Great Joy. Also God Bless YOU for your help without expecting anything from the readers. Keep it up. I pray to God “May All Your Dreams Come True In Reality”. Thank You.

  5. I like the 2 pole Butterworth filter. You combine it with price line is fast moving averages to generate good buy and sell signals. Or you can apply swing theory on the waves of the smoothed price.

  6. I looked up the theory on the Butterworth filter and then compared this with MA/EMA etc. This can be effectively used by swing traders as the low and high swing noise is filtered out effectively. Traders, should develop and test their strategy.

  7. Rajandran
    sir !

    nice afl ,thanks lot for sharing! sir i have a one mql4 cod , how can change for AFL, could u tell me please!! thanks a lot!!

  8. Rajandran

    sir !

    i don’t have this ,could u please convert me if u kind sir! thanks a lot!!!!!!!

  9. Rajandran
    sir !
    please if u kindness for , please sir! thanks a lot! here is file,

  10. Hello Sir,

    I am using Amibroker version 5.20, and facing below mentioned error at the time of implementation of indicator.
    ========================================
    Two Pole Butterworth Filter :
    }
    }

    Plot (TBFilter,

    ———-^

    Error 29.

    Variable ‘tbfilter’ used without having been initialized.

    Use ‘Edit Formula’ to correct error”
    =====================================

    It is my kind request to please assist for resolution.

    Regards,
    Hardik

  11. Hello Rajandran Sir,

    Thank you for your quick response.

    Could you please assist, with how to proceed for resolution?
    Because I have tried one by one with each file code mentioned in (v3a.odt, v3b.odt) but neither of them works. If you will elaborate process step by step for resolution, That would be a great help.

    Regards,
    Hardik

  12. Hello Rajandran Sir,

    It would be a great help, if you can assist on query.
    Because I have tried one by one with each file code mentioned in (v3a.odt, v3b.odt) but neither of them works. The code is still showing error for both those files, which you have shared. I am using Amibroker version 5.20.
    Please help/assist.

    Regards,
    Hardik

  13. Hello Rajandran Sir,

    The error is regarding:

    Variable ‘tbfilter’ used without having been initialized.

    if you can assist, that would be a great help.

    Awaiting your response soon.

    Regards,
    Hardik

  14. In what timeframe this can be used and which strategy is best suitable for daily timeframr

  15. Hi Rajandran,

    Many thanks for sharing this indicator with the public. May I know why is the current candle not being painted yet? its like we have to wait until tomorrow for the indi to paint.

Leave a Reply

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