Attach CheckForGuard Event Handler for Signallers to Handle Guards ...
This commit is contained in:
@@ -0,0 +1,214 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Seriallize Library
|
||||
// ---------------------------------------
|
||||
// Name: XGuardLib
|
||||
// Description: All models related to Guard ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Enumeration ...
|
||||
|
||||
//
|
||||
// Guard Actions ...
|
||||
enum ENUM_X_GUARD_ACTIONS
|
||||
{
|
||||
X_GUARD_ACTION_NONE, // Nothing to Do
|
||||
X_GUARD_ACTION_CLOSE, // Close Specified Position
|
||||
X_GUARD_ACTION_CLOSE_ALL, // Close All Positions
|
||||
X_GUARD_ACTION_CLOSE_LONGS, // Close All Long Positions
|
||||
X_GUARD_ACTION_CLOSE_SHORTS, // Close All Short Position
|
||||
X_GUARD_ACTION_CLOSE_IN_LOSTS, // Close All In Lost Position
|
||||
X_GUARD_ACTION_CLOSE_IN_PROFITS, // Close All In Profit Position
|
||||
X_GUARD_ACTION_CLOSE_IN_LOST_LONGS, // Close All In Lost Long Position
|
||||
X_GUARD_ACTION_CLOSE_IN_PROFIT_LONGS, // Close All In Profit Long Position
|
||||
X_GUARD_ACTION_CLOSE_IN_LOST_SHORTS, // Close All In Lost Short Position
|
||||
X_GUARD_ACTION_CLOSE_IN_PROFITS_SHORT, // Close All In Profit Short Position
|
||||
X_GUARD_ACTION_PARTIAL_CLOSE, // Partial Close Specified Position
|
||||
X_GUARD_ACTION_TRAIL_STOP, // Trail Stop of Specified Position
|
||||
X_GUARD_ACTION_TRAIL_TARGET, // Trail Target of Specified Position
|
||||
X_GUARD_ACTION_HEDGE, // Hedge Specified Positions
|
||||
};
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Model a Guard Action ...
|
||||
struct XGuard
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
ENUM_X_GUARD_ACTIONS action;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
string symbol;
|
||||
string provider;
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
// Specified Position ...
|
||||
ulong ticket;
|
||||
|
||||
//
|
||||
// Partial Close ...
|
||||
double volumeMultiplier;
|
||||
|
||||
//
|
||||
// SL Trial ...
|
||||
double sl;
|
||||
|
||||
//
|
||||
// TP Trial ...
|
||||
double tp;
|
||||
|
||||
//
|
||||
bool force;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XGuard()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleanup ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
time = NULL;
|
||||
action = X_GUARD_ACTION_NONE;
|
||||
|
||||
//
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
provider = NULL;
|
||||
|
||||
//
|
||||
ticket = 0;
|
||||
|
||||
//
|
||||
volumeMultiplier = 0;
|
||||
|
||||
//
|
||||
sl = 0;
|
||||
tp = 0;
|
||||
|
||||
//
|
||||
force = false;
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
IsSpecifiedValid(time) &&
|
||||
IsSpecifiedValid(symbol) &&
|
||||
IsSpecifiedValid(period) &&
|
||||
IsSpecifiedValid(action) &&
|
||||
IsSpecifiedValid(provider)
|
||||
//
|
||||
;
|
||||
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Model Based On Specified Guard Actions ...
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Extensions ...
|
||||
|
||||
//
|
||||
bool IsValid(ENUM_X_GUARD_ACTIONS item)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = item != X_GUARD_ACTION_NONE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
bool IsSpecifiedValid(ENUM_X_GUARD_ACTIONS item)
|
||||
{
|
||||
return IsValid(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Guard to Collection ...
|
||||
*
|
||||
* @param guard: XGuard instance ...
|
||||
* @param guards: XGuard instance Collection ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int AddGuard(
|
||||
XGuard &guard,
|
||||
XGuard &guards[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
if (!guard.IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
AddRef(
|
||||
guard,
|
||||
guards //
|
||||
);
|
||||
|
||||
//
|
||||
result = ArraySize(guards);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
@@ -22,6 +22,7 @@
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.x-guard.lib.mq5"
|
||||
#include <Trade/Trade.mqh>
|
||||
|
||||
//
|
||||
@@ -3752,6 +3753,15 @@ typedef bool (*TCanAnalyse)(
|
||||
datetime _time //
|
||||
);
|
||||
|
||||
//
|
||||
// an Event Type for Notify Guard Triggered ...
|
||||
typedef void (*TOnGuarded)(
|
||||
ENUM_X_GUARD_ACTIONS guard,
|
||||
XPosition &positions[]);
|
||||
|
||||
//
|
||||
typedef int (*TCheckForGuard)(XGuard &guards[]);
|
||||
|
||||
//
|
||||
typedef void (*TOnDealsChanged)(int count);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user