Add standard file headers to custom library files

This commit is contained in:
Matt Corcoran
2025-07-16 12:31:55 +02:00
parent d7f4813dab
commit 77481b97ed
21 changed files with 240 additions and 132 deletions
+10 -15
View File
@@ -1,25 +1,20 @@
//+------------------------------------------------------------------+
//| CustomeMax.mqh |
//| Defines custom optimization criteria for backtesting |
//| |
//| 2025 xMattC (github.com/xMattC) |
//+------------------------------------------------------------------+
#property copyright "2025 xMattC (github.com/xMattC)"
#property link "https://github.com/xMattC"
#property version "1.00"
#include <Trade/Trade.mqh>
// ---------------------------------------------------------------------
// ENUM: CUSTOM_MAX_TYPE
// ---------------------------------------------------------------------
// Defines the types of custom performance criteria that can be used
// for calculating max optimization targets.
//
// Values:
// - CM_WIN_LOSS_RATIO : Use win/loss ratio.
// - CM_WIN_PERCENT : Use win percentage.
// ---------------------------------------------------------------------
enum CUSTOM_MAX_TYPE {
CM_WIN_LOSS_RATIO,
CM_WIN_PERCENT
};
// ---------------------------------------------------------------------
// CLASS: CustomMax
// ---------------------------------------------------------------------
// Calculates custom performance criteria for use in optimizations.
// ---------------------------------------------------------------------
class CustomMax : public CObject {
protected:
double custom_criteria;
+17 -27
View File
@@ -1,33 +1,23 @@
// ---------------------------------------------------------------------
// ENUM: MODE_SPLIT_DATA
// ---------------------------------------------------------------------
// Defines how to split data during testing based on time attributes.
//
// Values:
// - NO_SPLIT : Do not split, always return true.
// - ODD_YEARS : Include only odd-numbered years.
// - EVEN_YEARS : Include only even-numbered years.
// - ODD_MONTHS : Include only odd-numbered months.
// - EVEN_MONTHS : Include only even-numbered months.
// - ODD_WEEKS : Include only odd-numbered weeks.
// - EVEN_WEEKS : Include only even-numbered weeks.
// ---------------------------------------------------------------------
//+------------------------------------------------------------------+
//| TestDataSplit.mqh |
//| Splits historical data into training/testing segments |
//| |
//| 2025 xMattC (github.com/xMattC) |
//+------------------------------------------------------------------+
#property copyright "2025 xMattC (github.com/xMattC)"
#property link "https://github.com/xMattC"
#property version "1.00"
enum MODE_SPLIT_DATA {
NO_SPLIT,
ODD_YEARS,
EVEN_YEARS,
ODD_MONTHS,
EVEN_MONTHS,
ODD_WEEKS,
EVEN_WEEKS
NO_SPLIT, // Do not split, always return true.
ODD_YEARS, // Include only odd-numbered years.
EVEN_YEARS, // Include only even-numbered years.
ODD_MONTHS, // Include only odd-numbered months.
EVEN_MONTHS, // Include only even-numbered months.
ODD_WEEKS, // Include only odd-numbered weeks.
EVEN_WEEKS // Include only even-numbered weeks.
};
// ---------------------------------------------------------------------
// CLASS: TestDataSplit
// ---------------------------------------------------------------------
// Provides logic to determine whether the current date falls within
// a selected split group for testing or optimization purposes.
// ---------------------------------------------------------------------
class TestDataSplit {
public:
bool in_test_period(MODE_SPLIT_DATA data_split_method);
+10 -6
View File
@@ -1,3 +1,13 @@
//+------------------------------------------------------------------+
//| AdjustPosition.mqh |
//| Manages stop loss adjustments, trailing stops, and breakevens |
//| |
//| 2025 xMattC (github.com/xMattC) |
//+------------------------------------------------------------------+
#property copyright "2025 xMattC (github.com/xMattC)"
#property link "https://github.com/xMattC"
#property version "1.00"
#include <Trade/Trade.mqh>
#include <MyLibs/utils/AtrHandleManager.mqh>
@@ -7,12 +17,6 @@
CTrade trade;
AtrHandleManager atr_manager;
// ---------------------------------------------------------------------
// CLASS: AdjustPosition
// ---------------------------------------------------------------------
// Provides methods to manage stop-loss logic for runner trades.
// Includes breakeven, trailing stop (fixed and ATR), and virtual TP SLs.
// ---------------------------------------------------------------------
class AdjustPosition {
public:
void set_breakeven_sl(string symbol, int runner_magic_no, double buffer_points = 5);
+11 -6
View File
@@ -1,14 +1,19 @@
//+------------------------------------------------------------------+
//| CalculatePositionData.mqh |
//| Provides core logic for computing stop loss, take profit, lot |
//| size, and trading costs based on symbol, price, and risk |
//| |
//| 2025 xMattC (github.com/xMattC) |
//+------------------------------------------------------------------+
#property copyright "2025 xMattC (github.com/xMattC)"
#property link "https://github.com/xMattC"
#property version "1.00"
#include <MyLibs/Utils/MarketDataUtils.mqh>
#include <MyLibs/Utils/TimeZones.mqh>
#include <MyLibs/Utils/AtrHandleManager.mqh>
#include <Trade/Trade.mqh>
// ---------------------------------------------------------------------
// CLASS: CalculatePositionData
// ---------------------------------------------------------------------
// Provides core logic for computing stop loss, take profit, lot size,
// and trading costs based on symbol, price, and risk parameters.
// ---------------------------------------------------------------------
class CalculatePositionData : public CObject {
protected:
CTrade trade;
+19 -31
View File
@@ -1,13 +1,25 @@
//+------------------------------------------------------------------+
//| EntryOrders.mqh |
//| Handles logic for opening buy/sell orders |
//| |
//| 2025 xMattC (github.com/xMattC) |
//+------------------------------------------------------------------+
#property copyright "2025 xMattC (github.com/xMattC)"
#property link "https://github.com/xMattC"
#property version "1.00"
#include <MyLibs/Orders/CalculatePositionData.mqh>
#include <MyLibs/Orders/OrderTracker.mqh>
#include <Trade/Trade.mqh>
class EntryOrders {
protected:
CTrade trade;
CalculatePositionData calc;
OrderTracker track;
public:
int count_open_positions(string symbol, int order_side, long _magic_number);
bool open_buy_orders(string symbol, bool condition, ENUM_TIMEFRAMES atr_period, string _sl_mode, double sl_var, string _tp_mode,
double tp_var, string _lot_mode, double lot_var, long _magic_number);
@@ -30,30 +42,6 @@ public:
string _tp_mode, double tp_var, string _lot_mode, double lot_var, long _magic_number);
};
// ---------------------------------------------------------------------
// Counts open positions by symbol, side, and magic number.
//
// Parameters:
// - symbol : Symbol to check.
// - order_side : 1 = Buy, 2 = Sell, 0 = Any.
// - _magic_number : Magic number to filter.
//
// Returns:
// - Number of matching open positions.
// ---------------------------------------------------------------------
int EntryOrders::count_open_positions(string symbol, int order_side, long _magic_number) {
int count = 0;
for (int i = PositionsTotal() - 1; i >= 0; i--) {
ulong ticket = PositionGetTicket(i);
if (PositionGetString(POSITION_SYMBOL) == symbol && PositionGetInteger(POSITION_MAGIC) == _magic_number) {
int type = (int) PositionGetInteger(POSITION_TYPE);
if (order_side == 0 || (order_side == 1 && type == POSITION_TYPE_BUY) || (order_side == 2 && type == POSITION_TYPE_SELL)) {
count++;
}
}
}
return count;
}
// ---------------------------------------------------------------------
// Opens a market BUY position.
@@ -77,7 +65,7 @@ bool EntryOrders::open_buy_orders(string symbol, bool condition, ENUM_TIMEFRAMES
string _tp_mode, double tp_var, string _lot_mode, double lot_var, long _magic_number) {
if (!condition) return false;
double current_price = SymbolInfoDouble(symbol, SYMBOL_ASK);
if (count_open_positions(symbol, 1, _magic_number) > 0) return false;
if (track.count_open_positions(symbol, 1, _magic_number) > 0) return false;
double stop_loss = calc.calculate_stoploss(symbol, current_price, 1, _sl_mode, sl_var, atr_period);
double take_profit = calc.calculate_take_profit(symbol, current_price, stop_loss, 1, _tp_mode, tp_var, atr_period);
@@ -118,7 +106,7 @@ bool EntryOrders::open_sell_orders(string symbol, bool condition, ENUM_TIMEFRAME
string _tp_mode, double tp_var, string _lot_mode, double lot_var, long _magic_number) {
if (!condition) return false;
double current_price = SymbolInfoDouble(symbol, SYMBOL_BID);
if (count_open_positions(symbol, 2, _magic_number) > 0) return false;
if (track.count_open_positions(symbol, 2, _magic_number) > 0) return false;
double stop_loss = calc.calculate_stoploss(symbol, current_price, 2, _sl_mode, sl_var, atr_period);
double take_profit = calc.calculate_take_profit(symbol, current_price, stop_loss, 2, _tp_mode, tp_var, atr_period);
@@ -161,7 +149,7 @@ bool EntryOrders::open_buy_stop_order(string symbol, bool condition, double entr
string _sl_mode, double sl_var, string _tp_mode, double tp_var, string _lot_mode, double lot_var,
long _magic_number) {
if (!condition) return false;
if (count_open_positions(symbol, 1, _magic_number) > 0) return false;
if (track.count_open_positions(symbol, 1, _magic_number) > 0) return false;
double stop_loss = calc.calculate_stoploss(symbol, entry_price, 1, _sl_mode, sl_var, atr_period);
double take_profit = calc.calculate_take_profit(symbol, entry_price, stop_loss, 1, _tp_mode, tp_var, atr_period);
@@ -204,7 +192,7 @@ bool EntryOrders::open_sell_stop_order(string symbol, bool condition, double ent
string _sl_mode, double sl_var, string _tp_mode, double tp_var, string _lot_mode, double lot_var,
long _magic_number) {
if (!condition) return false;
if (count_open_positions(symbol, 2, _magic_number) > 0) return false;
if (track.count_open_positions(symbol, 2, _magic_number) > 0) return false;
double stop_loss = calc.calculate_stoploss(symbol, entry_price, 2, _sl_mode, sl_var, atr_period);
double take_profit = calc.calculate_take_profit(symbol, entry_price, stop_loss, 2, _tp_mode, tp_var, atr_period);
@@ -246,7 +234,7 @@ bool EntryOrders::open_runner_buy_order_with_virtual_tp(string symbol, bool cond
long _magic_number) {
if (!condition) return false;
double current_price = SymbolInfoDouble(symbol, SYMBOL_ASK);
if (count_open_positions(symbol, 1, _magic_number) > 0) return false;
if (track.count_open_positions(symbol, 1, _magic_number) > 0) return false;
double stop_loss = calc.calculate_stoploss(symbol, current_price, 1, _sl_mode, sl_var, atr_period);
double virtual_tp = calc.calculate_take_profit(symbol, current_price, stop_loss, 1, _tp_mode, tp_var, atr_period);
@@ -288,7 +276,7 @@ bool EntryOrders::open_runner_sell_order_with_virtual_tp(string symbol, bool con
long _magic_number) {
if (!condition) return false;
double current_price = SymbolInfoDouble(symbol, SYMBOL_BID);
if (count_open_positions(symbol, 2, _magic_number) > 0) return false;
if (track.count_open_positions(symbol, 2, _magic_number) > 0) return false;
double stop_loss = calc.calculate_stoploss(symbol, current_price, 2, _sl_mode, sl_var, atr_period);
double virtual_tp = calc.calculate_take_profit(symbol, current_price, stop_loss, 2, _tp_mode, tp_var, atr_period);
+10
View File
@@ -1,3 +1,13 @@
//+------------------------------------------------------------------+
//| ExitOrders.mqh |
//| Handles logic for closing trades under various conditions |
//| |
//| 2025 xMattC (github.com/xMattC) |
//+------------------------------------------------------------------+
#property copyright "2025 xMattC (github.com/xMattC)"
#property link "https://github.com/xMattC"
#property version "1.00"
#include <MyLibs/Orders/CalculatePositionData.mqh>
#include <MyLibs/Utils/TimeZones.mqh>
#include <Trade/Trade.mqh>
+19 -39
View File
@@ -1,3 +1,13 @@
//+------------------------------------------------------------------+
//| OrderTracker.mqh |
//| Tracks open orders or pending positions |
//| |
//| 2025 xMattC (github.com/xMattC) |
//+------------------------------------------------------------------+
#property copyright "2025 xMattC (github.com/xMattC)"
#property link "https://github.com/xMattC"
#property version "1.00"
#include <Trade/OrderInfo.mqh>
#include <Trade/PositionInfo.mqh>
@@ -8,63 +18,33 @@ class OrderTracker {
public:
int count_open_positions(string symbol, int order_side, long magic_number);
int count_all_positions(string symbol, long magic_number);
int count_pending_orders(string symbol, ENUM_ORDER_TYPE order_type, long magic);
};
// ---------------------------------------------------------------------
// Counts the number of open BUY or SELL positions for a given symbol.
// Counts open positions by symbol, side, and magic number.
//
// Parameters:
// - symbol : Trading symbol (e.g., "EURUSD").
// - order_side : 1 = BUY, 2 = SELL.
// - magic_number : Magic number identifying strategy group.
// - symbol : Symbol to check.
// - order_side : 1 = Buy, 2 = Sell, 0 = Any.
// - _magic_number : Magic number to filter.
//
// Returns:
// - Number of matching open positions.
// ---------------------------------------------------------------------
int OrderTracker::count_open_positions(string symbol, int order_side, long magic_number) {
int OrderTracker::count_open_positions(string symbol, int order_side, long _magic_number) {
int count = 0;
for (int i = PositionsTotal() - 1; i >= 0; i--) {
ulong ticket = PositionGetTicket(i);
if (PositionGetString(POSITION_SYMBOL) == symbol && PositionGetInteger(POSITION_MAGIC) == magic_number) {
if (order_side == 1 && PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) {
count++;
}
if (order_side == 2 && PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL) {
if (PositionGetString(POSITION_SYMBOL) == symbol && PositionGetInteger(POSITION_MAGIC) == _magic_number) {
int type = (int) PositionGetInteger(POSITION_TYPE);
if (order_side == 0 || (order_side == 1 && type == POSITION_TYPE_BUY) || (order_side == 2 && type == POSITION_TYPE_SELL)) {
count++;
}
}
}
return count;
}
// ---------------------------------------------------------------------
// Counts all open positions for a symbol regardless of direction.
//
// Parameters:
// - symbol : Trading symbol.
// - magic_number : Magic number identifying strategy group.
//
// Returns:
// - Total number of matching positions.
// ---------------------------------------------------------------------
int OrderTracker::count_all_positions(string symbol, long magic_number) {
int count = 0;
for (int i = PositionsTotal() - 1; i >= 0; i--) {
ulong ticket = PositionGetTicket(i);
if (PositionGetString(POSITION_SYMBOL) == symbol && PositionGetInteger(POSITION_MAGIC) == magic_number) {
count++;
}
}
return count;
}
+10
View File
@@ -1,3 +1,13 @@
//+------------------------------------------------------------------+
//| StopLogic.mqh |
//| stoploss switch for in-code sl calculations |
//| |
//| 2025 xMattC (github.com/xMattC) |
//+------------------------------------------------------------------+
#property copyright "2025 xMattC (github.com/xMattC)"
#property link "https://github.com/xMattC"
#property version "1.00"
class StopLogic {
public:
double sl_specified_value_switch(string sl_mode, double inp_sl_var, double value);
+10
View File
@@ -1,3 +1,13 @@
//+------------------------------------------------------------------+
//| DrawdownControl.mqh |
//| Implements account drawdown-based risk controls (for prop-firms) |
//| |
//| 2025 xMattC (github.com/xMattC) |
//+------------------------------------------------------------------+
#property copyright "2025 xMattC (github.com/xMattC)"
#property link "https://github.com/xMattC"
#property version "1.00"
#property library
#include <Trade/Trade.mqh>
#include <MyLibs/Utils/MarketDataUtils.mqh>
+10
View File
@@ -1,3 +1,13 @@
//+------------------------------------------------------------------+
//| RangeCalculator.mqh |
//| Determines a high/low price point within a time range |
//| |
//| 2025 xMattC (github.com/xMattC) |
//+------------------------------------------------------------------+
#property copyright "2025 xMattC (github.com/xMattC)"
#property link "https://github.com/xMattC"
#property version "1.00"
#property library
#include <Trade/Trade.mqh>
#include <MyLibs/Utils/TimeZones.mqh>
+10
View File
@@ -1,3 +1,13 @@
//+------------------------------------------------------------------+
//| AtrHandleManager.mqh |
//| ATR Handle Caching Utility for MQL5 EAs |
//| |
//| 2025 xMattC (github.com/xMattC) |
//+------------------------------------------------------------------+
#property copyright "2025 xMattC (github.com/xMattC)"
#property link "https://github.com/xMattC"
#property version "1.00"
#include <Trade/SymbolInfo.mqh>
class AtrHandleManager {
+10
View File
@@ -1,3 +1,13 @@
//+------------------------------------------------------------------+
//| ChartUtils.mqh |
//| Utilities for drawing and annotating charts |
//| |
//| 2025 xMattC (github.com/xMattC) |
//+------------------------------------------------------------------+
#property copyright "2025 xMattC (github.com/xMattC)"
#property link "https://github.com/xMattC"
#property version "1.00"
#include <Object.mqh>
class ChartUtils : public CObject {
+10
View File
@@ -1,3 +1,13 @@
//+------------------------------------------------------------------+
//| Enums.mqh |
//| Enum declarations for inputs and logic flow |
//| |
//| 2025 xMattC (github.com/xMattC) |
//+------------------------------------------------------------------+
#property copyright "2025 xMattC (github.com/xMattC)"
#property link "https://github.com/xMattC"
#property version "1.00"
enum LOT_MODE{
LOT_MODE_FIXED, // Fixed Lot Size
LOT_MODE_PCT_ACCOUNT, // Percent of Account (fixed)
+10
View File
@@ -1,3 +1,13 @@
//+------------------------------------------------------------------+
//| MarketDataUtils.mqh |
//| Simplifies access to indicator buffers and price info |
//| |
//| 2025 xMattC (github.com/xMattC) |
//+------------------------------------------------------------------+
#property copyright "2025 xMattC (github.com/xMattC)"
#property link "https://github.com/xMattC"
#property version "1.00"
class MarketDataUtils {
public:
bool is_new_bar(string symbol, ENUM_TIMEFRAMES time_frame, string daily_start_time = "00:10");
+10
View File
@@ -1,3 +1,13 @@
//+------------------------------------------------------------------+
//| MultiSymbolSignalTracker.mqh |
//| Tracks per-symbol signal state in multi-asset EAs |
//| |
//| 2025 xMattC (github.com/xMattC) |
//+------------------------------------------------------------------+
#property copyright "2025 xMattC (github.com/xMattC)"
#property link "https://github.com/xMattC"
#property version "1.00"
#include <MyLibs/Utils/SignalStateTracker.mqh>
// ---------------------------------------------------------------------
+10
View File
@@ -1,3 +1,13 @@
//+------------------------------------------------------------------+
//| ResourceManager.mqh |
//| Central manager for indicator handle cleanup |
//| |
//| 2025 xMattC (github.com/xMattC) |
//+------------------------------------------------------------------+
#property copyright "2025 xMattC (github.com/xMattC)"
#property link "https://github.com/xMattC"
#property version "1.00"
#include <MyLibs/Utils/AtrHandleManager.mqh>
// ---------------------------------------------------------------------
+10
View File
@@ -1,3 +1,13 @@
//+------------------------------------------------------------------+
//| SignalStateTracker.mqh |
//| Tracks signal timing (e.g. how many bars ago a trigger occurred) |
//| |
//| 2025 xMattC (github.com/xMattC) |
//+------------------------------------------------------------------+
#property copyright "2025 xMattC (github.com/xMattC)"
#property link "https://github.com/xMattC"
#property version "1.00"
class SignalStateTracker {
private:
+11
View File
@@ -1,3 +1,14 @@
//+------------------------------------------------------------------+
//| TimeZones.mqh |
//| Handles timezone conversion and time window logic |
//| |
//| 2025 xMattC (github.com/xMattC) |
//+------------------------------------------------------------------+
#property copyright "2025 xMattC (github.com/xMattC)"
#property link "https://github.com/xMattC"
#property version "1.00"
#property library
#include <MyLibs/Utils/DealingWithTime.mqh>
#include <Trade/Trade.mqh>
+13 -2
View File
@@ -1,10 +1,21 @@
//+------------------------------------------------------------------+
//| TradeWindow.mqh |
//| Defines and manages tradable time sessions |
//| |
//| 2025 xMattC (github.com/xMattC) |
//+------------------------------------------------------------------+
#property copyright "2025 xMattC (github.com/xMattC)"
#property link "https://github.com/xMattC"
#property version "1.00"
#include <MyLibs/Utils/TimeZones.mqh>
class TradeSessionUtils {
protected:
TimeZones tz; // For handling timezone conversion
bool in_window; // Whether the current time is in the allowed window
TimeZones tz; // For handling timezone conversion
bool in_window; // Whether the current time is in the allowed window
datetime start_time; // Session start time (converted to Broker time)
datetime end_time; // Session end time (converted to Broker time)
+10
View File
@@ -1,3 +1,13 @@
//+------------------------------------------------------------------+
//| AtrBands.mqh |
//| Calculates and visualizes ATR-based dynamic bands |
//| |
//| 2025 xMattC (github.com/xMattC) |
//+------------------------------------------------------------------+
#property copyright "2025 xMattC (github.com/xMattC)"
#property link "https://github.com/xMattC"
#property version "1.00"
#include <MyLibs/Utils/MarketDataUtils.mqh>
#include <MyLibs/Utils/AtrHandleManager.mqh>
+10 -6
View File
@@ -1,11 +1,15 @@
//+------------------------------------------------------------------+
//| TrendlineAnalyser.mqh |
//| Detects price crossovers and trend direction for a ma buffer |
//| |
//| 2025 xMattC (github.com/xMattC) |
//+------------------------------------------------------------------+
#property copyright "2025 xMattC (github.com/xMattC)"
#property link "https://github.com/xMattC"
#property version "1.00"
#include <MyLibs/Utils/MarketDataUtils.mqh>
// ---------------------------------------------------------------------
// CLASS: TrendlineAnalyser
// ---------------------------------------------------------------------
// A utility class to detect price crossovers with a trendline buffer.
// Supports both crossover detection and trend direction checks.
// ---------------------------------------------------------------------
class TrendlineAnalyser {
private:
MarketDataUtils market_data_utils;