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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
//
|
||||
// Guard ...
|
||||
//
|
||||
// X92 ...
|
||||
bool canCheckX92 = IsAllowdSignaller(X92);
|
||||
if (canCheckX92)
|
||||
{
|
||||
//
|
||||
// Check Signals Close Conditions ...
|
||||
bool canX92Close =
|
||||
//
|
||||
mConditions.xichInfo.isTenkanSenCrossedUnderKijunSen ||
|
||||
mConditions.xichInfo.isFutureKumoSwitchedToBearish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (canX92Close)
|
||||
{
|
||||
//
|
||||
XGuard guard;
|
||||
|
||||
//
|
||||
guard.type = NULL;
|
||||
guard.symbol = mSymbol;
|
||||
guard.period = mPeriod;
|
||||
guard.provider = ToString(X92);
|
||||
guard.action = X_GUARD_ACTION_FORCE_CLOSE;
|
||||
|
||||
//
|
||||
Add(
|
||||
guard,
|
||||
guards);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Long ...
|
||||
bool x92HasSignal = false;
|
||||
bool canCheckX92 = IsAllowdSignaller(X92);
|
||||
if (canCheckX92)
|
||||
{
|
||||
//
|
||||
x92HasSignal =
|
||||
//
|
||||
mConditions.xichInfo.isFutureKumoBullish &&
|
||||
//
|
||||
(
|
||||
//
|
||||
mConditions.xichInfo.isTenkanSenCrossedOverKijunSen
|
||||
// //
|
||||
// ||
|
||||
// //
|
||||
// (
|
||||
// //
|
||||
// (mConditions.xichInfo.isTenkanSenOverKijunSen &&
|
||||
// mConditions.xichInfo.kijunSen > MathMax(mConditions.xichInfo.senkouSpanA, mConditions.xichInfo.senkouSpanB))
|
||||
// //
|
||||
// &&
|
||||
// //
|
||||
// !(mConditions2.xichInfo.isTenkanSenOverKijunSen &&
|
||||
// mConditions2.xichInfo.kijunSen > MathMax(mConditions2.xichInfo.senkouSpanA, mConditions2.xichInfo.senkouSpanB))
|
||||
// //
|
||||
// )
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (x92HasSignal)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
ToString(X92),
|
||||
mConditions.signal.providers);
|
||||
|
||||
//
|
||||
double tpPoint = 30;
|
||||
double tpPrice = PointToPrice(
|
||||
mConditions.symbol,
|
||||
tpPoint);
|
||||
double tp = entry + tpPrice;
|
||||
|
||||
//
|
||||
mConditions.signal.sl = 0;
|
||||
mConditions.signal.tp = 0; // tp;
|
||||
mConditions.signal.r2r = 1;
|
||||
mConditions.signal.entry = entry;
|
||||
mConditions.signal.riskAmount = 0.005;
|
||||
mConditions.signal.mode = X_ORDER_MODE_MARKET;
|
||||
|
||||
//
|
||||
mConditions.signal.ignoreSL = true;
|
||||
mConditions.signal.ignoreTP = true;
|
||||
mConditions.signal.useRiskAmountAsVolume = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
|
||||
//
|
||||
// Generate Specific Position's Support Comment
|
||||
// index is number of Supports ...
|
||||
string GenerateSupportSignalComment(
|
||||
ulong ticket, // Position/Order Ticket
|
||||
int index // Support Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
result = XSupportToken + "(" + (string)ticket + "," + ToString(index) + ")";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Extract Support Parameters String from specified Comment ...
|
||||
string ExtractSupportParam(string comment)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
if (StringLen(comment) <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = ExtractString(
|
||||
comment,
|
||||
XSupportToken + "(",
|
||||
")");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Extract Support Info as String array for Specific Comment ...
|
||||
bool ExtractSupportParams(
|
||||
string comment, // Specified Comment ...
|
||||
string ¶ms[] // Hold Result ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
string supParam = ExtractSupportParam(comment);
|
||||
if (StringLen(supParam) == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
SplitContent(
|
||||
params,
|
||||
supParam);
|
||||
int paramsCount = ArraySize(params);
|
||||
|
||||
//
|
||||
result = paramsCount == 2;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Extract Support Parent Ticket ...
|
||||
ulong ExtractParentTicket(string comment)
|
||||
{
|
||||
//
|
||||
ulong result = 0;
|
||||
|
||||
//
|
||||
string params[];
|
||||
bool isSupport = ExtractSupportParams(
|
||||
comment,
|
||||
params);
|
||||
if (!isSupport)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = (ulong)params[0];
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Extract Support Index ...
|
||||
int ExtractSupportIndex(string comment)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
string params[];
|
||||
bool isSupport = ExtractSupportParams(
|
||||
comment,
|
||||
params);
|
||||
if (!isSupport)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = (int)params[1];
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string GenerateSLTrailComment(int level)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
if (level <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = XSLTrailToken + "(" + ToString(level) + ")";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int ExtractSLTrailLevel(string comment)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
if (StringLen(comment) == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string levelStr = ExtractString(
|
||||
comment,
|
||||
XSLTrailToken + "(",
|
||||
")");
|
||||
if (StringLen(levelStr) == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = (int)levelStr;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string PrepareSLTrailComment(
|
||||
const string comment // Original Position Comment ...
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
if (StringLen(comment) == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int level = 0;
|
||||
result = comment;
|
||||
|
||||
//
|
||||
// Check Comment Contains SL Trailing or not ...
|
||||
int lastTrailLevel = ExtractSLTrailLevel(comment);
|
||||
if (lastTrailLevel <= 0)
|
||||
{
|
||||
level++;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
level = lastTrailLevel + 1;
|
||||
string lastLevelStr = GenerateSLTrailComment(lastTrailLevel);
|
||||
StringReplace(
|
||||
result,
|
||||
lastLevelStr,
|
||||
"");
|
||||
}
|
||||
|
||||
//
|
||||
// Generate level Comment ...
|
||||
string levelStr = GenerateSLTrailComment(level);
|
||||
result += levelStr;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
X786,X110,X121,X128
|
||||
X786,X110,X121,X128
|
||||
X786,X92,X110,X121,X128
|
||||
Reference in New Issue
Block a user