Rajandran R Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, 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. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

SDA2 Trend Trading System Verion 2.0 AFL code

2 min read

Earlier on October 26th, 2010 SDA2 Trend Trading System is introduced in Marketcalls. After revising my old strategy with better improvements releasing the newer version of the SDA2 Trend trading system(version 2.0). This version is more optimized for Long Only Signals (Short Signals are treated as an exit from the long position and stay away from the market). In the older version, the SDA2 trading system won’t perform well if there is any gap up or gap down in the trading instrument. The new version overcomes those flaws and it is more optimized towards those Gap Up/Gap Down. The trading system is tested in both Amibroker 5.4 and 5.5 versions.

 
The Above chart is for Educational Purpose only not for any kind of Buy or Sell Recommendation in Nifty

Now Upper Channel and Lower Channel are built using the formula

Derived=WMA(WMA(WMA(((H+L)/2)+(O-C),2),2),2);
i=WMA(Derived,3);
Upper=(Derived+StDev(Derived,7))+ATR(2)/1.5;
Lower=(Derived-StDev(Derived,7))-ATR(2)/1;

Buy and Sell Condition

Buy Condition : Buy the Next day open when there is a Buy signal on the chart.
Sell Condition : Sell the Next day open when there is a Sell Signal on the chart.

The Colour of the Candlestick will be toggled between Green and Red each time when the candlestick close breaks the Upper Channel or the low of the breaks the Lower Channel. This effort minimizes the maximum risk of any long position.

color=IIf(BarsSince(Cross(Lower,Low))>
BarsSince(Cross(C,Upper)), colorBrightGreen,colorRed);

The trading system had been backtested for nifty during the period 1st Jan 2000 to 16th Mar 2012. And the Results are shown Below

Trading System Statistics

Equity Curve

Profit Distribution

Profit Table for SDA2 Ver 2

SDA2 – Trend Trading System 2.0 – Amibroker AFL Code

_SECTION_BEGIN("SDA2 Channel Trading System ver 2.0");

/* Coded By : Rajandran R
   WebSite: www.marketcalls.in 

Earlier during October 26th, 2010 SDA2 Trend Trading System  is introduced in marketcalls.
After revising my old strategy( which contains too many flaws in the system) releasing the 
newer Version of SDA2 Trend trading system(Version 2.0).This Version is more optimized for 
Long Only Signals (Short Signals are treated as exit from the long position AND stay away 
from the market). In the older Version the SDA2 trading system wont perform good if there 
is any gap up OR gap down in the trading instrument. The new Version overcomes those flaw 
AND it is more optimized towards those Gap Up/Gap Down.  */


SetChartOptions(0,chartShowArrows|chartShowDates);
trailing=0;
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
SetTradeDelays( 1, 1, 1, 1 );
BuyPrice = Open;
SellPrice = Open;

Derived=WMA(WMA(WMA(((H+L)/2)+(O-C),2),2),2); 
i=WMA(Derived,3); 
Upper=(Derived+StDev(Derived,7))+ATR(2)/1.5; 
Lower=(Derived-StDev(Derived,7))-ATR(2)/1; 

color=IIf(BarsSince(Cross(Lower,Low))> 
BarsSince(Cross(C,Upper)), colorBrightGreen,colorRed); 
Plot(C,"",color,64); 
Plot(Upper,"upper band",colorGreen); 
Plot(Lower,"lower band",colorDarkRed); 

/* Buy or Sell Condition */
Buy = Cross(Close,Upper);
Sell = Cross(Lower,Low);
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Cover=Buy;
Short=Sell;


Filter = Buy OR Sell;
/* Exploration Parameters */
AddTextColumn( FullName(), "Company Name" );
AddColumn( Buy, "Buy", 1 );
AddColumn( Sell, "Sell", 1 );
AddColumn( C, "Close", 1.3 );
AddColumn( H, "High", 1.3 );
AddColumn( Lower, "Lower Band", 1.3 );
AddColumn( Upper, "Upper Band", 1.3 );

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45); 
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                      
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);


_SECTION_END();

/*_SECTION_BEGIN("WaterMark");
GfxSetOverlayMode(1);
GfxSelectFont("Tahoma", Status("pxheight")/12 );
GfxSetTextAlign( 6 );// center alignment
GfxSetTextColor( ColorHSB( 42, 42, 42 ) );
GfxSetBkMode(0); // transparent
GfxTextOut( "Budget 2012", Status("pxwidth")/4, Status("pxheight")/4 ); //you can change your own display name
GfxSelectFont("Tahoma", Status("pxheight")/12 );
GfxTextOut( " www.marketcalls.in", Status("pxwidth")/4, Status("pxheight")/4+90 ); //you can change your own display name
_SECTION_END(); */

Rajandran R Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, 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. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

Pivot Reversal Strategy – Tradingview Pinescript to Amibroker AFL…

Pivot Reversal Strategy is a popular in-built strategy in Tradingview Platform. Here I had attempted to convert the pinescript v5 to Amibroker AFL Code....
Rajandran R
3 min read

Interactive Brokers – Smart Order Chart Trading Module using…

The IB Controller is an interface designed to facilitate automatic trading with AmiBroker and Interactive Brokers (IB) TWS (Trader Workstation). It serves as a...
Rajandran R
8 min read

Introducing OpenAlgo V1.0: The Ultimate Open-Source Algorithmic Trading Framework…

OpenAlgo V1.0 is an open-source algorithmic trading platform to automate your trading strategies using Amibroker, Tradingview, Metatrader, Python etc. Designed with the modern trader...
Rajandran R
2 min read

3 Replies to “SDA2 Trend Trading System Verion 2.0 AFL code”

  1. Dear Rajandran,

    Thanks for the AFL. One request please- Can I get the AFL of Camarilla calculation on Intra day as well as for the EOD please.

    Regards,

    Veer

Leave a Reply

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