1537 lines
41 KiB
Plaintext
1537 lines
41 KiB
Plaintext
|
|
////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
// Draw ...
|
|
//
|
|
|
|
//
|
|
XCBaseObject *drawnObjects[];
|
|
|
|
//
|
|
if (hasBullishOBs)
|
|
{
|
|
//
|
|
for (int i = 0; i < bullishOBsCount; i++)
|
|
{
|
|
//
|
|
XCOrderBlock *iOb = conditions.bullishOBs[i];
|
|
|
|
//
|
|
XCBullishOrderBlockObject *iObObj;
|
|
bool isCreated = visionCycleHelper
|
|
.mPOIDrawer
|
|
.CreateBullishOrderBlock(
|
|
iOb,
|
|
iObObj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
Add(
|
|
(XCBaseObject *)iObObj,
|
|
drawnObjects //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
if (hasBearishOBs)
|
|
{
|
|
//
|
|
for (int i = 0; i < bearishOBsCount; i++)
|
|
{
|
|
//
|
|
XCOrderBlock *iOb = conditions.bearishOBs[i];
|
|
|
|
//
|
|
XCBearishOrderBlockObject *iObObj;
|
|
bool isCreated = visionCycleHelper
|
|
.mPOIDrawer
|
|
.CreateBearishOrderBlock(
|
|
iOb,
|
|
iObObj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
Add(
|
|
(XCBaseObject *)iObObj,
|
|
drawnObjects //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
if (hasBullishFVGs)
|
|
{
|
|
//
|
|
for (int i = 0; i < bullishFVGsCount; i++)
|
|
{
|
|
//
|
|
XCFVG *iFVG = conditions.bullishFVGs[i];
|
|
|
|
//
|
|
XCBullishFairValueGapObject *iFVGObj;
|
|
bool isCreated = visionCycleHelper
|
|
.mPOIDrawer
|
|
.CreateBullishFairValueGap(
|
|
iFVG,
|
|
iFVGObj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
Add(
|
|
(XCBaseObject *)iFVGObj,
|
|
drawnObjects //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
if (hasBearishFVGs)
|
|
{
|
|
//
|
|
for (int i = 0; i < bearishFVGsCount; i++)
|
|
{
|
|
//
|
|
XCFVG *iFVG = conditions.bearishFVGs[i];
|
|
|
|
//
|
|
XCBearishFairValueGapObject *iFVGObj;
|
|
bool isCreated = visionCycleHelper
|
|
.mPOIDrawer
|
|
.CreateBearishFairValueGap(
|
|
iFVG,
|
|
iFVGObj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
Add(
|
|
(XCBaseObject *)iFVGObj,
|
|
drawnObjects //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
if (hasSupportZones)
|
|
{
|
|
//
|
|
for (int i = 0; i < supportZonesCount; i++)
|
|
{
|
|
//
|
|
XCSupportZoneObject *iObj;
|
|
bool isCreated = visionCycleHelper
|
|
.mPOIDrawer
|
|
.CreateSupportZone(
|
|
conditions.supportZones[i],
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
//
|
|
Add(
|
|
(XCBaseObject *)iObj,
|
|
drawnObjects //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
if (hasResistanceZones)
|
|
{
|
|
//
|
|
for (int i = 0; i < resistanceZonesCount; i++)
|
|
{
|
|
//
|
|
XCResistanceZoneObject *iObj;
|
|
bool isCreated = visionCycleHelper
|
|
.mPOIDrawer
|
|
.CreateResistanceZone(
|
|
conditions.resistanceZones[i],
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
//
|
|
Add(
|
|
(XCBaseObject *)iObj,
|
|
drawnObjects //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
if (hasDemandZones)
|
|
{
|
|
//
|
|
for (int i = 0; i < demandZonesCount; i++)
|
|
{
|
|
//
|
|
XCDemandZoneObject *iObj;
|
|
bool isCreated = visionCycleHelper
|
|
.mPOIDrawer
|
|
.CreateDemandZone(
|
|
conditions.demandZones[i],
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
//
|
|
Add(
|
|
(XCBaseObject *)iObj,
|
|
drawnObjects //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
if (hasSupplyZones)
|
|
{
|
|
//
|
|
for (int i = 0; i < supplyZonesCount; i++)
|
|
{
|
|
//
|
|
XCSupplyZoneObject *iObj;
|
|
bool isCreated = visionCycleHelper
|
|
.mPOIDrawer
|
|
.CreateSupplyZone(
|
|
conditions.supplyZones[i],
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
//
|
|
Add(
|
|
(XCBaseObject *)iObj,
|
|
drawnObjects //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
// if (hasPriceBox && hasYoungestOB)
|
|
// {
|
|
// //
|
|
// X121SMCCycleState iState;
|
|
// bool iHasState = visionCycleHelper.GetCycleState(iState);
|
|
// if (iHasState)
|
|
// {
|
|
// //
|
|
// // Retrieve Youngest Order Blocks ...
|
|
// XCOrderBlock *iYOB;
|
|
// bool iHasYoungestOB = iState.GetYoungestOB(iYOB);
|
|
// if (iHasYoungestOB)
|
|
// {
|
|
// //
|
|
// bool isCreate = false;
|
|
// bool isYoungestBullish = iYOB.IsBullish();
|
|
// if (isYoungestBullish)
|
|
// {
|
|
// //
|
|
// // XCBullishOrderBlockObject *iObj;
|
|
// // isCreate = visionCycleHelper.mPOIDrawer.CreateBullishOrderBlock(
|
|
// // iYOB,
|
|
// // iObj //
|
|
// // );
|
|
|
|
// // //
|
|
// // if (isCreate) {
|
|
// // //
|
|
// // iObj.ZoneColor(clrAqua);
|
|
// // iObj.ZoneWidth(4);
|
|
// // }
|
|
// }
|
|
// else
|
|
// {
|
|
// //
|
|
// // XCBearishOrderBlockObject *iObj;
|
|
// // isCreate = visionCycleHelper.mPOIDrawer.CreateBearishOrderBlock(
|
|
// // iYOB,
|
|
// // iObj //
|
|
// // );
|
|
|
|
// // //
|
|
// // if (isCreate) {
|
|
// // //
|
|
// // iObj.ZoneColor(clrMagenta);
|
|
// // iObj.ZoneWidth(4);
|
|
// // }
|
|
// }
|
|
|
|
// //
|
|
// // Compare it with current Condition PriceOB ...
|
|
// bool isSame =
|
|
// //
|
|
// conditions.priceOB.Upper() == iYOB.Upper() &&
|
|
// conditions.priceOB.Lower() == iYOB.Lower() &&
|
|
// conditions.priceOB.From() == iYOB.From() &&
|
|
// conditions.priceOB.Type() == iYOB.Type()
|
|
// //
|
|
// ;
|
|
// if (!isSame)
|
|
// {
|
|
// conditions.Clean();
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
//
|
|
// bool canReset =
|
|
// //
|
|
// hasPriceBox &&
|
|
// conditions.isPriceOBActed &&
|
|
// conditions.isPriceOBBreaked &&
|
|
// //
|
|
// (
|
|
// //
|
|
// IsBullish(conditions.priceBox.dir)
|
|
// ? pBar.high < lower &&
|
|
// cBar.high < lower
|
|
// : pBar.low > upper &&
|
|
// cBar.low > upper
|
|
// //
|
|
// )
|
|
// //
|
|
// ;
|
|
// if (canReset)
|
|
// {
|
|
// //
|
|
// Print("canReset");
|
|
// }
|
|
|
|
//
|
|
// Check Conditions Clean Senario ...
|
|
// bool canResetConditions =
|
|
// //
|
|
// hasPriceBox &&
|
|
// !isPriceOBValid &&
|
|
// conditions.priceOB != NULL &&
|
|
// conditions.priceOB.IsValid()
|
|
// //
|
|
// ;
|
|
// bool canReset2 =
|
|
// //
|
|
// conditions.priceOB != NULL &&
|
|
// (
|
|
// //
|
|
// (
|
|
// //
|
|
// conditions.priceOB.IsBullish()
|
|
// ? hh < conditions.priceOB.Lower()
|
|
// : ll > conditions.priceOB.Upper()
|
|
// //
|
|
// )
|
|
// //
|
|
// ||
|
|
// //
|
|
// (
|
|
// //
|
|
// conditions.priceOB.IsBullish()
|
|
// ? ll50 > conditions.priceOB.Upper()
|
|
// : hh50 < conditions.priceOB.Lower()
|
|
// //
|
|
// )
|
|
// //
|
|
// )
|
|
// //
|
|
// ;
|
|
|
|
// if (canResetConditions)
|
|
// {
|
|
// Print("canResetConditions");
|
|
// }
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
X121SMCCycleState iState;
|
|
bool iHasState = visionCycleHelper.GetCycleState(iState);
|
|
if (iHasState)
|
|
{
|
|
//
|
|
// Check Price Inside Box ...
|
|
XBoxZone iPriceBox;
|
|
XCOrderBlock *iPriceOB = NULL;
|
|
bool iHasPriceBox = DetectPriceInsideBox(
|
|
iPriceBox,
|
|
iPriceOB,
|
|
decisionXConditions,
|
|
iState //
|
|
);
|
|
|
|
//
|
|
if (iHasPriceBox) {
|
|
//
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// //
|
|
// // Draw ...
|
|
// XCBaseObject *drawnObjects[];
|
|
// int drawnObjectsCount = visionCycleHelper.DrawCycleState(
|
|
// conditions.state,
|
|
// drawnObjects //
|
|
// );
|
|
|
|
// //
|
|
// if (hasPriceBox)
|
|
// {
|
|
// //
|
|
// bool isBullish = IsBullish(conditions.priceBox.dir);
|
|
// color boxColor = isBullish ? clrYellow : clrOrange;
|
|
|
|
// //
|
|
// XCBoxObject *iObj;
|
|
// bool isCreated = visionCycleHelper.mPOIDrawer.CreateBox(
|
|
// conditions.priceBox,
|
|
// iObj,
|
|
// boxColor,
|
|
// 1,
|
|
// false,
|
|
// STYLE_DASHDOTDOT //
|
|
// );
|
|
|
|
// //
|
|
// if (isCreated)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// (XCBaseObject *)iObj,
|
|
// drawnObjects //
|
|
// );
|
|
// }
|
|
|
|
// //
|
|
// XCBaseObject *priceOBObj = NULL;
|
|
// if (isBullish)
|
|
// {
|
|
// //
|
|
// XCBullishOrderBlockObject *iObj;
|
|
// isCreated = visionCycleHelper
|
|
// .mPOIDrawer
|
|
// .CreateBullishOrderBlock(
|
|
// conditions.priceOB,
|
|
// iObj //
|
|
// );
|
|
|
|
// //
|
|
// if (isCreated)
|
|
// {
|
|
// //
|
|
// iObj.ZoneWidth(2);
|
|
// iObj.ZoneColor(boxColor);
|
|
// iObj.ZoneStyle(STYLE_SOLID);
|
|
|
|
// //
|
|
// priceOBObj = (XCBaseObject *)iObj;
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// //
|
|
// XCBearishOrderBlockObject *iObj;
|
|
// isCreated = visionCycleHelper
|
|
// .mPOIDrawer
|
|
// .CreateBearishOrderBlock(
|
|
// conditions.priceOB,
|
|
// iObj //
|
|
// );
|
|
|
|
// //
|
|
// if (isCreated)
|
|
// {
|
|
// //
|
|
// iObj.ZoneWidth(2);
|
|
// iObj.ZoneColor(boxColor);
|
|
// iObj.ZoneStyle(STYLE_SOLID);
|
|
|
|
// //
|
|
// priceOBObj = (XCBaseObject *)iObj;
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// if (isCreated)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// priceOBObj,
|
|
// drawnObjects //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
/**
|
|
* Detect Order Blocks Breaker Bar ...
|
|
*
|
|
* @param breakerBar: XOHCL instance Reference ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool DetectBreakerBar(XOHCL &breakerBar)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
breakerBar.Clean();
|
|
|
|
//
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL fromBar;
|
|
result = FillBar(fromBar);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int fromIndex = fromBar.Index();
|
|
result = fromIndex > 0;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool isBullish = IsBullish();
|
|
ENUM_X_DIRECTION dir =
|
|
isBullish
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
double value =
|
|
isBullish
|
|
? Upper()
|
|
: Lower();
|
|
|
|
//
|
|
for (int i = fromIndex - 1; i >= 0; i--)
|
|
{
|
|
//
|
|
XOHCL iBar;
|
|
bool isInited = iBar.Init(
|
|
fromBar.symbol,
|
|
fromBar.period,
|
|
i //
|
|
);
|
|
if (!isInited)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
isInited = IsBarBreak(
|
|
value,
|
|
dir,
|
|
iBar //
|
|
);
|
|
if (isInited)
|
|
{
|
|
//
|
|
breakerBar = iBar;
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
result = breakerBar.IsValid();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Check Order Block is Hunted or not ...
|
|
*
|
|
* @param huntedBar: XOHCL instance Reference ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool IsHunted(XOHCL &huntedBar)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
huntedBar.Clean();
|
|
|
|
//
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL breakerBar;
|
|
result = DetectBreakerBar(breakerBar);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool isBullish = IsBullish();
|
|
|
|
//
|
|
int breakerIndex = breakerBar.Index();
|
|
for (int i = breakerIndex - 1; i >= 0; i--)
|
|
{
|
|
//
|
|
XOHCL iBar;
|
|
result = iBar.Init(
|
|
breakerBar.symbol,
|
|
breakerBar.period,
|
|
i //
|
|
);
|
|
|
|
//
|
|
double price =
|
|
isBullish
|
|
? iBar.low
|
|
: iBar.high;
|
|
|
|
//
|
|
result = IsPriceInsideZone(
|
|
price,
|
|
Upper(),
|
|
Lower() //
|
|
);
|
|
if (result)
|
|
{
|
|
//
|
|
huntedBar = iBar;
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
result = huntedBar.IsValid();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Check Order Block Validation ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool IsValidOrderBlock()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL breakerBar;
|
|
result = DetectBreakerBar(breakerBar);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
int breakerBarIndex = breakerBar.Index();
|
|
|
|
//
|
|
XOHCL huntedBar;
|
|
bool isHunted = IsHunted(huntedBar);
|
|
result = !isHunted;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool isBullish = IsBullish();
|
|
|
|
//
|
|
for (int i = breakerBarIndex - 1; i >= 0; i--)
|
|
{
|
|
//
|
|
XOHCL iBar;
|
|
result = iBar.Init(
|
|
breakerBar.symbol,
|
|
breakerBar.period,
|
|
i //
|
|
);
|
|
if (!result)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
double price =
|
|
isBullish
|
|
? iBar.low
|
|
: iBar.high;
|
|
|
|
//
|
|
result =
|
|
isBullish
|
|
? price > Upper()
|
|
: price < Lower();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// XCOrderBlock *tmp[];
|
|
// Copy(
|
|
// mBullishOrderBlocks,
|
|
// tmp //
|
|
// );
|
|
|
|
// //
|
|
// for (int i = 0; i <= bullOBsCount; i++)
|
|
// {
|
|
// //
|
|
// XCOrderBlock *iOB = tmp[i];
|
|
|
|
// //
|
|
// // Validate ...
|
|
// bool isValid = iOB.IsValid();
|
|
// if (!isValid)
|
|
// {
|
|
// //
|
|
// ArrayRemove(
|
|
// mBullishOrderBlocks,
|
|
// i,
|
|
// 1 //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/**
|
|
* Test Market for Detect Order Block FVG ...
|
|
*
|
|
* @param forDir: Direction
|
|
* @param bullishOrderBlocks: Detected Bullish Order Blocks ...
|
|
* @param bearishOrderBlocks: Detected Bearish Order Blocks ...
|
|
* @param orderBlockState: Order Block Detection POIState ...
|
|
* @param fairValueGapState: Fair Value Gap Detection POIState ...
|
|
* @param barIndex: Bar Index ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool DetectFVGOB(
|
|
ENUM_X_DIRECTION &forDir, // Test For Specified Direction ...
|
|
XFVGOrderBlock &bullishOrderBlocks[], // Bullish Order Blocks ...
|
|
XFVGOrderBlock &bearishOrderBlocks[], // Bearish Order Blocks ...
|
|
XPOIState &orderBlockState, // Order Block Detection TF POI(s) ...
|
|
XPOIState &fairValueGapState, // Fair Value Gap Detection TF POI(s) ...
|
|
int barIndex = 0 // Bar Index ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
forDir = X_DIRECTION_NONE;
|
|
|
|
//
|
|
// Validate Args ...
|
|
result =
|
|
orderBlockState.HasChild() &&
|
|
fairValueGapState.HasChild();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
string symbol = orderBlockState.symbol;
|
|
ENUM_TIMEFRAMES period = orderBlockState.period;
|
|
|
|
//
|
|
// Retrieve Bars ...
|
|
XOHCL triggerCBar;
|
|
result = triggerCBar.Init(
|
|
symbol,
|
|
period,
|
|
barIndex //
|
|
);
|
|
|
|
//
|
|
// Select Order Blocks Which Has Big Changes ...
|
|
int count = 0;
|
|
datetime cTime = TimeCurrent();
|
|
|
|
//
|
|
XOHCL jBar;
|
|
result = jBar.Init(
|
|
fairValueGapState.symbol,
|
|
fairValueGapState.period,
|
|
barIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
double jBarLL = jBar.FindLowest(3, MODE_LOW);
|
|
double jBarHH = jBar.FindHighest(3, MODE_HIGH);
|
|
|
|
//
|
|
// Bullish ...
|
|
int bullishOrderBlocksCount = orderBlockState.CountBullishOrderBlocks();
|
|
count = bullishOrderBlocksCount;
|
|
if (IsValidSize(count))
|
|
{
|
|
//
|
|
for (int i = count - 1; i >= 0; i--)
|
|
{
|
|
//
|
|
XCFVG *iFVG = NULL;
|
|
XStateZones iStateZones;
|
|
XCOrderBlock *iOb = orderBlockState.bullishOrderBlocks[i];
|
|
iOb.To(cTime);
|
|
|
|
//
|
|
// Find Exit Bar of Bullish OrderBlock Upper ...
|
|
XOHCL breakerBar;
|
|
bool hasBreakerBar = iOb.DetectBreakerBar(breakerBar);
|
|
if (!hasBreakerBar)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Detect Order Block is Hunted Or Not ...
|
|
XOHCL huntedBar;
|
|
bool isHunted = iOb.IsHunted(huntedBar);
|
|
if (isHunted)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Check Validation of Order Block ...
|
|
bool isValid = iOb.IsValidOrderBlock();
|
|
if (!isValid)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Check Order Block Has Fair Value Gap ...
|
|
int fvgsCount = fairValueGapState.CountBullishFairValueGaps();
|
|
bool hasFVG = IsValidSize(fvgsCount);
|
|
if (!hasFVG)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Detect an FVG for Order Block ...
|
|
for (int j = fvgsCount - 1; j >= 0; j--)
|
|
{
|
|
//
|
|
XCFVG *jFVG = fairValueGapState.bullishFairValueGaps[j];
|
|
|
|
//
|
|
bool isValid =
|
|
//
|
|
jFVG.IsBullish() &&
|
|
jBarLL > jFVG.Upper() &&
|
|
jBar.low > jFVG.Upper() &&
|
|
jFVG.From() >= iOb.From() &&
|
|
((jFVG.Upper() > iOb.Upper() &&
|
|
jFVG.Lower() <= iOb.Upper()) ||
|
|
(jFVG.Upper() <= iOb.Upper() &&
|
|
jFVG.Lower() >= iOb.Lower()))
|
|
//
|
|
;
|
|
if (isValid)
|
|
{
|
|
//
|
|
jFVG.To(cTime);
|
|
iFVG = jFVG;
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
hasFVG = iFVG != NULL;
|
|
result = hasFVG;
|
|
if (!result)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
// //
|
|
// double upper = MathMax(iOb.Upper(), iFVG.Upper());
|
|
// double lower = MathMin(iOb.Lower(), iFVG.Lower());
|
|
// datetime from = iFVG.From();
|
|
|
|
// //
|
|
// // Detect Price Zones ...
|
|
// // Based On Decision State ...
|
|
// bool hasStateZones = CalculateStateZones(
|
|
// iStateZones,
|
|
// decisionState,
|
|
// upper,
|
|
// lower,
|
|
// from //
|
|
// );
|
|
// result = hasStateZones;
|
|
// if (!result)
|
|
// {
|
|
// continue;
|
|
// }
|
|
|
|
//
|
|
XFVGOrderBlock iModel;
|
|
iModel.orderBlock = iOb;
|
|
iModel.fairValueGap = iFVG;
|
|
// iModel.stateZones = iStateZones;
|
|
|
|
//
|
|
AddRef(
|
|
iModel,
|
|
bullishOrderBlocks //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Bearish ...
|
|
int bearishOrderBlocksCount = orderBlockState.CountBearishOrderBlocks();
|
|
count = bearishOrderBlocksCount;
|
|
if (IsValidSize(count))
|
|
{
|
|
//
|
|
for (int i = count - 1; i >= 0; i--)
|
|
{
|
|
//
|
|
XCFVG *iFVG = NULL;
|
|
XStateZones iStateZones;
|
|
XCOrderBlock *iOb = orderBlockState.bearishOrderBlocks[i];
|
|
iOb.To(cTime);
|
|
|
|
//
|
|
// Find Exit Bar of Bullish OrderBlock Upper ...
|
|
XOHCL breakerBar;
|
|
bool hasBreakerBar = iOb.DetectBreakerBar(breakerBar);
|
|
if (!hasBreakerBar)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Detect Order Block is Hunted Or Not ...
|
|
XOHCL huntedBar;
|
|
bool isHunted = iOb.IsHunted(huntedBar);
|
|
if (isHunted)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Check Validation of Order Block ...
|
|
bool isValid = iOb.IsValidOrderBlock();
|
|
if (!isValid)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Check Order Block Has Fair Value Gap ...
|
|
int fvgsCount = fairValueGapState.CountBearishFairValueGaps();
|
|
bool hasFVG = IsValidSize(fvgsCount);
|
|
if (!hasFVG)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Detect an FVG for Order Block ...
|
|
for (int j = fvgsCount - 1; j >= 0; j--)
|
|
{
|
|
//
|
|
XCFVG *jFVG = fairValueGapState.bearishFairValueGaps[j];
|
|
|
|
//
|
|
bool isValid =
|
|
//
|
|
jFVG.IsBearish() &&
|
|
jBarHH < jFVG.Lower() &&
|
|
jBar.high < jFVG.Lower() &&
|
|
jFVG.From() >= iOb.From() &&
|
|
((jFVG.Upper() > iOb.Lower() &&
|
|
jFVG.Lower() <= iOb.Lower()) ||
|
|
(jFVG.Upper() <= iOb.Upper() &&
|
|
jFVG.Lower() >= iOb.Lower()))
|
|
//
|
|
;
|
|
if (isValid)
|
|
{
|
|
//
|
|
jFVG.To(cTime);
|
|
iFVG = jFVG;
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
hasFVG = iFVG != NULL;
|
|
result = hasFVG;
|
|
if (!result)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
double upper = MathMax(iOb.Upper(), iFVG.Upper());
|
|
double lower = MathMin(iOb.Lower(), iFVG.Lower());
|
|
datetime from = iFVG.From();
|
|
|
|
// //
|
|
// // Detect Price Zones ...
|
|
// // Based On Decision State ...
|
|
// bool hasStateZones = CalculateStateZones(
|
|
// iStateZones,
|
|
// decisionState,
|
|
// upper,
|
|
// lower,
|
|
// from //
|
|
// );
|
|
// result = hasStateZones;
|
|
// if (!result)
|
|
// {
|
|
// continue;
|
|
// }
|
|
|
|
//
|
|
XFVGOrderBlock iModel;
|
|
iModel.orderBlock = iOb;
|
|
iModel.fairValueGap = iFVG;
|
|
// iModel.stateZones = iStateZones;
|
|
|
|
//
|
|
AddRef(
|
|
iModel,
|
|
bearishOrderBlocks //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Check Order Blocks ...
|
|
bullishOrderBlocksCount = ArraySize(bullishOrderBlocks);
|
|
bool hasBullishOrderBlocks = IsValidSize(bullishOrderBlocksCount);
|
|
|
|
//
|
|
// Check Order Blocks ...
|
|
bearishOrderBlocksCount = ArraySize(bearishOrderBlocks);
|
|
bool hasBearishOrderBlocks = IsValidSize(bearishOrderBlocksCount);
|
|
|
|
//
|
|
result =
|
|
//
|
|
hasBullishOrderBlocks ||
|
|
hasBearishOrderBlocks
|
|
//
|
|
;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool isBullish = hasBullishOrderBlocks && !hasBearishOrderBlocks;
|
|
bool isBearish = hasBearishOrderBlocks && !hasBullishOrderBlocks;
|
|
|
|
//
|
|
forDir =
|
|
isBullish
|
|
? X_DIRECTION_BULLISH
|
|
: isBearish
|
|
? X_DIRECTION_BEARISH
|
|
: X_DIRECTION_NONE;
|
|
|
|
//
|
|
result = forDir != X_DIRECTION_NONE;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/**
|
|
* Handle POI Recieved ...
|
|
*
|
|
* @param event: ENUM_XPOI_EVENTS member ...
|
|
*/
|
|
// void OnPOIEvent(
|
|
// ENUM_XPOI_EVENTS event,
|
|
// XCBasePOI *param //
|
|
// )
|
|
// {
|
|
// //
|
|
// Print("POI Recieved: " + ToString(event));
|
|
|
|
// //
|
|
// if (param == NULL)
|
|
// {
|
|
// return;
|
|
// }
|
|
|
|
// switch (event)
|
|
// {
|
|
// //
|
|
// // Bullish Order Block ...
|
|
// case X_BULLISH_ORDERBLOCK_DETECTED: {
|
|
// //
|
|
// XCOrderBlock *ob = (XCOrderBlock *)param;
|
|
// Add(
|
|
// ob,
|
|
// mBullishOrderBlocks //
|
|
// );
|
|
// break;
|
|
// }
|
|
|
|
// //
|
|
// // Bearish Order Block ...
|
|
// case X_BEARISH_ORDERBLOCK_DETECTED: {
|
|
// //
|
|
// XCOrderBlock *ob = (XCOrderBlock *)param;
|
|
// Add(
|
|
// ob,
|
|
// mBearishOrderBlocks //
|
|
// );
|
|
// break;
|
|
// }
|
|
|
|
// //
|
|
// // Bullish Fair Value Gap ...
|
|
// case X_BULLISH_FVG_DETECTED: {
|
|
// //
|
|
// XCFVG *fvg = (XCFVG *)param;
|
|
// Add(
|
|
// fvg,
|
|
// mBullishFairValueGaps //
|
|
// );
|
|
// break;
|
|
// }
|
|
|
|
// //
|
|
// // Bearish Fair Value Gap ...
|
|
// case X_BEARISH_FVG_DETECTED: {
|
|
// //
|
|
// XCFVG *fvg = (XCFVG *)param;
|
|
// Add(
|
|
// fvg,
|
|
// mBearishFairValueGaps //
|
|
// );
|
|
// break;
|
|
// }
|
|
|
|
// //
|
|
// // Support Zone ...
|
|
// case X_SUPPORT_ZONE_DETECTED: {
|
|
// //
|
|
// XCSupportZone *zone = (XCSupportZone *)param;
|
|
// Add(
|
|
// zone,
|
|
// mSupportZones //
|
|
// );
|
|
// break;
|
|
// }
|
|
|
|
// //
|
|
// // Resistance Zone ...
|
|
// case X_RESISTANCE_ZONE_DETECTED: {
|
|
// //
|
|
// XCResistanceZone *zone = (XCResistanceZone *)param;
|
|
// Add(
|
|
// zone,
|
|
// mResistanceZones //
|
|
// );
|
|
// break;
|
|
// }
|
|
|
|
// //
|
|
// // Supply Zone ...
|
|
// case X_SUPPLY_ZONE_DETECTED: {
|
|
// //
|
|
// XCSupplyZone *zone = (XCSupplyZone *)param;
|
|
// Add(
|
|
// zone,
|
|
// mSupplyZones //
|
|
// );
|
|
// break;
|
|
// }
|
|
|
|
// //
|
|
// // Demand Zone ...
|
|
// case X_DEMAND_ZONE_DETECTED: {
|
|
// //
|
|
// XCDemandZone *zone = (XCDemandZone *)param;
|
|
// Add(
|
|
// zone,
|
|
// mDemandZones //
|
|
// );
|
|
// break;
|
|
// }
|
|
|
|
// //
|
|
// }
|
|
// }
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
// else
|
|
// {
|
|
// //
|
|
// mPOIDetector.GetState(state);
|
|
// bool isStateValid = state.IsValid() &&
|
|
// state.HasChild();
|
|
// if (isStateValid)
|
|
// {
|
|
// //
|
|
// // Order Blocks ...
|
|
|
|
// //
|
|
// // Bullish ...
|
|
// int bullishOBsCount = state.CountBullishOrderBlocks();
|
|
// bool hasBullishOBs = IsValidSize(bullishOBsCount);
|
|
// if (hasBullishOBs &&
|
|
// !IsValidSize(ArraySize(mBullishOrderBlocks)))
|
|
// {
|
|
// //
|
|
// for (int i = 0; i < bullishOBsCount; i++)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// state.bullishOrderBlocks[i],
|
|
// mBullishOrderBlocks //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Bearish ...
|
|
// int bearishOBsCount = state.CountBearishOrderBlocks();
|
|
// bool hasBearishOBs = IsValidSize(bearishOBsCount);
|
|
// if (hasBearishOBs &&
|
|
// !IsValidSize(ArraySize(mBearishOrderBlocks)))
|
|
// {
|
|
// //
|
|
// for (int i = 0; i < bearishOBsCount; i++)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// state.bearishOrderBlocks[i],
|
|
// mBearishOrderBlocks //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Fair Value Gaps ...
|
|
|
|
// //
|
|
// // Bullish ...
|
|
// int bullishFVGsCount = state.CountBullishFairValueGaps();
|
|
// bool hasBullishFVGs = IsValidSize(bullishFVGsCount);
|
|
// if (hasBullishFVGs &&
|
|
// !IsValidSize(ArraySize(mBullishFairValueGaps)))
|
|
// {
|
|
// //
|
|
// for (int i = 0; i < bullishFVGsCount; i++)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// state.bullishFairValueGaps[i],
|
|
// mBullishFairValueGaps //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Bearish ...
|
|
// int bearishFVGsCount = state.CountBearishFairValueGaps();
|
|
// bool hasBearishFVGs = IsValidSize(bearishFVGsCount);
|
|
// if (hasBearishFVGs &&
|
|
// !IsValidSize(ArraySize(mBearishFairValueGaps)))
|
|
// {
|
|
// //
|
|
// for (int i = 0; i < bearishFVGsCount; i++)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// state.bearishFairValueGaps[i],
|
|
// mBearishFairValueGaps //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Support and Resistance ...
|
|
|
|
// //
|
|
// // Support ...
|
|
// int supportZonesCount = state.CountSupportZones();
|
|
// bool hasSupportZones = IsValidSize(supportZonesCount);
|
|
// if (hasSupportZones &&
|
|
// !IsValidSize(ArraySize(mSupportZones)))
|
|
// {
|
|
// //
|
|
// for (int i = 0; i < supportZonesCount; i++)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// state.supportZones[i],
|
|
// mSupportZones //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Resistance ...
|
|
// int resistanceZonesCount = state.CountResistanceZones();
|
|
// bool hasResistanceZones = IsValidSize(resistanceZonesCount);
|
|
// if (hasResistanceZones &&
|
|
// !IsValidSize(ArraySize(mResistanceZones)))
|
|
// {
|
|
// //
|
|
// for (int i = 0; i < resistanceZonesCount; i++)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// state.resistanceZones[i],
|
|
// mResistanceZones //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Supply and Demand ...
|
|
|
|
// //
|
|
// // Supply ...
|
|
// int supplyZonesCount = state.CountSupplyZones();
|
|
// bool hasSupplyZones = IsValidSize(supplyZonesCount);
|
|
// if (hasSupplyZones &&
|
|
// !IsValidSize(ArraySize(mSupplyZones)))
|
|
// {
|
|
// //
|
|
// for (int i = 0; i < supplyZonesCount; i++)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// state.supplyZones[i],
|
|
// mSupplyZones //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Demand ...
|
|
// int demandZonesCount = state.CountDemandZones();
|
|
// bool hasDemandZones = IsValidSize(demandZonesCount);
|
|
// if (hasDemandZones &&
|
|
// !IsValidSize(ArraySize(mDemandZones)))
|
|
// {
|
|
// //
|
|
// for (int i = 0; i < demandZonesCount; i++)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// state.demandZones[i],
|
|
// mDemandZones //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// //
|
|
// //
|
|
|
|
// //
|
|
// // Swings ...
|
|
|
|
// //
|
|
// // Low ...
|
|
// int swingLowsCount = state.CountSwingLows();
|
|
// bool hasSwingLows = IsValidSize(swingLowsCount);
|
|
// if (hasSwingLows &&
|
|
// !IsValidSize(ArraySize(mSwingLows)))
|
|
// {
|
|
// //
|
|
// for (int i = 0; i < swingLowsCount; i++)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// state.swingLows[i],
|
|
// mSwingLows //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Highs...
|
|
// int swingHighsCount = state.CountSwingHighs();
|
|
// bool hasSwingHighs = IsValidSize(swingHighsCount);
|
|
// if (hasSwingHighs &&
|
|
// !IsValidSize(ArraySize(mSwingHighs)))
|
|
// {
|
|
// //
|
|
// for (int i = 0; i < swingHighsCount; i++)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// state.swingHighs[i],
|
|
// mSwingHighs //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Momentum Bars ...
|
|
|
|
// //
|
|
// // Bullish ...
|
|
// int bullishMomentumBarsCount = state.CountBullishMomentumBars();
|
|
// bool hasBullishMomentumBars = IsValidSize(bullishMomentumBarsCount);
|
|
// if (hasBullishMomentumBars &&
|
|
// !IsValidSize(ArraySize(mBullishMomentumBars)))
|
|
// {
|
|
// //
|
|
// for (int i = 0; i < bullishMomentumBarsCount; i++)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// state.bullishMomentumBars[i],
|
|
// mBullishMomentumBars //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Bearish ...
|
|
// int bearishMomentumBarsCount = state.CountBearishMomentumBars();
|
|
// bool hasBearishMomentumBars = IsValidSize(bearishMomentumBarsCount);
|
|
// if (hasBearishMomentumBars &&
|
|
// !IsValidSize(ArraySize(mBearishMomentumBars)))
|
|
// {
|
|
// //
|
|
// for (int i = 0; i < bearishMomentumBarsCount; i++)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// state.bearishMomentumBars[i],
|
|
// mBearishMomentumBars //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Rejection Bars ...
|
|
|
|
// //
|
|
// // Bullish ...
|
|
// int bullishRejectionBarsCount = state.CountBullishRejectionBars();
|
|
// bool hasBullishRejectionBars = IsValidSize(bullishRejectionBarsCount);
|
|
// if (hasBullishRejectionBars &&
|
|
// !IsValidSize(ArraySize(mBullishRejectionBars)))
|
|
// {
|
|
// //
|
|
// for (int i = 0; i < bullishRejectionBarsCount; i++)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// state.bullishRejectionBars[i],
|
|
// mBullishRejectionBars //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Bearish ...
|
|
// int bearishRejectionBarsCount = state.CountBearishRejectionBars();
|
|
// bool hasBearishRejectionBars = IsValidSize(bearishRejectionBarsCount);
|
|
// if (hasBearishRejectionBars &&
|
|
// !IsValidSize(ArraySize(mBearishRejectionBars)))
|
|
// {
|
|
// //
|
|
// for (int i = 0; i < bearishRejectionBarsCount; i++)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// state.bearishRejectionBars[i],
|
|
// mBearishRejectionBars //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// }
|
|
// }
|
|
|