Rajandran R Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

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

 
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 Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

What is QuantZilla?

Quantzilla is 75+ hours of code mentoring program designed for noncoders who want to learn the coding program right from designing indicators, scanners, trading...
Rajandran R
58 sec read

Things to Consider While Building a Bracket Order Execution…

Building a Bracket Order Strategy is the most demanded request we got from most of the algomojo traders. This article explains the list of...
Rajandran R
12 min read

PlaceOrder – Multi Broker Exectuion Code Snippets for Amibroker

This tutorial explains how to build a button trading right from scratch and with a click of a button how you can send orders...
Rajandran R
7 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. 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

  10. 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

  11. 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

  12. 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

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

  14. 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