diff --git a/.github/workflows/backtest.yml b/.github/workflows/backtest.yml index aa22124..273f2d9 100644 --- a/.github/workflows/backtest.yml +++ b/.github/workflows/backtest.yml @@ -41,14 +41,14 @@ jobs: include: . init-platform: true mt-version: 5.0.0.2361 - path: Stg_Meta_Reversal.mq4 + path: Stg_Meta_Trend.mq4 verbose: true - name: Compile for MQL5 uses: fx31337/mql-compile-action@master with: include: . mt-version: 5.0.0.2515 - path: Stg_Meta_Reversal.mq5 + path: Stg_Meta_Trend.mq5 verbose: true - name: List compiled files run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname' @@ -79,7 +79,7 @@ jobs: OptFormatBrief: true OptFormatJson: true OptVerbose: true - TestExpert: "Stg_Meta_Reversal" + TestExpert: "Stg_Meta_Trend" TestPeriod: M1 TestReportName: Report-${{ matrix.year }}-${{ matrix.month }} - name: Upload results diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index b847826..ae0bd66 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -43,14 +43,14 @@ jobs: include: . init-platform: true mt-version: 5.0.0.2361 - path: Stg_Meta_Reversal.mq4 + path: Stg_Meta_Trend.mq4 verbose: true - name: Compile for MQL5 uses: fx31337/mql-compile-action@master with: include: . mt-version: 5.0.0.2515 - path: Stg_Meta_Reversal.mq5 + path: Stg_Meta_Trend.mq5 verbose: true - name: List compiled files run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname' diff --git a/README.md b/README.md index d41f15a..b44d9c0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Strategy Meta Reversal +# Strategy Meta Trend [![Status][gha-image-check-master]][gha-link-check-master] [![Status][gha-image-compile-master]][gha-link-compile-master] @@ -7,7 +7,8 @@ [![License][license-image]][license-link] [![Edit][gh-edit-badge]][gh-edit-link] -Reversal meta strategy reverses signals of another strategy. +Trend meta strategy to filter out +signals of other strategies based on the current trend. ## Dependencies @@ -21,12 +22,12 @@ Reversal meta strategy reverses signals of another strategy. [gh-discuss-link]: https://github.com/EA31337/EA31337-Strategies/discussions [gh-edit-badge]: https://img.shields.io/badge/GitHub-edit-purple.svg?logo=github -[gh-edit-link]: https://github.dev/EA31337/Strategy-Meta_Reversal +[gh-edit-link]: https://github.dev/EA31337/Strategy-Meta_Trend -[gha-link-check-master]: https://github.com/EA31337/Strategy-Meta_Reversal/actions?query=workflow:Check+branch%3Amaster -[gha-image-check-master]: https://github.com/EA31337/Strategy-Meta_Reversal/workflows/Check/badge.svg?branch=master -[gha-link-compile-master]: https://github.com/EA31337/Strategy-Meta_Reversal/actions?query=workflow:Compile+branch%3Amaster -[gha-image-compile-master]: https://github.com/EA31337/Strategy-Meta_Reversal/workflows/Compile/badge.svg?branch=master +[gha-link-check-master]: https://github.com/EA31337/Strategy-Meta_Trend/actions?query=workflow:Check+branch%3Amaster +[gha-image-check-master]: https://github.com/EA31337/Strategy-Meta_Trend/workflows/Check/badge.svg?branch=master +[gha-link-compile-master]: https://github.com/EA31337/Strategy-Meta_Trend/actions?query=workflow:Compile+branch%3Amaster +[gha-image-compile-master]: https://github.com/EA31337/Strategy-Meta_Trend/workflows/Compile/badge.svg?branch=master [tg-channel-image]: https://img.shields.io/badge/Telegram-join-0088CC.svg?logo=telegram [tg-channel-link]: https://t.me/EA31337 diff --git a/Stg_Meta_Reversal.mq4 b/Stg_Meta_Trend.mq4 similarity index 84% rename from Stg_Meta_Reversal.mq4 rename to Stg_Meta_Trend.mq4 index 581e85c..e709df9 100644 --- a/Stg_Meta_Reversal.mq4 +++ b/Stg_Meta_Trend.mq4 @@ -6,8 +6,8 @@ /** * @file - * Implements Reversal meta strategy. + * Implements Trend meta strategy. */ // Includes the main code. -#include "Stg_Meta_Reversal.mq5" +#include "Stg_Meta_Trend.mq5" diff --git a/Stg_Meta_Reversal.mq5 b/Stg_Meta_Trend.mq5 similarity index 85% rename from Stg_Meta_Reversal.mq5 rename to Stg_Meta_Trend.mq5 index c340563..e7ca22a 100644 --- a/Stg_Meta_Reversal.mq5 +++ b/Stg_Meta_Trend.mq5 @@ -1,6 +1,6 @@ /** * @file - * Implements Reversal meta strategy. + * Implements Trend meta strategy. */ // Includes conditional compilation directives. @@ -32,13 +32,13 @@ input ENUM_LOG_LEVEL Log_Level = V_INFO; // Log level. input bool Info_On_Chart = true; // Display info on chart. // Includes strategy class. -#include "Stg_Meta_Reversal.mqh" +#include "Stg_Meta_Trend.mqh" // Defines. -#define ea_name "Strategy Meta Reversal" +#define ea_name "Strategy Meta Trend" #define ea_version "2.000" -#define ea_desc "Reversal meta strategy reverses signals of another strategy." -#define ea_link "https://github.com/EA31337/Strategy-Meta_Reversal" +#define ea_desc "Trend meta strategy to filter out signals of other strategies based on the current trend." +#define ea_link "https://github.com/EA31337/Strategy-Meta_Trend" #define ea_author "EA31337 Ltd" // Properties. @@ -64,7 +64,7 @@ int OnInit() { bool _result = true; EAParams ea_params(__FILE__, Log_Level); ea = new EA(ea_params); - _result &= ea.StrategyAdd(Active_Tfs); + _result &= ea.StrategyAdd(Active_Tfs); return (_result ? INIT_SUCCEEDED : INIT_FAILED); } diff --git a/Stg_Meta_Reversal.mqh b/Stg_Meta_Trend.mqh similarity index 66% rename from Stg_Meta_Reversal.mqh rename to Stg_Meta_Trend.mqh index fc62259..9e4db3c 100644 --- a/Stg_Meta_Reversal.mqh +++ b/Stg_Meta_Trend.mqh @@ -1,75 +1,87 @@ /** * @file - * Implements Reversal meta strategy. + * Implements Trend meta strategy. */ // Prevents processing this includes file multiple times. -#ifndef STG_META_REVERSAL_MQH -#define STG_META_REVERSAL_MQH +#ifndef STG_META_TREND_MQH +#define STG_META_TREND_MQH // User input params. -INPUT2_GROUP("Meta Reversal strategy: main params"); -INPUT2 ENUM_STRATEGY Meta_Reversal_Strategy = STRAT_ATR; // Strategy to reverse signals -INPUT2_GROUP("Meta Reversal strategy: common params"); -INPUT2 float Meta_Reversal_LotSize = 0; // Lot size -INPUT2 int Meta_Reversal_SignalOpenMethod = 0; // Signal open method -INPUT2 float Meta_Reversal_SignalOpenLevel = 0; // Signal open level -INPUT2 int Meta_Reversal_SignalOpenFilterMethod = 32; // Signal open filter method -INPUT2 int Meta_Reversal_SignalOpenFilterTime = 3; // Signal open filter time (0-31) -INPUT2 int Meta_Reversal_SignalOpenBoostMethod = 0; // Signal open boost method -INPUT2 int Meta_Reversal_SignalCloseMethod = 0; // Signal close method -INPUT2 int Meta_Reversal_SignalCloseFilter = 32; // Signal close filter (-127-127) -INPUT2 float Meta_Reversal_SignalCloseLevel = 0; // Signal close level -INPUT2 int Meta_Reversal_PriceStopMethod = 0; // Price limit method -INPUT2 float Meta_Reversal_PriceStopLevel = 2; // Price limit level -INPUT2 int Meta_Reversal_TickFilterMethod = 32; // Tick filter method (0-255) -INPUT2 float Meta_Reversal_MaxSpread = 4.0; // Max spread to trade (in pips) -INPUT2 short Meta_Reversal_Shift = 0; // Shift -INPUT2 float Meta_Reversal_OrderCloseLoss = 30; // Order close loss -INPUT2 float Meta_Reversal_OrderCloseProfit = 30; // Order close profit -INPUT2 int Meta_Reversal_OrderCloseTime = -10; // Order close time in mins (>0) or bars (<0) +INPUT2_GROUP("Meta Trend strategy: main params"); +INPUT2 ENUM_STRATEGY Meta_Trend_Strategy = STRAT_STOCHASTIC; // Strategy to filter by trend +INPUT2_GROUP("Meta Trend strategy: common params"); +INPUT2 float Meta_Trend_LotSize = 0; // Lot size +INPUT2 int Meta_Trend_SignalOpenMethod = 0; // Signal open method +INPUT2 float Meta_Trend_SignalOpenLevel = 0; // Signal open level +INPUT2 int Meta_Trend_SignalOpenFilterMethod = 32; // Signal open filter method +INPUT2 int Meta_Trend_SignalOpenFilterTime = 3; // Signal open filter time (0-31) +INPUT2 int Meta_Trend_SignalOpenBoostMethod = 0; // Signal open boost method +INPUT2 int Meta_Trend_SignalCloseMethod = 0; // Signal close method +INPUT2 int Meta_Trend_SignalCloseFilter = 32; // Signal close filter (-127-127) +INPUT2 float Meta_Trend_SignalCloseLevel = 0; // Signal close level +INPUT2 int Meta_Trend_PriceStopMethod = 0; // Price limit method +INPUT2 float Meta_Trend_PriceStopLevel = 2; // Price limit level +INPUT2 int Meta_Trend_TickFilterMethod = 32; // Tick filter method (0-255) +INPUT2 float Meta_Trend_MaxSpread = 4.0; // Max spread to trade (in pips) +INPUT2 short Meta_Trend_Shift = 0; // Shift +INPUT2 float Meta_Trend_OrderCloseLoss = 200; // Order close loss +INPUT2 float Meta_Trend_OrderCloseProfit = 200; // Order close profit +INPUT2 int Meta_Trend_OrderCloseTime = 2880; // Order close time in mins (>0) or bars (<0) +INPUT_GROUP("Meta Trend strategy: RSI oscillator params"); +INPUT int Meta_Trend_RSI_Period = 16; // Period +INPUT ENUM_APPLIED_PRICE Meta_Trend_RSI_Applied_Price = PRICE_WEIGHTED; // Applied Price +INPUT int Meta_Trend_RSI_Shift = 0; // Shift +INPUT ENUM_IDATA_SOURCE_TYPE Meta_Trend_RSI_SourceType = IDATA_BUILTIN; // Source type // Structs. - // Defines struct with default user strategy values. -struct Stg_Meta_Reversal_Params_Defaults : StgParams { - Stg_Meta_Reversal_Params_Defaults() - : StgParams(::Meta_Reversal_SignalOpenMethod, ::Meta_Reversal_SignalOpenFilterMethod, - ::Meta_Reversal_SignalOpenLevel, ::Meta_Reversal_SignalOpenBoostMethod, - ::Meta_Reversal_SignalCloseMethod, ::Meta_Reversal_SignalCloseFilter, - ::Meta_Reversal_SignalCloseLevel, ::Meta_Reversal_PriceStopMethod, ::Meta_Reversal_PriceStopLevel, - ::Meta_Reversal_TickFilterMethod, ::Meta_Reversal_MaxSpread, ::Meta_Reversal_Shift) { - Set(STRAT_PARAM_LS, Meta_Reversal_LotSize); - Set(STRAT_PARAM_OCL, Meta_Reversal_OrderCloseLoss); - Set(STRAT_PARAM_OCP, Meta_Reversal_OrderCloseProfit); - Set(STRAT_PARAM_OCT, Meta_Reversal_OrderCloseTime); - Set(STRAT_PARAM_SOFT, Meta_Reversal_SignalOpenFilterTime); +struct Stg_Meta_Trend_Params_Defaults : StgParams { + Stg_Meta_Trend_Params_Defaults() + : StgParams(::Meta_Trend_SignalOpenMethod, ::Meta_Trend_SignalOpenFilterMethod, ::Meta_Trend_SignalOpenLevel, + ::Meta_Trend_SignalOpenBoostMethod, ::Meta_Trend_SignalCloseMethod, ::Meta_Trend_SignalCloseFilter, + ::Meta_Trend_SignalCloseLevel, ::Meta_Trend_PriceStopMethod, ::Meta_Trend_PriceStopLevel, + ::Meta_Trend_TickFilterMethod, ::Meta_Trend_MaxSpread, ::Meta_Trend_Shift) { + Set(STRAT_PARAM_LS, ::Meta_Trend_LotSize); + Set(STRAT_PARAM_OCL, ::Meta_Trend_OrderCloseLoss); + Set(STRAT_PARAM_OCP, ::Meta_Trend_OrderCloseProfit); + Set(STRAT_PARAM_OCT, ::Meta_Trend_OrderCloseTime); + Set(STRAT_PARAM_SOFT, ::Meta_Trend_SignalOpenFilterTime); } }; -class Stg_Meta_Reversal : public Strategy { +class Stg_Meta_Trend : public Strategy { protected: Ref strat; public: - Stg_Meta_Reversal(StgParams &_sparams, TradeParams &_tparams, ChartParams &_cparams, string _name = "") + Stg_Meta_Trend(StgParams &_sparams, TradeParams &_tparams, ChartParams &_cparams, string _name = "") : Strategy(_sparams, _tparams, _cparams, _name) {} - static Stg_Meta_Reversal *Init(ENUM_TIMEFRAMES _tf = NULL, EA *_ea = NULL) { + static Stg_Meta_Trend *Init(ENUM_TIMEFRAMES _tf = NULL, EA *_ea = NULL) { // Initialize strategy initial values. - Stg_Meta_Reversal_Params_Defaults stg_reversal_defaults; - StgParams _stg_params(stg_reversal_defaults); + Stg_Meta_Trend_Params_Defaults stg_trend_defaults; + StgParams _stg_params(stg_trend_defaults); // Initialize Strategy instance. ChartParams _cparams(_tf, _Symbol); TradeParams _tparams; - Strategy *_strat = new Stg_Meta_Reversal(_stg_params, _tparams, _cparams, "(Meta) Reversal"); + Strategy *_strat = new Stg_Meta_Trend(_stg_params, _tparams, _cparams, "(Meta) Trend"); return _strat; } /** * Event on strategy's init. */ - void OnInit() { SetStrategy(Meta_Reversal_Strategy); } + void OnInit() { + SetStrategy(Meta_Trend_Strategy); + // Initialize indicators. + { + IndiRSIParams _indi_params(::Meta_Trend_RSI_Period, ::Meta_Trend_RSI_Applied_Price, ::Meta_Trend_RSI_Shift); + _indi_params.SetDataSourceType(::Meta_Trend_RSI_SourceType); + _indi_params.SetTf(PERIOD_D1); + SetIndicator(new Indi_RSI(_indi_params)); + } + } /** * Sets strategy. @@ -133,6 +145,9 @@ class Stg_Meta_Reversal : public Strategy { case STRAT_DEMARKER: _result &= StrategyAdd(_tf, _magic_no, _sid); break; + case STRAT_DPO: + _result &= StrategyAdd(_tf, _magic_no, _sid); + break; case STRAT_ENVELOPES: _result &= StrategyAdd(_tf, _magic_no, _sid); break; @@ -157,6 +172,9 @@ class Stg_Meta_Reversal : public Strategy { case STRAT_MA: _result &= StrategyAdd(_tf, _magic_no, _sid); break; + case STRAT_MA_BREAKOUT: + _result &= StrategyAdd(_tf, _magic_no, _sid); + break; case STRAT_MA_CROSS_PIVOT: _result &= StrategyAdd(_tf, _magic_no, _sid); break; @@ -273,15 +291,26 @@ class Stg_Meta_Reversal : public Strategy { * Check strategy's opening signal. */ bool SignalOpen(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(); + // uint _ishift = _indi.GetShift(); + uint _ishift = _shift; + switch (_cmd) { + case ORDER_TYPE_BUY: + _result &= _indi[_shift][0] >= 50 && _indi[_shift + 1][0] >= 50; + break; + case ORDER_TYPE_SELL: + _result &= _indi[_shift][0] <= 50 && _indi[_shift + 1][0] <= 50; + break; } _level = _level == 0.0f ? strat.Ptr().Get(STRAT_PARAM_SOL) : _level; _method = _method == 0 ? strat.Ptr().Get(STRAT_PARAM_SOM) : _method; _shift = _shift == 0 ? strat.Ptr().Get(STRAT_PARAM_SHIFT) : _shift; - _result |= strat.Ptr().SignalOpen(Order::NegateOrderType(_cmd), _method, _level, _shift); + _result &= strat.Ptr().SignalOpen(_cmd, _method, _level, _shift); return _result; } @@ -302,4 +331,4 @@ class Stg_Meta_Reversal : public Strategy { } }; -#endif // STG_META_REVERSAL_MQH +#endif // STG_META_TREND_MQH