GitHub で見る
FullDump BB RSI戦略
MT5エキスパートアドバイザー「FullDump」から変換されたBollinger BandsとRSIの多段階システム。この戦略はモメンタムの枯渇を待ち、Bollinger Bandsで平均回帰バイアスを確認し、価格が中央バンドに再整合したときのみ取引します。トレード管理は元のEAを反映し、固定のストップロス/ターゲットオフセットと、価格が反対側のバンドに戻ったときのブレイクイーブン調整を持ちます。
概要
- 市場: Bollinger BandsとRSIをサポートする任意の流動性の高いインストゥルメント。
- 時間軸: 設定可能なキャンドルタイプ(デフォルト15分)。
- 方向: ロング/ショート。
- 注文タイプ: 事前定義された保護レベルを持つ成行注文。
- コンセプト: 価格が中央バンドに戻る間、Bollingerエンベロープ内の短期的な極値をフェード。
トレードロジック
- RSIスキャン(ステップ1)
- ロング条件:最近のウィンドウ内で少なくとも1つのRSI読み取り値が30未満。
- ショート条件:同じルックバック内で少なくとも1つのRSI読み取り値が70超。
- バンド違反(ステップ2)
- ロング:現在の終値が直近の下限バンド値のいずれか以下。
- ショート:現在の終値が直近の上限バンド値のいずれか以上。
- 中央バンドアライメント(ステップ3)
- ロントレードは価格がBollingerの中央ラインを上回って閉じてから初めて発動。
- ショートトレードは終値が中央ラインを下回ることが必要。
- エントリー実行
- すべての条件が一致し、その方向に開いているポジションがない場合、設定量で成行注文が送られます。
リスク管理
- ストップロス: ロングはルックバックウィンドウの極値安値の下(設定の凹みオフセット分を引く)、ショートは極値高値の上(オフセット分を加える)に配置。
- テイクプロフィット: 現在の反対側のBollingerバンドに同じ凹みオフセットを加えた位置に配置。
- ブレイクイーブンルール: 価格が反対側のバンドに触れると、ポジションを確保するためストップロスをエントリー価格に移動。
- ポジション決済: ストップロスまたはテイクプロフィットレベルを価格が超えると決済。反対シグナルは方向を切り替える前に現在のポジションをフラットにします。
パラメーター
| 名前 |
説明 |
デフォルト |
注記 |
BandsPeriod |
Bollinger Bands計算の長さ。 |
20 |
最適化可能(10 → 40ステップ1)。 |
RsiPeriod |
RSIの平均化の長さ。 |
14 |
最適化可能(7 → 21ステップ1)。 |
Depth |
条件のために検査される直近のキャンドル数。 |
6 |
最適化可能(3 → 12ステップ1)。 |
IndentInPoints |
ストップロスとテイクプロフィットに追加される価格ステップのオフセット。 |
10 |
最適化可能(5 → 30ステップ5)。 |
OrderVolume |
ロット単位の注文サイズ。 |
1 |
エントリーとエグジットの両方に使用。 |
CandleType |
入力キャンドルの時間軸。 |
15分足 |
戦略の時間軸を調整するために変更。 |
フィルターとタグ
- カテゴリ: 平均回帰、ボラティリティバンド。
- インジケーター: Bollinger Bands、Relative Strength Index。
- ストップ: ハードストップ、ハードターゲット、ブレイクイーブン調整。
- 複雑さ: 中級(状態を持つ管理によるマルチ条件ロジック)。
- 自動化レベル: 完全自動のエントリーとエグジット。
- 最適な使用: Bollinger極値がしばしば中央値に戻るレンジ相場。
注記
- 凹みオフセットはインストゥルメントの価格ステップでスケーリングされ、元のEAのpipベースのロジックに合わせます。
- アルゴリズムはMT5の深さチェックを正確に複製するために直近のインジケーター値のキューを保持します。
- ライブトレードの前にRSIとBollinger Bandsの両方を初期化するのに十分な履歴キャンドルをインストゥルメントが提供していることを確認してください。
using System;
using System.Collections.Generic;
using Ecng.Common;
using StockSharp.Algo.Indicators;
using StockSharp.Algo.Strategies;
using StockSharp.BusinessEntities;
using StockSharp.Messages;
namespace StockSharp.Samples.Strategies;
/// <summary>
/// FullDump BB RSI strategy (simplified). Uses RSI oversold/overbought
/// with EMA trend filter for mean reversion entries.
/// </summary>
public class FullDumpBbRsiStrategy : Strategy
{
private readonly StrategyParam<DataType> _candleType;
private readonly StrategyParam<int> _rsiPeriod;
private readonly StrategyParam<int> _emaPeriod;
public DataType CandleType
{
get => _candleType.Value;
set => _candleType.Value = value;
}
public int RsiPeriod
{
get => _rsiPeriod.Value;
set => _rsiPeriod.Value = value;
}
public int EmaPeriod
{
get => _emaPeriod.Value;
set => _emaPeriod.Value = value;
}
public FullDumpBbRsiStrategy()
{
_candleType = Param(nameof(CandleType), TimeSpan.FromHours(4).TimeFrame())
.SetDisplay("Candle Type", "Candles", "General");
_rsiPeriod = Param(nameof(RsiPeriod), 14)
.SetGreaterThanZero()
.SetDisplay("RSI Period", "RSI averaging period", "Indicators");
_emaPeriod = Param(nameof(EmaPeriod), 20)
.SetGreaterThanZero()
.SetDisplay("EMA Period", "Trend filter EMA", "Indicators");
}
protected override void OnStarted2(DateTime time)
{
base.OnStarted2(time);
var rsi = new RelativeStrengthIndex { Length = RsiPeriod };
var ema = new ExponentialMovingAverage { Length = EmaPeriod };
var subscription = SubscribeCandles(CandleType);
subscription
.Bind(rsi, ema, (ICandleMessage candle, decimal rsiValue, decimal emaValue) =>
{
if (candle.State != CandleStates.Finished)
return;
if (!IsFormedAndOnlineAndAllowTrading())
return;
var close = candle.ClosePrice;
// RSI oversold => buy
if (rsiValue < 25m && Position <= 0)
BuyMarket();
// RSI overbought => sell
else if (rsiValue > 75m && Position >= 0)
SellMarket();
// Trend following on EMA cross
else if (close > emaValue && rsiValue > 60m && rsiValue < 70m && Position <= 0)
BuyMarket();
else if (close < emaValue && rsiValue < 40m && rsiValue > 30m && Position >= 0)
SellMarket();
})
.Start();
var area = CreateChartArea();
if (area != null)
{
DrawCandles(area, subscription);
DrawIndicator(area, ema);
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, ExponentialMovingAverage
from StockSharp.Algo.Strategies import Strategy
class full_dump_bb_rsi_strategy(Strategy):
def __init__(self):
super(full_dump_bb_rsi_strategy, self).__init__()
self._candle_type = self.Param("CandleType", DataType.TimeFrame(TimeSpan.FromHours(4))) \
.SetDisplay("Candle Type", "Candles", "General")
self._rsi_period = self.Param("RsiPeriod", 14) \
.SetDisplay("RSI Period", "RSI averaging period", "Indicators")
self._ema_period = self.Param("EmaPeriod", 20) \
.SetDisplay("EMA Period", "Trend filter EMA", "Indicators")
@property
def CandleType(self):
return self._candle_type.Value
@property
def RsiPeriod(self):
return self._rsi_period.Value
@property
def EmaPeriod(self):
return self._ema_period.Value
def OnStarted2(self, time):
super(full_dump_bb_rsi_strategy, self).OnStarted2(time)
rsi = RelativeStrengthIndex()
rsi.Length = self.RsiPeriod
ema = ExponentialMovingAverage()
ema.Length = self.EmaPeriod
subscription = self.SubscribeCandles(self.CandleType)
subscription.Bind(rsi, ema, self._on_process).Start()
area = self.CreateChartArea()
if area is not None:
self.DrawCandles(area, subscription)
self.DrawIndicator(area, ema)
self.DrawOwnTrades(area)
def _on_process(self, candle, rsi_value, ema_value):
if candle.State != CandleStates.Finished:
return
close = float(candle.ClosePrice)
rv = float(rsi_value)
ev = float(ema_value)
if rv < 25 and self.Position <= 0:
self.BuyMarket()
elif rv > 75 and self.Position >= 0:
self.SellMarket()
elif close > ev and rv > 60 and rv < 70 and self.Position <= 0:
self.BuyMarket()
elif close < ev and rv < 40 and rv > 30 and self.Position >= 0:
self.SellMarket()
def CreateClone(self):
return full_dump_bb_rsi_strategy()