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
+138 -230
View File
@@ -681,9 +681,10 @@ struct XTradeInfo
: selectedEntry; : selectedEntry;
// //
double nextVolume = rLevel % 2 == 1 double nextVolume = selectedVolume * volumeMultiplier;
? volume // rLevel % 2 == 1
: volume * volumeMultiplier; // ? volume
// : volume * volumeMultiplier;
// //
double zoneUpper = double zoneUpper =
@@ -1855,11 +1856,7 @@ public:
// Trailling ... // Trailling ...
if (EnableTrailling()) if (EnableTrailling())
{ {
// int traillings = HandleTrailling();
if (!forceState)
{
int traillings = HandleTrailling();
}
} }
// //
@@ -3699,12 +3696,12 @@ public:
: signalGenerator.HasShortVerifications(otherConditions)) : signalGenerator.HasShortVerifications(otherConditions))
// //
; ;
// //
bool forceState = ForceState(); bool forceState = ForceState();
// //
if (!isValid || forceState) if (!isValid || (forceState && isValid))
{ {
// //
// Clear Other Conditions ... // Clear Other Conditions ...
@@ -3744,7 +3741,8 @@ public:
mBullishSigns, mBullishSigns,
mBearishScore, mBearishScore,
mBearishSigns, mBearishSigns,
otherConditions // otherConditions,
isValid //
); );
continue; continue;
} }
@@ -4361,40 +4359,64 @@ private:
// EQM Functions ... // 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) if (!canDo)
{ {
return; return result;
} }
// //
XPosition positions[]; XPosition positions[];
int positionsCount = mTrader.GetPositions(positions); int positionsCount = mTrader.GetPositions(positions);
if (!IsValidSize(positionsCount)) result = IsValidSize(positionsCount);
if (!result)
{ {
return; return result;
} }
// //
double profit = SpecifiedCalculatePositionsProfit(positions); 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(
positions,
comment //
);
//
if (IsValidSize(closed))
{
//
}
} }
//
string comment = XEQMSupportToken + " Hedge ...";
int closed = Close(
positions,
comment //
);
//
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 ... // Checking Force Sate Conditions ...
if (ForceState()) 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; return;
} }
@@ -4532,7 +4591,47 @@ private:
; ;
if (isForceState) if (isForceState)
{ {
//
ForceState(true); 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;
} }
// //
@@ -4541,14 +4640,15 @@ private:
// //
// Handle any Invalid Signals ... // Handle any Invalid Signals ...
void EQMHandleInvalidSignal( void EQMHandleInvalidSignal(
XSignal &signal, // Invalid Signal XSignal &signal, // Invalid Signal
int pushers, // Pushers int pushers, // Pushers
double volumeOSC, // Volume Summary of Signal double volumeOSC, // Volume Summary of Signal
double bullishScore, // Bullish Score Summary double bullishScore, // Bullish Score Summary
int bullishSigns, // Number of Bullish Signs int bullishSigns, // Number of Bullish Signs
double bearishScore, // Bearish Score Summary double bearishScore, // Bearish Score Summary
int bearishSigns, // Number of Bearish Signs 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 ... // TODO: Implement it ...
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;
}
}
} }
// //
+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;
}
+3 -3
View File
@@ -81,7 +81,7 @@ input double x121EAMaxAllowedSupportVolume = 0.8; // Max Allowed Support Signals
// //
input group "Grid"; 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 int x121EAMaxNumberOfGrids = 5; // Max Number of Grid Signals
input double x121EAGridDistance = 100; // Grid Distance input double x121EAGridDistance = 100; // Grid Distance
input double x121EAGridVolumeMultiplier = 2.0; // Grid Volume Multiplier input double x121EAGridVolumeMultiplier = 2.0; // Grid Volume Multiplier
@@ -89,8 +89,8 @@ input double x121EAMaxAllowedGridVolume = 0.8; // Max Allowed Grid Signals Volum
// //
input group "Recovery"; input group "Recovery";
input bool x121EAAllowRecovery = true; // Allow Recovery Signals 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 x121EARecoveryDistance = 100; // Recovery Distance
input double x121EARecoveryVolumeMultiplier = 2; // Recovery Volume Multiplier input double x121EARecoveryVolumeMultiplier = 2; // Recovery Volume Multiplier
input double x121EAMaxAllowedRecoveryVolume = 0.8; // Max Allowed Recovery Signals Volume input double x121EAMaxAllowedRecoveryVolume = 0.8; // Max Allowed Recovery Signals Volume