콘텐츠로 이동

피벗 포인트 및 프랙탈 지표 생성 방법

많은 지표와 전략은 차트 객체를 사용하여 필수 정보를 표시하며, cTrader Algo는 이러한 객체를 그리기 위해 필요한 API 메서드를 제공합니다. 특히 피벗 포인트와 프랙탈은 중요한 가격 수준과 전환점을 식별하는 데 도움을 주기 위해 트레이딩 차트에 그려집니다.

이 글과 해당 비디오에서는 차트에 피벗 포인트와 프랙탈을 그리는 방법을 배우게 됩니다.

피벗 포인트 지표 생성하기

피벗 포인트는 이전 가격에서 계산된 가격 수준입니다. 이러한 포인트는 잠재적인 지지선 또는 저항선을 나타냅니다.

우리는 차트에 일일 피벗 포인트를 그리는 지표를 생성할 것입니다.

cTrader Algo에서 지표 탭으로 이동하여 새로 만들기를 클릭합니다. 새 지표의 이름을 입력한 후 생성 버튼을 클릭합니다.

코드 편집기에서 지표를 수정하여 오버레이 지표로 만듭니다.

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

Initialize() 메서드에서 일일 바를 정의하고 가져옵니다.

1
2
3
4
5
6
Bars _bars;

protected override void Initialize()
{
    _bars = MarketData.GetBars(TimeFrame.Daily, SymbolName);
}

피벗 포인트로 알려진 다양한 지지선과 저항선 수준을 계산합니다. 피벗 포인트, 세 개의 저항선 및 세 개의 지지선으로 구성된 일곱 개의 값을 계산합니다.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
var pivot = (_bars.HighPrices.Last(1) + _bars.LowPrices.Last(1) + _bars.ClosePrices.Last(1)) / 3;

var r1 = 2 * pivot - _bars.LowPrices.Last(1);
var s1 = 2 * pivot - _bars.HighPrices.Last(1);

var r2 = pivot + _bars.HighPrices.Last(1) - _bars.LowPrices.Last(1);
var s2 = pivot - _bars.HighPrices.Last(1) + _bars.LowPrices.Last(1);

var r3 = _bars.HighPrices.Last(1) + 2 * (pivot - _bars.LowPrices.Last(1));
var s3 = _bars.LowPrices.Last(1) - 2 * (_bars.HighPrices.Last(1) - pivot);

피벗 포인트가 계산되었으므로 추세선을 사용하여 차트에 그릴 수 있습니다.

1
2
3
4
5
6
7
Chart.DrawTrendLine("pivot ", _bars.OpenTimes.LastValue, pivot, _bars.OpenTimes.LastValue.AddDays(1), pivot, Color.White);
Chart.DrawTrendLine("r1 ", _bars.OpenTimes.LastValue, r1, _bars.OpenTimes.LastValue.AddDays(1), r1, Color.Green);
Chart.DrawTrendLine("r2 ", _bars.OpenTimes.LastValue, r2, _bars.OpenTimes.LastValue.AddDays(1), r2, Color.Green);
Chart.DrawTrendLine("r3 ", _bars.OpenTimes.LastValue, r3, _bars.OpenTimes.LastValue.AddDays(1), r3, Color.Green);
Chart.DrawTrendLine("s1 ", _bars.OpenTimes.LastValue, s1, _bars.OpenTimes.LastValue.AddDays(1), s1, Color.Red);
Chart.DrawTrendLine("s2 ", _bars.OpenTimes.LastValue, s2, _bars.OpenTimes.LastValue.AddDays(1), s2, Color.Red);
Chart.DrawTrendLine("s3 ", _bars.OpenTimes.LastValue, s3, _bars.OpenTimes.LastValue.AddDays(1), s3, 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
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 PivotPointsExample : Indicator
    {
        Bars _bars;

        protected override void Initialize()
        {
            _bars = MarketData.GetBars(TimeFrame.Daily, SymbolName);
        }

        public override void Calculate(int index)
        {
            var pivot = (_bars.HighPrices.Last(1) + _bars.LowPrices.Last(1) + _bars.ClosePrices.Last(1)) / 3;

            var r1 = 2 * pivot - _bars.LowPrices.Last(1);
            var s1 = 2 * pivot - _bars.HighPrices.Last(1);

            var r2 = pivot + _bars.HighPrices.Last(1) - _bars.LowPrices.Last(1);
            var s2 = pivot - _bars.HighPrices.Last(1) + _bars.LowPrices.Last(1);

            var r3 = _bars.HighPrices.Last(1) + 2 * (pivot - _bars.LowPrices.Last(1));
            var s3 = _bars.LowPrices.Last(1) - 2 * (_bars.HighPrices.Last(1) - pivot);

            Chart.DrawTrendLine("pivot ", _bars.OpenTimes.LastValue, pivot, _bars.OpenTimes.LastValue.AddDays(1), pivot, Color.White);
            Chart.DrawTrendLine("r1 ", _bars.OpenTimes.LastValue, r1, _bars.OpenTimes.LastValue.AddDays(1), r1, Color.Green);
            Chart.DrawTrendLine("r2 ", _bars.OpenTimes.LastValue, r2, _bars.OpenTimes.LastValue.AddDays(1), r2, Color.Green);
            Chart.DrawTrendLine("r3 ", _bars.OpenTimes.LastValue, r3, _bars.OpenTimes.LastValue.AddDays(1), r3, Color.Green);
            Chart.DrawTrendLine("s1 ", _bars.OpenTimes.LastValue, s1, _bars.OpenTimes.LastValue.AddDays(1), s1, Color.Red);
            Chart.DrawTrendLine("s2 ", _bars.OpenTimes.LastValue, s2, _bars.OpenTimes.LastValue.AddDays(1), s2, Color.Red);
            Chart.DrawTrendLine("s3 ", _bars.OpenTimes.LastValue, s3, _bars.OpenTimes.LastValue.AddDays(1), s3, Color.Red);

        }
    }
}

++ctrl+b++를 누르거나 빌드를 클릭한 후 인스턴스 추가를 클릭하여 지표를 차트에 추가합니다.

차트에 피벗 포인트가 그려진 것을 볼 수 있습니다.

프랙탈 지표 생성하기

우리는 차트에 프랙탈을 그리는 별도의 지표를 개발할 것입니다. 이전 섹션의 단계를 반복하고 새로운 이름으로 또 다른 지표를 생성합니다.

이 지표를 오버레이 지표로 만듭니다.

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

Calculate() 메서드에서 양쪽의 두 개의 인접한 바보다 높은 값을 가진 바 위에 화살표를 그립니다.

1
2
3
4
5
if (Bars.HighPrices[index - 2] > Bars.HighPrices[index - 1] && Bars.HighPrices[index - 2] > Bars.HighPrices[index] &&
    Bars.HighPrices[index - 2] > Bars.HighPrices[index - 3] && Bars.HighPrices[index - 2] > Bars.HighPrices[index - 4])
{
     Chart.DrawIcon(Bars.OpenTimes[index].ToString(), ChartIconType.DownArrow, Bars.OpenTimes[index - 2], Bars.HighPrices[index - 2], Color.Red);
}

양쪽의 두 개의 인접한 바보다 낮은 값을 가진 바 아래에 아래쪽 화살표를 그립니다.

1
2
3
4
5
if (Bars.LowPrices[index - 2] < Bars.LowPrices[index - 1] && Bars.LowPrices[index - 2] < Bars.LowPrices[index] &&
    Bars.LowPrices[index - 2] < Bars.LowPrices[index - 3] && Bars.LowPrices[index - 2] < Bars.LowPrices[index - 4])
{
     Chart.DrawIcon(Bars.OpenTimes[index].ToString(), ChartIconType.UpArrow, Bars.OpenTimes[index - 2], Bars.LowPrices[index - 2], Color.Green);
}

아래에서 전체 코드를 복사할 수 있습니다:

 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
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 FractalsExample : Indicator
    {
        protected override void Initialize()
        {

        }

        public override void Calculate(int index)
        {
            if (Bars.HighPrices[index - 2] > Bars.HighPrices[index - 1] && Bars.HighPrices[index - 2] > Bars.HighPrices[index] &&
                Bars.HighPrices[index - 2] > Bars.HighPrices[index - 3] && Bars.HighPrices[index - 2] > Bars.HighPrices[index - 4])
            {
                Chart.DrawIcon(Bars.OpenTimes[index].ToString(), ChartIconType.DownArrow, Bars.OpenTimes[index - 2], Bars.HighPrices[index - 2], Color.Red);
            }

            if (Bars.LowPrices[index - 2] < Bars.LowPrices[index - 1] && Bars.LowPrices[index - 2] < Bars.LowPrices[index] &&
                Bars.LowPrices[index - 2] < Bars.LowPrices[index - 3] && Bars.LowPrices[index - 2] < Bars.LowPrices[index - 4])
            {
                Chart.DrawIcon(Bars.OpenTimes[index].ToString(), ChartIconType.UpArrow, Bars.OpenTimes[index - 2], Bars.LowPrices[index - 2], Color.Green);
            }
        }
    }
}

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

차트의 관련 캔들에 프랙탈 객체가 표시되는 것을 볼 수 있습니다.

이 글은 차트에 피벗 포인트와 프랙탈을 추가하여 주요 정보를 시각적으로 표시하는 방법을 보여주었습니다.