last ...
This commit is contained in:
@@ -1699,6 +1699,692 @@ if (useSenario1)
|
||||
Print("Has Inside Box ...");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
XOBFVG waitingZones[];
|
||||
XOBFVG unavailableZones[];
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
bool DetectZone(
|
||||
X121SMCStrategySignalProviderData & provider //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid() &&
|
||||
provider.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int idx = -1;
|
||||
int count = 0;
|
||||
bool has = false;
|
||||
datetime cTime = TimeCurrent();
|
||||
|
||||
//
|
||||
XOBFVG obFVG;
|
||||
XBoxZone obBox;
|
||||
XBoxZone fvgBox;
|
||||
XBoxZone supplyBox;
|
||||
XBoxZone demandBox;
|
||||
|
||||
//
|
||||
XCFVG *fvg = NULL;
|
||||
XCOrderBlock *ob = NULL;
|
||||
XCSupplyZone *supply = NULL;
|
||||
XCDemandZone *demand = NULL;
|
||||
|
||||
//
|
||||
// Check New Supply Zone Detection ...
|
||||
bool hasNewSupply =
|
||||
Contains(
|
||||
X_SUPPLY_ZONE_DETECTED,
|
||||
provider.consolidationPoiEvents //
|
||||
);
|
||||
if (hasNewSupply)
|
||||
{
|
||||
//
|
||||
idx = GetYoungest(provider
|
||||
.consolidationState
|
||||
.supplyZones //
|
||||
);
|
||||
has = IsValidIndex(idx);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
supply = provider
|
||||
.consolidationState
|
||||
.supplyZones[idx];
|
||||
has = ToBox(
|
||||
supplyBox,
|
||||
supply //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
supply.To(cTime);
|
||||
supplyBox.to = cTime;
|
||||
hasNewSupply = supplyBox.IsValid();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check New Demand Zone Detection ...
|
||||
bool hasNewDemand =
|
||||
Contains(
|
||||
X_DEMAND_ZONE_DETECTED,
|
||||
provider
|
||||
.consolidationPoiEvents //
|
||||
);
|
||||
if (hasNewDemand)
|
||||
{
|
||||
//
|
||||
idx = GetYoungest(provider
|
||||
.consolidationState
|
||||
.demandZones //
|
||||
);
|
||||
has = IsValidIndex(idx);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
demand = provider
|
||||
.consolidationState
|
||||
.demandZones[idx];
|
||||
has = ToBox(
|
||||
demandBox,
|
||||
demand //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
demand.To(cTime);
|
||||
demandBox.to = cTime;
|
||||
hasNewDemand = demandBox.IsValid();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check New Fair Value Gap Detection ...
|
||||
bool hasNewFairValueGap =
|
||||
Contains(
|
||||
X_BULLISH_FVG_DETECTED,
|
||||
provider
|
||||
.analysePoiEvents //
|
||||
) ||
|
||||
Contains(
|
||||
X_BEARISH_FVG_DETECTED,
|
||||
provider
|
||||
.analysePoiEvents //
|
||||
);
|
||||
if (hasNewFairValueGap)
|
||||
{
|
||||
//
|
||||
idx = GetYoungest(provider
|
||||
.analyseState
|
||||
.fairValueGaps //
|
||||
);
|
||||
has = IsValidIndex(idx);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
fvg = provider
|
||||
.analyseState
|
||||
.fairValueGaps[idx];
|
||||
has = ToBox(
|
||||
fvgBox,
|
||||
fvg //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
fvg.To(cTime);
|
||||
fvgBox.to = cTime;
|
||||
hasNewFairValueGap = fvgBox.IsValid();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check New Order Block Detection ...
|
||||
bool hasNewOrderBlock =
|
||||
Contains(
|
||||
X_BULLISH_ORDERBLOCK_DETECTED,
|
||||
provider
|
||||
.consolidationPoiEvents //
|
||||
) ||
|
||||
Contains(
|
||||
X_BEARISH_ORDERBLOCK_DETECTED,
|
||||
provider
|
||||
.consolidationPoiEvents //
|
||||
);
|
||||
if (hasNewOrderBlock)
|
||||
{
|
||||
//
|
||||
idx = GetYoungest(provider
|
||||
.consolidationState
|
||||
.orderBlocks //
|
||||
);
|
||||
has = IsValidIndex(idx);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
ob = provider
|
||||
.consolidationState
|
||||
.orderBlocks[idx];
|
||||
has = ToBox(
|
||||
obBox,
|
||||
ob //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
ob.To(cTime);
|
||||
obBox.to = cTime;
|
||||
hasNewOrderBlock = obBox.IsValid();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Detect OB FVG ...
|
||||
if (hasNewOrderBlock)
|
||||
{
|
||||
//
|
||||
XOHCL obStartedBar;
|
||||
bool isOBStartedBodyOut = false;
|
||||
bool isOBStarted = ob.IsStarted(
|
||||
ob.GetDirection(),
|
||||
obStartedBar,
|
||||
isOBStartedBodyOut //
|
||||
);
|
||||
|
||||
//
|
||||
has = isOBStarted;
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
obFVG.ob = ob;
|
||||
|
||||
//
|
||||
// Select FVGs ...
|
||||
count = provider
|
||||
.analyseState
|
||||
.CountFairValueGaps();
|
||||
has = IsValidSize(count);
|
||||
if (!has)
|
||||
{
|
||||
obFVG.Clean();
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Select FVG ...
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XCFVG *iFVG = provider
|
||||
.analyseState
|
||||
.fairValueGaps[i];
|
||||
bool isBullish = iFVG.IsBullish();
|
||||
|
||||
//
|
||||
XOHCL iStartedBar;
|
||||
bool isBodyOut = false;
|
||||
bool isStarted = iFVG.IsStarted(
|
||||
iFVG.GetDirection(),
|
||||
iStartedBar,
|
||||
isBodyOut //
|
||||
);
|
||||
iStartedBar.Clean();
|
||||
|
||||
//
|
||||
bool isKindPassed = isStarted &&
|
||||
isBodyOut;
|
||||
bool isSameDir = iFVG.GetDirection() == ob.GetDirection();
|
||||
bool isFromPassed = iFVG.From() >= obStartedBar.time;
|
||||
bool isPlacePassed =
|
||||
//
|
||||
IsInsideOrDiff(
|
||||
iFVG,
|
||||
ob //
|
||||
)
|
||||
//
|
||||
// ||
|
||||
// //
|
||||
// (isBullish
|
||||
// ? IsAboveDiff(
|
||||
// iFVG,
|
||||
// ob,
|
||||
// true // Ignore Inside ...
|
||||
// )
|
||||
// : IsBelowDiff(
|
||||
// iFVG,
|
||||
// ob,
|
||||
// true // Ignore Inside ...
|
||||
// )
|
||||
// //
|
||||
// )
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
has = isSameDir &&
|
||||
isKindPassed &&
|
||||
isFromPassed &&
|
||||
isPlacePassed;
|
||||
if (has)
|
||||
{
|
||||
obFVG.AddFVG(iFVG);
|
||||
}
|
||||
|
||||
//
|
||||
ZeroMemory(iFVG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
has = obFVG.IsValid();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
has = IsExists(obFVG);
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
// New Waiting Zone ...
|
||||
AddRef(
|
||||
obFVG,
|
||||
waitingZones //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Check Item Is not Exists ...
|
||||
idx = FindIndex(
|
||||
obFVG,
|
||||
waitingZones //
|
||||
);
|
||||
has = !IsValidIndex(idx);
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
// Update Exists Waiting Zone ...
|
||||
waitingZones[idx].AddFVG(fvg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
obFVG.Clean();
|
||||
obStartedBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//
|
||||
bool lookingOthers = false;
|
||||
if (lookingOthers)
|
||||
{
|
||||
//
|
||||
// Check New Order Block Detection Analyse ...
|
||||
XBoxZone analyseOBBox;
|
||||
XCOrderBlock *analyseOB = NULL;
|
||||
bool hasNewAnalyseOrderBlock =
|
||||
Contains(
|
||||
X_BULLISH_ORDERBLOCK_DETECTED,
|
||||
provider
|
||||
.analysePoiEvents //
|
||||
) ||
|
||||
Contains(
|
||||
X_BEARISH_ORDERBLOCK_DETECTED,
|
||||
provider
|
||||
.analysePoiEvents //
|
||||
);
|
||||
if (hasNewAnalyseOrderBlock)
|
||||
{
|
||||
//
|
||||
idx = GetYoungest(provider
|
||||
.analyseState
|
||||
.orderBlocks //
|
||||
);
|
||||
has = IsValidIndex(idx);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
analyseOB = provider
|
||||
.analyseState
|
||||
.orderBlocks[idx];
|
||||
has = ToBox(
|
||||
analyseOBBox,
|
||||
analyseOB //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
analyseOB.To(cTime);
|
||||
analyseOBBox.to = cTime;
|
||||
hasNewAnalyseOrderBlock = analyseOBBox.IsValid();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Checking Analyse Order Block ...
|
||||
if (hasNewAnalyseOrderBlock)
|
||||
{
|
||||
//
|
||||
XOHCL obStartedBar;
|
||||
bool isOBStartedBodyOut = false;
|
||||
bool isOBStarted = analyseOB.IsStarted(
|
||||
analyseOB.GetDirection(),
|
||||
obStartedBar,
|
||||
isOBStartedBodyOut //
|
||||
);
|
||||
|
||||
//
|
||||
has = isOBStarted &&
|
||||
isOBStartedBodyOut;
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
analyseOBBox.from =
|
||||
obStartedBar.NextAt();
|
||||
|
||||
//
|
||||
has = IsExists(analyseOBBox);
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
analyseOBBox,
|
||||
waitingBoxes //
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
analyseOBBox.Clean();
|
||||
ZeroMemory(analyseOB);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//
|
||||
result = HasWaitingZones();
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
|
||||
//
|
||||
obFVG.Clean();
|
||||
obBox.Clean();
|
||||
fvgBox.Clean();
|
||||
supplyBox.Clean();
|
||||
demandBox.Clean();
|
||||
|
||||
//
|
||||
ZeroMemory(ob);
|
||||
ZeroMemory(fvg);
|
||||
ZeroMemory(supply);
|
||||
ZeroMemory(demand);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
int ValidateWaitingZones(
|
||||
int barIndex = 0 //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
if (barIndex == 0)
|
||||
{
|
||||
barIndex = 1;
|
||||
}
|
||||
|
||||
//
|
||||
has = IsValid() &&
|
||||
HasWaitingZones();
|
||||
if (!has)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int removeIDX[];
|
||||
result = CountWaitingZones();
|
||||
for (int i = 0; i < result; i++)
|
||||
{
|
||||
//
|
||||
has = waitingZones[i].IsValidZone(
|
||||
barIndex //
|
||||
);
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
i,
|
||||
removeIDX //
|
||||
);
|
||||
|
||||
//
|
||||
AddRef(
|
||||
waitingZones[i],
|
||||
unavailableZones //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
has = HasChild(removeIDX);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
CleanupArray(
|
||||
removeIDX,
|
||||
waitingZones //
|
||||
);
|
||||
}
|
||||
Clean(removeIDX);
|
||||
|
||||
//
|
||||
result = CountWaitingZones();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
bool IsExists(XOBFVG & zone)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Check Validation ...
|
||||
result = zone.IsValid() &&
|
||||
(HasWaitingZones() ||
|
||||
HasUnavailableZones());
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int idx = -1;
|
||||
|
||||
//
|
||||
// Check Index in Waiting Zones ...
|
||||
idx = FindIndex(
|
||||
zone,
|
||||
waitingZones //
|
||||
);
|
||||
result = IsValidIndex(idx);
|
||||
if (result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Index in Unavailable Zones ...
|
||||
idx = FindIndex(
|
||||
zone,
|
||||
unavailableZones //
|
||||
);
|
||||
result = IsValidIndex(idx);
|
||||
if (result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
Clean(waitingZones);
|
||||
Clean(unavailableZones);
|
||||
|
||||
//
|
||||
bool HasWaitingZones()
|
||||
{
|
||||
return HasChild(waitingZones);
|
||||
}
|
||||
|
||||
//
|
||||
int CountWaitingZones()
|
||||
{
|
||||
return ArraySize(waitingZones);
|
||||
}
|
||||
|
||||
//
|
||||
bool HasUnavailableZones()
|
||||
{
|
||||
return HasChild(unavailableZones);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
has = HasWaitingZones();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
count = CountWaitingZones();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
waitingZones[i].UpdateTo(value);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
has = HasWaitingZones();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
count = CountWaitingZones();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XCBaseObject *iObjects[];
|
||||
int iObjectsCount = drawer.DrawOBFVG(
|
||||
waitingZones[i],
|
||||
iObjects,
|
||||
true, // Draw Order Block ...
|
||||
true, // Draw Fair Value Gaps ...
|
||||
true, // Draw All Fair Value Gaps ...
|
||||
//
|
||||
true, // Draw OB StartedBar ...
|
||||
true, // Draw OB ActivatedBar ...
|
||||
true, // Draw OB BreakedBar ...
|
||||
true, // Draw OB WorkedBar ...
|
||||
//
|
||||
true, // Draw FVG StartedBar ...
|
||||
true, // Draw FVG ActivatedBar ...
|
||||
true, // Draw FVG BreakedBar ...
|
||||
true // Draw FVG WorkedBar ...
|
||||
//
|
||||
);
|
||||
has = IsValidSize(iObjectsCount);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
for (int j = 0; j < iObjectsCount; j++)
|
||||
{
|
||||
mDrawnObjects.Add(iObjects[j]);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// if (drawWaitingZonesBoxArea)
|
||||
// {
|
||||
// //
|
||||
// XBoxZone iBox;
|
||||
// has = waitingZones[i].ToZone(
|
||||
// iBox //
|
||||
// );
|
||||
// if (has)
|
||||
// {
|
||||
// //
|
||||
// XCBoxObject *iBoxObj;
|
||||
// has = drawer.DrawBox(
|
||||
// iBox,
|
||||
// iBoxObj //
|
||||
// );
|
||||
// if (has)
|
||||
// {
|
||||
// mDrawnObjects.Add(iBoxObj);
|
||||
// }
|
||||
// }
|
||||
|
||||
// //
|
||||
// iBox.Clean();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user