844 lines
15 KiB
Plaintext
844 lines
15 KiB
Plaintext
|
|
//
|
|
// Order Flow ...
|
|
|
|
//
|
|
bool drawOrderFlow;
|
|
XBoxZone orderFlow[];
|
|
bool manageOrderFlow;
|
|
ENUM_X_DIRECTION orderFlowDir;
|
|
|
|
//
|
|
bool HasOrderFlow()
|
|
{
|
|
//
|
|
return HasChild(orderFlow) &&
|
|
HasDirection(orderFlowDir);
|
|
}
|
|
|
|
//
|
|
bool HasBullishOrderFlow()
|
|
{
|
|
return HasOrderFlow() &&
|
|
IsXBullish(orderFlowDir);
|
|
}
|
|
|
|
//
|
|
bool HasBearishOrderFlow()
|
|
{
|
|
return HasOrderFlow() &&
|
|
IsXBearish(orderFlowDir);
|
|
}
|
|
|
|
//
|
|
bool GetOrderFlowBoundary(
|
|
double &upper,
|
|
double &lower //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Prepare ...
|
|
upper = EMPTY_VALUE;
|
|
lower = EMPTY_VALUE;
|
|
|
|
//
|
|
// Validate ...
|
|
result = HasOrderFlow();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int idx = -1;
|
|
|
|
//
|
|
// Upper ...
|
|
idx = GetHighest(orderFlow);
|
|
if (IsValidIndex(idx))
|
|
{
|
|
upper = orderFlow[idx].upper;
|
|
}
|
|
|
|
//
|
|
// Lower ...
|
|
idx = GetLowest(orderFlow);
|
|
if (IsValidIndex(idx))
|
|
{
|
|
lower = orderFlow[idx].lower;
|
|
}
|
|
|
|
//
|
|
result = NotEmptyZero(upper) &&
|
|
NotEmptyZero(lower) &&
|
|
upper > lower;
|
|
|
|
//
|
|
// Cleanup ...
|
|
if (!result)
|
|
{
|
|
//
|
|
upper = EMPTY_VALUE;
|
|
lower = EMPTY_VALUE;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool ValidateOrderFlow(XOHCL &bar)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Validate ...
|
|
result = bar.IsValid() &&
|
|
HasOrderFlow();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double upper = EMPTY_VALUE;
|
|
double lower = EMPTY_VALUE;
|
|
result = GetOrderFlowBoundary(upper, lower);
|
|
result = result &&
|
|
HasBullishOrderFlow()
|
|
? bar.low > lower
|
|
: bar.high < upper;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
void DrawOrderFlow()
|
|
{
|
|
//
|
|
if (!drawOrderFlow || !HasOrderFlow())
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
poiDrawer.DrawZones(orderFlow, structureDrawConfig.drawConfig);
|
|
}
|
|
|
|
//
|
|
void ManageOrderFlow(XOHCL &bar)
|
|
{
|
|
//
|
|
// Validate Exists ...
|
|
if (HasOrderFlow())
|
|
{
|
|
//
|
|
if (!ValidateOrderFlow(bar))
|
|
{
|
|
//
|
|
// Invalidate OrderFlow ...
|
|
XClean(orderFlow);
|
|
orderFlowDir = X_DIRECTION_NONE;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Detect New ...
|
|
if (!HasOrderFlow())
|
|
{
|
|
//
|
|
XPatternAnalysisConfig patternConfig = structureConfig.barsAnalysisConfig;
|
|
// patternConfig.Default();
|
|
// patternConfig.supportAndResistanceLoopbackLength = 21;
|
|
// patternConfig.supportAndResistanceValidationLength = 7;
|
|
|
|
//
|
|
poiDetector.HasOrderFlow(
|
|
bar,
|
|
orderFlowDir,
|
|
orderFlow,
|
|
structureConfig.orderFlowValidation,
|
|
structureConfig.orderFlowUseOB,
|
|
structureConfig.orderFlowUseFVG,
|
|
structureConfig.orderFlowUseSupportAndResistance,
|
|
patternConfig.supportAndResistanceLoopbackLength,
|
|
patternConfig.supportAndResistanceValidationLength,
|
|
structureConfig.loopback //
|
|
);
|
|
}
|
|
|
|
//
|
|
// Update Exists ...
|
|
if (HasOrderFlow())
|
|
{
|
|
//
|
|
// Update to Times ...
|
|
UpdateToTime(orderFlow, TimeCurrent());
|
|
|
|
//
|
|
DrawOrderFlow();
|
|
}
|
|
}
|
|
|
|
//
|
|
// Zone ...
|
|
|
|
//
|
|
XBoxZone support;
|
|
XBoxZone resistance;
|
|
bool drawZones;
|
|
bool drawSupport;
|
|
bool manageZones;
|
|
bool drawResistance;
|
|
|
|
//
|
|
bool HasZones()
|
|
{
|
|
return HasSupport() ||
|
|
HasResistance();
|
|
}
|
|
|
|
//
|
|
bool HasSupport()
|
|
{
|
|
return support.IsValid();
|
|
}
|
|
|
|
//
|
|
bool HasResistance()
|
|
{
|
|
return resistance.IsValid();
|
|
}
|
|
|
|
//
|
|
bool ValidateZones(XOHCL &bar)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Validate ...
|
|
result = bar.IsValid() &&
|
|
HasZones();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Support ...
|
|
bool hasSupport = HasSupport();
|
|
if (hasSupport)
|
|
{
|
|
//
|
|
result = bar.close > support.lower &&
|
|
!IsBreaked(support, X_PRICE_CLOSE);
|
|
if (!result)
|
|
{
|
|
//
|
|
iResistance = support;
|
|
iResistance.breakAt = NULL;
|
|
iResistance.dir = X_DIRECTION_BEARISH;
|
|
iResistance.to = bar.time + (PeriodSeconds(bar.period));
|
|
iResistance.from = bar.time - (PeriodSeconds(bar.period));
|
|
|
|
//
|
|
support.breakAt = bar.time;
|
|
support.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
// Resistance ...
|
|
bool hasResistance = HasResistance();
|
|
if (hasResistance)
|
|
{
|
|
//
|
|
result = bar.close < resistance.upper &&
|
|
!IsBreaked(resistance, X_PRICE_CLOSE);
|
|
if (!result)
|
|
{
|
|
//
|
|
iSupport = resistance;
|
|
iSupport.breakAt = NULL;
|
|
iSupport.dir = X_DIRECTION_BULLISH;
|
|
iSupport.to = bar.time + (PeriodSeconds(bar.period));
|
|
iSupport.from = bar.time - (PeriodSeconds(bar.period));
|
|
|
|
//
|
|
resistance.breakAt = bar.time;
|
|
resistance.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
result =
|
|
(hasSupport && !HasSupport()) ||
|
|
(hasResistance && !HasResistance());
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
void DrawZones()
|
|
{
|
|
//
|
|
if (!drawZones || !HasZones())
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
if (drawSupport && HasSupport())
|
|
{
|
|
poiDrawer.DrawZone(support, structureDrawConfig.drawConfig);
|
|
}
|
|
|
|
//
|
|
if (drawResistance && HasResistance())
|
|
{
|
|
poiDrawer.DrawZone(resistance, structureDrawConfig.drawConfig);
|
|
}
|
|
}
|
|
|
|
//
|
|
void ManageZones(XOHCL &bar)
|
|
{
|
|
//
|
|
// Validate Exists ...
|
|
if (HasZones())
|
|
{
|
|
//
|
|
if (!ValidateZones(bar))
|
|
{
|
|
//
|
|
// Invalidate Zones ...
|
|
|
|
//
|
|
// Support ...
|
|
if (IsXValid(support.breakAt))
|
|
{
|
|
//
|
|
iResistance = support;
|
|
iResistance.breakAt = NULL;
|
|
iResistance.dir = X_DIRECTION_BEARISH;
|
|
iResistance.to = bar.time + (PeriodSeconds(bar.period));
|
|
iResistance.from = bar.time - (PeriodSeconds(bar.period));
|
|
|
|
//
|
|
support.Clean();
|
|
}
|
|
|
|
//
|
|
// Resistance ...
|
|
if (IsXValid(resistance.breakAt))
|
|
{
|
|
//
|
|
iSupport = resistance;
|
|
iSupport.breakAt = NULL;
|
|
iSupport.dir = X_DIRECTION_BULLISH;
|
|
iSupport.to = bar.time + (PeriodSeconds(bar.period));
|
|
iSupport.from = bar.time - (PeriodSeconds(bar.period));
|
|
|
|
//
|
|
resistance.Clean();
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Detect New ...
|
|
XOHCL tmpBar;
|
|
bool has = false;
|
|
|
|
//
|
|
// Detect Support ...
|
|
if (!HasSupport())
|
|
{
|
|
//
|
|
has = poiDetector.HasSupport(
|
|
bar,
|
|
tmpBar,
|
|
structureConfig.barsAnalysisConfig.supportAndResistanceValidationLength,
|
|
structureConfig.barsAnalysisConfig.supportAndResistanceLoopbackLength //
|
|
);
|
|
if (has)
|
|
{
|
|
//
|
|
has = ToSupportBox(tmpBar, support, bar.time);
|
|
has =
|
|
has &&
|
|
!IsBreaked(support, X_PRICE_CLOSE);
|
|
if (!has)
|
|
{
|
|
//
|
|
if (support.IsValid())
|
|
{
|
|
//
|
|
iResistance = support;
|
|
iResistance.breakAt = NULL;
|
|
iResistance.dir = X_DIRECTION_BEARISH;
|
|
iResistance.to = bar.time + (PeriodSeconds(bar.period));
|
|
iResistance.from = bar.time - (PeriodSeconds(bar.period));
|
|
}
|
|
|
|
//
|
|
support.Clean();
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Detect Resistance ...
|
|
if (!HasResistance())
|
|
{
|
|
//
|
|
has = poiDetector.HasResistance(
|
|
bar,
|
|
tmpBar,
|
|
structureConfig.barsAnalysisConfig.supportAndResistanceValidationLength,
|
|
structureConfig.barsAnalysisConfig.supportAndResistanceLoopbackLength //
|
|
);
|
|
if (has)
|
|
{
|
|
//
|
|
has = ToResistanceBox(tmpBar, resistance, bar.time);
|
|
has =
|
|
has &&
|
|
!IsBreaked(resistance, X_PRICE_CLOSE);
|
|
if (!has)
|
|
{
|
|
//
|
|
if (resistance.IsValid())
|
|
{
|
|
//
|
|
iSupport = resistance;
|
|
iSupport.breakAt = NULL;
|
|
iSupport.dir = X_DIRECTION_BULLISH;
|
|
iSupport.to = bar.time + (PeriodSeconds(bar.period));
|
|
iSupport.from = bar.time - (PeriodSeconds(bar.period));
|
|
}
|
|
|
|
//
|
|
resistance.Clean();
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Update Exists ...
|
|
if (HasZones())
|
|
{
|
|
//
|
|
if (HasSupport())
|
|
{
|
|
//
|
|
support.to = bar.time;
|
|
support.type = "XFIMASup";
|
|
}
|
|
|
|
//
|
|
if (HasResistance())
|
|
{
|
|
//
|
|
resistance.to = bar.time;
|
|
resistance.type = "XFIMARes";
|
|
}
|
|
|
|
//
|
|
DrawZones();
|
|
}
|
|
|
|
//
|
|
// Cleanup ...
|
|
tmpBar.Clean();
|
|
}
|
|
|
|
//
|
|
XBoxZone iSupport;
|
|
XBoxZone iResistance;
|
|
bool drawIZones;
|
|
bool drawISupport;
|
|
bool manageIZones;
|
|
bool drawIResistance;
|
|
|
|
//
|
|
bool HasIZones()
|
|
{
|
|
//
|
|
return HasISupport() ||
|
|
HasIResistance();
|
|
}
|
|
|
|
//
|
|
bool HasISupport()
|
|
{
|
|
return iSupport.IsValid();
|
|
}
|
|
|
|
//
|
|
bool HasIResistance()
|
|
{
|
|
return iResistance.IsValid();
|
|
}
|
|
|
|
//
|
|
void DrawIZones()
|
|
{
|
|
//
|
|
if (!drawIZones || !HasIZones())
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
if (drawISupport && HasISupport())
|
|
{
|
|
poiDrawer.DrawZone(iSupport, structureDrawConfig.drawConfig);
|
|
}
|
|
|
|
//
|
|
if (drawIResistance && HasIResistance())
|
|
{
|
|
poiDrawer.DrawZone(iResistance, structureDrawConfig.drawConfig);
|
|
}
|
|
}
|
|
|
|
//
|
|
bool ValidateIZones(XOHCL &bar)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Validate ...
|
|
result = bar.IsValid() &&
|
|
HasIZones();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
|
|
//
|
|
// Support ...
|
|
bool hasSupport = HasISupport();
|
|
if (hasSupport)
|
|
{
|
|
//
|
|
result = bar.close > iSupport.lower &&
|
|
!IsBreaked(iSupport, X_PRICE_CLOSE);
|
|
if (!result)
|
|
{
|
|
//
|
|
iSupport.breakAt = bar.time;
|
|
iSupport.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
// Resistance ...
|
|
bool hasResistance = HasIResistance();
|
|
if (hasResistance)
|
|
{
|
|
//
|
|
result = bar.close < iResistance.upper &&
|
|
!IsBreaked(iResistance, X_PRICE_CLOSE);
|
|
if (!result)
|
|
{
|
|
//
|
|
iResistance.breakAt = bar.time;
|
|
iResistance.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
result =
|
|
(hasSupport && !HasISupport()) ||
|
|
(hasResistance && !HasIResistance());
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
void ManageIZones(XOHCL &bar)
|
|
{
|
|
//
|
|
// Validate Exists ...
|
|
if (HasIZones())
|
|
{
|
|
//
|
|
if (!ValidateIZones(bar))
|
|
{
|
|
//
|
|
// Invalidate Zones ...
|
|
|
|
//
|
|
// Support ...
|
|
if (IsXValid(iSupport.breakAt))
|
|
{
|
|
iSupport.Clean();
|
|
}
|
|
|
|
//
|
|
// Resistance ...
|
|
if (IsXValid(iResistance.breakAt))
|
|
{
|
|
iResistance.Clean();
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Update Exists ...
|
|
if (HasIZones())
|
|
{
|
|
//
|
|
if (HasISupport())
|
|
{
|
|
//
|
|
iSupport.to = bar.time;
|
|
iSupport.type = "XFIMAISup";
|
|
}
|
|
|
|
//
|
|
if (HasIResistance())
|
|
{
|
|
//
|
|
iResistance.to = bar.time;
|
|
iResistance.type = "XFIMAIRes";
|
|
}
|
|
|
|
//
|
|
DrawIZones();
|
|
}
|
|
}
|
|
|
|
//
|
|
// Trends ...
|
|
|
|
//
|
|
XTrend scTrend;
|
|
XTrend mcTrend;
|
|
XTrend lcTrend;
|
|
XTrend hcTrend;
|
|
|
|
//
|
|
bool drawTrends;
|
|
bool drawSCTrend;
|
|
bool drawMCTrend;
|
|
bool drawLCTrend;
|
|
bool drawHCTrend;
|
|
bool manageTrends;
|
|
|
|
//
|
|
bool HasTrend()
|
|
{
|
|
//
|
|
bool result =
|
|
HasSCTrend() ||
|
|
HasMCTrend() ||
|
|
HasLCTrend() ||
|
|
HasHCTrend();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool HasSCTrend()
|
|
{
|
|
return scTrend.IsValid() &&
|
|
scTrend.HasTrend();
|
|
}
|
|
|
|
//
|
|
bool HasMCTrend()
|
|
{
|
|
return mcTrend.IsValid() &&
|
|
mcTrend.HasTrend();
|
|
}
|
|
|
|
//
|
|
bool HasLCTrend()
|
|
{
|
|
return lcTrend.IsValid() &&
|
|
lcTrend.HasTrend();
|
|
}
|
|
|
|
//
|
|
bool HasHCTrend()
|
|
{
|
|
return hcTrend.IsValid() &&
|
|
hcTrend.HasTrend();
|
|
}
|
|
|
|
//
|
|
void DrawTrends()
|
|
{
|
|
//
|
|
if (!drawTrends || !HasTrend())
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
// SC ...
|
|
if (drawSCTrend && HasSCTrend())
|
|
{
|
|
poiDrawer.DrawTrendLine(scTrend, structureDrawConfig.drawConfig);
|
|
}
|
|
|
|
//
|
|
// MC ...
|
|
if (drawMCTrend && HasMCTrend())
|
|
{
|
|
poiDrawer.DrawTrendLine(mcTrend, structureDrawConfig.drawConfig);
|
|
}
|
|
|
|
//
|
|
// LC ...
|
|
if (drawLCTrend && HasLCTrend())
|
|
{
|
|
poiDrawer.DrawTrendLine(lcTrend, structureDrawConfig.drawConfig);
|
|
}
|
|
|
|
//
|
|
// HC ...
|
|
if (drawHCTrend && HasHCTrend())
|
|
{
|
|
poiDrawer.DrawTrendLine(hcTrend, structureDrawConfig.drawConfig);
|
|
}
|
|
}
|
|
|
|
//
|
|
void ManageTrends(XOHCL &bar)
|
|
{
|
|
//
|
|
// Validate ...
|
|
bool has = bar.IsValid();
|
|
if (!has)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
XTrend tmpTrend;
|
|
|
|
//
|
|
// SC ...
|
|
tmpTrend.Clean();
|
|
has = fimaParser.HasSCTrend(tmpTrend, bar.Index());
|
|
if (has)
|
|
{
|
|
scTrend = tmpTrend;
|
|
}
|
|
|
|
//
|
|
// MC ...
|
|
tmpTrend.Clean();
|
|
has = fimaParser.HasMCTrend(tmpTrend, bar.Index());
|
|
if (has)
|
|
{
|
|
mcTrend = tmpTrend;
|
|
}
|
|
|
|
//
|
|
// LC ...
|
|
tmpTrend.Clean();
|
|
has = fimaParser.HasLCTrend(tmpTrend, bar.Index());
|
|
if (has)
|
|
{
|
|
lcTrend = tmpTrend;
|
|
}
|
|
|
|
//
|
|
// HC ...
|
|
tmpTrend.Clean();
|
|
has = fimaParser.HasHCTrend(tmpTrend, bar.Index());
|
|
if (has)
|
|
{
|
|
hcTrend = tmpTrend;
|
|
}
|
|
|
|
//
|
|
DrawTrends();
|
|
|
|
//
|
|
// Cleanup ...
|
|
tmpTrend.Clean();
|
|
}
|
|
|
|
//
|
|
void Manage(XOHCL &bar)
|
|
{
|
|
//
|
|
bool has = bar.IsValid();
|
|
if (!has)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
XOHCL pBar;
|
|
XOHCL p2Bar;
|
|
XOHCL p3Bar;
|
|
has = bar.GetPreviousBar(pBar);
|
|
has = has &&
|
|
pBar.GetPreviousBar(p2Bar);
|
|
has = has &&
|
|
p2Bar.GetPreviousBar(p3Bar);
|
|
if (!has)
|
|
{
|
|
//
|
|
pBar.Clean();
|
|
p2Bar.Clean();
|
|
p3Bar.Clean();
|
|
}
|
|
|
|
//
|
|
ManageTrends(bar);
|
|
ManageZones(p2Bar);
|
|
ManageIZones(p2Bar);
|
|
ManageOrderFlow(p3Bar);
|
|
|
|
//
|
|
// Cleanup ...
|
|
pBar.Clean();
|
|
p2Bar.Clean();
|
|
p3Bar.Clean();
|
|
}
|
|
|
|
//
|
|
// Configure ...
|
|
drawZones = false;
|
|
drawIZones = false;
|
|
drawTrends = false;
|
|
drawSCTrend = false;
|
|
drawMCTrend = false;
|
|
drawLCTrend = false;
|
|
drawHCTrend = false;
|
|
drawSupport = false;
|
|
drawISupport = false;
|
|
drawOrderFlow = false;
|
|
drawResistance = false;
|
|
drawIResistance = false;
|
|
|
|
//
|
|
manageZones = true;
|
|
manageIZones = true;
|
|
manageTrends = false;
|
|
manageOrderFlow = true;
|
|
|
|
//
|
|
// Manage ...
|
|
Manage(iBar);
|