apply some EQM Force State Handling ...
This commit is contained in:
@@ -978,29 +978,11 @@ struct X121SignalGenerator
|
||||
{
|
||||
//
|
||||
string version;
|
||||
double hotLevels[];
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
void X121SignalGenerator()
|
||||
{
|
||||
//
|
||||
Add(
|
||||
0.25,
|
||||
hotLevels //
|
||||
);
|
||||
|
||||
//
|
||||
Add(
|
||||
0.20,
|
||||
hotLevels //
|
||||
);
|
||||
|
||||
//
|
||||
Add(
|
||||
0.15,
|
||||
hotLevels //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -3169,552 +3151,6 @@ struct X121SignalGenerator
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Ticks Zone ...
|
||||
XSCZones *zones = new XSCZones(
|
||||
signal.symbol,
|
||||
signal.period //
|
||||
);
|
||||
|
||||
//
|
||||
XSCZonesInput zonesInput;
|
||||
zonesInput.length = 26;
|
||||
zonesInput.numberOfZones = 10;
|
||||
|
||||
//
|
||||
zonesInput.AddLevelColor(
|
||||
hotLevels[0],
|
||||
clrRed //
|
||||
);
|
||||
zonesInput.AddLevelColor(
|
||||
hotLevels[1],
|
||||
clrOrange //
|
||||
);
|
||||
zonesInput.AddLevelColor(
|
||||
hotLevels[2],
|
||||
clrLightCoral //
|
||||
);
|
||||
|
||||
//
|
||||
bool canUseZones = zones.Init(zonesInput);
|
||||
if (canUseZones)
|
||||
{
|
||||
signal.zones = zones;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Trend ...
|
||||
XSCTrend *trend = new XSCTrend(
|
||||
signal.symbol,
|
||||
signal.period //
|
||||
);
|
||||
|
||||
//
|
||||
XSCTrendInput tInputs;
|
||||
tInputs.Default();
|
||||
bool canUseTrend = trend.Init(tInputs);
|
||||
if (canUseTrend)
|
||||
{
|
||||
//
|
||||
signal.trend = trend;
|
||||
}
|
||||
|
||||
//
|
||||
XSCCFInput cfInputs;
|
||||
cfInputs.Default();
|
||||
XSCCF *cf = new XSCCF(
|
||||
signal.symbol,
|
||||
signal.period //
|
||||
);
|
||||
bool canUseCF = cf.Init(cfInputs);
|
||||
if (canUseCF)
|
||||
{
|
||||
signal.cf = cf;
|
||||
}
|
||||
|
||||
//
|
||||
// Generate Support Signals ...
|
||||
// if (_useSupport)
|
||||
// {
|
||||
// //
|
||||
// GenerateSupportSignals(
|
||||
// signal //
|
||||
// );
|
||||
// }
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
void GenerateSupportSignals(
|
||||
XSignal &signal // Source Signal for Support Generating ...
|
||||
)
|
||||
{
|
||||
//
|
||||
double pivots[];
|
||||
int pivotsCount = GenerateSupportPivots(
|
||||
signal,
|
||||
pivots //
|
||||
);
|
||||
if (!IsValidSize(pivotsCount))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
XSignal supports[];
|
||||
int indirectionalsCount =
|
||||
PrepareInDirectionalSupportSignals(
|
||||
supports,
|
||||
signal,
|
||||
pivots //
|
||||
);
|
||||
if (IsValidSize(indirectionalsCount))
|
||||
{
|
||||
//
|
||||
Copy(
|
||||
supports,
|
||||
signal.supports //
|
||||
);
|
||||
|
||||
//
|
||||
Clean(supports);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
int GenerateSupportPivots(
|
||||
XSignal &signal, // Source Signal for Support Generating ...
|
||||
double &pivots[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Validate Signal ...
|
||||
if (!signal.IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Signal Direction ...
|
||||
bool isLong = IsLong(signal.type);
|
||||
|
||||
//
|
||||
bool canUseCF = signal.cf != NULL &&
|
||||
signal.cf.IsValid();
|
||||
bool canUseZones = signal.zones != NULL &&
|
||||
signal.zones.IsValid();
|
||||
bool canUseTrend = signal.trend != NULL &&
|
||||
signal.trend.IsValid();
|
||||
|
||||
//
|
||||
datetime prevTime = iTime(
|
||||
signal.symbol,
|
||||
signal.period,
|
||||
1 //
|
||||
);
|
||||
|
||||
//
|
||||
datetime cTime = TimeCurrent();
|
||||
|
||||
//
|
||||
string entryLineName = "sEntry" + signal.symbol;
|
||||
DrawTrendLine(
|
||||
0,
|
||||
entryLineName,
|
||||
0,
|
||||
prevTime,
|
||||
signal.entry,
|
||||
cTime,
|
||||
signal.entry,
|
||||
clrYellow,
|
||||
STYLE_SOLID,
|
||||
2,
|
||||
false,
|
||||
false,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
Clean(pivots);
|
||||
double tmpPivots[];
|
||||
|
||||
//
|
||||
if (canUseCF)
|
||||
{
|
||||
//
|
||||
signal.cf.Draw();
|
||||
XOHCL cfBULLBar = signal.cf.GetBullishBar();
|
||||
XOHCL cfBEARBar = signal.cf.GetBearishBar();
|
||||
|
||||
//
|
||||
Add(
|
||||
cfBULLBar.high,
|
||||
tmpPivots //
|
||||
);
|
||||
Add(
|
||||
cfBULLBar.low,
|
||||
tmpPivots //
|
||||
);
|
||||
Add(
|
||||
cfBEARBar.high,
|
||||
tmpPivots //
|
||||
);
|
||||
Add(
|
||||
cfBEARBar.low,
|
||||
tmpPivots //
|
||||
);
|
||||
|
||||
//
|
||||
signal.cf.Remove();
|
||||
}
|
||||
|
||||
//
|
||||
if (canUseTrend)
|
||||
{
|
||||
//
|
||||
signal.trend.Draw();
|
||||
|
||||
//
|
||||
// Lows ...
|
||||
Add(
|
||||
signal.trend.GetLows(),
|
||||
tmpPivots //
|
||||
);
|
||||
|
||||
//
|
||||
// Highs ...
|
||||
Add(
|
||||
signal.trend.GetHighs(),
|
||||
tmpPivots //
|
||||
);
|
||||
|
||||
//
|
||||
// Support ...
|
||||
Add(
|
||||
signal.trend.GetSupport(),
|
||||
tmpPivots //
|
||||
);
|
||||
|
||||
//
|
||||
// Resistance ...
|
||||
Add(
|
||||
signal.trend.GetResistance(),
|
||||
tmpPivots //
|
||||
);
|
||||
|
||||
//
|
||||
signal.trend.Remove();
|
||||
}
|
||||
|
||||
//
|
||||
if (canUseZones)
|
||||
{
|
||||
//
|
||||
signal.zones.Draw();
|
||||
|
||||
//
|
||||
// Find Hot Zones ...
|
||||
for (int i = 0; i < signal.zones.CountZones(); i++)
|
||||
{
|
||||
//
|
||||
// Retrieve Indexed Zone ...
|
||||
XSCZone *iZone = signal.zones.GetZone(i);
|
||||
|
||||
//
|
||||
// Check Zone is Hot Zone or not ...
|
||||
bool isHotZone = false;
|
||||
for (int j = 0; j < ArraySize(hotLevels); j++)
|
||||
{
|
||||
//
|
||||
isHotZone = (iZone.percent / 100) >= hotLevels[j];
|
||||
if (isHotZone)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Prevent Moving Forward if there isn't Hot Zone ...
|
||||
if (!isHotZone)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Zone High ...
|
||||
Add(
|
||||
iZone.high,
|
||||
tmpPivots //
|
||||
);
|
||||
|
||||
//
|
||||
// Zone Low ...
|
||||
Add(
|
||||
iZone.low,
|
||||
tmpPivots //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
signal.zones.Remove();
|
||||
}
|
||||
|
||||
//
|
||||
int tmpPivotsCount = ArraySize(tmpPivots);
|
||||
if (!IsValidSize(tmpPivotsCount))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < tmpPivotsCount; i++)
|
||||
{
|
||||
//
|
||||
double iPivot = tmpPivots[i];
|
||||
|
||||
//
|
||||
bool isValidPivot =
|
||||
isLong
|
||||
? signal.entry > iPivot
|
||||
: signal.entry < iPivot;
|
||||
if (isValidPivot)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
iPivot,
|
||||
pivots //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
ArrayFree(tmpPivots);
|
||||
|
||||
//
|
||||
RemoveDraws(entryLineName);
|
||||
|
||||
//
|
||||
result = ArraySize(pivots);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool PrepareDirectionalSupportSignals(
|
||||
XPosition &support,
|
||||
XPosition &parent,
|
||||
XSignal &result //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool mResult = false;
|
||||
|
||||
//
|
||||
result.Clean();
|
||||
|
||||
//
|
||||
mResult = support.IsValid() && parent.IsValid();
|
||||
if (!mResult)
|
||||
{
|
||||
return mResult;
|
||||
}
|
||||
|
||||
//
|
||||
mResult = support.provider == XEQMSupportToken + XINDirectionalToken;
|
||||
if (!mResult)
|
||||
{
|
||||
return mResult;
|
||||
}
|
||||
|
||||
//
|
||||
// Indirectional Supports Updated Using Directional ...
|
||||
|
||||
//
|
||||
double entryPrice = GetEntry(
|
||||
parent.symbol,
|
||||
parent.type //
|
||||
);
|
||||
|
||||
//
|
||||
ENUM_X_ORDER_MODES rMode = X_ORDER_MODE_NOTHING;
|
||||
bool isParentLong = IsLong(parent.type);
|
||||
if (isParentLong)
|
||||
{
|
||||
//
|
||||
if (entryPrice < parent.entry)
|
||||
{
|
||||
rMode = X_ORDER_MODE_STOP;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
if (entryPrice > parent.entry)
|
||||
{
|
||||
rMode = X_ORDER_MODE_STOP;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
mResult = rMode != X_ORDER_MODE_NOTHING;
|
||||
if (!mResult)
|
||||
{
|
||||
return mResult;
|
||||
}
|
||||
|
||||
//
|
||||
mResult = result.Prepare(
|
||||
parent.symbol,
|
||||
XEQMSupportToken + XDirectionalToken,
|
||||
parent.period,
|
||||
parent.type,
|
||||
rMode,
|
||||
parent.entry,
|
||||
parent.volume,
|
||||
0,
|
||||
0 //
|
||||
);
|
||||
|
||||
//
|
||||
if (mResult)
|
||||
{
|
||||
//
|
||||
string comment = GenerateSupportTag(parent.ticket);
|
||||
result.comment = comment;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
return mResult;
|
||||
}
|
||||
|
||||
//
|
||||
int PrepareInDirectionalSupportSignals(
|
||||
XSignal &supports[],
|
||||
XSignal &source,
|
||||
double &pivots[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
Clean(supports);
|
||||
|
||||
//
|
||||
int pivotsCount = ArraySize(pivots);
|
||||
if (!IsValidSize(pivotsCount))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool isLong = IsLong(source.type);
|
||||
|
||||
//
|
||||
XSignal rSignal; // Recovery Signal ...
|
||||
|
||||
//
|
||||
double rSL = 0; // Recovery Stop Loss ...
|
||||
double rTP = 0; // Recovery Take Profit ...
|
||||
double rEntry = 0; // Recovery Entry Point ...
|
||||
double rVolume = 0; // Recovery Volume ...
|
||||
ENUM_POSITION_TYPE rType; // Recovery Signal Type ...
|
||||
ENUM_X_ORDER_MODES rMode; // Recovery Signal Mode ...
|
||||
bool isSignalPrepared = false; // Check Signal Preparation Succeed ...
|
||||
|
||||
//
|
||||
bool condition = false;
|
||||
|
||||
//
|
||||
double onePointValue = PointToPrice(1, source.symbol);
|
||||
|
||||
//
|
||||
double directionalVolumeMultiplier = 1;
|
||||
double inDirectionalVolumeMultiplier = 2;
|
||||
|
||||
//
|
||||
// if Long we are Looking for lower prices than
|
||||
// entry price and vise verse ...
|
||||
|
||||
//
|
||||
for (int i = 0; i < pivotsCount; i++)
|
||||
{
|
||||
//
|
||||
double iPivot = pivots[i];
|
||||
|
||||
//
|
||||
bool isValidPrice =
|
||||
isLong
|
||||
? source.entry > iPivot
|
||||
: source.entry < iPivot;
|
||||
if (!isValidPrice)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// InDirectional ...
|
||||
if (isLong)
|
||||
{
|
||||
//
|
||||
rType = POSITION_TYPE_SELL;
|
||||
rMode = X_ORDER_MODE_STOP;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
rType = POSITION_TYPE_BUY;
|
||||
rMode = X_ORDER_MODE_STOP;
|
||||
}
|
||||
|
||||
//
|
||||
rEntry = iPivot;
|
||||
rVolume = source.volume;
|
||||
|
||||
//
|
||||
isSignalPrepared = rSignal.Prepare(
|
||||
source.symbol,
|
||||
XEQMSupportToken + XINDirectionalToken,
|
||||
source.period,
|
||||
rType,
|
||||
rMode,
|
||||
rEntry,
|
||||
rVolume,
|
||||
rSL,
|
||||
rTP //
|
||||
);
|
||||
if (isSignalPrepared)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
rSignal,
|
||||
supports //
|
||||
);
|
||||
|
||||
//
|
||||
rSignal.Clean();
|
||||
|
||||
//
|
||||
rSL = 0;
|
||||
rTP = 0;
|
||||
rEntry = 0;
|
||||
isSignalPrepared = false;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = ArraySize(supports);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user