From 10736895e436b348c71f6788fdba8cb64e5d035f Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 27 Aug 2023 23:22:24 +0100 Subject: [PATCH 1/4] Renames Demo to Oscillator --- .github/workflows/backtest.yml | 6 +- .github/workflows/compile.yml | 4 +- README.md | 22 +++--- Stg_Demo.mqh | 100 --------------------------- Stg_Demo.mq4 => Stg_Oscillator.mq4 | 4 +- Stg_Demo.mq5 => Stg_Oscillator.mq5 | 12 ++-- Stg_Oscillator.mqh | 104 +++++++++++++++++++++++++++++ 7 files changed, 126 insertions(+), 126 deletions(-) delete mode 100644 Stg_Demo.mqh rename Stg_Demo.mq4 => Stg_Oscillator.mq4 (86%) rename Stg_Demo.mq5 => Stg_Oscillator.mq5 (85%) create mode 100644 Stg_Oscillator.mqh diff --git a/.github/workflows/backtest.yml b/.github/workflows/backtest.yml index 32e9a88..f965572 100644 --- a/.github/workflows/backtest.yml +++ b/.github/workflows/backtest.yml @@ -39,14 +39,14 @@ jobs: include: . init-platform: true mt-version: 5.0.0.2361 - path: Stg_Demo.mq4 + path: Stg_Oscillator.mq4 verbose: true - name: Compile for MQL5 uses: fx31337/mql-compile-action@master with: include: . mt-version: 5.0.0.2515 - path: Stg_Demo.mq5 + path: Stg_Oscillator.mq5 verbose: true - name: List compiled files run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname' @@ -77,7 +77,7 @@ jobs: OptFormatBrief: true OptFormatJson: true OptVerbose: true - TestExpert: "Stg_Demo" + TestExpert: "Stg_Oscillator" TestPeriod: M1 TestReportName: Report-${{ matrix.year }}-${{ matrix.month }} - name: Upload results diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index d5b0911..603073f 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -37,14 +37,14 @@ jobs: include: . init-platform: true mt-version: 5.0.0.2361 - path: Stg_Demo.mq4 + path: Stg_Oscillator.mq4 verbose: true - name: Compile for MQL5 uses: fx31337/mql-compile-action@master with: include: . mt-version: 5.0.0.2515 - path: Stg_Demo.mq5 + path: Stg_Oscillator.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 8eda348..3e360c7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Strategy Demo +# Strategy Oscillator [![Status][gha-image-check-master]][gha-link-check-master] [![Status][gha-image-compile-master]][gha-link-compile-master] @@ -8,22 +8,18 @@ [![Twitter][twitter-image]][twitter-link] [![Edit][gh-edit-badge]][gh-edit-link] -Strategy based on the Demo indicator. +Strategy based on the Oscillator indicator. ## Description -This is example demo strategy for the demonstration purposes. +This is example oscillator strategy for the oscillatornstration purposes. ## Dependencies | Tag | Framework | |:--------:|:---------:| -| v1.000 | v2.000 | -| v1.001 | v2.001 | -| ... | ... | -| v1.012 | v2.012 | -| v1.013 | v2.013 | | v2.000 | v3.000.1 | +| v2.001 | v3.001.1 | @@ -31,12 +27,12 @@ This is example demo strategy for the demonstration purposes. [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-Demo +[gh-edit-link]: https://github.dev/EA31337/Strategy-Oscillator -[gha-link-check-master]: https://github.com/EA31337/Strategy-Demo/actions?query=workflow:Check+branch%3Amaster -[gha-image-check-master]: https://github.com/EA31337/Strategy-Demo/workflows/Check/badge.svg?branch=master -[gha-link-compile-master]: https://github.com/EA31337/Strategy-Demo/actions?query=workflow:Compile+branch%3Amaster -[gha-image-compile-master]: https://github.com/EA31337/Strategy-Demo/workflows/Compile/badge.svg?branch=master +[gha-link-check-master]: https://github.com/EA31337/Strategy-Oscillator/actions?query=workflow:Check+branch%3Amaster +[gha-image-check-master]: https://github.com/EA31337/Strategy-Oscillator/workflows/Check/badge.svg?branch=master +[gha-link-compile-master]: https://github.com/EA31337/Strategy-Oscillator/actions?query=workflow:Compile+branch%3Amaster +[gha-image-compile-master]: https://github.com/EA31337/Strategy-Oscillator/workflows/Compile/badge.svg?branch=master [license-image]: https://img.shields.io/github/license/EA31337/EA31337-Strategies.svg [license-link]: https://tldrlegal.com/license/gnu-general-public-license-v3-(gpl-3) diff --git a/Stg_Demo.mqh b/Stg_Demo.mqh deleted file mode 100644 index bdb1964..0000000 --- a/Stg_Demo.mqh +++ /dev/null @@ -1,100 +0,0 @@ -/** - * @file - * Implements Demo strategy based on the Demo indicator. - */ - -// User input params. -INPUT_GROUP("Demo strategy: strategy params"); -INPUT float Demo_LotSize = 0; // Lot size -INPUT int Demo_SignalOpenMethod = 0; // Signal open method -INPUT float Demo_SignalOpenLevel = 0; // Signal open level -INPUT int Demo_SignalOpenFilterMethod = 32; // Signal open filter method -INPUT int Demo_SignalOpenFilterTime = 3; // Signal open filter time (0-31) -INPUT int Demo_SignalOpenBoostMethod = 0; // Signal open boost method -INPUT int Demo_SignalCloseMethod = 0; // Signal close method -INPUT int Demo_SignalCloseFilter = 32; // Signal close filter (-127-127) -INPUT float Demo_SignalCloseLevel = 0; // Signal close level -INPUT int Demo_PriceStopMethod = 0; // Price limit method -INPUT float Demo_PriceStopLevel = 2; // Price limit level -INPUT int Demo_TickFilterMethod = 32; // Tick filter method (0-255) -INPUT float Demo_MaxSpread = 4.0; // Max spread to trade (in pips) -INPUT short Demo_Shift = 0; // Shift -INPUT float Demo_OrderCloseLoss = 80; // Order close loss -INPUT float Demo_OrderCloseProfit = 80; // Order close profit -INPUT int Demo_OrderCloseTime = -30; // Order close time in mins (>0) or bars (<0) -INPUT_GROUP("Demo strategy: Demo indicator params"); -INPUT int Demo_Indi_Demo_Shift = 0; // Shift -INPUT ENUM_IDATA_SOURCE_TYPE Demo_Indi_Demo_SourceType = IDATA_INDICATOR; // Source type - -// Structs. - -// Defines struct with default user strategy values. -struct Stg_Demo_Params_Defaults : StgParams { - Stg_Demo_Params_Defaults() - : StgParams(::Demo_SignalOpenMethod, ::Demo_SignalOpenFilterMethod, ::Demo_SignalOpenLevel, - ::Demo_SignalOpenBoostMethod, ::Demo_SignalCloseMethod, ::Demo_SignalCloseFilter, - ::Demo_SignalCloseLevel, ::Demo_PriceStopMethod, ::Demo_PriceStopLevel, ::Demo_TickFilterMethod, - ::Demo_MaxSpread, ::Demo_Shift) { - Set(STRAT_PARAM_LS, Demo_LotSize); - Set(STRAT_PARAM_OCL, Demo_OrderCloseLoss); - Set(STRAT_PARAM_OCP, Demo_OrderCloseProfit); - Set(STRAT_PARAM_OCT, Demo_OrderCloseTime); - Set(STRAT_PARAM_SOFT, Demo_SignalOpenFilterTime); - } -}; - -class Stg_Demo : public Strategy { - public: - Stg_Demo(StgParams &_sparams, TradeParams &_tparams, ChartParams &_cparams, string _name = "") - : Strategy(_sparams, _tparams, _cparams, _name) {} - - static Stg_Demo *Init(ENUM_TIMEFRAMES _tf = NULL, EA* _ea = NULL) { - // Initialize strategy initial values. - Stg_Demo_Params_Defaults stg_demo_defaults; - StgParams _stg_params(stg_demo_defaults); - // Initialize Strategy instance. - ChartParams _cparams(_tf, _Symbol); - TradeParams _tparams; - Strategy *_strat = new Stg_Demo(_stg_params, _tparams, _cparams, "Demo"); - return _strat; - } - - /** - * Event on strategy's init. - */ - void OnInit() { - // Initialize indicators. - IndiDemoParams _indi_params(::Demo_Indi_Demo_Shift); - _indi_params.SetTf(Get(STRAT_PARAM_TF)); - SetIndicator(new Indi_Demo(_indi_params)); - } - - /** - * Check strategy's opening signal. - */ - bool SignalOpen(ENUM_ORDER_TYPE _cmd, int _method, float _level = 0.0f, int _shift = 0) { - Indi_Demo *_indi = GetIndicator(); - bool _result = - _indi.GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) && _indi.GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1); - if (!_result) { - // Returns false when indicator data is not valid. - return false; - } - IndicatorSignal _signals = _indi.GetSignals(4, _shift); - switch (_cmd) { - case ORDER_TYPE_BUY: - // Buy signal. - _result &= _indi.IsIncreasing(1, 0, _shift); - _result &= _indi.IsIncByPct(_level / 10, 0, _shift, 2); - _result &= _method > 0 ? _signals.CheckSignals(_method) : _signals.CheckSignalsAll(-_method); - break; - case ORDER_TYPE_SELL: - // Sell signal. - _result &= _indi.IsDecreasing(1, 0, _shift); - _result &= _indi.IsDecByPct(_level / 10, 0, _shift, 2); - _result &= _method > 0 ? _signals.CheckSignals(_method) : _signals.CheckSignalsAll(-_method); - break; - } - return _result; - } -}; diff --git a/Stg_Demo.mq4 b/Stg_Oscillator.mq4 similarity index 86% rename from Stg_Demo.mq4 rename to Stg_Oscillator.mq4 index be4ade6..cc079f7 100644 --- a/Stg_Demo.mq4 +++ b/Stg_Oscillator.mq4 @@ -6,8 +6,8 @@ /** * @file - * Implements Demo strategy. + * Implements Oscillator strategy. */ // Includes the main code. -#include "Stg_Demo.mq5" +#include "Stg_Oscillator.mq5" diff --git a/Stg_Demo.mq5 b/Stg_Oscillator.mq5 similarity index 85% rename from Stg_Demo.mq5 rename to Stg_Oscillator.mq5 index 2a3f701..8ec494f 100644 --- a/Stg_Demo.mq5 +++ b/Stg_Oscillator.mq5 @@ -1,6 +1,6 @@ /** * @file - * Implements Demo strategy. + * Implements Oscillator strategy. */ // Includes conditional compilation directives. @@ -8,7 +8,7 @@ // Includes EA31337 framework. #include -#include +#include #include // Inputs. @@ -18,13 +18,13 @@ input ENUM_LOG_LEVEL Log_Level = V_INFO; // Log level. input bool Info_On_Chart = true; // Display info on chart. // Includes strategy. -#include "Stg_Demo.mqh" +#include "Stg_Oscillator.mqh" // Defines. -#define ea_name "Strategy Demo" +#define ea_name "Strategy Oscillator" #define ea_version "2.000" #define ea_desc "Strategy based on EA31337 framework." -#define ea_link "https://github.com/EA31337/Strategy-Demo" +#define ea_link "https://github.com/EA31337/Strategy-Oscillator" #define ea_author "EA31337 Ltd" // Properties. @@ -50,7 +50,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_Oscillator.mqh b/Stg_Oscillator.mqh new file mode 100644 index 0000000..f6c02b4 --- /dev/null +++ b/Stg_Oscillator.mqh @@ -0,0 +1,104 @@ +/** + * @file + * Implements Oscillator strategy based on the Oscillator indicator. + */ + +// User input params. +INPUT_GROUP("Oscillator strategy: strategy params"); +INPUT float Oscillator_LotSize = 0; // Lot size +INPUT int Oscillator_SignalOpenMethod = 0; // Signal open method +INPUT float Oscillator_SignalOpenLevel = 0; // Signal open level +INPUT int Oscillator_SignalOpenFilterMethod = 32; // Signal open filter method +INPUT int Oscillator_SignalOpenFilterTime = 3; // Signal open filter time (0-31) +INPUT int Oscillator_SignalOpenBoostMethod = 0; // Signal open boost method +INPUT int Oscillator_SignalCloseMethod = 0; // Signal close method +INPUT int Oscillator_SignalCloseFilter = 32; // Signal close filter (-127-127) +INPUT float Oscillator_SignalCloseLevel = 0; // Signal close level +INPUT int Oscillator_PriceStopMethod = 0; // Price limit method +INPUT float Oscillator_PriceStopLevel = 2; // Price limit level +INPUT int Oscillator_TickFilterMethod = 32; // Tick filter method (0-255) +INPUT float Oscillator_MaxSpread = 4.0; // Max spread to trade (in pips) +INPUT short Oscillator_Shift = 0; // Shift +INPUT float Oscillator_OrderCloseLoss = 80; // Order close loss +INPUT float Oscillator_OrderCloseProfit = 80; // Order close profit +INPUT int Oscillator_OrderCloseTime = -30; // Order close time in mins (>0) or bars (<0) +INPUT_GROUP("Oscillator strategy: Oscillator indicator params"); +INPUT int Oscillator_Indi_Oscillator_Shift = 0; // Shift +INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_Oscillator_SourceType = IDATA_INDICATOR; // Source type + +// Structs. + +// Defines struct with default user strategy values. +struct Stg_Oscillator_Params_Defaults : StgParams { + Stg_Oscillator_Params_Defaults() + : StgParams(::Oscillator_SignalOpenMethod, ::Oscillator_SignalOpenFilterMethod, ::Oscillator_SignalOpenLevel, + ::Oscillator_SignalOpenBoostMethod, ::Oscillator_SignalCloseMethod, ::Oscillator_SignalCloseFilter, + ::Oscillator_SignalCloseLevel, ::Oscillator_PriceStopMethod, ::Oscillator_PriceStopLevel, + ::Oscillator_TickFilterMethod, ::Oscillator_MaxSpread, ::Oscillator_Shift) { + Set(STRAT_PARAM_LS, Oscillator_LotSize); + Set(STRAT_PARAM_OCL, Oscillator_OrderCloseLoss); + Set(STRAT_PARAM_OCP, Oscillator_OrderCloseProfit); + Set(STRAT_PARAM_OCT, Oscillator_OrderCloseTime); + Set(STRAT_PARAM_SOFT, Oscillator_SignalOpenFilterTime); + } +}; + +class Stg_Oscillator : public Strategy { + public: + Stg_Oscillator(StgParams &_sparams, TradeParams &_tparams, ChartParams &_cparams, string _name = "") + : Strategy(_sparams, _tparams, _cparams, _name) {} + + static Stg_Oscillator *Init(ENUM_TIMEFRAMES _tf = NULL, EA *_ea = NULL) { + // Initialize strategy initial values. + Stg_Oscillator_Params_Defaults stg_oscillator_defaults; + StgParams _stg_params(stg_oscillator_defaults); + // Initialize Strategy instance. + ChartParams _cparams(_tf, _Symbol); + TradeParams _tparams; + Strategy *_strat = new Stg_Oscillator(_stg_params, _tparams, _cparams, "Oscillator"); + return _strat; + } + + /** + * Event on strategy's init. + */ + void OnInit() { + // Initialize indicators. + /* + IndiOscillatorParams _indi_params(::Oscillator_Indi_Oscillator_Shift); + _indi_params.SetTf(Get(STRAT_PARAM_TF)); + SetIndicator(new Indi_Oscillator(_indi_params)); + */ + } + + /** + * Check strategy's opening signal. + */ + bool SignalOpen(ENUM_ORDER_TYPE _cmd, int _method, float _level = 0.0f, int _shift = 0) { + // Indi_Oscillator *_indi = GetIndicator(); + bool _result = + _indi.GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) && _indi.GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1); + if (!_result) { + // Returns false when indicator data is not valid. + return false; + } + /* + IndicatorSignal _signals = _indi.GetSignals(4, _shift); + switch (_cmd) { + case ORDER_TYPE_BUY: + // Buy signal. + _result &= _indi.IsIncreasing(1, 0, _shift); + _result &= _indi.IsIncByPct(_level / 10, 0, _shift, 2); + _result &= _method > 0 ? _signals.CheckSignals(_method) : _signals.CheckSignalsAll(-_method); + break; + case ORDER_TYPE_SELL: + // Sell signal. + _result &= _indi.IsDecreasing(1, 0, _shift); + _result &= _indi.IsDecByPct(_level / 10, 0, _shift, 2); + _result &= _method > 0 ? _signals.CheckSignals(_method) : _signals.CheckSignalsAll(-_method); + break; + } + */ + return _result; + } +}; From 5ed06749625ae17c74639fef0b346c0be42a9887 Mon Sep 17 00:00:00 2001 From: kenorb Date: Mon, 28 Aug 2023 14:58:17 +0100 Subject: [PATCH 2/4] Initial strategy trading logic --- Stg_Oscillator.mq5 | 7 ++- Stg_Oscillator.mqh | 130 ++++++++++++++++++++++++++++++++++++++------- config/define.h | 1 + 3 files changed, 119 insertions(+), 19 deletions(-) diff --git a/Stg_Oscillator.mq5 b/Stg_Oscillator.mq5 index 8ec494f..35be04d 100644 --- a/Stg_Oscillator.mq5 +++ b/Stg_Oscillator.mq5 @@ -8,7 +8,12 @@ // Includes EA31337 framework. #include -#include +#include +#include +#include +#include +#include +// #include #include // Inputs. diff --git a/Stg_Oscillator.mqh b/Stg_Oscillator.mqh index f6c02b4..de2c461 100644 --- a/Stg_Oscillator.mqh +++ b/Stg_Oscillator.mqh @@ -3,7 +3,18 @@ * Implements Oscillator strategy based on the Oscillator indicator. */ +enum ENUM_STG_OSCILLATOR_TYPE { + STG_OSCILLATOR_TYPE_0_NONE = 0, // (None) + STG_OSCILLATOR_TYPE_AC, // AC + STG_OSCILLATOR_TYPE_AD, // AD + STG_OSCILLATOR_TYPE_RSI, // RSI + STG_OSCILLATOR_TYPE_STOCH, // Stochastic + STG_OSCILLATOR_TYPE_WPR, // WPR +}; + // User input params. +INPUT_GROUP("Oscillator strategy: main strategy params"); +INPUT ENUM_STG_OSCILLATOR_TYPE Oscillator_Type = STG_OSCILLATOR_TYPE_STOCH; // Oscillator type INPUT_GROUP("Oscillator strategy: strategy params"); INPUT float Oscillator_LotSize = 0; // Lot size INPUT int Oscillator_SignalOpenMethod = 0; // Signal open method @@ -22,9 +33,26 @@ INPUT short Oscillator_Shift = 0; // Shift INPUT float Oscillator_OrderCloseLoss = 80; // Order close loss INPUT float Oscillator_OrderCloseProfit = 80; // Order close profit INPUT int Oscillator_OrderCloseTime = -30; // Order close time in mins (>0) or bars (<0) -INPUT_GROUP("Oscillator strategy: Oscillator indicator params"); -INPUT int Oscillator_Indi_Oscillator_Shift = 0; // Shift -INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_Oscillator_SourceType = IDATA_INDICATOR; // Source type +INPUT_GROUP("Oscillator strategy: AC oscillator params"); +INPUT int Oscillator_Indi_AC_Shift = 0; // Shift +INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_AC_SourceType = IDATA_BUILTIN; // Source type +INPUT_GROUP("Oscillator strategy: AD oscillator params"); +INPUT int Oscillator_Indi_AD_Shift = 0; // Shift +INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_AD_SourceType = IDATA_BUILTIN; // Source type +INPUT_GROUP("Oscillator strategy: RSI indicator params"); +INPUT int Oscillator_Indi_RSI_Period = 16; // Period +INPUT ENUM_APPLIED_PRICE Oscillator_Indi_RSI_Applied_Price = PRICE_WEIGHTED; // Applied Price +INPUT int Oscillator_Indi_RSI_Shift = 0; // Shift +INPUT_GROUP("Oscillator strategy: Stochastic indicator params"); +INPUT int Oscillator_Indi_Stochastic_KPeriod = 8; // K line period +INPUT int Oscillator_Indi_Stochastic_DPeriod = 12; // D line period +INPUT int Oscillator_Indi_Stochastic_Slowing = 12; // Slowing +INPUT ENUM_MA_METHOD Oscillator_Indi_Stochastic_MA_Method = MODE_EMA; // Moving Average method +INPUT ENUM_STO_PRICE Oscillator_Indi_Stochastic_Price_Field = 0; // Price (0 - Low/High or 1 - Close/Close) +INPUT int Oscillator_Indi_Stochastic_Shift = 0; // Shift +INPUT_GROUP("Oscillator strategy: WPR indicator params"); +INPUT int Oscillator_Indi_WPR_Period = 18; // Period +INPUT int Oscillator_Indi_WPR_Shift = 0; // Shift // Structs. @@ -59,46 +87,112 @@ class Stg_Oscillator : public Strategy { return _strat; } + /** + * Validate soscillators's entry. + */ + bool IsValidEntry(IndicatorBase *_indi, int _shift = 0) { + bool _result = true; + switch (Oscillator_Type) { + case STG_OSCILLATOR_TYPE_AC: + _result &= dynamic_cast(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) && + dynamic_cast(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1); + break; + case STG_OSCILLATOR_TYPE_AD: + _result &= dynamic_cast(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) && + dynamic_cast(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1); + break; + case STG_OSCILLATOR_TYPE_RSI: + _result &= dynamic_cast(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) && + dynamic_cast(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1); + break; + case STG_OSCILLATOR_TYPE_STOCH: + _result &= dynamic_cast(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) && + dynamic_cast(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1); + break; + case STG_OSCILLATOR_TYPE_WPR: + _result &= dynamic_cast(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) && + dynamic_cast(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1); + break; + default: + break; + } + return _result; + } + /** * Event on strategy's init. */ void OnInit() { // Initialize indicators. - /* - IndiOscillatorParams _indi_params(::Oscillator_Indi_Oscillator_Shift); - _indi_params.SetTf(Get(STRAT_PARAM_TF)); - SetIndicator(new Indi_Oscillator(_indi_params)); - */ + switch (Oscillator_Type) { + case STG_OSCILLATOR_TYPE_AC: // AC + { + IndiACParams ac_params(::Oscillator_Indi_AC_Shift); + ac_params.SetTf(Get(STRAT_PARAM_TF)); + ac_params.SetDataSourceType(Oscillator_Indi_AC_SourceType); + SetIndicator(new Indi_AC(ac_params), ::Oscillator_Type); + break; + } + case STG_OSCILLATOR_TYPE_AD: // AD + { + IndiADParams ad_params(::Oscillator_Indi_AD_Shift); + ad_params.SetDataSourceType(Oscillator_Indi_AD_SourceType); + ad_params.SetTf(Get(STRAT_PARAM_TF)); + SetIndicator(new Indi_AD(ad_params), ::Oscillator_Type); + break; + } + case STG_OSCILLATOR_TYPE_RSI: // RSI + { + IndiRSIParams _indi_params(::Oscillator_Indi_RSI_Period, ::Oscillator_Indi_RSI_Applied_Price, + ::Oscillator_Indi_RSI_Shift); + _indi_params.SetTf(Get(STRAT_PARAM_TF)); + SetIndicator(new Indi_RSI(_indi_params), ::Oscillator_Type); + break; + } + case STG_OSCILLATOR_TYPE_STOCH: // Stochastic + { + IndiStochParams _indi_params(::Oscillator_Indi_Stochastic_KPeriod, ::Oscillator_Indi_Stochastic_DPeriod, + ::Oscillator_Indi_Stochastic_Slowing, ::Oscillator_Indi_Stochastic_MA_Method, + ::Oscillator_Indi_Stochastic_Price_Field, ::Oscillator_Indi_Stochastic_Shift); + _indi_params.SetTf(Get(STRAT_PARAM_TF)); + SetIndicator(new Indi_Stochastic(_indi_params), ::Oscillator_Type); + break; + } + case STG_OSCILLATOR_TYPE_WPR: // WPR + { + IndiWPRParams _indi_params(::Oscillator_Indi_WPR_Period, ::Oscillator_Indi_WPR_Shift); + _indi_params.SetTf(Get(STRAT_PARAM_TF)); + SetIndicator(new Indi_WPR(_indi_params), ::Oscillator_Type); + break; + } + case STG_OSCILLATOR_TYPE_0_NONE: // (None) + default: + break; + } } /** * Check strategy's opening signal. */ bool SignalOpen(ENUM_ORDER_TYPE _cmd, int _method, float _level = 0.0f, int _shift = 0) { - // Indi_Oscillator *_indi = GetIndicator(); - bool _result = - _indi.GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) && _indi.GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1); + IndicatorBase *_indi = GetIndicator(::Oscillator_Type); + bool _result = Oscillator_Type != STG_OSCILLATOR_TYPE_0_NONE && IsValidEntry(_indi, _shift); if (!_result) { // Returns false when indicator data is not valid. return false; } - /* - IndicatorSignal _signals = _indi.GetSignals(4, _shift); switch (_cmd) { case ORDER_TYPE_BUY: // Buy signal. _result &= _indi.IsIncreasing(1, 0, _shift); - _result &= _indi.IsIncByPct(_level / 10, 0, _shift, 2); - _result &= _method > 0 ? _signals.CheckSignals(_method) : _signals.CheckSignalsAll(-_method); + _result &= _indi.IsIncByPct(_level, 0, _shift, 2); break; case ORDER_TYPE_SELL: // Sell signal. _result &= _indi.IsDecreasing(1, 0, _shift); - _result &= _indi.IsDecByPct(_level / 10, 0, _shift, 2); - _result &= _method > 0 ? _signals.CheckSignals(_method) : _signals.CheckSignalsAll(-_method); + _result &= _indi.IsDecByPct(_level, 0, _shift, 2); break; } - */ return _result; } }; diff --git a/config/define.h b/config/define.h index 549ad0b..780191a 100644 --- a/config/define.h +++ b/config/define.h @@ -8,3 +8,4 @@ //#define __debug__ // Enables debugging. #define __input__ // Enables input parameters. //#define __optimize__ // Enables optimization mode. +//#define __resource__ // Enables resources. From 7808f3dcb7fe485ce67200ba3e22bf4f8b96b490 Mon Sep 17 00:00:00 2001 From: kenorb Date: Mon, 28 Aug 2023 15:36:05 +0100 Subject: [PATCH 3/4] Adds signal filtering methods --- Stg_Oscillator.mqh | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Stg_Oscillator.mqh b/Stg_Oscillator.mqh index de2c461..4c45d51 100644 --- a/Stg_Oscillator.mqh +++ b/Stg_Oscillator.mqh @@ -14,10 +14,10 @@ enum ENUM_STG_OSCILLATOR_TYPE { // User input params. INPUT_GROUP("Oscillator strategy: main strategy params"); -INPUT ENUM_STG_OSCILLATOR_TYPE Oscillator_Type = STG_OSCILLATOR_TYPE_STOCH; // Oscillator type +INPUT ENUM_STG_OSCILLATOR_TYPE Oscillator_Type = STG_OSCILLATOR_TYPE_RSI; // Oscillator type INPUT_GROUP("Oscillator strategy: strategy params"); INPUT float Oscillator_LotSize = 0; // Lot size -INPUT int Oscillator_SignalOpenMethod = 0; // Signal open method +INPUT int Oscillator_SignalOpenMethod = 6; // Signal open method INPUT float Oscillator_SignalOpenLevel = 0; // Signal open level INPUT int Oscillator_SignalOpenFilterMethod = 32; // Signal open filter method INPUT int Oscillator_SignalOpenFilterTime = 3; // Signal open filter time (0-31) @@ -176,6 +176,7 @@ class Stg_Oscillator : public Strategy { */ bool SignalOpen(ENUM_ORDER_TYPE _cmd, int _method, float _level = 0.0f, int _shift = 0) { IndicatorBase *_indi = GetIndicator(::Oscillator_Type); + // uint _ishift = _indi.GetShift(); bool _result = Oscillator_Type != STG_OSCILLATOR_TYPE_0_NONE && IsValidEntry(_indi, _shift); if (!_result) { // Returns false when indicator data is not valid. @@ -186,11 +187,25 @@ class Stg_Oscillator : public Strategy { // Buy signal. _result &= _indi.IsIncreasing(1, 0, _shift); _result &= _indi.IsIncByPct(_level, 0, _shift, 2); + if (_result && _method != 0) { + if (METHOD(_method, 0)) _result &= _indi.IsDecreasing(1, 0, _shift + 1); + if (METHOD(_method, 1)) _result &= _indi.IsIncreasing(4, 0, _shift + 3); + if (METHOD(_method, 2)) + _result &= fmax4(_indi[_shift][0], _indi[_shift + 1][0], _indi[_shift + 2][0], _indi[_shift + 3][0]) == + _indi[_shift][0]; + } break; case ORDER_TYPE_SELL: // Sell signal. _result &= _indi.IsDecreasing(1, 0, _shift); _result &= _indi.IsDecByPct(_level, 0, _shift, 2); + if (_result && _method != 0) { + if (METHOD(_method, 0)) _result &= _indi.IsIncreasing(1, 0, _shift + 1); + if (METHOD(_method, 1)) _result &= _indi.IsDecreasing(4, 0, _shift + 3); + if (METHOD(_method, 2)) + _result &= fmin4(_indi[_shift][0], _indi[_shift + 1][0], _indi[_shift + 2][0], _indi[_shift + 3][0]) == + _indi[_shift][0]; + } break; } return _result; From 5d289d73452064ab1136f05467c67ecf4cc4295a Mon Sep 17 00:00:00 2001 From: kenorb Date: Mon, 28 Aug 2023 15:42:44 +0100 Subject: [PATCH 4/4] Updates README --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 3e360c7..b887ea5 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,9 @@ [![Twitter][twitter-image]][twitter-link] [![Edit][gh-edit-badge]][gh-edit-link] -Strategy based on the Oscillator indicator. - ## Description -This is example oscillator strategy for the oscillatornstration purposes. +Strategy based on selected oscillator-type single-valued indicators. ## Dependencies