アンドリューズのピッチフォークの描画方法
アンドリューズのピッチフォークは、トレンド相場における潜在的なサポートとレジスタンスのレベルを特定するために使用される人気のあるテクニカル分析ツールです。これは他のインジケーターと組み合わせて使用されることもあります。 これらのレベルは成功する取引戦略の重要な基盤となり、トレーダーに明確さ、構造、そして決定に対する自信を与えます。
この記事と対応するビデオでは、アンドリューズのピッチフォークをチャートに描画するcBotの作成方法と、チャートの変化に合わせてピッチフォークを自動的に更新するコードの書き方を紹介します。
チャートにアンドリューズのピッチフォークを描画する
アンドリューズのピッチフォークは、中央線(センターライン)と2本の平行線からなるチャネルで構成されています。 これらのオブジェクトは、トレーダーがトレンドを視覚化し、価格の動きを予測し、取引の潜在的な参入ポイントと退出ポイントを特定するのに役立ちます。
アンドリューズのピッチフォークは、高値、安値、そしてその後の高値または安値の3つの重要なポイントを使用して価格チャートに描画されます。 このチャネル内での価格の動きは、上部と下部のラインの間を振動することが多く、中央線は反転ポイントとして機能します。
上昇トレンドのアンドリューズのピッチフォークを描画するcBotを作成します。これには通常、2つの安値とその間の高値が必要です。 下降トレンドのアンドリューズのピッチフォークの場合は逆になります:2つの高値とその間の安値が必要になります。
cTrader Algoで、新規ボタンをクリックしてcBotを作成し、名前を入力してから作成をクリックします。

アンドリューズのピッチフォークには、高値と2つの安値のインデックス、2つの最小価格、そして高値を格納するための6つのパラメーターが必要です。 6つのパラメーターを宣言します。
| private int _highIndex;
private int _lowIndex1;
private int _lowIndex2;
private double _max;
private double _min1;
private double _min2;
|
ピッチフォークのポイントに必要な2つの最小価格と高値を検出します。
| _max = Bars.HighPrices.Maximum(50);
_min1 = Bars.LowPrices.Minimum(50);
_min2 = Bars.LowPrices.Minimum(10);
|
cTrader Algoでは、絶対時間または相対バーインデックスのいずれかを提供するメソッドを通じて、時間の位置を定義できます。 チャートにピッチフォークを描画するために使用されるメソッドは、関連するオーバーライドを導入します。 この場合、相対バーインデックスを選択しました。
高値と安値のインデックスを検出するコードを書きます。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 | for (int i = 0; i <= 50; i++)
{
if (Bars.HighPrices.Last(i) == _max)
_highIndex = Bars.Count - i - 1;
}
for (int i = 0; i <= 50; i++)
{
if (Bars.LowPrices.Last(i) == _min1)
_lowIndex1 = Bars.Count - i - 1;
}
for (int i = 0; i <= 10; i++)
{
if (Bars.LowPrices.Last(i) == _min2)
_lowIndex2 = Bars.Count - i - 1;
}
|
チャートにピッチフォークを描画します。
| Chart.DrawAndrewsPitchfork("AndrewsPitchfork", _lowIndex1, _min1, _highIndex, _max, _lowIndex2, _min2, 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 | using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.None, AddIndicators = true)]
public class AndrewsPitchfork : Robot
{
private int _highIndex;
private int _lowIndex1;
private int _lowIndex2;
private double _max;
private double _min1;
private double _min2;
protected override void OnStart()
{
_max = Bars.HighPrices.Maximum(50);
_min1 = Bars.LowPrices.Minimum(50);
_min2 = Bars.LowPrices.Minimum(10);
for (int i = 0; i <= 50; i++)
{
if (Bars.HighPrices.Last(i) == _max)
_highIndex = Bars.Count - i - 1;
}
for (int i = 0; i <= 50; i++)
{
if (Bars.LowPrices.Last(i) == _min1)
_lowIndex1 = Bars.Count - i - 1;
}
for (int i = 0; i <= 10; i++)
{
if (Bars.LowPrices.Last(i) == _min2)
_lowIndex2 = Bars.Count - i - 1;
}
Chart.DrawAndrewsPitchfork("AndrewsPitchfork", _lowIndex1, _min1, _highIndex, _max, _lowIndex2, _min2, Color.Red);
}
protected override void OnTick()
{
// Handle price updates here
}
protected override void OnStop()
{
// Handle cBot stop here
}
}
}
|
cBotをビルドするには、Ctrl+Bホットキーを使用するか、ビルドをクリックします。
cBotのローカルインスタンスを追加します:インスタンスを追加をクリックし、ローカルでオプションを選択してからインスタンスを追加をクリックします。

インスタンスをクリックし、バックテストタブに移動します。 バックテストの期間を選択し、ビジュアルモードオプションを有効にしてから再生アイコンをクリックします。
チャートにAndrews' Pitchforkが描画されているはずです。

アンドリューズのピッチフォークを更新する
Algoアプリに戻り、チャートの変化に合わせてピッチフォークを更新するようにcBotをコーディングします。
ピッチフォークを描画する新しいメソッドを作成し、元のロジックをそのメソッドに移動します。
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 | private void DrawAndrewsPitchfork()
{
_max = Bars.HighPrices.Maximum(50);
_min1 = Bars.LowPrices.Minimum(50);
_min2 = Bars.LowPrices.Minimum(10);
for (int i = 0; i <= 50; i++)
{
if (Bars.HighPrices.Last(i) == _max)
_highIndex = Bars.Count - i - 1;
}
for (int i = 0; i <= 50; i++)
{
if (Bars.LowPrices.Last(i) == _min1)
_lowIndex1 = Bars.Count - i - 1;
}
for (int i = 0; i <= 10; i++)
{
if (Bars.LowPrices.Last(i) == _min2)
_lowIndex2 = Bars.Count - i - 1;
}
if (_lowIndex1 < _highIndex && _highIndex < _lowIndex2)
Chart.DrawAndrewsPitchfork("AndrewsPitchfork", _lowIndex1, _min1, _highIndex, _max, _lowIndex2, _min2, Color.Red);
}
|
OnBar()メソッドで新しいメソッドを呼び出します。
| protected override void OnBar()
{
DrawAndrewsPitchfork();
}
|
上昇トレンドのセットアップのみが必要なため、最小値と最大値が正しい順序にあることを確認する条件付きロジックを書きます。
| if (_lowIndex1 < _highIndex && _highIndex < _lowIndex2)
Chart.DrawAndrewsPitchfork("AndrewsPitchfork", _lowIndex1, _min1, _highIndex, _max, _lowIndex2, _min2, 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 | using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.None, AddIndicators = true)]
public class AndrewsPitchfork : Robot
{
private int _highIndex;
private int _lowIndex1;
private int _lowIndex2;
private double _max;
private double _min1;
private double _min2;
protected override void OnStart()
{
DrawAndrewsPitchfork();
}
private void DrawAndrewsPitchfork()
{
_max = Bars.HighPrices.Maximum(50);
_min1 = Bars.LowPrices.Minimum(50);
_min2 = Bars.LowPrices.Minimum(10);
for (int i = 0; i <= 50; i++)
{
if (Bars.HighPrices.Last(i) == _max)
_highIndex = Bars.Count - i - 1;
}
for (int i = 0; i <= 50; i++)
{
if (Bars.LowPrices.Last(i) == _min1)
_lowIndex1 = Bars.Count - i - 1;
}
for (int i = 0; i <= 10; i++)
{
if (Bars.LowPrices.Last(i) == _min2)
_lowIndex2 = Bars.Count - i - 1;
}
if (_lowIndex1 < _highIndex && _highIndex < _lowIndex2)
Chart.DrawAndrewsPitchfork("AndrewsPitchfork", _lowIndex1, _min1, _highIndex, _max, _lowIndex2, _min2, Color.Red);
}
protected override void OnBar()
{
DrawAndrewsPitchfork();
}
protected override void OnStop()
{
// Handle cBot stop here
}
}
}
|
cBotを再度ビルドし、バックテストを行います。
ビジュアルモードの速度を上げてplayアイコンをクリックします。
今回は、チャートの変化に合わせてピッチフォークが常に再描画されるのが確認できるはずです。

概要
この記事では、シンボルチャートにアンドリューズのピッチフォークを描画する方法と、チャートの変化に合わせてピッチフォークを自動更新するコードの書き方について説明しました。