Skip to content

Commit

Permalink
Merge tag 'v2.006' into dev-indis
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed Sep 19, 2021
2 parents f288f28 + fc809c6 commit ba5cd57
Show file tree
Hide file tree
Showing 56 changed files with 2,209 additions and 925 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ jobs:
test:
- AccountTest
- ActionTest
- BufferStructTest
- BufferTest
- ChartTest
- ConditionTest
- DatabaseTest
- DrawIndicatorTest
Expand All @@ -71,6 +73,7 @@ jobs:
- StatsTest
- StrategyTest
- StrategyTest-RSI
- SymbolInfoTest
- SummaryReportTest
- TaskTest
- TickerTest
Expand All @@ -87,6 +90,29 @@ jobs:
BtYears: 2020
TestExpert: ${{ matrix.test }}

Indicators-MQL4:
defaults:
run:
shell: bash
working-directory: Indicators/tests
needs: Compile
runs-on: ubuntu-latest
strategy:
matrix:
test:
- Indi_Pivot.test
steps:
- uses: actions/download-artifact@v2
with:
name: files-ex4
- name: Run ${{ matrix.test }}
uses: fx31337/mql-tester-action@master
with:
BtDays: 4-8
BtMonths: 1
BtYears: 2020
TestExpert: ${{ matrix.test }}

Scripts-MQL4:
defaults:
run:
Expand All @@ -106,6 +132,7 @@ jobs:
- LogTest
- MD5Test
- MathTest
- OrderQuery
- ProfilerTest
- RefsTest
- SerializerTest
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
build.properties
logs/

# Doxygen's and Sphinx's output.
docs/api/build

# Ignores compiled binary files.
*.ex?

Expand Down
20 changes: 12 additions & 8 deletions Account.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -559,21 +559,25 @@ class Account {
case ACCOUNT_COND_BAL_IN_PROFIT:
return GetBalance() > start_balance;
case ACCOUNT_COND_EQUITY_01PC_HIGH:
return AccountEquity() > (AccountBalance() + AccountCredit()) / 100 * 101;
return AccountEquity() > (GetTotalBalance()) / 100 * 101;
case ACCOUNT_COND_EQUITY_01PC_LOW:
return AccountEquity() < (AccountBalance() + AccountCredit()) / 100 * 99;
return AccountEquity() < (GetTotalBalance()) / 100 * 99;
case ACCOUNT_COND_EQUITY_02PC_HIGH:
return AccountEquity() > (GetTotalBalance()) / 100 * 102;
case ACCOUNT_COND_EQUITY_02PC_LOW:
return AccountEquity() < (GetTotalBalance()) / 100 * 98;
case ACCOUNT_COND_EQUITY_05PC_HIGH:
return AccountEquity() > (AccountBalance() + AccountCredit()) / 100 * 105;
return AccountEquity() > (GetTotalBalance()) / 100 * 105;
case ACCOUNT_COND_EQUITY_05PC_LOW:
return AccountEquity() < (AccountBalance() + AccountCredit()) / 100 * 95;
return AccountEquity() < (GetTotalBalance()) / 100 * 95;
case ACCOUNT_COND_EQUITY_10PC_HIGH:
return AccountEquity() > (AccountBalance() + AccountCredit()) / 100 * 110;
return AccountEquity() > (GetTotalBalance()) / 100 * 110;
case ACCOUNT_COND_EQUITY_10PC_LOW:
return AccountEquity() < (AccountBalance() + AccountCredit()) / 100 * 90;
return AccountEquity() < (GetTotalBalance()) / 100 * 90;
case ACCOUNT_COND_EQUITY_20PC_HIGH:
return AccountEquity() > (AccountBalance() + AccountCredit()) / 100 * 120;
return AccountEquity() > (GetTotalBalance()) / 100 * 120;
case ACCOUNT_COND_EQUITY_20PC_LOW:
return AccountEquity() < (AccountBalance() + AccountCredit()) / 100 * 80;
return AccountEquity() < (GetTotalBalance()) / 100 * 80;
case ACCOUNT_COND_EQUITY_IN_LOSS:
return GetEquity() < GetTotalBalance();
case ACCOUNT_COND_EQUITY_IN_PROFIT:
Expand Down
292 changes: 292 additions & 0 deletions BufferFXT.mqh
Original file line number Diff line number Diff line change
@@ -0,0 +1,292 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2020, 31337 Investments 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/>.
*/

// Prevents processing this includes file for the second time.
#ifndef BUFFER_FXT_MQH
#define BUFFER_FXT_MQH

// Includes.
#include "Account.mqh"
#include "Chart.mqh"
#include "DictStruct.mqh"
#include "Object.mqh"

// Defines.
#define FXT_VERSION 405
// Profit calculation mode.
#define PROFIT_CALC_FOREX 0 // Default.
#define PROFIT_CALC_CFD 1
#define PROFIT_CALC_FUTURES 2
// Type of swap.
#define SWAP_BY_POINTS 0 // Default.
#define SWAP_BY_BASECURRENCY 1
#define SWAP_BY_INTEREST 2
#define SWAP_BY_MARGINCURRENCY 3
// Free margin calculation mode.
#define MARGIN_DONT_USE 0
#define MARGIN_USE_ALL 1 // Default.
#define MARGIN_USE_PROFIT 2
#define MARGIN_USE_LOSS 3
// Margin calculation mode.
#define MARGIN_CALC_FOREX 0 // Default.
#define MARGIN_CALC_CFD 1
#define MARGIN_CALC_FUTURES 2
#define MARGIN_CALC_CFDINDEX 3
// Check mode for Stop Out level (AccountStopoutMode).
#define MARGIN_TYPE_PERCENT 0
#define MARGIN_TYPE_CURRENCY 1
// Basic commission type.
#define COMM_TYPE_MONEY 0
#define COMM_TYPE_PIPS 1
#define COMM_TYPE_PERCENT 2
// Commission per lot or per deal.
#define COMMISSION_PER_LOT 0
#define COMMISSION_PER_DEAL 1

// Structs.
struct BufferFXTEntry {
datetime otm; // Bar datetime.
double open; // OHLCV values.
double high;
double low;
double close;
long volume;
int ctm; // The current time within a bar.
int flag; // Flag to launch an expert (0 - bar will be modified, but the expert will not be launched).

public:
bool operator==(const BufferFXTEntry &_s) {
// @fixme
return false;
}
string ToJSON() {
// @fixme
return "{}";
}
};

// FXT file header.
struct BufferFXTHeader {
int version; // Header version: 405
char copyright[64]; // Copyright/description.
char description[128]; // Account server name.
// 196
char symbol[12]; // Symbol pair.
int period; // Period of data aggregation in minutes (timeframe).
int model; // Model type: 0 - every tick, 1 - control points, 2 - bar open.
int bars; // Bars - number of modeled bars in history.
int fromdate; // Modelling start date - date of the first tick.
int todate; // Modelling end date - date of the last tick.
int totalTicks; // Total ticks. Add 4 bytes to align to the next double?
double modelquality; // Modeling quality (max. 99.9).
// 240
// Market symbol properties.
char currency[12]; // Base currency (12 bytes). Same as: StringLeft(symbol, 3)
int spread; // Spread in points. Same as: MarketInfo(MODE_SPREAD)
int digits; // Digits (default: 5). Same as: MarketInfo(MODE_DIGITS)
int padding1; // Padding space - add 4 bytes to align to the next double.
double point; // Point size (e.g. 0.00001). Same as: MarketInfo(MODE_POINT)
int lot_min; // Minimal lot size in centi lots (hundredths). Same as: MarketInfo(MODE_MINLOT)*100
int lot_max; // Maximal lot size in centi lots (hundredths). Same as: MarketInfo(MODE_MAXLOT)*100
int lot_step; // Lot step in centi lots (hundredths). Same as: MarketInfo(MODE_LOTSTEP)*100
int stops_level; // Stops level value (orders stop distance in points). Same as: MarketInfo(MODE_STOPLEVEL)
int gtc_pendings; // GTC (Good till cancel) - instruction to close pending orders at end of day (default: False).
int padding2; // Padding space - add 4 bytes to align to the next double.
// 296
// Profit calculation parameters.
double contract_size; // Contract size (e.g. 100000). Same as: MarketInfo(MODE_LOTSIZE)
double tick_value; // Tick value in quote currency (empty). Same as: MarketInfo(MODE_TICKVALUE)
double tick_size; // Size of one tick (empty). Same as: MarketInfo(MODE_TICKSIZE)
int profit_mode; // Profit calculation mode { PROFIT_CALC_FOREX=0, PROFIT_CALC_CFD=1, PROFIT_CALC_FUTURES=2 }. Same
// as: MarketInfo(MODE_PROFITCALCMODE)
// 324
// Swap calculation.
int swap_enable; // Enable swaps (default: True).
int swap_type; // Type of swap { SWAP_BY_POINTS=0, SWAP_BY_BASECURRENCY=1, SWAP_BY_INTEREST=2,
// SWAP_BY_MARGINCURRENCY=3 }. Same as: MarketInfo(MODE_SWAPTYPE)
int padding3; // Padding space - add 4 bytes to align to the next double.
double swap_long; // Swap of the buy order - long overnight swap value. Same as: MarketInfo(MODE_SWAPLONG)
double swap_short; // Swap of the sell order - short overnight swap value. Same as: MarketInfo(MODE_SWAPSHORT)
int swap_rollover3days; // Day of week to charge 3 days swap rollover. Default: WEDNESDAY (3). Same as:
// MarketInfo(SYMBOL_SWAP_ROLLOVER3DAYS)
// 356
// Margin calculation.
int leverage; // Account leverage (default: 100). Same as: AccountLeverage()
int free_margin_mode; // Free margin calculation mode { MARGIN_DONT_USE=0, MARGIN_USE_ALL=1, MARGIN_USE_PROFIT=2,
// MARGIN_USE_LOSS=3 }. Same as: AccountFreeMarginMode()
int margin_mode; // Margin calculation mode { MARGIN_CALC_FOREX=0, MARGIN_CALC_CFD=1, MARGIN_CALC_FUTURES=2,
// MARGIN_CALC_CFDINDEX=3 }. Same as: MarketInfo(MODE_MARGINCALCMODE)
int margin_stopout; // Margin Stop Out level (default: 30). Same as: AccountStopoutLevel()

int margin_stopout_mode; // Check mode for Stop Out level { MARGIN_TYPE_PERCENT=0, MARGIN_TYPE_CURRENCY=1 }. Same as:
// AccountStopoutMode()
double margin_initial; // Initial margin requirement (in units). Same as: MarketInfo(MODE_MARGININIT)
double margin_maintenance; // Maintenance margin requirement (in units). Same as: MarketInfo(MODE_MARGINMAINTENANCE)
double margin_hedged; // Hedged margin requirement for positions (in units). Same as: MarketInfo(MODE_MARGINHEDGED)
double margin_divider; // Margin divider used for leverage calculation.
char margin_currency[12]; // Margin currency. Same as: AccountCurrency().
int padding4; // Padding space - add 4 bytes to align to the next double.
// 424
// Commission calculation.
double comm_base; // Basic commission rate.
int comm_type; // Basic commission type { COMM_TYPE_MONEY=0, COMM_TYPE_PIPS=1, COMM_TYPE_PERCENT=2 }.
int comm_lots; // Commission per lot or per deal { COMMISSION_PER_LOT=0, COMMISSION_PER_DEAL=1 }
// 440
// For internal use.
int from_bar; // Index of the first bar at which modeling started (0 for the first bar).
int to_bar; // Index of the last bar at which modeling started (0 for the last bar).
int start_period_m1; // Bar index where modeling started using M1 bars (0 for the first bar).
int start_period_m5; // Bar index where modeling started using M5 bars (0 for the first bar).
int start_period_m15; // Bar index where modeling started using M15 bars (0 for the first bar).
int start_period_m30; // Bar index where modeling started using M30 bars (0 for the first bar).
int start_period_h1; // Bar index where modeling started using H1 bars (0 for the first bar).
int start_period_h4; // Bar index where modeling started using H4 bars (0 for the first bar).
int set_from; // Begin date from tester settings (must be zero).
int set_to; // End date from tester settings (must be zero).
// 480
//----
int freeze_level; // Order freeze level in points. Same as: MarketInfo(MODE_FREEZELEVEL)
int generating_errors; // Number of errors during model generation which needs to be fixed before testing.
// 488
//----
int reserved[60]; // Reserved - space for future use.
// Struct constructor.
BufferFXTHeader(Chart *_c, Account *_a)
: version(405),
period(_c.Get<ENUM_TIMEFRAMES>(CHART_PARAM_TF)),
model(0),
bars(0),
fromdate(0),
todate(0),
totalTicks(0),
modelquality(0),
spread((int)_c.GetSpread()),
digits((int)_c.GetDigits()),
point(_c.GetPointSize()),
lot_min(int(_c.GetVolumeMin() * 100)),
lot_max(int(_c.GetVolumeMax() * 100)),
lot_step(int(_c.GetVolumeStep() * 100)),
stops_level(0), // @todo: Add MODE_STOPLEVEL to Account.
gtc_pendings(false),
contract_size(10000),
tick_value(_c.GetTickValue()),
tick_size(_c.GetTickSize()),
profit_mode(PROFIT_CALC_FOREX),
swap_enable(true),
swap_type(SWAP_BY_POINTS), // @todo: Add _c.GetSwapType() to SymbolInfo.
swap_long(_c.GetSwapLong()),
swap_short(_c.GetSwapShort()),
swap_rollover3days(3),
leverage((int)_a.GetLeverage()),
free_margin_mode(MARGIN_DONT_USE),
margin_mode(MARGIN_CALC_FOREX),
margin_stopout(30), // @fixme: _a.GetStopoutLevel() based on ACCOUNT_MARGIN_SO_CALL.
margin_stopout_mode(_a.GetStopoutMode()),
margin_initial(_c.GetMarginInit()),
margin_maintenance(_c.GetMarginMaintenance()),
margin_hedged(0),
margin_divider(0),
comm_base(0.0),
comm_type(COMM_TYPE_MONEY),
comm_lots(COMMISSION_PER_LOT),
from_bar(0),
to_bar(0),
start_period_m1(0),
start_period_m5(0),
start_period_m15(0),
start_period_m30(0),
start_period_h1(0),
start_period_h4(0),
set_from(0),
set_to(0),
freeze_level((int)_c.GetFreezeLevel()),
generating_errors(0) {
ArrayInitialize(copyright, 0);
// currency = StringSubstr(_m.GetSymbol(), 0, 3); // @fixme
ArrayInitialize(description, 0);
ArrayInitialize(margin_currency, 0);
ArrayInitialize(reserved, 0);
// symbol = _m.GetSymbol(); // @fixme
}
};

struct BufferFXTParams {
Account *account;
Chart *chart;
// Struct constructor.
void BufferFXTParams(Chart *_chart = NULL, Account *_account = NULL)
: account(Object::IsValid(_account) ? _account : new Account),
chart(Object::IsValid(_chart) ? _chart : new Chart) {}
// Struct deconstructor.
void ~BufferFXTParams() {
delete account;
delete chart;
}
};

string ToJSON(BufferFXTEntry &_value, const bool, const unsigned int) { return _value.ToJSON(); };

/**
* Implements class to store tick data.
*/
class BufferFXT : public DictStruct<long, BufferFXTEntry> {
protected:
BufferFXTParams params;

public:
/**
* Class constructor.
*/
BufferFXT() {}
BufferFXT(const BufferFXTParams &_params) { params = _params; }

/**
* Class deconstructor.
*/
~BufferFXT() {}

/**
* Adds new entry.
*/
void Add(BufferFXTEntry &_value, long _dt = 0) {
_dt = _dt > 0 ? _dt : TimeCurrent();
Set(_dt, _value);
}

/**
* Adds new entry.
*/
void Add(MqlTick &_value) {
// @todo: Parse MqlTick.
// Set(_dt, _value);
}

/**
* Save data into file.
*/
void SaveToFile() {
BufferFXTHeader header(params.chart, params.account);
// @todo: Save BufferFXTHeader, then foreach BufferFXTEntry.
// @see: https://docs.mql4.com/files/filewritestruct
}
};

#endif // BUFFER_FXT_MQH
Loading

0 comments on commit ba5cd57

Please sign in to comment.