GitHub で見る

Aroon Horn Sign 戦略

Aroon Horn Sign 戦略は、Aroonインジケーターを使用してトレンドのリバーサルを探します。 上位の時間軸のローソク足でAroon UpとAroon Downラインを監視します。Aroon Up ラインがAroon Downラインを上回り、50レベルを維持すると、 潜在的な強気のリバーサルを示します。戦略はショートポジションをすべて決済し、新しいロングポジションを開設します。 逆に、Aroon Downが50を超えて優勢な場合は、 既存のロングポジションが決済され、ショートポジションが開設されます。

このアプローチは価格単位で表現された固定のテイクプロフィットとストップロスレベルを使用します。 これらのレベルは組み込みのリスク保護モジュールを通じて有効化されます。 ロジックはAroonの値のみに依存するため、追加フィルターなしで異なる 市場や時間軸で機能します。

詳細

  • データ: 価格ローソク足。
  • エントリー条件:
    • ロング: Aroon Up > Aroon Down かつ Aroon Up >= 50。
    • ショート: Aroon Down > Aroon Up かつ Aroon Down >= 50。
  • エグジット条件:
    • ショートのエントリー条件が現れたときにロングポジションが決済される。
    • ロングのエントリー条件が現れたときにショートポジションが決済される。
  • ストップ: StartProtection を使った固定ストップロスとテイクプロフィット。
  • デフォルト値:
    • AroonPeriod = 9
    • CandleType = 4時間足ローソク
    • TakeProfit = 2000 (価格単位)
    • StopLoss = 1000 (価格単位)
  • フィルター:
    • カテゴリ: トレンドリバーサル
    • 方向: ロングとショート
    • インジケーター: Aroon
    • 複雑さ: シンプル
    • リスクレベル: 中
using System;
using System.Collections.Generic;

using Ecng.Common;

using StockSharp.Algo.Indicators;
using StockSharp.Algo.Strategies;
using StockSharp.BusinessEntities;
using StockSharp.Messages;

namespace StockSharp.Samples.Strategies;

/// <summary>
/// Aroon Horn Sign trend reversal strategy.
/// Opens long when Aroon Up crosses above Aroon Down above 50.
/// Opens short when the opposite occurs.
/// </summary>
public class AroonHornSignStrategy : Strategy
{
	private readonly StrategyParam<int> _aroonPeriod;
	private readonly StrategyParam<DataType> _candleType;

	private int _prevTrend;

	public int AroonPeriod { get => _aroonPeriod.Value; set => _aroonPeriod.Value = value; }
	public DataType CandleType { get => _candleType.Value; set => _candleType.Value = value; }

	public AroonHornSignStrategy()
	{
		_aroonPeriod = Param(nameof(AroonPeriod), 9)
			.SetDisplay("Aroon Period", "Aroon indicator period", "Indicators");

		_candleType = Param(nameof(CandleType), TimeSpan.FromHours(4).TimeFrame())
			.SetDisplay("Candle Type", "Timeframe for processing", "General");
	}

	/// <inheritdoc />
	public override IEnumerable<(Security sec, DataType dt)> GetWorkingSecurities()
		=> [(Security, CandleType)];

	/// <inheritdoc />
	protected override void OnReseted()
	{
		base.OnReseted();
		_prevTrend = 0;
	}

	/// <inheritdoc />
	protected override void OnStarted2(DateTime time)
	{
		base.OnStarted2(time);

		_prevTrend = 0;

		var aroon = new Aroon { Length = AroonPeriod };

		var subscription = SubscribeCandles(CandleType);
		subscription
			.BindEx(aroon, ProcessCandle)
			.Start();

		var area = CreateChartArea();
		if (area != null)
		{
			DrawCandles(area, subscription);
			DrawIndicator(area, aroon);
			DrawOwnTrades(area);
		}
	}

	private void ProcessCandle(ICandleMessage candle, IIndicatorValue aroonValue)
	{
		if (candle.State != CandleStates.Finished)
			return;

		if (!IsFormedAndOnlineAndAllowTrading())
			return;

		var value = (IAroonValue)aroonValue;

		var up = value.Up;
		var down = value.Down;

		if (up is null || down is null)
			return;

		var trend = _prevTrend;

		if (up > down && up >= 50m)
			trend = 1;
		else if (down > up && down >= 50m)
			trend = -1;

		if (_prevTrend <= 0 && trend > 0 && Position <= 0)
			BuyMarket();
		else if (_prevTrend >= 0 && trend < 0 && Position >= 0)
			SellMarket();

		_prevTrend = trend;
	}
}