ข้ามไปที่เนื้อหา

วิธีวาด Andrews pitchfork

Andrews pitchfork เป็นเครื่องมือการวิเคราะห์ทางเทคนิคที่ได้รับความนิยม ใช้ร่วมกับตัวบ่งชี้อื่น ๆ บางครั้งเพื่อระบุระดับแนวรับและแนวต้านที่อาจเกิดขึ้นในตลาดที่มีแนวโน้ม ระดับเหล่านี้ทำหน้าที่เป็นพื้นฐานสำคัญสำหรับกลยุทธ์การเทรดที่ประสบความสำเร็จ ให้ความชัดเจน โครงสร้าง และความมั่นใจในการตัดสินใจแก่นักเทรด

บทความนี้และวิดีโอที่เกี่ยวข้องจะแสดงวิธีสร้าง cBot ที่วาด Andrews pitchfork บนแผนภูมิ และเขียนโค้ดให้ pitchfork อัปเดตโดยอัตโนมัติเมื่อแผนภูมิเปลี่ยนแปลง

วาด Andrews pitchfork บนแผนภูมิ

Andrews pitchfork ประกอบด้วยเส้นกลาง (เส้นกึ่งกลาง) และเส้นขนานสองเส้นที่สร้างเป็นช่อง วัตถุเหล่านี้ช่วยให้นักเทรดมองเห็นแนวโน้ม คาดการณ์การเคลื่อนไหวของราคา และระบุจุดเข้าและออกที่อาจเกิดขึ้นสำหรับการเทรด

Andrews pitchfork ถูกวาดบนแผนภูมิราคาโดยใช้จุดสำคัญสามจุด: จุดสูง จุดต่ำ และจุดสูงหรือต่ำถัดไป การเคลื่อนไหวของราคาภายในช่องนี้มักจะแกว่งระหว่างเส้นบนและเส้นล่าง ในขณะที่เส้นกลางทำหน้าที่เป็นจุดย้อนกลับ

เราจะสร้าง cBot ที่วาด Andrews pitchfork แนวขาขึ้น ซึ่งโดยทั่วไปต้องใช้จุดต่ำสองจุดและจุดสูงหนึ่งจุดอยู่ตรงกลาง กรณีตรงกันข้ามคือ Andrews pitchfork แนวขาลง: ต้องใช้จุดสูงสองจุดและจุดต่ำหนึ่งจุดอยู่ตรงกลาง

ใน cTrader Algo คลิกปุ่ม New เพื่อสร้าง cBot และป้อนชื่อสำหรับ cBot จากนั้นคลิก Create

Andrews pitchfork ต้องใช้พารามิเตอร์หกตัวเพื่อจัดเก็บสิ่งต่อไปนี้: ดัชนีของจุดสูงและจุดต่ำสองจุด ราคาต่ำสุดสองราคา และราคาสูงหนึ่งราคา ประกาศพารามิเตอร์ทั้งหกตัว

1
2
3
4
5
6
private int _highIndex;
private int _lowIndex1;
private int _lowIndex2;
private double _max;
private double _min1;
private double _min2;

ตรวจหาราคาต่ำสุดสองราคาและราคาสูงหนึ่งราคาที่จำเป็นสำหรับจุดของ pitchfork

1
2
3
_max = Bars.HighPrices.Maximum(50);
_min1 = Bars.LowPrices.Minimum(50);
_min2 = Bars.LowPrices.Minimum(10);

cTrader Algo อนุญาตให้คุณกำหนดตำแหน่งเวลาผ่านเมธอดที่ให้เวลาสัมบูรณ์หรือดัชนีแท่งเทียนสัมพัทธ์ เมธอดที่ใช้ในการวาด pitchfork บนแผนภูมิแนะนำการแทนที่ที่เกี่ยวข้อง ในกรณีนี้ เราเลือกดัชนีแท่งเทียนสัมพัทธ์

เขียนโค้ดเพื่อตรวจหาดัชนีของราคาสูงและราคาต่ำ

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
for (int i = 0; i <= 50; i++)
{
    if (Bars.HighPrices.Last(i) == _max)
        _highIndex = Bars.Count - i - 1;
}

for (int i = 0; i <= 50; i++)
{
    if (Bars.LowPrices.Last(i) == _min1)
        _lowIndex1 = Bars.Count - i - 1;
}

for (int i = 0; i <= 10; i++)
{
    if (Bars.LowPrices.Last(i) == _min2)
        _lowIndex2 = Bars.Count - i - 1;
}

วาด pitchfork บนแผนภูมิ

1
Chart.DrawAndrewsPitchfork("AndrewsPitchfork", _lowIndex1, _min1, _highIndex, _max, _lowIndex2, _min2, Color.Red);

คุณสามารถคัดลอกโค้ดทั้งหมดด้านล่างนี้:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None, AddIndicators = true)]
    public class AndrewsPitchfork : Robot
    {
        private int _highIndex;
        private int _lowIndex1;
        private int _lowIndex2;
        private double _max;
        private double _min1;
        private double _min2;

        protected override void OnStart()
        {
            _max = Bars.HighPrices.Maximum(50);
            _min1 = Bars.LowPrices.Minimum(50);
            _min2 = Bars.LowPrices.Minimum(10);

            for (int i = 0; i <= 50; i++)
            {
                if (Bars.HighPrices.Last(i) == _max)
                    _highIndex = Bars.Count - i - 1;
            }

            for (int i = 0; i <= 50; i++)
            {
                if (Bars.LowPrices.Last(i) == _min1)
                    _lowIndex1 = Bars.Count - i - 1;
            }

            for (int i = 0; i <= 10; i++)
            {
                if (Bars.LowPrices.Last(i) == _min2)
                    _lowIndex2 = Bars.Count - i - 1;
            }

            Chart.DrawAndrewsPitchfork("AndrewsPitchfork", _lowIndex1, _min1, _highIndex, _max, _lowIndex2, _min2, Color.Red);

        }

        protected override void OnTick()
        {
            // Handle price updates here
        }

        protected override void OnStop()
        {
            // Handle cBot stop here
        }
    }
}

ในการสร้าง cBot ให้ใช้ปุ่มลัด Ctrl+B หรือคลิก Build

เพิ่มอินสแตนซ์ของ cBot ในเครื่อง: คลิก Add instance เลือกตัวเลือก Locally จากนั้นคลิก Add instance

คลิกที่อินสแตนซ์และไปที่แท็บ Backtesting เลือกช่วงเวลาสำหรับการ backtesting เปิดใช้งานตัวเลือก Visual mode แล้วคลิกไอคอนเล่น

คุณควรจะเห็น Andrews pitchfork ถูกวาดบนแผนภูมิ

อัปเดต Andrews pitchfork

กลับไปที่แอป Algo และเขียนโค้ด cBot เพื่ออัปเดต pitchfork เมื่อแผนภูมิเปลี่ยนแปลง

สร้างเมธอดใหม่เพื่อวาด pitchfork และย้ายตรรกะเดิมไปยังเมธอดนั้น

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
private void DrawAndrewsPitchfork()
{
    _max = Bars.HighPrices.Maximum(50);
    _min1 = Bars.LowPrices.Minimum(50);
    _min2 = Bars.LowPrices.Minimum(10);

    for (int i = 0; i <= 50; i++)
    {
        if (Bars.HighPrices.Last(i) == _max)
            _highIndex = Bars.Count - i - 1;
    }

    for (int i = 0; i <= 50; i++)
    {
        if (Bars.LowPrices.Last(i) == _min1)
            _lowIndex1 = Bars.Count - i - 1;
    }

    for (int i = 0; i <= 10; i++)
    {
        if (Bars.LowPrices.Last(i) == _min2)
            _lowIndex2 = Bars.Count - i - 1;
    }

    if (_lowIndex1 < _highIndex && _highIndex < _lowIndex2)
        Chart.DrawAndrewsPitchfork("AndrewsPitchfork", _lowIndex1, _min1, _highIndex, _max, _lowIndex2, _min2, Color.Red);
}

เรียกใช้เมธอดใหม่ในเมธอด OnBar()

1
2
3
4
protected override void OnBar()
{
    DrawAndrewsPitchfork();
}

เนื่องจากต้องการเฉพาะการตั้งค่าแนวโน้มขาขึ้น ให้เขียนตรรกะเงื่อนไขที่ตรวจสอบว่าค่าต่ำสุดและค่าสูงสุดอยู่ในลำดับที่ถูกต้อง

1
2
if (_lowIndex1 < _highIndex && _highIndex < _lowIndex2)
    Chart.DrawAndrewsPitchfork("AndrewsPitchfork", _lowIndex1, _min1, _highIndex, _max, _lowIndex2, _min2, Color.Red);

คุณสามารถคัดลอกโค้ดทั้งหมดด้านล่างนี้:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None, AddIndicators = true)]
    public class AndrewsPitchfork : Robot
    {
        private int _highIndex;
        private int _lowIndex1;
        private int _lowIndex2;
        private double _max;
        private double _min1;
        private double _min2;

        protected override void OnStart()
        {

        DrawAndrewsPitchfork(); 

        }

        private void DrawAndrewsPitchfork() 
        {
           _max = Bars.HighPrices.Maximum(50);
            _min1 = Bars.LowPrices.Minimum(50);
            _min2 = Bars.LowPrices.Minimum(10);

            for (int i = 0; i <= 50; i++)
            {
                if (Bars.HighPrices.Last(i) == _max)
                    _highIndex = Bars.Count - i - 1;
            }

            for (int i = 0; i <= 50; i++)
            {
                if (Bars.LowPrices.Last(i) == _min1)
                    _lowIndex1 = Bars.Count - i - 1;
            }

            for (int i = 0; i <= 10; i++)
            {
                if (Bars.LowPrices.Last(i) == _min2)
                    _lowIndex2 = Bars.Count - i - 1;
            }

            if (_lowIndex1 < _highIndex && _highIndex < _lowIndex2)
                 Chart.DrawAndrewsPitchfork("AndrewsPitchfork", _lowIndex1, _min1, _highIndex, _max, _lowIndex2, _min2, Color.Red);
        }

        protected override void OnBar()
        {
            DrawAndrewsPitchfork(); 
        }

        protected override void OnStop()
        {
            // Handle cBot stop here
        }
    }
}

สร้าง cBot อีกครั้งและทำการ backtest

เพิ่มความเร็วของโหมดภาพและคลิกไอคอน เล่น

ครั้งนี้ คุณควรจะเห็นว่า pitchfork ถูกวาดใหม่อย่างต่อเนื่องเมื่อแผนภูมิเปลี่ยนแปลง

สรุป

บทความนี้ได้อธิบายวิธีวาด Andrews pitchfork บนแผนภูมิสัญลักษณ์และเขียนโค้ดให้ pitchfork อัปเดตตัวเองเมื่อแผนภูมิเปลี่ยนแปลง