This commit is contained in:
2024-06-28 21:05:22 +03:30
parent 7af4e614b5
commit 35e8d63f94
2 changed files with 254 additions and 307 deletions
+246 -303
View File
@@ -4274,7 +4274,8 @@ public:
; ;
// //
bool forceState = mSetups[i].ForceState(); // bool forceState = mSetups[i].ForceState();
bool forceState = mForce;
// //
if (!forceState) if (!forceState)
@@ -4885,8 +4886,16 @@ protected:
Alert(message); Alert(message);
// //
mForce = true;
//
EQMHandleInvalidSignal();
return; return;
} }
else
{
mForce = false;
}
// //
bool executeOnBreakouts = ExecuteSignalsOnBreakout(); bool executeOnBreakouts = ExecuteSignalsOnBreakout();
@@ -4990,203 +4999,6 @@ protected:
return result; return result;
} }
//
// Private ...
private:
//
// Props ...
//
// Signals ...
bool mAllowLong; // Allow Long
bool mAllowShort; // Allow Short
int mReuiredSignalVerifications; // Required Verifications for Validate Signals
bool mExecuteSignalsOnBreakout; // Execute Signals On Breakouts
bool mGetVerificationFromOtherTimeFrames; // Get Verifications from Other Time Frames
//
// Risk Management ...
double mVolume; // Volume
double mTPPoint; // TP Point
double mSLPoint; // SL Point
bool mIgnoreTP; // Ignore Calculated TP
bool mIgnoreSL; // Ignore Calculated SL
int mMaxAllowedTrades; // Max Alloed Positions
bool mUseMaxAllowedPerDirection; // Use Max Allowed Positions Per Direction
bool mIncreaseNextSignalsVolume; // Increase Next Signals Volume
double mIncreaseNextSignalsVolumeMultiplier; // Increase Next Signals Volume Multiplier
bool mAcceptNextDirectionalSignalsWhenFirstInProfit; // Accept Same Symbol/Type Signal when Last in Profit
//
// Signalling ...
bool mCloseOnOpposit; // Close all Positions on Opposit
int mEndSignallingHoure; // End Signalling at Specific Time
int mCloseOnSpecificTime; // Close All Trades in 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
double mMaxDrawdownForce; // Force Handling State on Drawdown for Guard
int mDelayBetweenTwoSignal; // Delay between two same signal
double mMinFreeMargingForOpenTrades; // Min Free Margin for Open Trades
//
XTradeHandler *mTradeHandler; // Handle all Event which related to Signals and Positions
//
// Apply Default Configurations ...
void DefaultConfigs()
{
//
// Signals ...
AllowLong(false);
AllowShort(false);
ReuiredSignalVerifications(0);
GetVerificationFromOtherTimeFrames(false);
//
// Risk Management ...
TPPoint(0);
SLPoint(0);
Volume(0.01);
IgnoreTP(false);
IgnoreSL(false);
MaxAllowedTrades(0);
//
// Signalling ...
CloseOnOpposit(false);
EndSignallingHoure(-1);
CloseOnSpecificTime(-1);
StartSignallingHoure(-1);
//
// Trailling ...
AllowTrailStop(false);
NextTrailPoint(0);
FirstTrailPoint(0);
NextTrailDistance(0);
FirstTrailDistance(0);
//
// Supporting ...
AllowSupport(false);
MaxNumberOfSupports(0);
SupportVolumeMultiplier(0.01);
MaxAllowedSupportVolume(0.08);
//
// Grid ...
AllowGrid(false);
GridDistance(0);
MaxNumberOfGrids(0);
GridVolumeMultiplier(0.01);
MaxAllowedGridVolume(0.08);
//
// Recovery ...
AllowRecovery(false);
MaxNumberOfRecoveries(0);
RecoveryDistance(0);
RecoveryVolumeMultiplier(0.01);
MaxAllowedRecoveryVolume(0.08);
//
SaveResults(false);
SaveSignalsOnly(true);
}
//
XSCX121SetupCycles *mSetups[]; // Number of Setups
//
// Tools ...
int CountSetups()
{
return ArraySize(mSetups);
}
//
int FindSetupIndex(
string symbol,
ENUM_TIMEFRAMES period //
)
{
//
int result = -1;
//
int count = CountSetups();
if (!IsValidSize(count))
{
return result;
}
//
for (int i = 0; i < count; i++)
{
//
XSCX121SetupCycles *iSetup = mSetups[i];
//
X121SetupInputs iInputs = iSetup.GetInputs();
//
if (iInputs.symbol == symbol && iInputs.period == period)
{
//
result = i;
break;
}
}
//
return result;
}
//
int FindSetupIndex(
string symbol //
)
{
//
int result = -1;
//
int count = CountSetups();
if (!IsValidSize(count))
{
return result;
}
//
for (int i = 0; i < count; i++)
{
//
XSCX121SetupCycles *iSetup = mSetups[i];
//
X121SetupInputs iInputs = iSetup.GetInputs();
//
if (iInputs.symbol == symbol)
{
//
result = i;
break;
}
}
//
return result;
}
// //
// EQM Functions ... // EQM Functions ...
@@ -5240,7 +5052,7 @@ private:
} }
// //
// Do Gridding Mechanism ... // Do All Protecting Mechanism ...
void DoEQMProtect() void DoEQMProtect()
{ {
// //
@@ -5294,105 +5106,10 @@ private:
} }
} }
//
// Handle Force State Management ...
bool mForce;
void EQMHandleForceState(XSignal &forceSignals[])
{
//
// Validate Force Marigin ...
// double marigin = mTrader.mAccount.GetMargin();
// double minFreeMarigin = MinFreeMargingForOpenTrades();
// double forceMargin = 3 * minFreeMarigin; // TODO: Make It Configurable
//
// Retrieving Positions ...
// XPosition positions[];
// int positionsCount = mTrader.GetPositions(positions);
// if (!IsValidSize(positionsCount))
// {
// //
// mForce = false;
// //
// datetime cTime = TimeCurrent();
// string message = "Exit From Force State: " + ToString(cTime);
// //
// // Log(message);
// return;
// }
// //
// XPosition oldest;
// int oldestAge = GetOldest(
// oldest,
// positions //
// );
// //
// // Check Force State ...
// bool isForce = marigin >= forceMargin && oldestAge >= 288;
// if (!isForce)
// {
// //
// if (mForce)
// {
// //
// mForce = false;
// //
// datetime cTime = TimeCurrent();
// string message = "Exit From Force State: " + ToString(cTime);
// //
// // Log(message);
// }
// return;
// }
// else
// {
// mForce = true;
// }
// //
// // Prevent Moving Forward From Non Force State ...
// if (!mForce)
// {
// return;
// }
// //
// double minProfitPerTrade = MinProfitPerTrade();
// double minProfitPerVolumeFactor = MinProfitPerVolumeFactor();
// //
// double profit = SpecifiedCalculatePositionsProfit(positions);
// double requiredProfit = SpecifiedCalculateRequiredProfitForHedge(
// positions,
// minProfitPerTrade,
// minProfitPerVolumeFactor //
// );
// //
// XSymbolPositions symbolPositions[];
// int symbolPositionsCount = ExtractSymbolPositions(
// positions,
// symbolPositions,
// minProfitPerTrade,
// minProfitPerVolumeFactor //
// );
// if (!IsValidSize(symbolPositionsCount))
// {
// return;
// }
//
// Log("symbolPositionsCount: " + ToString(symbolPositionsCount));
}
// //
// Handle any Invalid Signals ... // Handle any Invalid Signals ...
// this Signals passed From Request For Signal Function ...
// these need to add to Trade Handler ....
void EQMHandleInvalidSignal( void EQMHandleInvalidSignal(
XSignal &signal, // Invalid Signal XSignal &signal, // Invalid Signal
int pushers, // Pushers int pushers, // Pushers
@@ -5400,13 +5117,6 @@ private:
X121SetupConditions &conditions[] // All Time Frames Conditions X121SetupConditions &conditions[] // All Time Frames Conditions
) )
{ {
//
// Check Force State ...
// if (!ForceState())
// {
// return;
// }
// //
int setupIDX = FindSetupIndex(signal.symbol); int setupIDX = FindSetupIndex(signal.symbol);
if (!IsValidIndex(setupIDX)) if (!IsValidIndex(setupIDX))
@@ -5482,6 +5192,35 @@ private:
} }
// //
// When Margin not passed and Happens an Invalid Signal
// HandleSignals Functions passed Signals to this Method ...
// these Signals Added to Trade Handler Before ...
void EQMHandleForceSignals(
XSignal &signals[] //
)
{
//
if (!mForce)
{
return;
}
//
int count = ArraySize(signals);
if (!IsValidSize(count))
{
return;
}
//
// TODO:
// Implement what we want ...
}
//
// Execute Signals which Provided through
// EQM Protecting Senarios and must be Executed withouth
// any Policies ...
void EQMExecuteSignals( void EQMExecuteSignals(
XSignal &signals[] // XSignal &signals[] //
) )
@@ -5575,6 +5314,7 @@ private:
} }
// //
// Clear All Force States of Setups ...
void EQMClearAllForceStates() void EQMClearAllForceStates()
{ {
// //
@@ -5591,6 +5331,209 @@ private:
} }
} }
//
// Private ...
private:
//
// Props ...
//
// Signals ...
bool mAllowLong; // Allow Long
bool mAllowShort; // Allow Short
int mReuiredSignalVerifications; // Required Verifications for Validate Signals
bool mExecuteSignalsOnBreakout; // Execute Signals On Breakouts
bool mGetVerificationFromOtherTimeFrames; // Get Verifications from Other Time Frames
//
// Risk Management ...
double mVolume; // Volume
double mTPPoint; // TP Point
double mSLPoint; // SL Point
bool mIgnoreTP; // Ignore Calculated TP
bool mIgnoreSL; // Ignore Calculated SL
int mMaxAllowedTrades; // Max Alloed Positions
bool mUseMaxAllowedPerDirection; // Use Max Allowed Positions Per Direction
bool mIncreaseNextSignalsVolume; // Increase Next Signals Volume
double mIncreaseNextSignalsVolumeMultiplier; // Increase Next Signals Volume Multiplier
bool mAcceptNextDirectionalSignalsWhenFirstInProfit; // Accept Same Symbol/Type Signal when Last in Profit
//
// Signalling ...
bool mCloseOnOpposit; // Close all Positions on Opposit
int mEndSignallingHoure; // End Signalling at Specific Time
int mCloseOnSpecificTime; // Close All Trades in 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 mForce; // Determine in Force State or not
int mDelayBetweenTwoSignal; // Delay between two same signal
double mMinFreeMargingForOpenTrades; // Min Free Margin for Open Trades
//
XSCX121SetupCycles *mSetups[]; // Number of Setups
XTradeHandler *mTradeHandler; // Handle all Event which related to Signals and Positions
//
// Apply Default Configurations ...
void DefaultConfigs()
{
//
// Signals ...
AllowLong(false);
AllowShort(false);
ReuiredSignalVerifications(0);
GetVerificationFromOtherTimeFrames(false);
//
// Risk Management ...
TPPoint(0);
SLPoint(0);
Volume(0.01);
IgnoreTP(false);
IgnoreSL(false);
MaxAllowedTrades(0);
UseMaxAllowedPerDirection(false);
IncreaseNextSignalsVolume(false);
IncreaseNextSignalsVolumeMultiplier(1);
AcceptNextDirectionalSignalsWhenFirstInProfit(false);
//
// Signalling ...
CloseOnOpposit(false);
EndSignallingHoure(-1);
CloseOnSpecificTime(-1);
StartSignallingHoure(-1);
//
// Trailling ...
AllowTrailStop(false);
NextTrailPoint(0);
FirstTrailPoint(0);
NextTrailDistance(0);
FirstTrailDistance(0);
//
// Supporting ...
AllowSupport(false);
MaxNumberOfSupports(0);
SupportOnlyForces(false);
SupportVolumeMultiplier(0.01);
MaxAllowedSupportVolume(0.08);
//
// Grid ...
GridDistance(0);
AllowGrid(false);
MaxNumberOfGrids(0);
GridOnlyForces(false);
GridVolumeMultiplier(0.01);
MaxAllowedGridVolume(0.08);
//
// Recovery ...
RecoveryDistance(0);
AllowRecovery(false);
MaxNumberOfRecoveries(0);
RecoverOnlyForces(false);
RecoveryVolumeMultiplier(0.01);
MaxAllowedRecoveryVolume(0.08);
//
SaveResults(false);
SaveSignalsOnly(true);
}
//
// Tools ...
int CountSetups()
{
return ArraySize(mSetups);
}
//
// Find Setup Index by Symbol and Period ...
int FindSetupIndex(
string symbol,
ENUM_TIMEFRAMES period //
)
{
//
int result = -1;
//
int count = CountSetups();
if (!IsValidSize(count))
{
return result;
}
//
for (int i = 0; i < count; i++)
{
//
XSCX121SetupCycles *iSetup = mSetups[i];
//
X121SetupInputs iInputs = iSetup.GetInputs();
//
if (iInputs.symbol == symbol && iInputs.period == period)
{
//
result = i;
break;
}
}
//
return result;
}
//
// Find Setup Index by Providing Symbol ...
int FindSetupIndex(
string symbol //
)
{
//
int result = -1;
//
int count = CountSetups();
if (!IsValidSize(count))
{
return result;
}
//
for (int i = 0; i < count; i++)
{
//
XSCX121SetupCycles *iSetup = mSetups[i];
//
X121SetupInputs iInputs = iSetup.GetInputs();
//
if (iInputs.symbol == symbol)
{
//
result = i;
break;
}
}
//
return result;
}
// //
}; };
+8 -4
View File
@@ -38,10 +38,15 @@ input long x121EAMagicNumber = 78692110; // Magic Number
input int x121EASlippage = 10; // Slippgae input int x121EASlippage = 10; // Slippgae
// //
// Signals ... // Symbols ...
input group "Signals"; input group "Symbol(s)";
input string x121EASymbols = "EURUSDb,USDCHFb,EURCHFb,USDJPYb,EURJPYb,GBPUSDb"; // Symbols input string x121EASymbols = "EURUSDb,USDCHFb,EURCHFb,USDJPYb,EURJPYb,GBPUSDb"; // Symbols
input bool x121EAUseAllSymbols = false; // Use All Available Symbols input bool x121EAUseAllSymbols = false; // Use All Available Symbols
input bool x121EAUseAllWatchListSymbols = false; // Use All Watch List Symbols
//
// Signals ...
input group "Signals";
input bool x121EAAllowLong = true; // Allow Long Trades input bool x121EAAllowLong = true; // Allow Long Trades
input bool x121EAAllowShort = true; // Allow Short Trades input bool x121EAAllowShort = true; // Allow Short Trades
input int x121EAStartSignallingHoure = 3; // Start Signalling at Specific Time input int x121EAStartSignallingHoure = 3; // Start Signalling at Specific Time
@@ -49,7 +54,6 @@ input int x121EAEndSignallingHoure = 22;
input int x121EACloseOnSpecificTime = -1; // Close All Trades in Specific Time input int x121EACloseOnSpecificTime = -1; // Close All Trades in Specific Time
input int x121EADelayBetweenTwoSignal = 10; // Delay Between two Same Signals input int x121EADelayBetweenTwoSignal = 10; // Delay Between two Same Signals
input int x121EAReuiredSignalVerifications = 4; // Required Verifications for Signals input int x121EAReuiredSignalVerifications = 4; // Required Verifications for Signals
input bool x121EAUseAllWatchListSymbols = false; // Use All WatchList Symbols
input bool x121EAExecuteSignalsOnBreakout = false; // Execute Signals On Breakouts input bool x121EAExecuteSignalsOnBreakout = false; // Execute Signals On Breakouts
input bool x121EAGetVerificationFromOtherTimeFrames = true; // Get Verifications from Other Time Frames input bool x121EAGetVerificationFromOtherTimeFrames = true; // Get Verifications from Other Time Frames
@@ -62,7 +66,7 @@ input double x121EASLPoint = 1000; // SL Poi
input bool x121EAIgnoreSL = false; // Ignore Calculated SL input bool x121EAIgnoreSL = false; // Ignore Calculated SL
input bool x121EAIgnoreTP = false; // Ignore Calculated TP input bool x121EAIgnoreTP = false; // Ignore Calculated TP
input bool x121EACloseOnOpposit = false; // Close all Positions on Opposit input bool x121EACloseOnOpposit = false; // Close all Positions on Opposit
input int x121EAMaxAllowedTrades = 0; // Max Allowed Positions Per Symbol input int x121EAMaxAllowedTrades = 2; // Max Allowed Positions Per Symbol
input bool x121EAUseMaxAllowedPerDirection = true; // Use Max Allowed Positions Per Direction input bool x121EAUseMaxAllowedPerDirection = true; // Use Max Allowed Positions Per Direction
input int x121EAMinFreeMargingForOpenTrades = 900; // Min Margin For Opening Trades input int x121EAMinFreeMargingForOpenTrades = 900; // Min Margin For Opening Trades
input bool x121EAIncreaseNextSignalsVolume = true; // Increase Next Signals Volume input bool x121EAIncreaseNextSignalsVolume = true; // Increase Next Signals Volume