Amibroker AFL Coding - Webinar
-
Upload
rajandran-r -
Category
Business
-
view
3.147 -
download
34
Transcript of Amibroker AFL Coding - Webinar
www.marketcalls.in Customer Support : 09738383344
Disclaimer
▪ TRADING FUTURES AND OPTIONS INVOLVES SUBSTANTIAL AMOUNT OF RISK OF LOSS AND IS NOT SUITABLE FOR ALL INVESTORS
▪ PAST PERFORMANCE IS NOT NECESSARILY INDICATIVE OF FUTURE RESULTS.
▪ AMIBROKER IS REGISTERED TRADEMARK OF AMIBROKER.COM.
▪ WE ARE NEITHER ASSOCIATED WITH THE ABOVE TRADEMARK OWNERS NOR DO WE REPRESENT THEM IN ANY MANNER. WE ARE NOT OFFERING AMIBROKER PLATFORM FOR SALE ON OUR WEBSITE / IN OUR OFFICE.
www.marketcalls.in Customer Support : 09738383344
About Me
▪ Running a Financial Start-up
▪ Author of www.marketcalls.in since Sep 2007
▪ Trading System Designer
▪ System Trader & Financial Blogger
▪ More www.marketcalls.in/about
www.marketcalls.in Customer Support : 09738383344
No Subjective Interpretation
▪ No Trend Lines▪ No Gann▪ No Fibonacci▪ No Elliot wave▪ No Trading Patterns▪ No Divergence▪ No News▪ No Fundamentals
www.marketcalls.in Customer Support : 09738383344
Trading Analysis Software
Amibroker
Metastock
Ninjatrader
Esignal Multicharts
www.marketcalls.in Customer Support : 09738383344
Free Data Providers for Amibroker
Google Finance(EOD,
Intraday)
Yahoo Finance(EOD,
Intraday, Fundamental
)
ASCII(csv, txt)
MSN Money(EOD)
Quandl(EOD)
www.marketcalls.in Customer Support : 09738383344
Subscription based Data Providers
Globaldatafeeds
Neotradeanalytics
Esignal(Platform + Data feed)
DTN IQFeedInteractive
Brokers(Brokerage + Data feed )
CQG
www.marketcalls.in Customer Support : 09738383344
Why Amibroker?
▪ Ease of Use▪ High Speed Execution▪ Supports Autotrading (Symphony Fintech, Interactive Brokers)▪ Custom Timeframe▪ Multi Timeframe Support▪ Backtesting Optimization Walk Forward Testing▪ Scanning and Exploration▪ Custom Indicators (AFL Programming)
www.marketcalls.in Customer Support : 09738383344
Amibroker Formula Language (AFL)
▪ AFL is Vector Programming Language
▪ Write your own Custom Indicators, Scanners, Exploration and custom commentaries
▪ Write your own Trading System Rules
www.marketcalls.in Customer Support : 09738383344
AFL Tokens
▪ Identifiers ▪ Constants▪ String – literals▪ Operators▪ Punctuators (Separators)
www.marketcalls.in Customer Support : 09738383344
Built-in Identifiers
Identifiers Abbreviation
Open OHigh HLow LClose CVolume VOpenInt OIAvg
www.marketcalls.in Customer Support : 09738383344
Comparison Operators
Symbol Meaning
< Less than > Greater than <= Less than or equal to >= Greater than or
equal to == Equal to ! Not != Not Equal to
www.marketcalls.in Customer Support : 09738383344
Arithmetic and Logical Operators
Symbol Meaning
+ Addition - Subtraction * Multiplication / Division % Modulus ^ Exponentiation | & Bitwise OR Bitwise
AND
Symbol MeaningNOT Logical NOTAND Logical ANDOR Logical OR
www.marketcalls.in Customer Support : 09738383344
Sample Built-in Functions
▪ RSI(14) - 14 period RSI▪ MACD() - Default MACD ▪ EMA(c,10) - 10 period EMA ▪ Ref(C, -1 ) - Previous Close Array▪ MA(C,25) - 25 period Simple MA▪ Cross(C, EMA(c10)) - Crossover Functions▪ Barindex() - returns total number of bars (similar to
Barcount)More at http://www.amibroker.com/guide/a_funref.html
www.marketcalls.in Customer Support : 09738383344
AFL Arrays Example 1
Day 1 2 3 4 5 6 7 8 9 10
1 Open 123 124 121 126 124 129 133 132 135 1372 High 124 127 125 129 125 129 135 135 137 1293 Low 120 121 119 120 121 124 130 128 131 1274 Close 123 126 124 128 125 125 131 130 132 1285 Volume 8310 3021 5325 2834 1432 5666 7847 555 6749 34566 Ref(C-1) NULL 123 126 124 128 125 125 131 130 132
www.marketcalls.in Customer Support : 09738383344
Pattern Detection Functions
▪ Inside()▪ Outside()▪ GapUp()▪ GapDown()
Gives a "1" or “True” when a inside Pattern occurs.Gives "0" or “False” otherwise.
www.marketcalls.in Customer Support : 09738383344
Plot Functions
▪ Plot()▪ PlotOHLC()▪ PlotShapes()
Demo
www.marketcalls.in Customer Support : 09738383344
Plot Arrows
/* Plot Buy and Sell Signal Arrows */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);
www.marketcalls.in Customer Support : 09738383344
AFL Arrays Example 2
Day 1 2 3 4 5 6 7 8 9 10
1 Open 123 124 121 126 124 129 133 132 135 1372 BeginValue( Open ) 124 124 124 124 124 124 124 124 124 1243 EndValue( Open ) 132 132 132 132 132 132 132 132 132 1324 SelectedValue(Open ) 121 121 121 121 121 121 121 121 121 1215 LastValue( Open ) 137 137 137 137 137 137 137 137 137 1376 Close 122 126 123 128 125 125 131 130 132 128
www.marketcalls.in Customer Support : 09738383344
Lowest/Highest Functions
▪ LLV()▪ HHV()▪ Lowest()▪ Highest()
▪ LLV(C,10)▪ HHV(c,10)▪ Lowest( RSI(14))▪ Highest( MFI(14) )
DEMO
www.marketcalls.in Customer Support : 09738383344
Alerts (in built and 3rd Party)
▪ Sound Alert▪ Voice Alert▪ Email Alert
▪ Alertif() , say() functions
▪ Twitter Alert [tweetymail]▪ Trade Sender ▪ Push Bullet [http api]
www.marketcalls.in Customer Support : 09738383344
Param Control Functions
▪ Param()▪ Paramcolor()▪ Paramstr()▪ ParamTime()▪ ParamDate()▪ ParamField()
▪ ParamTrigger()▪ ParamList()▪ ParamToggle()▪ ParamStyle()
DEMO
www.marketcalls.in Customer Support : 09738383344
Built-in Trading Logic Identifiers
▪ Buy ▪ Sell▪ Short▪ Cover
DEMO
www.marketcalls.in Customer Support : 09738383344
Simple Exploration
Filter =1;AddColumn(RSI(10),"RSI", 1.2);AddColumn(EMA(C,10),"EMA10",1.2);AddColumn(v,"volume",1);
www.marketcalls.in Customer Support : 09738383344
Understanding different IF Functions
▪ IF▪ IIF▪ WriteIF
▪ If(buy[barcount-1] == true)▪ Color =
iif(RSI(14)>70,colorgreen,colorred)
www.marketcalls.in Customer Support : 09738383344
Multitimeframe Functions
Switching Timeframe
• TimeFrameSet• TimeFrameRestor
e
Compress/Expand• TimeFrameCompr
ess• TimeFrameExpan
d
Access Diff Timeframe
• TimeFrameGetPrice
www.marketcalls.in Customer Support : 09738383344
Multimeframe Getprice
TimeFrameGetPrice( "O", inWeekly, -1 ) // gives you previous week Open price TimeFrameGetPrice( "C", inWeekly, -3 ) // gives you weekly Close price 3 weeks ago TimeFrameGetPrice( "H", inWeekly, -2 ) // gives you weekly High price 2 weeks ago TimeFrameGetPrice( "O", inWeekly, 0 ) // gives you this week Open price. TimeFrameGetPrice( "H", inDaily, -1 ) // gives previous Day High when working on intraday data
www.marketcalls.in Customer Support : 09738383344
Components of Trading System
Initial Paramete
rsTrading Logic
Position Size
Signals & Alerts
Dashboard
www.marketcalls.in Customer Support : 09738383344
Simple Trading System
SetTradeDelays(1,1,1,1);SetPositionSize(100,spsShares);
par1 = param("par1",10,1,50,1);par2 = param("par2",15,1,50,1);sema = EMA(C,par1);lema = EMA(C,par2);
Buy = Cross(sema,lema);Sell = Cross(lema,sema);
www.marketcalls.in Customer Support : 09738383344
Position Size & Trade Delay
▪ SetTradeDelays(1,1,1,1); // Trade Delay of 1 Bar▪ SetPositionSize( 100, spsShares ); // 100 shares
by default ▪ SetPositionSize( 10, spsPercentofEquity );
//Percentage Equity▪ SetPositionSize( 100000, spsValue ); // Fixed
Amount
http://www.amibroker.com/kb/2014/10/12/position-sizing-based-on-risk/
www.marketcalls.in Customer Support : 09738383344
Trading System Design Cycle
Analysis
Design
ImplementTesting
Evaluate
www.marketcalls.in Customer Support : 09738383344
Time Based Trading Rules
▪ Timenum() Function▪ Mostly Rules for Intraday
DEMO
www.marketcalls.in Customer Support : 09738383344
Foreign Functions
▪ Retrieve Data from other Symbols
DEMO
www.marketcalls.in Customer Support : 09738383344
Offers to Webinar Participants
Globaldatafeeds
▪ Take Data Subscription of NSE MCX NSE FX
www.marketcalls.in/services
Contact Customer Support 09738383344 Support Timings – (9a.m – 6p.m)Mon - Fri
Tradejini ( Discount Broker )▪ Get 50% of Brokerage
Reversal upto your purchased product
▪ Rs 20 Per Order▪ Trade in NSE, BSE, MCX,
MCX-SX▪ Nest/Now Trading
Terminal
www.marketcalls.in Customer Support : 09738383344
Recommended Trading Books
Beginners• Introduction to Amibroker – 2nd Edition – Howard Bandy• Amibroker User Guide
Intermediate• Quantitative Trading Systems – Howard Bandy• Modelling Trading System Performance – Howard Bandy
Experts• Mean Reversion Trading Systems – Howard Bandy• Quantitative Technical Analysis – Howard Bandy
www.marketcalls.in Customer Support : 09738383344
AFL Library & Forums
▪ Amibroker Librarywww.amibroker.com/library▪ Marketcalls Librarywww.marketcalls.in/library▪ Wisestocktrader Librarywww.wisestocktrader.com
▪ Amibroker Yahoo Groups▪ Traderji Forum▪ Inditraders Forum▪ Marketcalls Community