This commit is contained in:
2025-03-04 16:18:51 +03:30
parent ec006cd6b7
commit 52856ff815
4 changed files with 753 additions and 881 deletions
+137 -812
View File
@@ -2897,815 +2897,140 @@ int FilterZones(
//
//
// /**
// * Check Trading Conditions based on Specified Box ...
// *
// * @param box: XBoxZone instance Reference, specified Box for Checking Conditions ...
// * @param appliedBox: XBoxZone instance Reference, hold's Selected Box inside Parent which trading conditions happens on it ...
// * @param swingBar: XOHCL instance Reference, holds Swing Bar if Exists ...
// * @param breakerBar: XOHCL instance Reference, holds Breaker Bar if Exists ...
// * @param rejectionBar: XOHCL instance Reference, holds Rejection Bar if Exists ...
// * @param momentumBar: XOHCL instance Reference, holds Momentum Bar if Exists ...
// * @param state: XPOIState instance Reference, provides requirement zone's for check Conditions ...
// * @param barIndex: int, Specified Bar Index ...
// * @param forPeriod: ENUM_TIMEFRAMES member, Specified Conditions Checking Period ...
// *
// * @return ( bool )
// */
// bool CheckBoxForTradeConditions(
// XBoxZone &box,
// XBoxZone &appliedBox,
// XOHCL &swingBar,
// XOHCL &breakerBar,
// XOHCL &rejectionBar,
// XOHCL &momentumBar,
// XPOIState &state,
// int barIndex = 0,
// ENUM_TIMEFRAMES forPeriod = NULL //
// )
// {
// //
// bool result = false;
// //
// swingBar.Clean();
// appliedBox.Clean();
// breakerBar.Clean();
// momentumBar.Clean();
// rejectionBar.Clean();
// //
// if (barIndex < 0)
// {
// barIndex = 0;
// }
// //
// result = box.IsValid() &&
// state.IsValid() &&
// state.HasChild();
// if (!result)
// {
// return result;
// }
// //
// if (!IsValid(forPeriod))
// {
// forPeriod = box.period;
// }
// //
// string symbol = box.symbol;
// datetime cTime = iTime(
// symbol,
// forPeriod,
// barIndex //
// );
// //
// ENUM_X_DIRECTION forDir = box.dir;
// result = HasDirection(forDir);
// if (!result)
// {
// return result;
// }
// //
// 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);
// //
// return result;
// }
// //
// // Detect Bars ...
// //
// XOHCL zBar;
// result = zBar.Init(
// symbol,
// forPeriod,
// barIndex //
// );
// if (!result)
// {
// //
// zBar.Clean();
// Clean(supports);
// Clean(resistances);
// Clean(supResBoxes);
// //
// return result;
// }
// //
// XOHCL cBar;
// result = zBar.GetPreviousBar(cBar);
// if (!result)
// {
// //
// zBar.Clean();
// cBar.Clean();
// Clean(supports);
// Clean(resistances);
// Clean(supResBoxes);
// //
// return result;
// }
// //
// XOHCL pBar;
// result = cBar.GetPreviousBar(pBar);
// if (!result)
// {
// //
// zBar.Clean();
// cBar.Clean();
// pBar.Clean();
// Clean(supports);
// Clean(resistances);
// Clean(supResBoxes);
// //
// return result;
// }
// //
// XOHCL ppBar;
// result = pBar.GetPreviousBar(ppBar);
// if (!result)
// {
// //
// zBar.Clean();
// cBar.Clean();
// pBar.Clean();
// ppBar.Clean();
// Clean(supports);
// Clean(resistances);
// Clean(supResBoxes);
// //
// 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;
// }
/**
* Detect Nearest Price Out of Specified Box ...
*
* @param box: XBoxZone instance Reference ...
* @param outSideBar: XOHCL instance Reference which Represents Out Side Bar if Exists ...
* @param forPeriod: ENUM_TIMEFRAMES member which provides time frame of Out Bar, if not Provides used box Period as Default ...
* @param forDir: ENUM_X_DIRECTION member which Specified outSide Direction, use Box Dir as Default ...
* @param forceBodyIn: bool value which Specifyed Body Breakes or not, Default is false ...
* @param barIndex: integer value which Specified Start Bar Index, Default is 0 ...
*
* @return ( bool )
*/
bool DetectBoxNearestPriceOut(
XBoxZone &box,
XOHCL &outSideBar,
ENUM_TIMEFRAMES forPeriod = NULL,
ENUM_X_DIRECTION forDir = X_DIRECTION_NONE,
bool forceBodyIn = false,
int barIndex = 0 //
)
{
//
bool result = false;
//
outSideBar.Clean();
//
if (barIndex < 0)
{
barIndex = 0;
}
//
result = box.IsValid();
if (!result)
{
return result;
}
//
if (!IsValid(forPeriod))
{
forPeriod = box.period;
}
//
if (!HasDirection(forDir))
{
forDir = box.dir;
}
//
bool isBullish = IsBullish(forDir);
//
int fromIndex = iBarShift(
box.symbol,
box.period,
box.from //
);
result = IsValidIndex(fromIndex);
if (!result)
{
return result;
}
//
XOHCL iBar;
XOHCL iPBar;
bool has = false;
for (int i = barIndex; i < fromIndex; i++)
{
//
has = iBar.Init(
box.symbol,
forPeriod,
i //
);
if (!has)
{
continue;
}
//
has = iBar.GetPreviousBar(iPBar);
if (!has)
{
continue;
}
//
bool isInsideFromLower =
iBar.high < box.lower &&
iPBar.high > box.lower;
//
bool isInsideFromUpper =
iBar.low > box.upper &&
iPBar.low < box.upper;
//
bool isInsideBodyFromLower =
iPBar.GetUp() > box.lower;
//
bool isInsideBodyFromUpper =
iPBar.GetDown() < box.upper;
//
result =
isBullish
? (!forceBodyIn
? isInsideFromLower
: isInsideFromLower &&
isInsideBodyFromLower)
: (!forceBodyIn
? isInsideFromUpper
: isInsideFromUpper &&
isInsideBodyFromUpper);
if (result)
{
//
outSideBar = iBar;
break;
}
}
//
iBar.Clean();
iPBar.Clean();
//
return result;
}
//