コンテンツにスキップ

ピボットポイントとFractalインジケーターの作成方法

多くのインジケーターや戦略は、重要な情報を表示するためにチャートオブジェクトに依存しており、cTrader Algoはそのようなオブジェクトを描画するためのAPIメソッドを提供します。 特に、ピボットポイントとFractalは、重要な価格レベルや転換点を識別するためにトレーディングチャートに描画されます。

この記事と対応するビデオでは、チャートにピボットポイントとFractalを描画する方法を学びます。

ピボットポイントインジケーターを作成する

ピボットポイントは、以前の価格から計算された価格レベルです。 これらのポイントは、潜在的な支持線または抵抗線を示します。

チャートに日々のピボットポイントを描画するインジケーターを作成します。

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

ピボットポイントとして知られるさまざまな支持線と抵抗線を計算します。 ピボットポイント、3つの抵抗線、および3つの支持線を含む7つの値が計算されます。

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

チャートにピボットポイントが描画されるはずです。

Fractalインジケーターを作成する

チャート上にFractalをプロットする別のインジケーターを開発します。 前のセクションの手順を繰り返し、新しい名前で別のインジケーターを作成します。

このインジケーターをオーバーレイインジケーターにします。

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

Calculate()メソッド内で、両側の2本のバーよりも高値が高いバーの上に上向きの矢印を描画します。

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

両側の2本のバーよりも安値が低いバーの下に下向きの矢印を描画します。

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

インジケーターをビルドし、チャートにインスタンスを追加します。

チャート上の関連するローソク足にFractalオブジェクトが表示されるはずです。

この記事では、ピボットポイントとFractalをチャートに追加し、重要な情報を適切に視覚化する方法を説明しました。