コンテンツにスキップ

取引時間と支持線/抵抗線のインジケーターを作成する方法

cTrader Algo APIは、チャート上に長方形、線、三角形、などのオブジェクトを描画するインジケーターを作成するために必要なタイプを提供します。 特に長方形は、重要な期間、統合ゾーン、支持線/抵抗線を強調するために広く使用されています。

この記事と対応する動画では、シンボルチャート上に取引時間と支持線/抵抗線を表す長方形を描画する方法を学びます。

取引時間インジケーターを作成する

主要な取引時間は4つあります:シドニー、東京、ロンドン、ニューヨークです。 各取引時間は、ボラティリティと活動レベルにおいて独自の特徴を持っています。 取引時間とその重なりを監視することで、トレーダーは特定の資産が取引されるタイミングを知り、機会を活用できます。

この例では、チャート上に取引時間を描画するインジケーターを作成します。

cTrader Algoで、Indicatorsタブに移動し、Newボタンをクリックします。 テキストフィールドに名前を入力し、Createをクリックします。

コードエディターでインジケーターの修正を開始します。 まず、オーバーレイインジケーターにします。

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++を押すか、ビルドをクリックし、インスタンスを追加をクリックしてインジケーターをチャートに追加します。

チャート上にロンドン取引時間の長方形が表示されます。

コードエディターに戻り、残りの3つの取引時間のコードを追加します。

 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;
        }
    }
}

インジケーターをリビルドし、チャートを確認してすべての取引時間が表示されていることを確認します。

支持線/抵抗線インジケーターを作成する

Fractalを使用してチャート上に抵抗線と支持線のゾーンをプロットするインジケーターを作成します。

同じ手順で新しいインジケーターを作成しますが、別の名前を付けます。

IsOverlaytrueに設定して修正を開始します。

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

Fractal抵抗線ゾーンは、両側の2本のバーよりも高値が高い場所に描画されます。 ゾーンは、Fractalローソク足の高値と終値の間の領域です。 抵抗線ゾーンは、強気トレンドが停止して反転する可能性のある領域を特定するのに役立ち、取引の機会をもたらします。

抵抗線ゾーンを描画するコードを記述します。

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;
            }
        }
    }
}

インジケーターをビルドし、チャートにインスタンスを追加します。 チャート上に支持線と抵抗線のゾーンが表示されるはずです。

この記事では、取引時間や支持線/抵抗線をチャート上に表すために、長方形などの有用なオブジェクトを持つインジケーターを作成する方法を説明しました。