コンテンツにスキップ

cTraderインジケーターにクラウドを追加する方法

cTrader Algoを使用すると、チャート上の線の間にクラウドを描画できます。 このようなクラウドを使用すると、チャート上の主要な領域をすばやく識別し、市場の行動の変化を検出できます。

この記事とその対応する動画では、インジケーターにクラウドを追加およびカスタマイズする方法を紹介します。

インジケーターを追加する

典型的なBollinger Bandsインジケーターは、上部バンド、下部バンド、および中央の単純移動平均で構成されています。 インジケーターの外観を向上させるために、バンド間のスペースをクラウドで埋めることを計画しています。

インジケーターを作成するには、Algoアプリを開き、インジケータータブに移動します。 新規ボタンをクリックし、インジケーターの名前(例: "Bollinger Bands Cloud")を入力して、作成ボタンをクリックします。

これでインジケーターのコードを変更できます。 この例をオーバーレイインジケーターにします。

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

次に、チャート上にBollinger Bandsを描画するために必要な3つの出力ラインを追加します。

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

ビルドをクリックするか、Ctrl+Bショートカットを使用してインジケーターをビルドします。

EURUSDシンボルのインジケーターインスタンスを追加します。

チャート上に典型的なBollinger Bandsインジケーターが表示されるはずです。

Bollinger Bandsにクラウドを追加する

次に、コードエディターに戻り、バンド間にクラウドを追加する作業を行います。

目標を達成するために、既存のインジケーターにCloud属性を追加します。 Cloud属性は、TopラインとBottomラインの間にクラウドを描画するようインジケーターに指示します。

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