This commit is contained in:
2024-10-31 00:30:14 +03:30
parent 36f47d9f4f
commit d4dc005365
2 changed files with 476 additions and 363 deletions
+409 -361
View File
@@ -357,6 +357,10 @@ class XCX121SMCStrategy : public XSCBaseAlert
//
// Update POIs ...
//
ENUM_XPOI_EVENTS _1DStates[];
m1DPOI.Update(_1DStates);
//
ENUM_XPOI_EVENTS _4HStates[];
m4HPOI.Update(_4HStates);
@@ -373,6 +377,10 @@ class XCX121SMCStrategy : public XSCBaseAlert
ENUM_XPOI_EVENTS _5MStates[];
m5MPOI.Update(_5MStates);
//
ENUM_XPOI_EVENTS _1MStates[];
m1MPOI.Update(_1MStates);
//
// Check Current Processing Tick has Signal or not ...
XSignal signal;
@@ -492,6 +500,11 @@ class XCX121SMCStrategy : public XSCBaseAlert
//
// Reading POI(s) ...
//
// 1D ...
XPOIState _1DState;
m1DPOI.GetState(_1DState);
//
XPOIState _4HSupDemState;
m4HSupDemPOI.GetState(_4HSupDemState);
@@ -511,6 +524,11 @@ class XCX121SMCStrategy : public XSCBaseAlert
XPOIState _5MState;
m5MPOI.GetState(_5MState);
//
// 1M ...
XPOIState _1MState;
m1MPOI.GetState(_1MState);
//
// Try to Implement SMC Based Conditions ...
@@ -687,73 +705,7 @@ class XCX121SMCStrategy : public XSCBaseAlert
// Props ...
//
// Private ...
private:
//
// Props ...
//
string mSymbol; // Trading Symbol ...
ENUM_TIMEFRAMES mPeriod; // Trading TimeFrame ...
bool mForceDisabled; // Force Disabled ...
bool mAllowLong; // Allow Long Signals
bool mAllowShort; // Allow Short Signals
double mR2R; // Risk/Rewar Ratio ...
double mVolume; // Static Volume Per Trades ...
double mMaxAllowedSpread; // Max Allowed Spread ...
//
XTick mTicks[]; // Hold Ticks Data ...
MqlTick mLastTick; // Last Issued Tick ...
/**
* Cleanup Ticks Size ...
*/
void CleanupTicks()
{
//
int maxRequiredTicks = 50;
int ticksCount = ArraySize(mTicks);
if (!IsValidSize(ticksCount) ||
ticksCount <= maxRequiredTicks)
{
return;
}
//
int removeCount = ticksCount - maxRequiredTicks;
if (!IsValidSize(removeCount))
{
return;
}
//
ArrayRemove(
mTicks,
0,
removeCount //
);
}
/**
* Add new Tick Data to Collection ...
*/
void SaveTickData()
{
//
XTick tick;
bool isInited = tick.Init(mSymbol);
if (!isInited)
{
return;
}
//
AddRef(
tick,
mTicks //
);
}
// Actions ...
/**
* Check Spread Passed for Positions...
@@ -818,41 +770,6 @@ class XCX121SMCStrategy : public XSCBaseAlert
return result;
}
/**
* Calculate Ticks Param for Looping through Last n items ...
*
* @param start: Integer Reference to Start ...
* @param end: Integer Reference to End ...
* @param numOfLastTicks: Integer Max Number of Required N Last Ticks ...
*/
void CalculateTicksParams(
int &start,
int &end,
int numOfLastTicks = 5 //
)
{
//
start = -1;
end = -1;
//
int count = ArraySize(mTicks);
//
start = count - numOfLastTicks;
if (start < 0)
{
start = 0;
}
//
end = start + numOfLastTicks;
if (end > count)
{
end = count;
}
}
/**
* Check Ticks is Bullish or not ...
*
@@ -992,257 +909,6 @@ class XCX121SMCStrategy : public XSCBaseAlert
return result;
}
//
XBarTracker mBarTracker; // Strategy Time Tracker ...
//
// Point Of Interests ...
XCPOI *m4HPOI;
XCPOI *m4HSupDemPOI;
XCPOI *m15MPOI;
XCPOI *m5MPOI;
//
// Collect all Drawn Objects ...
CArrayObj mDrawnObjects;
/**
* Clear all Drawn Objects ...
*/
void ClearDraws()
{
mDrawnObjects.Clear();
}
/**
* Remove Specified Drawn Object ...
*
* @param name: Object name ...
*/
void RemoveObject(string name)
{
//
if (!IsValid(name))
{
return;
}
//
int count = mDrawnObjects.Total();
if (!IsValidSize(count))
{
return;
}
//
int idx = -1;
for (int i = 0; i < count; i++)
{
//
string iName = ((CChartObject *)mDrawnObjects.At(i)).Name();
string iObjName = NULL;
if (!IsValid(iName))
{
iObjName = ((XCBaseObject *)mDrawnObjects.At(i)).ObjName();
}
//
if ((IsValid(iName) &&
iName == name) ||
(IsValid(iObjName) &&
iObjName == name))
{
//
idx = i;
break;
}
}
//
if (IsValidIndex(idx))
{
mDrawnObjects.Delete(idx);
}
}
//
XOHCL mSwingHigh;
CChartObjectHLine *mSwingHighObject;
//
XOHCL mSwingLow;
CChartObjectHLine *mSwingLowObject;
//
// Holding Supply and Demand Zones ...
// XZone mSupplyZones[];
// XZone mDemandZones[];
//
// XZone mBearishOrderBlocks[];
// XZone mBullishOrderBlocks[];
//
// XZone mBearishFVGs[];
// XZone mBullishFVGs[];
//
X121SMCStrategyConditions mConditions[];
//
// Actions ...
/**
* Install all Helpers and Prepare all Configurations for required Indicators ...
*/
void Init()
{
//
mForceDisabled = false;
//
R2R(2);
Volume(0.01);
//
ChartIdentification(0);
SubWindowIdentification(0);
//
// Configure POI Drawer if Required ...
mPOIDrawer = new XCPOIDrawer();
mPOIDrawer.ChartIdentification(0);
mPOIDrawer.SubWindowIdentification(0);
//
mPOIDrawer.DemandZoneFill(false);
mPOIDrawer.SupplyZoneFill(false);
mPOIDrawer.BullishFVGFill(false);
mPOIDrawer.BearishFVGFill(false);
mPOIDrawer.SupportZoneFill(false);
mPOIDrawer.ResistanceZoneFill(false);
mPOIDrawer.BullishOrderBlockFill(false);
mPOIDrawer.BearishOrderBlockFill(false);
//
string symbol = Symbol();
ENUM_TIMEFRAMES period = Period();
//
// Initialize Bar Tracker ...
mBarTracker.Init(
symbol,
period //
);
//
// Initialize POIs ...
//
// this used only for Supply and
// Demand Zone for H4 Time Frame ..,
// POI Detector ...
m4HSupDemPOI = new XCPOI(
symbol,
PERIOD_M15 //
);
m4HSupDemPOI.DisablePOIs();
m4HSupDemPOI.DisableDrawPOIs();
m4HSupDemPOI.AllowSupplyZones(true);
m4HSupDemPOI.AllowDemandZones(true);
m4HSupDemPOI.SupplyZonePeriod(PERIOD_H4);
m4HSupDemPOI.DemandZonePeriod(PERIOD_H4);
m4HSupDemPOI.SubWindowIdentification(0);
m4HSupDemPOI.ChartIdentification(ChartID());
//
m4HSupDemPOI.Init();
//
// 4H Period ...
// POI Detector ...
m4HPOI = new XCPOI(
symbol,
PERIOD_H4 //
);
//
m4HPOI.DisableDrawPOIs();
m4HPOI.SupplyZonePeriod(PERIOD_H4);
m4HPOI.DemandZonePeriod(PERIOD_H4);
m4HPOI.SubWindowIdentification(0);
m4HPOI.ChartIdentification(ChartID());
//
m4HPOI.Init();
//
// 15M Period ...
// POI Detector ...
m15MPOI = new XCPOI(
symbol,
PERIOD_M15 //
);
//
m15MPOI.DisableDrawPOIs();
m15MPOI.MaxNumberOfRequiredPOIs(2);
m15MPOI.SupplyZonePeriod(PERIOD_M15);
m15MPOI.DemandZonePeriod(PERIOD_M15);
m15MPOI.SubWindowIdentification(0);
m15MPOI.ChartIdentification(ChartID());
//
m15MPOI.Init();
//
// Trigger Period ...
// POI Detector ...
m5MPOI = new XCPOI(
symbol,
PERIOD_M5 //
);
//
m5MPOI.DisableDrawPOIs();
m5MPOI.MaxNumberOfRequiredPOIs(2);
m5MPOI.SupplyZonePeriod(PERIOD_M5);
m5MPOI.DemandZonePeriod(PERIOD_M5);
m5MPOI.SubWindowIdentification(0);
m5MPOI.ChartIdentification(ChartID());
//
m5MPOI.Init();
//
}
/**
* De Initialize all Tools ...
*/
void DeInit()
{
//
delete m4HPOI;
delete m5MPOI;
delete m15MPOI;
delete m4HSupDemPOI;
//
delete mPOIDrawer;
//
ClearDraws();
}
/**
* Reste Bar Tracker ...
*/
void ResetBarTracker()
{
mBarTracker.Clean();
}
/**
* Prepare and Normalize Signal for Execution in Strategy ...
*
@@ -1880,10 +1546,6 @@ class XCX121SMCStrategy : public XSCBaseAlert
return result;
}
//
// On X121 Signal Recieved Event Handler(s) ...
TOnX121SMCSignal mSignalEventHandlers[];
//
/**
* Notified Signal Event Handler(s) ...
@@ -1923,10 +1585,64 @@ class XCX121SMCStrategy : public XSCBaseAlert
//
// Draw Functions ...
//
long mChartID; // Chart ID ...
int mSubWindow; // Sub Window ID ...
XCPOIDrawer *mPOIDrawer; // POI Drawer Class ...
/**
* Clear all Drawn Objects ...
*/
void ClearDraws()
{
mDrawnObjects.Clear();
}
/**
* Remove Specified Drawn Object ...
*
* @param name: Object name ...
*/
void RemoveObject(string name)
{
//
if (!IsValid(name))
{
return;
}
//
int count = mDrawnObjects.Total();
if (!IsValidSize(count))
{
return;
}
//
int idx = -1;
for (int i = 0; i < count; i++)
{
//
string iName = ((CChartObject *)mDrawnObjects.At(i)).Name();
string iObjName = NULL;
if (!IsValid(iName))
{
iObjName = ((XCBaseObject *)mDrawnObjects.At(i)).ObjName();
}
//
if ((IsValid(iName) &&
iName == name) ||
(IsValid(iObjName) &&
iObjName == name))
{
//
idx = i;
break;
}
}
//
if (IsValidIndex(idx))
{
mDrawnObjects.Delete(idx);
}
}
/**
* Draw Specific Condition ...
@@ -2353,6 +2069,338 @@ class XCX121SMCStrategy : public XSCBaseAlert
mDrawnObjects.Add(iObj);
}
//
// Private ...
private:
//
// Props ...
//
string mSymbol; // Trading Symbol ...
ENUM_TIMEFRAMES mPeriod; // Trading TimeFrame ...
bool mForceDisabled; // Force Disabled ...
bool mAllowLong; // Allow Long Signals
bool mAllowShort; // Allow Short Signals
double mR2R; // Risk/Rewar Ratio ...
double mVolume; // Static Volume Per Trades ...
double mMaxAllowedSpread; // Max Allowed Spread ...
//
long mChartID; // Chart ID ...
int mSubWindow; // Sub Window ID ...
XCPOIDrawer *mPOIDrawer; // POI Drawer Class ...
//
XTick mTicks[]; // Hold Ticks Data ...
MqlTick mLastTick; // Last Issued Tick ...
//
XBarTracker mBarTracker; // Strategy Time Tracker ...
//
// Point Of Interests ...
XCPOI *m1DPOI;
XCPOI *m4HPOI;
XCPOI *m4HSupDemPOI;
XCPOI *m15MPOI;
XCPOI *m5MPOI;
XCPOI *m1MPOI;
//
// Collect all Drawn Objects ...
CArrayObj mDrawnObjects;
//
XOHCL mSwingHigh;
CChartObjectHLine *mSwingHighObject;
//
XOHCL mSwingLow;
CChartObjectHLine *mSwingLowObject;
//
X121SMCStrategyConditions mConditions[];
//
// On X121 Signal Recieved Event Handler(s) ...
TOnX121SMCSignal mSignalEventHandlers[];
//
// Actions ...
/**
* Install all Helpers and Prepare all Configurations for required Indicators ...
*/
void Init()
{
//
mForceDisabled = false;
//
R2R(2);
Volume(0.01);
//
ChartIdentification(0);
SubWindowIdentification(0);
//
// Configure POI Drawer if Required ...
mPOIDrawer = new XCPOIDrawer();
mPOIDrawer.ChartIdentification(0);
mPOIDrawer.SubWindowIdentification(0);
//
mPOIDrawer.DemandZoneFill(false);
mPOIDrawer.SupplyZoneFill(false);
mPOIDrawer.BullishFVGFill(false);
mPOIDrawer.BearishFVGFill(false);
mPOIDrawer.SupportZoneFill(false);
mPOIDrawer.ResistanceZoneFill(false);
mPOIDrawer.BullishOrderBlockFill(false);
mPOIDrawer.BearishOrderBlockFill(false);
//
string symbol = Symbol();
ENUM_TIMEFRAMES period = Period();
//
// Initialize Bar Tracker ...
mBarTracker.Init(
symbol,
period //
);
//
// Initialize POIs ...
//
// 1D Period ...
// POI Detector ...
m1DPOI = new XCPOI(
symbol,
PERIOD_D1 //
);
//
m1DPOI.DisableDrawPOIs();
m1DPOI.SupplyZonePeriod(PERIOD_W1);
m1DPOI.DemandZonePeriod(PERIOD_W1);
m1DPOI.SubWindowIdentification(0);
m1DPOI.ChartIdentification(ChartID());
//
m1DPOI.Init();
//
// this used only for Supply and
// Demand Zone for H4 Time Frame ..,
// POI Detector ...
m4HSupDemPOI = new XCPOI(
symbol,
PERIOD_M15 //
);
m4HSupDemPOI.DisablePOIs();
m4HSupDemPOI.DisableDrawPOIs();
m4HSupDemPOI.AllowSupplyZones(true);
m4HSupDemPOI.AllowDemandZones(true);
m4HSupDemPOI.SupplyZonePeriod(PERIOD_H4);
m4HSupDemPOI.DemandZonePeriod(PERIOD_H4);
m4HSupDemPOI.SubWindowIdentification(0);
m4HSupDemPOI.ChartIdentification(ChartID());
//
m4HSupDemPOI.Init();
//
// 4H Period ...
// POI Detector ...
m4HPOI = new XCPOI(
symbol,
PERIOD_H4 //
);
//
m4HPOI.DisableDrawPOIs();
m4HPOI.SupplyZonePeriod(PERIOD_H4);
m4HPOI.DemandZonePeriod(PERIOD_H4);
m4HPOI.SubWindowIdentification(0);
m4HPOI.ChartIdentification(ChartID());
//
m4HPOI.Init();
//
// 15M Period ...
// POI Detector ...
m15MPOI = new XCPOI(
symbol,
PERIOD_M15 //
);
//
m15MPOI.DisableDrawPOIs();
m15MPOI.MaxNumberOfRequiredPOIs(2);
m15MPOI.SupplyZonePeriod(PERIOD_H4);
m15MPOI.DemandZonePeriod(PERIOD_H4);
m15MPOI.SubWindowIdentification(0);
m15MPOI.ChartIdentification(ChartID());
//
m15MPOI.Init();
//
// Trigger Period ...
// POI Detector ...
m5MPOI = new XCPOI(
symbol,
PERIOD_M5 //
);
//
m5MPOI.DisableDrawPOIs();
m5MPOI.MaxNumberOfRequiredPOIs(2);
m5MPOI.SupplyZonePeriod(PERIOD_M15);
m5MPOI.DemandZonePeriod(PERIOD_M15);
m5MPOI.SubWindowIdentification(0);
m5MPOI.ChartIdentification(ChartID());
//
m5MPOI.Init();
//
// 1M Period ...
// POI Detector ...
m1MPOI = new XCPOI(
symbol,
PERIOD_M1 //
);
//
m1MPOI.DisableDrawPOIs();
m1MPOI.SupplyZonePeriod(PERIOD_M5);
m1MPOI.DemandZonePeriod(PERIOD_M5);
m1MPOI.SubWindowIdentification(0);
m1MPOI.ChartIdentification(ChartID());
//
m1MPOI.Init();
//
}
/**
* De Initialize all Tools ...
*/
void DeInit()
{
//
delete m1DPOI;
delete m4HPOI;
delete m5MPOI;
delete m1MPOI;
delete m15MPOI;
delete m4HSupDemPOI;
//
delete mPOIDrawer;
//
ClearDraws();
}
/**
* Reste Bar Tracker ...
*/
void ResetBarTracker()
{
mBarTracker.Clean();
}
/**
* Cleanup Ticks Size ...
*/
void CleanupTicks()
{
//
int maxRequiredTicks = 50;
int ticksCount = ArraySize(mTicks);
if (!IsValidSize(ticksCount) ||
ticksCount <= maxRequiredTicks)
{
return;
}
//
int removeCount = ticksCount - maxRequiredTicks;
if (!IsValidSize(removeCount))
{
return;
}
//
ArrayRemove(
mTicks,
0,
removeCount //
);
}
/**
* Add new Tick Data to Collection ...
*/
void SaveTickData()
{
//
XTick tick;
bool isInited = tick.Init(mSymbol);
if (!isInited)
{
return;
}
//
AddRef(
tick,
mTicks //
);
}
/**
* Calculate Ticks Param for Looping through Last n items ...
*
* @param start: Integer Reference to Start ...
* @param end: Integer Reference to End ...
* @param numOfLastTicks: Integer Max Number of Required N Last Ticks ...
*/
void CalculateTicksParams(
int &start,
int &end,
int numOfLastTicks = 5 //
)
{
//
start = -1;
end = -1;
//
int count = ArraySize(mTicks);
//
start = count - numOfLastTicks;
if (start < 0)
{
start = 0;
}
//
end = start + numOfLastTicks;
if (end > count)
{
end = count;
}
}
//
};