Lorenzo SuperScalp 策略
该剥头皮策略结合RSI、布林带和MACD。当RSI低于45、价格接近下轨且MACD向上穿越信号线时买入;当RSI高于55、价格接近上轨且MACD向下穿越信号线时卖出。设置最小K线间隔以避免过于频繁的交易。
细节
- 入场条件:
- 多头:
RSI < 45且Close < LowerBand * 1.02且MACD向上穿越信号线。 - 空头:
RSI > 55且Close > UpperBand * 0.98且MACD向下穿越信号线。
- 多头:
- 多/空:双向。
- 退出条件:相反信号。
- 止损:无。
- 默认值:
RSI Length= 14Bollinger Length= 20Bollinger Multiplier= 2MACD Fast= 12MACD Slow= 26MACD Signal= 9Min Bars= 15
- 筛选:
- 类型:趋势跟随
- 方向:双向
- 指标:多个
- 止损:无
- 复杂度:中等
- 周期:短期
- 季节性:无
- 神经网络:无
- 背离:无
- 风险等级:中等
using System;
using Ecng.Common;
using StockSharp.Algo.Indicators;
using StockSharp.Algo.Strategies;
using StockSharp.Messages;
namespace StockSharp.Samples.Strategies;
public class LorenzoSuperScalpStrategy : Strategy
{
private readonly StrategyParam<int> _rsiLength;
private readonly StrategyParam<int> _bbLength;
private readonly StrategyParam<DataType> _candleType;
public int RsiLength { get => _rsiLength.Value; set => _rsiLength.Value = value; }
public int BbLength { get => _bbLength.Value; set => _bbLength.Value = value; }
public DataType CandleType { get => _candleType.Value; set => _candleType.Value = value; }
public LorenzoSuperScalpStrategy()
{
_rsiLength = Param(nameof(RsiLength), 14).SetGreaterThanZero();
_bbLength = Param(nameof(BbLength), 20).SetGreaterThanZero();
_candleType = Param(nameof(CandleType), TimeSpan.FromMinutes(5).TimeFrame());
}
/// <inheritdoc />
protected override void OnStarted2(DateTime time)
{
base.OnStarted2(time);
var rsi = new RelativeStrengthIndex { Length = RsiLength };
var bb = new BollingerBands { Length = BbLength, Width = 2m };
var lastSignal = DateTimeOffset.MinValue;
var cooldown = TimeSpan.FromMinutes(360);
var subscription = SubscribeCandles(CandleType);
subscription
.BindEx(rsi, bb, (candle, rsiVal, bbVal) =>
{
if (candle.State != CandleStates.Finished)
return;
if (!rsiVal.IsFormed || !bbVal.IsFormed)
return;
var r = rsiVal.ToDecimal();
var bbTyped = (BollingerBandsValue)bbVal;
if (bbTyped.UpBand is not decimal upper || bbTyped.LowBand is not decimal lower)
return;
if (candle.OpenTime - lastSignal < cooldown)
return;
if (r < 45m && candle.ClosePrice <= lower && Position <= 0)
{
BuyMarket();
lastSignal = candle.OpenTime;
}
else if (r > 55m && candle.ClosePrice >= upper && Position >= 0)
{
SellMarket();
lastSignal = candle.OpenTime;
}
})
.Start();
var area = CreateChartArea();
if (area != null)
{
DrawCandles(area, subscription);
DrawIndicator(area, bb);
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 RelativeStrengthIndex, BollingerBands
from StockSharp.Algo.Strategies import Strategy
class lorenzo_super_scalp_strategy(Strategy):
def __init__(self):
super(lorenzo_super_scalp_strategy, self).__init__()
self._rsi_length = self.Param("RsiLength", 14) \
.SetGreaterThanZero()
self._bb_length = self.Param("BbLength", 20) \
.SetGreaterThanZero()
self._candle_type = self.Param("CandleType", DataType.TimeFrame(TimeSpan.FromMinutes(5)))
self._last_signal_ticks = 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(lorenzo_super_scalp_strategy, self).OnReseted()
self._last_signal_ticks = 0
def OnStarted2(self, time):
super(lorenzo_super_scalp_strategy, self).OnStarted2(time)
self._last_signal_ticks = 0
self._rsi = RelativeStrengthIndex()
self._rsi.Length = self._rsi_length.Value
self._bb = BollingerBands()
self._bb.Length = self._bb_length.Value
self._bb.Width = 2
subscription = self.SubscribeCandles(self.candle_type)
subscription.BindEx(self._rsi, self._bb, self.OnProcess).Start()
def OnProcess(self, candle, rsi_val, bb_val):
if candle.State != CandleStates.Finished:
return
if not rsi_val.IsFormed or not bb_val.IsFormed:
return
r = float(rsi_val)
bb_upper = bb_val.UpBand
bb_lower = bb_val.LowBand
if bb_upper is None or bb_lower is None:
return
upper = float(bb_upper)
lower = float(bb_lower)
close = float(candle.ClosePrice)
cooldown_ticks = TimeSpan.FromMinutes(360).Ticks
current_ticks = candle.OpenTime.Ticks
if current_ticks - self._last_signal_ticks < cooldown_ticks:
return
if r < 45.0 and close <= lower and self.Position <= 0:
self.BuyMarket()
self._last_signal_ticks = current_ticks
elif r > 55.0 and close >= upper and self.Position >= 0:
self.SellMarket()
self._last_signal_ticks = current_ticks
def CreateClone(self):
return lorenzo_super_scalp_strategy()