View on GitHub

Liquidex V1 Strategy

Liquidex V1 is a breakout scalping strategy converted from the original MQL expert advisor. It combines a range filter and a weighted moving average (WMA) to identify short‑term opportunities.

Trading Logic

  1. For every finished candle the strategy measures its range (high - low).
  2. If the candle range is smaller than RangeFilter, the candle is ignored.
  3. A WMA with period MaPeriod is calculated using closing prices.
  4. When the candle opens below the WMA and closes above it, a buy market order is sent.
  5. When the candle opens above the WMA and closes below it, a sell market order is sent.
  6. Each position is protected by a stop loss defined in StopLoss.

Parameters

  • RangeFilter – minimum candle range in price units required to trade.
  • MaPeriod – number of periods for the weighted moving average.
  • StopLoss – protective stop loss in points.
  • CandleType – candle series used for analysis.

The strategy uses Strategy.Volume as order size and reverses the position when an opposite signal appears.

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>
/// WMA crossover strategy with range filter.
/// </summary>
public class LiquidexV1Strategy : Strategy
{
	private readonly StrategyParam<int> _maPeriod;
	private readonly StrategyParam<DataType> _candleType;

	private decimal _prevClose;
	private decimal _prevWma;
	private bool _hasPrev;

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

	public LiquidexV1Strategy()
	{
		_maPeriod = Param(nameof(MaPeriod), 10)
			.SetGreaterThanZero()
			.SetDisplay("MA Period", "WMA period", "Indicators");
		_candleType = Param(nameof(CandleType), TimeSpan.FromHours(4).TimeFrame())
			.SetDisplay("Candle Type", "Candle type", "General");
	}

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

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

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

		var wma = new WeightedMovingAverage { Length = MaPeriod };

		SubscribeCandles(CandleType)
			.Bind(wma, ProcessCandle)
			.Start();
	}

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

		if (!_hasPrev)
		{
			_prevClose = candle.ClosePrice;
			_prevWma = wmaVal;
			_hasPrev = true;
			return;
		}

		var crossUp = _prevClose <= _prevWma && candle.ClosePrice > wmaVal;
		var crossDown = _prevClose >= _prevWma && candle.ClosePrice < wmaVal;

		if (crossUp && Position <= 0)
		{
			if (Position < 0) BuyMarket();
			BuyMarket();
		}
		else if (crossDown && Position >= 0)
		{
			if (Position > 0) SellMarket();
			SellMarket();
		}

		_prevClose = candle.ClosePrice;
		_prevWma = wmaVal;
	}
}