Amibroker AFL: สอนขั้นตอนแบบ Step By Step ตอนที่ 1

Amibroker ถูกพิจารณาว่าเป็นหนึ่งในเครื่องมือที่ดีที่สุดสำหรับเทรดเดอร์ เป็นที่รู้จักอย่างกว้างขวางในโลก และสำหรับทุกสาย ไม่ว่าจะเป็นสาย Discretionary และ System Traders โดยเครื่องมือมาพร้อมด้วยเครื่องมือที่จัดว่า มีพลังในการ Backtest และ สามารถ Optimization engine แยกออกจากฟังก์ชันของชาร์ตที่ใช้ปกติ มีส่วนของเขียน Custom Indicator เอง และสร้าง Automate Trading system อย่างสมบูรณ์ ออกจาก Amibroker

ในการสร้างระบบเทรดผ่าน Amibroker  เราต้องมีความคุ้นเคยกับภาษาของ Amibroker เราเรียกว่า Amibroker  AFL โดยเป็นโปรแกรมมิงขั้นสูง และง่ายมากๆที่เราจะทำความเข้าใจ และเริ่มเขียนพื้นฐานต่างๆ ไม่ว่าจะเป็ใครก็ตามที่ไม่มีความรู้ทางด้านโปรแกรมเลยสามารถเลย ก็สามารถเรียน AFL และไม่จำเป็นต้องเสียค่าใช้จ่ายราคาแพงเพื่อซื้อ AFL ที่ถูกพัฒนามาแล้ว

ในโพสต์นี้ เราจะมาลองเรียนรู้ Amibroker  AFL แบบว่าไม่รู้อะไรเกี่ยวกับมันมาก่อนเลย ด้วยตัวอย่าง และ Code ที่สามารถดาวน์โหลดได้ เรารู้ว่าคุณเตรียมลงโปรแกรมเรียบร้อย และสามารถไปดึง Data จาก Live หรือ Historical Data Feed ได้แล้ว รวมถึงมีความรู้พื้นฐานของเทคนิคอลวิเคราะห์หุ้นมาพอสมควรแล้ว และ ทราบถึงการส่งคำสั่งซื้อขาย เพราะเป็น Pre-requisite สำหรับการเขียน Amibroker Coding

ใน Code นี้ มีคำอธิบาย และสามารถนำไป Copy &Pasted ได้เลย จึงค่อนข้างตรงไปตรงมา และจะเพิ่มความซับซ้อนขึ้นเรื่อยๆในขั้นตอน โดยสามารถ Comment หากมีข้อสงสัยได้ในแต่ละจุด

My First Amibroker AFL: Plotting a line chart

//------------------------------------------------------

//  Formula Name:    Basic Line Chart

//  Author/Uploader: Trading Tuitions

//  E-mail: [email protected]

//  Website: www.tradingtuitions.com

//------------------------------------------------------

 

_SECTION_BEGIN("Basic Line Chart");

Plot(Close,"Price",color=colorBlue,style=styleLine);

_SECTION_END();

 

Plotting a Candlestick chart

//------------------------------------------------------

//  Formula Name:    Basic Candlestick Chart

//  Author/Uploader: Trading Tuitions

//  E-mail: [email protected]

//  Website:

//------------------------------------------------------

 

_SECTION_BEGIN("Basic Candlestick Chart");

Plot(Close,"Price",style=styleCandle);

_SECTION_END();

 

Plotting a Bar Chart

//------------------------------------------------------

//  Formula Name:    Basic Bar Chart

//  Author/Uploader: Trading Tuitions

//  E-mail: [email protected]

//  Website: www.tradingtuitions.com

//------------------------------------------------------

 

_SECTION_BEGIN("Basic Bar Chart");

Plot(Close,"Price",color=colorBlue,style=styleBar);

_SECTION_END();

 

 

Plotting price with volume

//------------------------------------------------------

//

//  Formula Name:    Price with Volume

//  Author/Uploader: Trading Tuitions

//  E-mail: [email protected]

//  Website: www.tradingtuitions.com

//------------------------------------------------------

 

_SECTION_BEGIN("Price");

Plot( C, "Close", colorDefault,styleCandle );

_SECTION_END();

 

_SECTION_BEGIN("Volume");

Plot( Volume, "Volume", color=colorGrey40, ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick, maskHistogram  ) );

_SECTION_END();

 

 

Customizing chart title

//------------------------------------------------------

//

//  Formula Name:    Displaying Chart Title

//  Author/Uploader: Trading Tuitions

//  E-mail: [email protected]

//  Website: www.tradingtuitions.com

//------------------------------------------------------

 

_SECTION_BEGIN("Chart with Title");

SetChartOptions(0,chartShowArrows|chartShowDates);

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C ));

Plot(Close,"Price",color=colorBlue,style=styleCandle);

_SECTION_END();

หวังว่าเราจะมีความสะดวกกับการนำพื้นฐานของ Syntax ของ AFL ขอให้ลองด้วยตัวเองบน Amibroker และพยายามท้าทายตัวเองด้วยการเพิ่ม Parameter อีกเล็กน้อยเข้าไปในแต่ละฟังก์ชัน และสังเกตที่การเปลี่ยนแปลงที่ปรากฏบนชาร์ตหุ้น และติดตามบทเรียนในภาค 2 ต่อไป

ที่มา http://tradingtuitions.com/amibroker-afl-step-by-step-tutorial-part-1

สมาคมโปรแกรมเมอร์ไทยสนับสนุนการเรียน Financial Engineering และสอนการใช้งาน Ami Broker ผ่านทาง Course FINANCIAL ENGINEERING BOOTCAMP โดยสามารถดูรายละเอียดและลงทะเบียนได้เลย