Files
MQL5Data/Documents/BKP/inside.box.sig.mq5
T
2025-03-19 01:38:07 +03:30

831 lines
20 KiB
Plaintext

//
bool HasSenario1Conditions(
ENUM_X_CYCLES cycle,
XBoxZone &box,
XBoxZone &holderBox,
ENUM_X_DIRECTION &dir,
XBoxZone &waitingBoxes[],
X121SMCStrategySignalProviderData &provider,
ENUM_X_CYCLES holderCycle = X_CYCLE_NONE,
int barIndex = 0 //
)
{
//
bool result = false;
//
// Fil Selected Data ...
XPOIState cState;
X121Conditions cXConditions;
XPOIStateEvents cStateEvents;
XC121SMCCycleHelper *cHelper;
X121SMCCycleConditions cConditions;
result = provider.SelectCycle(
cycle,
cState,
cStateEvents,
cXConditions,
cHelper,
cConditions //
);
if (!result)
{
//
cState.Clean();
ZeroMemory(cHelper);
cConditions.Clean();
cXConditions.Clean();
cStateEvents.Clean();
//
return result;
}
Parse(cXConditions);
//
// Fil Selected Data ...
XPOIState chState;
X121Conditions chXConditions;
XPOIStateEvents chStateEvents;
XC121SMCCycleHelper *chHelper;
X121SMCCycleConditions chConditions;
if (holderCycle != X_CYCLE_NONE)
{
//
result = provider.SelectCycle(
holderCycle,
chState,
chStateEvents,
chXConditions,
chHelper,
chConditions //
);
if (!result)
{
//
chState.Clean();
ZeroMemory(chHelper);
chConditions.Clean();
chXConditions.Clean();
chStateEvents.Clean();
//
return result;
}
//
Parse(chXConditions);
}
//
// Checking Waiting Baoxes Exists ...
result = HasChild(waitingBoxes);
if (!result)
{
return result;
}
//
XCPOIDrawer *drawer = provider
.visionCycleHelper
.mPOIDrawer;
//
// Normalize Args ...
//
box.Clean();
holderBox.Clean();
dir = X_DIRECTION_NONE;
//
if (barIndex < 0)
{
barIndex = 0;
}
//
int idx = -1;
int count = 0;
bool has = false;
//
int zIDX = barIndex;
int cIDX = zIDX + 1;
int pIDX = cIDX + 1;
int ppIDX = pIDX + 1;
//
bool isBullish = false;
bool isBearish = false;
//
XOHCL zBar;
XOHCL cBar;
XOHCL pBar;
//
// Initial Bars ...
result = zBar.Init(
cState.symbol,
cState.period,
barIndex //
);
result =
result &&
zBar.GetPreviousBar(cBar);
result =
result &&
cBar.GetPreviousBar(pBar);
if (!result)
{
//
zBar.Clean();
cBar.Clean();
pBar.Clean();
cState.Clean();
chState.Clean();
ZeroMemory(cHelper);
cConditions.Clean();
cXConditions.Clean();
ZeroMemory(chHelper);
chConditions.Clean();
chXConditions.Clean();
//
return result;
}
//
// Detect Inside Box ...
XBoxZone insideBox;
count = ArraySize(waitingBoxes);
has = IsValidSize(count);
if (has)
{
//
for (int i = 0; i < count; i++)
{
//
XBoxZone iBox = waitingBoxes[i];
bool isBullish = iBox.IsBullish();
double iMid = iBox.lower + ((iBox.upper - iBox.lower) / 2);
//
has =
//
isBullish
? cBar.low < iMid &&
cBar.low > iBox.lower
: cBar.high > iMid &&
cBar.high < iBox.upper
//
;
if (has)
{
//
insideBox = iBox;
break;
}
}
}
has = insideBox.IsValid();
//
ENUM_X_DIRECTION iBarPosDir;
bool isBarValidForDir = cHelper
.mBarAnalyser
.IsValidForPosition(
cBar,
iBarPosDir //
);
bool isBarValidForBullish =
isBarValidForDir &&
IsBullish(iBarPosDir);
bool isBarValidForBearish =
isBarValidForDir &&
IsBearish(iBarPosDir);
//
if (has)
{
//
XCBoxObject *iObj;
has = drawer.DrawBox(
insideBox,
iObj //
);
if (has)
{
//
Print("Dec Scores:");
Print("-------------");
Print("Bull: ", provider.decisionBullishScore);
Print("Bear: ", provider.decisionBearishScore);
Print("-------------");
Print("Anal Scores:");
Print("-------------");
Print("Bull: ", provider.analyseBullishScore);
Print("Bear: ", provider.analyseBearishScore);
Print("-------------");
Print("Bar Valid For: " + ToString(iBarPosDir));
Print("-------------");
Print(ToString(insideBox.dir), " Inside ...");
Print("-------------");
}
}
//
result = has;
if (!result)
{
//
zBar.Clean();
cBar.Clean();
pBar.Clean();
cState.Clean();
chState.Clean();
insideBox.Clean();
ZeroMemory(cHelper);
cConditions.Clean();
cXConditions.Clean();
ZeroMemory(chHelper);
chConditions.Clean();
chXConditions.Clean();
//
return result;
}
//
// Detecting Signal Conditions ...
//
// Bullish Conditions ...
isBullish =
//
// Base Condition ...
(
//
insideBox.IsBullish() &&
isBarValidForBullish
//
)
//
;
//
// Bearish Conditions ...
isBearish =
//
// Base Condition ...
(
//
insideBox.IsBearish() &&
isBarValidForBearish
//
)
//
;
//
// Filling Requirements ...
result =
isBullish ||
isBearish;
if (result)
{
//
dir =
isBullish
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
//
box.dir = dir;
box.to = TimeCurrent();
box.from = insideBox.from;
box.upper = insideBox.upper;
box.lower = insideBox.lower;
box.symbol = cXConditions.symbol;
box.period = cXConditions.period;
}
//
// Check All Conditions ...
result =
box.IsValid() &&
HasDirection(dir) &&
(isBullish ||
isBearish);
//
// Cleanup Resources ...
zBar.Clean();
cBar.Clean();
pBar.Clean();
cState.Clean();
chState.Clean();
insideBox.Clean();
ZeroMemory(cHelper);
cConditions.Clean();
cStateEvents.Clean();
cXConditions.Clean();
ZeroMemory(chHelper);
chConditions.Clean();
chStateEvents.Clean();
chXConditions.Clean();
//
return result;
}
/////////////////////////////////////////////////////
/**
* Checking a Box Exists in Collections or not ...
*
* @param box: XBoxZone instance reference ...
*
* @return ( bool )
*/
bool IsExists(XBoxZone &box)
{
//
bool result = false;
//
// Check Validation ...
result = box.IsValid() &&
(HasWaitingBoxes() ||
HasBreakedBoxes() ||
HasUnavailableBoxes());
if (!result)
{
return result;
}
//
int idx = -1;
bool has = false;
//
// Check Index in Waiting Boxes ...
has = HasWaitingBoxes();
if (has)
{
//
idx = FindIndex(
box,
waitingBoxes //
);
result = IsValidIndex(idx);
if (result)
{
return result;
}
}
//
// Check Index in Breaked Boxes ...
has = HasBreakedBoxes();
if (has)
{
//
idx = FindIndex(
box,
breakedBoxes //
);
result = IsValidIndex(idx);
if (result)
{
return result;
}
}
//
// Check Index in Unavailable Boxes ...
has = HasUnavailableBoxes();
if (has)
{
//
idx = FindIndex(
box,
unavailableBoxes //
);
result = IsValidIndex(idx);
if (result)
{
return result;
}
}
//
return result;
}
/**
* Detect Signal Boxes ...
*
* @param cycle: ENUM_X_CYCLES member ...
* @param provider: X121SMCStrategySignalProviderData instance reference ...
* @param barIndex: int ...
*
* @return ( bool )
*/
bool DetectSignalBoxes(
ENUM_X_CYCLES cycle,
X121SMCStrategySignalProviderData &provider,
int barIndex = 0 //
)
{
//
bool result = false;
//
int idx = -1;
int count = 0;
bool has = false;
//
if (barIndex < 0)
{
barIndex = 0;
}
//
// Select Cycle ...
XPOIState cState;
XPOIStateEvents cStateEvents;
X121Conditions cXConditions;
XC121SMCCycleHelper *cHelper;
X121SMCCycleConditions cConditions;
result = provider.SelectCycle(
cycle,
cState,
cStateEvents,
cXConditions,
cHelper,
cConditions //
);
if (!result)
{
//
cState.Clean();
ZeroMemory(cHelper);
cConditions.Clean();
cStateEvents.Clean();
cXConditions.Clean();
//
return result;
}
//
// Select Rejection Boxes ...
// //
// // Select Validate Rejection Boxes ...
// XBoxZone rejections[];
// int count = cHelper
// .DetectRejections(
// rejections,
// barIndex //
// );
// //
// result = IsValidSize(count);
// if (result)
// {
// //
// for (int i = 0; i < count; i++)
// {
// //
// has = IsExists(rejections[i]);
// if (!has)
// {
// //
// AddRef(
// rejections[i],
// waitingBoxes //
// );
// }
// }
// }
// //
// // Select Order Blocks ...
// if (cStateEvents.hasNewOrderBlock)
// {
// //
// idx = GetYoungest(cState.orderBlocks);
// has = IsValidIndex(idx);
// if (has)
// {
// //
// XCOrderBlock *iOB = cState.orderBlocks[idx];
// //
// XBoxZone iBox;
// has = ToBox(
// iBox,
// iOB //
// );
// if (has)
// {
// //
// has = IsExists(iBox);
// if (!has)
// {
// //
// AddRef(
// iBox,
// waitingBoxes //
// );
// }
// }
// }
// }
//
// Select Fair Value Gaps ...
// if (cStateEvents.hasNewFairValueGap)
// {
// //
// idx = GetYoungest(cState.fairValueGaps);
// has = IsValidIndex(idx);
// if (has)
// {
// //
// XCFVG *iOB = cState.fairValueGaps[idx];
// //
// XBoxZone iBox;
// has = ToBox(
// iBox,
// iOB //
// );
// if (has)
// {
// //
// has = IsExists(iBox);
// if (!has)
// {
// //
// AddRef(
// iBox,
// waitingBoxes //
// );
// }
// }
// }
// }
//
// Select Supply/Demand Zones ...
// if (cStateEvents.hasNewSupplyZone)
// {
// //
// idx = GetYoungest(cState.supplyZones);
// has = IsValidIndex(idx);
// if (has)
// {
// //
// XCSupplyZone *iSupply = cState.supplyZones[idx];
// //
// XBoxZone iBox;
// has = ToBox(
// iBox,
// iSupply //
// );
// if (has)
// {
// //
// has = IsExists(iBox);
// if (!has)
// {
// //
// AddRef(
// iBox,
// waitingBoxes //
// );
// }
// }
// }
// }
// if (cStateEvents.hasNewDemandZone)
// {
// //
// idx = GetYoungest(cState.demandZones);
// has = IsValidIndex(idx);
// if (has)
// {
// //
// XCDemandZone *iDemand = cState.demandZones[idx];
// //
// XBoxZone iBox;
// has = ToBox(
// iBox,
// iDemand //
// );
// if (has)
// {
// //
// has = IsExists(iBox);
// if (!has)
// {
// //
// AddRef(
// iBox,
// waitingBoxes //
// );
// }
// }
// }
// }
//
// Select Support/Resistance Zones ...
// if (cStateEvents.hasNewSupportZone)
// {
// //
// idx = GetYoungest(cState.supportZones);
// has = IsValidIndex(idx);
// if (has)
// {
// //
// XCSupportZone *iSupport = cState.supportZones[idx];
// //
// XBoxZone iBox;
// has = ToBox(
// iBox,
// iSupport //
// );
// if (has)
// {
// //
// has = IsExists(iBox);
// if (!has)
// {
// //
// AddRef(
// iBox,
// waitingBoxes //
// );
// }
// }
// }
// }
// if (cStateEvents.hasNewResistanceZone)
// {
// //
// idx = GetYoungest(cState.resistanceZones);
// has = IsValidIndex(idx);
// if (has)
// {
// //
// XCResistanceZone *iResistance = cState.resistanceZones[idx];
// //
// XBoxZone iBox;
// has = ToBox(
// iBox,
// iResistance //
// );
// if (has)
// {
// //
// has = IsExists(iBox);
// if (!has)
// {
// //
// AddRef(
// iBox,
// waitingBoxes //
// );
// }
// }
// }
// }
//
count = CountWaitingBoxes();
result = IsValidSize(count);
//
// Cleanup Resources ...
//
cState.Clean();
ZeroMemory(cHelper);
cConditions.Clean();
cXConditions.Clean();
cStateEvents.Clean();
//
return result;
}
/**
* Validating Waiting Boxes and Detect Breaked Boxes ...
*
* @param barIndex: int ...
*
* @return ( int )
*/
int ValidateWaitingBoxes(
int barIndex = 0 //
)
{
//
int result = 0;
//
bool has = false;
//
if (barIndex < 0)
{
barIndex = 0;
}
//
if (barIndex == 0)
{
barIndex = 1;
}
//
has = HasWaitingBoxes();
if (!has)
{
return result;
}
//
int removeIDX[];
result = CountWaitingBoxes();
for (int i = 0; i < result; i++)
{
//
XOHCL iBar;
XBoxZone iBox = waitingBoxes[i];
bool isInite = iBar
.Init(
iBox.symbol,
iBox.period,
iBox.from //
);
//
has = isInite &&
IsBoxBreaked(
iBox,
iBar.Index() - 1,
barIndex,
period //
);
if (has)
{
//
Add(
i,
removeIDX //
);
//
AddRef(
iBox,
breakedBoxes //
);
}
//
iBox.Clean();
iBar.Clean();
}
//
has = HasChild(removeIDX);
if (has)
{
//
CleanupArray(
removeIDX,
waitingBoxes //
);
}
Clean(removeIDX);
//
result = CountWaitingBoxes();
//
return result;
}