Neuro Nirvaman EA 2 is a multi-layer perceptron strategy that was originally written for MetaTrader 5. The logic combines four Laguerre-smoothed +DI streams with two SilverTrend breakout detectors. Each bar the strategy evaluates three perceptrons whose weights are controlled by the X parameters. A supervisor module chooses which perceptron output should be traded based on the selected pass mode. Trading is allowed only inside the configured session window and all positions are flattened once the window closes.
Indicators and Signals
Laguerre +DI filters – Each Laguerre block smooths the +DI value of an ADX indicator (gamma = 0.764). The resulting value oscillates between 0 and 1 and is compared to a 0.5 center line with user-defined distance thresholds.
SilverTrend breakout – Two SilverTrend detectors compute dynamic support/resistance envelopes using the last nine bars. The risk setting modifies the envelope width (K = 33 - risk). A transition from bearish to bullish (or vice versa) produces ±1 signals that feed the perceptrons.
Trading Logic
Perceptron #1 uses Laguerre #1 for the tension component and SilverTrend #1 for the breakout component. Weights X11 and X12 offset the contributions relative to 100.
Perceptron #2 mirrors the first perceptron but relies on Laguerre #2 and SilverTrend #2 with weights X21 and X22.
Perceptron #3 combines the tension outputs of Laguerre #3 and Laguerre #4 weighted by X31 and X32.
3 – Open a long position when both perceptron #3 and #2 are positive. Open a short when perceptron #3 is non-positive and perceptron #1 is negative.
4 – Disable trading (matches the default behaviour of the original EA).
Each entry places a fixed-volume market order and records stop-loss / take-profit levels expressed in price steps. Positions are monitored on every finished candle: if the high/low pierces the recorded targets the strategy immediately exits. Leaving the trading window also forces an exit.
Parameters
Name
Description
Risk1, Risk2
SilverTrend risk settings. Higher values shrink the envelope and generate more frequent signals.
LaguerreXPeriod
ADX length that feeds the Laguerre smoother (for each of the four streams).
LaguerreXDistance
Percentage distance around the 0.5 center line that defines bullish/bearish tension.
X11, X12, X21, X22, X31, X32
Perceptron weights (values are offset by 100 inside the formula, exactly as in the MQL version).
TakeProfit1, StopLoss1, TakeProfit2, StopLoss2
Profit target and protective stop distances in price steps for the respective perceptron signals.
Pass
Supervisor mode selector (1–4).
TradeVolume
Base order size used for market entries.
StartHour, StartMinute, EndHour, EndMinute
Trading session boundaries. When the current time is outside this window all positions are closed and no new trades are allowed.
CandleType
Candle subscription to drive the high-level strategy.
Risk Management
The strategy relies on the fixed stop-loss and take-profit distances defined by the perceptron that triggered the entry. No pyramiding or averaging is performed. Because the logic only trades when no position is open, exposure is limited to a single active position and all trades are force-closed once the session window ends.
Notes
Gamma for the Laguerre smoother is fixed at 0.764 to match the MQL implementation.
Pass value 4 keeps the strategy idle, which mirrors the safety default of the original EA.
SilverTrend calculations use indicator primitives (highest, lowest, simple moving average) rather than custom buffers to comply with StockSharp guidelines.
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>
/// NeuroNirvaman EA 2 strategy. Uses DEMA crossover (10/30).
/// </summary>
public class NeuroNirvamanEa2Strategy : Strategy
{
private readonly StrategyParam<DataType> _candleType;
private readonly StrategyParam<int> _fastPeriod;
private readonly StrategyParam<int> _slowPeriod;
private decimal? _prevFast;
private decimal? _prevSlow;
public DataType CandleType { get => _candleType.Value; set => _candleType.Value = value; }
public int FastPeriod { get => _fastPeriod.Value; set => _fastPeriod.Value = value; }
public int SlowPeriod { get => _slowPeriod.Value; set => _slowPeriod.Value = value; }
public NeuroNirvamanEa2Strategy()
{
_candleType = Param(nameof(CandleType), TimeSpan.FromHours(1).TimeFrame()).SetDisplay("Candle Type", "Timeframe", "General");
_fastPeriod = Param(nameof(FastPeriod), 10).SetGreaterThanZero().SetDisplay("Fast DEMA", "Fast DEMA period", "Indicators");
_slowPeriod = Param(nameof(SlowPeriod), 30).SetGreaterThanZero().SetDisplay("Slow DEMA", "Slow DEMA period", "Indicators");
}
public override IEnumerable<(Security sec, DataType dt)> GetWorkingSecurities() => [(Security, CandleType)];
/// <inheritdoc />
protected override void OnReseted()
{
base.OnReseted();
_prevFast = null;
_prevSlow = null;
}
protected override void OnStarted2(DateTime time)
{
base.OnStarted2(time);
_prevFast = null; _prevSlow = null;
var fast = new DoubleExponentialMovingAverage { Length = FastPeriod };
var slow = new DoubleExponentialMovingAverage { Length = SlowPeriod };
var subscription = SubscribeCandles(CandleType);
subscription.Bind(fast, slow, ProcessCandle).Start();
var area = CreateChartArea();
if (area != null) { DrawCandles(area, subscription); DrawIndicator(area, fast); DrawIndicator(area, slow); DrawOwnTrades(area); }
}
private void ProcessCandle(ICandleMessage candle, decimal fast, decimal slow)
{
if (candle.State != CandleStates.Finished) return;
if (!IsFormedAndOnlineAndAllowTrading()) { _prevFast = fast; _prevSlow = slow; return; }
if (_prevFast == null || _prevSlow == null) { _prevFast = fast; _prevSlow = slow; return; }
var prevAbove = _prevFast.Value > _prevSlow.Value;
var currAbove = fast > slow;
_prevFast = fast; _prevSlow = slow;
if (!prevAbove && currAbove && Position <= 0) { if (Position < 0) BuyMarket(); BuyMarket(); }
else if (prevAbove && !currAbove && Position >= 0) { if (Position > 0) SellMarket(); 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 DoubleExponentialMovingAverage
from StockSharp.Algo.Strategies import Strategy
class neuro_nirvaman_ea2_strategy(Strategy):
def __init__(self):
super(neuro_nirvaman_ea2_strategy, self).__init__()
self._candle_type = self.Param("CandleType", DataType.TimeFrame(TimeSpan.FromHours(1))) \
.SetDisplay("Candle Type", "Timeframe", "General")
self._fast_period = self.Param("FastPeriod", 10) \
.SetDisplay("Fast DEMA", "Fast DEMA period", "Indicators")
self._slow_period = self.Param("SlowPeriod", 30) \
.SetDisplay("Slow DEMA", "Slow DEMA period", "Indicators")
self._prev_fast = None
self._prev_slow = None
@property
def CandleType(self):
return self._candle_type.Value
@property
def FastPeriod(self):
return self._fast_period.Value
@property
def SlowPeriod(self):
return self._slow_period.Value
def OnReseted(self):
super(neuro_nirvaman_ea2_strategy, self).OnReseted()
self._prev_fast = None
self._prev_slow = None
def OnStarted2(self, time):
super(neuro_nirvaman_ea2_strategy, self).OnStarted2(time)
self._prev_fast = None
self._prev_slow = None
fast = DoubleExponentialMovingAverage()
fast.Length = self.FastPeriod
slow = DoubleExponentialMovingAverage()
slow.Length = self.SlowPeriod
subscription = self.SubscribeCandles(self.CandleType)
subscription.Bind(fast, slow, self._on_process).Start()
area = self.CreateChartArea()
if area is not None:
self.DrawCandles(area, subscription)
self.DrawIndicator(area, fast)
self.DrawIndicator(area, slow)
self.DrawOwnTrades(area)
def _on_process(self, candle, fast_value, slow_value):
if candle.State != CandleStates.Finished:
return
fv = float(fast_value)
sv = float(slow_value)
if self._prev_fast is None or self._prev_slow is None:
self._prev_fast = fv
self._prev_slow = sv
return
prev_above = self._prev_fast > self._prev_slow
curr_above = fv > sv
self._prev_fast = fv
self._prev_slow = sv
if not prev_above and curr_above and self.Position <= 0:
if self.Position < 0:
self.BuyMarket()
self.BuyMarket()
elif prev_above and not curr_above and self.Position >= 0:
if self.Position > 0:
self.SellMarket()
self.SellMarket()
def CreateClone(self):
return neuro_nirvaman_ea2_strategy()