This commit is contained in:
2024-06-18 07:12:41 +03:30
parent 326d3f4929
commit 13eeb5d541
3 changed files with 474 additions and 233 deletions
+120 -212
View File
@@ -681,9 +681,10 @@ struct XTradeInfo
: selectedEntry;
//
double nextVolume = rLevel % 2 == 1
? volume
: volume * volumeMultiplier;
double nextVolume = selectedVolume * volumeMultiplier;
// rLevel % 2 == 1
// ? volume
// : volume * volumeMultiplier;
//
double zoneUpper =
@@ -1854,13 +1855,9 @@ public:
//
// Trailling ...
if (EnableTrailling())
{
//
if (!forceState)
{
int traillings = HandleTrailling();
}
}
//
// Supporting ...
@@ -3704,7 +3701,7 @@ public:
bool forceState = ForceState();
//
if (!isValid || forceState)
if (!isValid || (forceState && isValid))
{
//
// Clear Other Conditions ...
@@ -3744,7 +3741,8 @@ public:
mBullishSigns,
mBearishScore,
mBearishSigns,
otherConditions //
otherConditions,
isValid //
);
continue;
}
@@ -4361,27 +4359,44 @@ private:
// EQM Functions ...
//
void DoEQMForceClose()
bool DoEQMForceClose(
double requiredProfit = 0 // Required Profit For EQM Force Hedge ...
)
{
//
bool canDo = mForceCloseProfit > 0;
bool result = false;
//
double hedgingProfit =
requiredProfit == 0
? mForceCloseProfit
: requiredProfit;
bool canDo = hedgingProfit > 0;
if (!canDo)
{
return;
return result;
}
//
XPosition positions[];
int positionsCount = mTrader.GetPositions(positions);
if (!IsValidSize(positionsCount))
result = IsValidSize(positionsCount);
if (!result)
{
return;
return result;
}
//
double profit = SpecifiedCalculatePositionsProfit(positions);
if (profit > 0 && profit > mForceCloseProfit)
result =
hedgingProfit > 0
? profit > 0 && profit > hedgingProfit
: profit <= hedgingProfit;
if (!result)
{
return result;
}
//
string comment = XEQMSupportToken + " Hedge ...";
int closed = Close(
@@ -4390,11 +4405,18 @@ private:
);
//
if (IsValidSize(closed))
{
result = IsValidSize(closed);
//
// Handle Sleeping ...
int restingTime = RestingAfterHedge();
if (result && IsValidSize(restingTime))
{
Sleep(restingTime * 1000);
}
}
//
return result;
}
//
@@ -4487,6 +4509,43 @@ private:
// Checking Force Sate Conditions ...
if (ForceState())
{
//
// Check Force State Hedging ...
bool isHedged = DoEQMForceClose(2);
if (isHedged)
{
//
ForceState(false);
return;
}
//
isHedged = DoEQMForceClose(1);
if (isHedged)
{
//
ForceState(false);
return;
}
//
isHedged = DoEQMForceClose(0.5);
if (isHedged)
{
//
ForceState(false);
return;
}
isHedged = DoEQMForceClose(0.3);
if (isHedged)
{
//
ForceState(false);
return;
}
//
return;
}
@@ -4532,7 +4591,47 @@ private:
;
if (isForceState)
{
//
ForceState(true);
//
return;
}
//
XPosition supports[];
int supportsCount = ExtractSupports(
positions,
supports //
);
if (!IsValidSize(supportsCount))
{
return;
}
//
int maxSupports = mTradeHandler.EnableSupport()
? MaxNumberOfSupports()
: 0;
int maxGrids = mTradeHandler.EnableGrid()
? MaxNumberOfGrids()
: 0;
int maxRecoveries = mTradeHandler.EnableRecovery()
? MaxNumberOfRecoveries()
: 0;
//
// Supporting Force States ...
bool isProtectionForce =
supportsCount >= 1;
// supportsCount >= (maxSupports + maxGrids + maxRecoveries);
if (isProtectionForce)
{
//
ForceState(true);
//
return;
}
//
@@ -4548,7 +4647,8 @@ private:
int bullishSigns, // Number of Bullish Signs
double bearishScore, // Bearish Score Summary
int bearishSigns, // Number of Bearish Signs
X121SetupConditions &conditions[] // All Time Frames Conditions
X121SetupConditions &conditions[], // All Time Frames Conditions
bool isValid = false // IsValid Signal ...
)
{
//
@@ -4559,199 +4659,7 @@ private:
}
//
// Create an Instance of Signal Generator Structure ...
X121SignalGenerator signalGenerator;
//
int signalConditionsIDX = FindSignalConditionsIndex(
signal,
conditions //
);
if (!IsValidIndex(signalConditionsIDX))
{
return;
}
//
int longValidations = 0;
int shortValidations = 0;
//
bool isOSCValidForLong = signalGenerator
.IsOSCLongVerified(conditions[signalConditionsIDX]);
bool isOSCValidForShort = signalGenerator
.IsOSCShortVerified(conditions[signalConditionsIDX]);
//
// Calculate Long/Short Validations ...
for (int i = 0; i < ArraySize(conditions); i++)
{
//
int longValids = signalGenerator
.CountLongValidations(conditions[i]);
longValidations += longValids;
//
int shortValids = signalGenerator
.CountShortValidations(conditions[i]);
shortValidations += shortValids;
}
//
bool isLong = IsLong(signal.type);
//
// Reading Required Informations ...
XPosition positions[];
int positionsCount = mTrader.GetPositions(positions);
if (!IsValidSize(positionsCount))
{
return;
}
//
int longs = 0;
double longVolumes = 0;
double longProfits = 0;
//
int shorts = 0;
double shortVolumes = 0;
double shortProfits = 0;
//
// Retrieve Required Informations of Positions ...
CountPositions(
positions,
longs,
longProfits,
longVolumes,
shorts,
shortProfits,
shortVolumes //
);
//
longVolumes = NormalizeDouble(longVolumes, 2);
shortVolumes = NormalizeDouble(shortVolumes, 2);
//
// Select Signal for Execution ...
bool canSelect =
//
((isLong &&
longProfits > 0 &&
bullishScore > 20)
//
||
//
(!isLong &&
shortProfits > 0 &&
bearishScore > 0))
//
&&
//
longVolumes == shortVolumes
//
;
if (canSelect)
{
//
// Here we Can do Signals SL TP Manipulations ...
signal.tp = 0;
signal.sl = 0;
//
XSignal signals[];
AddRef(
signal,
signals //
);
//
// Add new Signal Info ...
mTradeHandler.Add(
signal,
pushers,
volumeOSC,
bullishSigns,
bearishSigns,
bullishScore,
bearishScore,
conditions[0],
conditions[1],
conditions[2],
conditions[3],
conditions[4] //
);
//
EQMExecuteSignals(signals);
//
return;
}
//
canSelect =
//
((isLong && shortProfits > 0) ||
(!isLong && longProfits > 0))
//
&&
//
longVolumes == shortVolumes
//
;
if (canSelect)
{
//
// Generate Opposit Signal ...
//
signal.tp = 0;
signal.sl = 0;
//
XSignal oppositSignal;
bool isGenerated = signal.GenerateOpposit(
oppositSignal //
);
//
if (isGenerated)
{
//
XSignal signals[];
AddRef(
oppositSignal,
signals //
);
//
// Add new Signal Info ...
mTradeHandler.Add(
oppositSignal,
pushers,
volumeOSC,
bullishSigns,
bearishSigns,
bullishScore,
bearishScore,
conditions[0],
conditions[1],
conditions[2],
conditions[3],
conditions[4] //
);
//
EQMExecuteSignals(signals);
//
return;
}
}
// TODO: Implement it ...
}
//
+333
View File
@@ -1409,3 +1409,336 @@
// }
// }
// }
///////////////////////////////////////////////////////////////
//
// Create an Instance of Signal Generator Structure ...
X121SignalGenerator signalGenerator;
//
int signalConditionsIDX = FindSignalConditionsIndex(
signal,
conditions //
);
if (!IsValidIndex(signalConditionsIDX))
{
return;
}
//
int longValidations = 0;
int shortValidations = 0;
//
bool isOSCValidForLong = signalGenerator
.IsOSCLongVerified(conditions[signalConditionsIDX]);
bool isOSCValidForShort = signalGenerator
.IsOSCShortVerified(conditions[signalConditionsIDX]);
//
// Calculate Long/Short Validations ...
for (int i = 0; i < ArraySize(conditions); i++)
{
//
int longValids = signalGenerator
.CountLongValidations(conditions[i]);
longValidations += longValids;
//
int shortValids = signalGenerator
.CountShortValidations(conditions[i]);
shortValidations += shortValids;
}
//
bool isLong = IsLong(signal.type);
//
// Reading Required Informations ...
XPosition positions[];
int positionsCount = mTrader.GetPositions(positions);
if (!IsValidSize(positionsCount))
{
return;
}
//
int longs = 0;
double longVolumes = 0;
double longProfits = 0;
//
int shorts = 0;
double shortVolumes = 0;
double shortProfits = 0;
//
// Retrieve Required Informations of Positions ...
CountPositions(
positions,
longs,
longProfits,
longVolumes,
shorts,
shortProfits,
shortVolumes //
);
//
longVolumes = NormalizeDouble(longVolumes, 2);
shortVolumes = NormalizeDouble(shortVolumes, 2);
//
// Select Signal for Execution ...
bool canSelect =
//
((isLong &&
longProfits > 0 &&
bullishScore > 20)
//
||
//
(!isLong &&
shortProfits > 0 &&
bearishScore > 0))
//
&&
//
longVolumes == shortVolumes
//
;
if (canSelect)
{
//
// Here we Can do Signals SL TP Manipulations ...
signal.tp = 0;
signal.sl = 0;
//
XSignal signals[];
AddRef(
signal,
signals //
);
//
// Add new Signal Info ...
mTradeHandler.Add(
signal,
pushers,
volumeOSC,
bullishSigns,
bearishSigns,
bullishScore,
bearishScore,
conditions[0],
conditions[1],
conditions[2],
conditions[3],
conditions[4] //
);
//
EQMExecuteSignals(signals);
//
return;
}
//
canSelect =
//
((isLong && shortProfits > 0) ||
(!isLong && longProfits > 0))
//
&&
//
longVolumes == shortVolumes
//
;
if (canSelect)
{
//
// Generate Opposit Signal ...
//
signal.tp = 0;
signal.sl = 0;
//
XSignal oppositSignal;
bool isGenerated = signal.GenerateOpposit(
oppositSignal //
);
//
if (isGenerated)
{
//
XSignal signals[];
AddRef(
oppositSignal,
signals //
);
//
// Add new Signal Info ...
mTradeHandler.Add(
oppositSignal,
pushers,
volumeOSC,
bullishSigns,
bearishSigns,
bullishScore,
bearishScore,
conditions[0],
conditions[1],
conditions[2],
conditions[3],
conditions[4] //
);
//
EQMExecuteSignals(signals);
//
return;
}
}
////////////////////////////////////////////////////////////////////////
//
XPosition positions[];
int positionsCount = mTrader.GetPositions(positions);
if (!IsValidSize(positionsCount))
{
return;
}
//
int longs = 0;
double longVolumes = 0;
double longProfits = 0;
//
int shorts = 0;
double shortVolumes = 0;
double shortProfits = 0;
//
// Retrieve Required Informations of Positions ...
CountPositions(
positions,
longs,
longProfits,
longVolumes,
shorts,
shortProfits,
shortVolumes //
);
//
longVolumes = NormalizeDouble(longVolumes, 2);
shortVolumes = NormalizeDouble(shortVolumes, 2);
//
if (isValid)
{
//
// Ignore Hind Time Frame Signals ...
//
signal.volume *= 1;
//
// Here we Can do Signals SL TP Manipulations ...
signal.tp = 0;
signal.sl = 0;
//
signal.provider = XEQMSupportToken;
signal.comment = GenerateEQMSupportTag(0);
//
bool isLong = IsLong(signal.type);
//
bool canDirect =
//
(isLong &&
longProfits > shortProfits)
//
||
//
(!isLong &&
shortProfits > longProfits)
//
;
bool canInDirect =
//
(isLong &&
shortProfits > longProfits)
//
||
//
(!isLong &&
longProfits > shortProfits)
//
;
//
XSignal tmpSignal;
if (canDirect)
{
tmpSignal = signal;
}
else
{
//
bool isGenerated = signal.GenerateOpposit(
tmpSignal //
);
//
if (!isGenerated)
{
tmpSignal.Clean();
}
}
//
if (tmpSignal.IsValid())
{
//
XSignal signals[];
AddRef(
signal,
signals //
);
//
// Add new Signal Info ...
mTradeHandler.Add(
signal,
pushers,
volumeOSC,
bullishSigns,
bearishSigns,
bullishScore,
bearishScore,
conditions[0],
conditions[1],
conditions[2],
conditions[3],
conditions[4] //
);
//
EQMExecuteSignals(signals);
}
return;
}
+2 -2
View File
@@ -81,7 +81,7 @@ input double x121EAMaxAllowedSupportVolume = 0.8; // Max Allowed Support Signals
//
input group "Grid";
input bool x121EAAllowGrid = false; // Allow Grid Signals
input bool x121EAAllowGrid = true; // Allow Grid Signals
input int x121EAMaxNumberOfGrids = 5; // Max Number of Grid Signals
input double x121EAGridDistance = 100; // Grid Distance
input double x121EAGridVolumeMultiplier = 2.0; // Grid Volume Multiplier
@@ -90,7 +90,7 @@ input double x121EAMaxAllowedGridVolume = 0.8; // Max Allowed Grid Signals Volum
//
input group "Recovery";
input bool x121EAAllowRecovery = true; // Allow Recovery Signals
input int x121EAMaxNumberOfRecoveries = 2; // Max Number of Recovery Signals
input int x121EAMaxNumberOfRecoveries = 3; // Max Number of Recovery Signals
input double x121EARecoveryDistance = 100; // Recovery Distance
input double x121EARecoveryVolumeMultiplier = 2; // Recovery Volume Multiplier
input double x121EAMaxAllowedRecoveryVolume = 0.8; // Max Allowed Recovery Signals Volume