Skip to content

Commit

Permalink
Merge pull request #22 from nseam/dev-mt5-code-in-mt4-indicator-support
Browse files Browse the repository at this point in the history
Fixes compilation error for MT4 Oscillators and Indicators.
  • Loading branch information
kenorb committed May 20, 2024
2 parents 10802da + 4fd24d1 commit f8e8d1e
Show file tree
Hide file tree
Showing 22 changed files with 174 additions and 12 deletions.
17 changes: 13 additions & 4 deletions Oscillators/AC.mq4
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,22 @@
// Indicator properties.
#ifdef __MQL__
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Black
#property indicator_color2 Green
#property indicator_color3 Red
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 Green
#property indicator_width1 2
#property indicator_label1 "AC"
#property version "1.000"
#endif

// This will allow calling MT5 functions in MT4.
#define INDICATOR_LEGACY_VERSION_MT5
#define INDICATOR_LEGACY_VERSION_LONG // OHLC-based OnCalculate().
#define INDICATOR_LEGACY_VERSION_ACQUIRE_BUFFER ACQUIRE_BUFFER1(ExtACBuffer)
#define INDICATOR_LEGACY_VERSION_RELEASE_BUFFER RELEASE_BUFFER1(ExtACBuffer)
#include <EA31337-classes/IndicatorLegacy.h>

// Includes the main code.
#include "AC.mq5"

Expand Down
10 changes: 7 additions & 3 deletions Oscillators/AC.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
#property description INDI_FULL_NAME
//--
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_buffers 2
#property indicator_plots 1
#property indicator_type1 DRAW_COLOR_HISTOGRAM
#property indicator_color1 Green, Red
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 Green
#property indicator_width1 2
#property indicator_label1 INDI_SHORT_NAME
#property version "1.000"
Expand All @@ -51,8 +51,11 @@
#resource "\\Indicators\\Examples\\Accelerator.ex5"
#endif

#define __debug__

// Includes.
#include <EA31337-classes/Indicators/Indi_AC.mqh>
#include <EA31337-classes/Platform.h>

// Input parameters.
input int InpShift = 0; // Indicator shift
Expand All @@ -75,6 +78,7 @@ void OnInit() {
// Initialize indicator.
IndiACParams _indi_params(::InpShift);
indi = new Indi_AC(_indi_params /* , InpSourceType */);
Platform::AddWithDefaultBindings(indi);
// Name for labels.
// @todo: Use serialized string of _indi_params.
string short_name = StringFormat("%s", indi.GetName());
Expand Down
7 changes: 7 additions & 0 deletions Oscillators/AC.mt5.mq4
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,12 @@
#property version "1.000"
#endif

// This will allow calling MT5 functions in MT4.
#define INDICATOR_LEGACY_VERSION_MT5
#define INDICATOR_LEGACY_VERSION_LONG // OHLC-based OnCalculate().
#define INDICATOR_LEGACY_VERSION_ACQUIRE_BUFFER ACQUIRE_BUFFER1(ExtACBuffer)
#define INDICATOR_LEGACY_VERSION_RELEASE_BUFFER RELEASE_BUFFER1(ExtACBuffer)
#include <EA31337-classes/IndicatorLegacy.h>

// Includes MQL5 version of indicator.
#include <../Indicators\Examples\Accelerator.mq5>
9 changes: 9 additions & 0 deletions Oscillators/AO.mq4
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
#property version "1.000"
#endif

// This will allow calling MT5 functions in MT4.
#define INDICATOR_LEGACY_VERSION_MT5
#define INDICATOR_LEGACY_VERSION_LONG // OHLC-based OnCalculate().
#define INDICATOR_LEGACY_VERSION_ACQUIRE_BUFFER \
ACQUIRE_BUFFER4(ExtAOBuffer, ExtColorBuffer, ExtFastBuffer, ExtSlowBuffer)
#define INDICATOR_LEGACY_VERSION_RELEASE_BUFFER \
RELEASE_BUFFER4(ExtAOBuffer, ExtColorBuffer, ExtFastBuffer, ExtSlowBuffer)
#include <EA31337-classes/IndicatorLegacy.h>

// Includes the main code.
#include "AO.mq5"

Expand Down
2 changes: 1 addition & 1 deletion Oscillators/AO.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ int OnCalculate(const int rates_total, const int prev_calculated,
int max_modes =
indi.Get<int>(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES));
*/
uint max_modes = indi.GetParams().max_modes;
uint max_modes = indi.GetModeCount();
start = prev_calculated == 0 ? fmax3(0, FAST_PERIOD, SLOW_PERIOD)
: prev_calculated - 1;
// Main calculations.
Expand Down
9 changes: 9 additions & 0 deletions Oscillators/AO.mt5.mq4
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,14 @@
#property version "1.000"
#endif

// This will allow calling MT5 functions in MT4.
#define INDICATOR_LEGACY_VERSION_MT5
#define INDICATOR_LEGACY_VERSION_LONG // OHLC-based OnCalculate().
#define INDICATOR_LEGACY_VERSION_ACQUIRE_BUFFER \
ACQUIRE_BUFFER4(ExtAOBuffer, ExtColorBuffer, ExtFastBuffer, ExtSlowBuffer)
#define INDICATOR_LEGACY_VERSION_RELEASE_BUFFER \
RELEASE_BUFFER4(ExtAOBuffer, ExtColorBuffer, ExtFastBuffer, ExtSlowBuffer)
#include <EA31337-classes/IndicatorLegacy.h>

// Includes MQL5 version of indicator.
#include <../Indicators\Examples\Awesome_Oscillator.mq5>
7 changes: 7 additions & 0 deletions Oscillators/Bears.mq4
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
#property version "1.000"
#endif

// This will allow calling MT5 functions in MT4.
#define INDICATOR_LEGACY_VERSION_MT5
#define INDICATOR_LEGACY_VERSION_LONG // OHLC-based OnCalculate().
#define INDICATOR_LEGACY_VERSION_ACQUIRE_BUFFER ACQUIRE_BUFFER1(ExtBearsBuffer)
#define INDICATOR_LEGACY_VERSION_RELEASE_BUFFER RELEASE_BUFFER1(ExtBearsBuffer)
#include <EA31337-classes/IndicatorLegacy.h>

// Includes the main code.
#include "Bears.mq5"

Expand Down
7 changes: 7 additions & 0 deletions Oscillators/Bears.mt5.mq4
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,12 @@
#property version "1.000"
#endif

// This will allow calling MT5 functions in MT4.
#define INDICATOR_LEGACY_VERSION_MT5
#define INDICATOR_LEGACY_VERSION_LONG // OHLC-based OnCalculate().
#define INDICATOR_LEGACY_VERSION_ACQUIRE_BUFFER ACQUIRE_BUFFER1(ExtBearsBuffer)
#define INDICATOR_LEGACY_VERSION_RELEASE_BUFFER RELEASE_BUFFER1(ExtBearsBuffer)
#include <EA31337-classes/IndicatorLegacy.h>

// Includes MQL5 version of indicator.
#include <../Indicators\Examples\Bears.mq5>
11 changes: 11 additions & 0 deletions Oscillators/Gator.mq4
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@
#property version "1.000"
#endif

// This will allow calling MT5 functions in MT4.
#define INDICATOR_LEGACY_VERSION_MT5
#define INDICATOR_LEGACY_VERSION_LONG // OHLC-based OnCalculate().
#define INDICATOR_LEGACY_VERSION_ACQUIRE_BUFFER \
ACQUIRE_BUFFER4(ExtUpperBuffer, ExtUpColorsBuffer, ExtLowerBuffer, \
ExtLoColorsBuffer)
#define INDICATOR_LEGACY_VERSION_RELEASE_BUFFER \
RELEASE_BUFFER4(ExtUpperBuffer, ExtUpColorsBuffer, ExtLowerBuffer, \
ExtLoColorsBuffer)
#include <EA31337-classes/IndicatorLegacy.h>

// Includes the main code.
#include "Gator.mq5"

Expand Down
4 changes: 1 addition & 3 deletions Oscillators/Gator.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,10 @@
// Resource files.
#ifdef __MQL5__
#property tester_indicator "::Indicators\\Examples\\Gator.ex5"
#ifdef __MQL5__
#property tester_indicator "::Indicators\\Examples\\Gator_2.ex5"
#endif
#endif
#resource "\\Indicators\\Examples\\Gator.ex5"
#resource "\\Indicators\\Examples\\Gator_2.ex5"
#endif

// Includes.
#include <EA31337-classes/Indicators/Indi_Gator.mqh>
Expand Down
11 changes: 11 additions & 0 deletions Oscillators/Gator.mt5.mq4
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,16 @@
#property version "1.000"
#endif

// This will allow calling MT5 functions in MT4.
#define INDICATOR_LEGACY_VERSION_MT5
#define INDICATOR_LEGACY_VERSION_LONG // OHLC-based OnCalculate().
#define INDICATOR_LEGACY_VERSION_ACQUIRE_BUFFER \
ACQUIRE_BUFFER4(ExtUpperBuffer, ExtUpColorsBuffer, ExtLowerBuffer, \
ExtLoColorsBuffer)
#define INDICATOR_LEGACY_VERSION_RELEASE_BUFFER \
RELEASE_BUFFER4(ExtUpperBuffer, ExtUpColorsBuffer, ExtLowerBuffer, \
ExtLoColorsBuffer)
#include <EA31337-classes/IndicatorLegacy.h>

// Includes MQL5 version of indicator.
#include <../Indicators\Examples\Gator.mq5>
7 changes: 7 additions & 0 deletions Oscillators/OsMA.mq4
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
#property version "1.000"
#endif

// This will allow calling MT5 functions in MT4.
#define INDICATOR_LEGACY_VERSION_MT5
#define INDICATOR_LEGACY_VERSION_LONG // OHLC-based OnCalculate().
#define INDICATOR_LEGACY_VERSION_ACQUIRE_BUFFER ACQUIRE_BUFFER1(ExtOsMABuffer)
#define INDICATOR_LEGACY_VERSION_RELEASE_BUFFER RELEASE_BUFFER1(ExtOsMABuffer)
#include <EA31337-classes/IndicatorLegacy.h>

// Includes the main code.
#include "OsMA.mq5"

Expand Down
7 changes: 7 additions & 0 deletions Oscillators/OsMA.mt5.mq4
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,12 @@
#property version "1.000"
#endif

// This will allow calling MT5 functions in MT4.
#define INDICATOR_LEGACY_VERSION_MT5
#define INDICATOR_LEGACY_VERSION_LONG // OHLC-based OnCalculate().
#define INDICATOR_LEGACY_VERSION_ACQUIRE_BUFFER ACQUIRE_BUFFER1(ExtOsMABuffer)
#define INDICATOR_LEGACY_VERSION_RELEASE_BUFFER RELEASE_BUFFER1(ExtOsMABuffer)
#include <EA31337-classes/IndicatorLegacy.h>

// Includes MQL5 version of indicator.
#include <../Indicators\Examples\OsMA.mq5>
7 changes: 7 additions & 0 deletions Oscillators/UOS.mq4
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
#property version "1.000"
#endif

// This will allow calling MT5 functions in MT4.
#define INDICATOR_LEGACY_VERSION_MT5
#define INDICATOR_LEGACY_VERSION_LONG // OHLC-based OnCalculate().
#define INDICATOR_LEGACY_VERSION_ACQUIRE_BUFFER ACQUIRE_BUFFER1(ExtBuffer)
#define INDICATOR_LEGACY_VERSION_RELEASE_BUFFER RELEASE_BUFFER1(ExtBuffer)
#include <EA31337-classes/IndicatorLegacy.h>

// Includes the main code.
#include "UOS.mq5"

Expand Down
11 changes: 11 additions & 0 deletions Oscillators/UOS.mt5.mq4
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,16 @@
#property version "1.000"
#endif

// This will allow calling MT5 functions in MT4.
#define INDICATOR_LEGACY_VERSION_MT5
#define INDICATOR_LEGACY_VERSION_LONG // OHLC-based OnCalculate().
#define INDICATOR_LEGACY_VERSION_ACQUIRE_BUFFER \
ACQUIRE_BUFFER5(ExtUOBuffer, ExtBPBuffer, ExtFastATRBuffer, \
ExtMiddleATRBuffer, ExtSlowATRBuffer)
#define INDICATOR_LEGACY_VERSION_RELEASE_BUFFER \
RELEASE_BUFFER5(ExtUOBuffer, ExtBPBuffer, ExtFastATRBuffer, \
ExtMiddleATRBuffer, ExtSlowATRBuffer)
#include <EA31337-classes/IndicatorLegacy.h>

// Includes MQL5 version of indicator.
#include <../Indicators\Examples\Ultimate_Oscillator.mq5>
10 changes: 9 additions & 1 deletion Oscillators/Volume/BWMFI.mt5.mq4
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@
#endif

// Includes EA31337 framework.
#include <EA31337-classes/Indicator.enum.h>
#include <EA31337-classes/DateTime.struct.h>
#include <EA31337-classes/Indicator/Indicator.enum.h>

datetime TimeTradeServer() { return DateTimeStatic::TimeTradeServer(); }

#define INDICATOR_LEGACY_VERSION_ACQUIRE_BUFFER \
ACQUIRE_BUFFER4(ExtMLBuffer, ExtTLBuffer, ExtBLBuffer, ExtStdDevBuffer)
#define INDICATOR_LEGACY_VERSION_RELEASE_BUFFER \
RELEASE_BUFFER4(ExtMLBuffer, ExtTLBuffer, ExtBLBuffer, ExtStdDevBuffer)

// Includes MQL5 version of indicator.
#include <../Indicators\Examples\MarketFacilitationIndex.mq5>
7 changes: 7 additions & 0 deletions Price/MA.mq4
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
#property version "1.000"
#endif

// This will allow calling MT5 functions in MT4.
#define INDICATOR_LEGACY_VERSION_MT5
#define INDICATOR_LEGACY_VERSION_LONG // OHLC-based OnCalculate().
#define INDICATOR_LEGACY_VERSION_ACQUIRE_BUFFER ACQUIRE_BUFFER1(ExtMABuffer)
#define INDICATOR_LEGACY_VERSION_RELEASE_BUFFER RELEASE_BUFFER1(ExtMABuffer)
#include <EA31337-classes/IndicatorLegacy.h>

// Includes the main code.
#include "MA.mq5"

Expand Down
7 changes: 7 additions & 0 deletions Price/MA.mt5.mq4
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,12 @@
#property version "1.000"
#endif

// This will allow calling MT5 functions in MT4.
#define INDICATOR_LEGACY_VERSION_MT5
#define INDICATOR_LEGACY_VERSION_SHORT // Non-OHLC OnCalculate().
#define INDICATOR_LEGACY_VERSION_ACQUIRE_BUFFER ACQUIRE_BUFFER1(ExtLineBuffer)
#define INDICATOR_LEGACY_VERSION_RELEASE_BUFFER RELEASE_BUFFER1(ExtLineBuffer)
#include <EA31337-classes/IndicatorLegacy.h>

// Includes MQL5 version of indicator.
#include <../Indicators\Examples\Custom Moving Average.mq5>
9 changes: 9 additions & 0 deletions Price/Multi/Alligator.mq4
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
#property version "1.000"
#endif

// This will allow calling MT5 functions in MT4.
#define INDICATOR_LEGACY_VERSION_MT5
#define INDICATOR_LEGACY_VERSION_LONG // OHLC-based OnCalculate().
#define INDICATOR_LEGACY_VERSION_ACQUIRE_BUFFER \
ACQUIRE_BUFFER3(ExtJaws, ExtTeeth, ExtLips)
#define INDICATOR_LEGACY_VERSION_RELEASE_BUFFER \
RELEASE_BUFFER3(ExtJaws, ExtTeeth, ExtLips)
#include <EA31337-classes/IndicatorLegacy.h>

// Includes the main code.
#include "Alligator.mq5"

Expand Down
9 changes: 9 additions & 0 deletions Price/Multi/Alligator.mt5.mq4
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
#property version "1.000"
#endif

// This will allow calling MT5 functions in MT4.
#define INDICATOR_LEGACY_VERSION_MT5
#define INDICATOR_LEGACY_VERSION_LONG // OHLC-based OnCalculate().
#define INDICATOR_LEGACY_VERSION_ACQUIRE_BUFFER \
ACQUIRE_BUFFER3(ExtJaws, ExtTeeth, ExtLips)
#define INDICATOR_LEGACY_VERSION_RELEASE_BUFFER \
RELEASE_BUFFER3(ExtJaws, ExtTeeth, ExtLips)
#include <EA31337-classes/IndicatorLegacy.h>

// Includes EA31337 framework.
#include <EA31337-classes/Indicators/Indi_MA.mqh>

Expand Down
9 changes: 9 additions & 0 deletions Price/Range/BB.mq4
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
#property version "1.000"
#endif

// This will allow calling MT5 functions in MT4.
#define INDICATOR_LEGACY_VERSION_MT5
#define INDICATOR_LEGACY_VERSION_LONG // OHLC-based OnCalculate().
#define INDICATOR_LEGACY_VERSION_ACQUIRE_BUFFER \
ACQUIRE_BUFFER4(ExtMLBuffer, ExtTLBuffer, ExtBLBuffer, ExtStdDevBuffer)
#define INDICATOR_LEGACY_VERSION_RELEASE_BUFFER \
RELEASE_BUFFER4(ExtMLBuffer, ExtTLBuffer, ExtBLBuffer, ExtStdDevBuffer)
#include <EA31337-classes/IndicatorLegacy.h>

// Includes the main code.
#include "BB.mq5"

Expand Down
9 changes: 9 additions & 0 deletions Price/Range/BB.mt5.mq4
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,14 @@
#property version "1.000"
#endif

// This will allow calling MT5 functions in MT4.
#define INDICATOR_LEGACY_VERSION_MT5
#define INDICATOR_LEGACY_VERSION_SHORT // Non-OHLC OnCalculate().
#define INDICATOR_LEGACY_VERSION_ACQUIRE_BUFFER \
ACQUIRE_BUFFER4(ExtMLBuffer, ExtTLBuffer, ExtBLBuffer, ExtStdDevBuffer)
#define INDICATOR_LEGACY_VERSION_RELEASE_BUFFER \
RELEASE_BUFFER4(ExtMLBuffer, ExtTLBuffer, ExtBLBuffer, ExtStdDevBuffer)
#include <EA31337-classes/IndicatorLegacy.h>

// Includes MQL5 version of indicator.
#include <../Indicators\Examples\BB.mq5>

0 comments on commit f8e8d1e

Please sign in to comment.