complete xea class ...

This commit is contained in:
2024-05-21 04:36:05 +03:30
parent 74ffc15d04
commit 57371b9343
15 changed files with 3227 additions and 1505 deletions
+266
View File
@@ -53,6 +53,9 @@ string XSymbolToken = "SMBL";
string XSupportToken = "SP";
string XEQMSupportToken = "EQM";
//
string XSLTrailToken = "SLT";
//
string XActionToken = "A";
@@ -107,6 +110,19 @@ enum ENUM_X_SIGNAL_MANAGING_ACTIONS
X_SIGNAL_PARTIAL_TRAIL, // Use 0 index as SL and Trail Stop on TP Levels and also Partial Close on TP Levels
};
//
// Available Guard Action ...
enum ENUM_X_GUARD_ACTIONS
{
X_GUARD_ACTION_NOTHING, // Nothing
X_GUARD_ACTION_HEDGE, // Hedge
X_GUARD_PARTIAL_CLOSE, // Partial Close
X_GUARD_ACTION_TRAIL_STOP, // Trail StopLoss
X_GUARD_ACTION_FORCE_CLOSE, // Force Close
X_GUARD_ACTION_ADD_SUPPORT_SIGNAL, // Add Support Signal
X_GUARD_ACTION_CANCEL_PENDING_ORDERS, // Cancel Pending Orders
};
//
// Structs ...
@@ -2427,6 +2443,96 @@ struct XOnTradeHandlerState
}
};
//
// Model Guard Info ...
struct XGuard
{
//
string symbol; // Trading Symbol ...
string provider; // Signal Provider ...
ENUM_TIMEFRAMES period; // Trading Timeframe ...
ENUM_POSITION_TYPE type; // Position Type ...
ENUM_X_GUARD_ACTIONS action; // Which Action to Do ...
//
double dblPayLoad;
string strPayload;
//
// Constructor ...
XGuard()
{
Clean();
}
//
// Initialize ...
//
// Global Initializer ...
bool Init(
string mSymbol, // Trading Symbol ...
ENUM_TIMEFRAMES mPeriod, // Trading Timeframe ...
ENUM_X_GUARD_ACTIONS mAction, // Which Action to Do ...
ENUM_POSITION_TYPE mType = NULL, // Position Type ...
string mProvider = NULL, // Signal Provider ...
double mDblPayLoad = NULL,
string mStrPayload = NULL //
)
{
//
type = mType;
symbol = mSymbol;
period = mPeriod;
action = mAction;
provider = mProvider;
dblPayLoad = mDblPayLoad;
strPayload = mStrPayload;
//
bool result = IsValid();
//
return result;
}
//
// Tools ...
//
// Cleanup ...
void Clean()
{
//
symbol = NULL;
provider = NULL;
period = NULL;
action = X_GUARD_ACTION_NOTHING;
//
strPayload = NULL;
dblPayLoad = EMPTY_VALUE;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
action != X_GUARD_ACTION_NOTHING
//
;
//
return result;
}
};
//
// Model a Position with all of it's Supports ...
struct XPositionPack
@@ -3717,6 +3823,73 @@ int FindIndex(
return result;
}
//
// Retrieve String Representation ...
string ToString(ENUM_X_SIGNAL_EXECUTION_RESULT value)
{
//
string result = NULL;
//
switch (value)
{
//
case X_SIGNAL_EXECUTION_UNKNOWN:
result = "Unknown";
break;
//
case X_SIGNAL_EXECUTION_SUCCEED:
result = "Succed";
break;
//
case X_SIGNAL_EXECUTION_FAILED_SPREAD:
result = "Spread more than Max Allowed";
break;
//
case X_SIGNAL_EXECUTION_FAILED_NO_EQUITY:
result = "No Equity for Trade";
break;
//
case X_SIGNAL_EXECUTION_FAILED_PRICE_ERROR:
result = "Price Error";
break;
//
case X_SIGNAL_EXECUTION_FAILED_MAX_REACHED:
result = "Max Allowed Positions Reached";
break;
//
case X_SIGNAL_EXECUTION_FAILED_INVALID_PARAMS:
result = "Invalid Params";
break;
}
//
return result;
}
//
// Converts Position Type to Order Type ...
ENUM_ORDER_TYPE ToOrderType(ENUM_POSITION_TYPE value)
{
//
bool isLong = IsLong(value);
//
ENUM_ORDER_TYPE result =
isLong
? ORDER_TYPE_BUY
: ORDER_TYPE_SELL;
//
return result;
}
//
// Tagging ...
@@ -3830,3 +4003,96 @@ ulong ExtractEQMSupportedTicket(string value)
}
//
// SL Trails ...
//
// Extract SL Trail Level ...
int ExtractSLTrailLevel(string comment)
{
//
int result = 0;
//
if (!IsValid(comment))
{
return result;
}
//
result = ParseIntSurrounded(
comment,
XSLTrailToken
//
);
//
return result;
}
//
// Generate SL Trail Comment Tag ...
string GenerateSLTrailTag(int level)
{
//
string result = NULL;
//
if (level <= 0)
{
return result;
}
//
result = Surround(
XSLTrailToken,
level
//
);
//
return result;
}
//
// Prepare SL Trail Comment ...
string PrepareSLTrailTag(
const string comment // Original Position Comment ...
)
{
//
string result = NULL;
//
int level = 0;
result = comment;
//
// Check Comment Contains SL Trailing or not ...
int lastTrailLevel = ExtractSLTrailLevel(comment);
if (lastTrailLevel <= 0)
{
level++;
}
else
{
//
level = lastTrailLevel + 1;
string lastLevelStr = GenerateSLTrailTag(lastTrailLevel);
StringReplace(
result,
lastLevelStr,
""
//
);
}
//
// Generate level Comment ...
string levelStr = GenerateSLTrailTag(level);
result += levelStr;
//
return result;
}
//