This strategy trades breakouts from a recent price range defined by pivot highs and lows. A position is opened when price closes beyond the previous range extremes. Optional stop loss can use a SuperTrend line or fixed percentage.
Details
Entry Criteria:
Close > previous range high → long
Close < previous range low → short
Long/Short: Configurable (Long, Short, Both).
Exit Criteria: Opposite breakout or stop loss.
Stops: SuperTrend or fixed percentage.
Default Values:
PivotLength = 12
StopLoss = SuperTrend
FixedPercentage = 0.1
SuperTrendPeriod = 10
SuperTrendMultiplier = 3
Filters:
Category: Breakout
Direction: Both
Indicators: Highest, Lowest, SuperTrend
Stops: Optional
Complexity: Low
Timeframe: 1h
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>
/// Liquidity Breakout strategy.
/// Trades breakouts above highest highs / below lowest lows.
/// </summary>
public class LiquidityBreakoutStrategy : Strategy
{
private readonly StrategyParam<int> _pivotLength;
private readonly StrategyParam<DataType> _candleType;
public int PivotLength { get => _pivotLength.Value; set => _pivotLength.Value = value; }
public DataType CandleType { get => _candleType.Value; set => _candleType.Value = value; }
public LiquidityBreakoutStrategy()
{
_pivotLength = Param(nameof(PivotLength), 20).SetGreaterThanZero().SetDisplay("Lookback", "Bars for range", "General");
_candleType = Param(nameof(CandleType), TimeSpan.FromMinutes(5).TimeFrame()).SetDisplay("Candle Type", "Timeframe", "General");
}
/// <inheritdoc />
public override IEnumerable<(Security sec, DataType dt)> GetWorkingSecurities()
{
return [(Security, CandleType)];
}
/// <inheritdoc />
protected override void OnStarted2(DateTime time)
{
base.OnStarted2(time);
var emaShort = new ExponentialMovingAverage { Length = 50 };
var emaLong = new ExponentialMovingAverage { Length = 200 };
var subscription = SubscribeCandles(CandleType);
subscription
.Bind(emaShort, emaLong, ProcessCandle)
.Start();
var area = CreateChartArea();
if (area != null)
{
DrawCandles(area, subscription);
DrawOwnTrades(area);
}
}
private void ProcessCandle(ICandleMessage candle, decimal emaShortVal, decimal emaLongVal)
{
if (candle.State != CandleStates.Finished)
return;
if (emaShortVal <= 0m || emaLongVal <= 0m)
return;
// Simple crossover breakout strategy
var longSignal = emaShortVal > emaLongVal;
var shortSignal = emaShortVal < emaLongVal;
if (longSignal && Position <= 0)
BuyMarket();
else if (shortSignal && Position >= 0)
SellMarket();
}
}
import clr
clr.AddReference("StockSharp.Messages")
clr.AddReference("StockSharp.Algo")
clr.AddReference("StockSharp.Algo.Indicators")
clr.AddReference("StockSharp.Algo.Strategies")
from System import TimeSpan
from StockSharp.Messages import DataType, CandleStates
from StockSharp.Algo.Indicators import ExponentialMovingAverage
from StockSharp.Algo.Strategies import Strategy
class liquidity_breakout_strategy(Strategy):
def __init__(self):
super(liquidity_breakout_strategy, self).__init__()
self._pivot_length = self.Param("PivotLength", 20) \
.SetGreaterThanZero() \
.SetDisplay("Lookback", "Bars for range", "General")
self._candle_type = self.Param("CandleType", DataType.TimeFrame(TimeSpan.FromMinutes(5))) \
.SetDisplay("Candle Type", "Timeframe", "General")
@property
def candle_type(self):
return self._candle_type.Value
@candle_type.setter
def candle_type(self, value):
self._candle_type.Value = value
def OnStarted2(self, time):
super(liquidity_breakout_strategy, self).OnStarted2(time)
ema_short = ExponentialMovingAverage()
ema_short.Length = 50
ema_long = ExponentialMovingAverage()
ema_long.Length = 200
subscription = self.SubscribeCandles(self.candle_type)
subscription.Bind(ema_short, ema_long, self.OnProcess).Start()
area = self.CreateChartArea()
if area is not None:
self.DrawCandles(area, subscription)
self.DrawOwnTrades(area)
def OnProcess(self, candle, ema_short_val, ema_long_val):
if candle.State != CandleStates.Finished:
return
sv = float(ema_short_val)
lv = float(ema_long_val)
if sv <= 0.0 or lv <= 0.0:
return
if sv > lv and self.Position <= 0:
self.BuyMarket()
elif sv < lv and self.Position >= 0:
self.SellMarket()
def CreateClone(self):
return liquidity_breakout_strategy()