Ruptura del Kumo Ichimoku
Estrategia basada en la ruptura del Kumo (nube) de Ichimoku.
Las pruebas indican un retorno anual promedio de aproximadamente 70%. Funciona mejor en el mercado de acciones.
Este enfoque se basa en las señales de la nube Ichimoku. El precio rompiendo por encima de la nube con Tenkan-sen cruzando sobre Kijun-sen desencadena una compra, mientras que la ruptura opuesta por debajo de la nube inicia un corto. Las posiciones se mantienen hasta que el precio vuelve a través de la nube.
La nube delinea niveles clave de soporte y resistencia, por lo que el sistema espera cierres decisivos más allá de ella. Combinando múltiples componentes de Ichimoku, la estrategia evita operaciones de menor probabilidad durante mercados laterales.
Detalles
- Criterios de entrada: Señales basadas en Ichimoku.
- Largo/Corto: Ambos directions.
- Criterios de salida: Señal opuesta.
- Stops: No.
- Valores predeterminados:
TenkanPeriod= 9KijunPeriod= 26SenkouSpanPeriod= 52CandleType= TimeSpan.FromMinutes(15)
- Filtros:
- Categoría: Ruptura
- Dirección: Ambos
- Indicadores: Ichimoku
- Stops: No
- Complejidad: Básico
- Marco temporal: Intradía (15m)
- Estacionalidad: No
- Redes neuronales: No
- Divergencia: No
- Nivel de riesgo: Medio
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>
/// Strategy based on Ichimoku Kumo (cloud) breakout.
/// Buys when the close is above the cloud with Tenkan-sen above Kijun-sen, sells when it is below the cloud with Tenkan-sen
/// below Kijun-sen, acting when the last of the two conditions appears. A position is held until the close goes through the cloud.
/// </summary>
public class IchimokuKumoBreakoutStrategy : Strategy
{
private readonly StrategyParam<int> _tenkanPeriod;
private readonly StrategyParam<int> _kijunPeriod;
private readonly StrategyParam<int> _senkouSpanPeriod;
private readonly StrategyParam<DataType> _candleType;
private bool? _prevLongSetup;
private bool? _prevShortSetup;
/// <summary>
/// Period for Tenkan-sen line.
/// </summary>
public int TenkanPeriod
{
get => _tenkanPeriod.Value;
set => _tenkanPeriod.Value = value;
}
/// <summary>
/// Period for Kijun-sen line.
/// </summary>
public int KijunPeriod
{
get => _kijunPeriod.Value;
set => _kijunPeriod.Value = value;
}
/// <summary>
/// Period for Senkou Span B.
/// </summary>
public int SenkouSpanPeriod
{
get => _senkouSpanPeriod.Value;
set => _senkouSpanPeriod.Value = value;
}
/// <summary>
/// Candle type.
/// </summary>
public DataType CandleType
{
get => _candleType.Value;
set => _candleType.Value = value;
}
/// <summary>
/// Initialize the Ichimoku Kumo Breakout strategy.
/// </summary>
public IchimokuKumoBreakoutStrategy()
{
_tenkanPeriod = Param(nameof(TenkanPeriod), 9)
.SetGreaterThanZero()
.SetDisplay("Tenkan-sen Period", "Period for Tenkan-sen line", "Indicators")
.SetOptimize(7, 13, 2);
_kijunPeriod = Param(nameof(KijunPeriod), 26)
.SetGreaterThanZero()
.SetDisplay("Kijun-sen Period", "Period for Kijun-sen line", "Indicators")
.SetOptimize(20, 30, 2);
_senkouSpanPeriod = Param(nameof(SenkouSpanPeriod), 52)
.SetGreaterThanZero()
.SetDisplay("Senkou Span B Period", "Period for Senkou Span B", "Indicators")
.SetOptimize(40, 60, 4);
_candleType = Param(nameof(CandleType), TimeSpan.FromMinutes(15).TimeFrame())
.SetDisplay("Candle Type", "Type of candles to use", "General");
}
/// <inheritdoc />
public override IEnumerable<(Security sec, DataType dt)> GetWorkingSecurities()
{
return [(Security, CandleType)];
}
/// <inheritdoc />
protected override void OnReseted()
{
base.OnReseted();
_prevLongSetup = null;
_prevShortSetup = null;
}
/// <inheritdoc />
protected override void OnStarted2(DateTime time)
{
base.OnStarted2(time);
var ichimoku = new Ichimoku
{
Tenkan = { Length = TenkanPeriod },
Kijun = { Length = KijunPeriod },
SenkouB = { Length = SenkouSpanPeriod },
};
var subscription = SubscribeCandles(CandleType);
subscription
.BindEx(ichimoku, ProcessCandle)
.Start();
var area = CreateChartArea();
if (area != null)
{
DrawCandles(area, subscription);
DrawIndicator(area, ichimoku);
DrawOwnTrades(area);
}
}
private void ProcessCandle(ICandleMessage candle, IIndicatorValue value)
{
if (candle.State != CandleStates.Finished)
return;
// The cloud is plotted ahead, so the spans of this candle were set Kijun periods ago.
if (value is not IIchimokuValue { Tenkan: decimal tenkan, Kijun: decimal kijun, SenkouA: decimal spanA, SenkouB: decimal spanB })
return;
var close = candle.ClosePrice;
var cloudTop = Math.Max(spanA, spanB);
var cloudBottom = Math.Min(spanA, spanB);
var longSetup = close > cloudTop && tenkan > kijun;
var shortSetup = close < cloudBottom && tenkan < kijun;
var wasLongSetup = _prevLongSetup;
var wasShortSetup = _prevShortSetup;
_prevLongSetup = longSetup;
_prevShortSetup = shortSetup;
if (wasLongSetup is not bool wasLong || wasShortSetup is not bool wasShort)
return;
if (!IsFormedAndOnlineAndAllowTrading())
return;
if (longSetup && !wasLong && Position <= 0)
{
BuyMarket(Volume + Math.Abs(Position));
}
else if (shortSetup && !wasShort && Position >= 0)
{
SellMarket(Volume + Math.Abs(Position));
}
else if (Position > 0 && close < cloudBottom)
{
SellMarket(Position);
}
else if (Position < 0 && close > cloudTop)
{
BuyMarket(-Position);
}
}
}
import clr
clr.AddReference("StockSharp.Messages")
clr.AddReference("StockSharp.Algo")
clr.AddReference("StockSharp.Algo.Indicators")
clr.AddReference("StockSharp.Algo.Strategies")
from System import TimeSpan, Math
from StockSharp.Messages import DataType, CandleStates
from StockSharp.Algo.Indicators import Ichimoku
from StockSharp.Algo.Strategies import Strategy
class ichimoku_kumo_breakout_strategy(Strategy):
"""
Strategy based on Ichimoku Kumo (cloud) breakout.
Buys when the close is above the cloud with Tenkan-sen above Kijun-sen, sells when it is below the cloud with Tenkan-sen
below Kijun-sen, acting when the last of the two conditions appears. A position is held until the close goes through the cloud.
"""
def __init__(self):
super(ichimoku_kumo_breakout_strategy, self).__init__()
self._tenkan_period = self.Param("TenkanPeriod", 9).SetGreaterThanZero().SetDisplay("Tenkan Period", "Tenkan-sen period", "Indicators")
self._kijun_period = self.Param("KijunPeriod", 26).SetGreaterThanZero().SetDisplay("Kijun Period", "Kijun-sen period", "Indicators")
self._senkou_span_period = self.Param("SenkouSpanPeriod", 52).SetGreaterThanZero().SetDisplay("Senkou Span B Period", "Period for Senkou Span B", "Indicators")
self._candle_type = self.Param("CandleType", DataType.TimeFrame(TimeSpan.FromMinutes(15))).SetDisplay("Candle Type", "Timeframe", "General")
self._prev_long_setup = None
self._prev_short_setup = None
@property
def candle_type(self):
return self._candle_type.Value
def OnReseted(self):
super(ichimoku_kumo_breakout_strategy, self).OnReseted()
self._prev_long_setup = None
self._prev_short_setup = None
def OnStarted2(self, time):
super(ichimoku_kumo_breakout_strategy, self).OnStarted2(time)
ichimoku = Ichimoku()
ichimoku.Tenkan.Length = self._tenkan_period.Value
ichimoku.Kijun.Length = self._kijun_period.Value
ichimoku.SenkouB.Length = self._senkou_span_period.Value
subscription = self.SubscribeCandles(self.candle_type)
subscription.BindEx(ichimoku, self._process_candle).Start()
area = self.CreateChartArea()
if area is not None:
self.DrawCandles(area, subscription)
self.DrawIndicator(area, ichimoku)
self.DrawOwnTrades(area)
def _process_candle(self, candle, value):
if candle.State != CandleStates.Finished:
return
# The cloud is plotted ahead, so the spans of this candle were set Kijun periods ago.
tenkan = value.Tenkan
kijun = value.Kijun
span_a = value.SenkouA
span_b = value.SenkouB
if tenkan is None or kijun is None or span_a is None or span_b is None:
return
close = candle.ClosePrice
cloud_top = Math.Max(span_a, span_b)
cloud_bottom = Math.Min(span_a, span_b)
long_setup = close > cloud_top and tenkan > kijun
short_setup = close < cloud_bottom and tenkan < kijun
was_long = self._prev_long_setup
was_short = self._prev_short_setup
self._prev_long_setup = long_setup
self._prev_short_setup = short_setup
if was_long is None or was_short is None:
return
if not self.IsFormedAndOnlineAndAllowTrading():
return
position = self.Position
if long_setup and not was_long and position <= 0:
self.BuyMarket(self.Volume + Math.Abs(position))
elif short_setup and not was_short and position >= 0:
self.SellMarket(self.Volume + Math.Abs(position))
elif position > 0 and close < cloud_bottom:
self.SellMarket(position)
elif position < 0 and close > cloud_top:
self.BuyMarket(-position)
def CreateClone(self):
return ichimoku_kumo_breakout_strategy()