This commit is contained in:
2024-06-24 17:08:46 +03:30
parent 1e424c4c71
commit ba23e2d9e9
4 changed files with 672 additions and 433 deletions
+273 -411
View File
@@ -1971,6 +1971,112 @@ public:
return result;
}
//
int GetBreakoutsSignals(XSignal &signals[])
{
//
int result = 0;
//
Clean(signals);
//
int count = Count();
if (!IsValidSize(count))
{
return result;
}
//
for (int i = 0; i < count; i++)
{
//
string iSymbol = data[i].symbol;
ENUM_TIMEFRAMES iPeriod = data[i].period;
//
double hotLevels[];
//
AddSpecific(
0.25,
hotLevels //
);
//
AddSpecific(
0.20,
hotLevels //
);
//
AddSpecific(
0.12,
hotLevels //
);
//
XSCZonesInput zonesInput;
zonesInput.length = 71;
zonesInput.numberOfZones = 10;
XSCZones *zones = new XSCZones(
iSymbol,
_Period //
);
//
zonesInput.AddLevelColor(
hotLevels[0],
clrRed //
);
zonesInput.AddLevelColor(
hotLevels[1],
clrOrange //
);
zonesInput.AddLevelColor(
hotLevels[2],
clrLightCoral //
);
bool canUseZones = zones.Init(zonesInput);
//
XSCCFInput cfInputs;
cfInputs.Default();
XSCCF *cf = new XSCCF(
iSymbol,
_Period //
);
bool canUseCF = cf.Init(cfInputs);
//
XSCTrendInput tInputs;
tInputs.Default();
XSCTrend *trend = new XSCTrend(
iSymbol,
_Period //
);
bool canUseTrend = trend.Init(tInputs);
if (canUseCF && canUseTrend && canUseZones)
{
//
// cf.Draw();
trend.Draw();
// zones.Draw();
Print("Use CF ...");
// cf.Remove();
// trend.Remove();
// zones.Remove();
}
}
//
result = ArraySize(signals);
//
return result;
}
//
// Protected ...
protected:
@@ -2783,6 +2889,18 @@ public:
mGetVerificationFromOtherTimeFrames = value;
}
//
bool ExecuteSignalsOnBreakout()
{
return mExecuteSignalsOnBreakout;
}
//
void ExecuteSignalsOnBreakout(bool value)
{
mExecuteSignalsOnBreakout = value;
}
//
// Risk Management ...
@@ -3304,75 +3422,6 @@ public:
mTradeHandler.SetSave(value);
}
//
double ForceCloseProfit()
{
return mForceCloseProfit;
}
//
void ForceCloseProfit(double value)
{
//
if (value < 0)
{
value = 0;
}
//
mForceCloseProfit = value;
}
//
double MaxDrawdownForce()
{
return mMaxDrawdownForce;
}
//
void MaxDrawdownForce(double value)
{
//
if (value < 0)
{
value = 0;
}
//
mMaxDrawdownForce = value;
}
//
int MaxPositionsForce()
{
return mMaxPositionsForce;
}
//
void MaxPositionsForce(int value)
{
//
if (value < 0)
{
value = 0;
}
//
mMaxPositionsForce = value;
}
//
bool AllowSymbolHedgeOnForce()
{
return mAllowSymbolHedgeOnForce;
}
//
void AllowSymbolHedgeOnForce(bool value)
{
mAllowSymbolHedgeOnForce = value;
}
//
double MinFreeMargingForHandleForce()
{
@@ -3392,18 +3441,6 @@ public:
mMinFreeMargingForHandleForce = value;
}
// //
// bool ForceState()
// {
// return mForceState;
// }
// //
// void ForceState(bool value)
// {
// mForceState = value;
// }
//
// Overrides ...
@@ -3533,6 +3570,13 @@ public:
bool allowLong = AllowLong();
bool allowShort = AllowShort();
//
bool useCMarket = false;
bool useSMarket = true;
bool useMMarket = false;
bool useLMarket = false;
bool useHMarket = false;
//
for (int i = 0; i < count; i++)
{
@@ -3547,24 +3591,26 @@ public:
cConditions.Clean();
//
cHasSignal = mSetups[i]
.ProcessMarket(
cSignal,
cConditions,
cPusher,
cProvider,
X_MARKET_CYCLE_UNKNOWN,
canSupport,
allowLong,
allowShort,
volume,
slPoint,
ignoreSL,
tpPoint,
ignoreTP,
0,
5 //
);
cHasSignal = !useCMarket
? false
: mSetups[i]
.ProcessMarket(
cSignal,
cConditions,
cPusher,
cProvider,
X_MARKET_CYCLE_UNKNOWN,
canSupport,
allowLong,
allowShort,
volume,
slPoint,
ignoreSL,
tpPoint,
ignoreTP,
0,
5 //
);
//
// Short Market ...
@@ -3577,24 +3623,26 @@ public:
sConditions.Clean();
//
sHasSignal = mSetups[i]
.ProcessMarket(
sSignal,
sConditions,
sPusher,
sProvider,
X_MARKET_CYCLE_SHORT,
canSupport,
allowLong,
allowShort,
volume,
slPoint,
ignoreSL,
tpPoint,
ignoreTP,
0,
5 //
);
sHasSignal = !useSMarket
? false
: mSetups[i]
.ProcessMarket(
sSignal,
sConditions,
sPusher,
sProvider,
X_MARKET_CYCLE_SHORT,
canSupport,
allowLong,
allowShort,
volume,
slPoint,
ignoreSL,
tpPoint,
ignoreTP,
0,
5 //
);
//
// Medium Market ...
@@ -3607,24 +3655,26 @@ public:
mConditions.Clean();
//
mHasSignal = mSetups[i]
.ProcessMarket(
mSignal,
mConditions,
mPusher,
mProvider,
X_MARKET_CYCLE_MEDIUM,
canSupport,
allowLong,
allowShort,
volume,
slPoint,
ignoreSL,
tpPoint,
ignoreTP,
0,
5 //
);
mHasSignal = !useMMarket
? false
: mSetups[i]
.ProcessMarket(
mSignal,
mConditions,
mPusher,
mProvider,
X_MARKET_CYCLE_MEDIUM,
canSupport,
allowLong,
allowShort,
volume,
slPoint,
ignoreSL,
tpPoint,
ignoreTP,
0,
5 //
);
//
// Long Market ...
@@ -3637,24 +3687,26 @@ public:
lConditions.Clean();
//
lHasSignal = mSetups[i]
.ProcessMarket(
lSignal,
lConditions,
lPusher,
lProvider,
X_MARKET_CYCLE_LONG,
canSupport,
allowLong,
allowShort,
volume,
slPoint,
ignoreSL,
tpPoint,
ignoreTP,
0,
5 //
);
lHasSignal = !useLMarket
? false
: mSetups[i]
.ProcessMarket(
lSignal,
lConditions,
lPusher,
lProvider,
X_MARKET_CYCLE_LONG,
canSupport,
allowLong,
allowShort,
volume,
slPoint,
ignoreSL,
tpPoint,
ignoreTP,
0,
5 //
);
//
// Hind Market ...
@@ -3667,24 +3719,26 @@ public:
hConditions.Clean();
//
hHasSignal = mSetups[i]
.ProcessMarket(
hSignal,
hConditions,
hPusher,
hProvider,
X_MARKET_CYCLE_HIND,
canSupport,
allowLong,
allowShort,
volume,
slPoint,
ignoreSL,
tpPoint,
ignoreTP,
0,
5 //
);
hHasSignal = !useHMarket
? false
: mSetups[i]
.ProcessMarket(
hSignal,
hConditions,
hPusher,
hProvider,
X_MARKET_CYCLE_HIND,
canSupport,
allowLong,
allowShort,
volume,
slPoint,
ignoreSL,
tpPoint,
ignoreTP,
0,
5 //
);
//
// Parse Signals and Add them for Executing ...
@@ -4317,12 +4371,33 @@ protected:
}
//
ENUM_X_SIGNAL_EXECUTION_RESULT states[];
int executedSignalsCount = ExecuteSignals(
signals,
states,
false //
);
bool executeOnBreakouts = ExecuteSignalsOnBreakout();
if (executeOnBreakouts)
{
//
XSignal bSignals[];
int bSignalsCount = mTradeHandler.GetBreakoutsSignals(bSignals);
if (IsValidSize(bSignalsCount))
{
//
ENUM_X_SIGNAL_EXECUTION_RESULT states[];
int executedSignalsCount = ExecuteSignals(
signals,
states,
false //
);
}
}
else
{
//
ENUM_X_SIGNAL_EXECUTION_RESULT states[];
int executedSignalsCount = ExecuteSignals(
signals,
states,
false //
);
}
}
//
@@ -4404,24 +4479,27 @@ protected:
bool result = false;
//
int maxAllowed = MaxPositionsForce();
result = maxAllowed <= 0;
if (result)
{
return result;
}
// int maxAllowed = MaxPositionsForce();
// result = maxAllowed <= 0;
// if (result)
// {
// return result;
// }
// //
// XPosition positions[];
// int positionsCount = mTrader.GetPositions(positions);
// result = !IsValidSize(positionsCount);
// if (result)
// {
// return result;
// }
// //
// result = positionsCount < maxAllowed;
//
XPosition positions[];
int positionsCount = mTrader.GetPositions(positions);
result = !IsValidSize(positionsCount);
if (result)
{
return result;
}
//
result = positionsCount < maxAllowed;
result = true;
//
return result;
@@ -4437,8 +4515,8 @@ private:
// Signals ...
bool mAllowLong; // Allow Long
bool mAllowShort; // Allow Short
double mForceCloseProfit; // Close All Positions Regardless of Policies when Profit Reached
int mReuiredSignalVerifications; // Required Verifications for Validate Signals
bool mExecuteSignalsOnBreakout; // Execute Signals On Breakouts
bool mGetVerificationFromOtherTimeFrames; // Get Verifications from Other Time Frames
//
@@ -4667,7 +4745,7 @@ private:
int restingTime = RestingAfterHedge();
if (result && IsValidSize(restingTime))
{
Sleep(restingTime * 1000);
Sleeping(restingTime);
}
//
@@ -4838,222 +4916,6 @@ private:
return;
}
//
if (!IsValidSize(setupsCount))
{
return;
}
//
// Here i Can Check what to do In Force State ...
//
// Handle Hedging Based On Positions ...
double drawdown = GetDrawdownPercent();
double forceDrawdown = MaxDrawdownForce();
int positionsForce = MaxPositionsForce();
double forceCloseProfit = ForceCloseProfit();
double minRequiredProfitPerTrade = MinRequiredProfitPerTrade();
double minRequiredProfitPerVolumeFactor = MinRequiredProfitPerVolumeFactor();
//
// Try To Force Hedging ...
bool canForceHedge =
(positionsForce <= 0
? true
: positionsCount > positionsForce)
//
||
//
(forceDrawdown > 0 &&
drawdown >= forceDrawdown);
if (canForceHedge)
{
//
// Check Required Profit ...
//
double profit = SpecifiedCalculatePositionsProfit(positions);
//
// Check Force Close Profit ...
if (forceCloseProfit > 0)
{
//
canForceHedge = profit >= forceCloseProfit;
if (canForceHedge)
{
//
bool isHedged = DoEQMForceClose();
if (isHedged)
{
return;
}
}
}
//
// Calculate Required Profit ...
double requiredProfit = SpecifiedCalculateRequiredProfitForHedge(
positions,
minRequiredProfitPerTrade,
minRequiredProfitPerVolumeFactor //
);
//
canForceHedge =
requiredProfit <= 0
? profit > 0
: profit >= (requiredProfit / 2);
if (canForceHedge)
{
//
bool isHedged = DoEQMForceClose();
if (isHedged)
{
return;
}
}
//
// At Least Hedgeing ...
// Minimal Hedge ...
//
// Check Symbol Hedging ...
bool allowSymbolHedge = AllowSymbolHedgeOnForce();
if (allowSymbolHedge)
{
for (int i = 0; i < setupsCount; i++)
{
//
string iSymbol = mSetups[i].GetSymbol();
//
XPosition iSymbolPositions[];
int iSymbolPositionsCount = mTrader.GetPositions(
iSymbolPositions,
//
iSymbol,
NULL, // All Providers ...
NULL, // All Periods ...
NULL, // All Types ...
true // Filter By Magic ...
);
if (!IsValidSize(iSymbolPositionsCount))
{
continue;
}
//
double profit = SpecifiedCalculatePositionsProfit(iSymbolPositions);
//
double requiredProfit = SpecifiedCalculateRequiredProfitForHedge(
iSymbolPositions,
minRequiredProfitPerTrade,
minRequiredProfitPerVolumeFactor //
);
//
bool canHedge =
requiredProfit <= 0
? profit > 0
: profit >= requiredProfit;
if (canHedge)
{
//
string comment = XEQMSupportToken + " Hedge Symbol ...";
//
int closed = mTrader.Close(
iSymbolPositions,
comment //
);
//
if (closed == iSymbolPositionsCount)
{
//
mSetups[i].ForceState(false);
//
string message = XEQMSupportToken + " Hedge Symbol (" + iSymbol + "): " + ToString(profit);
Alert(message);
}
}
}
}
return;
}
//
// Implement Other Senarios ...
//
bool isMarginPassed = IsMarginPassed();
bool isMaxNumberPassed = IsNumberOfPositionsPassed();
bool canProtect = !isMarginPassed || !isMaxNumberPassed;
if (canProtect)
{
//
int maxInDIDX = FindMaxDrawdownIndex(
positions //
);
int setupIDX = FindSetupIndex(positions[maxInDIDX].symbol);
if (IsValidIndex(maxInDIDX) && IsValidIndex(setupIDX))
{
//
string iSymbol = positions[maxInDIDX].symbol;
ENUM_TIMEFRAMES iPeriod = mSetups[setupIDX].GetPeriod();
//
// Check Position Age ...
int age = GetAge(
positions[maxInDIDX],
iPeriod //
);
if (age >= 700)
{
//
// Calculate Trend ...
XSCTrend *trend = new XSCTrend(
iSymbol,
iPeriod //
);
//
XSCTrendInput tInputs;
tInputs.Default();
bool canUseTrend = trend.Init(tInputs);
if (canUseTrend)
{
//
trend.Draw();
Print("UseTrend");
trend.Remove();
}
// string comment = XEQMSupportToken + " Close Max In D ...";
// bool isClosed = mTrader.Close(
// positions[maxInDIDX].ticket,
// comment //
// );
// if (isClosed)
// {
// //
// string message = XEQMSupportToken + " Close Position (" + ToString(positions[maxInDIDX].ticket) + ") Due Max In Drawdown ...";
// Alert(message);
// }
}
}
}
//
// Find Max In Profit ...
// and Min In Profit ...
//
}