콘텐츠로 이동

트레이딩 세션 및 지지/저항 지표를 생성하는 방법

cTrader Algo API는 거래 차트에 사각형, 선, 삼각형, 구름 및 기타 객체를 그리는 지표를 생성하는 데 필요한 유형을 제공합니다. 특히 사각형은 중요한 기간, 통합 구역 및 지지/저항 수준을 강조하는 데 널리 사용됩니다.

이 글과 해당 비디오에서는 심볼 차트에서 트레이딩 세션과 지지/저항 수준을 나타내는 사각형을 그리는 방법을 배우게 됩니다.

트레이딩 세션 지표 생성

네 가지 주요 트레이딩 세션이 있습니다: 시드니, 도쿄, 런던 및 뉴욕. 각 세션은 변동성과 활동 수준에서 독특합니다. 트레이더는 세션과 그 사이의 중첩을 모니터링함으로써 특정 자산이 거래되는 시기를 알고 기회를 활용할 수 있습니다.

이 예제에서는 차트에 트레이딩 세션을 그리는 지표를 생성하려고 합니다.

cTrader Algo에서 지표 탭으로 이동하여 새로 만들기 버튼을 클릭하세요. 텍스트 필드에 이름을 입력한 후 생성을 클릭하세요.

코드 편집기에서 지표 수정을 시작하세요. 먼저, 오버레이 지표로 만드세요.

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

런던 세션을 나타내는 사각형을 그리는 코드를 작성하세요.

1
2
3
4
5
6
7
TimeSpan londonOpen = TimeZoneInfo.ConvertTimeToUtc(new DateTime(Server.Time.Year, Server.Time.Month, Server.Time.Day, 9, 0, 0),
TimeZoneInfo.FindSystemTimeZoneById("Greenwich Standard Time")).TimeOfDay;
TimeSpan londonClose = TimeZoneInfo.ConvertTimeToUtc(new DateTime(Server.Time.Year, Server.Time.Month, Server.Time.Day, 18, 0, 0),
TimeZoneInfo.FindSystemTimeZoneById("Greenwich Standard Time")).TimeOfDay;

Chart.DrawRectangle("London Session ", Server.Time.Date.Add(londonOpen), Chart.TopY, Server.Time.Date.Add(londonClose), Chart.BottomY, 
Color.FromArgb(50, 0, 50, 255)).IsFilled = true;

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

런던 세션 사각형이 차트에 표시됩니다.

코드 편집기로 돌아가 나머지 세 가지 트레이딩 세션에 대한 코드를 추가하세요.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
TimeSpan nyOpen = TimeZoneInfo.ConvertTimeToUtc(new DateTime(Server.Time.Year, Server.Time.Month, Server.Time.Day, 9, 0, 0),
TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")).TimeOfDay;
TimeSpan nyClose = TimeZoneInfo.ConvertTimeToUtc(new DateTime(Server.Time.Year, Server.Time.Month, Server.Time.Day, 18, 0, 0),
TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")).TimeOfDay;

Chart.DrawRectangle("NY Session ", Server.Time.Date.Add(nyOpen), Chart.TopY, Server.Time.Date.Add(nyClose), Chart.BottomY,
Color.FromArgb(50, 255, 50, 0)).IsFilled = true;

TimeSpan sydneyOpen = TimeZoneInfo.ConvertTimeToUtc(new DateTime(Server.Time.Year, Server.Time.Month, Server.Time.Day, 9, 0, 0),
TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time")).TimeOfDay;
TimeSpan sydneyClose = TimeZoneInfo.ConvertTimeToUtc(new DateTime(Server.Time.Year, Server.Time.Month, Server.Time.Day, 18, 0, 0),
TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time")).TimeOfDay;

Chart.DrawRectangle("Sydney Session ", Server.Time.Date.Add(sydneyOpen).AddDays(-1), Chart.TopY, Server.Time.Date.Add(sydneyClose),
Chart.BottomY, Color.FromArgb(50, 50, 255, 0)).IsFilled = true;

TimeSpan tokyoOpen = TimeZoneInfo.ConvertTimeToUtc(new DateTime(Server.Time.Year, Server.Time.Month, Server.Time.Day, 9, 0, 0),
TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time")).TimeOfDay;
TimeSpan tokyoClose = TimeZoneInfo.ConvertTimeToUtc(new DateTime(Server.Time.Year, Server.Time.Month, Server.Time.Day, 18, 0, 0),
TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time")).TimeOfDay;

Chart.DrawRectangle("Tokio Session ", Server.Time.Date.Add(tokyoOpen), Chart.TopY, Server.Time.Date.Add(tokyoClose), Chart.BottomY,
Color.FromArgb(50, 0, 50, 255)).IsFilled = true;

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

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

        }

        public override void Calculate(int index)
        {
            TimeSpan londonOpen = TimeZoneInfo.ConvertTimeToUtc(new DateTime(Server.Time.Year, Server.Time.Month, Server.Time.Day, 9, 0, 0),
            TimeZoneInfo.FindSystemTimeZoneById("Greenwich Standard Time")).TimeOfDay;
            TimeSpan londonClose = TimeZoneInfo.ConvertTimeToUtc(new DateTime(Server.Time.Year, Server.Time.Month, Server.Time.Day, 18, 0, 0),
            TimeZoneInfo.FindSystemTimeZoneById("Greenwich Standard Time")).TimeOfDay;

            Chart.DrawRectangle("London Session ", Server.Time.Date.Add(londonOpen), Chart.TopY, Server.Time.Date.Add(londonClose), Chart.BottomY, 
            Color.FromArgb(50, 0, 50, 255)).IsFilled = true;

            TimeSpan nyOpen = TimeZoneInfo.ConvertTimeToUtc(new DateTime(Server.Time.Year, Server.Time.Month, Server.Time.Day, 9, 0, 0),
            TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")).TimeOfDay;
            TimeSpan nyClose = TimeZoneInfo.ConvertTimeToUtc(new DateTime(Server.Time.Year, Server.Time.Month, Server.Time.Day, 18, 0, 0),
            TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")).TimeOfDay;

            Chart.DrawRectangle("NY Session ", Server.Time.Date.Add(nyOpen), Chart.TopY, Server.Time.Date.Add(nyClose), Chart.BottomY,
            Color.FromArgb(50, 255, 50, 0)).IsFilled = true;

            TimeSpan sydneyOpen = TimeZoneInfo.ConvertTimeToUtc(new DateTime(Server.Time.Year, Server.Time.Month, Server.Time.Day, 9, 0, 0),
            TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time")).TimeOfDay;
            TimeSpan sydneyClose = TimeZoneInfo.ConvertTimeToUtc(new DateTime(Server.Time.Year, Server.Time.Month, Server.Time.Day, 18, 0, 0),
            TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time")).TimeOfDay;

            Chart.DrawRectangle("Sydney Session ", Server.Time.Date.Add(sydneyOpen).AddDays(-1), Chart.TopY, Server.Time.Date.Add(sydneyClose),
            Chart.BottomY, Color.FromArgb(50, 50, 255, 0)).IsFilled = true;

            TimeSpan tokyoOpen = TimeZoneInfo.ConvertTimeToUtc(new DateTime(Server.Time.Year, Server.Time.Month, Server.Time.Day, 9, 0, 0),
            TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time")).TimeOfDay;
            TimeSpan tokyoClose = TimeZoneInfo.ConvertTimeToUtc(new DateTime(Server.Time.Year, Server.Time.Month, Server.Time.Day, 18, 0, 0),
            TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time")).TimeOfDay;

            Chart.DrawRectangle("Tokyo Session ", Server.Time.Date.Add(tokyoOpen), Chart.TopY, Server.Time.Date.Add(tokyoClose), Chart.BottomY,
            Color.FromArgb(50, 0, 50, 255)).IsFilled = true;
        }
    }
}

지표를 다시 빌드한 후 차트를 확인하여 모든 트레이딩 세션이 표시되는지 확인하세요.

지지/저항 지표 생성

프랙탈을 사용하여 차트에 저항 및 지지 구역을 표시하는 지표를 생성할 것입니다.

동일한 단계를 사용하여 새로운 지표를 생성하되, 다른 이름을 지정하세요.

IsOverlaytrue로 설정하여 수정을 시작하세요.

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

프랙탈 저항 구역은 양쪽의 두 인접 바보다 높은 고점이 있는 곳에 그려집니다. 이 구역은 프랙탈 캔들의 고점과 종가 사이의 영역입니다. 저항 구역은 강세 추세가 멈추고 반전될 수 있는 영역을 식별하는 데 도움이 되며, 이는 거래 기회로 이어질 수 있습니다.

저항 구역을 그리는 코드를 작성하세요.

1
2
3
4
5
6
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.DrawRectangle(Bars.OpenTimes[index - 2].ToString(), Bars.OpenTimes[index - 2], Bars.HighPrices[index - 2], Bars.OpenTimes[index - 2].AddDays(1),
    Bars.ClosePrices[index - 2], Color.FromArgb(50, Color.Green)).IsFilled = true;
}

저항 구역과 달리, 지지 구역은 약세 추세가 멈추고 반전될 수 있는 영역을 식별하는 데 도움이 됩니다. 이러한 구역은 매수 신호로 해석될 수 있습니다.

지지 구역을 그리는 코드를 작성하세요.

1
2
3
4
5
6
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.DrawRectangle(Bars.OpenTimes[index - 2].ToString(), Bars.OpenTimes[index - 2], Bars.ClosePrices[index - 2], Bars.OpenTimes[index - 2].AddDays(1),
    Bars.LowPrices[index - 2], Color.FromArgb(50, Color.Red)).IsFilled = true;
}

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

 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
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 SupportResistanceExample : 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.DrawRectangle(Bars.OpenTimes[index - 2].ToString(), Bars.OpenTimes[index - 2], Bars.HighPrices[index - 2], Bars.OpenTimes[index - 2].AddDays(1),
                Bars.ClosePrices[index - 2], Color.FromArgb(50, Color.Green)).IsFilled = true;
            }

            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.DrawRectangle(Bars.OpenTimes[index - 2].ToString(), Bars.OpenTimes[index - 2], Bars.ClosePrices[index - 2], Bars.OpenTimes[index - 2].AddDays(1),
                Bars.LowPrices[index - 2], Color.FromArgb(50, Color.Red)).IsFilled = true;
            }
        }
    }
}

지표를 빌드하고 차트에 인스턴스를 추가합니다. 차트에 지지 및 저항 구역이 표시되어야 합니다.

이 글은 사각형과 같은 유용한 객체를 사용하여 차트에 트레이딩 세션과 지지/저항 수준을 나타내는 지표를 생성하는 방법을 보여주었습니다.