The Exp T3 TRIX strategy replicates the MetaTrader 5 expert advisor built around the triple-smoothed TRIX oscillator. It applies Tillson T3 smoothing to generate a fast and slow TRIX stream and reacts to momentum reversals using three selectable modes. Each mode controls how the histogram or the relative position of the fast and slow components must behave before the strategy will enter or exit a position.
Trading Logic
Tillson T3 TRIX calculation
Two stacks of six exponential moving averages with the same length produce Tillson T3 values for a fast and a slow stream.
The derivative of each T3 value (current minus previous divided by previous) becomes the TRIX histogram used for decision making.
Mode = Breakdown
Long entry: Fast TRIX crosses from below zero to above zero while long entries are enabled. Any open short position is closed first (if short exits are permitted).
Short entry: Fast TRIX crosses from above zero to below zero while short entries are enabled. Any open long position is closed first (if long exits are permitted).
Exit only: When a cross occurs but the corresponding entry is disabled, the strategy still closes the opposite exposure if the relevant exit permission is enabled.
Mode = Twist
Long entry: The fast TRIX slope changes from negative to positive (i.e., the current bar is rising after falling). The strategy mirrors the closing and permission rules from the Breakdown mode.
Short entry: The fast TRIX slope changes from positive to negative.
Mode = CloudTwist
Long entry: The fast TRIX moves above the slow TRIX after being below it on the previous completed bar.
Short entry: The fast TRIX falls below the slow TRIX after sitting above it on the previous bar.
Order handling
The strategy first closes the opposite exposure when a reversal signal appears and exits are allowed.
New orders use Volume + |Position| so a reversal can be executed in a single trade when permitted.
StartProtection() is activated to reuse the built-in StockSharp safety layer from the original project template.
Parameters
Parameter
Default
Description
Fast Length
10
Depth used for the fast Tillson T3 stack (six linked EMAs).
Slow Length
18
Depth used for the slow Tillson T3 stack.
Volume Factor
0.7
Tillson T3 smoothing coefficient (0 to 1).
Mode
Twist
Chooses between Breakdown, Twist, or CloudTwist signal detection.
Allow Long Entry
true
Enables opening long positions.
Allow Short Entry
true
Enables opening short positions.
Allow Long Exit
true
Enables closing long positions.
Allow Short Exit
true
Enables closing short positions.
Candle Type
4 hour time frame
Aggregation interval used to request candles and feed the indicator chain.
All parameters are exposed through StrategyParam<T> making them visible in the Designer UI and ready for optimization.
Usage Notes
The logic only works with finished candles. Ensure the data source delivers the timeframe configured in Candle Type.
Because the TRIX derivative requires historical values, the first two completed candles are used for initialization and do not produce signals.
To replicate the MetaTrader behavior, disable the corresponding Allow ... flag if you want one-sided trading or exit suppression.
Risk management such as stop-loss or take-profit levels were not included in the original expert advisor and therefore are not implemented here. Combine the strategy with StockSharp money management modules if needed.
Conversion Details
Source: MQL/2156/exp_t3_trix.mq5 plus the t3_trix.mq5 indicator.
API port implements the same three signal modes while using StockSharp high-level candle subscriptions and indicator classes.
Tillson T3 smoothing is recreated using six chained exponential moving averages and the canonical 0.7 volume factor, adjustable through Volume Factor.
using System;
using System.Collections.Generic;
using StockSharp.Algo.Indicators;
using StockSharp.Algo.Strategies;
using StockSharp.BusinessEntities;
using StockSharp.Messages;
namespace StockSharp.Samples.Strategies;
/// <summary>
/// T3 TRIX strategy using TRIX indicator for momentum signals.
/// Trades on TRIX zero-line crossovers.
/// </summary>
public class ExpT3TrixStrategy : Strategy
{
private readonly StrategyParam<DataType> _candleType;
private readonly StrategyParam<int> _period;
private decimal? _prevTrix;
public DataType CandleType
{
get => _candleType.Value;
set => _candleType.Value = value;
}
public int Period
{
get => _period.Value;
set => _period.Value = value;
}
public ExpT3TrixStrategy()
{
_candleType = Param(nameof(CandleType), TimeSpan.FromHours(1).TimeFrame())
.SetDisplay("Candle Type", "Timeframe", "General");
_period = Param(nameof(Period), 14)
.SetGreaterThanZero()
.SetDisplay("Period", "TRIX period", "Indicators");
}
public override IEnumerable<(Security sec, DataType dt)> GetWorkingSecurities()
{
return [(Security, CandleType)];
}
/// <inheritdoc />
protected override void OnReseted()
{
base.OnReseted();
_prevTrix = null;
}
protected override void OnStarted2(DateTime time)
{
base.OnStarted2(time);
_prevTrix = null;
var trix = new Trix { Length = Period };
var subscription = SubscribeCandles(CandleType);
subscription
.Bind(trix, ProcessCandle)
.Start();
var area = CreateChartArea();
if (area != null)
{
DrawCandles(area, subscription);
DrawOwnTrades(area);
}
var indArea = CreateChartArea();
if (indArea != null)
{
DrawIndicator(indArea, trix);
}
}
private void ProcessCandle(ICandleMessage candle, decimal trixValue)
{
if (candle.State != CandleStates.Finished)
return;
if (!IsFormedAndOnlineAndAllowTrading())
{
_prevTrix = trixValue;
return;
}
if (_prevTrix == null)
{
_prevTrix = trixValue;
return;
}
// TRIX crosses above zero → buy
if (_prevTrix.Value <= 0 && trixValue > 0)
{
if (Position < 0)
BuyMarket();
if (Position <= 0)
BuyMarket();
}
// TRIX crosses below zero → sell
else if (_prevTrix.Value >= 0 && trixValue < 0)
{
if (Position > 0)
SellMarket();
if (Position >= 0)
SellMarket();
}
_prevTrix = trixValue;
}
}
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 Trix
from StockSharp.Algo.Strategies import Strategy
class exp_t3_trix_strategy(Strategy):
def __init__(self):
super(exp_t3_trix_strategy, self).__init__()
self._candle_type = self.Param("CandleType", DataType.TimeFrame(TimeSpan.FromHours(1))) \
.SetDisplay("Candle Type", "Timeframe", "General")
self._period = self.Param("Period", 14) \
.SetDisplay("Period", "TRIX period", "Indicators")
self._prev_trix = None
@property
def CandleType(self):
return self._candle_type.Value
@property
def Period(self):
return self._period.Value
def OnReseted(self):
super(exp_t3_trix_strategy, self).OnReseted()
self._prev_trix = None
def OnStarted2(self, time):
super(exp_t3_trix_strategy, self).OnStarted2(time)
self._prev_trix = None
trix = Trix()
trix.Length = self.Period
subscription = self.SubscribeCandles(self.CandleType)
subscription.Bind(trix, self._on_process).Start()
area = self.CreateChartArea()
if area is not None:
self.DrawCandles(area, subscription)
self.DrawOwnTrades(area)
ind_area = self.CreateChartArea()
if ind_area is not None:
self.DrawIndicator(ind_area, trix)
def _on_process(self, candle, trix_value):
if candle.State != CandleStates.Finished:
return
tv = float(trix_value)
if not self.IsFormedAndOnlineAndAllowTrading():
self._prev_trix = tv
return
if self._prev_trix is None:
self._prev_trix = tv
return
# TRIX crosses above zero
if self._prev_trix <= 0 and tv > 0:
if self.Position < 0:
self.BuyMarket()
if self.Position <= 0:
self.BuyMarket()
# TRIX crosses below zero
elif self._prev_trix >= 0 and tv < 0:
if self.Position > 0:
self.SellMarket()
if self.Position >= 0:
self.SellMarket()
self._prev_trix = tv
def CreateClone(self):
return exp_t3_trix_strategy()