This strategy layers up to five long entries using the Acceleration/Deceleration oscillator. A new buy stop is placed above the bar's high each time momentum builds in the direction of the trend identified by fractals and the Alligator teeth. When the oscillator weakens or the trend reverses, all pending orders are cancelled and the position is closed.
Details
Entry Criteria:
Uptrend confirmed when price breaks an up fractal above the Alligator teeth.
AC oscillator prints a green bar pattern and the close is above the EMA filter.
Up to five stop orders are placed at the activation level.
Long/Short: Long only.
Exit Criteria:
Trend flips to down.
Oscillator turns negative.
Stops: Uses fractal-based stop loss.
Default Values:
EMA Length = 100.
Filters:
Category: Trend following
Direction: Long
Indicators: Multiple
Stops: Yes
Complexity: Complex
Timeframe: Medium-term
Seasonality: No
Neural networks: No
Divergence: No
Risk level: Medium
using System;
using Ecng.Common;
using StockSharp.Algo.Indicators;
using StockSharp.Algo.Strategies;
using StockSharp.BusinessEntities;
using StockSharp.Messages;
namespace StockSharp.Samples.Strategies;
public class MultiLayerAccelerationDecelerationStrategy : Strategy
{
private readonly StrategyParam<DataType> _candleType;
public DataType CandleType { get => _candleType.Value; set => _candleType.Value = value; }
public MultiLayerAccelerationDecelerationStrategy()
{
_candleType = Param(nameof(CandleType), TimeSpan.FromMinutes(15).TimeFrame());
}
protected override void OnStarted2(DateTime time)
{
base.OnStarted2(time);
var fast = new ExponentialMovingAverage { Length = 10 };
var slow = new ExponentialMovingAverage { Length = 30 };
var rsi = new RelativeStrengthIndex { Length = 14 };
var prevF = 0m; var prevS = 0m; var init = false;
var sub = SubscribeCandles(CandleType);
sub.Bind(fast, slow, rsi, (c, f, s, r) =>
{
if (c.State != CandleStates.Finished || !fast.IsFormed || !slow.IsFormed || !rsi.IsFormed) return;
if (!init) { prevF = f; prevS = s; init = true; return; }
if (prevF <= prevS && f > s && r > 45 && Position <= 0) BuyMarket();
else if (prevF >= prevS && f < s && r < 55 && Position > 0) SellMarket();
prevF = f; prevS = s;
}).Start();
var area = CreateChartArea();
if (area != null) { DrawCandles(area, sub); DrawIndicator(area, fast); DrawIndicator(area, slow); DrawOwnTrades(area); }
}
}
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
from StockSharp.Algo.Strategies import Strategy
class multi_layer_acceleration_deceleration_strategy(Strategy):
def __init__(self):
super(multi_layer_acceleration_deceleration_strategy, self).__init__()
self._candle_type = self.Param("CandleType", DataType.TimeFrame(TimeSpan.FromMinutes(15)))
self._prev_fast = 0.0
self._prev_slow = 0.0
self._initialized = False
@property
def candle_type(self):
return self._candle_type.Value
@candle_type.setter
def candle_type(self, value):
self._candle_type.Value = value
def OnReseted(self):
super(multi_layer_acceleration_deceleration_strategy, self).OnReseted()
self._prev_fast = 0.0
self._prev_slow = 0.0
self._initialized = False
def OnStarted2(self, time):
super(multi_layer_acceleration_deceleration_strategy, self).OnStarted2(time)
self._prev_fast = 0.0
self._prev_slow = 0.0
self._initialized = False
self._fast = ExponentialMovingAverage()
self._fast.Length = 10
self._slow = ExponentialMovingAverage()
self._slow.Length = 30
self._rsi = RelativeStrengthIndex()
self._rsi.Length = 14
subscription = self.SubscribeCandles(self.candle_type)
subscription.Bind(self._fast, self._slow, self._rsi, self.OnProcess).Start()
def OnProcess(self, candle, f, s, r):
if candle.State != CandleStates.Finished:
return
if not self._fast.IsFormed or not self._slow.IsFormed or not self._rsi.IsFormed:
return
fv = float(f)
sv = float(s)
rv = float(r)
if not self._initialized:
self._prev_fast = fv
self._prev_slow = sv
self._initialized = True
return
if self._prev_fast <= self._prev_slow and fv > sv and rv > 45.0 and self.Position <= 0:
self.BuyMarket()
elif self._prev_fast >= self._prev_slow and fv < sv and rv < 55.0 and self.Position > 0:
self.SellMarket()
self._prev_fast = fv
self._prev_slow = sv
def CreateClone(self):
return multi_layer_acceleration_deceleration_strategy()