GitHub で見る

Color Schaff JCCX トレンドサイクル戦略

この戦略は、MQL5エキスパートExp_ColorSchaffJCCXTrendCycleのC#変換です。 JCCXアルゴリズムに基づいた**Schaff Trend Cycle (STC)**オシレーターを採用しています。

トレードロジック

  • 各完了ローソク足でSchaff Trend Cycleを計算する。
  • オシレーターがHigh Levelを上回った後に下回ると、ロングポジションを開きショートポジションを決済する。
  • オシレーターがLow Levelを下回った後に上回ると、ショートポジションを開きロングポジションを決済する。

パラメーター

名前 説明
Fast JCCX インジケーターで使用する高速JCCX期間。
Slow JCCX インジケーターで使用する低速JCCX期間。
Smoothing JCCXのJJMA平滑化係数。
Phase JJMA位相値。
Cycle Schaff Trend計算のサイクル長。
High Level オシレーターの上側トリガーレベル。
Low Level オシレーターの下側トリガーレベル。
Open Long ロングポジションの開設を許可する。
Open Short ショートポジションの開設を許可する。
Close Long 既存のロングポジションの決済を許可する。
Close Short 既存のショートポジションの決済を許可する。

注記

この戦略はStockSharpの高レベルAPIを使用し、ローソク足データを購読します。完了したローソク足にのみ反応します。資金管理とリスク管理はデモンストレーション目的でシンプルに保たれています。

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>
/// Strategy based on the Schaff Trend Cycle indicator level crossovers.
/// </summary>
public class ColorSchaffJccxTrendCycleStrategy : Strategy
{
	private readonly StrategyParam<decimal> _highLevel;
	private readonly StrategyParam<decimal> _lowLevel;
	private readonly StrategyParam<DataType> _candleType;

	private decimal? _prev;

	public decimal HighLevel { get => _highLevel.Value; set => _highLevel.Value = value; }
	public decimal LowLevel { get => _lowLevel.Value; set => _lowLevel.Value = value; }
	public DataType CandleType { get => _candleType.Value; set => _candleType.Value = value; }

	public ColorSchaffJccxTrendCycleStrategy()
	{
		_highLevel = Param(nameof(HighLevel), 75m)
			.SetDisplay("High Level", "Upper trigger level", "Signal");

		_lowLevel = Param(nameof(LowLevel), 25m)
			.SetDisplay("Low Level", "Lower trigger level", "Signal");

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

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

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

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

		var stc = new SchaffTrendCycle();

		var subscription = SubscribeCandles(CandleType);
		subscription
			.Bind(stc, ProcessCandle)
			.Start();

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

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

		if (_prev is null)
		{
			_prev = stc;
			return;
		}

		if (_prev > HighLevel && stc <= HighLevel && Position <= 0)
		{
			if (Position < 0) BuyMarket();
			BuyMarket();
		}
		else if (_prev < LowLevel && stc >= LowLevel && Position >= 0)
		{
			if (Position > 0) SellMarket();
			SellMarket();
		}

		_prev = stc;
	}
}