last ...
This commit is contained in:
@@ -985,3 +985,435 @@ void HandleEquitySupportGuard()
|
||||
// Add(
|
||||
// vBreakoutSignal,
|
||||
// conditions.signal.supports);
|
||||
|
||||
//
|
||||
// Generate Equity Support Signals ...
|
||||
bool GenerateSupportSignals(
|
||||
XPosition &position, // Source Position which we have to Generate Support's Signal for it
|
||||
XSignal &supports[], // Hold Result ...
|
||||
double providedVolume = 0 // Provided Support Volume ...
|
||||
)
|
||||
{
|
||||
//
|
||||
Clean(supports);
|
||||
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// TODO: Add this to Config ...
|
||||
double maxAllowedSupportVolume = 0.02;
|
||||
|
||||
//
|
||||
// Normalize Volume ...
|
||||
if (providedVolume <= 0)
|
||||
{
|
||||
providedVolume = 0.02;
|
||||
}
|
||||
else if (providedVolume > maxAllowedSupportVolume)
|
||||
{
|
||||
providedVolume = maxAllowedSupportVolume;
|
||||
}
|
||||
NormalizeVolume(
|
||||
providedVolume,
|
||||
position.symbol);
|
||||
|
||||
//
|
||||
// Check Position Has Support ...
|
||||
XPositionPack pack;
|
||||
bool hasPack = mTrader.GetPositionPack(
|
||||
position.ticket,
|
||||
pack);
|
||||
if (hasPack && pack.supportOrdersCount > 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Position X121 Provider Instance ...
|
||||
int idx = GetProviderIndex(
|
||||
position.symbol,
|
||||
position.period);
|
||||
if (idx < 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Market Conditions ...
|
||||
X121MarketConditions conditions = mProviders[idx]
|
||||
.provider
|
||||
.GetMarketConditions(1);
|
||||
|
||||
//
|
||||
// Now we can used Market Conditions to Generate Support Signals ...
|
||||
double tp;
|
||||
double entry;
|
||||
double tpPoint = 30;
|
||||
double tpPrice = PointToPrice(
|
||||
conditions.symbol,
|
||||
tpPoint);
|
||||
string positionProvider = ExtractProvider(position.comment);
|
||||
|
||||
//
|
||||
// Generate Peaks Breakout Signals ...
|
||||
// LONG ...
|
||||
XSignal pbuSignal;
|
||||
|
||||
//
|
||||
pbuSignal.symbol = conditions.symbol;
|
||||
pbuSignal.period = conditions.period;
|
||||
pbuSignal.type = POSITION_TYPE_BUY;
|
||||
|
||||
//
|
||||
// Since Price above Current Entry ...
|
||||
// we SEt Sell Stop ...
|
||||
pbuSignal.mode = X_ORDER_MODE_STOP;
|
||||
|
||||
//
|
||||
entry = NormalizePrice(
|
||||
conditions.xpvInfo.peak,
|
||||
conditions.symbol);
|
||||
pbuSignal.entry = entry;
|
||||
|
||||
//
|
||||
tp = entry + tpPrice;
|
||||
pbuSignal.tp = tp;
|
||||
pbuSignal.sl = 0;
|
||||
|
||||
//
|
||||
pbuSignal.volume = providedVolume;
|
||||
|
||||
//
|
||||
Add(positionProvider,
|
||||
pbuSignal.providers);
|
||||
|
||||
//
|
||||
Add(pbuSignal,
|
||||
supports);
|
||||
|
||||
//
|
||||
// SHORT ...
|
||||
XSignal pbdSignal;
|
||||
|
||||
//
|
||||
pbdSignal.symbol = conditions.symbol;
|
||||
pbdSignal.period = conditions.period;
|
||||
pbdSignal.type = POSITION_TYPE_SELL;
|
||||
|
||||
//
|
||||
// Since Price above Current Entry ...
|
||||
// we SEt Sell Stop ...
|
||||
pbdSignal.mode = X_ORDER_MODE_LIMIT;
|
||||
|
||||
//
|
||||
entry = NormalizePrice(
|
||||
conditions.xpvInfo.peak,
|
||||
conditions.symbol);
|
||||
pbdSignal.entry = entry;
|
||||
|
||||
//
|
||||
tp = entry - tpPrice;
|
||||
pbdSignal.tp = 0; // tp;
|
||||
pbdSignal.sl = 0;
|
||||
|
||||
//
|
||||
pbdSignal.volume = providedVolume;
|
||||
|
||||
//
|
||||
Add(positionProvider,
|
||||
pbdSignal.providers);
|
||||
|
||||
//
|
||||
Add(pbdSignal,
|
||||
supports);
|
||||
|
||||
//
|
||||
// Generate Vales Breakout Signal ...
|
||||
// LONG ...
|
||||
XSignal vbuSignal;
|
||||
|
||||
//
|
||||
vbuSignal.symbol = conditions.symbol;
|
||||
vbuSignal.period = conditions.period;
|
||||
vbuSignal.type = POSITION_TYPE_BUY;
|
||||
|
||||
//
|
||||
// Since Price above Current Entry ...
|
||||
// we SEt Sell Stop ...
|
||||
vbuSignal.mode = X_ORDER_MODE_LIMIT;
|
||||
|
||||
//
|
||||
entry = NormalizePrice(
|
||||
conditions.xpvInfo.vale,
|
||||
conditions.symbol);
|
||||
vbuSignal.entry = entry;
|
||||
|
||||
//
|
||||
tp = entry + tpPrice;
|
||||
vbuSignal.tp = tp;
|
||||
vbuSignal.sl = 0;
|
||||
|
||||
//
|
||||
vbuSignal.volume = providedVolume;
|
||||
|
||||
//
|
||||
Add(positionProvider,
|
||||
vbuSignal.providers);
|
||||
|
||||
//
|
||||
Add(vbuSignal,
|
||||
supports);
|
||||
|
||||
//
|
||||
// SHORT ...
|
||||
XSignal vbdSignal;
|
||||
|
||||
//
|
||||
vbdSignal.symbol = conditions.symbol;
|
||||
vbdSignal.period = conditions.period;
|
||||
vbdSignal.type = POSITION_TYPE_SELL;
|
||||
|
||||
//
|
||||
// Since Price above Current Entry ...
|
||||
// we SEt Sell Stop ...
|
||||
vbdSignal.mode = X_ORDER_MODE_STOP;
|
||||
|
||||
//
|
||||
entry = NormalizePrice(
|
||||
conditions.xpvInfo.vale,
|
||||
conditions.symbol);
|
||||
vbdSignal.entry = entry;
|
||||
|
||||
//
|
||||
tp = entry - tpPrice;
|
||||
vbdSignal.tp = 0; // tp;
|
||||
vbdSignal.sl = 0;
|
||||
|
||||
//
|
||||
vbdSignal.volume = providedVolume;
|
||||
|
||||
//
|
||||
Add(positionProvider,
|
||||
vbdSignal.providers);
|
||||
|
||||
//
|
||||
Add(vbdSignal,
|
||||
supports);
|
||||
|
||||
//
|
||||
// Check Market Conditions for Supporting Using Fibonacci ...
|
||||
bool isFLSame = true;
|
||||
// TODO: Fix this ...
|
||||
// mProvider.mXPVHelper.Calculate(0);
|
||||
// for (int i = 1; i < 4; i++)
|
||||
// {
|
||||
// //
|
||||
// if (mProvider.mXPVHelper.fl2Buffer[i] != conditions.xpvInfo.fl3)
|
||||
// {
|
||||
// //
|
||||
// isFLSame = false;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
//
|
||||
if (isFLSame)
|
||||
{
|
||||
//
|
||||
// Now we Can also Add FLBase Support Signals ...
|
||||
|
||||
//
|
||||
// TODO: Complete this ...
|
||||
|
||||
//
|
||||
// bool isPriceOverFL3 = false;
|
||||
// bool isPriceUnderFL1 = false;
|
||||
// XSignal flbuSignal;
|
||||
|
||||
// //
|
||||
// flbuSignal.symbol = conditions.symbol;
|
||||
// flbuSignal.period = conditions.period;
|
||||
// flbuSignal.type = POSITION_TYPE_BUY;
|
||||
|
||||
// //
|
||||
// // Since Price above Current Entry ...
|
||||
// // we SEt Sell Stop ...
|
||||
// flbuSignal.mode = X_ORDER_MODE_LIMIT;
|
||||
|
||||
// //
|
||||
// entry = NormalizePrice(
|
||||
// conditions.xpvInfo.vale,
|
||||
// conditions.symbol);
|
||||
// flbuSignal.entry = entry;
|
||||
|
||||
// //
|
||||
// tp = entry + tpPrice;
|
||||
// flbuSignal.tp = tp;
|
||||
// flbuSignal.sl = 0;
|
||||
|
||||
// //
|
||||
// flbuSignal.volume = providedVolume;
|
||||
|
||||
// //
|
||||
// Add(positionProvider,
|
||||
// flbuSignal.providers);
|
||||
|
||||
// //
|
||||
// Add(flbuSignal,
|
||||
// supports);
|
||||
|
||||
// //
|
||||
// XSignal flbdSignal;
|
||||
|
||||
// //
|
||||
// flbdSignal.symbol = conditions.symbol;
|
||||
// flbdSignal.period = conditions.period;
|
||||
// flbdSignal.type = POSITION_TYPE_SELL;
|
||||
|
||||
// //
|
||||
// // Since Price above Current Entry ...
|
||||
// // we SEt Sell Stop ...
|
||||
// flbdSignal.mode = X_ORDER_MODE_STOP;
|
||||
|
||||
// //
|
||||
// entry = NormalizePrice(
|
||||
// conditions.xpvInfo.vale,
|
||||
// conditions.symbol);
|
||||
// flbdSignal.entry = entry;
|
||||
|
||||
// //
|
||||
// tp = entry - tpPrice;
|
||||
// flbdSignal.tp = tp;
|
||||
// flbdSignal.sl = 0;
|
||||
|
||||
// //
|
||||
// flbdSignal.volume = providedVolume;
|
||||
|
||||
// //
|
||||
// Add(positionProvider,
|
||||
// flbdSignal.providers);
|
||||
|
||||
// //
|
||||
// Add(flbdSignal,
|
||||
// supports);
|
||||
}
|
||||
|
||||
//
|
||||
result = ArraySize(supports) > 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Execute a Collection Of Support Signals for Specific Position ...
|
||||
// NOTE: the position's Supports must be Closed ...
|
||||
int ExecuteSupportSignals(
|
||||
XPosition &position, // Specify Supported Position ...
|
||||
XSignal &supports[] // Provided Support Signals ...
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
int supportsCount = ArraySize(supports);
|
||||
if (position.ticket <= 0 ||
|
||||
supportsCount <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < supportsCount; i++)
|
||||
{
|
||||
//
|
||||
XSignal iSignal = supports[i];
|
||||
|
||||
//
|
||||
// Generate Comment for Signal ...
|
||||
int idx = i + 1;
|
||||
string comment = GenerateSupportSignalComment(
|
||||
position.ticket,
|
||||
idx);
|
||||
|
||||
//
|
||||
// Execute ...
|
||||
bool isExecuted = mTrader.ExecuteSignal(
|
||||
iSignal,
|
||||
comment);
|
||||
if (isExecuted)
|
||||
{
|
||||
result++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Cancel Spcific Position's Pack ...
|
||||
// if set closePosition flag to true, Supported Position also closed ...
|
||||
bool CancelSupport(
|
||||
XPositionPack &pack, // Specified Position Pack to Cancell it's Support ...
|
||||
bool closePosition = false // Determines Supported Position itself Close or not ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (pack.ticket <= 0 ||
|
||||
pack.ticket != pack.position.ticket ||
|
||||
(pack.supportOrdersCount <= 0 &&
|
||||
pack.supportPositionsCount <= 0))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string comment = "Close (" + ToString(pack.ticket) + ") Position's Pack ...";
|
||||
|
||||
//
|
||||
if (closePosition)
|
||||
{
|
||||
//
|
||||
result = mTrader.Close(
|
||||
pack.ticket,
|
||||
comment);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
bool isCancelOrders = false;
|
||||
if (pack.supportOrdersCount > 0)
|
||||
{
|
||||
//
|
||||
isCancelOrders = mTrader.CancelOrders(
|
||||
pack.supportOrders);
|
||||
}
|
||||
|
||||
//
|
||||
bool isClosePositions = false;
|
||||
if (pack.supportPositionsCount > 0)
|
||||
{
|
||||
//
|
||||
int closed = mTrader.ClosePositions(
|
||||
pack.supportPositions,
|
||||
comment);
|
||||
|
||||
//
|
||||
isClosePositions = closed == pack.supportPositionsCount;
|
||||
}
|
||||
|
||||
//
|
||||
result = isCancelOrders || isClosePositions;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user