last working ...

This commit is contained in:
2025-06-04 00:04:32 +03:30
parent 043c635812
commit a7ea212ada
8 changed files with 1784 additions and 288 deletions
+991
View File
@@ -5699,4 +5699,995 @@ class XCX121XCatbHelper : public XCBaseHelper
//
};
//
// Extensions ...
//
enum ENUM_XCATB_DIRECTION_SHIFT_TYPES
{
XCATB_DIRECTION_SHIFT_TYPE_NONE, // None
XCATB_DIRECTION_SHIFT_TYPE_SAR, // XSARB
XCATB_DIRECTION_SHIFT_TYPE_TREND, // XTRNDB
XCATB_DIRECTION_SHIFT_TYPE_DELTA, // XDELTAB
XCATB_DIRECTION_SHIFT_TYPE_VOLUME, // XVLMB
XCATB_DIRECTION_SHIFT_TYPE_SIGNAL_BAR, // XSBARB
XCATB_DIRECTION_SHIFT_TYPE_HK_SIGNAL_BAR, // XHKSBARB
};
//
bool IsValid(ENUM_XCATB_DIRECTION_SHIFT_TYPES value)
{
return value != XCATB_DIRECTION_SHIFT_TYPE_NONE;
}
//
string ToString(ENUM_XCATB_DIRECTION_SHIFT_TYPES value)
{
return EnumToString(value);
}
//
ENUM_XCATB_DIRECTION_SHIFT_TYPES GetDirectionShiftType(XBoxZone &box)
{
//
ENUM_XCATB_DIRECTION_SHIFT_TYPES result = XCATB_DIRECTION_SHIFT_TYPE_NONE;
//
if (!box.IsValid())
{
return result;
}
//
ENUM_XCATB_DIRECTION_SHIFT_TYPES all[] = {
XCATB_DIRECTION_SHIFT_TYPE_SAR,
XCATB_DIRECTION_SHIFT_TYPE_TREND,
XCATB_DIRECTION_SHIFT_TYPE_DELTA,
XCATB_DIRECTION_SHIFT_TYPE_VOLUME,
XCATB_DIRECTION_SHIFT_TYPE_SIGNAL_BAR,
XCATB_DIRECTION_SHIFT_TYPE_HK_SIGNAL_BAR,
};
//
int count = ArraySize(all);
for (int i = 0; i < count; i++)
{
//
if (box.type == ToString(all[i]))
{
//
result = all[i];
break;
}
}
//
return result;
}
//
bool IsDirectionShift(XBoxZone &box)
{
//
bool result = false;
//
result = IsValid(GetDirectionShiftType(box));
//
return result;
}
/**
* Generate Sar Direction Shift Box ...
*
* @param box: XBoxZone instance reference, Holds Generated Box ...
* @param helper: XCX121XCatbHelper instance pointer ...
* @param conditions: X121XCatbConditions instance reference, Specified Market Conditions ...
*
* @return ( bool )
*/
bool GenerateSarDirectionShiftBox(
XBoxZone &box,
XCX121XCatbHelper *helper,
X121XCatbConditions &conditions //
)
{
//
bool result = false;
//
// Normalize Args ...
box.Clean();
//
// Validate Args ...
result =
helper != NULL;
if (!result)
{
return result;
}
//
// Define Requirements ...
//
int idx = -1;
int zIDX = 0;
int cIDX = zIDX + 1;
int pIDX = cIDX + 1;
//
// Check Sar Direction Changed Happens or not ...
//
bool isBullish =
//
(
//
// Current SAR is Directional ...
conditions.isSarBullish &&
//
// Previous InDirectional Sar Exists ...
helper.lastSarBearish.IsValid() &&
//
// Current Close is Over previous Sar ...
conditions.bars[cIDX].close > helper.lastSarBearish.after &&
//
// Before Close is not Over previous Sar ...
conditions.bars[pIDX].close <= helper.lastSarBearish.after
//
)
//
;
//
bool isBearish =
//
(
//
// Current SAR is Directional ...
conditions.isSarBearish &&
//
// Previous InDirectional Sar Exists ...
helper.lastSarBullish.IsValid() &&
//
// Current Close is Under previous ...
conditions.bars[cIDX].close < helper.lastSarBullish.after &&
//
// Before Close is not Under previous ...
conditions.bars[pIDX].close >= helper.lastSarBullish.after
//
)
//
;
//
result =
isBullish ||
isBearish;
if (!result)
{
return result;
}
//
// Assign Last Direction Shift ...
XDirectionShift lastBullish = helper.lastSarBullish;
XDirectionShift lastBearish = helper.lastSarBearish;
XDirectionShift selected = isBullish
? lastBearish
: lastBullish;
//
// Convert to Box ...
box.type = "XSARB";
box.from = selected.at;
box.symbol = selected.symbol;
box.period = selected.period;
box.dir = isBullish
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
box.to = conditions.bars[zIDX].time;
//
// Detect Boundary ...
idx = selected.Index();
result = IsValidIndex(idx);
if (result)
{
//
box.lower = conditions.bars[zIDX].FindLowest(idx, MODE_CLOSE);
box.upper = conditions.bars[zIDX].FindHighest(idx, MODE_CLOSE);
}
//
// Summarize Result ...
result = box.IsValid();
//
// Cleanup Resources ...
//
if (!result)
{
box.Clean();
}
//
selected.Clean();
lastBullish.Clean();
lastBearish.Clean();
//
return result;
}
/**
* Generate Trend Direction Shift Box ...
*
* @param box: XBoxZone instance reference, Holds Generated Box ...
* @param helper: XCX121XCatbHelper instance pointer ...
* @param conditions: X121XCatbConditions instance reference, Specified Market Conditions ...
*
* @return ( bool )
*/
bool GenerateTrendDirectionShiftBox(
XBoxZone &box,
XCX121XCatbHelper *helper,
X121XCatbConditions &conditions //
)
{
//
bool result = false;
//
// Normalize Args ...
box.Clean();
//
// Validate Args ...
result =
helper != NULL;
if (!result)
{
return result;
}
//
// Define Requirements ...
//
int idx = -1;
int zIDX = 0;
int cIDX = zIDX + 1;
int pIDX = cIDX + 1;
//
// Check Sar Direction Changed Happens or not ...
//
bool isBullish =
//
(
//
// Current Trend is Directional ...
conditions.isTrendBullish &&
//
// Previous InDirectiona; Trend Exists ...
helper.lastTrendBearish.IsValid() &&
//
// Current Close is Over previous ...
conditions.bars[cIDX].close > helper.lastTrendBearish.after &&
//
// Before close is not Over previous ...
conditions.bars[pIDX].close <= helper.lastTrendBearish.after
//
)
//
;
//
bool isBearish =
//
(
//
// Current Trend is Directional ...
conditions.isTrendBearish &&
//
// Previous InDirectiona; Trend Exists ...
helper.lastTrendBullish.IsValid() &&
//
// Current Close is Under previous ...
conditions.bars[cIDX].close < helper.lastTrendBullish.after &&
//
// Before close is not Under previous ...
conditions.bars[pIDX].close >= helper.lastTrendBullish.after
//
)
//
;
//
result =
isBullish ||
isBearish;
if (!result)
{
return result;
}
//
// Assign Last Direction Shift ...
XDirectionShift lastBullish = helper.lastTrendBullish;
XDirectionShift lastBearish = helper.lastTrendBearish;
XDirectionShift selected = isBullish
? lastBearish
: lastBullish;
//
// Convert to Box ...
box.type = "XTRNDB";
box.from = selected.at;
box.symbol = selected.symbol;
box.period = selected.period;
box.dir = isBullish
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
box.to = conditions.bars[zIDX].time;
//
// Detect Boundary ...
idx = selected.Index();
result = IsValidIndex(idx);
if (result)
{
//
box.lower = conditions.bars[zIDX].FindLowest(idx, MODE_CLOSE);
box.upper = conditions.bars[zIDX].FindHighest(idx, MODE_CLOSE);
}
//
// Summarize Result ...
result = box.IsValid();
//
// Cleanup Resources ...
//
if (!result)
{
box.Clean();
}
//
selected.Clean();
lastBullish.Clean();
lastBearish.Clean();
//
return result;
}
/**
* Generate Delta Direction Shift Box ...
*
* @param box: XBoxZone instance reference, Holds Generated Box ...
* @param helper: XCX121XCatbHelper instance pointer ...
* @param conditions: X121XCatbConditions instance reference, Specified Market Conditions ...
*
* @return ( bool )
*/
bool GenerateDeltaDirectionShiftBox(
XBoxZone &box,
XCX121XCatbHelper *helper,
X121XCatbConditions &conditions //
)
{
//
bool result = false;
//
// Normalize Args ...
box.Clean();
//
// Validate Args ...
result =
helper != NULL;
if (!result)
{
return result;
}
//
// Define Requirements ...
//
int idx = -1;
int zIDX = 0;
int cIDX = zIDX + 1;
int pIDX = cIDX + 1;
//
// Check Sar Direction Changed Happens or not ...
//
bool isBullish =
//
// Check State ...
(
//
// Delta is Up ...
conditions.deltaBuffer[cIDX] > conditions.deltaBuffer[pIDX] &&
//
// Delta Signal is Up ...
conditions.deltaSignalBuffer[cIDX] > conditions.deltaSignalBuffer[pIDX] &&
//
// Delta Crossed Over Delta Signal ...
conditions.deltaBuffer[cIDX] > conditions.deltaSignalBuffer[cIDX]
//
)
//
&&
//
// Check Last InDirectional Exists ...
helper.lastDeltaBearish.IsValid() &&
//
// Current Close is Over last ...
conditions.bars[cIDX].close > helper.lastDeltaBearish.after &&
//
// Before Close is not Over last ...
conditions.bars[pIDX].close <= helper.lastDeltaBearish.after
//
;
//
bool isBearish =
//
// Check State ...
(
//
// Delta is Down ...
conditions.deltaBuffer[cIDX] < conditions.deltaBuffer[pIDX] &&
//
// Delta Signal is Down ...
conditions.deltaSignalBuffer[cIDX] < conditions.deltaSignalBuffer[pIDX] &&
//
// Delta Crossed Under Delta Signal ...
conditions.deltaBuffer[cIDX] < conditions.deltaSignalBuffer[cIDX]
//
)
//
&&
//
// Check Last InDirectional Exists ...
helper.lastDeltaBullish.IsValid() &&
//
// Current Close is Under last ...
conditions.bars[cIDX].close < helper.lastDeltaBullish.after &&
//
// Before Close is not Under last ...
conditions.bars[pIDX].close >= helper.lastDeltaBullish.after
//
;
//
result =
isBullish ||
isBearish;
if (!result)
{
return result;
}
//
// Assign Last Direction Shift ...
XDirectionShift lastBullish = helper.lastDeltaBullish;
XDirectionShift lastBearish = helper.lastDeltaBearish;
XDirectionShift selected = isBullish
? lastBearish
: lastBullish;
//
// Convert to Box ...
box.type = "XDELTAB";
box.from = selected.at;
box.symbol = selected.symbol;
box.period = selected.period;
box.dir = isBullish
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
box.to = conditions.bars[zIDX].time;
//
// Detect Boundary ...
idx = selected.Index();
result = IsValidIndex(idx);
if (result)
{
//
box.lower = conditions.bars[zIDX].FindLowest(idx, MODE_CLOSE);
box.upper = conditions.bars[zIDX].FindHighest(idx, MODE_CLOSE);
}
//
// Summarize Result ...
result = box.IsValid();
//
// Cleanup Resources ...
//
if (!result)
{
box.Clean();
}
//
selected.Clean();
lastBullish.Clean();
lastBearish.Clean();
//
return result;
}
/**
* Generate Volume Direction Shift Box ...
*
* @param box: XBoxZone instance reference, Holds Generated Box ...
* @param helper: XCX121XCatbHelper instance pointer ...
* @param conditions: X121XCatbConditions instance reference, Specified Market Conditions ...
*
* @return ( bool )
*/
bool GenerateVolumeDirectionShiftBox(
XBoxZone &box,
XCX121XCatbHelper *helper,
X121XCatbConditions &conditions //
)
{
//
bool result = false;
//
// Normalize Args ...
box.Clean();
//
// Validate Args ...
result =
helper != NULL;
if (!result)
{
return result;
}
//
// Define Requirements ...
//
int idx = -1;
int zIDX = 0;
int cIDX = zIDX + 1;
int pIDX = cIDX + 1;
//
// Check Sar Direction Changed Happens or not ...
//
bool isBullish =
//
(
//
//
// Volume is Up ...
conditions.bullishVolumeBuffer[1] > conditions.bullishVolumeBuffer[2] &&
//
// Volume Signal is Up ...
conditions.bullishVolumeSignalBuffer[1] > conditions.bullishVolumeSignalBuffer[2] &&
//
// Volume Signals Crossed Over ...
conditions.bullishVolumeSignalBuffer[1] > conditions.bearishVolumeSignalBuffer[1]
//
)
//
&&
//
// Check Last InDirectional Exists ...
helper.lastVolumeBearish.IsValid() &&
//
// Current Close is Over last ...
conditions.bars[cIDX].close > helper.lastVolumeBearish.after &&
//
// Before Close is not Over last ...
conditions.bars[pIDX].close <= helper.lastVolumeBearish.after
//
;
//
bool isBearish =
//
(
//
//
// Volume is Up ...
conditions.bearishVolumeBuffer[1] > conditions.bearishVolumeBuffer[2] &&
//
// Volume Signal is Up ...
conditions.bearishVolumeSignalBuffer[1] > conditions.bearishVolumeSignalBuffer[2] &&
//
// Volume Signals Crossed Over ...
conditions.bearishVolumeSignalBuffer[1] > conditions.bullishVolumeSignalBuffer[1]
//
)
//
&&
//
// Check Last InDirectional Exists ...
helper.lastVolumeBullish.IsValid() &&
//
// Current Close is Over last ...
conditions.bars[cIDX].close < helper.lastVolumeBullish.after &&
//
// Before Close is not Over last ...
conditions.bars[pIDX].close >= helper.lastVolumeBullish.after
//
;
//
result =
isBullish ||
isBearish;
if (!result)
{
return result;
}
//
// Assign Last Direction Shift ...
XDirectionShift lastBullish = helper.lastVolumeBullish;
XDirectionShift lastBearish = helper.lastVolumeBearish;
XDirectionShift selected = isBullish
? lastBearish
: lastBullish;
//
// Convert to Box ...
box.type = "XVLMB";
box.from = selected.at;
box.symbol = selected.symbol;
box.period = selected.period;
box.dir = isBullish
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
box.to = conditions.bars[zIDX].time;
//
// Detect Boundary ...
idx = selected.Index();
result = IsValidIndex(idx);
if (result)
{
//
box.lower = conditions.bars[zIDX].FindLowest(idx, MODE_CLOSE);
box.upper = conditions.bars[zIDX].FindHighest(idx, MODE_CLOSE);
}
//
// Summarize Result ...
result = box.IsValid();
//
// Cleanup Resources ...
//
if (!result)
{
box.Clean();
}
//
selected.Clean();
lastBullish.Clean();
lastBearish.Clean();
//
return result;
}
/**
* Generate Signal Bar Direction Shift Box ...
*
* @param box: XBoxZone instance reference, Holds Generated Box ...
* @param helper: XCX121XCatbHelper instance pointer ...
* @param conditions: X121XCatbConditions instance reference, Specified Market Conditions ...
*
* @return ( bool )
*/
bool GenerateSignalBarDirectionShiftBox(
XBoxZone &box,
XCX121XCatbHelper *helper,
X121XCatbConditions &conditions //
)
{
//
bool result = false;
//
// Normalize Args ...
box.Clean();
//
// Validate Args ...
result =
helper != NULL;
if (!result)
{
return result;
}
//
// Define Requirements ...
//
int idx = -1;
int zIDX = 0;
int cIDX = zIDX + 1;
int pIDX = cIDX + 1;
//
// Check Sar Direction Changed Happens or not ...
//
bool isBullish =
//
(
//
// Check Direction ...
conditions.isSBarBullish &&
//
// Previous InDirectional Exists ...
helper.lastSignalBarBearish.IsValid() &&
//
// Current Signal Bar close over prev ...
conditions.sBarCloseBuffer[cIDX] > helper.lastSignalBarBearish.after &&
//
// Prev Signal Bar not close over prev ...
conditions.sBarCloseBuffer[pIDX] <= helper.lastSignalBarBearish.after
//
)
//
;
//
bool isBearish =
//
(
//
// Check Direction ...
conditions.isSBarBearish &&
//
// Previous InDirectional Exists ...
helper.lastSignalBarBullish.IsValid() &&
//
// Current Signal Bar close over prev ...
conditions.sBarCloseBuffer[cIDX] < helper.lastSignalBarBullish.after &&
//
// Prev Signal Bar not close over prev ...
conditions.sBarCloseBuffer[pIDX] >= helper.lastSignalBarBullish.after
//
)
//
;
//
result =
isBullish ||
isBearish;
if (!result)
{
return result;
}
//
// Assign Last Direction Shift ...
XDirectionShift lastBullish = helper.lastSignalBarBullish;
XDirectionShift lastBearish = helper.lastSignalBarBearish;
XDirectionShift selected = isBullish
? lastBearish
: lastBullish;
//
// Convert to Box ...
box.type = "XSBARB";
box.from = selected.at;
box.symbol = selected.symbol;
box.period = selected.period;
box.dir = isBullish
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
box.to = conditions.bars[zIDX].time;
//
// Detect Boundary ...
idx = selected.Index();
result = IsValidIndex(idx);
if (result)
{
//
box.lower = conditions.bars[zIDX].FindLowest(idx, MODE_CLOSE);
box.upper = conditions.bars[zIDX].FindHighest(idx, MODE_CLOSE);
}
//
// Summarize Result ...
result = box.IsValid();
//
// Cleanup Resources ...
//
if (!result)
{
box.Clean();
}
//
selected.Clean();
lastBullish.Clean();
lastBearish.Clean();
//
return result;
}
/**
* Generate HK Signal Bar Direction Shift Box ...
*
* @param box: XBoxZone instance reference, Holds Generated Box ...
* @param helper: XCX121XCatbHelper instance pointer ...
* @param conditions: X121XCatbConditions instance reference, Specified Market Conditions ...
*
* @return ( bool )
*/
bool GenerateHKSignalBarDirectionShiftBox(
XBoxZone &box,
XCX121XCatbHelper *helper,
X121XCatbConditions &conditions //
)
{
//
bool result = false;
//
// Normalize Args ...
box.Clean();
//
// Validate Args ...
result =
helper != NULL;
if (!result)
{
return result;
}
//
// Define Requirements ...
//
int idx = -1;
int zIDX = 0;
int cIDX = zIDX + 1;
int pIDX = cIDX + 1;
//
// Check Sar Direction Changed Happens or not ...
//
bool isBullish =
//
(
//
// Check Direction ...
conditions.isHKSBarBullish &&
//
// Previous InDirectional Exists ...
helper.lastHKSignalBarBearish.IsValid() &&
//
// Current Signal Bar close over prev ...
conditions.hkSBarCloseBuffer[cIDX] > helper.lastHKSignalBarBearish.after &&
//
// Prev Signal Bar not close over prev ...
conditions.hkSBarCloseBuffer[pIDX] <= helper.lastHKSignalBarBearish.after
//
)
//
;
//
bool isBearish =
//
(
//
// Check Direction ...
conditions.isHKSBarBearish &&
//
// Previous InDirectional Exists ...
helper.lastHKSignalBarBullish.IsValid() &&
//
// Current Signal Bar close over prev ...
conditions.hkSBarCloseBuffer[cIDX] < helper.lastHKSignalBarBullish.after &&
//
// Prev Signal Bar not close over prev ...
conditions.hkSBarCloseBuffer[pIDX] >= helper.lastHKSignalBarBullish.after
//
)
//
;
//
result =
isBullish ||
isBearish;
if (!result)
{
return result;
}
//
// Assign Last Direction Shift ...
XDirectionShift lastBullish = helper.lastHKSignalBarBullish;
XDirectionShift lastBearish = helper.lastHKSignalBarBearish;
XDirectionShift selected = isBullish
? lastBearish
: lastBullish;
//
// Convert to Box ...
box.type = "XHKSBARB";
box.from = selected.at;
box.symbol = selected.symbol;
box.period = selected.period;
box.dir = isBullish
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
box.to = conditions.bars[zIDX].time;
//
// Detect Boundary ...
idx = selected.Index();
result = IsValidIndex(idx);
if (result)
{
//
box.lower = conditions.bars[zIDX].FindLowest(idx, MODE_CLOSE);
box.upper = conditions.bars[zIDX].FindHighest(idx, MODE_CLOSE);
}
//
// Summarize Result ...
result = box.IsValid();
//
// Cleanup Resources ...
//
if (!result)
{
box.Clean();
}
//
selected.Clean();
lastBullish.Clean();
lastBearish.Clean();
//
return result;
}
//