6. Indicators FXdreema

#Indicators คืออะไร ?

Indicator เอาไว้ให้เราเห็นภาพว่า ตอนนี้ราคาเป็นเช่นไร ซึ่งถ้าหากเราไม่มีภาพเราจะไม่เข้าใจว่าตอนนี้เทรนด์ขาขึ้นขาลง

Indicators ยังสามารถเป็นแหล่งข้อมูลให้กับ EA ซึ่งก็คือ ค่าตัวเลขที่โปรแกรมคอมพิวเตอร์สามารถเข้าใจได้เท่านั้น

โดยทั่วไปแล้ว Indicator จะทำงานเหมือนักน ซึ่งจะให้ค่าตัวเลขออกมาเรียกว่า  output buffers ( buffers). MetaTrader จะใช้มันเขียนบนกราฟเป็นภาพ

#หา Custom Indicators

คำว่า Custom Indicators – คือเครื่องมือที่เขียนขึ้นเพื่อ MetaTrader ซึ่ง MT4 หรือ MT5 จะมีเครื่องมือพวกนี้ติดมาอยู่แล้วใน :

  • MetaTrader 4: %Data Folder%/MQL4/Indicators/
  • MetaTrader 5: %Data Folder%/MQL5/Indicators/

สามารถหาได้ที่นี่

metatrader open data folder

 

# Indicators สื่อสารกับโปรแกรมอื่นอย่างไร

อย่างที่เรารู้ว่า Indicator เป็นค่า  buffersซึ่งทำให้ EA สามารถอ่านค่าได้ ซึ่งจะเป็นตัวเลข แต่ละตัวก็จะเป็นตัวเลขของแท่งเทียน บนกราฟ ซึ่งจะมีค่าอยู่ เราลองมาดูตัวอย่างของค่า MA กัน Moving Average :

indicators buffers ma

 

แต่ละแท่งจะมี ID ของแท่ง ซึ่งเรียกแท่งใหม่สุดเรียกว่า แท่ง 0 และถัดไปเรียกว่า แท่ง 1,2,3,4 ตามลำดับ ในตัวอย่าง ค่า MA แต่ละแท่งไม่เท่ากัน ดังนี้ :

  •  0 คือ 1.3667
  •  1 คือ 1.3658
  •  2  1.3641

ค่าพวกนี้ก็คือ ค่า Buffer และเอาไปสร้างกราฟในโปรแกรมที่เราเห็นเป็นเส้น

เราสามารถเอาแต่ละค่ามาแสดงเหมือนกับแท่งเทียน

ทีนี้ถ้าหากเราอยากได้ค่าของ indicator มาใช้ EA เราต้องชี้ไปที่ file ชื่อของมัน พร้อมกับค่า Buffer และค่า (0, 1, 2, 3…)

อ่านข้อมูล Buffer เพิ่มเติม

6 Indicators FXdreema หา Buffer

#Custom Indicator มีค่า Buffer อะไรบ้าง ?

เมื่อคุณเพิ่ม custom indicator ในกราฟ คุณจะเห็น parameter เหล่านี้ ไปที่ แถบสี จะเห็นแบบที่แสดงอยู่นี้

6 Indicators FXdreema หา custon indicator ที่มี Buffer

ในนี้มี 3 buffer ซึ่งจะเห็นตัวเลขคือ 0, 1, 2. เดาได้ไหมว่าแต่ละอันคืออะไร:

  • Buffer 0 คือ center line
  • Buffer 1 คือ upper line
  • buffer 2 คือ lower line

#Arrows In Indicators

Indicator บางตัวไม่ได้เป็นเส้น แต่ว่ามีลูกศรขึ้นมา มันเป็นยังไง

Indicator จะดึงข้อมูลจาก  MetaTrader และวาดข้อมูลบนกราฟ ซึ่งจะคล้ายเส้น หรือ histogram หรือ เส้นประ แล้วแต่การวาด :

ซึ่งเราก็ได้รู้แล้วว่า แต่ละ Buffer มีค่าหลายรูปแบบ ตามแท่งเทียนที่อยู่บนกราฟ แล้วเราจะไม่แสดงค่าในแท่งเทียนที่กำหนดได้ไหม เรื่องนี้สามารถทำได้ เมื่อ MT4 เห็นค่า มันจะไม่แสดงอะไรบนกราฟเลย ซึ่งค่านี้เรียกว่า  EMPTY_VALUE เป็นตัวแปรคงที่และเป็นค่าที่ใหญ่ที่สุดเท่าที่จะเป็นไปได้ของแต่ละรุ่น ดังนี้

  • 32 bit (MetaTrader 4): EMPTY_VALUE เท่ากับ 2,147,483,647
  • 64 bit (MetaTrader 5): EMPTY_VALUE เท่ากับ 9,223,372,036,854,775,807

ลองคิดดูว่าถ้าหากมีการใส่  EMPTY_VALUE ในกราฟเราจะไม่เห็นอะไรเลย บนกราฟ

 

#Arrows และ Lines บนกราฟ แต่ว่าไม่มี Buffer?

เป็นไปได้ไหม ที่มีเส้น แต่ไม่มีค่า Buffer ของ Indicator แน่นอนว่าได้ ซึ่งจะเป็นพวก ลากเส้น หรือลูกศร เช่น เส้น Trend Line ที่เราลากเอามาใส่ ซึ่งกรณีนี้จะไม่สามารถใช้ค่า Buffer ในการสร้างค่าคณิตศาสตร์ได้ แต่ว่าได้ข้อมูลจาก Object เท่านั้น ซึ่งค่อนข้างยาก

และเช่นกัน ถ้าหากว่าคุณใช้รูปแบบนี้ใน EA ตอน Backtest อาจจะใช้ไม่ได้เพราะข้อจำกัดของ MT4 หรือ MT5.

อ่านข้อมูลเพิ่มเติมเกี่ยวกับ Chart Objects

#มาดู Buffer กัน

เมื่อคุณลอง custom indicator คุณจะไม่รู้ว่า อะไรที่อยู่ในค่า Buffer นั้น แล้วก็ใช้ยังไง แต่ว่าคุณสามารถตรวจสอบได้ จากการไปดูที่ Block แล้วดูว่ามันมีค่าอะไรบ้าง ในนี้ (ไปที่ลิงค์) .

6 Indicators FXdreema ดู Buffer

https://fxdreema.com/demo/mt4-trace-multiple

ถ้าเราทำ Backtest ผลจะเป็นแบบนี้ :

6 Indicators FXdreema การทำ Backtest

#เมื่อใดที่ indicator แสดงบนกราฟอัติโนมัติ

คุณจะเห็นว่า indicator ส่วนใหญ่จะแสดงหลังจาก Backtest เสร็จแล้ว แต่ว่า แล้วถ้าเราจะแสดงตอน Backtest หล่ะ

เมื่อ  Expert Advisor หรือ Script ใช้ Indicator ตัวนั้นจะทำงานอยู่ข้างหลังและไม่เห็น และถ้าคุณอยากเห็นต้องเอามาใส่เอง แต่เมื่อคุณทำแบบนี้มันก็คืออันใหม่ไม่ใช่อันเก่า และเมื่อคุณทำ Backtest เสร็จคุณจะเห็นมันมี 2 อัน

#การใช้ Custom Indicators ใน FxDreema?

ใน fxDreema คุณสามารถใช้ custom indicators ในการส่งคำสั่ง EA การเพิ่มคุณจะต้องมี Source code ไฟล์ ซึ่งส่วนใหญ่จะเป็นนามสกุล  .mq4 หรือ .mq5. คุณสามารถใส่ code เข้าไปได้ ถ้าคุณไม่มี code indicator

การเพิ่ม indicator เข้าไป ไม่ได้เป็นการ upload file ไปที่ server สำหรับข้อมูลที่ต้องใช้ มีดังต่อไปนี้ t:

  • Indicator Name – ชื่อนี้ต้องเป็นชื่อเดียวกับ ชื่อ เช่น “Custom ATR.mq5”, ใส่ว่า “Custom ATR”.
  • Input Parameters – ต้องตรงกับที่ Indicator มี ชื่อต้องเป็นเหมือนกัน และข้อมูลก็ต้องเหมือนกัน .
  • Output Buffers – ควรใช้ชื่อที่เข้าใจได้

6 Indicators FXdreema การใช้งาน Custom indicator

ถ้าใส่เสร็จแล้วจะสามารถใช้ custom indicator ใน fxdreema ได้แล้ว ดังตัวอย่าง  Condition.

6 Indicators FXdreema ตัวอย่าง condition

#ใส่แบบไม่อัติโนมัติ Custom Indicator?

มี 2 ตัวเลือก ในการได้ข้อมูลเกี่ยวกับ Source code ของ MT4

Option 1: เอามาจาก Code

เปิดไฟล์มา แล้วเอาข้อมูลที่จำเป็นจากส่วนบนมา ซึ่งนี่คือส่วนหนึ่งของ custom indicator:

//+——————————————————————+

//|                                                    Alligator.mq5 |

//|                   Copyright 2009-2017, MetaQuotes Software Corp. |

//|                                              http://www.mql5.com |

//+——————————————————————+

#property copyright “2009-2017, MetaQuotes Software Corp.”

#property link      “http://www.mql5.com”

 

//—- indicator settings

#property indicator_chart_window

#property indicator_buffers 3

#property indicator_plots   3

#property indicator_type1   DRAW_LINE

#property indicator_type2   DRAW_LINE

#property indicator_type3   DRAW_LINE

#property indicator_color1  Blue

#property indicator_color2  Red

#property indicator_color3  Lime

#property indicator_width1  1

#property indicator_width2  1

#property indicator_width3  1

#property indicator_label1  “Jaws”

#property indicator_label2  “Teeth”

#property indicator_label3  “Lips”

//—- input parameters

input int                InpJawsPeriod=13;               // Jaws period

input int                InpJawsShift=8;                 // Jaws shift

input int                InpTeethPeriod=8;               // Teeth period

input int                InpTeethShift=5;                // Teeth shift

input int                InpLipsPeriod=5;                // Lips period

input int                InpLipsShift=3;                 // Lips shift

input ENUM_MA_METHOD     InpMAMethod=MODE_SMMA;          // Moving average method

input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_MEDIAN;   // Applied price

//—- indicator buffers

double ExtJaws[];

double ExtTeeth[];

double ExtLips[];

//—- handles for moving averages

int    ExtJawsHandle;

int    ExtTeethHandle;

int    ExtLipsHandle;

//— bars minimum for calculation

int    ExtBarsMinimum;

 

คุณจะเห็นข้อมูลเหล่านี้ :

input int                InpJawsPeriod=13;               // Jaws period

input int                InpJawsShift=8;                 // Jaws shift

input int                InpTeethPeriod=8;               // Teeth period

input int                InpTeethShift=5;                // Teeth shift

input int                InpLipsPeriod=5;                // Lips period

input int                InpLipsShift=3;                 // Lips shift

input ENUM_MA_METHOD     InpMAMethod=MODE_SMMA;          // Moving average method

input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_MEDIAN;   // Applied price

 

ดูได้จากคำว่า  input ซึ่งก็คือ global variables คำที่สองได้แก่ ประเภทข้อมูล (int, ENUM_MA_METHOD, ENUM_APPLIED_PRICE). เราจะเห็ฯชื่อตัวแปร เช่น (InpJawsPeriod, InpJawsShift…). หลังจากนั้นเราจะเห็นค่าเดิมของมัน (13, 8…). สุดท้ายเราจะเห็ฯคำอธิบาย

ซึ่งนี่คือตัวเลขอขง output buffer ที่เรามี 3 buffers :

#property indicator_buffers 3

#property indicator_plots 3

 

Option 2: ได้ข้อมูลจาก MetaTrader

เปิด Parameter ของคุณ ใน  Input Parameters ที่ List อยู่ใน  Inputs และ Output Buffers ในแถบ Colors :

6 Indicators FXdreema ปรับ custom indicator ใน MetaTrader 1

6 Indicators FXdreema ปรับ custom indicator ใน MetaTrader 2

ประเภทข้อมูลจะมีลักษณะและสัญลักษณ์ตัวย่อ ดังต่อไปนี้ :

6 Indicators FXdreema สัญลักษณ์ประเภทข้อมูล

  • int – ตัวแปรตัวเลข ตัวจำนวนเต็ม เช่น 3
  • double -ตัวแปรตัวเลขที่ไม่สิ้นสุด มีทศนิยม 3.654
  • bool – Boolean เป็น true หรือ false
  • string – ตัวแปรข้อความ “Hello, World”
  • datetime – ตัวแปรเวลา ถือเป็น integer อีกรูปแบบหนึ่ง
  • color – ค่าสีตัวเลขแต่นับเป็น integer ด้วย

อ่านข้อมูลประเภทข้อมูลเพิ่มที่นี่