last works on Force State Management ...
This commit is contained in:
@@ -2061,16 +2061,13 @@ struct X121SignalGenerator
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
bool IsConditionsValidForLong(
|
// Count Number of Long Validations ...
|
||||||
X121SetupConditions &conditions, // Conditions
|
int CountLongValidations(
|
||||||
int verification = 4 // Number of Verifications
|
X121SetupConditions &conditions // Conditions
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
bool result = false;
|
int result = 0;
|
||||||
|
|
||||||
//
|
|
||||||
int signs = 0;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// XTD ...
|
// XTD ...
|
||||||
@@ -2082,7 +2079,7 @@ struct X121SignalGenerator
|
|||||||
;
|
;
|
||||||
if (isTDPassed)
|
if (isTDPassed)
|
||||||
{
|
{
|
||||||
signs++;
|
result++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -2100,7 +2097,7 @@ struct X121SignalGenerator
|
|||||||
;
|
;
|
||||||
if (isHKPassed)
|
if (isHKPassed)
|
||||||
{
|
{
|
||||||
signs++;
|
result++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -2115,7 +2112,7 @@ struct X121SignalGenerator
|
|||||||
;
|
;
|
||||||
if (isCHEPassed)
|
if (isCHEPassed)
|
||||||
{
|
{
|
||||||
signs++;
|
result++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -2142,7 +2139,7 @@ struct X121SignalGenerator
|
|||||||
;
|
;
|
||||||
if (isICHPassed)
|
if (isICHPassed)
|
||||||
{
|
{
|
||||||
signs++;
|
result++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -2155,7 +2152,7 @@ struct X121SignalGenerator
|
|||||||
;
|
;
|
||||||
if (isSTRPassed)
|
if (isSTRPassed)
|
||||||
{
|
{
|
||||||
signs++;
|
result++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -2168,7 +2165,7 @@ struct X121SignalGenerator
|
|||||||
;
|
;
|
||||||
if (isMRBPassed)
|
if (isMRBPassed)
|
||||||
{
|
{
|
||||||
signs++;
|
result++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -2182,7 +2179,7 @@ struct X121SignalGenerator
|
|||||||
;
|
;
|
||||||
if (isVLMPassed)
|
if (isVLMPassed)
|
||||||
{
|
{
|
||||||
signs++;
|
result++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -2195,7 +2192,7 @@ struct X121SignalGenerator
|
|||||||
;
|
;
|
||||||
if (isSSLCPassed)
|
if (isSSLCPassed)
|
||||||
{
|
{
|
||||||
signs++;
|
result++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -2210,7 +2207,7 @@ struct X121SignalGenerator
|
|||||||
;
|
;
|
||||||
if (isHULLPassed)
|
if (isHULLPassed)
|
||||||
{
|
{
|
||||||
signs++;
|
result++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -2224,7 +2221,7 @@ struct X121SignalGenerator
|
|||||||
;
|
;
|
||||||
if (isADXTDPassed)
|
if (isADXTDPassed)
|
||||||
{
|
{
|
||||||
signs++;
|
result++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -2252,13 +2249,31 @@ struct X121SignalGenerator
|
|||||||
;
|
;
|
||||||
if (isMATDPassed)
|
if (isMATDPassed)
|
||||||
{
|
{
|
||||||
signs++;
|
result++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool IsConditionsValidForLong(
|
||||||
|
X121SetupConditions &conditions, // Conditions
|
||||||
|
int verifications = 4 // Number of Verifications
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
int signs = CountLongValidations(conditions);
|
||||||
|
|
||||||
//
|
//
|
||||||
result =
|
result =
|
||||||
//
|
//
|
||||||
signs > verification
|
verifications <= 0
|
||||||
|
? signs > 0
|
||||||
|
: signs >= verifications
|
||||||
//
|
//
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -2303,16 +2318,12 @@ struct X121SignalGenerator
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
bool IsConditionsValidForShort(
|
int CountShortValidations(
|
||||||
X121SetupConditions &conditions, // Conditions
|
X121SetupConditions &conditions // Conditions
|
||||||
int verification = 4 // Number of Verifications
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
bool result = false;
|
int result = 0;
|
||||||
|
|
||||||
//
|
|
||||||
int signs = 0;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// XTD ...
|
// XTD ...
|
||||||
@@ -2324,7 +2335,7 @@ struct X121SignalGenerator
|
|||||||
;
|
;
|
||||||
if (isTDPassed)
|
if (isTDPassed)
|
||||||
{
|
{
|
||||||
signs++;
|
result++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -2342,7 +2353,7 @@ struct X121SignalGenerator
|
|||||||
;
|
;
|
||||||
if (isHKPassed)
|
if (isHKPassed)
|
||||||
{
|
{
|
||||||
signs++;
|
result++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -2357,7 +2368,7 @@ struct X121SignalGenerator
|
|||||||
;
|
;
|
||||||
if (isCHEPassed)
|
if (isCHEPassed)
|
||||||
{
|
{
|
||||||
signs++;
|
result++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -2384,7 +2395,7 @@ struct X121SignalGenerator
|
|||||||
;
|
;
|
||||||
if (isICHPassed)
|
if (isICHPassed)
|
||||||
{
|
{
|
||||||
signs++;
|
result++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -2397,7 +2408,7 @@ struct X121SignalGenerator
|
|||||||
;
|
;
|
||||||
if (isSTRPassed)
|
if (isSTRPassed)
|
||||||
{
|
{
|
||||||
signs++;
|
result++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -2410,7 +2421,7 @@ struct X121SignalGenerator
|
|||||||
;
|
;
|
||||||
if (isMRBPassed)
|
if (isMRBPassed)
|
||||||
{
|
{
|
||||||
signs++;
|
result++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -2424,7 +2435,7 @@ struct X121SignalGenerator
|
|||||||
;
|
;
|
||||||
if (isVLMPassed)
|
if (isVLMPassed)
|
||||||
{
|
{
|
||||||
signs++;
|
result++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -2437,7 +2448,7 @@ struct X121SignalGenerator
|
|||||||
;
|
;
|
||||||
if (isSSLCPassed)
|
if (isSSLCPassed)
|
||||||
{
|
{
|
||||||
signs++;
|
result++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -2452,7 +2463,7 @@ struct X121SignalGenerator
|
|||||||
;
|
;
|
||||||
if (isHULLPassed)
|
if (isHULLPassed)
|
||||||
{
|
{
|
||||||
signs++;
|
result++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -2466,7 +2477,7 @@ struct X121SignalGenerator
|
|||||||
;
|
;
|
||||||
if (isADXTDPassed)
|
if (isADXTDPassed)
|
||||||
{
|
{
|
||||||
signs++;
|
result++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -2494,13 +2505,31 @@ struct X121SignalGenerator
|
|||||||
;
|
;
|
||||||
if (isMATDPassed)
|
if (isMATDPassed)
|
||||||
{
|
{
|
||||||
signs++;
|
result++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool IsConditionsValidForShort(
|
||||||
|
X121SetupConditions &conditions, // Conditions
|
||||||
|
int verifications = 4 // Number of Verifications
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
int signs = CountShortValidations(conditions);
|
||||||
|
|
||||||
//
|
//
|
||||||
result =
|
result =
|
||||||
//
|
//
|
||||||
signs > verification
|
verifications <= 0
|
||||||
|
? signs > 0
|
||||||
|
: signs >= verifications
|
||||||
//
|
//
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -3410,3 +3439,52 @@ private:
|
|||||||
// Props ...
|
// Props ...
|
||||||
X121SetupInputs inputs; // Setup Configurations ...
|
X121SetupInputs inputs; // Setup Configurations ...
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Tools ...
|
||||||
|
|
||||||
|
//
|
||||||
|
int FindSignalConditionsIndex(
|
||||||
|
XSignal &signal,
|
||||||
|
X121SetupConditions &conditions[] //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = -1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Signal is Valid ...
|
||||||
|
if (!signal.IsValid())
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Conditions Count ...
|
||||||
|
int conditionsCount = ArraySize(conditions);
|
||||||
|
if (!IsValidSize(conditionsCount))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
for (int i = 0; i < conditionsCount; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
X121SetupConditions iConditions = conditions[i];
|
||||||
|
|
||||||
|
//
|
||||||
|
if (signal.symbol == iConditions.symbol &&
|
||||||
|
signal.period == iConditions.period)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
result = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
@@ -681,7 +681,9 @@ struct XTradeInfo
|
|||||||
: selectedEntry;
|
: selectedEntry;
|
||||||
|
|
||||||
//
|
//
|
||||||
double nextVolume = selectedVolume * volumeMultiplier;
|
double nextVolume = rLevel % 2 == 1
|
||||||
|
? volume
|
||||||
|
: volume * volumeMultiplier;
|
||||||
|
|
||||||
//
|
//
|
||||||
double zoneUpper =
|
double zoneUpper =
|
||||||
@@ -821,15 +823,15 @@ struct XTradeInfo
|
|||||||
string comment = GenerateSupportTag(ticket);
|
string comment = GenerateSupportTag(ticket);
|
||||||
signal.comment = comment;
|
signal.comment = comment;
|
||||||
|
|
||||||
|
//
|
||||||
|
rLevel++;
|
||||||
|
|
||||||
//
|
//
|
||||||
PrepareNextRecovery(
|
PrepareNextRecovery(
|
||||||
distance,
|
distance,
|
||||||
volumeMultiplier,
|
volumeMultiplier,
|
||||||
rType //
|
rType //
|
||||||
);
|
);
|
||||||
|
|
||||||
//
|
|
||||||
rLevel++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -1838,8 +1840,9 @@ public:
|
|||||||
//
|
//
|
||||||
// Handle Do All Protecting ...
|
// Handle Do All Protecting ...
|
||||||
int DoProtect(
|
int DoProtect(
|
||||||
XSignal &signals[], // if PRotecting Generate Some Support Signals, Holds them here
|
XSignal &signals[], // if PRotecting Generate Some Support Signals, Holds them here
|
||||||
XSCX121SetupCycles *&setups[] // Number of Setups
|
XSCX121SetupCycles *&setups[], // Number of Setups
|
||||||
|
bool forceState = false //
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -1853,7 +1856,10 @@ public:
|
|||||||
if (EnableTrailling())
|
if (EnableTrailling())
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
int traillings = HandleTrailling();
|
if (!forceState)
|
||||||
|
{
|
||||||
|
int traillings = HandleTrailling();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -3070,6 +3076,18 @@ public:
|
|||||||
mForceCloseProfit = value;
|
mForceCloseProfit = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool ForceState()
|
||||||
|
{
|
||||||
|
return mForceState;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
void ForceState(bool value)
|
||||||
|
{
|
||||||
|
mForceState = value;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Overrides ...
|
// Overrides ...
|
||||||
|
|
||||||
@@ -3683,34 +3701,81 @@ public:
|
|||||||
;
|
;
|
||||||
|
|
||||||
//
|
//
|
||||||
if (!isValid)
|
bool forceState = ForceState();
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!isValid || forceState)
|
||||||
{
|
{
|
||||||
|
//
|
||||||
|
// Clear Other Conditions ...
|
||||||
|
Clean(otherConditions);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Fill All Conditions to Other Conditions ...
|
||||||
|
AddRef(
|
||||||
|
cConditions,
|
||||||
|
otherConditions //
|
||||||
|
);
|
||||||
|
AddRef(
|
||||||
|
sConditions,
|
||||||
|
otherConditions //
|
||||||
|
);
|
||||||
|
AddRef(
|
||||||
|
mConditions,
|
||||||
|
otherConditions //
|
||||||
|
);
|
||||||
|
AddRef(
|
||||||
|
lConditions,
|
||||||
|
otherConditions //
|
||||||
|
);
|
||||||
|
AddRef(
|
||||||
|
hConditions,
|
||||||
|
otherConditions //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// If Recieved Any Unverified Signal
|
||||||
|
// we Passed it to EQM Manager ...
|
||||||
|
EQMHandleInvalidSignal(
|
||||||
|
signal,
|
||||||
|
pushers,
|
||||||
|
mVolumeOSC,
|
||||||
|
mBullishScore,
|
||||||
|
mBullishSigns,
|
||||||
|
mBearishScore,
|
||||||
|
mBearishSigns,
|
||||||
|
otherConditions //
|
||||||
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Add Signal to Execution Result ...
|
if (!forceState)
|
||||||
AddRef(
|
{
|
||||||
signal,
|
//
|
||||||
signals //
|
// Add Signal to Execution Result ...
|
||||||
);
|
AddRef(
|
||||||
|
signal,
|
||||||
|
signals //
|
||||||
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Add new Signal Info ...
|
// Add new Signal Info ...
|
||||||
mTradeHandler.Add(
|
mTradeHandler.Add(
|
||||||
signal,
|
signal,
|
||||||
pushers,
|
pushers,
|
||||||
mVolumeOSC,
|
mVolumeOSC,
|
||||||
mBullishSigns,
|
mBullishSigns,
|
||||||
mBearishSigns,
|
mBearishSigns,
|
||||||
mBullishScore,
|
mBullishScore,
|
||||||
mBearishScore,
|
mBearishScore,
|
||||||
cConditions,
|
cConditions,
|
||||||
sConditions,
|
sConditions,
|
||||||
mConditions,
|
mConditions,
|
||||||
lConditions,
|
lConditions,
|
||||||
hConditions //
|
hConditions //
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4122,6 +4187,15 @@ private:
|
|||||||
int mCloseOnSpecificTime; // Close All Trades in Specific Time
|
int mCloseOnSpecificTime; // Close All Trades in Specific Time
|
||||||
int mStartSignallingHoure; // Start Signalling at Specific Time
|
int mStartSignallingHoure; // Start Signalling at Specific Time
|
||||||
|
|
||||||
|
//
|
||||||
|
// Force State:
|
||||||
|
// we can do many things in force state:
|
||||||
|
// - Prepare Force Hedging;
|
||||||
|
// - Receive Signals with minimal Verifications;
|
||||||
|
// - Increase Volume Size of in Profit Positions;
|
||||||
|
// - etc ...
|
||||||
|
bool mForceState; // Determine in Force State or not
|
||||||
|
|
||||||
//
|
//
|
||||||
XTradeHandler *mTradeHandler; // Handle all Event which related to Signals and Positions
|
XTradeHandler *mTradeHandler; // Handle all Event which related to Signals and Positions
|
||||||
|
|
||||||
@@ -4327,11 +4401,20 @@ private:
|
|||||||
// Do Gridding Mechanism ...
|
// Do Gridding Mechanism ...
|
||||||
void DoEQMProtect()
|
void DoEQMProtect()
|
||||||
{
|
{
|
||||||
|
//
|
||||||
|
// Check if there are open Positions
|
||||||
|
// and their doesn't have TP and SL and
|
||||||
|
// Youngest Age of Positions longest as enough
|
||||||
|
// Make State of Signalling to Force State for Recieving
|
||||||
|
// Signal and Clear their Tp and SL for allowing hedges ...
|
||||||
|
EQMHandleForceState();
|
||||||
|
|
||||||
//
|
//
|
||||||
XSignal supports[];
|
XSignal supports[];
|
||||||
int supportsCount = mTradeHandler.DoProtect(
|
int supportsCount = mTradeHandler.DoProtect(
|
||||||
supports,
|
supports,
|
||||||
mSetups //
|
mSetups,
|
||||||
|
ForceState() //
|
||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -4341,35 +4424,6 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
void EQMExecuteSignals(
|
|
||||||
XSignal &signals[] //
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int signalsCount = ArraySize(signals);
|
|
||||||
if (!IsValidSize(signals))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Execute Supports ...
|
|
||||||
ENUM_X_SIGNAL_EXECUTION_RESULT states[];
|
|
||||||
int executed = ExecuteSignals(
|
|
||||||
signals,
|
|
||||||
states,
|
|
||||||
false // Ignore Policies ...
|
|
||||||
);
|
|
||||||
if (executed != signalsCount)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// TODO: Dow What We Want ...
|
|
||||||
// Print("Error On Executing Support Signal ...");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Handle Close Trades on Specific Time ...
|
// Handle Close Trades on Specific Time ...
|
||||||
void DoEQMCloseOnSpecificTime()
|
void DoEQMCloseOnSpecificTime()
|
||||||
@@ -4406,6 +4460,376 @@ private:
|
|||||||
Alert(message);
|
Alert(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handle Force State Management ...
|
||||||
|
void EQMHandleForceState()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
XPosition positions[];
|
||||||
|
int positionsCount = mTrader.GetPositions(positions);
|
||||||
|
if (!IsValidSize(positionsCount))
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Disable Force State if there isn't any open Positions
|
||||||
|
// and it's Enabled ...
|
||||||
|
// this means Hedged positions ...
|
||||||
|
if (ForceState())
|
||||||
|
{
|
||||||
|
ForceState(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Checking Force Sate Conditions ...
|
||||||
|
if (ForceState())
|
||||||
|
{
|
||||||
|
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 //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Youngest Age ...
|
||||||
|
XPosition youngest;
|
||||||
|
int youngestAge = GetYoungest(
|
||||||
|
youngest,
|
||||||
|
positions //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Now Comparing items for enabling force State ...
|
||||||
|
bool isForceState =
|
||||||
|
//
|
||||||
|
longs > 0 &&
|
||||||
|
shorts > 0 &&
|
||||||
|
youngestAge >= 20 && // TODO: Make this Configurable ...
|
||||||
|
longVolumes == shortVolumes
|
||||||
|
//
|
||||||
|
;
|
||||||
|
if (isForceState)
|
||||||
|
{
|
||||||
|
ForceState(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handle any Invalid Signals ...
|
||||||
|
void EQMHandleInvalidSignal(
|
||||||
|
XSignal &signal, // Invalid Signal
|
||||||
|
int pushers, // Pushers
|
||||||
|
double volumeOSC, // Volume Summary of Signal
|
||||||
|
double bullishScore, // Bullish Score Summary
|
||||||
|
int bullishSigns, // Number of Bullish Signs
|
||||||
|
double bearishScore, // Bearish Score Summary
|
||||||
|
int bearishSigns, // Number of Bearish Signs
|
||||||
|
X121SetupConditions &conditions[] // All Time Frames Conditions
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Check Force State ...
|
||||||
|
if (!ForceState())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
void EQMExecuteSignals(
|
||||||
|
XSignal &signals[] //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int signalsCount = ArraySize(signals);
|
||||||
|
if (!IsValidSize(signals))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Execute Supports ...
|
||||||
|
ENUM_X_SIGNAL_EXECUTION_RESULT states[];
|
||||||
|
int executed = ExecuteSignals(
|
||||||
|
signals,
|
||||||
|
states,
|
||||||
|
false // Ignore Policies ...
|
||||||
|
);
|
||||||
|
if (executed != signalsCount)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// TODO: Dow What We Want ...
|
||||||
|
// Print("Error On Executing Support Signal ...");
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Remove Supported Signals TP and SL and leave them for Handling using HEDGE Mechanism ...
|
||||||
|
if (IsValidSize(executed))
|
||||||
|
{
|
||||||
|
//
|
||||||
|
for (int i = 0; i < signalsCount; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
ENUM_X_SIGNAL_EXECUTION_RESULT iState = states[i];
|
||||||
|
if (iState != X_SIGNAL_EXECUTION_SUCCEED)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
XSignal iSignal = signals[i];
|
||||||
|
if (!iSignal.IsValid() || !iSignal.IsExecuted())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
ulong iParentTicket = ExtractParentTicket(iSignal.comment);
|
||||||
|
if (iParentTicket <= 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Remove TP and SL of Supported Positions ...
|
||||||
|
string comment = "EQM Remove TPSL ...";
|
||||||
|
bool isModified = Modify(
|
||||||
|
iParentTicket,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
comment //
|
||||||
|
);
|
||||||
|
if (isModified)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// TODO:
|
||||||
|
// do What we want ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ input bool x121EAIgnoreTP = false; // Ignore Calculated TP
|
|||||||
//
|
//
|
||||||
// Protection ...
|
// Protection ...
|
||||||
input group "Signalling";
|
input group "Signalling";
|
||||||
input int x121EAStartSignallingHoure = 0; // Start Signalling at Specific Time
|
input int x121EAStartSignallingHoure = 3; // Start Signalling at Specific Time
|
||||||
input int x121EAEndSignallingHoure = 22; // End Signalling at Specific Time
|
input int x121EAEndSignallingHoure = 22; // End Signalling at Specific Time
|
||||||
input int x121EACloseOnSpecificTime = -1; // Close All Trades in Specific Time
|
input int x121EACloseOnSpecificTime = -1; // Close All Trades in Specific Time
|
||||||
input bool x121EACloseOnOpposit = false; // Close all Positions on Opposit
|
input bool x121EACloseOnOpposit = false; // Close all Positions on Opposit
|
||||||
|
|||||||
@@ -4181,6 +4181,32 @@ bool IsSupport(string value)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
ulong ExtractParentTicket(string value)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
ulong result = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!IsSupport(value))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = ExtractSupportedTicket(value);
|
||||||
|
if (result > 0)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = ExtractEQMSupportedTicket(value);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// SL Trails ...
|
// SL Trails ...
|
||||||
|
|
||||||
@@ -4482,14 +4508,14 @@ void CountPositions(
|
|||||||
//
|
//
|
||||||
longs++;
|
longs++;
|
||||||
longProfits += iPosition.profit;
|
longProfits += iPosition.profit;
|
||||||
longVolumes = iPosition.volume;
|
longVolumes += iPosition.volume;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
shorts++;
|
shorts++;
|
||||||
shortProfits += iPosition.profit;
|
shortProfits += iPosition.profit;
|
||||||
shortVolumes = iPosition.volume;
|
shortVolumes += iPosition.volume;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user