Add standard file headers to custom library files
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user