利弗莫尔-塞科塔突破
该策略结合利弗莫尔枢轴点与塞科塔趋势过滤,并使用ATR进行退出。
测试显示年化收益约87%,在股票市场表现最佳。
策略寻找价格突破最近的枢轴点,同时通过EMA排列和成交量确认趋势方向,并使用ATR止损或移动止损管理风险。
详情
- 入场条件: 价格在趋势和成交量确认下突破最后的枢轴点
- 多空方向: 双向
- 退出条件: ATR止损或移动止损
- 止损: 基于ATR的止损与追踪
- 默认值:
MainEmaLength= 50FastEmaLength= 20SlowEmaLength= 200PivotLength= 3AtrLength= 14StopAtrMultiplier= 3TrailAtrMultiplier= 2VolumeSmaLength= 20CandleType= TimeSpan.FromMinutes(15)
- 过滤器:
- 类型: 突破
- 方向: 双向
- 指标: EMA, 成交量, ATR, Pivot
- 止损: ATR 追踪
- 复杂度: 基础
- 时间框架: 日内 (15m)
- 季节性: 无
- 神经网络: 无
- 背离: 无
- 风险等级: 中
using System;
using Ecng.Common;
using StockSharp.Algo.Indicators;
using StockSharp.Algo.Strategies;
using StockSharp.Messages;
namespace StockSharp.Samples.Strategies;
public class LivermoreSeykotaBreakoutStrategy : Strategy
{
private readonly StrategyParam<int> _emaLength;
private readonly StrategyParam<int> _pivotLength;
private readonly StrategyParam<int> _atrLength;
private readonly StrategyParam<decimal> _trailAtrMultiplier;
private readonly StrategyParam<DataType> _candleType;
private readonly StrategyParam<int> _cooldownBars;
private ExponentialMovingAverage _ema;
private AverageTrueRange _atr;
private Highest _highest;
private Lowest _lowest;
private decimal _prevHighest;
private decimal _prevLowest;
private int _barsSinceSignal;
public int EmaLength { get => _emaLength.Value; set => _emaLength.Value = value; }
public int PivotLength { get => _pivotLength.Value; set => _pivotLength.Value = value; }
public int AtrLength { get => _atrLength.Value; set => _atrLength.Value = value; }
public decimal TrailAtrMultiplier { get => _trailAtrMultiplier.Value; set => _trailAtrMultiplier.Value = value; }
public DataType CandleType { get => _candleType.Value; set => _candleType.Value = value; }
public int CooldownBars { get => _cooldownBars.Value; set => _cooldownBars.Value = value; }
public LivermoreSeykotaBreakoutStrategy()
{
_emaLength = Param(nameof(EmaLength), 50)
.SetDisplay("EMA Length", "EMA trend period", "Indicators");
_pivotLength = Param(nameof(PivotLength), 30)
.SetDisplay("Pivot Length", "Bars for pivot high/low", "General");
_atrLength = Param(nameof(AtrLength), 14)
.SetDisplay("ATR Length", "ATR period", "Indicators");
_trailAtrMultiplier = Param(nameof(TrailAtrMultiplier), 10m)
.SetDisplay("Trail ATR Mult", "ATR trailing mult", "Risk");
_candleType = Param(nameof(CandleType), TimeSpan.FromMinutes(15).TimeFrame())
.SetDisplay("Candle Type", "Candles", "General");
_cooldownBars = Param(nameof(CooldownBars), 50)
.SetDisplay("Cooldown Bars", "Min bars between signals", "General");
}
/// <inheritdoc />
protected override void OnReseted()
{
base.OnReseted();
_ema = null;
_atr = null;
_highest = null;
_lowest = null;
_prevHighest = 0;
_prevLowest = 0;
_barsSinceSignal = 0;
}
protected override void OnStarted2(DateTime time)
{
base.OnStarted2(time);
_ema = new ExponentialMovingAverage { Length = EmaLength };
_atr = new AverageTrueRange { Length = AtrLength };
_highest = new Highest { Length = PivotLength };
_lowest = new Lowest { Length = PivotLength };
_prevHighest = 0;
_prevLowest = 0;
_barsSinceSignal = 0;
var subscription = SubscribeCandles(CandleType);
subscription
.Bind(_ema, _atr, _highest, _lowest, ProcessCandle)
.Start();
var area = CreateChartArea();
if (area != null)
{
DrawCandles(area, subscription);
DrawIndicator(area, _ema);
DrawOwnTrades(area);
}
}
private void ProcessCandle(ICandleMessage candle, decimal emaVal, decimal atrVal, decimal highVal, decimal lowVal)
{
if (candle.State != CandleStates.Finished)
return;
_barsSinceSignal++;
if (!_ema.IsFormed || !_atr.IsFormed || !_highest.IsFormed || !_lowest.IsFormed)
{
_prevHighest = highVal;
_prevLowest = lowVal;
return;
}
if (atrVal <= 0 || _barsSinceSignal < CooldownBars)
{
_prevHighest = highVal;
_prevLowest = lowVal;
return;
}
// Breakout above previous highest with EMA confirmation — go long
if (candle.ClosePrice > _prevHighest && candle.ClosePrice > emaVal && Position <= 0)
{
BuyMarket(Volume + Math.Abs(Position));
_barsSinceSignal = 0;
}
// Breakout below previous lowest with EMA confirmation — go short
else if (candle.ClosePrice < _prevLowest && candle.ClosePrice < emaVal && Position >= 0)
{
SellMarket(Volume + Math.Abs(Position));
_barsSinceSignal = 0;
}
_prevHighest = highVal;
_prevLowest = lowVal;
}
}
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, AverageTrueRange, Highest, Lowest
from StockSharp.Algo.Strategies import Strategy
class livermore_seykota_breakout_strategy(Strategy):
def __init__(self):
super(livermore_seykota_breakout_strategy, self).__init__()
self._ema_length = self.Param("EmaLength", 50) \
.SetDisplay("EMA Length", "EMA trend period", "Indicators")
self._pivot_length = self.Param("PivotLength", 30) \
.SetDisplay("Pivot Length", "Bars for pivot high/low", "General")
self._atr_length = self.Param("AtrLength", 14) \
.SetDisplay("ATR Length", "ATR period", "Indicators")
self._trail_atr_mult = self.Param("TrailAtrMultiplier", 10.0) \
.SetDisplay("Trail ATR Mult", "ATR trailing mult", "Risk")
self._candle_type = self.Param("CandleType", DataType.TimeFrame(TimeSpan.FromMinutes(15))) \
.SetDisplay("Candle Type", "Candles", "General")
self._cooldown_bars = self.Param("CooldownBars", 50) \
.SetDisplay("Cooldown Bars", "Min bars between signals", "General")
self._prev_highest = 0.0
self._prev_lowest = 0.0
self._bars_since_signal = 0
@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(livermore_seykota_breakout_strategy, self).OnReseted()
self._prev_highest = 0.0
self._prev_lowest = 0.0
self._bars_since_signal = 0
def OnStarted2(self, time):
super(livermore_seykota_breakout_strategy, self).OnStarted2(time)
self._prev_highest = 0.0
self._prev_lowest = 0.0
self._bars_since_signal = 0
self._ema = ExponentialMovingAverage()
self._ema.Length = self._ema_length.Value
self._atr = AverageTrueRange()
self._atr.Length = self._atr_length.Value
self._highest = Highest()
self._highest.Length = self._pivot_length.Value
self._lowest = Lowest()
self._lowest.Length = self._pivot_length.Value
subscription = self.SubscribeCandles(self.candle_type)
subscription.Bind(self._ema, self._atr, self._highest, self._lowest, self.OnProcess).Start()
area = self.CreateChartArea()
if area is not None:
self.DrawCandles(area, subscription)
self.DrawIndicator(area, self._ema)
self.DrawOwnTrades(area)
def OnProcess(self, candle, ema_val, atr_val, high_val, low_val):
if candle.State != CandleStates.Finished:
return
self._bars_since_signal += 1
ev = float(ema_val)
av = float(atr_val)
hv = float(high_val)
lv = float(low_val)
if not self._ema.IsFormed or not self._atr.IsFormed or not self._highest.IsFormed or not self._lowest.IsFormed:
self._prev_highest = hv
self._prev_lowest = lv
return
if av <= 0.0 or self._bars_since_signal < self._cooldown_bars.Value:
self._prev_highest = hv
self._prev_lowest = lv
return
close = float(candle.ClosePrice)
if close > self._prev_highest and close > ev and self.Position <= 0:
self.BuyMarket(self.Volume + abs(self.Position))
self._bars_since_signal = 0
elif close < self._prev_lowest and close < ev and self.Position >= 0:
self.SellMarket(self.Volume + abs(self.Position))
self._bars_since_signal = 0
self._prev_highest = hv
self._prev_lowest = lv
def CreateClone(self):
return livermore_seykota_breakout_strategy()