This commit is contained in:
2025-05-13 20:19:58 +03:30
parent 8a329570a5
commit 4b91fff5d9
9 changed files with 875 additions and 820 deletions
+45 -633
View File
@@ -486,6 +486,49 @@ struct XRR
}
};
//
// Model a Target ...
struct XTarget
{
//
// Props ...
double target;
double volumeMultiplier;
//
// Constructor ...
XTarget()
{
Clean();
}
//
// Tools ...
//
// Cleanup ...
void Clean()
{
//
target = 0;
volumeMultiplier = 0;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result = target > 0;
//
return result;
}
};
//
// Model an Open Position ...
struct XPosition
@@ -1125,38 +1168,17 @@ struct XSignal
ENUM_X_ORDER_MODES mode; // Execution Mode ...
//
XSignal supports[]; // a Collecion of Support Signals ...
//
int pushers; // Signal Pushers ...
string conditions; // Signal Conditions ...
//
// Additional ...
//
// TP ...
double fullTPLevel; // Full TP ...
bool isPartiallyClosed; // Check Partially Closed Before or not ...
double partialCloseMultiplier; // Amount of Partial Close ...
double partialCloseOnTPLevel; // Do Partial Close on TP Level ...
//
// RF ...
double tpLevelForBreakEven; // TP Level for Break Even ...
bool riskFreeOnBreakEven; // Risk Free Signal On Break Even ...
//
// Traget ...
double targets[]; // Force Risk Free On Targets ...
bool isTargetApplied; // Target Applied ...
XTarget targets[]; // Provided Targets ...
int appliedTargetIDX; // Last Applied Target Index ...
bool ignoreEAVolume; // Ignore EA Volume ...
//
// SL Trail ...
bool trailSL; // Do SL Trail ...
double trailSLStartOnReachTPLevel; // Start SL Trail After Reached TP Level ...
bool isTargetApplied; // Check if Target Applied or not ...
//
// Constructor ...
@@ -1165,528 +1187,6 @@ struct XSignal
Default();
}
//
bool Prepare(
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
ENUM_POSITION_TYPE mType, // Long (Buy) or Short (Sell)
ENUM_X_ORDER_MODES mMode, // Execution Mode
double mEntry, // Entry Price
double mVolume, // Volume
double mSL = 0, // Stop Loss
double mTP = 0 // Take Profit
)
{
//
bool result = false;
//
result =
//
IsValid(mMode) &&
IsValid(mSymbol) &&
IsValid(mPeriod) &&
NotEmpty(mEntry) &&
NotEmpty(mVolume) &&
IsValid(mProvider)
//
;
if (!result)
{
return result;
}
//
if (mTP < 0)
{
mTP = 0;
}
//
if (mSL < 0)
{
mSL = 0;
}
//
type = mType;
mode = mMode;
symbol = mSymbol;
period = mPeriod;
provider = mProvider;
//
// Normalization Values ...
sl = NormalizePrice(mSL, mSymbol);
tp = NormalizePrice(mTP, mSymbol);
mEntry = NormalizePrice(mEntry, mSymbol);
mVolume = NormalizeVolume(mVolume, mSymbol);
//
entry = mEntry;
volume = mVolume;
//
result = Normalize();
//
return result;
}
//
bool PrepareComplex(
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
ENUM_POSITION_TYPE mType, // Long (Buy) or Short (Sell)
ENUM_X_ORDER_MODES mMode, // Execution Mode
double mEntry, // Entry Price
double mVolume, // Volume
double mSL = 0, // Stop Loss
//
// TP ...
double mFullTPLevel = 0, // Full TP Level
double mPartialCloseOnTPLevel = 0, // Partial Close On TP Level
double mPartialCloseMultiplier = 0, // Partial Close Multiplier
//
// RF ...
bool mRiskFreeOnBreakEven = false, // Risk Free Signal On Break Even ...
double mTpLevelForBreakEven = 0, // TP Level for Break Even ...
//
// SL Trail ...
bool mTrailSL = false, // Trail SL
double mTrailSLStartOnReachTPLevel = 0 // Trail SL Starts after Reached TP Level
)
{
//
bool result = false;
//
// Validate Args ...
result =
//
// Common ...
mSL > 0 &&
mEntry > 0 &&
mVolume > 0 &&
IsValid(mSymbol) &&
IsValid(mPeriod) &&
IsValid(mProvider) &&
mMode != X_ORDER_MODE_NOTHING
//
&&
//
// TP ...
mFullTPLevel > 0
//
;
if (!result)
{
return result;
}
//
// Prepare Regular Signal Values ...
double _risk = MathAbs(mEntry - mSL);
double _reward = _risk * mFullTPLevel;
//
bool isLong = IsLong(mType);
//
sl = mSL;
type = mType;
mode = mMode;
entry = mEntry;
symbol = mSymbol;
period = mPeriod;
volume = mVolume;
provider = mProvider;
fullTPLevel = mFullTPLevel;
tp = isLong
? mEntry + _reward
: mEntry - _reward;
//
result = Normalize();
if (!result)
{
return result;
}
//
// Calculate Other Conditions ...
//
bool canPartialClose =
//
mPartialCloseOnTPLevel > 0 &&
mPartialCloseMultiplier > 0 &&
mPartialCloseOnTPLevel < mFullTPLevel
//
;
if (canPartialClose)
{
//
partialCloseOnTPLevel = mPartialCloseOnTPLevel;
partialCloseMultiplier = mPartialCloseMultiplier;
}
//
bool canRFOnBEP =
//
mRiskFreeOnBreakEven &&
mTpLevelForBreakEven > 0
//
;
if (canRFOnBEP)
{
//
riskFreeOnBreakEven = mRiskFreeOnBreakEven;
tpLevelForBreakEven = mTpLevelForBreakEven;
}
//
bool canTrailSL =
//
mTrailSL &&
mTrailSLStartOnReachTPLevel > 0 &&
mTrailSLStartOnReachTPLevel < mFullTPLevel
//
;
if (canTrailSL)
{
//
trailSL = mTrailSL;
trailSLStartOnReachTPLevel = mTrailSLStartOnReachTPLevel;
}
//
result = IsValid();
//
return result;
}
//
bool PrepareLong(
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
ENUM_X_ORDER_MODES mMode, // Execution Mode
double mEntry, // Entry Price
double mVolume, // Volume
double mSL = 0, // Stop Loss
double mTP = 0 // Take Profit
)
{
//
return Prepare(
mSymbol,
mProvider,
mPeriod,
POSITION_TYPE_BUY,
mMode,
mEntry,
mVolume,
mSL,
mTP
//
);
}
//
bool PrepareShort(
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
ENUM_X_ORDER_MODES mMode, // Execution Mode
double mEntry, // Entry Price
double mVolume, // Volume
double mSL = 0, // Stop Loss
double mTP = 0 // Take Profit
)
{
//
return Prepare(
mSymbol,
mProvider,
mPeriod,
POSITION_TYPE_SELL,
mMode,
mEntry,
mVolume,
mSL,
mTP
//
);
}
//
// Market Mode ...
//
bool PrepareMarketLong(
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
double mEntry, // Entry Price
double mVolume, // Volume
double mSL = 0, // Stop Loss
double mTP = 0 // Take Profit
)
{
//
return PrepareLong(
mSymbol,
mProvider,
mPeriod,
X_ORDER_MODE_MARKET,
mEntry,
mVolume,
mSL,
mTP
//
);
}
//
bool PrepareMarketShort(
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
double mEntry, // Entry Price
double mVolume, // Volume
double mSL = 0, // Stop Loss
double mTP = 0 // Take Profit
)
{
//
return PrepareShort(
mSymbol,
mProvider,
mPeriod,
X_ORDER_MODE_MARKET,
mEntry,
mVolume,
mSL,
mTP
//
);
}
//
// Stop Mode ...
//
bool PrepareStopLong(
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
double mEntry, // Entry Price
double mVolume, // Volume
double mSL = 0, // Stop Loss
double mTP = 0 // Take Profit
)
{
//
return PrepareLong(
mSymbol,
mProvider,
mPeriod,
X_ORDER_MODE_STOP,
mEntry,
mVolume,
mSL,
mTP
//
);
}
//
bool PrepareStopShort(
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
double mEntry, // Entry Price
double mVolume, // Volume
double mSL = 0, // Stop Loss
double mTP = 0 // Take Profit
)
{
//
return PrepareShort(
mSymbol,
mProvider,
mPeriod,
X_ORDER_MODE_STOP,
mEntry,
mVolume,
mSL,
mTP
//
);
}
//
// Limit Mode ...
//
bool PrepareLimitLong(
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
double mEntry, // Entry Price
double mVolume, // Volume
double mSL = 0, // Stop Loss
double mTP = 0 // Take Profit
)
{
//
return PrepareLong(
mSymbol,
mProvider,
mPeriod,
X_ORDER_MODE_LIMIT,
mEntry,
mVolume,
mSL,
mTP
//
);
}
//
bool PrepareLimitShort(
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
double mEntry, // Entry Price
double mVolume, // Volume
double mSL = 0, // Stop Loss
double mTP = 0 // Take Profit
)
{
//
return PrepareShort(
mSymbol,
mProvider,
mPeriod,
X_ORDER_MODE_LIMIT,
mEntry,
mVolume,
mSL,
mTP
//
);
}
//
// Generate Opposit Direction ...
bool GenerateOpposit(
XSignal &mSignal // Oppsoit Signal
)
{
//
bool result = false;
//
result = IsValid();
if (!result)
{
return result;
}
//
ENUM_POSITION_TYPE mType = Opposit(this.type);
double mEntry = GetExit(this.symbol, mType);
//
bool isLong = IsLong(mType);
//
// Calculate Risk Reward Ratio ...
double risk = GetRisk();
double reward = GetReward();
//
double mSL = isLong
? mEntry - risk
: mEntry + risk;
//
double mTP = isLong
? mEntry + reward
: mEntry - reward;
//
result = mSignal.Prepare(
this.symbol,
this.provider,
this.period,
mType,
this.mode,
mEntry,
this.volume,
mSL,
mTP //
);
//
return result;
}
//
// Prepare Opposit Signal based On a Position ...
bool PrepareOpposit(
XPosition &source // Source Data
)
{
//
bool result = false;
//
ENUM_POSITION_TYPE mType = Opposit(source.type);
double mEntry = GetEntry(source.symbol, mType);
//
bool isLong = IsLong(mType);
//
double risk = source.GetRisk();
double reward = source.GetReward();
//
double mSL = isLong
? mEntry - risk
: mEntry + risk;
//
double mTP = isLong
? mEntry + reward
: mEntry - reward;
//
return Prepare(
source.symbol,
source.provider,
source.period,
mType,
X_ORDER_MODE_MARKET,
mEntry,
source.volume,
mSL,
mTP //
);
//
result = IsValid();
//
return result;
}
//
// Tools ...
@@ -1697,7 +1197,6 @@ struct XSignal
//
entry = 0;
volume = 0;
pushers = 0;
positionId = 0;
//
@@ -1716,21 +1215,6 @@ struct XSignal
ignoreEAVolume = false;
isTargetApplied = false;
//
trailSL = false;
riskFreeOnBreakEven = false;
//
fullTPLevel = 0;
tpLevelForBreakEven = 0;
partialCloseOnTPLevel = 0;
isPartiallyClosed = false;
partialCloseMultiplier = 0;
trailSLStartOnReachTPLevel = 0;
//
Clean(supports);
//
ZeroMemory(this);
}
@@ -1742,7 +1226,6 @@ struct XSignal
//
entry = 0;
volume = 0;
pushers = 0;
positionId = 0;
//
@@ -1760,21 +1243,6 @@ struct XSignal
appliedTargetIDX = -1;
ignoreEAVolume = false;
isTargetApplied = false;
//
trailSL = false;
riskFreeOnBreakEven = false;
//
fullTPLevel = 0;
tpLevelForBreakEven = 0;
isPartiallyClosed = false;
partialCloseOnTPLevel = 0;
partialCloseMultiplier = 0;
trailSLStartOnReachTPLevel = 0;
//
Clean(supports);
}
//
@@ -1954,61 +1422,6 @@ struct XSignal
return result;
}
//
// Check Can Partial Close on Specified TP Level ...
bool CanPartialClose()
{
//
bool result = false;
//
result =
IsValid() &&
fullTPLevel > 0 &&
partialCloseOnTPLevel > 0 &&
partialCloseMultiplier > 0 &&
partialCloseOnTPLevel < fullTPLevel;
//
return result;
}
//
// Check Can Risk Free On Break Even Point ...
bool CanRiskFreeOnBreakEvenPoint()
{
//
bool result = false;
//
result =
IsValid() &&
riskFreeOnBreakEven &&
tpLevelForBreakEven > 0;
//
return result;
}
//
// Check Can Trail SL ...
bool CanTrailSL()
{
//
bool result = false;
//
result =
IsValid() &&
trailSL &&
fullTPLevel > 0 &&
trailSLStartOnReachTPLevel > 0 &&
trailSLStartOnReachTPLevel < fullTPLevel;
//
return result;
}
//
string GetTag()
{
@@ -4016,7 +3429,6 @@ struct XTradeData
symbol = _signal.symbol;
volume = _signal.volume;
period = _signal.period;
pushers = _signal.pushers;
provider = _signal.provider;
conditions = _signal.conditions;
type = ToPositionType(_signal.type);