GitHub で見る

Renkoスキャルパー戦略

この戦略は現在の終値と前回の終値を比較することで短期モメンタムを捉えようとします。 最新のローソク足が前のローソク足より高く終わった場合、戦略はロングポジションを開きます。 最新のローソク足が前のローソク足より低く終わった場合、ショートポジションを開きます。

ストップとオプションのトレーリングストップは組み込みの保護モジュールで処理されます。 このアプローチは市場の両方向で機能し、純粋に価格行動のみに依存します。

詳細

  • エントリー条件:
    • ロング: Close(t) > Close(t-1)
    • ショート: Close(t) < Close(t-1)
  • ロング/ショート: 両方。
  • エグジット条件: 反対シグナルまたは保護ストップ。
  • ストップ: StartProtection によるオプションのトレーリングストップ、ストップロス、テイクプロフィット。
  • デフォルト値:
    • CandleType = 1分足。
    • StopLossPercent = 1。
    • TakeProfitPercent = 2。
    • IsTrailingStop = true。
  • フィルター:
    • カテゴリ: スキャルピング。
    • 方向: 両方。
    • インジケーター: なし。
    • ストップ: はい。
    • 複雑さ: シンプル。
    • 時間軸: 短期。
    • 季節性: いいえ。
    • ニューラルネットワーク: いいえ。
    • ダイバージェンス: いいえ。
    • リスクレベル: 高。
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>
/// Renko scalper strategy.
/// Opens long when close moves significantly above previous close, short when below.
/// </summary>
public class RenkoScalperStrategy : Strategy
{
	private readonly StrategyParam<DataType> _candleType;

	private decimal _previousClose;
	private bool _hasPrev;

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

	public RenkoScalperStrategy()
	{
		_candleType = Param(nameof(CandleType), TimeSpan.FromHours(4).TimeFrame())
			.SetDisplay("Candle Type", "Type of candles", "General");
	}

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

	protected override void OnReseted()
	{
		base.OnReseted();
		_previousClose = 0;
		_hasPrev = false;
	}

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

		var stdev = new StandardDeviation { Length = 20 };
		SubscribeCandles(CandleType).Bind(stdev, ProcessCandle).Start();
	}

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

		var close = candle.ClosePrice;

		if (!_hasPrev)
		{
			_previousClose = close;
			_hasPrev = true;
			return;
		}

		if (stdevVal <= 0) { _previousClose = close; return; }

		var diff = close - _previousClose;

		if (diff > stdevVal && Position <= 0)
		{
			if (Position < 0) BuyMarket();
			BuyMarket();
		}
		else if (diff < -stdevVal && Position >= 0)
		{
			if (Position > 0) SellMarket();
			SellMarket();
		}

		_previousClose = close;
	}
}