save last ...

This commit is contained in:
2024-06-29 20:33:08 +03:30
parent a2c935eb5b
commit 2dcbab85ba
2 changed files with 292 additions and 104 deletions
+276 -88
View File
@@ -374,7 +374,20 @@ struct XTradeInfo
ToString("Type", ToString(type)) +
ToString("Time", time) +
ToString("Pushers", pushers) +
(onlySignals ? "" : "-------------" + "\n" + ToString("Volume", volume) + ToString("Profit", profit) + ToString("Commission", commission) + ToString("Swap", swap) + ToString("End Time", endTime) + ToString("Age", age) + ToString("Message", message)) +
(onlySignals
? ""
:
//
"-------------" + "\n" +
ToString("Volume", volume) +
ToString("Profit", profit) +
ToString("Commission", commission) +
ToString("Swap", swap) +
ToString("End Time", endTime) +
ToString("Age", age) +
ToString("Message", message)
//
) +
"-------------" + "\n" +
"Conditions" + "\n" +
"-------------" + "\n" +
@@ -495,13 +508,19 @@ struct XTradeInfo
//
double selectedEntry =
gEntry <= 0 ? entry : gEntry;
gEntry <= 0
? entry
: gEntry;
double selectedVolume =
gVolume <= 0 ? volume : gVolume;
gVolume <= 0
? volume
: gVolume;
//
double nextEntry =
isLong ? selectedEntry - distancePrice : selectedEntry + distancePrice;
isLong
? selectedEntry - distancePrice
: selectedEntry + distancePrice;
double nextVolume = selectedVolume * volumeMultiplier;
//
@@ -550,7 +569,9 @@ struct XTradeInfo
//
result =
isLong ? cEntry <= gEntry : cEntry >= gEntry;
isLong
? cEntry <= gEntry
: cEntry >= gEntry;
if (!result)
{
return result;
@@ -665,16 +686,27 @@ struct XTradeInfo
//
double selectedEntry =
isLong ? rLongEntry <= 0 ? entry : rLongEntry : rShortEntry <= 0 ? entry
: rShortEntry;
isLong
? rLongEntry <= 0
? entry
: rLongEntry
: rShortEntry <= 0
? entry
: rShortEntry;
double selectedVolume =
rVolume <= 0 ? volume : rVolume;
rVolume <= 0
? volume
: rVolume;
//
double nextLongEntry =
isLong ? selectedEntry : selectedEntry + distancePrice;
isLong
? selectedEntry
: selectedEntry + distancePrice;
double nextShortEntry =
isLong ? selectedEntry - distancePrice : selectedEntry;
isLong
? selectedEntry - distancePrice
: selectedEntry;
//
double nextVolume = selectedVolume * volumeMultiplier;
@@ -684,11 +716,17 @@ struct XTradeInfo
//
double zoneUpper =
rZoneUpper > 0 ? rZoneUpper : isLong ? entry + distancePrice
: entry + (distancePrice * 2);
rZoneUpper > 0
? rZoneUpper
: isLong
? entry + distancePrice
: entry + (distancePrice * 2);
double zoneLower =
rZoneLower > 0 ? rZoneLower : isLong ? entry + (distancePrice * 2)
: entry - distancePrice;
rZoneLower > 0
? rZoneLower
: isLong
? entry + (distancePrice * 2)
: entry - distancePrice;
//
SetRecovery(
@@ -773,19 +811,27 @@ struct XTradeInfo
//
ENUM_POSITION_TYPE rType =
hasLongRecovery ? POSITION_TYPE_BUY : POSITION_TYPE_SELL;
hasLongRecovery
? POSITION_TYPE_BUY
: POSITION_TYPE_SELL;
//
double rEntry =
hasLongRecovery ? cLongEntry : cShortEntry;
hasLongRecovery
? cLongEntry
: cShortEntry;
//
double rTP =
hasLongRecovery ? rZoneUpper : rZoneLower;
hasLongRecovery
? rZoneUpper
: rZoneLower;
//
double rSL =
hasLongRecovery ? rZoneLower : rZoneUpper;
hasLongRecovery
? rZoneLower
: rZoneUpper;
//
result = signal.Prepare(
@@ -2139,7 +2185,10 @@ public:
//
bool isLong = IsLong(iType);
ENUM_POSITION_TYPE iPType = isLong ? POSITION_TYPE_BUY : POSITION_TYPE_SELL;
ENUM_POSITION_TYPE iPType =
isLong
? POSITION_TYPE_BUY
: POSITION_TYPE_SELL;
//
double cEntry = GetEntry(
@@ -2169,7 +2218,13 @@ public:
//
bool isBreaked =
isLong ? isBullish && isBreakUp && cEntry > iEntry : isBearish && isBreakDown && cEntry < iEntry;
isLong
? isBullish &&
isBreakUp &&
cEntry > iEntry
: isBearish &&
isBreakDown &&
cEntry < iEntry;
//
if (isBreaked)
@@ -2497,7 +2552,9 @@ protected:
//
double usedTrailDiff =
isFirstTrail ? MathMax(firstTrailPoint, firstTrailDistance) : MathMax(nextTrailPoint, nextTrailDistance);
isFirstTrail
? MathMax(firstTrailPoint, firstTrailDistance)
: MathMax(nextTrailPoint, nextTrailDistance);
//
double iExit = GetExit(
@@ -2551,7 +2608,9 @@ protected:
//
usedTrailDiff =
isFirstTrail ? MathMin(firstTrailPoint, firstTrailDistance) : MathMin(nextTrailPoint, nextTrailDistance);
isFirstTrail
? MathMin(firstTrailPoint, firstTrailDistance)
: MathMin(nextTrailPoint, nextTrailDistance);
double usedTrailDiffPrice = PointToPrice(
usedTrailDiff,
iPosition.symbol //
@@ -2559,7 +2618,9 @@ protected:
//
double sl =
isLong ? usedPrice + usedTrailDiffPrice : usedPrice - usedTrailDiffPrice;
isLong
? usedPrice + usedTrailDiffPrice
: usedPrice - usedTrailDiffPrice;
string comment = PrepareSLTrailTag(iPosition.comment);
//
@@ -2769,7 +2830,9 @@ protected:
//
// Check Count ...
bool isMaxPassed =
maxAllowed <= 0 ? true : data[i].gLevel < maxAllowed;
maxAllowed <= 0
? true
: data[i].gLevel < maxAllowed;
if (!isMaxPassed)
{
continue;
@@ -2789,7 +2852,9 @@ protected:
//
// Check Max Volume ...
iSignal.volume =
maxAllowedVolume <= 0 ? iSignal.volume : MathMin(iSignal.volume, maxAllowedVolume);
maxAllowedVolume <= 0
? iSignal.volume
: MathMin(iSignal.volume, maxAllowedVolume);
//
AddRef(
@@ -2838,7 +2903,9 @@ protected:
//
// Check Count ...
bool isMaxPassed =
maxAllowed <= 0 ? true : data[i].rLevel < maxAllowed;
maxAllowed <= 0
? true
: data[i].rLevel < maxAllowed;
if (!isMaxPassed)
{
continue;
@@ -2858,7 +2925,9 @@ protected:
//
// Check Max Volume ...
iSignal.volume =
maxAllowedVolume <= 0 ? iSignal.volume : MathMin(iSignal.volume, maxAllowedVolume);
maxAllowedVolume <= 0
? iSignal.volume
: MathMin(iSignal.volume, maxAllowedVolume);
//
AddRef(
@@ -3700,6 +3769,27 @@ public:
mMinFreeMargingForOpenTrades = value;
}
//
double MaxAllowedDrawdownPercent() {
return mMaxAllowedDrawdownPercent;
}
//
void MaxAllowedDrawdownPercent(double value) {
//
if (value < 0) {
value = 0;
}
//
if (value > 50) {
value = 50;
}
//
mMaxAllowedDrawdownPercent = value;
}
//
// Hedging ...
@@ -3891,9 +3981,28 @@ public:
cConditions.Clean();
//
cHasSignal = !useCMarket ? false : mSetups[i].ProcessMarket(cSignal, cConditions, cPusher, cProvider, cTP, cSL, X_MARKET_CYCLE_UNKNOWN, canSupport, allowLong, allowShort, volume, slPoint, ignoreSL, tpPoint, ignoreTP, 0,
5 //
);
cHasSignal =
!useCMarket
? false
: mSetups[i].ProcessMarket(
cSignal,
cConditions,
cPusher,
cProvider,
cTP,
cSL,
X_MARKET_CYCLE_UNKNOWN,
canSupport,
allowLong,
allowShort,
volume,
slPoint,
ignoreSL,
tpPoint,
ignoreTP,
0,
5 //
);
//
// Short Market ...
@@ -3906,9 +4015,28 @@ public:
sConditions.Clean();
//
sHasSignal = !useSMarket ? false : mSetups[i].ProcessMarket(sSignal, sConditions, sPusher, sProvider, sTP, sSL, X_MARKET_CYCLE_SHORT, canSupport, allowLong, allowShort, volume, slPoint, ignoreSL, tpPoint, ignoreTP, 0,
5 //
);
sHasSignal =
!useSMarket
? false
: mSetups[i].ProcessMarket(
sSignal,
sConditions,
sPusher,
sProvider,
sTP,
sSL,
X_MARKET_CYCLE_SHORT,
canSupport,
allowLong,
allowShort,
volume,
slPoint,
ignoreSL,
tpPoint,
ignoreTP,
0,
5 //
);
//
// Medium Market ...
@@ -3921,9 +4049,27 @@ public:
mConditions.Clean();
//
mHasSignal = !useMMarket ? false : mSetups[i].ProcessMarket(mSignal, mConditions, mPusher, mProvider, mTP, mSL, X_MARKET_CYCLE_MEDIUM, canSupport, allowLong, allowShort, volume, slPoint, ignoreSL, tpPoint, ignoreTP, 0,
5 //
);
mHasSignal = !useMMarket
? false
: mSetups[i].ProcessMarket(
mSignal,
mConditions,
mPusher,
mProvider,
mTP,
mSL,
X_MARKET_CYCLE_MEDIUM,
canSupport,
allowLong,
allowShort,
volume,
slPoint,
ignoreSL,
tpPoint,
ignoreTP,
0,
5 //
);
//
// Long Market ...
@@ -3936,9 +4082,27 @@ public:
lConditions.Clean();
//
lHasSignal = !useLMarket ? false : mSetups[i].ProcessMarket(lSignal, lConditions, lPusher, lProvider, lTP, lSL, X_MARKET_CYCLE_LONG, canSupport, allowLong, allowShort, volume, slPoint, ignoreSL, tpPoint, ignoreTP, 0,
5 //
);
lHasSignal = !useLMarket
? false
: mSetups[i].ProcessMarket(
lSignal,
lConditions,
lPusher,
lProvider,
lTP,
lSL,
X_MARKET_CYCLE_LONG,
canSupport,
allowLong,
allowShort,
volume,
slPoint,
ignoreSL,
tpPoint,
ignoreTP,
0,
5 //
);
//
// Hind Market ...
@@ -3951,9 +4115,27 @@ public:
hConditions.Clean();
//
hHasSignal = !useHMarket ? false : mSetups[i].ProcessMarket(hSignal, hConditions, hPusher, hProvider, hTP, hSL, X_MARKET_CYCLE_HIND, canSupport, allowLong, allowShort, volume, slPoint, ignoreSL, tpPoint, ignoreTP, 0,
5 //
);
hHasSignal = !useHMarket
? false
: mSetups[i].ProcessMarket(
hSignal,
hConditions,
hPusher,
hProvider,
hTP,
hSL,
X_MARKET_CYCLE_HIND,
canSupport,
allowLong,
allowShort,
volume,
slPoint,
ignoreSL,
tpPoint,
ignoreTP,
0,
5 //
);
//
// Parse Signals and Add them for Executing ...
@@ -3982,14 +4164,6 @@ public:
mConditions,
otherConditions //
);
// AddRef(
// lConditions,
// otherConditions //
// );
// AddRef(
// hConditions,
// otherConditions //
// );
}
//
@@ -4007,14 +4181,6 @@ public:
mConditions,
otherConditions //
);
// AddRef(
// lConditions,
// otherConditions //
// );
// AddRef(
// hConditions,
// otherConditions //
// );
}
//
@@ -4041,10 +4207,6 @@ public:
signal = lSignal;
//
// AddRef(
// cConditions,
// otherConditions //
// );
AddRef(
mConditions,
otherConditions //
@@ -4095,13 +4257,18 @@ public:
bool isValid =
//
// Handle Pusher Validations ...
(mReuiredSignalVerifications <= 0 ? true : pushers >= mReuiredSignalVerifications)
(mReuiredSignalVerifications <= 0
? true
: pushers >= mReuiredSignalVerifications)
//
&&
//
// Handle Other Conditions Validations ...
(!mGetVerificationFromOtherTimeFrames ? true : isLong ? signalGenerator.HasLongVerifications(otherConditions)
: signalGenerator.HasShortVerifications(otherConditions))
(!mGetVerificationFromOtherTimeFrames
? true
: isLong
? signalGenerator.HasLongVerifications(otherConditions)
: signalGenerator.HasShortVerifications(otherConditions))
//
;
@@ -4110,7 +4277,7 @@ public:
bool forceState = mForce;
//
if (!forceState)
if (isValid && !forceState)
{
//
// Add Signal to Execution Result ...
@@ -4272,16 +4439,6 @@ public:
}
}
//
// TODO: Remove this ...
// isSignalValid = !AllowSupport()
// ? true
// : IsValidSize(ArraySize(iSignal.supports));
// if (!isSignalValid)
// {
// continue;
// }
//
// Filter Signals Based On Max Allowed ...
if (maxAllowed > 0)
@@ -4289,7 +4446,9 @@ public:
//
// Here we Get Opposite Signals of Same Symbol Valid ...
ENUM_X_POSITION_TYPES iType =
perDirection ? ToPositionType(iSignal.type) : X_POSITION_TYPE_ALL;
perDirection
? ToPositionType(iSignal.type)
: X_POSITION_TYPE_ALL;
XPosition iSymbolsPositions[];
int iSymbolsPositionsCount = mTrader.GetPositions(
iSymbolsPositions,
@@ -4315,7 +4474,9 @@ public:
//
isSignalValid =
iSupportsCount <= 0 ? iSymbolsPositionsCount < maxAllowed : iSymbolsPositionsCount - iSupportsCount < maxAllowed;
iSupportsCount <= 0
? iSymbolsPositionsCount < maxAllowed
: iSymbolsPositionsCount - iSupportsCount < maxAllowed;
if (!isSignalValid)
{
continue;
@@ -4448,7 +4609,9 @@ public:
//
int multiplier =
iSupportsCount <= 0 ? iSymbolsPositionsCount : iSymbolsPositionsCount - iSupportsCount;
iSupportsCount <= 0
? iSymbolsPositionsCount
: iSymbolsPositionsCount - iSupportsCount;
if (multiplier <= 0)
{
multiplier = 1;
@@ -4493,6 +4656,9 @@ public:
signals //
);
//
Clean(eSignals);
//
HandleSignals(signals);
}
@@ -4646,13 +4812,22 @@ protected:
//
bool isStartHourPassed =
startHour <= -1 ? true : cTime.hour >= startHour;
startHour <= -1
? true
: cTime.hour >= startHour;
bool isEndHourPassed =
endHour <= -1 ? true : cTime.hour < endHour;
bool isTimePassed = isTimeRecieved && isStartHourPassed && isEndHourPassed;
endHour <= -1
? true
: cTime.hour < endHour;
bool isTimePassed =
isTimeRecieved &&
isStartHourPassed &&
isEndHourPassed;
//
result = isTypePassed && isTimePassed;
result =
isTypePassed &&
isTimePassed;
//
return result;
@@ -4665,7 +4840,9 @@ protected:
bool result = false;
//
result = mCloseOnSpecificTime >= 0 && mCloseOnSpecificTime <= 23;
result =
mCloseOnSpecificTime >= 0 &&
mCloseOnSpecificTime <= 23;
if (!result)
{
return result;
@@ -4814,7 +4991,9 @@ protected:
double minFreeMargingForHandleForce = MinFreeMargingForOpenTrades();
//
bool result = minFreeMargingForHandleForce <= 0 ? true : freeMargin >= minFreeMargingForHandleForce;
bool result = minFreeMargingForHandleForce <= 0
? true
: freeMargin >= minFreeMargingForHandleForce;
//
return result;
@@ -4827,11 +5006,13 @@ protected:
bool result = false;
//
double maxAllowedDrawdownPercent = 5; // MaxAllowedDrawdownPercent();
double maxAllowedDrawdownPercent = MaxAllowedDrawdownPercent();
double drawdownPercent = GetDrawdownPercent();
//
result = maxAllowedDrawdownPercent <= 0 ? true : drawdownPercent <= maxAllowedDrawdownPercent;
result = maxAllowedDrawdownPercent <= 0
? true
: drawdownPercent <= maxAllowedDrawdownPercent;
//
return result;
@@ -5251,6 +5432,7 @@ private:
bool mForce; // Determine in Force State or not
int mDelayBetweenTwoSignal; // Delay between two same signal
double mMinFreeMargingForOpenTrades; // Min Free Margin for Open Trades
double mMaxAllowedDrawdownPercent; // Max Allowed Drawdown for Open Trades
//
XSCX121SetupCycles *mSetups[]; // Number of Setups
@@ -5321,6 +5503,10 @@ private:
RecoveryVolumeMultiplier(0.01);
MaxAllowedRecoveryVolume(0.08);
//
MaxAllowedDrawdownPercent(5);
MinFreeMargingForOpenTrades(0);
//
SaveResults(false);
SaveSignalsOnly(true);
@@ -5360,7 +5546,9 @@ private:
X121SetupInputs iInputs = iSetup.GetInputs();
//
if (iInputs.symbol == symbol && iInputs.period == period)
if (
iInputs.symbol == symbol &&
iInputs.period == period)
{
//
result = i;
+16 -16
View File
@@ -47,15 +47,15 @@ input bool x121EAUseAllWatchListSymbols = false;
//
// Signals ...
input group "Signals";
input bool x121EAAllowLong = true; // Allow Long Trades
input bool x121EAAllowShort = true; // Allow Short Trades
input int x121EAStartSignallingHoure = 3; // Start 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 x121EADelayBetweenTwoSignal = 10; // Delay Between two Same Signals
input int x121EAReuiredSignalVerifications = 4; // Required Verifications for Signals
input bool x121EAExecuteSignalsOnBreakout = false; // Execute Signals On Breakouts
input bool x121EAGetVerificationFromOtherTimeFrames = true; // Get Verifications from Other Time Frames
input bool x121EAAllowLong = true; // Allow Long Trades
input bool x121EAAllowShort = true; // Allow Short Trades
input int x121EAStartSignallingHoure = 3; // Start 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 x121EADelayBetweenTwoSignal = 5; // Delay Between two Same Signals
input int x121EAReuiredSignalVerifications = 10; // Required Verifications for Signals
input bool x121EAExecuteSignalsOnBreakout = false; // Execute Signals On Breakouts
input bool x121EAGetVerificationFromOtherTimeFrames = true; // Get Verifications from Other Time Frames
//
// Risk Management ...
@@ -63,19 +63,19 @@ input group "Risk Management";
input double x121EAVolume = 0.01; // Static Volume
input double x121EATPPoint = 1000; // TP Point
input double x121EASLPoint = 1000; // SL Point
input bool x121EAIgnoreSL = false; // Ignore Calculated SL
input bool x121EAIgnoreTP = false; // Ignore Calculated TP
input bool x121EAIgnoreSL = true; // Ignore Calculated SL
input bool x121EAIgnoreTP = true; // Ignore Calculated TP
input bool x121EACloseOnOpposit = false; // Close all Positions on Opposit
input int x121EAMaxAllowedTrades = 2; // Max Allowed Positions Per Symbol
input int x121EAMaxAllowedTrades = 0; // Max Allowed Positions Per Symbol
input bool x121EAUseMaxAllowedPerDirection = true; // Use Max Allowed Positions Per Direction
input int x121EAMinFreeMargingForOpenTrades = 900; // Min Margin For Opening Trades
input int x121EAMaxAllowedDrawdownPercent = 5; // Max Allowed Drawdown for Open Trades
input bool x121EAIncreaseNextSignalsVolume = true; // Increase Next Signals Volume
input double x121EAIncreaseNextSignalsVolumeMultiplier = 1; // Increase Next Signals Volume Multiplier
input bool x121EAAcceptNextDirectionalSignalsWhenFirstInProfit = true; // Accept Same Symbol/Type Signal when Last in Profit
//
input group "Trailling";
input bool x121EAAllowTrailStop = true; // Enable Trailling Stop Losses
input bool x121EAAllowTrailStop = false; // Enable Trailling Stop Losses
input bool x121EADisableTrailingWhenOpposit = true; // Disable Trailling When has Opposite In Drawdown
input double x121EAFirstTrailDistance = 100; // Start Trailling Distance
input double x121EAFirstTrailPoint = 60; // First Stop Trail
@@ -112,7 +112,7 @@ input double x121EAMaxAllowedRecoveryVolume = 0; // Max Allowed Recovery Signals
//
input group "Hedging";
input int x121EARestingAfterHedge = 1000; // Resting Seconds After Hedge
input double x121EAMinRequiredProfitPerTrade = 0.3; // Minimum Required Profit for Hedging
input double x121EAMinRequiredProfitPerTrade = 2.5; // Minimum Required Profit for Hedging
input double x121EAMinRequiredProfitPerVolumeFactor = 0.01; // Minimum Required Profit for Hedging Per Volume
//
@@ -326,7 +326,7 @@ bool InitialEA()
x121EA.MaxAllowedTrades(x121EAMaxAllowedTrades);
x121EA.IncreaseNextSignalsVolume(x121EAIncreaseNextSignalsVolume);
x121EA.UseMaxAllowedPerDirection(x121EAUseMaxAllowedPerDirection);
x121EA.MinFreeMargingForOpenTrades(x121EAMinFreeMargingForOpenTrades);
x121EA.MaxAllowedDrawdownPercent(x121EAMaxAllowedDrawdownPercent);
x121EA.IncreaseNextSignalsVolumeMultiplier(x121EAIncreaseNextSignalsVolumeMultiplier);
x121EA.AcceptNextDirectionalSignalsWhenFirstInProfit(x121EAAcceptNextDirectionalSignalsWhenFirstInProfit);