last ...
This commit is contained in:
@@ -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 ...
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
@@ -323,6 +323,15 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Sleeping State ...
|
||||
bool isSlept = IsSlept();
|
||||
if (isSlept)
|
||||
{
|
||||
Print("Slept");
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Second Check For Signals ...
|
||||
// then Execute Signals if Provided ...
|
||||
@@ -580,7 +589,7 @@ public:
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
|
||||
//
|
||||
// Calculate Max Drawdown and it's Percent ...
|
||||
double CalculateMaxDrawdown()
|
||||
@@ -1657,6 +1666,83 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Sleeping Context ...
|
||||
|
||||
//
|
||||
// Sleeping Mode ...
|
||||
int mSleepingDuration;
|
||||
datetime mSleepingStartAt;
|
||||
bool Sleeping(int seconds = -1)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSleepingDuration =
|
||||
seconds > 0
|
||||
? seconds
|
||||
: mRestingAfterHedge > 0
|
||||
? mRestingAfterHedge
|
||||
: 0;
|
||||
result = mSleepingDuration > 0;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
ResetSleeping();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Doesnt Sleep Before ...
|
||||
result = mSleepingStartAt == NULL;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
ResetSleeping();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
datetime cTime = TimeCurrent();
|
||||
mSleepingStartAt = cTime;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
bool IsSlept()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = mSleepingDuration > 0 &&
|
||||
mSleepingStartAt != NULL;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
ResetSleeping();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
datetime cTime = TimeCurrent();
|
||||
result = (int)cTime < (int)mSleepingStartAt + mSleepingDuration;
|
||||
if (!result)
|
||||
{
|
||||
ResetSleeping();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
void ResetSleeping()
|
||||
{
|
||||
//
|
||||
mSleepingDuration = 0;
|
||||
mSleepingStartAt = NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
|
||||
@@ -4567,3 +4567,302 @@ int pivotsCount = ArraySize(pivots);
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// input double x121EAForceCloseProfit = 5; // Close All Positions Regardless of Policies when Profit Reached
|
||||
// input double x121EAMaxDrawdownForce = 5; // Max Drawdown Force State for Handling Guards
|
||||
// input int x121EAMaxPositionsForce = 10; // Max Number of Positions Force State for Handling Guards
|
||||
// input double x121EAMinFreeMargingForHandleForce = 800; // Min Free Margin for Force States
|
||||
// input bool x121EAAllowSymbolHedgeOnForce = false; // Allow Symbol Hedging on Force States
|
||||
|
||||
// x121EA.ForceCloseProfit(x121EAForceCloseProfit);
|
||||
// x121EA.MaxDrawdownForce(x121EAMaxDrawdownForce);
|
||||
// x121EA.MaxPositionsForce(x121EAMaxPositionsForce);
|
||||
// x121EA.AllowSymbolHedgeOnForce(x121EAAllowSymbolHedgeOnForce);
|
||||
// x121EA.MinFreeMargingForHandleForce(x121EAMinFreeMargingForHandleForce);
|
||||
|
||||
double mForceCloseProfit; // Close All Positions Regardless of Policies when Profit Reached
|
||||
|
||||
//
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,14 +44,15 @@ input group "Signals";
|
||||
//,USDCHFb,EURCHFb,USDJPYb,EURJPYb,GBPUSDb
|
||||
// EURUSDb,USDCHFb,EURCHFb,USDJPYb,EURJPYb,GBPUSDb
|
||||
// EURUSDb,USDCHFb,EURCHFb,USDJPYb,EURJPYb,GBPUSDb,XAUUSDb,NZDUSDb,AUDUSDb,USDCADb,BTCUSD,ETHUSD
|
||||
input string x121EASymbols = "EURUSDb,USDCHFb,EURCHFb,USDJPYb,EURJPYb,GBPUSDb"; // Symbols
|
||||
input bool x121EAUseAllSymbols = false; // Use All Available Symbols
|
||||
input bool x121EAUseAllWatchListSymbols = false; // Use All WatchList Symbols
|
||||
input bool x121EAAllowLong = true; // Allow Long Trades
|
||||
input bool x121EAAllowShort = true; // Allow Short Trades
|
||||
input int x121EADelayBetweenTwoSignal = 5; // Delay Between two Same Signals
|
||||
input int x121EAReuiredSignalVerifications = 4; // Required Verifications for Signals
|
||||
input bool x121EAGetVerificationFromOtherTimeFrames = true; // Get Verifications from Other Time Frames
|
||||
input string x121EASymbols = "EURUSDb"; // Symbols
|
||||
input bool x121EAUseAllSymbols = false; // Use All Available Symbols
|
||||
input bool x121EAUseAllWatchListSymbols = false; // Use All WatchList Symbols
|
||||
input bool x121EAAllowLong = true; // Allow Long Trades
|
||||
input bool x121EAAllowShort = true; // Allow Short Trades
|
||||
input bool x121EAExecuteSignalsOnBreakout = false; // Execute Signals On Breakouts
|
||||
input int x121EADelayBetweenTwoSignal = 5; // Delay Between two Same Signals
|
||||
input int x121EAReuiredSignalVerifications = 3; // Required Verifications for Signals
|
||||
input bool x121EAGetVerificationFromOtherTimeFrames = false; // Get Verifications from Other Time Frames
|
||||
|
||||
//
|
||||
// Risk Management ...
|
||||
@@ -101,8 +102,8 @@ input double x121EAMaxAllowedGridVolume = 0.04; // Max Allowed Grid Signals Volu
|
||||
|
||||
//
|
||||
input group "Recovery";
|
||||
input bool x121EAAllowRecovery = true; // Allow Recovery Signals
|
||||
input bool x121EARecoverOnlyForces = true; // Recover Only Force Signals
|
||||
input bool x121EAAllowRecovery = false; // Allow Recovery Signals
|
||||
input bool x121EARecoverOnlyForces = true; // Recover Only Force Signals
|
||||
input int x121EAMaxNumberOfRecoveries = 2; // Max Number of Recovery Signals
|
||||
input double x121EARecoveryDistance = 100; // Recovery Distance
|
||||
input double x121EARecoveryVolumeMultiplier = 2; // Recovery Volume Multiplier
|
||||
@@ -110,12 +111,7 @@ input double x121EAMaxAllowedRecoveryVolume = 0.08; // Max Allowed Recovery Sign
|
||||
|
||||
//
|
||||
input group "Hedging";
|
||||
input int x121EARestingAfterHedge = 3000; // Resting Seconds After Hedge
|
||||
input double x121EAForceCloseProfit = 5; // Close All Positions Regardless of Policies when Profit Reached
|
||||
input double x121EAMaxDrawdownForce = 5; // Max Drawdown Force State for Handling Guards
|
||||
input int x121EAMaxPositionsForce = 10; // Max Number of Positions Force State for Handling Guards
|
||||
input double x121EAMinFreeMargingForHandleForce = 800; // Min Free Margin for Force States
|
||||
input bool x121EAAllowSymbolHedgeOnForce = false; // Allow Symbol Hedging on Force States
|
||||
input int x121EARestingAfterHedge = 0; // Resting Seconds After Hedge
|
||||
input double x121EAMinRequiredProfitPerTrade = 0.2; // Minimum Required Profit for Hedging
|
||||
input double x121EAMinRequiredProfitPerVolumeFactor = 0.01; // Minimum Required Profit for Hedging Per Volume
|
||||
|
||||
@@ -316,6 +312,7 @@ bool InitialEA()
|
||||
x121EA.AllowLong(x121EAAllowLong);
|
||||
x121EA.AllowShort(x121EAAllowShort);
|
||||
x121EA.DelayBetweenTwoSignal(x121EADelayBetweenTwoSignal);
|
||||
x121EA.ExecuteSignalsOnBreakout(x121EAExecuteSignalsOnBreakout);
|
||||
x121EA.ReuiredSignalVerifications(x121EAReuiredSignalVerifications);
|
||||
x121EA.GetVerificationFromOtherTimeFrames(x121EAGetVerificationFromOtherTimeFrames);
|
||||
|
||||
@@ -377,13 +374,8 @@ bool InitialEA()
|
||||
|
||||
//
|
||||
// Hedging ...
|
||||
x121EA.ForceCloseProfit(x121EAForceCloseProfit);
|
||||
x121EA.RestingAfterHedge(x121EARestingAfterHedge);
|
||||
x121EA.MaxDrawdownForce(x121EAMaxDrawdownForce);
|
||||
x121EA.MaxPositionsForce(x121EAMaxPositionsForce);
|
||||
x121EA.AllowSymbolHedgeOnForce(x121EAAllowSymbolHedgeOnForce);
|
||||
x121EA.MinRequiredProfitPerTrade(x121EAMinRequiredProfitPerTrade);
|
||||
x121EA.MinFreeMargingForHandleForce(x121EAMinFreeMargingForHandleForce);
|
||||
x121EA.MinRequiredProfitPerVolumeFactor(x121EAMinRequiredProfitPerVolumeFactor);
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user