2733 lines
60 KiB
Plaintext
2733 lines
60 KiB
Plaintext
|
|
/**
|
|
* Sort Order Blocks / Fair Value Gaps based on Place and Remove unused ...
|
|
*/
|
|
template <typename T>
|
|
void OrderedSortZones(
|
|
T *youngest,
|
|
T *&items[] //
|
|
)
|
|
{
|
|
//
|
|
int count = ArraySize(items);
|
|
if (youngest == NULL ||
|
|
!youngest.IsValid() ||
|
|
!IsValidSize(count))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
ENUM_X_DIRECTION dir = youngest.GetDirection();
|
|
bool isBullish = IsBullish(dir);
|
|
|
|
//
|
|
T *tmp[];
|
|
T *lastOB = youngest;
|
|
while (IsValidSize(count))
|
|
{
|
|
//
|
|
// Detect Youngest of Collection ...
|
|
int idx = GetYoungest(items);
|
|
T *iChild = items[idx];
|
|
ArrayRemove(
|
|
items,
|
|
idx,
|
|
1 //
|
|
);
|
|
count = ArraySize(items);
|
|
|
|
//
|
|
// Check Direction Must be Same ...
|
|
ENUM_X_DIRECTION iDir = iChild.GetDirection();
|
|
bool isSameDir = dir == iDir;
|
|
if (!isSameDir)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Check Creation time Sequence ...
|
|
bool isFromPassed = lastOB.From() > iChild.From();
|
|
if (!isFromPassed)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Check Order Block Place ...
|
|
bool isPlacePassed =
|
|
isBullish
|
|
? IsBelow(
|
|
iChild,
|
|
lastOB,
|
|
true // Ignore Inside ...
|
|
)
|
|
: IsAbove(
|
|
iOB,
|
|
lastOB,
|
|
true // Ignore Inside ...
|
|
);
|
|
if (!isPlacePassed)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Update Last OB ...
|
|
lastOB = iChild;
|
|
Add(
|
|
iChild,
|
|
tmp //
|
|
);
|
|
|
|
//
|
|
}
|
|
|
|
//
|
|
// Update Ordered Sorted Order Blocks ...
|
|
count = ArraySize(tmp);
|
|
if (IsValidSize(count))
|
|
{
|
|
//
|
|
Copy(
|
|
tmp,
|
|
orderBlocks //
|
|
);
|
|
}
|
|
}
|
|
template <typename T>
|
|
void OrderedSortZones(
|
|
T *&items[] //
|
|
)
|
|
{
|
|
//
|
|
int count = ArraySize(items);
|
|
if (!IsValidSize(count))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
// Detect Youngest ...
|
|
int youngestIDX = GetYoungest(
|
|
items //
|
|
);
|
|
bool hasYoungest = IsValidSize(youngestIDX);
|
|
if (!hasYoungest)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
T *youngest = items[youngestIDX];
|
|
ArrayRemove(
|
|
items,
|
|
youngestIDX,
|
|
1 //
|
|
);
|
|
count = ArraySize(items);
|
|
if (!IsValidSize(count))
|
|
{
|
|
//
|
|
Add(
|
|
youngest,
|
|
items //
|
|
);
|
|
|
|
//
|
|
return;
|
|
}
|
|
|
|
//
|
|
if (youngest == NULL ||
|
|
!youngest.IsValid())
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
ENUM_X_DIRECTION dir = youngest.GetDirection();
|
|
bool isBullish = IsBullish(dir);
|
|
|
|
//
|
|
T *tmp[];
|
|
T *lastOB = youngest;
|
|
while (IsValidSize(count))
|
|
{
|
|
//
|
|
// Detect Youngest of Collection ...
|
|
int idx = GetYoungest(items);
|
|
T *iChild = items[idx];
|
|
ArrayRemove(
|
|
items,
|
|
idx,
|
|
1 //
|
|
);
|
|
count = ArraySize(items);
|
|
|
|
//
|
|
// Check Direction Must be Same ...
|
|
ENUM_X_DIRECTION iDir = iChild.GetDirection();
|
|
bool isSameDir = dir == iDir;
|
|
if (!isSameDir)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Check Creation time Sequence ...
|
|
bool isFromPassed = lastOB.From() > iChild.From();
|
|
if (!isFromPassed)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Check Order Block Place ...
|
|
bool isPlacePassed =
|
|
isBullish
|
|
? IsBelow(
|
|
iChild,
|
|
lastOB,
|
|
true // Ignore Inside ...
|
|
)
|
|
: IsAbove(
|
|
iChild,
|
|
lastOB,
|
|
true // Ignore Inside ...
|
|
);
|
|
if (!isPlacePassed)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Update Last OB ...
|
|
lastOB = iChild;
|
|
Add(
|
|
iChild,
|
|
tmp //
|
|
);
|
|
|
|
//
|
|
}
|
|
|
|
//
|
|
// Update Ordered Sorted Order Blocks ...
|
|
count = ArraySize(tmp);
|
|
if (IsValidSize(count))
|
|
{
|
|
//
|
|
Copy(
|
|
tmp,
|
|
items //
|
|
);
|
|
}
|
|
}
|
|
|
|
void OrderedSortBoxes(
|
|
XBoxZone &items[] //
|
|
)
|
|
{
|
|
//
|
|
int count = ArraySize(items);
|
|
if (!IsValidSize(count))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
// Detect Youngest ...
|
|
int youngestIDX = GetYoungest(
|
|
items //
|
|
);
|
|
bool hasYoungest = IsValidSize(youngestIDX);
|
|
if (!hasYoungest)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
XBoxZone youngest = items[youngestIDX];
|
|
ArrayRemove(
|
|
items,
|
|
youngestIDX,
|
|
1 //
|
|
);
|
|
count = ArraySize(items);
|
|
if (!IsValidSize(count))
|
|
{
|
|
//
|
|
AddRef(
|
|
youngest,
|
|
items //
|
|
);
|
|
|
|
//
|
|
return;
|
|
}
|
|
|
|
//
|
|
if (!youngest.IsValid())
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
ENUM_X_DIRECTION dir = youngest.dir;
|
|
bool isBullish = IsBullish(dir);
|
|
|
|
//
|
|
XBoxZone tmp[];
|
|
XBoxZone last = youngest;
|
|
while (IsValidSize(count))
|
|
{
|
|
//
|
|
// Detect Youngest of Collection ...
|
|
int idx = GetYoungest(items);
|
|
XBoxZone iChild = items[idx];
|
|
ArrayRemove(
|
|
items,
|
|
idx,
|
|
1 //
|
|
);
|
|
count = ArraySize(items);
|
|
|
|
//
|
|
// Check Direction Must be Same ...
|
|
ENUM_X_DIRECTION iDir = iChild.dir;
|
|
bool isSameDir = dir == iDir;
|
|
if (!isSameDir)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Check Creation time Sequence ...
|
|
bool isFromPassed = last.from > iChild.from;
|
|
if (!isFromPassed)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Check Order Block Place ...
|
|
bool isPlacePassed =
|
|
isBullish
|
|
? IsBoxBelow(
|
|
iChild,
|
|
last,
|
|
true // Ignore Inside ...
|
|
)
|
|
: IsBoxAbove(
|
|
iChild,
|
|
last,
|
|
true // Ignore Inside ...
|
|
);
|
|
if (!isPlacePassed)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Update Last OB ...
|
|
last = iChild;
|
|
AddRef(
|
|
iChild,
|
|
tmp //
|
|
);
|
|
|
|
//
|
|
}
|
|
|
|
//
|
|
// Update Ordered Sorted Order Blocks ...
|
|
count = ArraySize(tmp);
|
|
if (IsValidSize(count))
|
|
{
|
|
//
|
|
Copy(
|
|
tmp,
|
|
items //
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Extract Order Flows Swing Points ...
|
|
*
|
|
* @param type: ENUM_X_SWING_TYPE member ...
|
|
* @param swings: double Collection ...
|
|
*
|
|
* @return ( int )
|
|
*/
|
|
int ExtractSwingPoints(
|
|
ENUM_X_SWING_TYPE type,
|
|
XCOrderBlock *&orderBlocks[],
|
|
XSwingPoint &swings[] //
|
|
)
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
Clean(swings);
|
|
|
|
//
|
|
int count = ArraySize(orderBlocks);
|
|
|
|
//
|
|
if (type == X_NO_SWING ||
|
|
!IsValidSize(count))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool lookingForSwingLows = type == X_SWING_LOW;
|
|
|
|
//
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCOrderBlock *iOB = orderBlocks[i];
|
|
|
|
//
|
|
string iSymbol = iOB.GetSymbol();
|
|
ENUM_TIMEFRAMES iPeriod = iOB.GetPeriod();
|
|
|
|
//
|
|
int fromIndex = iBarShift(
|
|
iSymbol,
|
|
iPeriod,
|
|
iOB.From() //
|
|
);
|
|
|
|
//
|
|
fromIndex++;
|
|
|
|
//
|
|
double iValue = 0;
|
|
datetime iVTime = NULL;
|
|
if (lookingForSwingLows)
|
|
{
|
|
//
|
|
int idx = iLowest(
|
|
iSymbol,
|
|
iPeriod,
|
|
MODE_LOW,
|
|
fromIndex //
|
|
);
|
|
|
|
//
|
|
if (IsValidIndex(idx))
|
|
{
|
|
//
|
|
iValue = iLow(
|
|
iSymbol,
|
|
iPeriod,
|
|
idx //
|
|
);
|
|
|
|
//
|
|
iVTime = iTime(
|
|
iSymbol,
|
|
iPeriod,
|
|
idx //
|
|
);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//
|
|
int idx = iHighest(
|
|
iSymbol,
|
|
iPeriod,
|
|
MODE_HIGH,
|
|
fromIndex //
|
|
);
|
|
|
|
//
|
|
if (IsValidIndex(idx))
|
|
{
|
|
//
|
|
iValue = iHigh(
|
|
iSymbol,
|
|
iPeriod,
|
|
idx //
|
|
);
|
|
|
|
//
|
|
iVTime = iTime(
|
|
iSymbol,
|
|
iPeriod,
|
|
idx //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
if (iValue > 0)
|
|
{
|
|
//
|
|
XSwingPoint iSwingP;
|
|
|
|
//
|
|
iSwingP.type = type;
|
|
iSwingP.time = iVTime;
|
|
iSwingP.swing = iValue;
|
|
iSwingP.symbol = iSymbol;
|
|
iSwingP.period = iPeriod;
|
|
|
|
//
|
|
if (iSwingP.IsValid())
|
|
{
|
|
//
|
|
AddRef(
|
|
iSwingP,
|
|
swings //
|
|
);
|
|
}
|
|
|
|
//
|
|
iSwingP.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
result = ArraySize(swings);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
|
|
//
|
|
bool IsRejectBox(
|
|
ENUM_X_DIRECTION &forDir,
|
|
XOHCL &bar,
|
|
XBoxZone &box,
|
|
XPOIState &state,
|
|
XOHCL &swingBar,
|
|
XOHCL &rejectBar,
|
|
XOHCL &breakerBar,
|
|
XOHCL &momentumBar,
|
|
bool forceSwingRejection = true //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
swingBar.Clean();
|
|
rejectBar.Clean();
|
|
breakerBar.Clean();
|
|
momentumBar.Clean();
|
|
|
|
//
|
|
result = bar.IsValid() &&
|
|
box.IsValid() &&
|
|
state.IsValid() &&
|
|
state.HasChild() &&
|
|
HasDirection(forDir);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool isBullish = IsBullish(forDir);
|
|
|
|
//
|
|
double appliedPrice =
|
|
isBullish
|
|
? box.upper
|
|
: box.lower;
|
|
|
|
//
|
|
// Fetch Required Bars ...
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = bar.GetPreviousBar(cBar);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL pBar;
|
|
result = cBar.GetPreviousBar(pBar);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL ppBar;
|
|
result = pBar.GetPreviousBar(ppBar);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check Directional Swing Type ...
|
|
ENUM_X_SWING_TYPE swingType =
|
|
isBullish
|
|
? X_SWING_LOW
|
|
: X_SWING_HIGH;
|
|
|
|
//
|
|
bool isSwingLow =
|
|
//
|
|
pBar.low < ppBar.low &&
|
|
pBar.low < cBar.low &&
|
|
bar.open > pBar.low &&
|
|
//
|
|
appliedPrice > pBar.low &&
|
|
appliedPrice < pBar.GetDown()
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isSwingHigh =
|
|
//
|
|
pBar.high > ppBar.high &&
|
|
pBar.high > cBar.high &&
|
|
bar.open < pBar.high &&
|
|
//
|
|
appliedPrice < pBar.high &&
|
|
appliedPrice > pBar.GetUp()
|
|
//
|
|
;
|
|
|
|
//
|
|
// Force Rejected By Swing ...
|
|
if (forceSwingRejection)
|
|
{
|
|
//
|
|
result = swingType == X_SWING_HIGH
|
|
? isSwingHigh
|
|
: swingType == X_SWING_LOW
|
|
? isSwingLow
|
|
: false;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
}
|
|
|
|
//
|
|
bool hasValidSwing =
|
|
isBullish
|
|
? isSwingLow
|
|
: isSwingHigh;
|
|
if (hasValidSwing)
|
|
{
|
|
swingBar = pBar;
|
|
}
|
|
|
|
//
|
|
bool isCBarBreaked = IsBarBreak(
|
|
appliedPrice,
|
|
forDir,
|
|
cBar //
|
|
);
|
|
if (isCBarBreaked)
|
|
{
|
|
breakerBar = cBar;
|
|
}
|
|
bool isPBarBreaked = IsBarBreak(
|
|
appliedPrice,
|
|
forDir,
|
|
pBar //
|
|
);
|
|
if (isPBarBreaked)
|
|
{
|
|
breakerBar = pBar;
|
|
}
|
|
bool isPPBarBreaked = IsBarBreak(
|
|
appliedPrice,
|
|
forDir,
|
|
ppBar //
|
|
);
|
|
if (isPPBarBreaked)
|
|
{
|
|
breakerBar = ppBar;
|
|
}
|
|
bool isBoxBreaked = isCBarBreaked ||
|
|
isPBarBreaked ||
|
|
isPPBarBreaked;
|
|
|
|
//
|
|
bool isCBarRejected = IsBarReject(
|
|
appliedPrice,
|
|
forDir,
|
|
cBar //
|
|
);
|
|
if (isCBarRejected)
|
|
{
|
|
rejectBar = cBar;
|
|
}
|
|
bool isPBarRejected = IsBarReject(
|
|
appliedPrice,
|
|
forDir,
|
|
pBar //
|
|
);
|
|
if (isPBarRejected)
|
|
{
|
|
rejectBar = pBar;
|
|
}
|
|
bool isPPBarRejected = IsBarReject(
|
|
appliedPrice,
|
|
forDir,
|
|
ppBar //
|
|
);
|
|
if (isPPBarRejected)
|
|
{
|
|
rejectBar = ppBar;
|
|
}
|
|
bool isBoxRejected = isCBarRejected ||
|
|
isPBarRejected ||
|
|
isPPBarRejected;
|
|
|
|
//
|
|
int count = 0;
|
|
|
|
//
|
|
bool hasRejectionBar = false;
|
|
if (isBullish)
|
|
{
|
|
//
|
|
count = state.CountBullishRejectionBars();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCRejectionBar *iZone = state.bullishRejectionBars[i];
|
|
|
|
//
|
|
XOHCL iBar;
|
|
bool isFilled = iZone.FillBar(iBar);
|
|
if (!isFilled)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
int iBarIndex = iBar.Index();
|
|
|
|
//
|
|
hasRejectionBar =
|
|
//
|
|
(iBarIndex == cBar.Index() ||
|
|
iBarIndex == pBar.Index())
|
|
//
|
|
;
|
|
if (hasRejectionBar)
|
|
{
|
|
//
|
|
if (!rejectBar.IsValid())
|
|
{
|
|
rejectBar = iBar;
|
|
}
|
|
|
|
//
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//
|
|
count = state.CountBearishRejectionBars();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCRejectionBar *iZone = state.bearishRejectionBars[i];
|
|
|
|
//
|
|
XOHCL iBar;
|
|
bool isFilled = iZone.FillBar(iBar);
|
|
if (!isFilled)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
int iBarIndex = iBar.Index();
|
|
|
|
//
|
|
hasRejectionBar =
|
|
//
|
|
(iBarIndex == cBar.Index() ||
|
|
iBarIndex == pBar.Index())
|
|
//
|
|
;
|
|
if (hasRejectionBar)
|
|
{
|
|
//
|
|
if (!rejectBar.IsValid())
|
|
{
|
|
rejectBar = iBar;
|
|
}
|
|
|
|
//
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
bool hasMomentumBar = false;
|
|
if (isBullish)
|
|
{
|
|
//
|
|
count = state.CountBullishMomentumBars();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCMomentumBar *iZone = state.bullishMomentumBars[i];
|
|
|
|
//
|
|
XOHCL iBar;
|
|
bool isFilled = iZone.FillBar(iBar);
|
|
if (!isFilled)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
int iBarIndex = iBar.Index();
|
|
|
|
//
|
|
hasMomentumBar =
|
|
//
|
|
(iBarIndex == cBar.Index() ||
|
|
iBarIndex == pBar.Index())
|
|
//
|
|
;
|
|
if (hasMomentumBar)
|
|
{
|
|
//
|
|
if (!momentumBar.IsValid())
|
|
{
|
|
momentumBar = iBar;
|
|
}
|
|
|
|
//
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//
|
|
count = state.CountBearishMomentumBars();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCMomentumBar *iZone = state.bearishMomentumBars[i];
|
|
|
|
//
|
|
XOHCL iBar;
|
|
bool isFilled = iZone.FillBar(iBar);
|
|
if (!isFilled)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
int iBarIndex = iBar.Index();
|
|
|
|
//
|
|
hasMomentumBar =
|
|
//
|
|
(iBarIndex == cBar.Index() ||
|
|
iBarIndex == pBar.Index())
|
|
//
|
|
;
|
|
if (hasMomentumBar)
|
|
{
|
|
//
|
|
if (!momentumBar.IsValid())
|
|
{
|
|
momentumBar = iBar;
|
|
}
|
|
|
|
//
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
bool hasSwing = false;
|
|
if (isBullish)
|
|
{
|
|
//
|
|
count = state.CountSwingLows();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCSwing *iSwing = state.swingLows[i];
|
|
|
|
//
|
|
XOHCL iBar;
|
|
bool isFilled = iSwing.FillBar(iBar);
|
|
if (!isFilled)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
int iBarIndex = iBar.Index();
|
|
|
|
//
|
|
hasSwing =
|
|
//
|
|
(iBarIndex == cBar.Index() ||
|
|
iBarIndex == pBar.Index())
|
|
//
|
|
;
|
|
if (hasSwing)
|
|
{
|
|
//
|
|
if (!swingBar.IsValid())
|
|
{
|
|
swingBar = iBar;
|
|
}
|
|
|
|
//
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//
|
|
count = state.CountSwingHighs();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCSwing *iSwing = state.swingHighs[i];
|
|
|
|
//
|
|
XOHCL iBar;
|
|
bool isFilled = iSwing.FillBar(iBar);
|
|
if (!isFilled)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
int iBarIndex = iBar.Index();
|
|
|
|
//
|
|
hasSwing =
|
|
//
|
|
(iBarIndex == cBar.Index() ||
|
|
iBarIndex == pBar.Index())
|
|
//
|
|
;
|
|
if (hasSwing)
|
|
{
|
|
//
|
|
if (!swingBar.IsValid())
|
|
{
|
|
swingBar = iBar;
|
|
}
|
|
|
|
//
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
bool hasRequiredValidations =
|
|
//
|
|
(hasRejectionBar ||
|
|
hasMomentumBar)
|
|
//
|
|
||
|
|
//
|
|
(hasRejectionBar ||
|
|
hasSwing)
|
|
//
|
|
||
|
|
//
|
|
(hasMomentumBar ||
|
|
hasSwing)
|
|
//
|
|
;
|
|
|
|
//
|
|
result =
|
|
//
|
|
(isBoxBreaked &&
|
|
(hasRequiredValidations ||
|
|
hasValidSwing))
|
|
//
|
|
||
|
|
//
|
|
(isBoxRejected &&
|
|
(hasRequiredValidations ||
|
|
hasValidSwing))
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
|
|
template <typename T>
|
|
void UpdateTo(
|
|
T *&source[],
|
|
datetime time = NULL //
|
|
)
|
|
{
|
|
//
|
|
if (!IsValid(time))
|
|
{
|
|
time = TimeCurrent();
|
|
}
|
|
|
|
//
|
|
int count = ArraySize(source);
|
|
if (!IsValidSize(count))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
source[i].To(time);
|
|
}
|
|
}
|
|
|
|
|
|
template <typename T>
|
|
bool IsReject(
|
|
ENUM_X_DIRECTION forDir,
|
|
XOHCL &bar,
|
|
T *source,
|
|
XPOIState &state,
|
|
XOHCL &swingBar,
|
|
XOHCL &rejectBar,
|
|
XOHCL &breakerBar,
|
|
XOHCL &momentumBar,
|
|
bool forceSwingRejection = true //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
XBoxZone sourceBox;
|
|
result = ToBox(
|
|
sourceBox,
|
|
source //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = IsRejectBox(
|
|
forDir,
|
|
bar,
|
|
sourceBox,
|
|
state,
|
|
swingBar,
|
|
rejectBar,
|
|
breakerBar,
|
|
momentumBar,
|
|
forceSwingRejection //
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
|
|
//
|
|
bool HasConditions(
|
|
ENUM_X_DIRECTION &conditionsDir,
|
|
XPOIState &state,
|
|
int barIndex = 0,
|
|
ENUM_TIMEFRAMES forPeriod = NULL //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
conditionsDir = X_DIRECTION_NONE;
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
if (forPeriod == NULL)
|
|
{
|
|
forPeriod = period;
|
|
}
|
|
|
|
//
|
|
result =
|
|
//
|
|
IsValid(symbol) &&
|
|
IsValid(period) &&
|
|
state.IsValid() &&
|
|
HasWorkingZone() &&
|
|
state.HasChild()
|
|
//
|
|
;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = false;
|
|
|
|
//
|
|
// Detect Conditions Based On Start Zones ...
|
|
bool hasStartZones = HasStartZones();
|
|
if (hasStartZones)
|
|
{
|
|
//
|
|
int count = CountStartZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
X121SMCXWZZone iStartZone = startZones[i];
|
|
|
|
//
|
|
XBoxZone insideBox;
|
|
bool isPriceInside = iStartZone.IsPriceInside(
|
|
insideBox,
|
|
barIndex,
|
|
forPeriod //
|
|
);
|
|
if (!isPriceInside)
|
|
{
|
|
//
|
|
iStartZone.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
Print("PriceInside ...");
|
|
|
|
//
|
|
bool hasConditions = iStartZone.HasCondition(
|
|
insideBox,
|
|
state,
|
|
barIndex,
|
|
forPeriod //
|
|
);
|
|
if (!hasConditions)
|
|
{
|
|
//
|
|
iStartZone.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
iStartZone.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
// Detect Conditions Based On Working Zones ...
|
|
if (!result)
|
|
{
|
|
//
|
|
// Detect Result Based On WorkingZone ...
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
|
|
//
|
|
bool HasCondition(
|
|
XBoxZone &box,
|
|
XPOIState &state,
|
|
int barIndex = 0,
|
|
ENUM_TIMEFRAMES forPeriod = NULL //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
swingBar.Clean();
|
|
breakerBar.Clean();
|
|
appliedBox.Clean();
|
|
momentumBar.Clean();
|
|
rejectionBar.Clean();
|
|
|
|
//
|
|
result = IsValid() &&
|
|
box.IsValid() &&
|
|
HasDirection() &&
|
|
state.IsValid() &&
|
|
state.HasChild();
|
|
if (!result)
|
|
{
|
|
//
|
|
swingBar.Clean();
|
|
breakerBar.Clean();
|
|
appliedBox.Clean();
|
|
momentumBar.Clean();
|
|
rejectionBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
string symbol = box.symbol;
|
|
if (!IsValid(forPeriod))
|
|
{
|
|
forPeriod = box.period;
|
|
}
|
|
datetime cTime = iTime(
|
|
symbol,
|
|
forPeriod,
|
|
barIndex //
|
|
);
|
|
|
|
//
|
|
ENUM_X_DIRECTION forDir = box.dir;
|
|
bool isBullish = IsBullish(forDir);
|
|
|
|
//
|
|
int supportsCount = 0;
|
|
bool hasSupports = false;
|
|
XCSupportZone *supports[];
|
|
|
|
//
|
|
int resistancesCount = 0;
|
|
bool hasResistances = false;
|
|
XCResistanceZone *resistances[];
|
|
|
|
//
|
|
XBoxZone supResBoxes[];
|
|
int supresBoxesCount = 0;
|
|
bool hasSupResBoxes = false;
|
|
|
|
//
|
|
int count = 0;
|
|
bool has = false;
|
|
|
|
//
|
|
has = state.HasSupportZones();
|
|
if (has)
|
|
{
|
|
//
|
|
count = state.CountSupportZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCSupportZone *iZone = state.supportZones[i];
|
|
|
|
//
|
|
iZone.To(cTime);
|
|
|
|
//
|
|
XBoxZone iBox;
|
|
bool hasBox = ToBox(
|
|
iBox,
|
|
iZone //
|
|
);
|
|
if (!hasBox)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Check From ...
|
|
bool isInside = IsBoxInside(
|
|
iBox,
|
|
box //
|
|
);
|
|
if (!isInside)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
Add(
|
|
iZone,
|
|
supports //
|
|
);
|
|
|
|
//
|
|
AddRef(
|
|
iBox,
|
|
supResBoxes //
|
|
);
|
|
|
|
//
|
|
iBox.Clean();
|
|
}
|
|
|
|
//
|
|
supportsCount = ArraySize(supports);
|
|
hasSupports = IsValidSize(supportsCount);
|
|
|
|
//
|
|
supresBoxesCount = ArraySize(supResBoxes);
|
|
hasSupResBoxes = IsValidSize(supresBoxesCount);
|
|
}
|
|
|
|
//
|
|
has = state.HasResistanceZones();
|
|
if (has)
|
|
{
|
|
//
|
|
count = state.CountResistanceZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCResistanceZone *iZone = state.resistanceZones[i];
|
|
|
|
//
|
|
iZone.To(cTime);
|
|
|
|
//
|
|
XBoxZone iBox;
|
|
bool hasBox = ToBox(
|
|
iBox,
|
|
iZone //
|
|
);
|
|
if (!hasBox)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Check From ...
|
|
bool isInside = IsBoxInside(
|
|
iBox,
|
|
box //
|
|
);
|
|
if (!isInside)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
Add(
|
|
iZone,
|
|
resistances //
|
|
);
|
|
|
|
//
|
|
AddRef(
|
|
iBox,
|
|
supResBoxes //
|
|
);
|
|
|
|
//
|
|
iBox.Clean();
|
|
}
|
|
|
|
//
|
|
resistancesCount = ArraySize(resistances);
|
|
hasResistances = IsValidSize(resistancesCount);
|
|
|
|
//
|
|
supresBoxesCount = ArraySize(supResBoxes);
|
|
hasSupResBoxes = IsValidSize(supresBoxesCount);
|
|
}
|
|
|
|
//
|
|
result = hasSupResBoxes;
|
|
if (!result)
|
|
{
|
|
//
|
|
Clean(supports);
|
|
Clean(resistances);
|
|
Clean(supResBoxes);
|
|
|
|
//
|
|
swingBar.Clean();
|
|
breakerBar.Clean();
|
|
appliedBox.Clean();
|
|
momentumBar.Clean();
|
|
rejectionBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
// //
|
|
// AddRef(
|
|
// box,
|
|
// supResBoxes //
|
|
// );
|
|
|
|
//
|
|
// Detect Bars ...
|
|
|
|
//
|
|
XOHCL zBar;
|
|
result = zBar.Init(
|
|
symbol,
|
|
forPeriod,
|
|
barIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
zBar.Clean();
|
|
Clean(supports);
|
|
Clean(resistances);
|
|
Clean(supResBoxes);
|
|
|
|
//
|
|
swingBar.Clean();
|
|
breakerBar.Clean();
|
|
appliedBox.Clean();
|
|
momentumBar.Clean();
|
|
rejectionBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = zBar.GetPreviousBar(cBar);
|
|
if (!result)
|
|
{
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
Clean(supports);
|
|
Clean(resistances);
|
|
Clean(supResBoxes);
|
|
|
|
//
|
|
swingBar.Clean();
|
|
breakerBar.Clean();
|
|
appliedBox.Clean();
|
|
momentumBar.Clean();
|
|
rejectionBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL pBar;
|
|
result = cBar.GetPreviousBar(pBar);
|
|
if (!result)
|
|
{
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
Clean(supports);
|
|
Clean(resistances);
|
|
Clean(supResBoxes);
|
|
|
|
//
|
|
swingBar.Clean();
|
|
breakerBar.Clean();
|
|
appliedBox.Clean();
|
|
momentumBar.Clean();
|
|
rejectionBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL ppBar;
|
|
result = pBar.GetPreviousBar(ppBar);
|
|
if (!result)
|
|
{
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
ppBar.Clean();
|
|
Clean(supports);
|
|
Clean(resistances);
|
|
Clean(supResBoxes);
|
|
|
|
//
|
|
swingBar.Clean();
|
|
breakerBar.Clean();
|
|
appliedBox.Clean();
|
|
momentumBar.Clean();
|
|
rejectionBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check Conditions ...
|
|
|
|
//
|
|
// Detect Start Senario ...
|
|
|
|
//
|
|
double fiboPressureLevel = GetFiboLevelValue(X_FIBO_LEVEL_382);
|
|
|
|
//
|
|
double fiboUpDown = GetFibonacciLevel(
|
|
pBar.high,
|
|
pBar.low,
|
|
X_FIBO_LEVEL_382,
|
|
X_DIRECTION_BEARISH //
|
|
);
|
|
double fiboDownUp = GetFibonacciLevel(
|
|
pBar.high,
|
|
pBar.low,
|
|
X_FIBO_LEVEL_382,
|
|
X_DIRECTION_BULLISH //
|
|
);
|
|
|
|
//
|
|
bool hasFiboToUpPressure =
|
|
fiboDownUp > 0 &&
|
|
fiboDownUp <= pBar.GetDown();
|
|
bool hasFiboToDownPressure =
|
|
fiboUpDown > 0 &&
|
|
fiboUpDown >= pBar.GetUp();
|
|
|
|
//
|
|
int selectedBoxIDX = -1;
|
|
for (int j = 0; j < supresBoxesCount; j++)
|
|
{
|
|
//
|
|
double appliedPrice =
|
|
isBullish
|
|
? supResBoxes[j].lower
|
|
: supResBoxes[j].upper;
|
|
|
|
//
|
|
// Check Swing Low ...
|
|
bool isSwingLow =
|
|
//
|
|
pBar.low < ppBar.low &&
|
|
pBar.low < cBar.low &&
|
|
zBar.open > pBar.low &&
|
|
//
|
|
appliedPrice > pBar.low &&
|
|
appliedPrice < pBar.GetDown()
|
|
//
|
|
;
|
|
bool isPressuredSwingLow =
|
|
isSwingLow &&
|
|
hasFiboToUpPressure;
|
|
bool isPressuredStrongSwingLow =
|
|
pBar.IsBullish() &&
|
|
isPressuredSwingLow;
|
|
|
|
//
|
|
bool isSwingHigh =
|
|
//
|
|
pBar.high > ppBar.high &&
|
|
pBar.high > cBar.high &&
|
|
zBar.open < pBar.high &&
|
|
//
|
|
appliedPrice < pBar.high &&
|
|
appliedPrice > pBar.GetUp()
|
|
//
|
|
;
|
|
bool isPressuredSwingHigh =
|
|
isSwingHigh &&
|
|
hasFiboToDownPressure;
|
|
bool isPressuredStrongSwingHigh =
|
|
pBar.IsBearish() &&
|
|
isPressuredSwingHigh;
|
|
|
|
//
|
|
bool hasValidSwing =
|
|
isBullish
|
|
? isSwingLow
|
|
: isSwingHigh;
|
|
bool hasValidPressuredSwing =
|
|
isBullish
|
|
? isPressuredSwingLow
|
|
: isPressuredSwingHigh;
|
|
bool hasValidPressuredStrongSwing =
|
|
isBullish
|
|
? isPressuredStrongSwingLow
|
|
: isPressuredStrongSwingHigh;
|
|
if (hasValidSwing)
|
|
{
|
|
swingBar = pBar;
|
|
}
|
|
if (hasValidPressuredSwing)
|
|
{
|
|
swingBar = pBar;
|
|
}
|
|
if (hasValidPressuredStrongSwing)
|
|
{
|
|
swingBar = pBar;
|
|
}
|
|
|
|
//
|
|
bool isCBarBreaked = IsBarBreak(
|
|
appliedPrice,
|
|
forDir,
|
|
cBar //
|
|
);
|
|
if (isCBarBreaked)
|
|
{
|
|
breakerBar = cBar;
|
|
}
|
|
bool isPBarBreaked = IsBarBreak(
|
|
appliedPrice,
|
|
forDir,
|
|
pBar //
|
|
);
|
|
if (!isCBarBreaked && isPBarBreaked)
|
|
{
|
|
breakerBar = pBar;
|
|
}
|
|
else
|
|
{
|
|
isPBarBreaked = false;
|
|
}
|
|
bool isPPBarBreaked = IsBarBreak(
|
|
appliedPrice,
|
|
forDir,
|
|
ppBar //
|
|
);
|
|
if (!isCBarBreaked &&
|
|
!isPBarBreaked &&
|
|
isPPBarBreaked)
|
|
{
|
|
breakerBar = ppBar;
|
|
}
|
|
else
|
|
{
|
|
isPPBarBreaked = false;
|
|
}
|
|
bool isBoxBreaked = isCBarBreaked ||
|
|
isPBarBreaked ||
|
|
isPPBarBreaked;
|
|
|
|
//
|
|
bool isCBarRejected = IsBarReject(
|
|
appliedPrice,
|
|
forDir,
|
|
cBar //
|
|
);
|
|
if (isCBarRejected)
|
|
{
|
|
rejectionBar = cBar;
|
|
}
|
|
bool isPBarRejected = IsBarReject(
|
|
appliedPrice,
|
|
forDir,
|
|
pBar //
|
|
);
|
|
if (!isCBarRejected && isPBarRejected)
|
|
{
|
|
rejectionBar = pBar;
|
|
}
|
|
else
|
|
{
|
|
isPBarRejected = false;
|
|
}
|
|
bool isPPBarRejected = IsBarReject(
|
|
appliedPrice,
|
|
forDir,
|
|
ppBar //
|
|
);
|
|
if (!isCBarRejected &&
|
|
!isPBarRejected &&
|
|
isPPBarRejected)
|
|
{
|
|
rejectionBar = ppBar;
|
|
}
|
|
else
|
|
{
|
|
isPPBarRejected = false;
|
|
}
|
|
bool isBoxRejected = isCBarRejected ||
|
|
isPBarRejected ||
|
|
isPPBarRejected;
|
|
|
|
//
|
|
bool hasRejectionBar = false;
|
|
if (isBullish)
|
|
{
|
|
//
|
|
count = state.CountBullishRejectionBars();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCRejectionBar *iZone = state.bullishRejectionBars[i];
|
|
|
|
//
|
|
XOHCL iBar;
|
|
bool isFilled = iZone.FillBar(iBar);
|
|
if (!isFilled)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
int iBarIndex = iBar.Index();
|
|
|
|
//
|
|
hasRejectionBar =
|
|
//
|
|
(iBarIndex == cBar.Index() ||
|
|
iBarIndex == pBar.Index())
|
|
//
|
|
;
|
|
if (hasRejectionBar)
|
|
{
|
|
//
|
|
if (!rejectionBar.IsValid())
|
|
{
|
|
rejectionBar = iBar;
|
|
}
|
|
|
|
//
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//
|
|
count = state.CountBearishRejectionBars();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCRejectionBar *iZone = state.bearishRejectionBars[i];
|
|
|
|
//
|
|
XOHCL iBar;
|
|
bool isFilled = iZone.FillBar(iBar);
|
|
if (!isFilled)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
int iBarIndex = iBar.Index();
|
|
|
|
//
|
|
hasRejectionBar =
|
|
//
|
|
(iBarIndex == cBar.Index() ||
|
|
iBarIndex == pBar.Index())
|
|
//
|
|
;
|
|
if (hasRejectionBar)
|
|
{
|
|
//
|
|
if (!rejectionBar.IsValid())
|
|
{
|
|
rejectionBar = iBar;
|
|
}
|
|
|
|
//
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
bool hasMomentumBar = false;
|
|
if (isBullish)
|
|
{
|
|
//
|
|
count = state.CountBullishMomentumBars();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCMomentumBar *iZone = state.bullishMomentumBars[i];
|
|
|
|
//
|
|
XOHCL iBar;
|
|
bool isFilled = iZone.FillBar(iBar);
|
|
if (!isFilled)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
int iBarIndex = iBar.Index();
|
|
|
|
//
|
|
hasMomentumBar =
|
|
//
|
|
(iBarIndex == cBar.Index() ||
|
|
iBarIndex == pBar.Index())
|
|
//
|
|
;
|
|
if (hasMomentumBar)
|
|
{
|
|
//
|
|
if (!momentumBar.IsValid())
|
|
{
|
|
momentumBar = iBar;
|
|
}
|
|
|
|
//
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//
|
|
count = state.CountBearishMomentumBars();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCMomentumBar *iZone = state.bearishMomentumBars[i];
|
|
|
|
//
|
|
XOHCL iBar;
|
|
bool isFilled = iZone.FillBar(iBar);
|
|
if (!isFilled)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
int iBarIndex = iBar.Index();
|
|
|
|
//
|
|
hasMomentumBar =
|
|
//
|
|
(iBarIndex == cBar.Index() ||
|
|
iBarIndex == pBar.Index())
|
|
//
|
|
;
|
|
if (hasMomentumBar)
|
|
{
|
|
//
|
|
if (!momentumBar.IsValid())
|
|
{
|
|
momentumBar = iBar;
|
|
}
|
|
|
|
//
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
bool hasSwing = false;
|
|
if (isBullish)
|
|
{
|
|
//
|
|
count = state.CountSwingLows();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCSwing *iSwing = state.swingLows[i];
|
|
|
|
//
|
|
XOHCL iBar;
|
|
bool isFilled = iSwing.FillBar(iBar);
|
|
if (!isFilled)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
int iBarIndex = iBar.Index();
|
|
|
|
//
|
|
hasSwing =
|
|
//
|
|
(iBarIndex == cBar.Index() ||
|
|
iBarIndex == pBar.Index())
|
|
//
|
|
;
|
|
if (hasSwing)
|
|
{
|
|
//
|
|
if (!swingBar.IsValid())
|
|
{
|
|
swingBar = iBar;
|
|
}
|
|
|
|
//
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//
|
|
count = state.CountSwingHighs();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCSwing *iSwing = state.swingHighs[i];
|
|
|
|
//
|
|
XOHCL iBar;
|
|
bool isFilled = iSwing.FillBar(iBar);
|
|
if (!isFilled)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
int iBarIndex = iBar.Index();
|
|
|
|
//
|
|
hasSwing =
|
|
//
|
|
(iBarIndex == cBar.Index() ||
|
|
iBarIndex == pBar.Index())
|
|
//
|
|
;
|
|
if (hasSwing)
|
|
{
|
|
//
|
|
if (!swingBar.IsValid())
|
|
{
|
|
swingBar = iBar;
|
|
}
|
|
|
|
//
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
bool hasRequiredValidations =
|
|
//
|
|
(hasRejectionBar ||
|
|
hasMomentumBar)
|
|
//
|
|
||
|
|
//
|
|
(hasRejectionBar ||
|
|
hasSwing)
|
|
//
|
|
||
|
|
//
|
|
(hasMomentumBar ||
|
|
hasSwing)
|
|
//
|
|
;
|
|
|
|
//
|
|
result =
|
|
//
|
|
(isBoxBreaked &&
|
|
(hasRequiredValidations ||
|
|
hasValidPressuredSwing))
|
|
//
|
|
||
|
|
//
|
|
(isBoxRejected &&
|
|
(hasRequiredValidations ||
|
|
hasValidPressuredSwing))
|
|
//
|
|
;
|
|
if (result)
|
|
{
|
|
//
|
|
selectedBoxIDX = j;
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
result =
|
|
result &&
|
|
(isBullish
|
|
? zBar.open >= box.upper
|
|
: zBar.open <= box.lower) &&
|
|
IsValidIndex(selectedBoxIDX);
|
|
if (result)
|
|
{
|
|
appliedBox = supResBoxes[selectedBoxIDX];
|
|
}
|
|
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
ppBar.Clean();
|
|
Clean(supports);
|
|
Clean(resistances);
|
|
Clean(supResBoxes);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
|
|
|
|
//
|
|
ulong chartID = visionCycleHelper.mPOIDrawer.ChartIdentification();
|
|
int subWindow = visionCycleHelper.mPOIDrawer.SubWindowIdentification();
|
|
|
|
//
|
|
if (pivot > 0)
|
|
{
|
|
//
|
|
string name = "Pivot_" + symbol + ToString(period) + ToString(pivot) + "_";
|
|
CChartObjectHLine *iObj;
|
|
iObj = new CChartObjectHLine();
|
|
bool isCreated = iObj.Create(
|
|
chartID,
|
|
name,
|
|
subWindow,
|
|
pivot //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
iObj.Color(clrLime);
|
|
mObjects.Add(iObj);
|
|
}
|
|
}
|
|
|
|
//
|
|
if (point > 0)
|
|
{
|
|
//
|
|
string name = "Point_" + symbol + ToString(period) + ToString(pivot) + "_";
|
|
CChartObjectHLine *iObj;
|
|
iObj = new CChartObjectHLine();
|
|
bool isCreated = iObj.Create(
|
|
chartID,
|
|
name,
|
|
subWindow,
|
|
point //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
iObj.Color(clrLime);
|
|
mObjects.Add(iObj);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//
|
|
RemoveDraws();
|
|
|
|
//
|
|
if (hasLastBullishConsolidationZone)
|
|
{
|
|
//
|
|
XCConsolidationZoneObject *iObj;
|
|
bool isCreated = visionCycleHelper
|
|
.mPOIDrawer
|
|
.CreateConsolidationZone(
|
|
lastBullishConsolidationZone,
|
|
iObj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
mObjects.Add(iObj);
|
|
}
|
|
}
|
|
|
|
//
|
|
if (hasLastBearishConsolidationZone)
|
|
{
|
|
//
|
|
XCConsolidationZoneObject *iObj;
|
|
bool isCreated = visionCycleHelper
|
|
.mPOIDrawer
|
|
.CreateConsolidationZone(
|
|
lastBearishConsolidationZone,
|
|
iObj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
mObjects.Add(iObj);
|
|
}
|
|
}
|
|
|
|
//
|
|
if (hasPrevBullishConsolidationZone)
|
|
{
|
|
//
|
|
XCConsolidationZoneObject *iObj;
|
|
bool isCreated = visionCycleHelper
|
|
.mPOIDrawer
|
|
.CreateConsolidationZone(
|
|
prevBullishConsolidationZone,
|
|
iObj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
mObjects.Add(iObj);
|
|
}
|
|
}
|
|
|
|
//
|
|
if (hasPrevBearishConsolidationZone)
|
|
{
|
|
//
|
|
XCConsolidationZoneObject *iObj;
|
|
bool isCreated = visionCycleHelper
|
|
.mPOIDrawer
|
|
.CreateConsolidationZone(
|
|
prevBearishConsolidationZone,
|
|
iObj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
mObjects.Add(iObj);
|
|
}
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
XPOIState state;
|
|
mXWZPOIDetector.GetState(state);
|
|
|
|
//
|
|
ENUM_X_DIRECTION trend =
|
|
IsValid(lastBullishTrend) &&
|
|
lastBullishTrend > lastBearishTrend
|
|
? X_DIRECTION_BULLISH
|
|
: IsValid(lastBearishTrend) &&
|
|
lastBearishTrend > lastBullishTrend
|
|
? X_DIRECTION_BEARISH
|
|
: X_DIRECTION_NONE;
|
|
bool hasTrend = HasDirection(trend);
|
|
bool hasBullishTrend = hasTrend &&
|
|
IsBullish(trend);
|
|
bool hasBearishTrend = hasTrend &&
|
|
IsBearish(trend);
|
|
|
|
//
|
|
// Order Block ...
|
|
has = hasBullishTrend &&
|
|
state.HasBullishOrderBlocks();
|
|
if (has)
|
|
{
|
|
//
|
|
XCOrderBlock *tmps[];
|
|
count = ExtractInsideZones(
|
|
iBar,
|
|
state.bullishOrderBlocks,
|
|
tmps //
|
|
);
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
idx = GetLowest(tmps);
|
|
hasInsideOB = IsValidIndex(idx);
|
|
if (hasInsideOB)
|
|
{
|
|
insideOB = tmps[idx];
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(tmps);
|
|
}
|
|
has = hasBearishTrend &&
|
|
state.HasBearishOrderBlocks();
|
|
if (has)
|
|
{
|
|
//
|
|
XCOrderBlock *tmps[];
|
|
count = ExtractInsideZones(
|
|
iBar,
|
|
state.bearishOrderBlocks,
|
|
tmps //
|
|
);
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
idx = GetHighest(tmps);
|
|
hasInsideOB = IsValidIndex(idx);
|
|
if (hasInsideOB)
|
|
{
|
|
insideOB = tmps[idx];
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(tmps);
|
|
}
|
|
|
|
//
|
|
// Fair Value Gap ...
|
|
has = hasBullishTrend &&
|
|
state.HasBullishFairValueGaps();
|
|
if (has)
|
|
{
|
|
//
|
|
XCFVG *tmps[];
|
|
count = ExtractInsideZones(
|
|
iBar,
|
|
state.bullishFairValueGaps,
|
|
tmps //
|
|
);
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
idx = GetLowest(tmps);
|
|
hasInsideFVG = IsValidIndex(idx);
|
|
if (hasInsideFVG)
|
|
{
|
|
insideFVG = tmps[idx];
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(tmps);
|
|
}
|
|
has = hasBearishTrend &&
|
|
state.HasBearishFairValueGaps();
|
|
if (has)
|
|
{
|
|
//
|
|
XCFVG *tmps[];
|
|
count = ExtractInsideZones(
|
|
iBar,
|
|
state.bearishFairValueGaps,
|
|
tmps //
|
|
);
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
idx = GetHighest(tmps);
|
|
hasInsideFVG = IsValidIndex(idx);
|
|
if (hasInsideFVG)
|
|
{
|
|
insideFVG = tmps[idx];
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(tmps);
|
|
}
|
|
|
|
//
|
|
// Supply Zone ...
|
|
has = hasBearishTrend &&
|
|
state.HasSupplyZones();
|
|
if (has)
|
|
{
|
|
//
|
|
XCSupplyZone *tmps[];
|
|
count = ExtractInsideZones(
|
|
iBar,
|
|
state.supplyZones,
|
|
tmps //
|
|
);
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
idx = GetHighest(tmps);
|
|
hasInsideSupply = IsValidIndex(idx);
|
|
if (hasInsideSupply)
|
|
{
|
|
insideSupply = tmps[idx];
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(tmps);
|
|
}
|
|
|
|
//
|
|
// Resistance Zone ...
|
|
has = hasBearishTrend &&
|
|
state.HasResistanceZones();
|
|
if (has)
|
|
{
|
|
//
|
|
XCResistanceZone *tmps[];
|
|
count = ExtractInsideZones(
|
|
iBar,
|
|
state.resistanceZones,
|
|
tmps //
|
|
);
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
idx = GetHighest(tmps);
|
|
hasInsideResistance = IsValidIndex(idx);
|
|
if (hasInsideResistance)
|
|
{
|
|
insideResistnce = tmps[idx];
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(tmps);
|
|
}
|
|
|
|
//
|
|
// Demand Zone ...
|
|
has = hasBullishTrend &&
|
|
state.HasDemandZones();
|
|
if (has)
|
|
{
|
|
//
|
|
XCDemandZone *tmps[];
|
|
count = ExtractInsideZones(
|
|
iBar,
|
|
state.demandZones,
|
|
tmps //
|
|
);
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
idx = GetLowest(tmps);
|
|
hasInsideDemand = IsValidIndex(idx);
|
|
if (hasInsideDemand)
|
|
{
|
|
insideDemand = tmps[idx];
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(tmps);
|
|
}
|
|
|
|
//
|
|
// Support Zone ...
|
|
has = hasBullishTrend &&
|
|
state.HasSupportZones();
|
|
if (has)
|
|
{
|
|
//
|
|
XCSupportZone *tmps[];
|
|
count = ExtractInsideZones(
|
|
iBar,
|
|
state.supportZones,
|
|
tmps //
|
|
);
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
idx = GetLowest(tmps);
|
|
hasInsideSupport = IsValidIndex(idx);
|
|
if (hasInsideSupport)
|
|
{
|
|
insideSupport = tmps[idx];
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(tmps);
|
|
}
|
|
|
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
|
|
// //
|
|
// // Calculate Rejection Values ...
|
|
|
|
// //
|
|
// double fiboUpDown = GetFibonacciLevel(
|
|
// iBar.high,
|
|
// iBar.low,
|
|
// X_FIBO_LEVEL_382,
|
|
// X_DIRECTION_BEARISH //
|
|
// );
|
|
// double fiboDownUp = GetFibonacciLevel(
|
|
// iBar.high,
|
|
// iBar.low,
|
|
// X_FIBO_LEVEL_382,
|
|
// X_DIRECTION_BULLISH //
|
|
// );
|
|
|
|
// //
|
|
// bool hasFiboToUpPressure =
|
|
// fiboDownUp > 0 &&
|
|
// fiboDownUp <= iBar.GetDown();
|
|
// bool hasFiboToDownPressure =
|
|
// fiboUpDown > 0 &&
|
|
// fiboUpDown >= iBar.GetUp();
|
|
|
|
// //
|
|
// bool isLongReject =
|
|
// //
|
|
// iBar.low < iMa &&
|
|
// iBar.high >= iMa &&
|
|
// iBar.GetDown() >= iMa
|
|
// //
|
|
// ;
|
|
// bool isStrongLongReject =
|
|
// iBar.IsBullish() &&
|
|
// isLongReject;
|
|
// bool isPressuredLongReject =
|
|
// isLongReject &&
|
|
// hasFiboToUpPressure;
|
|
// bool isPressuredStrongLongReject =
|
|
// isStrongLongReject &&
|
|
// isPressuredLongReject;
|
|
|
|
// //
|
|
// bool isShortReject =
|
|
// //
|
|
// iBar.high > iMa &&
|
|
// iBar.low <= iMa &&
|
|
// iBar.GetUp() <= iMa
|
|
// //
|
|
// ;
|
|
// bool isStrongShortReject =
|
|
// iBar.IsBearish() &&
|
|
// isShortReject;
|
|
// bool isPressuredShortReject =
|
|
// isShortReject &&
|
|
// hasFiboToDownPressure;
|
|
// bool isPressuredStrongShortReject =
|
|
// isStrongShortReject &&
|
|
// isPressuredShortReject;
|
|
|
|
// //
|
|
// double iLongRejectValue = 0;
|
|
// double iShortRejectValue = 0;
|
|
|
|
// //
|
|
// bool isAppliedLongReject = false;
|
|
// bool isAppliedShortReject = false;
|
|
// switch (rejectionType)
|
|
// {
|
|
// //
|
|
// case XWZ_REJECTION_BAR:
|
|
// isAppliedLongReject = isLongReject;
|
|
// isAppliedShortReject = isShortReject;
|
|
// break;
|
|
|
|
// //
|
|
// case XWZ_REJECTION_STRONG_BAR:
|
|
// isAppliedLongReject = isStrongLongReject;
|
|
// isAppliedShortReject = isStrongShortReject;
|
|
// break;
|
|
|
|
// //
|
|
// case XWZ_REJECTION_PRESSURED_BAR:
|
|
// isAppliedLongReject = isPressuredLongReject;
|
|
// isAppliedShortReject = isPressuredShortReject;
|
|
// break;
|
|
|
|
// //
|
|
// case XWZ_REJECTION_STRONG_PRESSURED_BAR:
|
|
// isAppliedLongReject = isPressuredStrongLongReject;
|
|
// isAppliedShortReject = isPressuredStrongShortReject;
|
|
// break;
|
|
// }
|
|
|
|
// //
|
|
// // Calculate Rejection Verification Values ...
|
|
|
|
// //
|
|
// int iLLIDX = pBar
|
|
// .FindLowestIndex(
|
|
// rejectionVerificationLength,
|
|
// MODE_LOW //
|
|
// );
|
|
// datetime iLLTime = iTime(
|
|
// _Symbol,
|
|
// _Period,
|
|
// iLLIDX //
|
|
// );
|
|
// double iLL = iLow(
|
|
// _Symbol,
|
|
// _Period,
|
|
// iLLIDX //
|
|
// );
|
|
|
|
// //
|
|
// int iHHIDX = pBar
|
|
// .FindHighestIndex(
|
|
// rejectionVerificationLength,
|
|
// MODE_HIGH //
|
|
// );
|
|
// datetime iHHTime = iTime(
|
|
// _Symbol,
|
|
// _Period,
|
|
// iHHIDX //
|
|
// );
|
|
// double iHH = iHigh(
|
|
// _Symbol,
|
|
// _Period,
|
|
// iHHIDX //
|
|
// );
|
|
|
|
// //
|
|
// bool isLLBreaked = false;
|
|
// bool isHHBreaked = false;
|
|
// if (rejectionVerificationLength > 0)
|
|
// {
|
|
// //
|
|
// for (int i = bar_index + 1; i < bar_index + rejectionVerificationLength; i++)
|
|
// {
|
|
// //
|
|
// double iMaValue = maBuffer[i];
|
|
|
|
// //
|
|
// XOHCL iBar;
|
|
// bool isInited = iBar.Init(
|
|
// _Symbol,
|
|
// _Period,
|
|
// i //
|
|
// );
|
|
// if (!isInited)
|
|
// {
|
|
// //
|
|
// iBar.Clean();
|
|
// isLLBreaked = true;
|
|
// isHHBreaked = true;
|
|
// break;
|
|
// }
|
|
|
|
// //
|
|
// if (!isLLBreaked)
|
|
// {
|
|
// isLLBreaked = iBar.low < iMaValue;
|
|
// }
|
|
|
|
// //
|
|
// if (!isHHBreaked)
|
|
// {
|
|
// isHHBreaked = iBar.high > iMaValue;
|
|
// }
|
|
|
|
// //
|
|
// if (isLLBreaked &&
|
|
// isHHBreaked)
|
|
// {
|
|
// break;
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Validate Rejections ...
|
|
|
|
// //
|
|
// // -[] Before Reject Long, price
|
|
// // must not touch Ma from Up for at least 3 Bar ...
|
|
// bool isValidAppliedLongReject =
|
|
// !isLLBreaked &&
|
|
// isAppliedLongReject;
|
|
|
|
// //
|
|
// // -[] Before Reject Short Price
|
|
// // must no touch Ma from down at least 3 Bar ...
|
|
// bool isValidAppliedShortReject =
|
|
// !isHHBreaked &&
|
|
// isAppliedShortReject;
|
|
|
|
// //
|
|
// if (isValidAppliedLongReject)
|
|
// {
|
|
// iLongRejectValue = iBar.low - points10;
|
|
// }
|
|
// else
|
|
// {
|
|
// iLongRejectValue = 0;
|
|
// }
|
|
|
|
// //
|
|
// if (isValidAppliedShortReject)
|
|
// {
|
|
// iShortRejectValue = iBar.high + points10;
|
|
// }
|
|
// else
|
|
// {
|
|
// iShortRejectValue = 0;
|
|
// }
|
|
|
|
// //
|
|
// // Draw Verification Box ...
|
|
// if (isValidAppliedLongReject ||
|
|
// isValidAppliedShortReject)
|
|
// {
|
|
// //
|
|
// datetime time1 = iTime(
|
|
// _Symbol,
|
|
// _Period,
|
|
// iBar.Index() + rejectionVerificationLength //
|
|
// );
|
|
// datetime time2 = iTime(
|
|
// _Symbol,
|
|
// _Period,
|
|
// iBar.Index() + 0 //
|
|
// );
|
|
// string llName = ToString(iLLIDX) + "_" +
|
|
// ToString(iLL) + "_" +
|
|
// ToMD5(iLLTime);
|
|
// CChartObjectTrend *llTrend;
|
|
// llTrend = new CChartObjectTrend();
|
|
// bool isCreated = llTrend.Create(
|
|
// 0,
|
|
// llName,
|
|
// 0,
|
|
// time1,
|
|
// iLL,
|
|
// time2,
|
|
// iLL //
|
|
// );
|
|
// if (isCreated)
|
|
// {
|
|
// mXWZDrawnObjects.Add(llTrend);
|
|
// }
|
|
|
|
// //
|
|
// string hhName = ToString(iHHIDX) + "_" +
|
|
// ToString(iHH) + "_" +
|
|
// ToMD5(iHHTime);
|
|
// CChartObjectTrend *hhTrend;
|
|
// hhTrend = new CChartObjectTrend();
|
|
// isCreated = hhTrend.Create(
|
|
// 0,
|
|
// hhName,
|
|
// 0,
|
|
// time1,
|
|
// iHH,
|
|
// time2,
|
|
// iHH //
|
|
// );
|
|
// if (isCreated)
|
|
// {
|
|
// mXWZDrawnObjects.Add(hhTrend);
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// int idx = -1;
|
|
// int count = 0;
|
|
// bool has = false;
|
|
|
|
// //
|
|
// ENUM_X_DIRECTION trend =
|
|
// IsValid(lastBullishTrend) &&
|
|
// lastBullishTrend > lastBearishTrend
|
|
// ? X_DIRECTION_BULLISH
|
|
// : IsValid(lastBearishTrend) &&
|
|
// lastBearishTrend > lastBullishTrend
|
|
// ? X_DIRECTION_BEARISH
|
|
// : X_DIRECTION_NONE;
|
|
// bool hasTrend = HasDirection(trend);
|
|
// bool hasBullishTrend = hasTrend &&
|
|
// IsBullish(trend);
|
|
// bool hasBearishTrend = hasTrend &&
|
|
// IsBearish(trend);
|
|
|
|
// //
|
|
// // Filling Buffers ...
|
|
|
|
// //
|
|
// longSLBuffer[bar_index] = iLongSL;
|
|
// shortSLBuffer[bar_index] = iShortSL;
|
|
|
|
|
|
///////////////////////////////////////////////////
|
|
|
|
//
|
|
// Draw ...
|
|
bool isBullish = signalZone.ob.IsBullish();
|
|
bool isCreated = false;
|
|
XCBaseObject *iObj = NULL;
|
|
if (isBullish)
|
|
{
|
|
//
|
|
XCBullishOrderBlockObject *mObj;
|
|
isCreated = visionCycleHelper.mPOIDrawer
|
|
.CreateBullishOrderBlock(
|
|
signalZone.ob,
|
|
mObj //
|
|
);
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
//
|
|
mObj.ZoneWidth(2);
|
|
mObj.ZoneColor(clrGold);
|
|
mObj.ZoneStyle(STYLE_SOLID);
|
|
|
|
//
|
|
iObj = (XCBaseObject *)mObj;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//
|
|
XCBearishOrderBlockObject *mObj;
|
|
isCreated = visionCycleHelper.mPOIDrawer
|
|
.CreateBearishOrderBlock(
|
|
signalZone.ob,
|
|
mObj //
|
|
);
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
//
|
|
mObj.ZoneWidth(2);
|
|
mObj.ZoneColor(clrGold);
|
|
mObj.ZoneStyle(STYLE_SOLID);
|
|
|
|
//
|
|
iObj = (XCBaseObject *)mObj;
|
|
}
|
|
}
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
mWorkingZoneObjects.Add(iObj);
|
|
}
|
|
|
|
//
|
|
Print("Signal Zone ...");
|