Add standard file headers to custom library files
This commit is contained in:
@@ -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>
|
#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 {
|
enum CUSTOM_MAX_TYPE {
|
||||||
CM_WIN_LOSS_RATIO,
|
CM_WIN_LOSS_RATIO,
|
||||||
CM_WIN_PERCENT
|
CM_WIN_PERCENT
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
// CLASS: CustomMax
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
// Calculates custom performance criteria for use in optimizations.
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
class CustomMax : public CObject {
|
class CustomMax : public CObject {
|
||||||
protected:
|
protected:
|
||||||
double custom_criteria;
|
double custom_criteria;
|
||||||
|
|||||||
@@ -1,33 +1,23 @@
|
|||||||
// ---------------------------------------------------------------------
|
//+------------------------------------------------------------------+
|
||||||
// ENUM: MODE_SPLIT_DATA
|
//| TestDataSplit.mqh |
|
||||||
// ---------------------------------------------------------------------
|
//| Splits historical data into training/testing segments |
|
||||||
// Defines how to split data during testing based on time attributes.
|
//| |
|
||||||
//
|
//| 2025 xMattC (github.com/xMattC) |
|
||||||
// Values:
|
//+------------------------------------------------------------------+
|
||||||
// - NO_SPLIT : Do not split, always return true.
|
#property copyright "2025 xMattC (github.com/xMattC)"
|
||||||
// - ODD_YEARS : Include only odd-numbered years.
|
#property link "https://github.com/xMattC"
|
||||||
// - EVEN_YEARS : Include only even-numbered years.
|
#property version "1.00"
|
||||||
// - 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.
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
enum MODE_SPLIT_DATA {
|
enum MODE_SPLIT_DATA {
|
||||||
NO_SPLIT,
|
NO_SPLIT, // Do not split, always return true.
|
||||||
ODD_YEARS,
|
ODD_YEARS, // Include only odd-numbered years.
|
||||||
EVEN_YEARS,
|
EVEN_YEARS, // Include only even-numbered years.
|
||||||
ODD_MONTHS,
|
ODD_MONTHS, // Include only odd-numbered months.
|
||||||
EVEN_MONTHS,
|
EVEN_MONTHS, // Include only even-numbered months.
|
||||||
ODD_WEEKS,
|
ODD_WEEKS, // Include only odd-numbered weeks.
|
||||||
EVEN_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 {
|
class TestDataSplit {
|
||||||
public:
|
public:
|
||||||
bool in_test_period(MODE_SPLIT_DATA data_split_method);
|
bool in_test_period(MODE_SPLIT_DATA data_split_method);
|
||||||
|
|||||||
@@ -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 <Trade/Trade.mqh>
|
||||||
#include <MyLibs/utils/AtrHandleManager.mqh>
|
#include <MyLibs/utils/AtrHandleManager.mqh>
|
||||||
|
|
||||||
@@ -7,12 +17,6 @@
|
|||||||
CTrade trade;
|
CTrade trade;
|
||||||
AtrHandleManager atr_manager;
|
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 {
|
class AdjustPosition {
|
||||||
public:
|
public:
|
||||||
void set_breakeven_sl(string symbol, int runner_magic_no, double buffer_points = 5);
|
void set_breakeven_sl(string symbol, int runner_magic_no, double buffer_points = 5);
|
||||||
|
|||||||
@@ -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/MarketDataUtils.mqh>
|
||||||
#include <MyLibs/Utils/TimeZones.mqh>
|
#include <MyLibs/Utils/TimeZones.mqh>
|
||||||
#include <MyLibs/Utils/AtrHandleManager.mqh>
|
#include <MyLibs/Utils/AtrHandleManager.mqh>
|
||||||
#include <Trade/Trade.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 {
|
class CalculatePositionData : public CObject {
|
||||||
protected:
|
protected:
|
||||||
CTrade trade;
|
CTrade trade;
|
||||||
|
|||||||
@@ -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/CalculatePositionData.mqh>
|
||||||
|
#include <MyLibs/Orders/OrderTracker.mqh>
|
||||||
#include <Trade/Trade.mqh>
|
#include <Trade/Trade.mqh>
|
||||||
|
|
||||||
class EntryOrders {
|
class EntryOrders {
|
||||||
protected:
|
protected:
|
||||||
CTrade trade;
|
CTrade trade;
|
||||||
CalculatePositionData calc;
|
CalculatePositionData calc;
|
||||||
|
OrderTracker track;
|
||||||
|
|
||||||
public:
|
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,
|
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);
|
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);
|
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.
|
// 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) {
|
string _tp_mode, double tp_var, string _lot_mode, double lot_var, long _magic_number) {
|
||||||
if (!condition) return false;
|
if (!condition) return false;
|
||||||
double current_price = SymbolInfoDouble(symbol, SYMBOL_ASK);
|
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 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);
|
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) {
|
string _tp_mode, double tp_var, string _lot_mode, double lot_var, long _magic_number) {
|
||||||
if (!condition) return false;
|
if (!condition) return false;
|
||||||
double current_price = SymbolInfoDouble(symbol, SYMBOL_BID);
|
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 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);
|
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,
|
string _sl_mode, double sl_var, string _tp_mode, double tp_var, string _lot_mode, double lot_var,
|
||||||
long _magic_number) {
|
long _magic_number) {
|
||||||
if (!condition) return false;
|
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 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);
|
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,
|
string _sl_mode, double sl_var, string _tp_mode, double tp_var, string _lot_mode, double lot_var,
|
||||||
long _magic_number) {
|
long _magic_number) {
|
||||||
if (!condition) return false;
|
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 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);
|
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) {
|
long _magic_number) {
|
||||||
if (!condition) return false;
|
if (!condition) return false;
|
||||||
double current_price = SymbolInfoDouble(symbol, SYMBOL_ASK);
|
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 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);
|
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) {
|
long _magic_number) {
|
||||||
if (!condition) return false;
|
if (!condition) return false;
|
||||||
double current_price = SymbolInfoDouble(symbol, SYMBOL_BID);
|
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 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);
|
double virtual_tp = calc.calculate_take_profit(symbol, current_price, stop_loss, 2, _tp_mode, tp_var, atr_period);
|
||||||
|
|||||||
@@ -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/Orders/CalculatePositionData.mqh>
|
||||||
#include <MyLibs/Utils/TimeZones.mqh>
|
#include <MyLibs/Utils/TimeZones.mqh>
|
||||||
#include <Trade/Trade.mqh>
|
#include <Trade/Trade.mqh>
|
||||||
|
|||||||
@@ -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/OrderInfo.mqh>
|
||||||
#include <Trade/PositionInfo.mqh>
|
#include <Trade/PositionInfo.mqh>
|
||||||
|
|
||||||
@@ -8,63 +18,33 @@ class OrderTracker {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
int count_open_positions(string symbol, int order_side, long magic_number);
|
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);
|
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:
|
// Parameters:
|
||||||
// - symbol : Trading symbol (e.g., "EURUSD").
|
// - symbol : Symbol to check.
|
||||||
// - order_side : 1 = BUY, 2 = SELL.
|
// - order_side : 1 = Buy, 2 = Sell, 0 = Any.
|
||||||
// - magic_number : Magic number identifying strategy group.
|
// - _magic_number : Magic number to filter.
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// - Number of matching open positions.
|
// - 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;
|
int count = 0;
|
||||||
|
|
||||||
for (int i = PositionsTotal() - 1; i >= 0; i--) {
|
for (int i = PositionsTotal() - 1; i >= 0; i--) {
|
||||||
ulong ticket = PositionGetTicket(i);
|
ulong ticket = PositionGetTicket(i);
|
||||||
|
|
||||||
if (PositionGetString(POSITION_SYMBOL) == symbol && PositionGetInteger(POSITION_MAGIC) == magic_number) {
|
if (PositionGetString(POSITION_SYMBOL) == symbol && PositionGetInteger(POSITION_MAGIC) == _magic_number) {
|
||||||
if (order_side == 1 && PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) {
|
int type = (int) PositionGetInteger(POSITION_TYPE);
|
||||||
count++;
|
if (order_side == 0 || (order_side == 1 && type == POSITION_TYPE_BUY) || (order_side == 2 && type == POSITION_TYPE_SELL)) {
|
||||||
}
|
|
||||||
|
|
||||||
if (order_side == 2 && PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL) {
|
|
||||||
count++;
|
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;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 {
|
class StopLogic {
|
||||||
public:
|
public:
|
||||||
double sl_specified_value_switch(string sl_mode, double inp_sl_var, double value);
|
double sl_specified_value_switch(string sl_mode, double inp_sl_var, double value);
|
||||||
|
|||||||
@@ -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
|
#property library
|
||||||
#include <Trade/Trade.mqh>
|
#include <Trade/Trade.mqh>
|
||||||
#include <MyLibs/Utils/MarketDataUtils.mqh>
|
#include <MyLibs/Utils/MarketDataUtils.mqh>
|
||||||
|
|||||||
@@ -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
|
#property library
|
||||||
#include <Trade/Trade.mqh>
|
#include <Trade/Trade.mqh>
|
||||||
#include <MyLibs/Utils/TimeZones.mqh>
|
#include <MyLibs/Utils/TimeZones.mqh>
|
||||||
|
|||||||
@@ -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>
|
#include <Trade/SymbolInfo.mqh>
|
||||||
|
|
||||||
class AtrHandleManager {
|
class AtrHandleManager {
|
||||||
|
|||||||
@@ -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>
|
#include <Object.mqh>
|
||||||
|
|
||||||
class ChartUtils : public CObject {
|
class ChartUtils : public CObject {
|
||||||
|
|||||||
@@ -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{
|
enum LOT_MODE{
|
||||||
LOT_MODE_FIXED, // Fixed Lot Size
|
LOT_MODE_FIXED, // Fixed Lot Size
|
||||||
LOT_MODE_PCT_ACCOUNT, // Percent of Account (fixed)
|
LOT_MODE_PCT_ACCOUNT, // Percent of Account (fixed)
|
||||||
|
|||||||
@@ -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 {
|
class MarketDataUtils {
|
||||||
public:
|
public:
|
||||||
bool is_new_bar(string symbol, ENUM_TIMEFRAMES time_frame, string daily_start_time = "00:10");
|
bool is_new_bar(string symbol, ENUM_TIMEFRAMES time_frame, string daily_start_time = "00:10");
|
||||||
|
|||||||
@@ -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>
|
#include <MyLibs/Utils/SignalStateTracker.mqh>
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|||||||
@@ -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>
|
#include <MyLibs/Utils/AtrHandleManager.mqh>
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|||||||
@@ -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 {
|
class SignalStateTracker {
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
#property library
|
||||||
#include <MyLibs/Utils/DealingWithTime.mqh>
|
#include <MyLibs/Utils/DealingWithTime.mqh>
|
||||||
#include <Trade/Trade.mqh>
|
#include <Trade/Trade.mqh>
|
||||||
|
|||||||
@@ -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>
|
#include <MyLibs/Utils/TimeZones.mqh>
|
||||||
|
|
||||||
class TradeSessionUtils {
|
class TradeSessionUtils {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TimeZones tz; // For handling timezone conversion
|
TimeZones tz; // For handling timezone conversion
|
||||||
bool in_window; // Whether the current time is in the allowed window
|
bool in_window; // Whether the current time is in the allowed window
|
||||||
datetime start_time; // Session start time (converted to Broker time)
|
datetime start_time; // Session start time (converted to Broker time)
|
||||||
datetime end_time; // Session end time (converted to Broker time)
|
datetime end_time; // Session end time (converted to Broker time)
|
||||||
|
|
||||||
|
|||||||
@@ -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/MarketDataUtils.mqh>
|
||||||
#include <MyLibs/Utils/AtrHandleManager.mqh>
|
#include <MyLibs/Utils/AtrHandleManager.mqh>
|
||||||
|
|
||||||
|
|||||||
@@ -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>
|
#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 {
|
class TrendlineAnalyser {
|
||||||
private:
|
private:
|
||||||
MarketDataUtils market_data_utils;
|
MarketDataUtils market_data_utils;
|
||||||
|
|||||||
Reference in New Issue
Block a user