last ...
This commit is contained in:
@@ -514,6 +514,85 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XSCZones *GetZones(
|
||||
ENUM_X_MARKET_CYCLES cycle = X_MARKET_CYCLE_UNKNOWN, //
|
||||
int barIndex = 0, //
|
||||
int numberOfZones = 10 //
|
||||
)
|
||||
{
|
||||
//
|
||||
XSCZonesInput zInputs;
|
||||
zInputs.numberOfZones = numberOfZones;
|
||||
zInputs.AddLevelColor(
|
||||
0.15,
|
||||
clrYellow //
|
||||
);
|
||||
zInputs.AddLevelColor(
|
||||
0.20,
|
||||
clrOrange //
|
||||
);
|
||||
zInputs.AddLevelColor(
|
||||
0.25,
|
||||
clrRed //
|
||||
);
|
||||
|
||||
//
|
||||
int length = 0;
|
||||
ENUM_TIMEFRAMES zPeriod = NULL;
|
||||
switch (cycle)
|
||||
{
|
||||
//
|
||||
case X_MARKET_CYCLE_SHORT:
|
||||
//
|
||||
zPeriod = sCycle.GetPeriod();
|
||||
break;
|
||||
|
||||
//
|
||||
case X_MARKET_CYCLE_MEDIUM:
|
||||
//
|
||||
zPeriod = mCycle.GetPeriod();
|
||||
break;
|
||||
|
||||
//
|
||||
case X_MARKET_CYCLE_LONG:
|
||||
//
|
||||
zPeriod = lCycle.GetPeriod();
|
||||
break;
|
||||
|
||||
//
|
||||
case X_MARKET_CYCLE_HIND:
|
||||
//
|
||||
zPeriod = hCycle.GetPeriod();
|
||||
break;
|
||||
|
||||
//
|
||||
default:
|
||||
case X_MARKET_CYCLE_UNKNOWN:
|
||||
//
|
||||
zPeriod = cCycle.GetPeriod();
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
ENUM_TIMEFRAMES cPeriod = GetPeriod();
|
||||
length = (PeriodSeconds(zPeriod) / PeriodSeconds(cPeriod)) + 1;
|
||||
|
||||
//
|
||||
zInputs.length = length;
|
||||
XSCZones *result = new XSCZones(
|
||||
GetSymbol(),
|
||||
cPeriod //
|
||||
);
|
||||
if (!result.Init(zInputs))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
|
||||
@@ -1042,6 +1042,118 @@ public:
|
||||
mSave = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Trailling Stop ...
|
||||
|
||||
//
|
||||
bool AllowTrailStop()
|
||||
{
|
||||
return mAllowTrailStop;
|
||||
}
|
||||
|
||||
//
|
||||
void AllowTrailStop(bool value)
|
||||
{
|
||||
mAllowTrailStop = value;
|
||||
}
|
||||
|
||||
//
|
||||
double NextTrailPoint()
|
||||
{
|
||||
return mNextTrailPoint;
|
||||
}
|
||||
|
||||
//
|
||||
void NextTrailPoint(double value)
|
||||
{
|
||||
//
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
|
||||
//
|
||||
mNextTrailPoint = value;
|
||||
}
|
||||
|
||||
//
|
||||
double FirstTrailPoint()
|
||||
{
|
||||
return mFirstTrailPoint;
|
||||
}
|
||||
|
||||
//
|
||||
void FirstTrailPoint(double value)
|
||||
{
|
||||
//
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
|
||||
//
|
||||
mFirstTrailPoint = value;
|
||||
}
|
||||
|
||||
//
|
||||
double NextTrailDistance()
|
||||
{
|
||||
return mNextTrailDistance;
|
||||
}
|
||||
|
||||
//
|
||||
void NextTrailDistance(double value)
|
||||
{
|
||||
//
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
|
||||
//
|
||||
mNextTrailDistance = value;
|
||||
}
|
||||
|
||||
//
|
||||
double FirstTrailDistance()
|
||||
{
|
||||
return mFirstTrailDistance;
|
||||
}
|
||||
|
||||
//
|
||||
void FirstTrailDistance(double value)
|
||||
{
|
||||
//
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
|
||||
//
|
||||
mFirstTrailDistance = value;
|
||||
}
|
||||
|
||||
//
|
||||
bool EnableTrailling()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
AllowTrailStop() &&
|
||||
NextTrailPoint() > 0 &&
|
||||
FirstTrailPoint() > 0 &&
|
||||
NextTrailDistance() > 0 &&
|
||||
FirstTrailDistance() > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Grid System ...
|
||||
|
||||
@@ -1469,6 +1581,140 @@ public:
|
||||
Finish(infoIDX);
|
||||
}
|
||||
|
||||
//
|
||||
// Protection Handlers ...
|
||||
|
||||
//
|
||||
int HandleTrailling()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Check Trailling is Enabled or not ...
|
||||
if (!EnableTrailling())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Do Synch Before Start Trailing ...
|
||||
Sync();
|
||||
|
||||
//
|
||||
// Since Trailing Done based On In Profit Positions ...
|
||||
// First we Check if ...
|
||||
XPosition positions[];
|
||||
int positionsCount = mTrader.GetInProfitPositions(positions);
|
||||
if (!IsValidSize(positionsCount))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
XPosition iPosition = positions[i];
|
||||
|
||||
//
|
||||
// ignore Support Positions ...
|
||||
bool isSupport = IsSupport(iPosition.comment);
|
||||
if (isSupport)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Positin Info Index ...
|
||||
int idx = FindIndex(iPosition.ticket);
|
||||
if (!IsValidIndex(idx))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
bool isLong = IsLong(iPosition.type);
|
||||
|
||||
//
|
||||
// Here we Select Price for SL Trailling ...
|
||||
double usedPrice =
|
||||
iPosition.sl > 0 &&
|
||||
isLong
|
||||
? iPosition.sl < iPosition.entry
|
||||
? iPosition.entry
|
||||
: iPosition.sl
|
||||
: iPosition.sl > iPosition.entry
|
||||
? iPosition.entry
|
||||
: iPosition.sl;
|
||||
|
||||
//
|
||||
double nextTrailPoint = NextTrailPoint();
|
||||
double firstTrailPoint = FirstTrailPoint();
|
||||
double nextTrailDistance = NextTrailDistance();
|
||||
double firstTrailDistance = FirstTrailDistance();
|
||||
|
||||
//
|
||||
bool isFirstTrail = usedPrice == iPosition.entry;
|
||||
|
||||
//
|
||||
double usedTrailDiff =
|
||||
isFirstTrail
|
||||
? MathMax(firstTrailPoint, firstTrailDistance)
|
||||
: MathMax(nextTrailPoint, nextTrailDistance);
|
||||
|
||||
//
|
||||
double iExit = GetExit(
|
||||
iPosition.symbol,
|
||||
iPosition.type //
|
||||
);
|
||||
double iPriceDistance = MathAbs(usedPrice - iExit);
|
||||
double iPriceDistanceInPoint = PriceToPoint(
|
||||
iPriceDistance,
|
||||
iPosition.symbol //
|
||||
);
|
||||
|
||||
//
|
||||
bool canTrail = iPriceDistanceInPoint >= usedTrailDiff;
|
||||
if (!canTrail)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
usedTrailDiff =
|
||||
isFirstTrail
|
||||
? MathMin(firstTrailPoint, firstTrailDistance)
|
||||
: MathMin(nextTrailPoint, nextTrailDistance);
|
||||
double usedTrailDiffPrice = PointToPrice(
|
||||
usedTrailDiff,
|
||||
iPosition.symbol //
|
||||
);
|
||||
|
||||
//
|
||||
double sl =
|
||||
isLong
|
||||
? usedPrice + usedTrailDiffPrice
|
||||
: usedPrice - usedTrailDiffPrice;
|
||||
string comment = PrepareSLTrailTag(iPosition.comment);
|
||||
|
||||
//
|
||||
bool isModified = mTrader.Modify(
|
||||
iPosition.ticket,
|
||||
sl,
|
||||
iPosition.tp,
|
||||
comment //
|
||||
);
|
||||
if (isModified)
|
||||
{
|
||||
result++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int RequestForGrid(XSignal &signals[])
|
||||
{
|
||||
@@ -1703,6 +1949,14 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Stop Trailling ...
|
||||
bool mAllowTrailStop; // Enable Trailling Stop Losses
|
||||
double mFirstTrailDistance; // Start Trailling Distance
|
||||
double mFirstTrailPoint; // First Stop Trail
|
||||
double mNextTrailDistance; // Next Trailling Distance
|
||||
double mNextTrailPoint; // Next Trailling Step
|
||||
|
||||
//
|
||||
// Grid ...
|
||||
bool mAllowGrid; // Use Grid System to Recovery Positions
|
||||
@@ -2006,6 +2260,69 @@ public:
|
||||
mUseSupport = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Trailling Stop ...
|
||||
|
||||
//
|
||||
bool AllowTrailStop()
|
||||
{
|
||||
return mTradeInfoHandler.AllowTrailStop();
|
||||
}
|
||||
|
||||
//
|
||||
void AllowTrailStop(bool value)
|
||||
{
|
||||
mTradeInfoHandler.AllowTrailStop(value);
|
||||
}
|
||||
|
||||
//
|
||||
double NextTrailPoint()
|
||||
{
|
||||
return mTradeInfoHandler.NextTrailPoint();
|
||||
}
|
||||
|
||||
//
|
||||
void NextTrailPoint(double value)
|
||||
{
|
||||
mTradeInfoHandler.NextTrailPoint(value);
|
||||
}
|
||||
|
||||
//
|
||||
double FirstTrailPoint()
|
||||
{
|
||||
return mTradeInfoHandler.FirstTrailPoint();
|
||||
}
|
||||
|
||||
//
|
||||
void FirstTrailPoint(double value)
|
||||
{
|
||||
mTradeInfoHandler.FirstTrailPoint(value);
|
||||
}
|
||||
|
||||
//
|
||||
double NextTrailDistance()
|
||||
{
|
||||
return mTradeInfoHandler.NextTrailDistance();
|
||||
}
|
||||
|
||||
//
|
||||
void NextTrailDistance(double value)
|
||||
{
|
||||
mTradeInfoHandler.NextTrailDistance(value);
|
||||
}
|
||||
|
||||
//
|
||||
double FirstTrailDistance()
|
||||
{
|
||||
return mTradeInfoHandler.FirstTrailDistance();
|
||||
}
|
||||
|
||||
//
|
||||
void FirstTrailDistance(double value)
|
||||
{
|
||||
mTradeInfoHandler.FirstTrailDistance(value);
|
||||
}
|
||||
|
||||
//
|
||||
// Grid System ...
|
||||
|
||||
@@ -3087,9 +3404,52 @@ private:
|
||||
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 ...
|
||||
|
||||
//
|
||||
bool EnableTrailling()
|
||||
{
|
||||
return mTradeInfoHandler.EnableTrailling();
|
||||
}
|
||||
|
||||
//
|
||||
bool EnableGrid()
|
||||
{
|
||||
@@ -3105,7 +3465,7 @@ private:
|
||||
//
|
||||
bool EnableProtection()
|
||||
{
|
||||
return EnableGrid() || EnableRecovery();
|
||||
return EnableGrid() || EnableRecovery() || EnableTrailling();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -3347,6 +3707,22 @@ private:
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Trailling ...
|
||||
if (EnableTrailling())
|
||||
{
|
||||
//
|
||||
int trailsCount = mTradeInfoHandler.HandleTrailling();
|
||||
if (IsValidSize(trailsCount))
|
||||
{
|
||||
//
|
||||
string message = XEQMSupportToken + " Successfully Trail Stop for: " + ToString(trailsCount) + " Position(s) ...";
|
||||
|
||||
//
|
||||
Alert(message);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
XSignal signals[];
|
||||
int signalsCount = mTradeInfoHandler
|
||||
@@ -3364,6 +3740,10 @@ private:
|
||||
states,
|
||||
false // Ignore Policies ...
|
||||
);
|
||||
if (executed != signalsCount)
|
||||
{
|
||||
Print("Error On Executing Support Signal ...");
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -344,7 +344,8 @@ public:
|
||||
|
||||
//
|
||||
// Find Highest Value in Range ...
|
||||
mRangeHigh = mHighs[ArrayMaximum(mHighs)];
|
||||
int highIDX = ArrayMaximum(mHighs);
|
||||
mRangeHigh = mHighs[highIDX];
|
||||
|
||||
//
|
||||
// Retrieve Lows ...
|
||||
@@ -359,7 +360,20 @@ public:
|
||||
|
||||
//
|
||||
// Find Lowest Value in Range ...
|
||||
mRangeLow = mLows[ArrayMinimum(mLows)];
|
||||
int lowIDX = ArrayMinimum(mLows);
|
||||
mRangeLow = mLows[lowIDX];
|
||||
|
||||
//
|
||||
datetime mTimes[];
|
||||
CopyTime(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
mStartTime,
|
||||
mEndTime,
|
||||
mTimes //
|
||||
);
|
||||
mRangeHighTime = mTimes[highIDX];
|
||||
mRangeLowTime = mTimes[lowIDX];
|
||||
|
||||
//
|
||||
double mRangeSize = GetRange();
|
||||
@@ -632,7 +646,9 @@ protected:
|
||||
double mHighs[];
|
||||
double mLows[];
|
||||
double mRangeHigh;
|
||||
datetime mRangeHighTime;
|
||||
double mRangeLow;
|
||||
datetime mRangeLowTime;
|
||||
|
||||
//
|
||||
CArrayObj mZones;
|
||||
|
||||
@@ -1280,7 +1280,7 @@ protected:
|
||||
string message = "Guard Hedge " + provider + "'s Positions on Profit: " + ToString(profit);
|
||||
|
||||
//
|
||||
mAlert.Alert(message);
|
||||
Alert(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1323,7 +1323,7 @@ protected:
|
||||
string message = "Guard Close (" + ToString(positionsCount) + ") Postion(s) In Profit ...";
|
||||
|
||||
//
|
||||
mAlert.Alert(message);
|
||||
Alert(message);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1365,7 +1365,7 @@ protected:
|
||||
string message = "Guard Close (" + ToString(positionsCount) + ") Position(s) In Drawdown ...";
|
||||
|
||||
//
|
||||
mAlert.Alert(message);
|
||||
Alert(message);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1441,7 +1441,7 @@ protected:
|
||||
//
|
||||
if (IsValid(comment))
|
||||
{
|
||||
mAlert.Alert(comment);
|
||||
Alert(comment);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1519,7 +1519,7 @@ protected:
|
||||
string message = "(" + ToString(modified) + ") Position's Stop Trailed Successfully ...";
|
||||
|
||||
//
|
||||
mAlert.Alert(message);
|
||||
Alert(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1573,7 +1573,7 @@ protected:
|
||||
//
|
||||
if (IsValid(comment))
|
||||
{
|
||||
mAlert.Alert(comment);
|
||||
Alert(comment);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1613,7 +1613,7 @@ protected:
|
||||
string message = "Guard Cancel (" + ToString(canceledOrdersCount) + ") Pending Orders ...";
|
||||
|
||||
//
|
||||
mAlert.Alert(message);
|
||||
Alert(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user