Auf GitHub ansehen

MultiLayer Acceleration Deceleration Strategy

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); }
	}
}