This commit is contained in:
2025-05-30 23:37:27 +03:30
parent 1e002ced49
commit 16c58af75c
9 changed files with 5676 additions and 4503 deletions
+523 -2
View File
@@ -22,8 +22,8 @@
//
// Imports ...
#include "../../Classes/x-saherelm.x-alert.class.mq5"
#include "../../Classes/x-saherelm.x-bar.analyser.class.mq5"
#include "../../Classes/x-saherelm.x-guard.class.mq5"
#include "../../Helpers/x-saherelm.x121.xcatb.helper.mq5";
#include "../Classes/xcatbea.x-poi.detector.class.mq5";
#include "../Classes/xcatbea.x-poi.drawer.class.mq5";
@@ -33,6 +33,527 @@
//
// Definitions ...
class XCXCATBEASignaller : XCBaseAlert
//
struct XCATBEASignallerInputs
{
//
// Pros ...
string symbol;
string provider;
ENUM_TIMEFRAMES period;
X121XCatbInputs catbInputs;
XTriggerBlockFilters filters;
XTriggerBlockValidationRules validations;
//
// Constructor(s) ...
XCATBEASignallerInputs()
{
Clean();
}
//
// Tools ...
//
// Cleanup ...
void Clean()
{
//
symbol = NULL;
period = NULL;
provider = NULL;
filters.Clean();
catbInputs.Clean();
validations.Clean();
//
ZeroMemory(this);
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
IsValid(symbol) &&
IsValid(period) &&
IsValid(provider) &&
catbInputs.IsValid();
//
return result;
}
//
};
class XCXCATBEASignaller : XCBase
{
//
// Public ...
public:
//
// Props ...
//
bool useGuards; // Use Guards or not ...
bool allowDraws; // Allow Draws or not ...
//
XBarTracker barTraker; // Bar Tracker ...
XCX121XCatbHelper *helper; // XCATB Helper Class instance ...
XCBarAnalyser *barAnalyser; // Bar Analyser ...
XCXCATBEAPOIDrawer *drawer; // POI Drawer ...
XCXCATBEAPOIDetector *detector; // POI Detector ...
//
XCATBEAStrategyConditions mConditions;
XCATBEAStrategyConditions mConditionsCollection[];
//
// Constructor ...
XCXCATBEASignaller(XCATBEASignallerInputs &inputs)
{
Init(inputs);
}
//
// Deconstructor ...
~XCXCATBEASignaller()
{
DeInit();
}
//
// Properties ...
//
string GetSymbol()
{
return symbol;
}
//
string GetProvider()
{
return provider;
}
//
ENUM_TIMEFRAMES GetPeriod()
{
return period;
}
//
// Tick Analyser ...
/**
* Process Tick ...
*/
void ProcessTick(
XPosition &positions[],
XGuard &guards[],
XCATBEAStrategyConditions &conditions //
)
{
//
Clean(guards);
conditions.Clean();
//
int count = 0;
bool has = false;
int barIndex = 0;
//
// Check Guards ...
has = DetectGuards(
guards,
positions,
barIndex //
);
//
// Check Triggered Conditions ...
has = HasChild(mConditionsCollection);
if (has)
{
//
int selectedIDX = -1;
count = ArraySize(mConditionsCollection);
for (int i = 0; i < count; i++)
{
//
// Select indexed Conditions ...
XCATBEAStrategyConditions iConditions = mConditionsCollection[i];
//
// Check Conditions Triggered ...
has = DetectSignalTrigger(
iConditions,
barIndex //
);
if (has)
{
//
selectedIDX = i;
conditions = iConditions;
iConditions.Clean();
//
break;
}
//
iConditions.Clean();
}
//
// Check Can Trigger ...
has = IsValidIndex(selectedIDX) &&
conditions.IsValid() &&
conditions.IsSetuped() &&
conditions.CanTrigger();
if (has)
{
//
ArrayRemove(
mConditionsCollection,
selectedIDX,
1 //
);
}
else
{
conditions.Clean();
}
}
//
// Check Bar Processing ...
if (!barTraker.CanProcessBar())
{
return;
}
//
// Check Signal Setups ...
has = DetectSignalSetup(barIndex);
if (has) {
//
barTraker.Waits();
//
AddConditionsIfNotExists();
//
mConditions.Clean();
}
}
//
// Signalling Tools ...
/**
* Detect Setup Conditions based on Signalling ...
*
* @param maxAllowedSLDistanceInPoint: int, Max Allowed SL Distance in Points (if Bigger thn Zero Provided) ...
*
* @return ( bool )
*/
bool DetectSignalSetup(int barIndex = 0)
{
//
bool result = false;
//
// Normalize Args ...
barIndex = NormalizeInt(barIndex, 0);
//
// Cleanup Resource ...
//
return result;
}
/**
* Detect Trigger Conditions for Specified Signal ...
*
* @param conditions: XCATBEAStrategyConditions instance Reference, Specified Signal Conditions ...
* @param maxAllowedSetupAge: specified Setup Age for Expiration (if bigger than Zero) ...
*
* @return ( bool )
*/
bool DetectSignalTrigger(
XCATBEAStrategyConditions &conditions,
int barIndex = 0 //
)
{
//
bool result = false;
//
// Normalize Args ...
barIndex = NormalizeInt(barIndex, 0);
//
// Validate Setup ...
result = conditions.IsSetuped();
if (!result)
{
return result;
}
//
// Cleanup Resources ...
//
return result;
}
/**
* Detect Guards bsed on Signalling Class ...
*
* @param guards: XCAEAGuard instance Collection, Holds Provided Guards ...
* @param positions: XPosition instance Collection, Provides Signalling Based Positions for Apply Guards on them ...
* @param provider: X121SMCStrategySignalProviderData instance Reference, Specified Data for Cycles ...
*
* @return ( bool )
*/
bool DetectGuards(
XGuard &guards[],
const XPosition &positions[],
int barIndex = 0 //
)
{
//
bool result = false;
//
// Normalize Args ...
barIndex = NormalizeInt(barIndex, 0);
//
// TODO: Implement this ...
//
// Cleanup Resources ...
//
return result;
}
//
// Protected ...
protected:
//
/**
* Initialize ...
*/
void Init(XCATBEASignallerInputs &inputs)
{
//
bool has = inputs.IsValid();
if (!has)
{
return;
}
//
symbol = inputs.symbol;
period = inputs.period;
provider = inputs.provider;
//
// Initialize Bar Tracker ...
has = barTraker.Init(
symbol,
period //
);
if (!has)
{
return;
}
//
// Initialize Bar Analyser ...
barAnalyser = new XCBarAnalyser();
//
// initialize Helper ...
has = helper.Init(
symbol,
period,
inputs.catbInputs //
);
if (!has)
{
return;
}
//
mConditions.Clean();
Clean(mConditionsCollection);
//
InitPOI();
}
/**
* DeInitialize ...
*/
void DeInit()
{
//
drawer.Clear();
delete drawer;
ZeroMemory(drawer);
//
detector.CleanPivots();
delete detector;
ZeroMemory(detector);
//
delete helper;
ZeroMemory(helper);
//
delete barAnalyser;
ZeroMemory(barAnalyser);
//
barTraker.Clean();
}
/**
* Add Conditions to Conditions Collection if not Exists ...
*
* @param maxAllowed: int, Specified Max Allowed Holding Conditions ...
*
* @return ( int )
*/
int AddConditionsIfNotExists(
int maxAllowed = 10 //
)
{
//
int result = 0;
//
bool isSetuped = IsValid(mConditions.setupTime) &&
HasDirection(mConditions.dir);
if (!isSetuped)
{
return result;
}
//
int count = ArraySize(mConditionsCollection);
if (IsValidSize(count))
{
//
// Copy Original Items ...
XCATBEAStrategyConditions tmpItems[];
Copy(
mConditionsCollection,
tmpItems //
);
//
// Prese Item Data ...
bool isBullish = IsBullish(mConditions.dir);
//
for (int i = 0; i < count; i++)
{
//
XCATBEAStrategyConditions iItem = tmpItems[i];
//
bool canRemove = mConditions.dir == iItem.dir &&
mConditions.pivot == iItem.pivot;
if (canRemove)
{
//
ArrayRemove(
mConditionsCollection,
i,
1 //
);
}
}
//
Clean(tmpItems);
}
//
AddRef(
mConditions,
mConditionsCollection //
);
//
// Remove Olds ...
CleanupArray(
mConditionsCollection,
maxAllowed //
);
//
result = ArraySize(mConditionsCollection);
//
return result;
}
//
// Private ...
private:
//
// Props ...
string symbol;
string provider;
ENUM_TIMEFRAMES period;
//
// Initialize and Configure POI Detector and Drawer ...
void InitPOI()
{
//
// Initialize POI Detector ...
bool has = helper != NULL;
if (has)
{
//
detector = new XCXCATBEAPOIDetector(helper);
//
// Configure ...
}
//
// Initialize POI Drawer ...
has = detector != NULL;
if (has)
{
//
drawer = new XCXCATBEAPOIDrawer(detector);
//
// Configure ...
}
}
//
};