콘텐츠로 이동

cTrader 지표에 클라우드를 추가하는 방법

cTrader Algo를 사용하면 차트의 선들 사이에 클라우드를 그릴 수 있습니다. 이러한 클라우드는 차트에서 주요 영역을 빠르게 식별하고 시장 행동의 변화를 감지할 수 있게 해줍니다.

이 문서와 해당 비디오에서는 지표에 클라우드를 추가하고 맞춤 설정하는 방법을 보여드리겠습니다.

지표 추가

일반적인 Bollinger Bands 지표는 상단 밴드, 하단 밴드 및 중간의 Simple Moving Average로 구성됩니다. 지표의 외관을 향상시키기 위해 밴드 사이의 공간을 클라우드로 채우려고 합니다.

지표를 생성하려면 Algo 앱을 열고 Indicators 탭으로 이동합니다. New 버튼을 클릭하고 "Bollinger Bands Cloud"와 같은 지표 이름을 입력한 후 Create 버튼을 클릭합니다.

이제 지표 코드를 수정할 수 있습니다. 우리의 예제를 오버레이 지표로 만들 것입니다.

1
[Indicator(AccessRights = AccessRights.None, IsOverlay = true)]

그런 다음 차트에 Bollinger Bands를 그리기 위해 필요한 세 개의 출력 라인을 추가합니다.

1
2
3
4
5
6
7
8
[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 지표를 선언합니다.

1
private BollingerBands _bollingerBands;

지표를 초기화합니다.

1
_bollingerBands = Indicators.BollingerBands(Bars.ClosePrices, 20, 2, MovingAverageType.Simple);

Calculate() 메서드에서 지표 값으로 라인을 채웁니다.

1
2
3
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 속성은 지표에게 TopBottom 라인 사이에 클라우드를 그리도록 지시합니다.

1
[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 (노란색) 라인 앞에만 클라우드를 그리도록 합니다.

1
[Cloud("Top", "Main", Opacity = 0.2)]

지표를 다시 빌드한 후 새로운 모양을 확인합니다.

MA 크로스오버에 클라우드 추가

새로운 지표를 생성하고 다른 색상의 클라우드를 차트에 추가하는 방법을 보여드리겠습니다. 상승 추세에는 녹색 클라우드, 하락 추세에는 빨간색 클라우드가 있는 Moving Average (MA) 크로스오버 지표를 개발하려고 합니다.

이전 섹션의 단계를 반복하여 새로운 지표를 생성합니다. 이번에는 지표 이름을 "MA Cloud"로 지정합니다.

새 지표를 수정하기 위해 IsOverlay 속성을 True로 설정합니다.

1
[Indicator(AccessRights = AccessRights.None, IsOverlay = true)]

필요한 Cloud 속성을 추가합니다.

1
[Cloud("Fast", "Slow", Opacity = 0.2)]

출력 라인을 추가하고 이동 평균을 선언합니다.

1
2
3
4
5
6
7
8
[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)의 단계를 반복합니다. 이동 평균을 초기화하고 결과 값을 라인에 전달하여 차트에 표시되도록 합니다.

1
2
3
4
5
_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];
        }
    }
}

지표를 빌드하고 인스턴스를 추가하여 차트에서 지표를 확인합니다.

이동 평균이 교차할 때마다 클라우드 색상이 변경됩니다.

이 문서에서는 cTrader에서 유용한 클라우드를 지표에 추가하는 방법을 보여드렸습니다.

Image title