This profitable trading strategy utilizes the power of MACD, RSI, Stochastic, and Exponential Moving Average (EMA). The combination of these indicators aims to secure consistent returns while minimizing market fluctuations. In the chart, upward trends are depicted in blue, while downward trends are shown in red.
For an in-depth understanding of coding and the opportunity to create your personalized trading systems, please explore here!
Also Read: Decoding Amibroker Backtest Reports
AFL Overview
Parameter | Value |
---|---|
Preferred Timeframe | Daily, Hourly |
Indicators Used | MACD, Stochastic, RSI, EMA |
Buy Condition | RSI period 3 is greater than 50, the difference between MACD and MACD signal line is greater than 0 and also greater than that of the previous candle, the Stochastic %D line is less than 80 and greater than that of the previous candle, and Closing price greater than EMA period 100. |
Sell Condition | RSI period 3 is less than 50, the difference between MACD and MACD signal line is less than 0 and also less than that of the previous candle, the Stochastic %D line is greater than 20 and less than that of the previous candle, Closing price less than EMA period 100. |
Stop Loss | 2.5% |
Targets | No fixed target, Stop and reverse when AFL gives the opposite signal |
Position Size | 300 (fixed) |
Initial Equity | $200,000 |
Brokerage | $50 per order |
Margin | 10% |
AFL Code
// Formula Name: Trend following trading System
// Website: zerobrokerageclub.com
//------------------------------------------------------
_SECTION_BEGIN("Trend following Trading system");
SetTradeDelays( 1, 1, 1, 1 );
SetOption( "InitialEquity", 200000);
SetOption("FuturesMode" ,True);
SetOption("MinShares",1);
SetOption("CommissionMode",2);
SetOption("CommissionAmount",50);
SetOption("AccountMargin",10);
SetOption("RefreshWhenCompleted",True);
SetPositionSize(300,spsShares);
SetOption( "AllowPositionShrinking", True );
BuyPrice=Open;
SellPrice=Open;
ShortPrice=Open;
CoverPrice=Open;
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
SD = StochD(8, 3, 3);
MH = MACD(8, 21) - Signal(8, 21, 5);
trendup = IIf(MH > 0 OR (MH > 0 AND MH > Ref(MH, -1)) AND RSI(3) >50 AND SD < 80 AND SD > Ref(SD, -1) AND ValueWhen(C,O 20 AND SD < Ref(SD, -1) AND ValueWhen(C,O>C), colorRed, trendup);
EMA20=EMA(Close,100);
Buy=MH > 0 OR (MH > 0 AND MH > Ref(MH, -1)) AND RSI(3) >50 AND SD < 80 AND SD > Ref(SD, -1) AND ValueWhen(C,O 20 AND SD < Ref(SD, -1) AND ValueWhen(C,O>C);
Buy = Buy AND Close>EMA20;
Sell=Sell AND Close
Trading Performance Summary
Parameter | Value |
---|---|
Asset | NSE BankNifty |
Initial Capital | $200,000 |
Final Capital | $5,370,094.50 |
Backtest Period | June 9, 2000 to February 26, 2016 |
Timeframe | Daily |
Net Profit Percentage | 2585.05% |
Annual Return Percentage | 22.58% |
Number of Trades | 110 |
Winning Trade Percentage | 28.18% |
Average Holding Period | 30.73 periods |
Max Consecutive Losses | 12 |
Max System Percentage Drawdown | -56.04% |
Max Trade Percentage Drawdown | -62.51% |
You can download the detailed backtest report here.
Please note that if you allow for the compounding of your returns, you may achieve even better results.
Also Read: Excel-Based Moving Average Trading System
Additional Amibroker Settings for Backtesting
To specify lot size and margin requirements, navigate to Symbol → Information in Amibroker. Below is a screenshot illustrating a lot size of 30 and a margin requirement of 10% for Bank Nifty: