update to my mt5 libs to include better comments

This commit is contained in:
Matt Corcoran
2025-07-12 15:29:30 +02:00
parent ec3fc120ce
commit 136522ef1c
31 changed files with 1389 additions and 2024 deletions
+66 -4
View File
@@ -3,7 +3,7 @@
#include <Trade/Trade.mqh>
class ExitOrders {
protected:
protected:
CTrade trade;
TimeZones tz;
CalculatePositionData calc;
@@ -12,15 +12,27 @@ class ExitOrders {
long position_open_time;
long first_allowed_close_time;
public:
public:
bool close_buy_orders(string symbol, bool condition, int close_bars, ENUM_TIMEFRAMES close_bar_period, long _magic_number);
bool close_sell_orders(string symbol, bool condition, int close_bars, ENUM_TIMEFRAMES close_bar_period, long _magic_number);
bool daily_timed_exit(string symbol, datetime exit_time, int delay_days, long _magic_number);
bool daily_timed_profit_exit(string symbol, ENUM_TIMEFRAMES close_bar_period, string exit_time, string cw_tzone, int delay_days,
long _magic_number);
bool daily_timed_profit_exit(string symbol, ENUM_TIMEFRAMES close_bar_period, string exit_time, string cw_tzone, int delay_days, long _magic_number);
bool first_profitable_close_exit(string symbol, ENUM_TIMEFRAMES close_bar_period, long _magic_number);
};
// ---------------------------------------------------------------------
// Closes BUY positions on condition + after a number of bars (if non 0) .
//
// Parameters:
// - symbol : Symbol to evaluate positions for.
// - condition : If true, closes position immediately.
// - close_bars : Minimum number of bars before auto close.
// - close_bar_period : Timeframe to count bars on.
// - _magic_number : Magic number to identify the trade group.
//
// Returns:
// - True after evaluation and any attempted closes.
// ---------------------------------------------------------------------
bool ExitOrders::close_buy_orders(string symbol, bool condition, int close_bars, ENUM_TIMEFRAMES close_bar_period, long _magic_number) {
for (int i = PositionsTotal() - 1; i >= 0; i--) {
posTicket = PositionGetTicket(i);
@@ -38,6 +50,19 @@ bool ExitOrders::close_buy_orders(string symbol, bool condition, int close_bars,
return true;
}
// ---------------------------------------------------------------------
// Closes SELL positions on condition + after a number of bars (if non 0) .
//
// Parameters:
// - symbol : Symbol to evaluate positions for.
// - condition : If true, closes position immediately.
// - close_bars : Minimum number of bars before auto close.
// - close_bar_period : Timeframe to count bars on.
// - _magic_number : Magic number to identify the trade group.
//
// Returns:
// - True after evaluation and any attempted closes.
// ---------------------------------------------------------------------
bool ExitOrders::close_sell_orders(string symbol, bool condition, int close_bars, ENUM_TIMEFRAMES close_bar_period, long _magic_number) {
for (int i = PositionsTotal() - 1; i >= 0; i--) {
posTicket = PositionGetTicket(i);
@@ -55,6 +80,18 @@ bool ExitOrders::close_sell_orders(string symbol, bool condition, int close_bars
return true;
}
// ---------------------------------------------------------------------
// Closes position after a fixed exit time and delay in days.
//
// Parameters:
// - symbol : Symbol to evaluate.
// - exit_time : Time of day when exit is permitted.
// - delay_days : Number of full days before close allowed.
// - _magic_number : Magic number to identify the trade group.
//
// Returns:
// - True after evaluation and any attempted closes.
// ---------------------------------------------------------------------
bool ExitOrders::daily_timed_exit(string symbol, datetime exit_time, int delay_days, long _magic_number) {
for (int i = PositionsTotal() - 1; i >= 0; i--) {
posTicket = PositionGetTicket(i);
@@ -73,6 +110,20 @@ bool ExitOrders::daily_timed_exit(string symbol, datetime exit_time, int delay_d
return true;
}
// ---------------------------------------------------------------------
// Closes a position only if it's profitable after a given time.
//
// Parameters:
// - symbol : Symbol to evaluate.
// - close_bar_period : Bar timeframe for bar-close evaluation.
// - exit_time : Time of day when profit exit is checked.
// - cw_tzone : Clockwork time zone for exit conversion.
// - delay_days : Minimum days to wait before closing.
// - _magic_number : Magic number to identify the trade group.
//
// Returns:
// - True after evaluation and any attempted closes.
// ---------------------------------------------------------------------
bool ExitOrders::daily_timed_profit_exit(string symbol, ENUM_TIMEFRAMES close_bar_period, string exit_time, string cw_tzone, int delay_days,
long _magic_number) {
for (int i = PositionsTotal() - 1; i >= 0; i--) {
@@ -108,6 +159,17 @@ bool ExitOrders::daily_timed_profit_exit(string symbol, ENUM_TIMEFRAMES close_ba
return true;
}
// ---------------------------------------------------------------------
// Closes position on first profitable bar after one bar completes.
//
// Parameters:
// - symbol : Symbol to evaluate.
// - close_bar_period : Timeframe for bar-close evaluation.
// - _magic_number : Magic number to identify the trade group.
//
// Returns:
// - True after evaluation and any attempted closes.
// ---------------------------------------------------------------------
bool ExitOrders::first_profitable_close_exit(string symbol, ENUM_TIMEFRAMES close_bar_period, long _magic_number) {
position_open_time = PositionGetInteger(POSITION_TIME);
first_allowed_close_time = position_open_time + PeriodSeconds(close_bar_period);