วิธีเพิ่มเมฆให้กับอินดิเคเตอร์ cTrader
cTrader Algo ช่วยให้คุณสามารถวาดเมฆระหว่างเส้นบนแผนภูมิ เมฆดังกล่าวช่วยให้คุณสามารถระบุพื้นที่สำคัญบนแผนภูมิและตรวจจับการเปลี่ยนแปลงในพฤติกรรมตลาดได้อย่างรวดเร็ว
ในบทความนี้และวิดีโอที่เกี่ยวข้อง เราจะแสดงวิธีเพิ่มและปรับแต่งเมฆในอินดิเคเตอร์
เพิ่มอินดิเคเตอร์
อินดิเคเตอร์ Bollinger Bands ทั่วไปประกอบด้วยแบนด์บน แบนด์ล่าง และเส้นค่าเฉลี่ยเคลื่อนที่อย่างง่ายตรงกลาง เพื่อเพิ่มประสิทธิภาพการแสดงผลของอินดิเคเตอร์ เราวางแผนที่จะเติมพื้นที่ระหว่างแบนด์ด้วยเมฆ
ในการสร้างอินดิเคเตอร์ เปิดแอป Algo และไปที่แท็บ Indicators คลิกปุ่ม New พิมพ์ชื่อสำหรับอินดิเคเตอร์ เช่น "Bollinger Bands Cloud" แล้วคลิกปุ่ม Create

ตอนนี้เราสามารถแก้ไขโค้ดของอินดิเคเตอร์ได้ เราจะทำให้ตัวอย่างของเราเป็นอินดิเคเตอร์แบบซ้อนทับ
| [Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
|
จากนั้นเราเพิ่มเส้นผลลัพธ์สามเส้นที่จำเป็นเพื่อวาด Bollinger Bands บนแผนภูมิ
| [Output("Main", LineColor = "Yellow", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries Main { get; set; }
[Output("Top", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries Top { get; set; }
[Output("Bottom", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries Bottom { get; set; }
|
เราประกาศอินดิเคเตอร์ Bollinger Bands ของเรา
| private BollingerBands _bollingerBands;
|
เริ่มต้นอินดิเคเตอร์
| _bollingerBands = Indicators.BollingerBands(Bars.ClosePrices, 20, 2, MovingAverageType.Simple);
|
เติมเส้นด้วยค่าของอินดิเคเตอร์ในเมธอด Calculate()
| Main[index] = _bollingerBands.Main[index];
Top[index] = _bollingerBands.Top[index];
Bottom[index] = _bollingerBands.Bottom[index];
|
คุณสามารถคัดลอกโค้ดทั้งหมดด้านล่างนี้:
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 | using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo
{
[Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
public class BollingerBandsCloud : Indicator
{
[Output("Main", LineColor = "Yellow", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries Main { get; set; }
[Output("Top", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries Top { get; set; }
[Output("Bottom", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries Bottom { get; set; }
private BollingerBands _bollingerBands;
protected override void Initialize()
{
_bollingerBands = Indicators.BollingerBands(Bars.ClosePrices, 20, 2, MovingAverageType.Simple);
}
public override void Calculate(int index)
{
Main[index] = _bollingerBands.Main[index];
Top[index] = _bollingerBands.Top[index];
Bottom[index] = _bollingerBands.Bottom[index];
}
}
}
|
คลิก Build หรือใช้ทางลัด Ctrl+B เพื่อสร้างอินดิเคเตอร์
เพิ่มอินสแตนซ์ของอินดิเคเตอร์สำหรับสัญลักษณ์ EURUSD

คุณควรจะเห็นอินดิเคเตอร์ Bollinger Bands ทั่วไปบนแผนภูมิ
เพิ่มเมฆให้กับ Bollinger Bands
ตอนนี้เรากลับไปที่ตัวแก้ไขโค้ดแล้วทำงานเกี่ยวกับการเพิ่มเมฆระหว่างแบนด์
เพื่อให้บรรลุเป้าหมายของเรา เราเพิ่มแอตทริบิวต์ Cloud ให้กับอินดิเคเตอร์ที่มีอยู่ แอตทริบิวต์ Cloud สั่งให้อินดิเคเตอร์วาดเมฆระหว่างเส้น Top และ Bottom
| [Cloud("Top", "Bottom", Opacity = 0.2)]
|
คุณสามารถคัดลอกโค้ดที่แก้ไขทั้งหมดด้านล่าง:
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 | using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo
{
[Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
[Cloud("Top", "Bottom", Opacity = 0.2)]
public class BollingerBandsCloud : Indicator
{
[Output("Main", LineColor = "Yellow", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries Main { get; set; }
[Output("Top", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries Top { get; set; }
[Output("Bottom", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries Bottom { get; set; }
private BollingerBands _bollingerBands;
protected override void Initialize()
{
_bollingerBands = Indicators.BollingerBands(Bars.ClosePrices, 20, 2, MovingAverageType.Simple);
}
public override void Calculate(int index)
{
Main[index] = _bollingerBands.Main[index];
Top[index] = _bollingerBands.Top[index];
Bottom[index] = _bollingerBands.Bottom[index];
}
}
}
|
เราสร้างอัลกอริทึมใหม่แล้วตรวจสอบอินดิเคเตอร์ของเราเพื่อดูว่ามีอะไรเปลี่ยนแปลงไป

คุณควรจะเห็นเมฆสีแดงระหว่างแบนด์ หากคุณเปลี่ยนสีของเส้น Top สีของเมฆจะอัปเดตโดยอัตโนมัติ
เรากลับไปที่ตัวแก้ไขโค้ดและเปลี่ยนแอตทริบิวต์ Cloud เพื่อวาดเมฆเฉพาะก่อนเส้น Main (สีเหลือง)
| [Cloud("Top", "Main", Opacity = 0.2)]
|
สร้างอินดิเคเตอร์ใหม่แล้วตรวจสอบเพื่อยืนยันรูปลักษณ์ใหม่

เพิ่มเมฆให้กับ MA crossover
เราจะสร้างอินดิเคเตอร์ใหม่และใช้มันเพื่อสาธิตวิธีการเพิ่มเมฆที่มีสีต่างกันลงในแผนภูมิ เราตั้งใจที่จะพัฒนา Moving Average (MA) Crossover indicator พร้อมกับเมฆสีเขียวสำหรับแนวโน้มขาขึ้นและเมฆสีแดงสำหรับแนวโน้มขาลง
ทำซ้ำขั้นตอนจากส่วนก่อนหน้าเพื่อสร้างอินดิเคเตอร์ใหม่ ครั้งนี้ ชื่อของอินดิเคเตอร์ควรเป็น "MA Cloud"

เราเริ่มปรับเปลี่ยนอินดิเคเตอร์ใหม่โดยตั้งค่าคุณสมบัติ IsOverlay เป็น True
| [Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
|
เพิ่มแอตทริบิวต์ Cloud ที่จำเป็น
| [Cloud("Fast", "Slow", Opacity = 0.2)]
|
เพิ่มเส้น output และประกาศ moving averages
| [Output("Fast", LineColor = "Green", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries Fast { get; set; }
[Output("Slow", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries Slow { get; set; }
SimpleMovingAverage _fastMA;
SimpleMovingAverage _slowMA;
|
ทำซ้ำขั้นตอนจากตัวอย่างก่อนหน้า (Bollinger Bands) เริ่มต้น moving averages และส่งค่าที่ได้ไปยังเส้นเพื่อให้แสดงบนแผนภูมิ
| _fastMA = Indicators.SimpleMovingAverage(Bars.ClosePrices, 7);
_slowMA = Indicators.SimpleMovingAverage(Bars.ClosePrices, 13);
Fast[index] = _fastMA.Result[index];
Slow[index] = _slowMA.Result[index];
|
คุณสามารถคัดลอกโค้ดทั้งหมดด้านล่างนี้:
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 | using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo
{
[Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
[Cloud("Top", "Bottom", Opacity = 0.2)]
public class BollingerBandsCloud : Indicator
{
[Output("Main", LineColor = "Yellow", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries Main { get; set; }
[Output("Top", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries Top { get; set; }
[Output("Bottom", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries Bottom { get; set; }
private BollingerBands _bollingerBands;
protected override void Initialize()
{
_bollingerBands = Indicators.BollingerBands(Bars.ClosePrices, 20, 2, MovingAverageType.Simple);
}
public override void Calculate(int index)
{
Main[index] = _bollingerBands.Main[index];
Top[index] = _bollingerBands.Top[index];
Bottom[index] = _bollingerBands.Bottom[index];
}
}
}
|
สร้างอินดิเคเตอร์และเพิ่มอินสแตนซ์เพื่อดูอินดิเคเตอร์บนแผนภูมิ

สีของเมฆจะเปลี่ยนไปในแต่ละครั้งที่ moving averages ตัดกัน
บทความนี้แสดงให้คุณเห็นวิธีการเพิ่มเมฆที่มีประโยชน์ให้กับอินดิเคเตอร์ใน cTrader
