Эта стратегия пытается поймать краткосрочное ценовое движение, сравнивая цену закрытия текущей свечи с предыдущей.
Если текущая свеча закрывается выше предыдущей, открывается длинная позиция.
Если закрывается ниже предыдущей, открывается короткая позиция.
Стопы и трейлинг управляются через встроенную защиту. Стратегия работает в обе стороны рынка и опирается только на динамику цены.
Детали
Условия входа:
Лонг: Close(t) > Close(t-1).
Шорт: Close(t) < Close(t-1).
Лонг/Шорт: обе стороны.
Условия выхода: противоположный сигнал или защитные стопы.
Стопы: опциональные трейлинг-стоп, стоп-лосс и тейк-профит через StartProtection.
Значения по умолчанию:
CandleType = 1 минута.
StopLossPercent = 1.
TakeProfitPercent = 2.
IsTrailingStop = true.
Фильтры:
Категория: Скальпинг.
Направление: обе.
Индикаторы: нет.
Стопы: да.
Сложность: простая.
Таймфрейм: краткосрочный.
Сезонность: нет.
Нейросети: нет.
Дивергенция: нет.
Уровень риска: высокий.
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>
/// Renko scalper strategy.
/// Opens long when close moves significantly above previous close, short when below.
/// </summary>
public class RenkoScalperStrategy : Strategy
{
private readonly StrategyParam<DataType> _candleType;
private decimal _previousClose;
private bool _hasPrev;
public DataType CandleType { get => _candleType.Value; set => _candleType.Value = value; }
public RenkoScalperStrategy()
{
_candleType = Param(nameof(CandleType), TimeSpan.FromHours(4).TimeFrame())
.SetDisplay("Candle Type", "Type of candles", "General");
}
public override IEnumerable<(Security sec, DataType dt)> GetWorkingSecurities()
=> [(Security, CandleType)];
protected override void OnReseted()
{
base.OnReseted();
_previousClose = 0;
_hasPrev = false;
}
protected override void OnStarted2(DateTime time)
{
base.OnStarted2(time);
var stdev = new StandardDeviation { Length = 20 };
SubscribeCandles(CandleType).Bind(stdev, ProcessCandle).Start();
}
private void ProcessCandle(ICandleMessage candle, decimal stdevVal)
{
if (candle.State != CandleStates.Finished) return;
var close = candle.ClosePrice;
if (!_hasPrev)
{
_previousClose = close;
_hasPrev = true;
return;
}
if (stdevVal <= 0) { _previousClose = close; return; }
var diff = close - _previousClose;
if (diff > stdevVal && Position <= 0)
{
if (Position < 0) BuyMarket();
BuyMarket();
}
else if (diff < -stdevVal && Position >= 0)
{
if (Position > 0) SellMarket();
SellMarket();
}
_previousClose = close;
}
}
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 StandardDeviation
from StockSharp.Algo.Strategies import Strategy
class renko_scalper_strategy(Strategy):
def __init__(self):
super(renko_scalper_strategy, self).__init__()
self._candle_type = self.Param("CandleType", DataType.TimeFrame(TimeSpan.FromHours(4))) \
.SetDisplay("Candle Type", "Type of candles", "General")
self._previous_close = 0.0
self._has_prev = False
@property
def candle_type(self):
return self._candle_type.Value
def OnReseted(self):
super(renko_scalper_strategy, self).OnReseted()
self._previous_close = 0.0
self._has_prev = False
def OnStarted2(self, time):
super(renko_scalper_strategy, self).OnStarted2(time)
stdev = StandardDeviation()
stdev.Length = 20
subscription = self.SubscribeCandles(self.candle_type)
subscription.Bind(stdev, self.on_process).Start()
area = self.CreateChartArea()
if area is not None:
self.DrawCandles(area, subscription)
self.DrawOwnTrades(area)
def on_process(self, candle, stdev_val):
if candle.State != CandleStates.Finished:
return
close = candle.ClosePrice
if not self._has_prev:
self._previous_close = close
self._has_prev = True
return
if stdev_val <= 0:
self._previous_close = close
return
diff = close - self._previous_close
if diff > stdev_val and self.Position <= 0:
if self.Position < 0:
self.BuyMarket()
self.BuyMarket()
elif diff < -stdev_val and self.Position >= 0:
if self.Position > 0:
self.SellMarket()
self.SellMarket()
self._previous_close = close
def CreateClone(self):
return renko_scalper_strategy()