GitHub で見る

Cronex DeMarker 戦略

Cronex DeMarker戦略は、DeMarkerオシレーターを二重平滑化スタックと組み合わせたクラシックなCronexエキスパートアドバイザーを再現します。まず、DeMarker値がファスト単純移動平均で平滑化され、次にその結果がより遅い平均でもう一度平滑化されます。これら2本のラインの距離と相対的な順序が逆張りスタイルのエントリーシグナルを提供します。

元のMQL5実装はトレード方向の切り替えを許可し、上位時間軸で動作します。このStockSharpポートは同じ哲学を維持します:ファストラインがスローラインを通過してクロスしたとき反応し、即座に反対ポジションを閉じます。システムは逆張りなので、スローラインを下回るクロスはロングポジションを開き、上回るクロスはショートを開きます。両方向はパラメーターを通じて独立して無効化でき、戦略をさまざまなポートフォリオ配分に柔軟にします。

仕組み

  1. 選択した時間軸のローソク足をリクエストする(デフォルトは4H)。
  2. DeMarkerオシレーターを計算し、ファストSMAで平滑化する(デフォルト14バー)。
  3. ファストライン上に第2SMA(デフォルト25バー)を適用してシグナルラインを得る。
  4. ファストラインが前のローソク足でスローラインを上回っており、現在下回った場合、戦略が買う(逆張り反転)。既存のショートポジションはフラット化される。
  5. ファストラインが前のローソク足でスローラインを下回っており、現在上回った場合、戦略が売ってオープンロングポジションを閉じる。
  6. ポジションサイズはVolumeプロパティで定義される;反転は即座に転換するために絶対ポジションを使用する。

このロジックにより、エキスパートは強いモメンタムプッシュ後の短期的な疲弊ムーブを捕捉でき、レンジやチョッピーな市場を好む平均回帰ツールになります。

デフォルトパラメーター

パラメーター デフォルト 説明
DeMarkerPeriod 25 DeMarkerオシレーターが使用するバーの数。
FastPeriod 14 DeMarker値に適用する第1平滑化SMAの長さ。
SlowPeriod 25 ファストラインに適用するシグナルSMAの長さ。
CandleType 4時間 インジケーター計算に使用するローソク足シリーズ。
EnableLongEntry true ファストラインがスローラインを下回ってクロスしたとき、逆張りロングエントリーを許可する。
EnableShortEntry true ファストラインがスローラインを上回ってクロスしたとき、ショートエントリーを許可する。
EnableLongExit true 弱気条件が現れたとき、既存のロングポジションを閉じる。
EnableShortExit true 強気条件が現れたとき、既存のショートポジションを閉じる。

フィルターとタグ

  • カテゴリ: 平均回帰、オシレーターベース
  • 方向: ロングとショート(設定可能)
  • インジケーター: DeMarker、単純移動平均(二重平滑化)
  • ストップ: なし(完全にシグナル駆動)
  • 時間軸: スイングトレード(デフォルトH4、調整可能)
  • 複雑さ: 連続インジケーターチェーンのため中級
  • リスクプロファイル: 中 — 逆張りエントリーは延長されたトレンドに直面する可能性がある
  • 自動化: StockSharpの高レベルAPIを通じて完全自動化

使用上の注意

  • 戦略は再描画の問題を避けるために完成したローソク足のみを処理する。
  • 反転注文は絶対ポジションサイズを再利用し、新しい方向に入る前の即座のフラット化を保証する。
  • チャート出力は2本の平滑化ラインとトレードマーカーを描画し、裁量的な検証を助ける。
  • 一方向のみを許可するポートフォリオでは、提供されたパラメーターを通じて不要なエントリーとエグジットを無効にする。
  • ボラティリティの高い資産に展開する際は、外部リスクコントロール(ストップロス、トレーリング出口)の追加を検討する。
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;

public class CronexDeMarkerStrategy : Strategy
{
	private readonly StrategyParam<int> _fastPeriod;
	private readonly StrategyParam<int> _slowPeriod;
	private readonly StrategyParam<int> _stopLossPoints;
	private readonly StrategyParam<int> _takeProfitPoints;

	private ExponentialMovingAverage _fast;
	private ExponentialMovingAverage _slow;

	private decimal _prevFast;
	private decimal _prevSlow;
	private decimal _entryPrice;
	private int _cooldown;

	public int FastPeriod { get => _fastPeriod.Value; set => _fastPeriod.Value = value; }
	public int SlowPeriod { get => _slowPeriod.Value; set => _slowPeriod.Value = value; }
	public int StopLossPoints { get => _stopLossPoints.Value; set => _stopLossPoints.Value = value; }
	public int TakeProfitPoints { get => _takeProfitPoints.Value; set => _takeProfitPoints.Value = value; }

	public CronexDeMarkerStrategy()
	{
		_fastPeriod = Param(nameof(FastPeriod), 14).SetGreaterThanZero().SetDisplay("Fast Period", "Fast EMA period", "Indicator");
		_slowPeriod = Param(nameof(SlowPeriod), 50).SetGreaterThanZero().SetDisplay("Slow Period", "Slow EMA period", "Indicator");
		_stopLossPoints = Param(nameof(StopLossPoints), 200).SetNotNegative().SetDisplay("Stop Loss", "Stop-loss in price steps", "Risk");
		_takeProfitPoints = Param(nameof(TakeProfitPoints), 400).SetNotNegative().SetDisplay("Take Profit", "Take-profit in price steps", "Risk");
	}

	public override IEnumerable<(Security sec, DataType dt)> GetWorkingSecurities()
	{
		yield return (Security, TimeSpan.FromMinutes(5).TimeFrame());
	}

	protected override void OnReseted()
	{
		base.OnReseted();
		_fast = null; _slow = null;
		_prevFast = 0; _prevSlow = 0; _entryPrice = 0; _cooldown = 0;
	}

	protected override void OnStarted2(DateTime time)
	{
		base.OnStarted2(time);
		_fast = new ExponentialMovingAverage { Length = FastPeriod };
		_slow = new ExponentialMovingAverage { Length = SlowPeriod };
		var subscription = SubscribeCandles(TimeSpan.FromMinutes(5).TimeFrame());
		subscription.Bind(_fast, _slow, ProcessCandle);
		subscription.Start();
	}

	private void ProcessCandle(ICandleMessage candle, decimal fastValue, decimal slowValue)
	{
		if (candle.State != CandleStates.Finished) return;
		if (!_fast.IsFormed || !_slow.IsFormed) { _prevFast = fastValue; _prevSlow = slowValue; return; }
		if (_cooldown > 0) { _cooldown--; _prevFast = fastValue; _prevSlow = slowValue; return; }

		var close = candle.ClosePrice;
		var step = Security?.PriceStep ?? 1m;

		if (Position > 0 && _entryPrice > 0)
		{
			if (StopLossPoints > 0 && close <= _entryPrice - StopLossPoints * step) { SellMarket(); _entryPrice = 0; _cooldown = 100; _prevFast = fastValue; _prevSlow = slowValue; return; }
			if (TakeProfitPoints > 0 && close >= _entryPrice + TakeProfitPoints * step) { SellMarket(); _entryPrice = 0; _cooldown = 100; _prevFast = fastValue; _prevSlow = slowValue; return; }
		}
		else if (Position < 0 && _entryPrice > 0)
		{
			if (StopLossPoints > 0 && close >= _entryPrice + StopLossPoints * step) { BuyMarket(); _entryPrice = 0; _cooldown = 100; _prevFast = fastValue; _prevSlow = slowValue; return; }
			if (TakeProfitPoints > 0 && close <= _entryPrice - TakeProfitPoints * step) { BuyMarket(); _entryPrice = 0; _cooldown = 100; _prevFast = fastValue; _prevSlow = slowValue; return; }
		}

		if (_prevFast <= _prevSlow && fastValue > slowValue && Position <= 0)
		{ if (Position < 0) BuyMarket(); BuyMarket(); _entryPrice = close; _cooldown = 100; }
		else if (_prevFast >= _prevSlow && fastValue < slowValue && Position >= 0)
		{ if (Position > 0) SellMarket(); SellMarket(); _entryPrice = close; _cooldown = 100; }

		_prevFast = fastValue; _prevSlow = slowValue;
	}
}