From 1c0ce5d38c636c3f599a886aee8052795a66cdc1 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 24 Sep 2023 14:35:48 +0100 Subject: [PATCH] Improves closing signal Adds support for level --- Stg_Meta_Trend.mqh | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Stg_Meta_Trend.mqh b/Stg_Meta_Trend.mqh index 9e4db3c..bdf36a1 100644 --- a/Stg_Meta_Trend.mqh +++ b/Stg_Meta_Trend.mqh @@ -301,10 +301,10 @@ class Stg_Meta_Trend : public Strategy { uint _ishift = _shift; switch (_cmd) { case ORDER_TYPE_BUY: - _result &= _indi[_shift][0] >= 50 && _indi[_shift + 1][0] >= 50; + _result &= _indi[_shift][0] >= 50 - _level && _indi[_shift + 1][0] >= 50 - _level; break; case ORDER_TYPE_SELL: - _result &= _indi[_shift][0] <= 50 && _indi[_shift + 1][0] <= 50; + _result &= _indi[_shift][0] <= 50 + _level && _indi[_shift + 1][0] <= 50 + _level; break; } _level = _level == 0.0f ? strat.Ptr().Get(STRAT_PARAM_SOL) : _level; @@ -318,15 +318,20 @@ class Stg_Meta_Trend : public Strategy { * Check strategy's closing signal. */ bool SignalClose(ENUM_ORDER_TYPE _cmd, int _method, float _level = 0.0f, int _shift = 0) { - bool _result = false; + bool _result = true; if (!strat.IsSet()) { // Returns false when strategy is not set. - return _result; + return false; + } + IndicatorBase *_indi = GetIndicator(); + switch (_cmd) { + case ORDER_TYPE_BUY: + _result &= _indi[_shift][0] <= 50 + _level && _indi[_shift + 1][0] <= 50 + _level; + break; + case ORDER_TYPE_SELL: + _result &= _indi[_shift][0] >= 50 - _level && _indi[_shift + 1][0] >= 50 - _level; + break; } - _level = _level == 0.0f ? strat.Ptr().Get(STRAT_PARAM_SCL) : _level; - _method = _method == 0 ? strat.Ptr().Get(STRAT_PARAM_SCM) : _method; - _shift = _shift == 0 ? strat.Ptr().Get(STRAT_PARAM_SHIFT) : _shift; - _result |= strat.Ptr().SignalClose(Order::NegateOrderType(_cmd), _method, _level, _shift); return _result; } };