diff --git a/Indicator/IndicatorTf.h b/Indicator/IndicatorTf.h index c4195c68b..00f2ec094 100644 --- a/Indicator/IndicatorTf.h +++ b/Indicator/IndicatorTf.h @@ -39,9 +39,6 @@ template class IndicatorTf : public IndicatorCandle> { protected: - // Time-frame used to create candles. - ENUM_TIMEFRAMES tf; - /* Protected methods */ /** @@ -80,7 +77,7 @@ class IndicatorTf : public IndicatorCandle _ref = _indi; + + DictStructIterator> _iter; + for (_iter = indis_dflt.Begin(); _iter.IsValid(); ++_iter) { + if (_iter.Value() == _ref) { + Alert("Warning: ", _indi PTR_DEREF GetFullName(), + " was already added as default candle/tick indicator and shouldn't be added by Platform:Add() as default " + "indicators are also ticked when calling Platform::Tick()."); + DebugBreak(); + } + } + indis.Set(_indi PTR_DEREF GetId(), _ref); } @@ -333,11 +344,15 @@ class Platform { // Adding indicator to list of default indicators in order to tick it on every Tick() call. Ref _ref = _indi_candle; indis_dflt.Set(_indi_candle PTR_DEREF GetId(), _ref); - } - if (!_indi_candle PTR_DEREF HasDataSource()) { - // Missing tick indicator. - _indi_candle PTR_DEREF InjectDataSource(FetchDefaultTickIndicator(_symbol)); + if (!_indi_candle PTR_DEREF HasDataSource()) { + // Missing tick indicator. + _indi_candle PTR_DEREF InjectDataSource(FetchDefaultTickIndicator(_symbol)); + } +#ifdef __debug__ + Print("Added default candle indicator for symbol ", _symbol, " and time-frame ", _tf, ". Now it has symbol ", + _indi_candle PTR_DEREF GetSymbol(), " and time-frame ", EnumToString(_indi_candle PTR_DEREF GetTf())); +#endif } return _indi_candle; diff --git a/tests/TradeTest.mq5 b/tests/TradeTest.mq5 index 55ff0c3a4..cc828bdd7 100644 --- a/tests/TradeTest.mq5 +++ b/tests/TradeTest.mq5 @@ -46,10 +46,9 @@ bool _finish_test = false; */ int OnInit() { Platform::Init(); - _chart_m1 = Platform::FetchDefaultCandleIndicator(_Symbol, PERIOD_M1); - _chart_m5 = Platform::FetchDefaultCandleIndicator(_Symbol, PERIOD_M5); - Platform::Add(_chart_m1.Ptr()); - Platform::Add(_chart_m5.Ptr()); + _chart_m1 = Platform::FetchDefaultCandleIndicator("EURUSD", PERIOD_M1); + _chart_m5 = Platform::FetchDefaultCandleIndicator("EURUSD", PERIOD_M5); + return INIT_SUCCEEDED; } @@ -83,7 +82,7 @@ int Test() { // Test market. assertTrueOrFail(trade1 PTR_DEREF IsTradeAllowed(), "Trade not allowed!"); assertTrueOrFail(trade1 PTR_DEREF GetSource() PTR_DEREF GetTf() == PERIOD_M1, - StringFormat("Fail on GetTf() => [%s]!", trade1 PTR_DEREF GetSource() PTR_DEREF GetTf())); + StringFormat("Fail on GetTf() => [%d]!", trade1 PTR_DEREF GetSource() PTR_DEREF GetTf())); assertTrueOrFail(trade1 PTR_DEREF GetSource() PTR_DEREF GetOpen() > 0, "Fail on GetOpen()!"); assertTrueOrFail(trade1 PTR_DEREF GetSource() PTR_DEREF GetSymbol() == _Symbol, "Fail on GetSymbol()!"); // assertTrueOrFail(trade1.IsTradeAllowed(), "Fail on IsTradeAllowed()!"); // @fixme