GitHub で見る

コンボ EA4 FSF R 更新された 5 戦略

概要

この戦略は、MetaTrader エキスパート アドバイザー「Combo_EA4FSFrUpdated5」の StockSharp 変換です。移動平均、RSI、確率オシレーター、放物線 SAR、ゼロラグ MACD の 5 つの異なる技術モジュールを組み合わせて、あらゆる取引上の意思決定を検証します。 すべての有効なモジュールが同じ方向を向いている場合にのみポジションが開かれ、元の EA の厳密なコンセンサス ロジックが再作成されます。オプションのトレーリング管理、自動シグナルベースの出口、およびクローズ後に反対方向に反転する機能も維持されます。

インジケータースタック

  • 移動平均 – 誤ったクロスオーバー信号を減らす、ATR ベースのバッファーを備えた 3 つの構成可能な平均 (MA1、MA2、MA3)。 5 つの異なる集計モードは、EA の「MA_MODE」オプションを複製します。
  • 相対強度指数 (RSI) – 従来の買われ過ぎ/売られ過ぎ、傾きベースのトレンド検出、複合モード、ゾーンベースの検証を含む複数の確認モード。
  • Stochastic オシレーター – 高速/低速/減速の長さ (オプションの高帯域/低帯域フィルタリングあり)。
  • Parabolic SAR – 前回のローソク足の終値に対するトレンドの極性チェックを提供します。
  • ゼロラグ MACD – ゼロラグの指数移動平均を使用して、バンドルされている ZeroLag_MACD.mq4 インジケーターと一致します。 3 つのシグナル モード (トレンド構造、ゼロライン クロス、または組み合わせ) をサポートします。
  • 平均トゥルー レンジ (ATR) – ストップロス/テイクプロフィット距離と MA クロスオーバー バッファーを駆動します。

取引ロジック

エントリー条件

  1. すべての有効なモジュールのインジケーター値が利用可能である必要があります (ストラテジーは自動的にウォームアップを待ちます)。
  2. 有効なモジュールごとに、そのモードに従って強気または弱気の方向が計算されます。
    • 移動平均 – 方向の変化を確認するための ATR バッファーとの MA1/MA2/MA3 の組み合わせ。
    • RSI – しきい値、運動量、ゾーン ロジックをカバーする 4 つのモード。
    • Stochastic – オプションの高/低フィルターを使用した K/D 相互確認。
    • Parabolic SAR – 価格が前のローソク足の SAR 値を上回るか下回る必要があります。
    • ゼロラグ MACD – トレンドの調整、ゼロラインのクロス確認、またはその両方。
  3. すべての有効なモジュールが Buy を返した場合、ストラテジーは成行買い注文を送信します。すべてのモジュールが Sell を返した場合、成行売り注文が発行されます。それ以外の場合、取引は開かれません。

終了条件

  • シグナルベースの終了AutoClose が有効な場合、専用の終了フラグ (UseMaClosingUseMacdClosing など) を使用して同じコンセンサス ロジックが評価されます。ロングポジションは、すべての有効な出口モジュールが弱気シグナルに同意するとクローズされます。強気のシグナルに同意すると、ショートポジションはクローズされます。 OpenOppositeAfterClose が true の場合、反対のポジションは終了約定の直後にキューに入れられます。
  • 保護レベル – 初期のストップロスとテイクプロフィットのレベルは、現在の ATR 値 (AtrPeriod) に AtrMultiplier を乗算して求められます。 EA のピップ バッファは、機器のステップ サイズでエミュレートされます。ロング取引では、ストップに ATR × multiplier − buffer を使用し、ターゲットに ATR × multiplier + buffer を使用します(ショートにはミラーリングされます)。
  • トレーリングストップUseTrailingStop が有効な場合、設定されたポイント距離 (TrailingStop) を使用して、終了したローソク足ごとにストップ価格が調整されます。
  • ハードエグジット – 価格がストップロスまたはテイクプロフィットのイントラバーに達すると、ポジションは即座にクローズされ、反対のエントリーはトリガーされません。

ポジションサイジング

  • 静的モードUseStaticVolume が true の場合、固定の StaticVolume パラメータを使用して取引が行われます。
  • 動的モード – それ以外の場合、戦略はポートフォリオの現在値と RiskPercent からおおよそのサイズを導き出し、ポートフォリオまたは価格データが利用できない場合はベースの Volume にフォールバックします。

パラメーター

グループ パラメータ 説明
エントリー UseMa 移動平均確認を有効にします。
エントリー MaMode MA の組み合わせ (高速/中、中/低速、複合など) を選択します。
指標 Ma1Period, Ma2Period, Ma3Period 3 つの移動平均の期間。
指標 Ma1BufferPeriod, Ma2BufferPeriod ATR 期間は MA クロスチェックのバッファとして使用されます。
指標 Ma1Method, Ma2Method, Ma3Method 移動平均の計算タイプ (SMA、EMA、SMMA、LWMA)。
指標 Ma1Price, Ma2Price, Ma3Price 各移動平均に適用される価格。
エントリー UseRsi RSI の確認を有効にします。
指標 RsiPeriod RSI の計算期間。
エントリー RsiMode RSI 確認モード (買われ過ぎ/売られ過ぎ、トレンド、組み合わせ、ゾーン)。
エントリー RsiBuyLevel, RsiSellLevel 売られすぎ/買われすぎロジックのしきい値。
エントリー RsiBuyZone, RsiSellZone モード 4 のゾーンしきい値。
エントリー UseStochastic 確率的確認を有効にします。
指標 StochasticK, StochasticD, StochasticSlowing K/D/遅いパラメータ。
エントリー UseStochasticHighLow 構成された高/低バンドを壊すには確率論が必要です。
エントリー StochasticHigh, StochasticLow 確率的しきい値の上限と下限。
エントリー UseSar 放物線の SAR 確認を有効にします。
指標 SarStep, SarMax SAR の加速設定。
エントリー UseMacd 遅延ゼロの MACD 確認を有効にします。
指標 MacdFast, MacdSlow, MacdSignal MACD パラメータ。
指標 MacdPrice MACD の適用価格。
エントリー MacdMode MACD 確認モード。
リスク UseTrailingStop, TrailingStop トレーリングストップの切り替えと距離 (ポイント単位)。
リスク UseStaticVolume, StaticVolume, RiskPercent 位置のサイズ調整コントロール。
リスク AtrPeriod, AtrMultiplier リスク管理のための ATR 設定。
出口 AutoClose 終了コンセンサスロジックを有効にします。
出口 OpenOppositeAfterClose 信号に基づいて終了した後、反対方向に反転します。
出口 UseMaClosing, MaModeClosing 移動平均出口の設定。
出口 UseMacdClosing, MacdModeClosing MACD 構成を終了します。
出口 UseRsiClosing, RsiModeClosing RSI 構成を終了します。
出口 UseStochasticClosing Stochastic 終了トグル。
出口 UseSarClosing SAR 終了トグル。
一般 CandleType 主要な時間枠 (デフォルトの 5 分足のローソク足)。

注意事項

  • この戦略は、一度に 1 つのネット ポジション (ロング、ショート、またはフラット) を運用し、MetaTrader の「最大同一注文数」制限を反映した、よりシンプルな StockSharp に優しいアプローチです。
  • 保留中の反対のエントリーは、シグナルベースのエグジットの場合にのみキューに入れられ、ストップロスまたはテイクプロフィットが取引を終了する場合はスキップされます。
  • 口座証拠金要件はブローカー固有であるため、動的なポジションサイジングでは、おおよそのリスクベースの計算式が使用されます。ライブ展開の前に、結果として得られるボリュームを確認します。
  • 元の EA と同様に、ゼロラグの MACD インジケーターと ATR インジケーターに、取引を期待する前に十分なウォームアップ履歴があることを確認してください。
using System;

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

namespace StockSharp.Samples.Strategies;

/// <summary>
/// Combo EA: Triple EMA confirmation with RSI filter and ATR stops.
/// </summary>
public class ComboEa4FsfrUpdated5Strategy : Strategy
{
	private readonly StrategyParam<DataType> _candleType;
	private readonly StrategyParam<int> _fastEmaLength;
	private readonly StrategyParam<int> _slowEmaLength;
	private readonly StrategyParam<int> _rsiLength;
	private readonly StrategyParam<int> _atrLength;

	private decimal _prevFast;
	private decimal _prevSlow;
	private decimal _entryPrice;

	public ComboEa4FsfrUpdated5Strategy()
	{
		_candleType = Param(nameof(CandleType), TimeSpan.FromMinutes(5).TimeFrame())
			.SetDisplay("Candle Type", "Timeframe.", "General");

		_fastEmaLength = Param(nameof(FastEmaLength), 8)
			.SetDisplay("Fast EMA", "Fast EMA period.", "Indicators");

		_slowEmaLength = Param(nameof(SlowEmaLength), 21)
			.SetDisplay("Slow EMA", "Slow EMA period.", "Indicators");

		_rsiLength = Param(nameof(RsiLength), 14)
			.SetDisplay("RSI Length", "RSI period.", "Indicators");

		_atrLength = Param(nameof(AtrLength), 14)
			.SetDisplay("ATR Length", "ATR period.", "Indicators");
	}

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

	public int FastEmaLength
	{
		get => _fastEmaLength.Value;
		set => _fastEmaLength.Value = value;
	}

	public int SlowEmaLength
	{
		get => _slowEmaLength.Value;
		set => _slowEmaLength.Value = value;
	}

	public int RsiLength
	{
		get => _rsiLength.Value;
		set => _rsiLength.Value = value;
	}

	public int AtrLength
	{
		get => _atrLength.Value;
		set => _atrLength.Value = value;
	}

	/// <inheritdoc />
	protected override void OnReseted()
	{
		base.OnReseted();

		_prevFast = 0;
		_prevSlow = 0;
		_entryPrice = 0;
	}

		protected override void OnStarted2(DateTime time)
	{
		base.OnStarted2(time);

		_prevFast = 0;
		_prevSlow = 0;
		_entryPrice = 0;

		var fastEma = new ExponentialMovingAverage { Length = FastEmaLength };
		var slowEma = new ExponentialMovingAverage { Length = SlowEmaLength };
		var rsi = new RelativeStrengthIndex { Length = RsiLength };
		var atr = new AverageTrueRange { Length = AtrLength };

		var subscription = SubscribeCandles(CandleType);
		subscription
			.Bind(fastEma, slowEma, rsi, atr, ProcessCandle)
			.Start();

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

	private void ProcessCandle(ICandleMessage candle, decimal fastVal, decimal slowVal, decimal rsiVal, decimal atrVal)
	{
		if (candle.State != CandleStates.Finished)
			return;

		if (_prevFast == 0 || _prevSlow == 0 || atrVal <= 0)
		{
			_prevFast = fastVal;
			_prevSlow = slowVal;
			return;
		}

		var close = candle.ClosePrice;

		if (Position > 0)
		{
			if (fastVal < slowVal && _prevFast >= _prevSlow)
			{
				SellMarket();
				_entryPrice = 0;
			}
			else if (close <= _entryPrice - atrVal * 2m)
			{
				SellMarket();
				_entryPrice = 0;
			}
		}
		else if (Position < 0)
		{
			if (fastVal > slowVal && _prevFast <= _prevSlow)
			{
				BuyMarket();
				_entryPrice = 0;
			}
			else if (close >= _entryPrice + atrVal * 2m)
			{
				BuyMarket();
				_entryPrice = 0;
			}
		}

		if (Position == 0)
		{
			if (fastVal > slowVal && _prevFast <= _prevSlow && rsiVal > 50)
			{
				_entryPrice = close;
				BuyMarket();
			}
			else if (fastVal < slowVal && _prevFast >= _prevSlow && rsiVal < 50)
			{
				_entryPrice = close;
				SellMarket();
			}
		}

		_prevFast = fastVal;
		_prevSlow = slowVal;
	}
}