Skip to content

Commit

Permalink
Merge tag 'v2.011' into v3.002-dev-new
Browse files Browse the repository at this point in the history
* tag 'v2.011': (32 commits)
  Fixes timeframe handling
  Indicators: Adds Indicator source type and mode to constructor's argument.
  Moves indicator data related methods to IndicatorData
  Indicator: Moves GetValuePrice() to IndicatorData
  Splits IndicatorParams struct into IndicatorDataParams
  Refactors IndicatorData class to be inherited by Indicator class
  Refs #337 New week detection. Added check if it's the first day of the week (which is Monday in MQL). Previously we only checked if current day of the week has changed.
  CPP: Removes EnumToString
  Should fix new issues with C++ compatibility.
  Should fix all GCC warnings.
  Working compilation via GCC for TradeSignal.test.cpp and TradeSignalManager.test.cpp.
  State in the art of MQL/C++ compatibility.
  Making MQL code to compile in C++. Especially the TradeSignalManager.test.cpp.
  Trade: Fixes C++ compilation errors
  Adds TradeSignal and TradeSignalManager C++ compilation tests
  GHA: Compiles based on the file list
  Adds Compile workflow for CPP
  Adds StringSplit() as extern
  Adds .extern.h file for DateTime
  Refs: Uses PTR_ATTRIB syntax
  ...
  • Loading branch information
kenorb committed Apr 24, 2024
2 parents 761b3d7 + 78a0fbd commit 42d1880
Show file tree
Hide file tree
Showing 184 changed files with 4,847 additions and 3,525 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/compile-cpp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
name: Compile C++

# yamllint disable-line rule:truthy
on:
pull_request:
paths-ignore:
- '**.md'
push:
paths-ignore:
- '**.md'

jobs:

FileList:
outputs:
filelist: ${{ steps.get-files.outputs.filelist }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set output with list of files
id: get-files
run: |
import glob, json, os
files = glob.glob("**/tests/*.cpp")
print("::set-output name=filelist::{}".format(json.dumps(files)))
shell: python
- name: Display output
run: echo ${{ steps.get-files.outputs.filelist }}

Compile:
runs-on: ubuntu-latest
needs: [FileList]
strategy:
matrix:
file: ${{ fromJson(needs.FileList.outputs.filelist) }}
steps:
- uses: actions/checkout@v2
- name: Install compiler
uses: rlalik/[email protected]
with:
compiler: gcc-latest
- name: Compile ${{ matrix.file }}
run: g++ "${{ matrix.file }}"
62 changes: 62 additions & 0 deletions .github/workflows/test-exchange.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
name: Test Exchange

# yamllint disable-line rule:truthy
on:
pull_request:
paths:
- 'Exchange/**.h'
- 'Exchange/**.mq?'
- '.github/workflows/test-exchange.yml'
push:
paths:
- 'Exchange/**.h'
- 'Exchange/**.mq?'
- '.github/workflows/test-exchange.yml'

jobs:

Compile:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Compile
uses: fx31337/mql-compile-action@master
with:
init-platform: true
path: 'Exchange/tests'
verbose: true
- name: Print compiled files
run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname'
shell: powershell
- name: Upload artifacts (MQL4)
uses: actions/upload-artifact@v2
with:
name: files-ex4
path: '**/*.ex4'
- name: Upload artifacts (MQL5)
uses: actions/upload-artifact@v2
with:
name: files-ex5
path: '**/*.ex5'

Exchange-Tests-MQL4:
defaults:
run:
shell: bash
working-directory: Exchange/tests
needs: Compile
runs-on: ubuntu-latest
strategy:
matrix:
test:
- Exchange.test
steps:
- uses: actions/download-artifact@v2
with:
name: files-ex4
- name: Run ${{ matrix.test }}
uses: fx31337/mql-tester-action@master
with:
Script: ${{ matrix.test }}
timeout-minutes: 10
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- CompileIndicatorsTest
- ConditionTest
- DatabaseTest
- DrawIndicatorTest
# - DrawIndicatorTest
- EATest
- IndicatorDataTest
- IndicatorTest
Expand Down
6 changes: 6 additions & 0 deletions Account.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Account;
// Includes.
#include "Account/Account.define.h"
#include "Account/Account.enum.h"
#include "Account/Account.extern.h"
#include "Account/Account.struct.h"
#include "Array.mqh"
#include "BufferStruct.mqh"
Expand Down Expand Up @@ -63,6 +64,11 @@ class Account {
*/
Account() : init_balance(CalcInitDeposit()), start_balance(GetBalance()), start_credit(GetCredit()) {}

/**
* Class copy constructor.
*/
Account(const Account &_account) {}

/**
* Class deconstructor.
*/
Expand Down
29 changes: 29 additions & 0 deletions Account/Account.extern.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2022, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

/*
* This file is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

// Includes.
#include "Account.enum.h"

// Define external global functions.
#ifndef __MQL__
extern string AccountInfoString(ENUM_ACCOUNT_INFO_STRING property_id);
#endif
1 change: 1 addition & 0 deletions Account/Account.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Serializer;

// Includes.
#include "../Serializer.mqh"
#include "../Terminal.define.h"

// Struct for account entries.
struct AccountEntry {
Expand Down
1 change: 1 addition & 0 deletions Account/AccountBase.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Serializer;

// Includes.
#include "../Serializer.mqh"
#include "../Terminal.define.h"

// Struct for account entries.
struct AccountBaseEntry {
Expand Down
1 change: 1 addition & 0 deletions Account/AccountForex.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Serializer;

// Includes.
#include "../Serializer.mqh"
#include "../Terminal.define.h"

// Struct for account entries.
struct AccountForexEntry : public AccountBaseEntry {
Expand Down
2 changes: 1 addition & 1 deletion Account/tests/Account.test.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int OnInit() {
bool _result = true;
Account<AccountBaseState, AccountBaseEntry> acc1;
// ...
return _result && GetLastError() == ERR_NO_ERROR ? INIT_SUCCEEDED : INIT_FAILED;
return _result && GetLastError() == 0 ? INIT_SUCCEEDED : INIT_FAILED;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Account/tests/AccountForex.test.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int OnInit() {
bool _result = true;
Account<AccountForexState, AccountForexEntry> acc1;
// ...
return _result && GetLastError() == ERR_NO_ERROR ? INIT_SUCCEEDED : INIT_FAILED;
return _result && GetLastError() == 0 ? INIT_SUCCEEDED : INIT_FAILED;
}

/**
Expand Down
57 changes: 57 additions & 0 deletions Array.extern.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2022, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

/*
* This file is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

// Define external global functions.
#ifndef __MQL__
#pragma once

template <typename T>
extern int ArraySize(const ARRAY_REF(T, _array));

template <typename T, int size>
extern constexpr int ArraySize(const T REF(_array)[size]);

template <typename T>
extern int ArrayResize(ARRAY_REF(T, _array), int _new_size, int _reserve_size = 0);

template <typename T>
extern bool ArraySetAsSeries(ARRAY_REF(T, _array), bool _flag);

template <typename T>
extern int ArrayMaximum(const ARRAY_REF(T, _array), int _start = 0, unsigned int _count = WHOLE_ARRAY);

template <typename T>
extern int ArrayMinimum(const ARRAY_REF(T, _array), int _start = 0, unsigned int _count = WHOLE_ARRAY);

template <typename T>
extern int ArrayFree(const ARRAY_REF(T, _array));

template <typename T>
extern int ArrayReverse(const ARRAY_REF(T, _array));

template <typename T>
extern int ArrayInitialize(ARRAY_REF(T, array), char value);

template <typename T>
extern int ArraySort(ARRAY_REF(T, array));

#endif
11 changes: 8 additions & 3 deletions Array.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@
#endif

// Includes.
#include "Array.extern.h"
#include "Common.extern.h"
#include "Convert.extern.h"
#include "Math.extern.h"
#include "Std.h"
#include "String.extern.h"

// Defines.
#ifndef MODE_ASCEND
Expand Down Expand Up @@ -529,7 +534,7 @@ static int GetLowestArrDoubleValue(double& arr[][], int key) {
*/
template <typename T>
void ArrayPrint(ARRAY_REF(T, _arr), // Printed array.
int _digits = NULL, // Number of decimal places.
int _digits = 0, // Number of decimal places.
const string _dlm = NULL, // Separator of the structure field values.
long _start = 0, // First printed element index.
long _count = WHOLE_ARRAY, // Number of printed elements.
Expand All @@ -539,7 +544,7 @@ static int GetLowestArrDoubleValue(double& arr[][], int key) {
#else
int i;
string output = "";
for (i = _start; i < _count == WHOLE_ARRAY ? ArraySize(_arr) : _count; i++) {
for (i = _start; i < (_count == WHOLE_ARRAY ? ArraySize(_arr) : _count); i++) {
output += (string)_arr[i] + _dlm;
}
Print(output);
Expand Down Expand Up @@ -635,7 +640,7 @@ static int GetLowestArrDoubleValue(double& arr[][], int key) {
* if error occured).
*/
template <typename X, typename Y>
static int ArrayResizeFill(ARRAY_REF(X, array), int new_size, int reserve_size = 0, Y fill_value = EMPTY_VALUE) {
static int ArrayResizeFill(ARRAY_REF(X, array), int new_size, int reserve_size = 0, Y fill_value = NULL) {
const int old_size = ArrayRange(array, 0);

if (new_size <= old_size) return old_size;
Expand Down
1 change: 1 addition & 0 deletions Chart.struct.tf.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
// Includes.
#include "Chart.enum.h"
#include "Serializer.mqh"
#include "Terminal.define.h"

/* Defines struct for chart timeframe. */
struct ChartTf {
Expand Down
35 changes: 35 additions & 0 deletions Common.define.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2022, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

/*
* This file is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

/**
* @file
* Defines common defines.
*/
#ifndef __MQL__
// Data types.
#include <string>
typedef std::string string;
typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned short ushort;
#endif
47 changes: 47 additions & 0 deletions Common.extern.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2022, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

/*
* This file is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

// Define external global functions.
#ifndef __MQL__
#pragma once
#include "Chart.enum.h"
#include "DateTime.enum.h"

extern void DebugBreak();
// Errors.
extern void SetUserError(ushort user_error);
// Exceptions.
extern int NotImplementedException();
// Print-related functions.
template <typename... Args>
extern std::string StringFormat(const std::string& format, Args... args);

template <typename... Args>
extern std::string PrintFormat(const std::string& format, Args... args);

template <typename... Args>
extern void Print(Args... args);

template <typename... Args>
extern void Alert(Args... args);

#endif
Loading

0 comments on commit 42d1880

Please sign in to comment.