การสร้าง Custom Indicator อย่างง่าย

IUX Markets Bonus

ตัวอย่างการสร้าง Custom Indicator อย่างง่าย

การสร้าง Custom Indicator อย่างง่าย
การสร้าง Custom Indicator อย่างง่าย


int OnInit()
{
    SetIndexBuffer(0, CustomMABuffer);
    SetIndexStyle(0, DRAW_LINE);
    return(INIT_SUCCEEDED);
}

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
    int limit = rates_total - prev_calculated;
    
    for(int i = limit; i >= 0; i--)
    {
        CustomMABuffer[i] = (close[i] + high[i] + low[i]) / 3;
    }
    
    return(rates_total);
}

การสร้าง Custom Indicator: OnInit() และ OnCalculate()

ฟังก์ชันทั้งสองนี้ใช้ในการสร้าง custom indicator ที่คำนวณค่าเฉลี่ยของราคาปิด, สูงสุด, และต่ำสุด

ฟังก์ชัน OnInit()

int OnInit()
{
SetIndexBuffer(0, CustomMABuffer);
SetIndexStyle(0, DRAW_LINE);
return(INIT_SUCCEEDED);
}

วัตถุประสงค์:

  • เตรียมการและกำหนดค่าเริ่มต้นสำหรับ indicator

การทำงาน:

  1. SetIndexBuffer(0, CustomMABuffer): กำหนดให้ CustomMABuffer เป็น buffer หลักของ indicator
  2. SetIndexStyle(0, DRAW_LINE): กำหนดให้แสดงผลเป็นเส้น
  3. คืนค่า INIT_SUCCEEDED เพื่อบอกว่าการเริ่มต้นสำเร็จ

ฟังก์ชัน OnCalculate()

วัตถุประสงค์:

  • คำนวณค่า indicator สำหรับแต่ละแท่งเทียน

การทำงาน:

  1. คำนวณจำนวนแท่งเทียนที่ต้องอัพเดท (limit)
  2. วนลูปเพื่อคำนวณค่าเฉลี่ยของราคาปิด, สูงสุด, และต่ำสุดสำหรับแต่ละแท่ง
  3. เก็บผลลัพธ์ใน CustomMABuffer
  4. คืนค่าจำนวนแท่งเทียนทั้งหมดที่คำนวณ

Custom Indicator

  • Indicator นี้คำนวณค่าเฉลี่ยของราคาปิด, สูงสุด, และต่ำสุดสำหรับแต่ละแท่งเทียน
  • แสดงผลเป็นเส้นบนกราฟ
  • สามารถใช้เป็นเครื่องมือวิเคราะห์แนวโน้มราคาที่ง่ายและรวดเร็ว

การสร้าง custom indicator แบบนี้ช่วยให้สามารถพัฒนาเครื่องมือวิเคราะห์ทางเทคนิคที่เหมาะสมกับกลยุทธ์การเทรดเฉพาะของคุณได้

 Exness Promotion
PNFPB Install PWA using share icon

For IOS and IPAD browsers, Install PWA using add to home screen in ios safari browser or add to dock option in macos safari browser