Warrior Trading Momentum Strategy
Momentum strategy inspired by Warrior Trading combining gap detection, VWAP and red-to-green setups.
Details
- Entry Criteria: Gap-and-go, red-to-green, or VWAP bounce with volume spike.
- Long/Short: Long only.
- Exit Criteria: ATR-based stop, take profit and trailing.
- Stops: Yes.
- Default Values:
GapThreshold= 2mGapVolumeMultiplier= 2mVwapDistance= 0.5mMinRedCandles= 3RiskRewardRatio= 2mTrailingStopTrigger= 1mMaxDailyTrades= 2CandleType= TimeSpan.FromMinutes(1)
- Filters:
- Category: Momentum
- Direction: Long
- Indicators: VWAP, RSI, EMA, ATR, Volume
- Stops: Yes
- Complexity: Advanced
- Timeframe: Intraday (1m)
- Seasonality: No
- Neural Networks: No
- Divergence: No
- Risk Level: High
using System;
using System.Linq;
using System.Collections.Generic;
using Ecng.Common;
using Ecng.Collections;
using Ecng.Serialization;
using StockSharp.Algo.Indicators;
using StockSharp.Algo.Strategies;
using StockSharp.BusinessEntities;
using StockSharp.Messages;
namespace StockSharp.Samples.Strategies;
/// <summary>
/// Warrior Trading inspired momentum strategy.
/// Detects red-to-green reversals and volume spikes with EMA trend filter.
/// Uses StdDev-based stops with risk/reward targeting.
/// </summary>
public class WarriorTradingMomentumStrategy : Strategy
{
private readonly StrategyParam<int> _minRedCandles;
private readonly StrategyParam<decimal> _riskReward;
private readonly StrategyParam<int> _maxDailyTrades;
private readonly StrategyParam<int> _volAvgLength;
private readonly StrategyParam<decimal> _volMult;
private readonly StrategyParam<DataType> _candleType;
private readonly List<decimal> _volumes = new();
private decimal _stopPrice;
private decimal _takeProfitPrice;
private int _redCount;
private DateTime _currentDay;
private int _dailyTrades;
public int MinRedCandles { get => _minRedCandles.Value; set => _minRedCandles.Value = value; }
public decimal RiskReward { get => _riskReward.Value; set => _riskReward.Value = value; }
public int MaxDailyTrades { get => _maxDailyTrades.Value; set => _maxDailyTrades.Value = value; }
public int VolAvgLength { get => _volAvgLength.Value; set => _volAvgLength.Value = value; }
public decimal VolMult { get => _volMult.Value; set => _volMult.Value = value; }
public DataType CandleType { get => _candleType.Value; set => _candleType.Value = value; }
public WarriorTradingMomentumStrategy()
{
_minRedCandles = Param(nameof(MinRedCandles), 3)
.SetGreaterThanZero()
.SetDisplay("Min Red", "Red candles before reversal", "Momentum");
_riskReward = Param(nameof(RiskReward), 2m)
.SetGreaterThanZero()
.SetDisplay("Risk Reward", "TP to SL ratio", "Risk");
_maxDailyTrades = Param(nameof(MaxDailyTrades), 1)
.SetGreaterThanZero()
.SetDisplay("Max Trades", "Daily trade limit", "Risk");
_volAvgLength = Param(nameof(VolAvgLength), 20)
.SetGreaterThanZero()
.SetDisplay("Vol Avg Length", "Volume average period", "Parameters");
_volMult = Param(nameof(VolMult), 3m)
.SetGreaterThanZero()
.SetDisplay("Vol Mult", "Volume spike multiplier", "Parameters");
_candleType = Param(nameof(CandleType), TimeSpan.FromHours(4).TimeFrame())
.SetDisplay("Candle Type", "Type of candles", "General");
}
public override IEnumerable<(Security sec, DataType dt)> GetWorkingSecurities()
{
return [(Security, CandleType)];
}
protected override void OnReseted()
{
base.OnReseted();
_volumes.Clear();
_stopPrice = 0;
_takeProfitPrice = 0;
_redCount = 0;
_currentDay = default;
_dailyTrades = 0;
}
protected override void OnStarted2(DateTime time)
{
base.OnStarted2(time);
var ema = new ExponentialMovingAverage { Length = 20 };
var rsi = new RelativeStrengthIndex { Length = 14 };
var stdDev = new StandardDeviation { Length = 14 };
_volumes.Clear();
_stopPrice = 0;
_takeProfitPrice = 0;
_redCount = 0;
_currentDay = default;
_dailyTrades = 0;
var subscription = SubscribeCandles(CandleType);
subscription.Bind(ema, rsi, stdDev, ProcessCandle).Start();
var area = CreateChartArea();
if (area != null)
{
DrawCandles(area, subscription);
DrawIndicator(area, ema);
DrawOwnTrades(area);
}
}
private void ProcessCandle(ICandleMessage candle, decimal emaVal, decimal rsiVal, decimal stdVal)
{
if (candle.State != CandleStates.Finished)
return;
var day = candle.OpenTime.Date;
if (day != _currentDay)
{
_currentDay = day;
_dailyTrades = 0;
}
// Track volume
_volumes.Add(candle.TotalVolume);
while (_volumes.Count > VolAvgLength + 1)
_volumes.RemoveAt(0);
// TP/SL exit
if (Position > 0)
{
if (candle.LowPrice <= _stopPrice || candle.HighPrice >= _takeProfitPrice)
{
SellMarket();
_stopPrice = 0;
_takeProfitPrice = 0;
return;
}
}
else if (Position < 0)
{
if (candle.HighPrice >= _stopPrice || candle.LowPrice <= _takeProfitPrice)
{
BuyMarket();
_stopPrice = 0;
_takeProfitPrice = 0;
return;
}
}
// Red candle tracking
if (candle.ClosePrice < candle.OpenPrice)
_redCount++;
else
_redCount = 0;
if (stdVal <= 0 || _volumes.Count < VolAvgLength || _dailyTrades >= MaxDailyTrades)
return;
if (Position != 0)
return;
var volAvg = _volumes.Take(VolAvgLength).Sum() / VolAvgLength;
var volumeSpike = candle.TotalVolume > volAvg * VolMult;
var bullish = candle.ClosePrice > candle.OpenPrice;
// Red-to-green reversal with volume spike
if (_redCount >= MinRedCandles && bullish && volumeSpike && candle.ClosePrice > emaVal && rsiVal > 55)
{
BuyMarket();
var stopDist = stdVal * 2m;
_stopPrice = candle.ClosePrice - stopDist;
_takeProfitPrice = candle.ClosePrice + stopDist * RiskReward;
_dailyTrades++;
}
else if (candle.ClosePrice < emaVal && rsiVal < 45 && volumeSpike)
{
SellMarket();
var stopDist = stdVal * 2m;
_stopPrice = candle.ClosePrice + stopDist;
_takeProfitPrice = candle.ClosePrice - stopDist * RiskReward;
_dailyTrades++;
}
}
}
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, RelativeStrengthIndex, StandardDeviation
from StockSharp.Algo.Strategies import Strategy
class warrior_trading_momentum_strategy(Strategy):
def __init__(self):
super(warrior_trading_momentum_strategy, self).__init__()
self._min_red_candles = self.Param("MinRedCandles", 3) \
.SetDisplay("Min Red", "Red candles before reversal", "Momentum")
self._risk_reward = self.Param("RiskReward", 2.0) \
.SetDisplay("Risk Reward", "TP to SL ratio", "Risk")
self._max_daily_trades = self.Param("MaxDailyTrades", 1) \
.SetDisplay("Max Trades", "Daily trade limit", "Risk")
self._vol_avg_length = self.Param("VolAvgLength", 20) \
.SetDisplay("Vol Avg Length", "Volume average period", "Parameters")
self._vol_mult = self.Param("VolMult", 3.0) \
.SetDisplay("Vol Mult", "Volume spike multiplier", "Parameters")
self._candle_type = self.Param("CandleType", DataType.TimeFrame(TimeSpan.FromHours(4))) \
.SetDisplay("Candle Type", "Type of candles", "General")
self._volumes = []
self._stop_price = 0.0
self._take_profit_price = 0.0
self._red_count = 0
self._current_day = None
self._daily_trades = 0
@property
def min_red_candles(self):
return self._min_red_candles.Value
@property
def risk_reward(self):
return self._risk_reward.Value
@property
def max_daily_trades(self):
return self._max_daily_trades.Value
@property
def vol_avg_length(self):
return self._vol_avg_length.Value
@property
def vol_mult(self):
return self._vol_mult.Value
@property
def candle_type(self):
return self._candle_type.Value
def OnReseted(self):
super(warrior_trading_momentum_strategy, self).OnReseted()
self._volumes = []
self._stop_price = 0.0
self._take_profit_price = 0.0
self._red_count = 0
self._current_day = None
self._daily_trades = 0
def OnStarted2(self, time):
super(warrior_trading_momentum_strategy, self).OnStarted2(time)
ema = ExponentialMovingAverage()
ema.Length = 20
rsi = RelativeStrengthIndex()
rsi.Length = 14
std_dev = StandardDeviation()
std_dev.Length = 14
subscription = self.SubscribeCandles(self.candle_type)
subscription.Bind(ema, rsi, std_dev, self.on_process).Start()
area = self.CreateChartArea()
if area is not None:
self.DrawCandles(area, subscription)
self.DrawIndicator(area, ema)
self.DrawOwnTrades(area)
def on_process(self, candle, ema_val, rsi_val, std_val):
if candle.State != CandleStates.Finished:
return
ema_val = float(ema_val)
rsi_val = float(rsi_val)
std_val = float(std_val)
close = float(candle.ClosePrice)
day = candle.OpenTime.Date
if day != self._current_day:
self._current_day = day
self._daily_trades = 0
self._volumes.append(float(candle.TotalVolume))
while len(self._volumes) > int(self.vol_avg_length) + 1:
self._volumes.pop(0)
if self.Position > 0:
if float(candle.LowPrice) <= self._stop_price or float(candle.HighPrice) >= self._take_profit_price:
self.SellMarket()
self._stop_price = 0.0
self._take_profit_price = 0.0
return
elif self.Position < 0:
if float(candle.HighPrice) >= self._stop_price or float(candle.LowPrice) <= self._take_profit_price:
self.BuyMarket()
self._stop_price = 0.0
self._take_profit_price = 0.0
return
if candle.ClosePrice < candle.OpenPrice:
self._red_count += 1
else:
self._red_count = 0
val = int(self.vol_avg_length)
if std_val <= 0 or len(self._volumes) < val or self._daily_trades >= int(self.max_daily_trades):
return
if self.Position != 0:
return
vol_avg = sum(self._volumes[:val]) / val
volume_spike = float(candle.TotalVolume) > vol_avg * float(self.vol_mult)
bullish = candle.ClosePrice > candle.OpenPrice
if self._red_count >= int(self.min_red_candles) and bullish and volume_spike and close > ema_val and rsi_val > 55:
self.BuyMarket()
stop_dist = std_val * 2.0
self._stop_price = close - stop_dist
self._take_profit_price = close + stop_dist * float(self.risk_reward)
self._daily_trades += 1
elif close < ema_val and rsi_val < 45 and volume_spike:
self.SellMarket()
stop_dist = std_val * 2.0
self._stop_price = close + stop_dist
self._take_profit_price = close - stop_dist * float(self.risk_reward)
self._daily_trades += 1
def CreateClone(self):
return warrior_trading_momentum_strategy()