using System;
using System.Linq;
using System.Collections.Generic;
using Ecng.Common;
using Ecng.Collections;
using Ecng.Serialization;
using StockSharp.Algo.Indicators;
using StockSharp.Algo.Strategies;
using StockSharp.BusinessEntities;
using StockSharp.Messages;
namespace StockSharp.Samples.Strategies;
/// <summary>
/// Awesome Oscillator + CCI strategy with pivot and jump filters.
/// </summary>
public class AocciStrategy : Strategy
{
private readonly StrategyParam<decimal> _tradeVolume;
private readonly StrategyParam<decimal> _stopLossPips;
private readonly StrategyParam<decimal> _takeProfitPips;
private readonly StrategyParam<decimal> _trailingStopPips;
private readonly StrategyParam<decimal> _trailingStepPips;
private readonly StrategyParam<int> _cciPeriod;
private readonly StrategyParam<int> _signalCandleShift;
private readonly StrategyParam<decimal> _bigJumpPips;
private readonly StrategyParam<decimal> _doubleJumpPips;
private readonly StrategyParam<DataType> _candleType;
private readonly StrategyParam<DataType> _higherCandleType;
private AwesomeOscillator _ao;
private CommodityChannelIndex _cci;
private decimal? _lastAoValue;
private readonly Queue<decimal> _cciValues = new();
private int _maxCciValues;
private readonly Queue<ICandleMessage> _recentCandles = new();
private int _maxRecentCandles;
private decimal? _longStop;
private decimal? _longTake;
private decimal? _shortStop;
private decimal? _shortTake;
private decimal? _longEntryPrice;
private decimal? _shortEntryPrice;
private decimal _pipSize;
private decimal? _lastHigherClose;
/// <summary>
/// Base order volume.
/// </summary>
public decimal TradeVolume
{
get => _tradeVolume.Value;
set => _tradeVolume.Value = value;
}
/// <summary>
/// Stop loss distance expressed in pips.
/// </summary>
public decimal StopLossPips
{
get => _stopLossPips.Value;
set => _stopLossPips.Value = value;
}
/// <summary>
/// Take profit distance expressed in pips.
/// </summary>
public decimal TakeProfitPips
{
get => _takeProfitPips.Value;
set => _takeProfitPips.Value = value;
}
/// <summary>
/// Trailing stop distance in pips.
/// </summary>
public decimal TrailingStopPips
{
get => _trailingStopPips.Value;
set => _trailingStopPips.Value = value;
}
/// <summary>
/// Trailing step in pips.
/// </summary>
public decimal TrailingStepPips
{
get => _trailingStepPips.Value;
set => _trailingStepPips.Value = value;
}
/// <summary>
/// CCI indicator length.
/// </summary>
public int CciPeriod
{
get => _cciPeriod.Value;
set => _cciPeriod.Value = value;
}
/// <summary>
/// Offset applied when reading the CCI values.
/// </summary>
public int SignalCandleShift
{
get => _signalCandleShift.Value;
set => _signalCandleShift.Value = value;
}
/// <summary>
/// Maximum allowed jump between consecutive opens in pips.
/// </summary>
public decimal BigJumpPips
{
get => _bigJumpPips.Value;
set => _bigJumpPips.Value = value;
}
/// <summary>
/// Maximum allowed jump between every second open in pips.
/// </summary>
public decimal DoubleJumpPips
{
get => _doubleJumpPips.Value;
set => _doubleJumpPips.Value = value;
}
/// <summary>
/// Working candle type.
/// </summary>
public DataType CandleType
{
get => _candleType.Value;
set => _candleType.Value = value;
}
/// <summary>
/// Higher timeframe used for confirmation.
/// </summary>
public DataType HigherCandleType
{
get => _higherCandleType.Value;
set => _higherCandleType.Value = value;
}
/// <summary>
/// Initializes a new instance of <see cref="AocciStrategy"/>.
/// </summary>
public AocciStrategy()
{
_tradeVolume = Param(nameof(TradeVolume), 1m)
.SetGreaterThanZero()
.SetDisplay("Trade Volume", "Base order volume", "Risk");
_stopLossPips = Param(nameof(StopLossPips), 50m)
.SetNotNegative()
.SetDisplay("Stop Loss (pips)", "Stop loss distance in pips", "Risk");
_takeProfitPips = Param(nameof(TakeProfitPips), 50m)
.SetNotNegative()
.SetDisplay("Take Profit (pips)", "Take profit distance in pips", "Risk");
_trailingStopPips = Param(nameof(TrailingStopPips), 5m)
.SetNotNegative()
.SetDisplay("Trailing Stop (pips)", "Trailing stop distance", "Risk");
_trailingStepPips = Param(nameof(TrailingStepPips), 5m)
.SetNotNegative()
.SetDisplay("Trailing Step (pips)", "Trailing step distance", "Risk");
_cciPeriod = Param(nameof(CciPeriod), 55)
.SetGreaterThanZero()
.SetDisplay("CCI Period", "Commodity Channel Index period", "Indicators");
_signalCandleShift = Param(nameof(SignalCandleShift), 0)
.SetDisplay("Signal Candle Shift", "Offset for reading indicator values", "Logic");
_bigJumpPips = Param(nameof(BigJumpPips), 100m)
.SetNotNegative()
.SetDisplay("Big Jump (pips)", "Maximum allowed consecutive open gap", "Filters");
_doubleJumpPips = Param(nameof(DoubleJumpPips), 100m)
.SetNotNegative()
.SetDisplay("Double Jump (pips)", "Maximum allowed two-bar open gap", "Filters");
_candleType = Param(nameof(CandleType), TimeSpan.FromMinutes(15).TimeFrame())
.SetDisplay("Candle Type", "Primary timeframe", "General");
_higherCandleType = Param(nameof(HigherCandleType), TimeSpan.FromHours(1).TimeFrame())
.SetDisplay("Higher Candle", "Higher timeframe for confirmation", "General");
}
/// <inheritdoc />
public override IEnumerable<(Security sec, DataType dt)> GetWorkingSecurities()
=> new[] { (Security, CandleType), (Security, HigherCandleType) };
/// <inheritdoc />
protected override void OnReseted()
{
base.OnReseted();
_ao = null;
_cci = null;
_lastAoValue = null;
_cciValues.Clear();
_maxCciValues = 0;
_recentCandles.Clear();
_maxRecentCandles = 0;
ResetLongState();
ResetShortState();
_pipSize = 0m;
_lastHigherClose = null;
}
/// <inheritdoc />
protected override void OnStarted2(DateTime time)
{
base.OnStarted2(time);
Volume = TradeVolume;
_pipSize = CalculatePipSize();
_ao = new AwesomeOscillator();
_cci = new CommodityChannelIndex { Length = CciPeriod };
_maxCciValues = Math.Max(SignalCandleShift + 2, 2);
_maxRecentCandles = Math.Max(SignalCandleShift + 2, 6);
var subscription = SubscribeCandles(CandleType);
subscription
.Bind(_ao, _cci, ProcessCandle)
.Start();
var higherSubscription = SubscribeCandles(HigherCandleType);
higherSubscription
.Bind(ProcessHigherCandle)
.Start();
var area = CreateChartArea();
if (area != null)
{
DrawCandles(area, subscription);
DrawIndicator(area, _ao);
DrawIndicator(area, _cci);
DrawOwnTrades(area);
}
}
private void ProcessHigherCandle(ICandleMessage candle)
{
if (candle.State != CandleStates.Finished)
return;
// Store the last closed higher timeframe candle for pivot confirmation.
_lastHigherClose = candle.ClosePrice;
}
private void ProcessCandle(ICandleMessage candle, decimal aoValue, decimal cciValue)
{
if (candle.State != CandleStates.Finished)
return;
// Maintain sliding windows for candles and indicator values.
UpdateRecentCandles(candle);
UpdateCciQueue(cciValue);
var closedPosition = HandleActivePositions(candle);
if (_ao == null || _cci == null)
{
_lastAoValue = aoValue;
return;
}
if (!_ao.IsFormed || !_cci.IsFormed)
{
_lastAoValue = aoValue;
return;
}
if (_lastAoValue is null)
{
_lastAoValue = aoValue;
return;
}
if (!IsFormedAndOnlineAndAllowTrading())
{
_lastAoValue = aoValue;
return;
}
if (_cciValues.Count <= SignalCandleShift + 1)
{
_lastAoValue = aoValue;
return;
}
if (_recentCandles.Count < 6)
{
_lastAoValue = aoValue;
return;
}
if (!TryGetCciValue(SignalCandleShift, out var cciShift0) ||
!TryGetCciValue(SignalCandleShift + 1, out var cciShift1))
{
_lastAoValue = aoValue;
return;
}
if (!TryGetRecentCandle(SignalCandleShift + 1, out var pivotSource))
{
_lastAoValue = aoValue;
return;
}
if (_lastHigherClose is null)
{
_lastAoValue = aoValue;
return;
}
if (ShouldSkipDueToJumps())
{
_lastAoValue = aoValue;
return;
}
if (closedPosition || Position != 0)
{
_lastAoValue = aoValue;
return;
}
var pivot = (pivotSource.HighPrice + pivotSource.LowPrice + pivotSource.ClosePrice) / 3m;
var aoPrev = _lastAoValue.Value;
var higherClose = _lastHigherClose.Value;
var price = candle.ClosePrice;
// Long condition from original MQL logic.
var openLong = aoValue > 0m && cciShift0 >= 0m && price > pivot &&
(aoPrev < 0m || cciShift1 <= 0m || higherClose < pivot);
// Short condition mirrors the original code (identical filters).
var openShort = aoValue > 0m && cciShift0 >= 0m && price > pivot &&
(aoPrev < 0m || cciShift1 <= 0m || higherClose < pivot);
if (openLong)
{
var volume = Volume + Math.Abs(Position);
if (volume > 0m)
{
BuyMarket(volume);
_longEntryPrice = price;
_longStop = StopLossPips > 0m ? price - StopLossPips * _pipSize : null;
_longTake = TakeProfitPips > 0m ? price + TakeProfitPips * _pipSize : null;
ResetShortState();
}
}
else if (openShort)
{
var volume = Volume + Math.Abs(Position);
if (volume > 0m)
{
SellMarket(volume);
_shortEntryPrice = price;
_shortStop = StopLossPips > 0m ? price + StopLossPips * _pipSize : null;
_shortTake = TakeProfitPips > 0m ? price - TakeProfitPips * _pipSize : null;
ResetLongState();
}
}
_lastAoValue = aoValue;
}
private bool HandleActivePositions(ICandleMessage candle)
{
var closed = false;
if (Position > 0)
{
_longEntryPrice ??= candle.ClosePrice;
UpdateTrailingForLong(candle);
if (_longTake.HasValue && candle.HighPrice >= _longTake.Value)
{
SellMarket(Math.Abs(Position));
ResetLongState();
closed = true;
}
else if (_longStop.HasValue && candle.LowPrice <= _longStop.Value)
{
SellMarket(Math.Abs(Position));
ResetLongState();
closed = true;
}
}
else if (Position < 0)
{
_shortEntryPrice ??= candle.ClosePrice;
UpdateTrailingForShort(candle);
if (_shortTake.HasValue && candle.LowPrice <= _shortTake.Value)
{
BuyMarket(Math.Abs(Position));
ResetShortState();
closed = true;
}
else if (_shortStop.HasValue && candle.HighPrice >= _shortStop.Value)
{
BuyMarket(Math.Abs(Position));
ResetShortState();
closed = true;
}
}
else
{
ResetLongState();
ResetShortState();
}
return closed;
}
private void UpdateTrailingForLong(ICandleMessage candle)
{
if (TrailingStopPips <= 0m || TrailingStepPips <= 0m || !_longEntryPrice.HasValue)
return;
var trailingStop = TrailingStopPips * _pipSize;
var trailingStep = TrailingStepPips * _pipSize;
var price = candle.ClosePrice;
var entry = _longEntryPrice.Value;
if (price - entry > trailingStop + trailingStep)
{
var minimal = price - (trailingStop + trailingStep);
if (!_longStop.HasValue || _longStop.Value < minimal)
_longStop = price - trailingStop;
}
}
private void UpdateTrailingForShort(ICandleMessage candle)
{
if (TrailingStopPips <= 0m || TrailingStepPips <= 0m || !_shortEntryPrice.HasValue)
return;
var trailingStop = TrailingStopPips * _pipSize;
var trailingStep = TrailingStepPips * _pipSize;
var price = candle.ClosePrice;
var entry = _shortEntryPrice.Value;
if (entry - price > trailingStop + trailingStep)
{
var maximal = price + (trailingStop + trailingStep);
if (!_shortStop.HasValue || _shortStop.Value > maximal)
_shortStop = price + trailingStop;
}
}
private void UpdateCciQueue(decimal value)
{
var required = Math.Max(SignalCandleShift + 2, 2);
if (_maxCciValues != required)
{
_maxCciValues = required;
while (_cciValues.Count > _maxCciValues)
_cciValues.Dequeue();
}
_cciValues.Enqueue(value);
while (_cciValues.Count > _maxCciValues)
_cciValues.Dequeue();
}
private void UpdateRecentCandles(ICandleMessage candle)
{
var required = Math.Max(SignalCandleShift + 2, 6);
if (_maxRecentCandles != required)
{
_maxRecentCandles = required;
while (_recentCandles.Count > _maxRecentCandles)
_recentCandles.Dequeue();
}
_recentCandles.Enqueue(candle);
while (_recentCandles.Count > _maxRecentCandles)
_recentCandles.Dequeue();
}
private bool TryGetCciValue(int shift, out decimal value)
{
value = 0m;
if (shift < 0 || shift >= _cciValues.Count)
return false;
var targetIndex = _cciValues.Count - 1 - shift;
var index = 0;
foreach (var item in _cciValues)
{
if (index == targetIndex)
{
value = item;
return true;
}
index++;
}
return false;
}
private bool TryGetRecentCandle(int shift, out ICandleMessage candle)
{
candle = null;
if (shift < 0 || shift >= _recentCandles.Count)
return false;
var targetIndex = _recentCandles.Count - 1 - shift;
var index = 0;
foreach (var item in _recentCandles)
{
if (index == targetIndex)
{
candle = item;
return candle != null;
}
index++;
}
return false;
}
private bool ShouldSkipDueToJumps()
{
if (_pipSize <= 0m)
return false;
var bigJump = BigJumpPips * _pipSize;
var doubleJump = DoubleJumpPips * _pipSize;
if (BigJumpPips > 0m)
{
if (Math.Abs(GetOpenDifference(0, 1)) >= bigJump ||
Math.Abs(GetOpenDifference(1, 2)) >= bigJump ||
Math.Abs(GetOpenDifference(2, 3)) >= bigJump ||
Math.Abs(GetOpenDifference(3, 4)) >= bigJump ||
Math.Abs(GetOpenDifference(4, 5)) >= bigJump)
return true;
}
if (DoubleJumpPips > 0m)
{
if (Math.Abs(GetOpenDifference(0, 2)) >= doubleJump ||
Math.Abs(GetOpenDifference(1, 3)) >= doubleJump ||
Math.Abs(GetOpenDifference(2, 4)) >= doubleJump ||
Math.Abs(GetOpenDifference(3, 5)) >= doubleJump)
return true;
}
return false;
}
private decimal GetOpenDifference(int firstShift, int secondShift)
{
if (!TryGetRecentCandle(firstShift, out var first) ||
!TryGetRecentCandle(secondShift, out var second))
return 0m;
return second.OpenPrice - first.OpenPrice;
}
private decimal CalculatePipSize()
{
var priceStep = Security?.PriceStep ?? 1m;
if (priceStep <= 0m)
priceStep = 1m;
var decimals = GetDecimalPlaces(priceStep);
var factor = decimals == 3 || decimals == 5 ? 10m : 1m;
return priceStep * factor;
}
private static int GetDecimalPlaces(decimal value)
{
value = Math.Abs(value);
if (value == 0m)
return 0;
var bits = decimal.GetBits(value);
return (bits[3] >> 16) & 0xFF;
}
private void ResetLongState()
{
_longStop = null;
_longTake = null;
_longEntryPrice = null;
}
private void ResetShortState()
{
_shortStop = null;
_shortTake = null;
_shortEntryPrice = null;
}
}
import clr
clr.AddReference("StockSharp.Messages")
clr.AddReference("StockSharp.Algo")
clr.AddReference("StockSharp.Algo.Indicators")
clr.AddReference("StockSharp.Algo.Strategies")
from StockSharp.Algo.Indicators import AwesomeOscillator, CommodityChannelIndex
from StockSharp.Algo.Strategies import Strategy
from StockSharp.Messages import DataType, CandleStates
from System import TimeSpan, Math
class aocci_strategy(Strategy):
def __init__(self):
super(aocci_strategy, self).__init__()
self._trade_volume = self.Param("TradeVolume", 1.0)
self._stop_loss_pips = self.Param("StopLossPips", 50.0)
self._take_profit_pips = self.Param("TakeProfitPips", 50.0)
self._trailing_stop_pips = self.Param("TrailingStopPips", 5.0)
self._trailing_step_pips = self.Param("TrailingStepPips", 5.0)
self._cci_period = self.Param("CciPeriod", 55)
self._signal_candle_shift = self.Param("SignalCandleShift", 0)
self._big_jump_pips = self.Param("BigJumpPips", 100.0)
self._double_jump_pips = self.Param("DoubleJumpPips", 100.0)
self._candle_type = self.Param("CandleType", DataType.TimeFrame(TimeSpan.FromMinutes(15)))
self._ao = None
self._cci = None
self._last_ao_value = None
self._cci_values = []
self._max_cci_values = 0
self._recent_candles = []
self._max_recent_candles = 0
self._long_stop = None
self._long_take = None
self._short_stop = None
self._short_take = None
self._long_entry_price = None
self._short_entry_price = None
self._pip_size = 0.0
@property
def CandleType(self):
return self._candle_type.Value
def OnStarted2(self, time):
super(aocci_strategy, self).OnStarted2(time)
self._pip_size = self._calculate_pip_size()
self._ao = AwesomeOscillator()
self._cci = CommodityChannelIndex()
self._cci.Length = self._cci_period.Value
self._max_cci_values = max(self._signal_candle_shift.Value + 2, 2)
self._max_recent_candles = max(self._signal_candle_shift.Value + 2, 6)
sub = self.SubscribeCandles(self.CandleType)
sub.Bind(self._ao, self._cci, self._process_candle).Start()
def _process_candle(self, candle, ao_value, cci_value):
if candle.State != CandleStates.Finished:
return
ao_val = float(ao_value)
cci_val = float(cci_value)
self._update_recent_candles(candle)
self._update_cci_queue(cci_val)
closed_position = self._handle_active_positions(candle)
if self._ao is None or self._cci is None:
self._last_ao_value = ao_val
return
if not self._ao.IsFormed or not self._cci.IsFormed:
self._last_ao_value = ao_val
return
if self._last_ao_value is None:
self._last_ao_value = ao_val
return
if len(self._cci_values) <= self._signal_candle_shift.Value + 1:
self._last_ao_value = ao_val
return
if len(self._recent_candles) < 6:
self._last_ao_value = ao_val
return
cci_shift0 = self._try_get_cci_value(self._signal_candle_shift.Value)
cci_shift1 = self._try_get_cci_value(self._signal_candle_shift.Value + 1)
if cci_shift0 is None or cci_shift1 is None:
self._last_ao_value = ao_val
return
pivot_source = self._try_get_recent_candle(self._signal_candle_shift.Value + 1)
if pivot_source is None:
self._last_ao_value = ao_val
return
if self._should_skip_due_to_jumps():
self._last_ao_value = ao_val
return
if closed_position or self.Position != 0:
self._last_ao_value = ao_val
return
pivot = (float(pivot_source.HighPrice) + float(pivot_source.LowPrice) + float(pivot_source.ClosePrice)) / 3.0
ao_prev = self._last_ao_value
price = float(candle.ClosePrice)
# Long condition from original MQL logic
open_long = ao_val > 0 and cci_shift0 >= 0 and price > pivot and (ao_prev < 0 or cci_shift1 <= 0)
# Short condition mirrors the original code
open_short = ao_val > 0 and cci_shift0 >= 0 and price > pivot and (ao_prev < 0 or cci_shift1 <= 0)
if open_long:
volume = float(self.Volume) + abs(self.Position)
if volume > 0:
self.BuyMarket(volume)
self._long_entry_price = price
self._long_stop = price - self._stop_loss_pips.Value * self._pip_size if self._stop_loss_pips.Value > 0 else None
self._long_take = price + self._take_profit_pips.Value * self._pip_size if self._take_profit_pips.Value > 0 else None
self._reset_short_state()
elif open_short:
volume = float(self.Volume) + abs(self.Position)
if volume > 0:
self.SellMarket(volume)
self._short_entry_price = price
self._short_stop = price + self._stop_loss_pips.Value * self._pip_size if self._stop_loss_pips.Value > 0 else None
self._short_take = price - self._take_profit_pips.Value * self._pip_size if self._take_profit_pips.Value > 0 else None
self._reset_long_state()
self._last_ao_value = ao_val
def _handle_active_positions(self, candle):
closed = False
if self.Position > 0:
if self._long_entry_price is None:
self._long_entry_price = float(candle.ClosePrice)
self._update_trailing_for_long(candle)
if self._long_take is not None and float(candle.HighPrice) >= self._long_take:
self.SellMarket(abs(self.Position))
self._reset_long_state()
closed = True
elif self._long_stop is not None and float(candle.LowPrice) <= self._long_stop:
self.SellMarket(abs(self.Position))
self._reset_long_state()
closed = True
elif self.Position < 0:
if self._short_entry_price is None:
self._short_entry_price = float(candle.ClosePrice)
self._update_trailing_for_short(candle)
if self._short_take is not None and float(candle.LowPrice) <= self._short_take:
self.BuyMarket(abs(self.Position))
self._reset_short_state()
closed = True
elif self._short_stop is not None and float(candle.HighPrice) >= self._short_stop:
self.BuyMarket(abs(self.Position))
self._reset_short_state()
closed = True
else:
self._reset_long_state()
self._reset_short_state()
return closed
def _update_trailing_for_long(self, candle):
if self._trailing_stop_pips.Value <= 0 or self._trailing_step_pips.Value <= 0 or self._long_entry_price is None:
return
trailing_stop = self._trailing_stop_pips.Value * self._pip_size
trailing_step = self._trailing_step_pips.Value * self._pip_size
price = float(candle.ClosePrice)
entry = self._long_entry_price
if price - entry > trailing_stop + trailing_step:
minimal = price - (trailing_stop + trailing_step)
if self._long_stop is None or self._long_stop < minimal:
self._long_stop = price - trailing_stop
def _update_trailing_for_short(self, candle):
if self._trailing_stop_pips.Value <= 0 or self._trailing_step_pips.Value <= 0 or self._short_entry_price is None:
return
trailing_stop = self._trailing_stop_pips.Value * self._pip_size
trailing_step = self._trailing_step_pips.Value * self._pip_size
price = float(candle.ClosePrice)
entry = self._short_entry_price
if entry - price > trailing_stop + trailing_step:
maximal = price + (trailing_stop + trailing_step)
if self._short_stop is None or self._short_stop > maximal:
self._short_stop = price + trailing_stop
def _update_cci_queue(self, value):
self._cci_values.append(value)
while len(self._cci_values) > self._max_cci_values:
self._cci_values.pop(0)
def _update_recent_candles(self, candle):
self._recent_candles.append(candle)
while len(self._recent_candles) > self._max_recent_candles:
self._recent_candles.pop(0)
def _try_get_cci_value(self, shift):
if shift < 0 or shift >= len(self._cci_values):
return None
target_index = len(self._cci_values) - 1 - shift
if target_index < 0 or target_index >= len(self._cci_values):
return None
return self._cci_values[target_index]
def _try_get_recent_candle(self, shift):
if shift < 0 or shift >= len(self._recent_candles):
return None
target_index = len(self._recent_candles) - 1 - shift
if target_index < 0 or target_index >= len(self._recent_candles):
return None
return self._recent_candles[target_index]
def _should_skip_due_to_jumps(self):
if self._pip_size <= 0:
return False
big_jump = self._big_jump_pips.Value * self._pip_size
double_jump = self._double_jump_pips.Value * self._pip_size
if self._big_jump_pips.Value > 0:
for i in range(5):
if abs(self._get_open_difference(i, i + 1)) >= big_jump:
return True
if self._double_jump_pips.Value > 0:
for i in range(4):
if abs(self._get_open_difference(i, i + 2)) >= double_jump:
return True
return False
def _get_open_difference(self, first_shift, second_shift):
first = self._try_get_recent_candle(first_shift)
second = self._try_get_recent_candle(second_shift)
if first is None or second is None:
return 0.0
return float(second.OpenPrice) - float(first.OpenPrice)
def _calculate_pip_size(self):
price_step = float(self.Security.PriceStep) if self.Security is not None and self.Security.PriceStep is not None else 1.0
if price_step <= 0:
price_step = 1.0
decimals = self._get_decimal_places(price_step)
factor = 10.0 if decimals == 3 or decimals == 5 else 1.0
return price_step * factor
def _get_decimal_places(self, value):
value = abs(value)
decimals = 0
while value != int(value) and decimals < 10:
value *= 10.0
decimals += 1
return decimals
def _reset_long_state(self):
self._long_stop = None
self._long_take = None
self._long_entry_price = None
def _reset_short_state(self):
self._short_stop = None
self._short_take = None
self._short_entry_price = None
def OnReseted(self):
super(aocci_strategy, self).OnReseted()
self._ao = None
self._cci = None
self._last_ao_value = None
self._cci_values = []
self._max_cci_values = 0
self._recent_candles = []
self._max_recent_candles = 0
self._reset_long_state()
self._reset_short_state()
self._pip_size = 0.0
def CreateClone(self):
return aocci_strategy()