Ver en GitHub

Estrategia Lorenzo SuperScalp

Esta estrategia de scalping combina RSI, Bandas de Bollinger y MACD. Compra cuando el RSI está por debajo de 45, el precio está cerca de la banda inferior y el MACD cruza hacia arriba. Vende cuando el RSI está por encima de 55, el precio está cerca de la banda superior y el MACD cruza hacia abajo. Un número mínimo de barras entre operaciones evita la re-entrada rápida.

Detalles

  • Criterios de entrada:
    • Largo: RSI < 45 && Close < LowerBand * 1.02 && MACD cruza por encima de la señal.
    • Corto: RSI > 55 && Close > UpperBand * 0.98 && MACD cruza por debajo de la señal.
  • Largo/Corto: Ambos.
  • Criterios de salida: Señal opuesta.
  • Stops: Ninguno.
  • Valores predeterminados:
    • RSI Length = 14
    • Bollinger Length = 20
    • Bollinger Multiplier = 2
    • MACD Fast = 12
    • MACD Slow = 26
    • MACD Signal = 9
    • Min Bars = 15
  • Filtros:
    • Categoría: Seguimiento de tendencia
    • Dirección: Ambos
    • Indicadores: Múltiples
    • Stops: No
    • Complejidad: Moderado
    • Marco temporal: Corto plazo
    • Estacionalidad: No
    • Redes neuronales: No
    • Divergencia: No
    • Nivel de riesgo: Medio
using System;

using Ecng.Common;

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

namespace StockSharp.Samples.Strategies;

public class LorenzoSuperScalpStrategy : Strategy
{
	private readonly StrategyParam<int> _rsiLength;
	private readonly StrategyParam<int> _bbLength;
	private readonly StrategyParam<DataType> _candleType;

	public int RsiLength { get => _rsiLength.Value; set => _rsiLength.Value = value; }
	public int BbLength { get => _bbLength.Value; set => _bbLength.Value = value; }
	public DataType CandleType { get => _candleType.Value; set => _candleType.Value = value; }

	public LorenzoSuperScalpStrategy()
	{
		_rsiLength = Param(nameof(RsiLength), 14).SetGreaterThanZero();
		_bbLength = Param(nameof(BbLength), 20).SetGreaterThanZero();
		_candleType = Param(nameof(CandleType), TimeSpan.FromMinutes(5).TimeFrame());
	}

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

		var rsi = new RelativeStrengthIndex { Length = RsiLength };
		var bb = new BollingerBands { Length = BbLength, Width = 2m };

		var lastSignal = DateTimeOffset.MinValue;
		var cooldown = TimeSpan.FromMinutes(360);

		var subscription = SubscribeCandles(CandleType);
		subscription
			.BindEx(rsi, bb, (candle, rsiVal, bbVal) =>
			{
				if (candle.State != CandleStates.Finished)
					return;

				if (!rsiVal.IsFormed || !bbVal.IsFormed)
					return;

				var r = rsiVal.ToDecimal();

				var bbTyped = (BollingerBandsValue)bbVal;
				if (bbTyped.UpBand is not decimal upper || bbTyped.LowBand is not decimal lower)
					return;

				if (candle.OpenTime - lastSignal < cooldown)
					return;

				if (r < 45m && candle.ClosePrice <= lower && Position <= 0)
				{
					BuyMarket();
					lastSignal = candle.OpenTime;
				}
				else if (r > 55m && candle.ClosePrice >= upper && Position >= 0)
				{
					SellMarket();
					lastSignal = candle.OpenTime;
				}
			})
			.Start();

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