backup workspace ...
This commit is contained in:
@@ -0,0 +1,987 @@
|
||||
|
||||
//
|
||||
// Check All Open Positions and it's Supports ...
|
||||
void HandleSupportHedgeGuard()
|
||||
{
|
||||
//
|
||||
// We Have two different Senario ...
|
||||
// 1- Hedge a Position by it's Supprots ...
|
||||
// 2- Hedge Whole Positions ...
|
||||
|
||||
//
|
||||
double minSupportVolume = 0.01;
|
||||
double minRequiredProfitPerEachTradeForHedging = 0.2;
|
||||
|
||||
//
|
||||
// Check Open Positions ...
|
||||
int positionsCount = mTrader.CountPositions();
|
||||
if (positionsCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Profit Summary Variable ...
|
||||
double profitSummary = 0;
|
||||
|
||||
//
|
||||
// Retrieve Open Positions ...
|
||||
XPosition positions[];
|
||||
mTrader.GetPositions(positions);
|
||||
|
||||
//
|
||||
// Try to Detect Each Position by it's Supports ...
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
// Retrieve Indexed Position ...
|
||||
XPosition iPosition = positions[i];
|
||||
|
||||
//
|
||||
// Define Profit Summary Variable ...
|
||||
profitSummary = iPosition.profit;
|
||||
|
||||
//
|
||||
XPositionPack pack;
|
||||
bool hasPack = mTrader.GetPositionPack(
|
||||
iPosition.ticket,
|
||||
pack);
|
||||
if (!hasPack)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Position's Supports is Executed or Not ...
|
||||
bool isSupportOpen = pack.supportPositionsCount > 0;
|
||||
if (!isSupportOpen)
|
||||
{
|
||||
//
|
||||
// Here we must Check to Do Additional Support ...
|
||||
|
||||
//
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Profit Summary ...
|
||||
for (int j = 0; j < pack.supportPositionsCount; j++)
|
||||
{
|
||||
//
|
||||
XPosition jPosition = pack.supportPositions[j];
|
||||
|
||||
//
|
||||
profitSummary += jPosition.profit;
|
||||
}
|
||||
|
||||
//
|
||||
// Now se Decide What to do based On Profit Summary ...
|
||||
if (profitSummary > 0)
|
||||
{
|
||||
//
|
||||
// Close and Hedge ...
|
||||
CancelSupport(
|
||||
pack,
|
||||
true);
|
||||
}
|
||||
else if (profitSummary < 0)
|
||||
{
|
||||
//
|
||||
// Do Additional Supports ...
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check Conditions for All Hedge Senario ...
|
||||
profitSummary = 0;
|
||||
double requiredProfit = 0;
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
XPosition iPosition = positions[i];
|
||||
|
||||
//
|
||||
requiredProfit += (minRequiredProfitPerEachTradeForHedging * (iPosition.volume / minSupportVolume)) + (-1 * iPosition.swap);
|
||||
profitSummary += iPosition.profit;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Closing Condition ...
|
||||
bool isProfitPassedForHedge = (profitSummary > requiredProfit);
|
||||
if (!isProfitPassedForHedge)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
string comment = "EQM Close ...";
|
||||
int closed = mTrader.ClosePositions(
|
||||
positions,
|
||||
comment);
|
||||
|
||||
//
|
||||
if (closed > 0)
|
||||
{
|
||||
//
|
||||
string message = "In Profit Hedge using Equity Manager by Profit: " + ToString(profitSummary);
|
||||
|
||||
//
|
||||
LogMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// When Equity is Locked but Support Positions doesn't
|
||||
// Triggered ...
|
||||
void HandleEquitySupportGuard()
|
||||
{
|
||||
//
|
||||
// Add theme on Coonfigs ...
|
||||
int reuiredAge = 35;
|
||||
|
||||
//
|
||||
bool hasEquity = CheckEquityForTrade();
|
||||
if (hasEquity)
|
||||
{
|
||||
//
|
||||
// TODO:
|
||||
// Here We Can Close All Exists Support Signals if their
|
||||
// related Positions was Gone ...
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve in DrawDown Positions ...
|
||||
XPosition positions[];
|
||||
GetInDrawdownPositions(
|
||||
positions);
|
||||
int positionsCount = ArraySize(positions);
|
||||
if (positionsCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
XPosition iPosition = positions[i];
|
||||
|
||||
//
|
||||
XPositionPack iPack;
|
||||
bool hasPack = mTrader.GetPositionPack(
|
||||
iPosition.ticket,
|
||||
iPack);
|
||||
if (!hasPack || iPack.supportOrdersCount <= 0)
|
||||
{
|
||||
//
|
||||
// Here We Have to Check if Added before or not ...
|
||||
int supIdx = GetSupportsIndex(iPosition.ticket);
|
||||
if (supIdx < 0)
|
||||
{
|
||||
//
|
||||
XSupport support;
|
||||
|
||||
//
|
||||
support.position = iPosition;
|
||||
support.lastSupportVolume = iPosition.volume;
|
||||
support.lastSupport = TimeToMilliSeconds(iPosition.openAt);
|
||||
|
||||
//
|
||||
AddSupports(support);
|
||||
|
||||
//
|
||||
supIdx = GetSupportsIndex(iPosition.ticket);
|
||||
}
|
||||
|
||||
//
|
||||
int supportAge = GetSupportAge(supIdx);
|
||||
bool isSupportAgePassed = supportAge > reuiredAge;
|
||||
if (!isSupportAgePassed)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
XSignal supports[];
|
||||
bool isGenerated = GenerateSupportSignals(
|
||||
iPosition,
|
||||
supports,
|
||||
mSupports[supIdx].lastSupportVolume * 2);
|
||||
if (!isGenerated)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Try to Execute New Support Signals ...
|
||||
bool isExecuted = ExecuteSupportSignals(
|
||||
iPosition,
|
||||
supports);
|
||||
if (isExecuted)
|
||||
{
|
||||
//
|
||||
// Update Support ...
|
||||
datetime barTime = iTime(
|
||||
iPosition.symbol,
|
||||
iPosition.period,
|
||||
0);
|
||||
mSupports[supIdx].position = iPosition;
|
||||
mSupports[supIdx].lastSupportVolume *= 2;
|
||||
mSupports[supIdx].lastSupport = TimeToMilliSeconds(barTime);
|
||||
|
||||
//
|
||||
// string message = "Position (" + ToString(iPosition.ticket) + ") Close Due Equity Manager ...";
|
||||
string message = "Cancel Position (" + ToString(iPosition.ticket) + ") Supports and Provide New Supports for Equity Management ...";
|
||||
|
||||
//
|
||||
LogMessage(message);
|
||||
}
|
||||
|
||||
//
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Support Order Age ...
|
||||
int longAge = 0;
|
||||
for (int j = 0; j < iPack.supportOrdersCount; j++)
|
||||
{
|
||||
//
|
||||
XOrder jOrder = iPack.supportOrders[j];
|
||||
|
||||
//
|
||||
int jAge = GetOrderAge(
|
||||
jOrder,
|
||||
iPosition.period);
|
||||
|
||||
//
|
||||
if (longAge == 0 || longAge < jAge)
|
||||
{
|
||||
longAge = jAge;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check Longest Oreder Age is Passed Required Age or not ...
|
||||
bool hasLongAgeSupport = longAge >= reuiredAge;
|
||||
if (!hasLongAgeSupport)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// now we Have to Cancel all Supports ...
|
||||
bool isCancelSupports = CancelSupport(
|
||||
iPack);
|
||||
if (!isCancelSupports)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
XSignal supports[];
|
||||
bool isGenerated = GenerateSupportSignals(
|
||||
iPack.position,
|
||||
supports);
|
||||
if (!isGenerated)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Try to Execute New Support Signals ...
|
||||
bool isExecuted = ExecuteSupportSignals(
|
||||
iPack.position,
|
||||
supports);
|
||||
if (isExecuted)
|
||||
{
|
||||
//
|
||||
string message = "Cancel Position (" + ToString(iPack.ticket) + ") Supports and Provide New Supports for Equity Management ...";
|
||||
|
||||
//
|
||||
LogMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// if (result)
|
||||
// {
|
||||
// //
|
||||
// bool hasEquity = CheckEquityForTrade();
|
||||
// if (!hasEquity)
|
||||
// {
|
||||
// //
|
||||
// // TODO:
|
||||
// // Here we can check MaxIn Drawdown Position Type and
|
||||
// // ignore Indirection Positions if it's Only One Trade Open ...
|
||||
// // since Base EA Class ignore this Case and doesn't do anything, since
|
||||
// // it's a Custom Senario ...
|
||||
// // We have to implement it manually ...
|
||||
// // PickEquityManagerSignal(signals);
|
||||
// }
|
||||
// }
|
||||
|
||||
//
|
||||
void PickEquityManagerSignal(XSignal &signals[])
|
||||
{
|
||||
//
|
||||
// Check Equity ...
|
||||
bool hasEquity = CheckEquityForTrade();
|
||||
if (hasEquity)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Singals Count ...
|
||||
int signalsCount = ArraySize(signals);
|
||||
if (signalsCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Provider Count ...
|
||||
int providersCount = ArraySize(mProviders);
|
||||
if (providersCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through Registered Provider Instances ...
|
||||
for (int i = 0; i < providersCount; i++)
|
||||
{
|
||||
//
|
||||
X121SignalProvider iSProvider = mProviders[i];
|
||||
|
||||
//
|
||||
string symbol = iSProvider.symbol;
|
||||
ENUM_TIMEFRAMES period = iSProvider.period;
|
||||
|
||||
//
|
||||
// Now we Have to Retrieve In Darwdown Position ...
|
||||
XPosition inDrawDownPositions[];
|
||||
GetInDrawdownPositions(
|
||||
inDrawDownPositions,
|
||||
symbol,
|
||||
NULL, // All Types Of Positions ...
|
||||
period,
|
||||
NULL, // All Types Of Signal Providers ...
|
||||
X_POSITION_SELECT_MAX // Max Positions Select ...
|
||||
);
|
||||
int inDrawDownPositionsCount = ArraySize(inDrawDownPositions);
|
||||
if (inDrawDownPositionsCount <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Since we Select Max Method and then Validate count, there was at least one it ...
|
||||
// which is the max ...
|
||||
ENUM_POSITION_TYPE type = inDrawDownPositions[0].type;
|
||||
|
||||
//
|
||||
// Now we have to Loop Through Provided Signals which
|
||||
// relate to Indirection type of in drawdown position,
|
||||
// then simplely we can Execute it ...
|
||||
for (int j = 0; j < signalsCount; j++)
|
||||
{
|
||||
//
|
||||
XSignal jSignal = signals[j];
|
||||
|
||||
//
|
||||
// Check Signal is belong to this provider ...
|
||||
if (jSignal.symbol != iSProvider.symbol ||
|
||||
jSignal.period != iSProvider.period)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// we have sure the signal is belongs to current provider ...
|
||||
// Check signal direction ...
|
||||
// also we Check Signal Execution mode is MARKET mode ...
|
||||
if (jSignal.type == type || jSignal.mode != X_ORDER_MODE_MARKET)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Do Signal Preparation ...
|
||||
PrepareSignal(jSignal);
|
||||
|
||||
//
|
||||
// Now we can Execute Signal ...
|
||||
bool isExecuted = mTrader.ExecuteSignal(jSignal);
|
||||
if (isExecuted)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
void HandleEquityManagement()
|
||||
{
|
||||
//
|
||||
// TODO: add this to Configurations ...
|
||||
int longAgeDetection = 35;
|
||||
double supportVolumeMultiplier = 2;
|
||||
|
||||
//
|
||||
// Check Equity ...
|
||||
bool hasEquity = CheckEquityForTrade();
|
||||
if (hasEquity)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Provider Count ...
|
||||
int providersCount = ArraySize(mProviders);
|
||||
if (providersCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through Registered Provider Instances ...
|
||||
for (int i = 0; i < providersCount; i++)
|
||||
{
|
||||
//
|
||||
X121SignalProvider iSProvider = mProviders[i];
|
||||
|
||||
//
|
||||
string symbol = iSProvider.symbol;
|
||||
ENUM_TIMEFRAMES period = iSProvider.period;
|
||||
XSCX121Provider *analyzer = iSProvider.provider;
|
||||
|
||||
//
|
||||
// Now we Have to Retrieve In Darwdown Position ...
|
||||
XPosition inDrawDownPositions[];
|
||||
GetInDrawdownPositions(
|
||||
inDrawDownPositions,
|
||||
symbol,
|
||||
NULL, // All Types Of Positions ...
|
||||
period,
|
||||
NULL, // All Types Of Signal Providers ...
|
||||
NULL // All Positions Select ...
|
||||
);
|
||||
int inDrawDownPositionsCount = ArraySize(inDrawDownPositions);
|
||||
if (inDrawDownPositionsCount <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop throuigh Positions ...
|
||||
for (int j = 0; j < inDrawDownPositionsCount; j++)
|
||||
{
|
||||
//
|
||||
// Select Index Model ...
|
||||
XPosition jPosition = inDrawDownPositions[j];
|
||||
|
||||
//
|
||||
// Check Position is Signal Type or Support Position ...
|
||||
string jParams[];
|
||||
bool isSupport = ExtractSupportParams(
|
||||
jPosition.comment,
|
||||
jParams);
|
||||
if (!isSupport)
|
||||
{
|
||||
//
|
||||
// there was some case which a Position still Open in Drawdown
|
||||
// and it's supports close due take profit ...
|
||||
// in this case we can simply make sure there isn't any ...
|
||||
XPositionPack jPack;
|
||||
bool hasPack = mTrader.GetPositionPack(
|
||||
jPosition.ticket,
|
||||
jPack);
|
||||
if (hasPack && jPack.supportOrdersCount > 0)
|
||||
{
|
||||
//
|
||||
// Check Support Order Age ...
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// at the moment we are sure the jPosition is Open Support Position ...
|
||||
|
||||
//
|
||||
// First Sure there isn't any other Positions Open ...
|
||||
// Ignore Support for Support Trades which their related Positions Exists Open ...
|
||||
// TODO: Check and use this if required ...
|
||||
int positionsCount = mTrader.CountPositions();
|
||||
if (positionsCount > 1)
|
||||
{
|
||||
//
|
||||
// Close Max In Profit Trade if it is long age ...
|
||||
// Detect Positions ...
|
||||
// TODO: here ...
|
||||
// XPosition positions[];
|
||||
// GetPositions();
|
||||
// int ordersCount = CountPlacedSupports(symbol, period);
|
||||
// double profit = mTrader.GetPositionsProfit(symbol);
|
||||
// if (profit > 1 ||
|
||||
// profit < -1 ||
|
||||
// (profit < 0 &&
|
||||
// ordersCount == 0))
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
}
|
||||
|
||||
//
|
||||
// then We Have to Check the Open Positions age ...
|
||||
// ignore recently opesitions ...
|
||||
int positionAge = GetPositionAge(
|
||||
jPosition,
|
||||
period);
|
||||
bool isAgeTooOld = positionAge >= longAgeDetection;
|
||||
if (!isAgeTooOld)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Now Check Supported Before Or Not ...
|
||||
int supportIndex = GetSupportsIndex(jPosition.ticket);
|
||||
if (supportIndex < 0)
|
||||
{
|
||||
//
|
||||
// This means we don't support it bere ...
|
||||
|
||||
//
|
||||
XSupport jSupport;
|
||||
|
||||
//
|
||||
jSupport.position = jPosition;
|
||||
jSupport.lastSupportVolume = jPosition.volume;
|
||||
jSupport.lastSupport = TimeToMilliSeconds(jPosition.openAt);
|
||||
|
||||
//
|
||||
// Add Support ...
|
||||
AddSupports(jSupport);
|
||||
|
||||
//
|
||||
// Update Support Index ...
|
||||
supportIndex = GetSupportsIndex(jPosition.ticket);
|
||||
}
|
||||
|
||||
//
|
||||
// Now we Have to Check Last Support Age ...
|
||||
int supportAge = GetSupportAge(supportIndex);
|
||||
isAgeTooOld = supportAge >= longAgeDetection;
|
||||
if (!isAgeTooOld)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Remove all Previously Executed Support Signals which not triggered ...
|
||||
XOrder orders[];
|
||||
GetOrders(
|
||||
orders,
|
||||
mSupports[supportIndex].position.symbol,
|
||||
NULL, // All Type of Orders ...
|
||||
NULL, // All State Of Orders ...
|
||||
mSupports[supportIndex].position.period,
|
||||
NULL // All Signallers type Orders ...
|
||||
);
|
||||
int ordersCount = ArraySize(orders);
|
||||
if (ordersCount > 0)
|
||||
{
|
||||
//
|
||||
for (int u = 0; u < ordersCount; u++)
|
||||
{
|
||||
//
|
||||
XOrder uOrder = orders[u];
|
||||
|
||||
//
|
||||
// Now we have to Make sure this Orders is Support Order ...
|
||||
string uParams[];
|
||||
bool isSupportOrder = ExtractSupportParams(
|
||||
uOrder.comment,
|
||||
uParams);
|
||||
if (!isSupportOrder)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
bool isCancelled = mTrader.CancelOrder(uOrder.ticket);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
double lastSupportVolume = mSupports[supportIndex].lastSupportVolume * supportVolumeMultiplier;
|
||||
|
||||
//
|
||||
// Here we Make Sure that we Have a Long Position which added in our Supports ...
|
||||
// now we have to Eneable Equity Manager Support Signals for this Specific Signal ...
|
||||
XSignal jSupportSignals[];
|
||||
bool isSupportSignalsGenerated = GenerateSupportSignals(
|
||||
mSupports[supportIndex].position,
|
||||
jSupportSignals,
|
||||
lastSupportVolume);
|
||||
if (!isSupportSignalsGenerated)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Execute Support Signals ...
|
||||
bool isExecuted = ExecuteSupportSignals(
|
||||
mSupports[supportIndex].position,
|
||||
jSupportSignals);
|
||||
if (isExecuted)
|
||||
{
|
||||
//
|
||||
// Now we Have to Update Support Info to Prevent Multiple Supporting ...
|
||||
|
||||
//
|
||||
datetime barTime = iTime(
|
||||
mSupports[supportIndex].position.symbol,
|
||||
mSupports[supportIndex].position.period,
|
||||
0);
|
||||
|
||||
//
|
||||
mSupports[supportIndex].lastSupportVolume = lastSupportVolume;
|
||||
mSupports[supportIndex].lastSupport = TimeToMilliSeconds(barTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
void HandleEquitySupportGuard()
|
||||
{
|
||||
//
|
||||
double minVolumeFactor = 0.01;
|
||||
double minProfitForEachTrade = 0.3;
|
||||
|
||||
//
|
||||
int positionsCount = mTrader.CountPositions();
|
||||
if (positionsCount < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Provider Count ...
|
||||
int providersCount = ArraySize(mProviders);
|
||||
if (providersCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through Registered Provider Instances ...
|
||||
for (int i = 0; i < providersCount; i++)
|
||||
{
|
||||
//
|
||||
X121SignalProvider iSProvider = mProviders[i];
|
||||
|
||||
//
|
||||
string symbol = iSProvider.symbol;
|
||||
ENUM_TIMEFRAMES period = iSProvider.period;
|
||||
|
||||
//
|
||||
XPosition positions[];
|
||||
GetPositions(
|
||||
positions,
|
||||
symbol,
|
||||
NULL, // All Position Types ...
|
||||
period);
|
||||
positionsCount = ArraySize(positions);
|
||||
if (positionsCount < 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
double profit = 0;
|
||||
double requiredProfit = 0;
|
||||
|
||||
//
|
||||
for (int j = 0; j < positionsCount; j++)
|
||||
{
|
||||
//
|
||||
XPosition jPosition = positions[j];
|
||||
|
||||
//
|
||||
profit += jPosition.profit;
|
||||
requiredProfit += ((jPosition.volume / minVolumeFactor) * minProfitForEachTrade) + (-1 * jPosition.swap);
|
||||
}
|
||||
|
||||
//
|
||||
bool isProfitPassed = profit >= requiredProfit;
|
||||
if (!isProfitPassed)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
string comment = "EQM Close ...";
|
||||
int closed = mTrader.ClosePositions(
|
||||
positions,
|
||||
comment);
|
||||
|
||||
//
|
||||
bool isClosed = closed == positionsCount;
|
||||
if (isClosed)
|
||||
{
|
||||
//
|
||||
Clean(mSupports);
|
||||
|
||||
//
|
||||
string message = "Equity Management Close (" + ToString(positionsCount) + ") due Hedging by: " + ToString(profit);
|
||||
|
||||
//
|
||||
LogMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//
|
||||
void HandleEquityManagement()
|
||||
{
|
||||
//
|
||||
// TODO: add this to Configurations ...
|
||||
int longAgeDetection = 35;
|
||||
double supportVolumeMultiplier = 2;
|
||||
|
||||
//
|
||||
// Check Equity ...
|
||||
bool hasEquity = CheckEquityForTrade();
|
||||
if (hasEquity)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Provider Count ...
|
||||
int providersCount = ArraySize(mProviders);
|
||||
if (providersCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through Registered Provider Instances ...
|
||||
for (int i = 0; i < providersCount; i++)
|
||||
{
|
||||
//
|
||||
X121SignalProvider iSProvider = mProviders[i];
|
||||
|
||||
//
|
||||
string symbol = iSProvider.symbol;
|
||||
ENUM_TIMEFRAMES period = iSProvider.period;
|
||||
XSCX121Provider *analyzer = iSProvider.provider;
|
||||
|
||||
//
|
||||
// TODO: Complete this here ...
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
void HandleEquitySupportGuard()
|
||||
{
|
||||
//
|
||||
double minVolumeFactor = 0.01;
|
||||
double minProfitForEachTrade = 0.3;
|
||||
|
||||
//
|
||||
int positionsCount = mTrader.CountPositions();
|
||||
if (positionsCount < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Provider Count ...
|
||||
int providersCount = ArraySize(mProviders);
|
||||
if (providersCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through Registered Provider Instances ...
|
||||
for (int i = 0; i < providersCount; i++)
|
||||
{
|
||||
//
|
||||
X121SignalProvider iSProvider = mProviders[i];
|
||||
|
||||
//
|
||||
string symbol = iSProvider.symbol;
|
||||
ENUM_TIMEFRAMES period = iSProvider.period;
|
||||
|
||||
//
|
||||
XPosition positions[];
|
||||
GetPositions(
|
||||
positions,
|
||||
symbol,
|
||||
NULL, // All Position Types ...
|
||||
period);
|
||||
positionsCount = ArraySize(positions);
|
||||
if (positionsCount < 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
double profit = 0;
|
||||
double requiredProfit = 0;
|
||||
|
||||
//
|
||||
for (int j = 0; j < positionsCount; j++)
|
||||
{
|
||||
//
|
||||
XPosition jPosition = positions[j];
|
||||
|
||||
//
|
||||
profit += jPosition.profit;
|
||||
requiredProfit += ((jPosition.volume / minVolumeFactor) * minProfitForEachTrade) + (-1 * jPosition.swap);
|
||||
}
|
||||
|
||||
//
|
||||
bool isProfitPassed = profit >= requiredProfit;
|
||||
if (!isProfitPassed)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
string comment = "EQM Close ...";
|
||||
int closed = mTrader.ClosePositions(
|
||||
positions,
|
||||
comment);
|
||||
|
||||
//
|
||||
bool isClosed = closed == positionsCount;
|
||||
if (isClosed)
|
||||
{
|
||||
//
|
||||
Clean(mSupports);
|
||||
|
||||
//
|
||||
string message = "Equity Management Close (" + ToString(positionsCount) + ") due Hedging by: " + ToString(profit);
|
||||
|
||||
//
|
||||
LogMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Since we Have to Add Some Sorts of Support Signals for
|
||||
// All Issued Signals ...
|
||||
// here we Implement Support Signals to Attached all Signallers ...
|
||||
|
||||
// //
|
||||
// // Peaks Break Out Signal ...
|
||||
// XSignal pBreakoutSignal;
|
||||
|
||||
// //
|
||||
// // Vales BreakOut Signal ...
|
||||
// // XSignal vBreakoutSignal;
|
||||
|
||||
// //
|
||||
// pBreakoutSignal.symbol = conditions.symbol;
|
||||
// pBreakoutSignal.period = conditions.period;
|
||||
// pBreakoutSignal.type = POSITION_TYPE_BUY;
|
||||
|
||||
// //
|
||||
// // Since Price above Current Entry ...
|
||||
// // we SEt Sell Stop ...
|
||||
// pBreakoutSignal.mode = X_ORDER_MODE_STOP;
|
||||
|
||||
// //
|
||||
// double entry = NormalizePrice(
|
||||
// conditions.xpvInfo.peak,
|
||||
// conditions.symbol);
|
||||
// pBreakoutSignal.entry = entry;
|
||||
|
||||
// //
|
||||
// double tpPoint = 30;
|
||||
// double tpPrice = PointToPrice(
|
||||
// mConditions.symbol,
|
||||
// tpPoint);
|
||||
// double tp = entry + tpPrice;
|
||||
// pBreakoutSignal.tp = tp;
|
||||
// pBreakoutSignal.sl = 0;
|
||||
|
||||
// //
|
||||
// pBreakoutSignal.volume = 0.02;
|
||||
|
||||
// //
|
||||
// Copy(
|
||||
// conditions.signal.providers,
|
||||
// pBreakoutSignal.providers);
|
||||
|
||||
// //
|
||||
// Add(
|
||||
// pBreakoutSignal,
|
||||
// conditions.signal.supports);
|
||||
|
||||
//
|
||||
// Since we Have to Add Some Sorts of Support Signals for
|
||||
// All Issued Signals ...
|
||||
// here we Implement Support Signals to Attached all Signallers ...
|
||||
|
||||
// //
|
||||
// // Peaks Break Out Signal ...
|
||||
// XSignal pBreakoutSignal;
|
||||
|
||||
// //
|
||||
// // Vales BreakOut Signal ...
|
||||
// XSignal vBreakoutSignal;
|
||||
|
||||
// //
|
||||
// vBreakoutSignal.symbol = conditions.symbol;
|
||||
// vBreakoutSignal.period = conditions.period;
|
||||
// vBreakoutSignal.type = POSITION_TYPE_SELL;
|
||||
|
||||
// //
|
||||
// // Since Price above Current Entry ...
|
||||
// // we SEt Sell Stop ...
|
||||
// vBreakoutSignal.mode = X_ORDER_MODE_LIMIT;
|
||||
|
||||
// //
|
||||
// double entry = NormalizePrice(
|
||||
// conditions.xpvInfo.peak,
|
||||
// conditions.symbol);
|
||||
// vBreakoutSignal.entry = entry;
|
||||
|
||||
// //
|
||||
// double tpPoint = 30;
|
||||
// double tpPrice = PointToPrice(
|
||||
// mConditions.symbol,
|
||||
// tpPoint);
|
||||
// double tp = entry - tpPrice;
|
||||
// vBreakoutSignal.tp = tp;
|
||||
// vBreakoutSignal.sl = 0;
|
||||
|
||||
// //
|
||||
// vBreakoutSignal.volume = 0.02;
|
||||
|
||||
// //
|
||||
// Copy(
|
||||
// conditions.signal.providers,
|
||||
// vBreakoutSignal.providers);
|
||||
|
||||
// //
|
||||
// Add(
|
||||
// vBreakoutSignal,
|
||||
// conditions.signal.supports);
|
||||
@@ -0,0 +1,86 @@
|
||||
//
|
||||
bool x786CanTrailLongStop =
|
||||
//
|
||||
false
|
||||
// ll1 > ll2 &&
|
||||
// c0Price > ll2
|
||||
// mConditions.xcheInfo.longExit2 > mConditions2.xcheInfo.longExit2
|
||||
//
|
||||
;
|
||||
if (x786CanTrailLongStop)
|
||||
{
|
||||
//
|
||||
XGuard guard;
|
||||
|
||||
//
|
||||
guard.symbol = mSymbol;
|
||||
guard.period = mPeriod;
|
||||
guard.provider = ToString(X786);
|
||||
guard.action = X_GUARD_ACTION_TRAIL_STOP;
|
||||
|
||||
//
|
||||
guard.type = POSITION_TYPE_BUY;
|
||||
guard.dblPayLoad = mConditions.xcheInfo.longExit2;
|
||||
|
||||
//
|
||||
Add(
|
||||
guard,
|
||||
guards);
|
||||
}
|
||||
|
||||
//
|
||||
bool x786CanTrailShortStop =
|
||||
//
|
||||
mConditions.xcheInfo.shortExit2 < mConditions2.xcheInfo.shortExit2
|
||||
//
|
||||
;
|
||||
if (x786CanTrailShortStop)
|
||||
{
|
||||
//
|
||||
XGuard guard;
|
||||
|
||||
//
|
||||
guard.symbol = mSymbol;
|
||||
guard.period = mPeriod;
|
||||
guard.provider = ToString(X786);
|
||||
guard.action = X_GUARD_ACTION_TRAIL_STOP;
|
||||
|
||||
//
|
||||
guard.type = POSITION_TYPE_SELL;
|
||||
guard.dblPayLoad = mConditions.xcheInfo.shortExit2;
|
||||
|
||||
//
|
||||
Add(
|
||||
guard,
|
||||
guards);
|
||||
}
|
||||
|
||||
//
|
||||
// X128 Guard ...
|
||||
|
||||
//
|
||||
bool x128HasLongForceCloseGuard =
|
||||
//
|
||||
// isXAMACrossedUnderXTM
|
||||
false
|
||||
//
|
||||
;
|
||||
if (x128HasLongForceCloseGuard)
|
||||
{
|
||||
//
|
||||
XGuard guard;
|
||||
|
||||
//
|
||||
guard.symbol = mSymbol;
|
||||
guard.period = mPeriod;
|
||||
guard.provider = ToString(X128);
|
||||
guard.action = X_GUARD_ACTION_FORCE_CLOSE;
|
||||
|
||||
//
|
||||
guard.type = POSITION_TYPE_BUY;
|
||||
|
||||
//
|
||||
Add(
|
||||
guard,
|
||||
guards);
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
//
|
||||
bool x786HasSignal =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
x786HasSignal = false;
|
||||
if (x786HasSignal)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
ToString(X786),
|
||||
mConditions.signal.providers);
|
||||
|
||||
//
|
||||
mConditions.signal.r2r = 1.5;
|
||||
mConditions.signal.riskAmount = 0.005;
|
||||
mConditions.signal.mode = X_ORDER_MODE_MARKET;
|
||||
mConditions.signal.entry = entry;
|
||||
mConditions.signal.sl = mConditions.xcheInfo.shortExit2;
|
||||
mConditions.signal.tp = 0;
|
||||
|
||||
//
|
||||
mConditions.signal.calculateTP = true;
|
||||
}
|
||||
|
||||
//
|
||||
bool x110HasSignal =
|
||||
//
|
||||
isMRBSlowCrossedWithPVFL3 &&
|
||||
mConditions.xtmInfo.isBearish
|
||||
//
|
||||
;
|
||||
x110HasSignal = false;
|
||||
if (x110HasSignal)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
ToString(X110),
|
||||
mConditions.signal.providers);
|
||||
|
||||
//
|
||||
mConditions.signal.r2r = 1;
|
||||
mConditions.signal.riskAmount = 0.005;
|
||||
mConditions.signal.mode = X_ORDER_MODE_MARKET;
|
||||
mConditions.signal.entry = entry;
|
||||
mConditions.signal.sl = mConditions.xcheInfo.shortExit2;
|
||||
mConditions.signal.tp = 0;
|
||||
|
||||
//
|
||||
mConditions.signal.ignoreSL = true;
|
||||
mConditions.signal.calculateTP = true;
|
||||
}
|
||||
|
||||
//
|
||||
bool x128HasSignal =
|
||||
//
|
||||
isValeHappens &&
|
||||
mConditions.xamaInfo.value < mConditions.xtmInfo.value
|
||||
//
|
||||
;
|
||||
// x128HasSignal = false;
|
||||
if (x128HasSignal)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
ToString(X128),
|
||||
mConditions.signal.providers);
|
||||
|
||||
//
|
||||
double slPoint = 15;
|
||||
double slPrice = PointToPrice(
|
||||
mConditions.symbol,
|
||||
slPoint);
|
||||
double sl = entry + slPrice;
|
||||
|
||||
//
|
||||
double tpPoint = 30;
|
||||
double tpPrice = PointToPrice(
|
||||
mConditions.symbol,
|
||||
tpPoint);
|
||||
double tp = entry - tpPrice;
|
||||
|
||||
//
|
||||
mConditions.signal.r2r = 1;
|
||||
mConditions.signal.riskAmount = 0.005;
|
||||
mConditions.signal.mode = X_ORDER_MODE_MARKET;
|
||||
mConditions.signal.entry = entry;
|
||||
mConditions.signal.sl = 0; // mConditions.xpvInfo.peak;
|
||||
mConditions.signal.tp = tp;
|
||||
|
||||
//
|
||||
mConditions.signal.ignoreSL = true;
|
||||
mConditions.signal.useRiskAmountAsVolume = true;
|
||||
}
|
||||
|
||||
//
|
||||
// X786 Signal Provider ...
|
||||
bool x786HasSignal =
|
||||
//
|
||||
mConditions.xpvInfo.peak > mConditions2.xpvInfo.peak
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Chandelier Exit must provide Long Exit 1 && 2 ...
|
||||
(
|
||||
//
|
||||
// 1
|
||||
mConditions.xcheInfo.longExit1 != EMPTY_VALUE &&
|
||||
mConditions.xcheInfo.longExit1 < c0SelectedPrice &&
|
||||
// 2
|
||||
mConditions.xcheInfo.longExit2 != EMPTY_VALUE &&
|
||||
mConditions.xcheInfo.longExit2 < c0SelectedPrice &&
|
||||
//
|
||||
(mConditions.xcheInfo.longExit1 > mConditions2.xcheInfo.longExit1 ||
|
||||
mConditions.xcheInfo.longExit2 > mConditions2.xcheInfo.longExit2)
|
||||
//
|
||||
)
|
||||
//
|
||||
&&
|
||||
//
|
||||
entry > mConditions.xdemaInfo.dema
|
||||
// // entry > c0SelectedPrice &&
|
||||
// // c0.close > c0.open &&
|
||||
// c0SelectedPrice > c1.low + (GetCandleRange(c1) / 2)
|
||||
// //
|
||||
// // SSS ...
|
||||
// //
|
||||
// c1.low == mConditions.xpvInfo.vale &&
|
||||
// mConditions.xpvInfo.vale != mConditions2.xpvInfo.vale &&
|
||||
// c0SelectedPrice > c1.low
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
x786HasSignal = false;
|
||||
if (x786HasSignal)
|
||||
{
|
||||
//
|
||||
// disableX786Longs = true;
|
||||
|
||||
//
|
||||
Add(
|
||||
ToString(X786),
|
||||
mConditions.signal.providers);
|
||||
|
||||
//
|
||||
mConditions.signal.r2r = 1.5;
|
||||
mConditions.signal.riskAmount = 0.01;
|
||||
mConditions.signal.mode = X_ORDER_MODE_MARKET;
|
||||
mConditions.signal.entry = entry;
|
||||
mConditions.signal.sl = GetLowestLow(mSymbol, mPeriod, 2, 0); // mConditions.xcheInfo.longExit2;
|
||||
mConditions.signal.tp = GetHighestHigh(mSymbol, mPeriod, 2, 0); // entry + PointToPrice(mConditions.symbol, 10);
|
||||
|
||||
//
|
||||
mConditions.signal.ignoreTP = false;
|
||||
mConditions.signal.calculateTP = false;
|
||||
mConditions.signal.useRiskAmountAsVolume = true;
|
||||
}
|
||||
|
||||
//
|
||||
bool x110HasSignal =
|
||||
//
|
||||
isMRBFastCrossedWithPVFL3 &&
|
||||
mConditions.xtmInfo.isBullish
|
||||
//
|
||||
;
|
||||
x110HasSignal = false;
|
||||
if (x110HasSignal)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
ToString(X110),
|
||||
mConditions.signal.providers);
|
||||
|
||||
//
|
||||
mConditions.signal.r2r = 1;
|
||||
mConditions.signal.riskAmount = 0.005;
|
||||
mConditions.signal.mode = X_ORDER_MODE_MARKET;
|
||||
mConditions.signal.entry = entry;
|
||||
mConditions.signal.sl = mConditions.xcheInfo.longExit2;
|
||||
mConditions.signal.tp = 0;
|
||||
|
||||
//
|
||||
mConditions.signal.ignoreSL = true;
|
||||
mConditions.signal.calculateTP = true;
|
||||
}
|
||||
|
||||
//
|
||||
bool x128HasSignal =
|
||||
//
|
||||
isPeakHappens &&
|
||||
mConditions.xamaInfo.value > mConditions.xtmInfo.value
|
||||
//
|
||||
;
|
||||
// x128HasSignal = false;
|
||||
if (x128HasSignal)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
ToString(X128),
|
||||
mConditions.signal.providers);
|
||||
|
||||
//
|
||||
double slPoint = 15;
|
||||
double slPrice = PointToPrice(
|
||||
mConditions.symbol,
|
||||
slPoint);
|
||||
double sl = entry - slPrice;
|
||||
|
||||
//
|
||||
double tpPoint = 30;
|
||||
double tpPrice = PointToPrice(
|
||||
mConditions.symbol,
|
||||
tpPoint);
|
||||
double tp = entry + tpPrice;
|
||||
|
||||
//
|
||||
mConditions.signal.r2r = 1;
|
||||
mConditions.signal.riskAmount = 0.01;
|
||||
mConditions.signal.mode = X_ORDER_MODE_MARKET;
|
||||
mConditions.signal.entry = entry;
|
||||
mConditions.signal.sl = 0;
|
||||
mConditions.signal.tp = tp;
|
||||
|
||||
//
|
||||
mConditions.signal.ignoreSL = true;
|
||||
mConditions.signal.useRiskAmountAsVolume = true;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
x786HasSignal
|
||||
//
|
||||
||
|
||||
//
|
||||
x110HasSignal
|
||||
//
|
||||
||
|
||||
//
|
||||
x128HasSignal
|
||||
//
|
||||
;
|
||||
@@ -0,0 +1,380 @@
|
||||
|
||||
//
|
||||
// Generate SL Support Signal ...
|
||||
bool GenerateSLSupportSignal(
|
||||
XSignal &signal, // Holds Result ....
|
||||
ulong ticket, // Specific Position Ticket ...
|
||||
double slGapPoint = 10, // Which Distance to SL for Enabling Signal ...
|
||||
double volumeMultiplier = 2 // Support Signals Volume Multiplier ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
int count = CountPositions();
|
||||
if (count <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool hasSupport = HasSupport(ticket);
|
||||
if (hasSupport)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XPosition position;
|
||||
result = GetPosition(
|
||||
position,
|
||||
ticket);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool isLong =
|
||||
IsLong(position.type);
|
||||
|
||||
//
|
||||
string symbol = position.symbol;
|
||||
ENUM_TIMEFRAMES period = ExtractPositionPeriod(position.comment);
|
||||
double volume = position.volume * volumeMultiplier;
|
||||
volume = NormalizeVolume(
|
||||
volume,
|
||||
symbol);
|
||||
|
||||
ENUM_POSITION_TYPE type = isLong
|
||||
? POSITION_TYPE_SELL
|
||||
: POSITION_TYPE_BUY;
|
||||
ENUM_X_ORDER_MODES mode = X_ORDER_MODE_STOP;
|
||||
|
||||
//
|
||||
double slGapPrice = PointToPrice(
|
||||
symbol,
|
||||
slGapPoint);
|
||||
double riskPrice = MathAbs(position.entry - position.sl);
|
||||
|
||||
//
|
||||
double entry =
|
||||
isLong
|
||||
? position.sl + slGapPrice
|
||||
: position.sl - slGapPrice;
|
||||
entry = NormalizePrice(entry, symbol);
|
||||
|
||||
//
|
||||
double sl =
|
||||
isLong
|
||||
? entry + riskPrice
|
||||
: entry - riskPrice;
|
||||
sl = NormalizePrice(sl, symbol);
|
||||
|
||||
//
|
||||
double tp =
|
||||
isLong
|
||||
? entry - riskPrice
|
||||
: entry + riskPrice;
|
||||
tp = NormalizePrice(tp, symbol);
|
||||
|
||||
//
|
||||
signal.sl = sl;
|
||||
signal.tp = tp;
|
||||
signal.type = type;
|
||||
signal.mode = mode;
|
||||
signal.entry = entry;
|
||||
signal.volume = volume;
|
||||
signal.symbol = symbol;
|
||||
signal.period = period;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find an Specific Position Has Support Signal Or not ...
|
||||
bool HasSupport(ulong ticket)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
int count = CountPositions();
|
||||
if (count <= 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XPosition position;
|
||||
result = GetPosition(
|
||||
position,
|
||||
ticket);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XPosition positions[];
|
||||
GetPositions(positions);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XPosition iPosition = positions[i];
|
||||
|
||||
//
|
||||
string supportTicketStr = ExtractParentTicketOfSupport(iPosition.comment);
|
||||
if (StringLen(supportTicketStr) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
ulong parentTicket = (ulong)supportTicketStr;
|
||||
|
||||
//
|
||||
result =
|
||||
parentTicket == ticket &&
|
||||
iPosition.ticket != parentTicket;
|
||||
if (result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Get All Support Positions for Specific Position ...
|
||||
bool GetSupportPositions(
|
||||
ulong ticket, // Parent Position Ticket
|
||||
XPosition &supports[] // Holds Result ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
Clean(supports);
|
||||
|
||||
//
|
||||
int count = CountPositions();
|
||||
if (count <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XPosition parentPosition;
|
||||
bool positionExist = GetPosition(
|
||||
parentPosition,
|
||||
ticket);
|
||||
if (!positionExist)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool hasSupport = HasSupport(ticket);
|
||||
if (!hasSupport)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XPosition positions[];
|
||||
GetPositions(positions);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XPosition iPosition = positions[i];
|
||||
|
||||
//
|
||||
if (iPosition.ticket == ticket)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
string pTicketStr = ExtractParentTicketOfSupport(iPosition.comment);
|
||||
if (StringLen(pTicketStr) <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
ulong pTicket = (ulong)pTicketStr;
|
||||
if (pTicket != ticket)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
Add(
|
||||
iPosition,
|
||||
supports);
|
||||
}
|
||||
|
||||
//
|
||||
result = ArraySize(supports) > 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool GetSupportOrders(
|
||||
ulong ticket, // Parent Position Ticket
|
||||
XOrder &supports[], // Holds Result ...
|
||||
string symbol, // Trading Symbol ...
|
||||
ENUM_TIMEFRAMES period, // Trading TimeFrame ...
|
||||
ENUM_ORDER_STATE state = NULL // Order State ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
Clean(supports);
|
||||
|
||||
//
|
||||
XOrder orders[];
|
||||
GetOrders(
|
||||
orders,
|
||||
symbol,
|
||||
period,
|
||||
state);
|
||||
int ordersCount = ArraySize(orders);
|
||||
result = ordersCount > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < ordersCount; i++)
|
||||
{
|
||||
//
|
||||
XOrder iOrder = orders[i];
|
||||
|
||||
//
|
||||
string pTicketStr = ExtractParentTicketOfSupport(iOrder.comment);
|
||||
if (StringLen(pTicketStr) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
ulong pTicket = (ulong)pTicketStr;
|
||||
if (pTicket != ticket)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
Add(
|
||||
iOrder,
|
||||
supports);
|
||||
}
|
||||
|
||||
//
|
||||
result = ArraySize(supports) > 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Close a Position and it's Supports on a Profit ...
|
||||
bool ClosePositionAndSupports(
|
||||
ulong ticket, // Position Ticket
|
||||
double minProfit = 4 // Minimum Profit For Closing
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (minProfit <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int count = CountPositions();
|
||||
if (count <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XPosition position;
|
||||
bool isExist = GetPosition(
|
||||
position,
|
||||
ticket);
|
||||
if (!isExist)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool hasSupport = HasSupport(ticket);
|
||||
if (!hasSupport)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XPosition supports[];
|
||||
hasSupport = GetSupportPositions(
|
||||
ticket,
|
||||
supports);
|
||||
int supportsCount = ArraySize(supports);
|
||||
if (!hasSupport || supportsCount <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double profitSummary = 0;
|
||||
for (int i = 0; i < supportsCount; i++)
|
||||
{
|
||||
//
|
||||
XPosition iSupport = supports[i];
|
||||
|
||||
//
|
||||
profitSummary += iSupport.profit;
|
||||
}
|
||||
|
||||
//
|
||||
result = profitSummary > 0 && profitSummary >= minProfit;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
Add(
|
||||
position,
|
||||
supports);
|
||||
|
||||
//
|
||||
string comment = "Close Position (" + (string)ticket + ") and it's Supports in Profit: " + (string)profitSummary + " ...";
|
||||
ClosePositions(
|
||||
supports,
|
||||
comment);
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
LogMessage(comment);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
|
||||
//
|
||||
// X786 ...
|
||||
bool x786HasSignal = false;
|
||||
bool canCheckX786 = IsAllowdSignaller(X786);
|
||||
if (canCheckX786)
|
||||
{
|
||||
//
|
||||
x786HasSignal =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
}
|
||||
|
||||
//
|
||||
// X110 ...
|
||||
bool x110HasSignal = false;
|
||||
bool canCheckX110 = IsAllowdSignaller(X110);
|
||||
if (canCheckX110)
|
||||
{
|
||||
//
|
||||
x110HasSignal =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
}
|
||||
|
||||
//
|
||||
// X121 ...
|
||||
bool x121HasSignal = false;
|
||||
bool canCheckX121 = IsAllowdSignaller(X121);
|
||||
if (canCheckX121)
|
||||
{
|
||||
//
|
||||
x121HasSignal =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
}
|
||||
|
||||
//
|
||||
// X128 ...
|
||||
bool x128HasSignal = false;
|
||||
bool canCheckX128 = IsAllowdSignaller(X128);
|
||||
if (canCheckX128)
|
||||
{
|
||||
//
|
||||
x128HasSignal =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
x786HasSignal
|
||||
//
|
||||
||
|
||||
//
|
||||
x110HasSignal
|
||||
//
|
||||
||
|
||||
//
|
||||
x121HasSignal
|
||||
//
|
||||
||
|
||||
//
|
||||
x128HasSignal
|
||||
//
|
||||
;
|
||||
@@ -0,0 +1 @@
|
||||
X786,X110,X121,X128
|
||||
Reference in New Issue
Block a user