Fix all Refactors issues on X121SMC for start Implementing Strategy ...

This commit is contained in:
2024-11-15 10:36:57 +03:30
parent b921b45eb2
commit 801b37806e
15 changed files with 1584 additions and 151 deletions
+342
View File
@@ -449,6 +449,348 @@ class XCBarAnalyser : public XCBase
return result;
}
/**
* Check Bar Has Bullish Trend or not ...
*
* @param bar: XOHCL instance ...
* @param forceAll: Boolean ...
*
* @return ( bool )
*/
bool HasBullishTrend(
XOHCL &bar,
bool forceAll = false //
)
{
//
bool result = false;
//
result = bar.IsValid();
if (!result)
{
return result;
}
//
XOHCL tmpHSW[];
XOHCL tmpLSW[];
//
bool trend1 = bar.HasBullishTrend(
tmpHSW,
tmpLSW,
true //
);
//
bool trend2 = bar.HasBullishTrend(
tmpHSW,
tmpLSW,
false //
);
//
if (!forceAll)
{
//
result = trend1;
if (!result)
{
return result;
}
}
//
result =
trend1 ||
trend2;
//
return result;
}
/**
* Check Bar Has Bearish Trend or not ...
*
* @param bar: XOHCL instance ...
* @param forceAll: Boolean ...
*
* @return ( bool )
*/
bool HasBearishTrend(
XOHCL &bar,
bool forceAll = false //
)
{
//
bool result = false;
//
result = bar.IsValid();
if (!result)
{
return result;
}
//
XOHCL tmpHSW[];
XOHCL tmpLSW[];
//
bool trend1 = bar.HasBearishTrend(
tmpHSW,
tmpLSW,
true //
);
//
bool trend2 = bar.HasBearishTrend(
tmpHSW,
tmpLSW,
false //
);
//
if (!forceAll)
{
//
result = trend1;
if (!result)
{
return result;
}
}
//
result =
trend1 ||
trend2;
//
return result;
}
/**
* Check Specified Bar Has Bullish Pattern or not ...
*
* @param bar: XOHCL instance, Specified Bar ...
* @param loopback: Integer, Loopback Length for Patterns ...
* @param verifications: Integer, Number of Given Verifications ...
* @param checkHammer: Boolean, Specified Check Hammer Pattern ...
* @param checkMorningStar: Boolean, Specified Check Morning Star Pattern ...
* @param checkBullishMarubozu: Boolean, Specified Check Marubozu Pattern ...
* @param checkBullishEngulfing: Boolean, Specified Check Engulfing Pattern ...
*
* @return ( bool )
*/
bool HasBullishPattern(
XOHCL &bar,
int loopback = 0,
int verifications = 1,
bool checkHammer = true,
bool checkMorningStar = true,
bool checkBullishMarubozu = true,
bool checkBullishEngulfing = true //
)
{
//
bool result = false;
//
result = bar.IsValid();
if (!result)
{
return result;
}
//
if (verifications <= 0)
{
verifications = 1;
}
//
int founded = 0;
//
int idx = bar.Index();
for (int i = idx; i <= idx + loopback; i++)
{
//
XOHCL iBar;
result = iBar.Init(
bar.symbol,
bar.period,
i //
);
if (!result)
{
break;
}
//
bool isHammer =
!checkHammer
? false
: iBar.IsHammer();
if (isHammer)
{
founded++;
}
//
bool isMorningStar =
!checkMorningStar
? false
: iBar.IsMorningStar();
if (isMorningStar)
{
founded++;
}
//
bool isBullishMarubozu =
!checkBullishMarubozu
? false
: iBar.IsBullishMarubozu();
if (isBullishMarubozu)
{
founded++;
}
//
bool isBullishEngulfing =
!checkBullishEngulfing
? false
: iBar.IsBullishEngulfing();
if (isBullishEngulfing)
{
founded++;
}
//
}
//
result =
result &&
founded >= verifications;
//
return result;
}
/**
* Check Specified Bar Has Bearish Pattern or not ...
*
* @param bar: XOHCL instance, Specified Bar ...
* @param loopback: Integer, Loopback Length for Patterns ...
* @param verifications: Integer, Number of Given Verifications ...
* @param checkShootingStar: Boolean, Specified Check Shooting Star Pattern ...
* @param checkEveningStar: Boolean, Specified Check Evening Star Pattern ...
* @param checkBearishMarubozu: Boolean, Specified Check Marubozu Pattern ...
* @param checkBearishEngulfing: Boolean, Specified Check Engulfing Pattern ...
*
* @return ( bool )
*/
bool HasBearishPattern(
XOHCL &bar,
int loopback = 0,
int verifications = 1,
bool checkShootingStar = true,
bool checkEveningStar = true,
bool checkBearishMarubozu = true,
bool checkBearishEngulfing = true //
)
{
//
bool result = false;
//
result = bar.IsValid();
if (!result)
{
return result;
}
//
if (verifications <= 0)
{
verifications = 1;
}
//
int founded = 0;
//
int idx = bar.Index();
for (int i = idx - 1; i <= idx + loopback; i++)
{
//
XOHCL iBar;
result = iBar.Init(
bar.symbol,
bar.period,
i //
);
if (!result)
{
break;
}
//
bool isShootingStar =
!checkShootingStar
? false
: iBar.IsShootingStar();
if (isShootingStar)
{
founded++;
}
//
bool isEveningStar =
!checkEveningStar
? false
: iBar.IsEveningStar();
if (isEveningStar)
{
founded++;
}
//
bool isBearishMarubozu =
!checkBearishMarubozu
? false
: iBar.IsBearishMarubozu();
if (isBearishMarubozu)
{
founded++;
}
//
bool isBearishEngulfing =
!checkBearishEngulfing
? false
: iBar.IsBearishEngulfing();
if (isBearishEngulfing)
{
founded++;
}
//
}
//
result =
result &&
founded >= verifications;
//
return result;
}
//
// Commons ...
+266 -2
View File
@@ -1534,6 +1534,269 @@ class XCBearishFairValueGapObject : public XCZoneObject
return X_BEARISH_FVG_OBJ;
}
};
//
// Signal ...
class XCSignalObject : public XCBaseObject
{
//
public:
//
//
// Constructor ...
void XCSignalObject()
{
}
//
// Deconstructor ...
void ~XCSignalObject()
{
}
/**
* Create a Signal Object on Chart ...
*
* @param chart_id: Long ...
* @param name: String ...
* @param window: Integer ...
* @param signal: XSignal instance ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
const string name,
const int window,
XSignal &signal //
)
{
//
bool result = false;
//
result = IsValid(name) &&
signal
.IsValid();
if (!result)
{
return result;
}
//
string nameMD5 = ToMD5(name);
//
int delay = (PeriodSeconds(signal.period) * 2);
datetime time1 = (datetime)((int)signal.time - delay);
datetime time2 = (datetime)((int)signal.time + delay);
//
// TP ...
string tpName = ToString(X_TP) + "_" + nameMD5;
result = mTPTrend.Create(
chart_id,
tpName,
window,
time1,
signal.tp,
time2,
signal.tp //
);
if (!result)
{
return result;
}
//
// SL ...
string slName = ToString(X_SL) + "_" + nameMD5;
result = mSLTrend.Create(
chart_id,
slName,
window,
time1,
signal.sl,
time2,
signal.sl //
);
if (!result)
{
//
mTPTrend.Delete();
return result;
}
//
// ENTRY ...
string entrName = ToString(X_ENTRY) + "_" + nameMD5;
result = mEntryTrend.Create(
chart_id,
entrName,
window,
time1,
signal.entry,
time2,
signal.entry //
);
if (!result)
{
//
mTPTrend.Delete();
mSLTrend.Delete();
return result;
}
//
// Set Object Name ...
ObjName(name);
//
return result;
}
//
// Setter(s) ...
//
// TP ...
/**
* Set TP Width ...
*
* @param value: Integer ...
*/
void TPWidth(int value)
{
//
if (value < 1)
{
value = 1;
}
//
mTPTrend.Width(value);
}
/**
* Set TP Color ...
*
* @param value: Color ...
*/
void TPColor(color value)
{
mTPTrend.Color(value);
}
/**
* Set TP Style ...
*
* @param value: ENUM_LINE_STYLE ...
*/
void TPStyle(ENUM_LINE_STYLE value)
{
mTPTrend.Style(value);
}
//
// SL ...
/**
* Set SL Width ...
*
* @param value: Integer ...
*/
void SLWidth(int value)
{
//
if (value < 1)
{
value = 1;
}
//
mSLTrend.Width(value);
}
/**
* Set SL Color ...
*
* @param value: Color ...
*/
void SLColor(color value)
{
mSLTrend.Color(value);
}
/**
* Set SL Style ...
*
* @param value: ENUM_LINE_STYLE ...
*/
void SLStyle(ENUM_LINE_STYLE value)
{
mSLTrend.Style(value);
}
//
// ENTRY ...
/**
* Set Entry Width ...
*
* @param value: Integer ...
*/
void EntryWidth(int value)
{
//
if (value < 1)
{
value = 1;
}
//
mEntryTrend.Width(value);
}
/**
* Set Entry Color ...
*
* @param value: Color ...
*/
void EntryColor(color value)
{
mEntryTrend.Color(value);
}
/**
* Set Entry Style ...
*
* @param value: ENUM_LINE_STYLE ...
*/
void EntryStyle(ENUM_LINE_STYLE value)
{
mEntryTrend.Style(value);
}
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_SIGNAL_OBJ;
}
//
private:
//
//
CChartObjectTrend mTPTrend;
CChartObjectTrend mSLTrend;
CChartObjectTrend mEntryTrend;
};
//
// Zone Ticks ...
@@ -1844,8 +2107,9 @@ class XCTicksZoneObject : public XCBaseObject
//
// Actions ...
void Destroy() {
void Destroy()
{
mZones.Clear();
}
+94 -9
View File
@@ -1068,10 +1068,95 @@ class XCPOIDetector : public XCBaseAlert
//
state.symbol = mSymbol;
state.period = mPeriod;
state.reportedAt = TimeCurrent();
state.time = TimeCurrent();
//
// TODO: Fill State ...
Copy(
mSwingHighs,
state.swingHighs //
);
//
Copy(
mSwingLows,
state.swingLows //
);
//
Copy(
mBullishMomentumBars,
state.bullishMomentumBars //
);
//
Copy(
mBearishMomentumBars,
state.bearishMomentumBars //
);
//
Copy(
mBullishRejectionBars,
state.bullishRejectionBars //
);
//
Copy(
mBearishRejectionBars,
state.bearishRejectionBars //
);
//
Copy(
mSupportZones,
state.supportZones //
);
//
Copy(
mResistanceZones,
state.resistanceZones //
);
//
Copy(
mSupplyZones,
state.supplyZones //
);
//
Copy(
mDemandZones,
state.demandZones //
);
//
Copy(
mBullishOrderBlocks,
state.bullishOrderBlocks //
);
//
Copy(
mBearishOrderBlocks,
state.bearishOrderBlocks //
);
//
Copy(
mBullishFairValueGaps,
state.bullishFairValueGaps //
);
//
Copy(
mBearishFairValueGaps,
state.bearishFairValueGaps //
);
//
state.ticksZone = mTicksZone;
//
}
//
@@ -2993,7 +3078,7 @@ class XCPOIDetector : public XCBaseAlert
//
// Supply Zone(s) ...
XCSupplyZone *mSupplyZones[];
XCSupplyZone *mSupplyZones[]; // Holds Founded Supply Zones ...
/**
* Detect Supply Zone ...
@@ -3162,7 +3247,7 @@ class XCPOIDetector : public XCBaseAlert
//
// Demand Zone(s) ...
XCDemandZone *mDemandZones[];
XCDemandZone *mDemandZones[]; // Holds Founded Demand Zones ...
/**
* Detect Demand Zone ...
@@ -3335,7 +3420,7 @@ class XCPOIDetector : public XCBaseAlert
//
// Bullish OB ...
XCOrderBlock *mBullishOrderBlocks[];
XCOrderBlock *mBullishOrderBlocks[]; // Holds Founded Bullish Order Blocks ...
/**
* Detect Bullish Order Block ...
@@ -3493,7 +3578,7 @@ class XCPOIDetector : public XCBaseAlert
//
// Bearish OB ...
XCOrderBlock *mBearishOrderBlocks[];
XCOrderBlock *mBearishOrderBlocks[]; // Holds Founded Bearish Order Blocks ...
/**
* Detect Bearish Order Block ...
@@ -3655,7 +3740,7 @@ class XCPOIDetector : public XCBaseAlert
//
// Bullish FVG ...
XCFVG *mBullishFairValueGaps[];
XCFVG *mBullishFairValueGaps[]; // Holds Founded Bullish Fair Value Gaps ...
/**
* Detect Bullish Fair Value Gap ...
@@ -3816,7 +3901,7 @@ class XCPOIDetector : public XCBaseAlert
//
// Bearish FVG ...
XCFVG *mBearishFairValueGaps[];
XCFVG *mBearishFairValueGaps[]; // Holds Founded Bearish Fair Value Gaps ...
/**
* Detect Bearish Fair Value Gap ...
@@ -3981,7 +4066,7 @@ class XCPOIDetector : public XCBaseAlert
int mTicksRangeZoneRange; // Ticks Range Zone Loopback Period ...
//
XCTicksZone *mTicksZone; // Ticks Zone ...
XCTicksZone *mTicksZone; // Ticks Zone ...
// XCTicksZoneObject *mTicksZoneObject; // Ticks Zone Object ...
/**
+1 -1
View File
@@ -23,7 +23,7 @@
//
// Imports ...
#include "../X121SMCEA/Experts/x-121.poi.expert.class.mq5"
#include "../X121SMCEA/Experts/x-121.smc.expert.class.mq5"
//
// Inputs ...
+5 -5
View File
@@ -22,7 +22,7 @@
//
// Imports ...
#include "../Classes/x-saherelm.xhelper.class.mq5"
#include "../Classes/x-saherelm.x-helper.class.mq5"
//
// Definitions ...
@@ -299,7 +299,7 @@ struct X3MAConditions
//
// Class ...
class XSCX3MAHelper : public XSCBaseHelper
class XCX3MAHelper : public XCBaseHelper
{
//
// Public ...
@@ -309,14 +309,14 @@ class XSCX3MAHelper : public XSCBaseHelper
//
// Constructors ...
XSCX3MAHelper()
: XSCBaseHelper(_Symbol, _Period)
XCX3MAHelper()
: XCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XSCX3MAHelper()
~XCX3MAHelper()
{
//
Clean(fastBuffer);
+5 -5
View File
@@ -22,7 +22,7 @@
//
// Imports ...
#include "../Classes/x-saherelm.xhelper.class.mq5"
#include "../Classes/x-saherelm.x-helper.class.mq5"
//
// Definitions ...
@@ -356,7 +356,7 @@ struct X3VWAPConditions
//
// Class ...
class XSCX3VWAPHelper : public XSCBaseHelper
class XCX3VWAPHelper : public XCBaseHelper
{
//
// Public ...
@@ -366,14 +366,14 @@ class XSCX3VWAPHelper : public XSCBaseHelper
//
// Constructors ...
XSCX3VWAPHelper()
: XSCBaseHelper(_Symbol, _Period)
XCX3VWAPHelper()
: XCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XSCX3VWAPHelper()
~XCX3VWAPHelper()
{
//
Clean(fastBuffer);
+4 -4
View File
@@ -22,7 +22,7 @@
//
// Imports ...
#include "../Classes/x-saherelm.xhelper.class.mq5"
#include "../Classes/x-saherelm.x-helper.class.mq5"
//
// Definitions ...
@@ -948,7 +948,7 @@ struct XPVConditions
//
// Class ...
class XSCXPVHelper : public XSCBaseHelper
class XCXPVHelper : public XCBaseHelper
{
//
// Public ...
@@ -958,13 +958,13 @@ public:
//
// Constructors ...
XSCXPVHelper() : XSCBaseHelper(_Symbol, _Period)
XCXPVHelper() : XCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XSCXPVHelper()
~XCXPVHelper()
{
//
Clean(fib1Buffer);
+173 -2
View File
@@ -2934,9 +2934,26 @@ struct XPOIState
//
string symbol;
ENUM_TIMEFRAMES period;
datetime reportedAt;
datetime time;
//
XCTicksZone *ticksZone; // Ticks Zone ...
//
XCSwing *swingHighs[]; // Holds Founded Swing Highs ...
XCSwing *swingLows[]; // Holds Founded Swing Lows ...
XCMomentumBar *bullishMomentumBars[]; // Holds Founded Bullish Momentum Bars ...
XCMomentumBar *bearishMomentumBars[]; // Holds Founded Bearish Momentum Bars ...
XCRejectionBar *bullishRejectionBars[]; // Holds Founded Bullish Rejection Bars ...
XCRejectionBar *bearishRejectionBars[]; // Holds Founded Bearish Rejection Bars ...
XCSupportZone *supportZones[]; // Holds Founded Support Zones ...
XCResistanceZone *resistanceZones[]; // Holds Founded Resistance Zones ...
XCSupplyZone *supplyZones[]; // Holds Founded Supply Zones ...
XCDemandZone *demandZones[]; // Holds Founded Demand Zones ...
XCOrderBlock *bullishOrderBlocks[]; // Holds Founded Bullish Order Blocks ...
XCOrderBlock *bearishOrderBlocks[]; // Holds Founded Bearish Order Blocks ...
XCFVG *bullishFairValueGaps[]; // Holds Founded Bullish Fair Value Gaps ...
XCFVG *bearishFairValueGaps[]; // Holds Founded Bearish Fair Value Gaps ...
//
// Constructor ...
@@ -2956,7 +2973,26 @@ struct XPOIState
//
symbol = NULL;
period = NULL;
reportedAt = NULL;
time = NULL;
//
ticksZone.Clean();
//
Clean(swingHighs);
Clean(swingLows);
Clean(bullishMomentumBars);
Clean(bearishMomentumBars);
Clean(bullishRejectionBars);
Clean(bearishRejectionBars);
Clean(supportZones);
Clean(resistanceZones);
Clean(supplyZones);
Clean(demandZones);
Clean(bullishOrderBlocks);
Clean(bearishOrderBlocks);
Clean(bullishFairValueGaps);
Clean(bearishFairValueGaps);
}
//
@@ -3215,6 +3251,141 @@ string ToString(ENUM_XPOI_EVENTS value)
return result;
}
/**
* Combine a Collection of States into dest ...
*
* @param dest: XPOIState instance ...
* @param source: XPOIState Collection ...
*/
void CombineStates(
XPOIState &dest,
XPOIState &source[] //
)
{
//
dest.Clean();
//
int count = ArraySize(source);
if (!IsValidSize(count))
{
return;
}
//
for (int i = 0; i < count; i++)
{
//
XPOIState iState = source[i];
//
if (dest.ticksZone == NULL)
{
dest.ticksZone = iState.ticksZone;
}
//
Copy(
iState.swingHighs,
dest.swingHighs,
false //
);
//
Copy(
iState.swingLows,
dest.swingLows,
false //
);
//
Copy(
iState.bullishMomentumBars,
dest.bullishMomentumBars,
false //
);
//
Copy(
iState.bearishMomentumBars,
dest.bearishMomentumBars,
false //
);
//
Copy(
iState.bullishRejectionBars,
dest.bullishRejectionBars,
false //
);
//
Copy(
iState.bearishRejectionBars,
dest.bearishRejectionBars,
false //
);
//
Copy(
iState.supportZones,
dest.supportZones,
false //
);
//
Copy(
iState.resistanceZones,
dest.resistanceZones,
false //
);
//
Copy(
iState.supplyZones,
dest.supplyZones,
false //
);
//
Copy(
iState.demandZones,
dest.demandZones,
false //
);
//
Copy(
iState.bullishOrderBlocks,
dest.bullishOrderBlocks,
false //
);
//
Copy(
iState.bearishOrderBlocks,
dest.bearishOrderBlocks,
false //
);
//
Copy(
iState.bullishFairValueGaps,
dest.bullishFairValueGaps,
false //
);
//
Copy(
iState.bearishFairValueGaps,
dest.bearishFairValueGaps,
false //
);
//
}
}
//
typedef void (*TOnPOIEvent)(ENUM_XPOI_EVENTS event,
XCBasePOI *param //
@@ -23,11 +23,11 @@
// Imports ...
//
#include "../../Classes/x-saherelm.x-alert.class.mq5"
#include "../../Classes/x-saherelm.x-bar.analyser.class.mq5"
#include "../../Classes/x-saherelm.x-poi.class.mq5"
#include "../../Classes/x-saherelm.xalert.class.mq5"
#include "../../Classes/x-saherelm.xtrade.class.mq5"
#include "../../Classes/z-saherelm.x-bar.analyser.class.mq5"
#include "../Classes/x-121.smc.chart.objects.class.mq5"
#include "../../Classes/x-saherelm.x-trade.class.mq5"
#include "../Classes/x-121.smc.cobjects.class.mq5"
#include "../Libraries/x-121.smc.lib.mq5"
//
@@ -35,7 +35,7 @@
//
// XStrategy Class Implementation(s) ...
class XCX121SMCBaseStrategy : public XSCBaseAlert
class XCX121SMCBaseStrategy : public XCBaseAlert
{
//
// Public ...
@@ -311,6 +311,13 @@ class XCX121SMCBaseStrategy : public XSCBaseAlert
//
// Virtual Actions ...
/**
* Destroy All Class Implementations ...
*/
virtual void Destroy()
{
}
/**
* Handle Tick Processing ...
*/
@@ -486,6 +493,23 @@ class XCX121SMCBaseStrategy : public XSCBaseAlert
return result;
}
/**
* Detect SL Candidates based on Strategy and Conditions ...
*
* @param result: Double array reference ...
* @param entry: Double, Position Entry Price ...
* @param conditions: X121SMCStrategyConditions instance, Provides Configurations ...
* @param type: ENUM_X_POSITION_TYPES member, Specified Position Type ...
*/
virtual void DetectSLCandidates(
double &result[],
double entry,
X121SMCStrategyConditions &conditions,
ENUM_X_POSITION_TYPES type //
)
{
}
/**
* Customize Strategy Identifier ...
*
@@ -506,13 +530,13 @@ class XCX121SMCBaseStrategy : public XSCBaseAlert
//
// Point Of Interests ...
XCPOI *m1DPOI;
XCPOI *m4HPOI;
XCPOI *m2HPOI;
XCPOI *m1HPOI;
XCPOI *m15MPOI;
XCPOI *m5MPOI;
XCPOI *m1MPOI;
XCPOIDetector *m1DPOI;
XCPOIDetector *m4HPOI;
XCPOIDetector *m2HPOI;
XCPOIDetector *m1HPOI;
XCPOIDetector *m15MPOI;
XCPOIDetector *m5MPOI;
XCPOIDetector *m1MPOI;
//
XPOIState _1DState;
@@ -1024,128 +1048,77 @@ class XCX121SMCBaseStrategy : public XSCBaseAlert
//
// 1D Period ...
// POI Detector ...
m1DPOI = new XCPOI(
m1DPOI = new XCPOIDetector(
symbol,
PERIOD_D1 //
);
//
m1DPOI.DisableDrawPOIs();
m1DPOI.SupplyZonePeriod(PERIOD_W1);
m1DPOI.DemandZonePeriod(PERIOD_W1);
m1DPOI.SubWindowIdentification(0);
m1DPOI.ChartIdentification(ChartID());
//
m1DPOI.Init();
//
// 4H Period ...
// POI Detector ...
m4HPOI = new XCPOI(
m4HPOI = new XCPOIDetector(
symbol,
PERIOD_H4 //
);
//
m4HPOI.DisableDrawPOIs();
m4HPOI.SupplyZonePeriod(PERIOD_D1);
m4HPOI.DemandZonePeriod(PERIOD_D1);
m4HPOI.SubWindowIdentification(0);
m4HPOI.ChartIdentification(ChartID());
//
m4HPOI.Init();
//
// 2H Period ...
// POI Detector ...
m2HPOI = new XCPOI(
m2HPOI = new XCPOIDetector(
symbol,
PERIOD_H2 //
);
//
m2HPOI.DisableDrawPOIs();
m2HPOI.SupplyZonePeriod(PERIOD_H12);
m2HPOI.DemandZonePeriod(PERIOD_H12);
m2HPOI.SubWindowIdentification(0);
m2HPOI.ChartIdentification(ChartID());
//
m2HPOI.Init();
//
// 1H Period ...
// POI Detector ...
m1HPOI = new XCPOI(
m1HPOI = new XCPOIDetector(
symbol,
PERIOD_H1 //
);
//
m1HPOI.DisableDrawPOIs();
m1HPOI.SupplyZonePeriod(PERIOD_H6);
m1HPOI.DemandZonePeriod(PERIOD_H6);
m1HPOI.SubWindowIdentification(0);
m1HPOI.ChartIdentification(ChartID());
//
m1HPOI.Init();
//
// 15M Period ...
// POI Detector ...
m15MPOI = new XCPOI(
m15MPOI = new XCPOIDetector(
symbol,
PERIOD_M15 //
);
//
m15MPOI.DisableDrawPOIs();
m15MPOI.MaxNumberOfRequiredPOIs(2);
m15MPOI.SupplyZonePeriod(PERIOD_H4);
m15MPOI.DemandZonePeriod(PERIOD_H4);
m15MPOI.SubWindowIdentification(0);
m15MPOI.ChartIdentification(ChartID());
//
m15MPOI.Init();
//
// 5M Period ...
// POI Detector ...
m5MPOI = new XCPOI(
m5MPOI = new XCPOIDetector(
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(
m1MPOI = new XCPOIDetector(
symbol,
PERIOD_M1 //
);
//
m1MPOI.DisableDrawPOIs();
m1MPOI.SupplyZonePeriod(PERIOD_M5);
m1MPOI.DemandZonePeriod(PERIOD_M5);
m1MPOI.SubWindowIdentification(0);
m1MPOI.ChartIdentification(ChartID());
//
m1MPOI.Init();
@@ -1168,7 +1141,7 @@ class XCX121SMCBaseStrategy : public XSCBaseAlert
delete mPOIDrawer;
//
// ClearDraws();
Destroy();
}
/**
@@ -24,6 +24,7 @@
//
#include "../../Classes/x-saherelm.x-alert.class.mq5"
#include "../../Classes/x-saherelm.x-bar.analyser.class.mq5"
#include "../../Classes/x-saherelm.x-trade.class.mq5"
//
@@ -1301,7 +1302,7 @@ class XC121SMCTradeHandler : public XCBaseAlert
return mMaxAllowedSLReachedPauseDelay;
}
//
//
void MaxAllowedSLReachedPauseDelay(int value)
{
//
@@ -2742,7 +2743,7 @@ class XC121SMCTradeHandler : public XCBaseAlert
// Protected ...
protected:
//
XCTrade *mTrader; // Instance of Trader Class
XCTrade *mTrader; // Instance of Trader Class
X121SMCTradeCollector *mCollector; // Instance of Trade Collector Class
//
@@ -3180,63 +3181,22 @@ class XC121SMCTradeHandler : public XCBaseAlert
//
// Common Conditions For Bullish and Bearish Powers ...
//
// For Trend ...
XOHCL tmpHSW[];
XOHCL tmpLSW[];
//
// Detect Bullish/Bearish Patterns and Trends ...
//
// Bullish ...
bool hasBullishPower = cBar.HasBullishPower();
bool hasBullishPattern = HasBullishPattern(cBar);
bool hasBullishPattern = mBarAnalyser.HasBullishPattern(cBar);
bool hasBullishPressure = cBar.HasBullishPressure();
bool isBullishTrend = cBar.HasBullishTrend(
tmpHSW,
tmpLSW,
true //
);
bool isBullishTrend1 = cBar.HasBullishTrend(
tmpHSW,
tmpLSW,
false //
);
bool hasBullishTrend =
//
isBullishTrend
//
||
//
isBullishTrend1
//
;
bool hasBullishTrend = mBarAnalyser.HasBullishTrend(cBar, true);
//
// Bearish ...
bool hasBearishPower = cBar.HasBearishPower();
bool hasBearishPattern = HasBearishPattern(cBar);
bool hasBearishPattern = mBarAnalyser.HasBearishPattern(cBar);
bool hasBearishPressure = cBar.HasBearishPressure();
bool isBearishTrend = cBar.HasBearishTrend(
tmpHSW,
tmpLSW,
true //
);
bool isBearishTrend1 = cBar.HasBearishTrend(
tmpHSW,
tmpLSW,
false //
);
bool hasBearishTrend =
//
isBearishTrend
//
||
//
isBearishTrend1
//
;
bool hasBearishTrend = mBarAnalyser.HasBearishTrend(cBar, true);
//
// Define Conditions ...
@@ -3810,6 +3770,7 @@ class XC121SMCTradeHandler : public XCBaseAlert
double mHedgeBEMinProfitPerVolumeStep; // Minimum Required Profit For BE Hedge Per Volume Step
//
XCBarAnalyser mBarAnalyser;
X121SMCSymbolPositionInfo mSymbolInfos[];
/**
+6 -5
View File
@@ -21,8 +21,9 @@
//
// Imports ...
#include "../../Classes/x-saherelm.xexpert.class.mq5"
#include "../Classes/x-121.smc.xtradehandler.class.mq5"
#include "../Libraries/x-121.smc.lib.mq5"
#include "../../Classes/x-saherelm.x-expert.class.mq5"
#include "../Classes/x-121.smc.x-tradehandler.class.mq5"
#include "../Strategy/x-121.smc.test.strategy.class.mq5"
//
@@ -400,7 +401,7 @@ class XC121SMCExpert : public XCBaseExpert
// Bar Timer ...
XCTInputs ctInputs;
ctInputs.Default(); // Default Configurations ...
mCTHelper = new XSCXCTHelper();
mCTHelper = new XCXCTHelper();
result = mCTHelper.Init(
GetSymbol(),
GetPeriod(),
@@ -415,7 +416,7 @@ class XC121SMCExpert : public XCBaseExpert
// Bar Styles ...
XCCInputs ccInputs;
ccInputs.Default(); // Default Configurations ...
mCCHelper = new XSCXCCHelper();
mCCHelper = new XCXCCHelper();
result = mCCHelper.Init(
GetSymbol(),
GetPeriod(),
@@ -428,7 +429,7 @@ class XC121SMCExpert : public XCBaseExpert
//
// Create Trader Instance and Configure it ...
mTrader = new XSCTrade(
mTrader = new XCTrade(
Slippage(),
MagicNumber() //
);
+229
View File
@@ -0,0 +1,229 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Common Library
// --------------------------------------
// Name: X121SMCLib
// Description: provide all commonly used functions ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// Imports ...
#include "../../Classes/x-saherelm.base.class.mq5"
#include "../../Libraries/x-saherelm.common.lib.mq5"
#include "../../Libraries/x-saherelm.x-poi.lib.mq5"
#include "../../Libraries/x-saherelm.x-trade.lib.mq5"
//
// Definitions ...
const string X121SMCStrategyToken = "X121SMC";
struct X121SMCStrategyConditions
{
//
string symbol;
ENUM_TIMEFRAMES period;
datetime time;
//
void X121SMCStrategyConditions()
{
Clean();
}
//
// Tools ...
/**
* Cleanup ...
*/
void Clean()
{
//
symbol = NULL;
period = NULL;
time = NULL;
}
/**
* Validate ...
*
* @return ( bool )
*/
bool IsValid()
{
//
bool result = false;
//
result = IsSpecifiedValid(symbol) &&
IsSpecifiedValid(period) &&
IsSpecifiedValid(time);
//
return result;
}
/**
* Generate Provided Scores ...
*
* @param bullishScore: Integer, reference ...
* @param bearishScore: Integer, referenceF ...
*/
void GenerateScore(
double &bullishScore,
double &bearishScore //
)
{
//
bullishScore = 0;
bearishScore = 0;
//
if (!IsValid())
{
return;
}
//
double bullScore = 0;
double bearScore = 0;
// //
// // XPV ...
// pvConditions.GenerateScore(
// bullScore,
// bearScore //
// );
// bullishScore += bullScore;
// bearishScore += bearScore;
}
/**
* Generate Summary ...
*
* @param onlyCommons: Boolean ...
* @param onlyConditions: Boolean ...
* @param includeScores: Boolean ...
* @param ignoreFalseConditions: Boolean ...
* @param separator: String ...
*
* @return ( string )
*/
string GenerateSummary(
bool onlyCommons = false,
bool onlyConditions = false,
bool includeScores = true,
bool ignoreFalseConditions = true,
string separator = "\n" //
)
{
//
string result = NULL;
//
double bullishScore = 0;
double bearishScore = 0;
GenerateScore(
bullishScore,
bearishScore //
);
//
string commonStr = GenerateSpecifiedCommonSummary(
this,
separator,
includeScores,
true //
);
// //
// // XPV ...
// string pvStr = pvConditions.GenerateSummary(
// false,
// true,
// false,
// ignoreFalseConditions //
// );
//
string conditionsStr =
//
// pvStr + separator +
""
//
;
//
result =
//
"[" + GetTag() + "]" + separator +
"----------" + separator +
(onlyConditions
? ""
: commonStr) +
" " + separator +
(onlyCommons
? ""
: conditionsStr) +
""
//
;
//
return result;
}
/**
* Get Unique Identifier ...
*
* @param forObject: Boolean ...
*
* @return ( string )
*/
string GetTag(
bool forObject = false //
)
{
//
string result = NULL;
//
if (!forObject)
{
result = X121SMCStrategyToken;
}
else
{
//
result = X121SMCStrategyToken + "_" +
symbol + "_" + ToString(period) + "_" +
ToMD5(time);
}
//
return result;
}
//
};
typedef void (*TOnX121SMCSignal)(
XSignal &signal,
X121SMCStrategyConditions &conditions //
);
//
@@ -0,0 +1,407 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XCX121SMCTestStrategy
// Description: provides all based classes for use ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// Imports ...
//
#include "../../Helpers/x-saherelm.x3ma.helper.mq5"
#include "../../Helpers/x-saherelm.x3vwap.helper.mq5"
#include "../../Helpers/x-saherelm.xpv.helper.mq5"
#include "../Classes/x-121.smc.base.strategy.class.mq5"
//
// Helper(s) ...
//
// XStrategy Class Implementation(s) ...
class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy
{
//
// Public ...
public:
//
//
// Constructor(s) ...
void XCX121SMCTestStrategy(
//
// Base ...
string _symbol, // Trading Symbol
ENUM_TIMEFRAMES _period // Trading TimeFrame
)
: XCX121SMCBaseStrategy(_symbol, _period)
{
InitialHelpers();
}
//
// Deconstructur ...
void ~XCX121SMCTestStrategy()
{
}
//
// Overrides Actions ...
/**
* Destroy All Class Implementations ...
*/
void Destroy() override
{
//
delete xpvHelper;
delete x3maHelper;
delete x3vwapHelper;
}
/**
* Check Conditions For Signal ...
*/
bool HasSignal(
XSignal &signal,
X121SMCStrategyConditions &conditions //
) override
{
//
bool result = false;
//
signal.Clean();
conditions.Clean();
//
int pushers = 0;
//
double sl = 0;
double tp = 0;
double risk = 0;
double entry = 0;
double reward = 0;
double r2r = R2R();
double volume = Volume();
ENUM_POSITION_TYPE type = POSITION_TYPE_BUY;
ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET;
//
bool hasLong = false;
bool hasShort = false;
//
// Start Calculations ...
//
string _symbol = GetSymbol();
ENUM_TIMEFRAMES _period = GetPeriod();
//
double points = GetPoints(_symbol);
double pip = GetPipPrice(_symbol);
double pip2 = 2 * pip;
//
int zIndex = 0;
int cIndex = zIndex + 1;
int pIndex = cIndex + 1;
int ppIndex = pIndex + 1;
//
// Retrieve Bars ...
//
// Zero Bar ...
XOHCL zBar;
result = zBar.Init(
_symbol,
_period,
zIndex //
);
if (!result)
{
return result;
}
//
// Last Bar ...
XOHCL cBar;
result = cBar.Init(
_symbol,
_period,
cIndex //
);
if (!result)
{
return result;
}
//
// Previous Bar ...
XOHCL pBar;
result = pBar.Init(
_symbol,
_period,
pIndex //
);
if (!result)
{
return result;
}
//
bool isSpreadPassed = IsSpreadPass();
result = isSpreadPassed;
if (!result)
{
return result;
}
//
// Try to Implement SMC Based Conditions ...
//
result = hasLong ||
hasShort;
//
// Rmove Signal Condition ...
if (result)
{
//
// TYPE ...
type =
hasLong
? POSITION_TYPE_BUY
: POSITION_TYPE_SELL;
ENUM_X_POSITION_TYPES xType =
hasLong
? X_POSITION_TYPE_LONG
: X_POSITION_TYPE_SHORT;
//
entry = GetEntry(
conditions.symbol,
type //
);
//
double candidates[];
DetectSLCandidates(
candidates,
entry,
conditions,
xType //
);
double selectedSL =
hasLong
? GetMax(candidates)
: GetMin(candidates);
sl =
hasLong
? selectedSL - pip2
: selectedSL + pip2;
//
// RISK Reward ...
risk =
hasLong
? entry - sl
: sl - entry;
reward = risk * r2r;
tp =
hasLong
? entry + reward
: entry - reward;
//
ClearDraws();
//
signal.sl = sl;
signal.tp = tp;
signal.type = type;
signal.mode = mode;
signal.entry = entry;
signal.volume = volume;
signal.symbol = _symbol;
signal.pushers = pushers;
signal.provider = GetTag();
signal.time = TimeCurrent();
signal.period = _5MState.period;
//
result = PrepareSignal(signal);
//
hasLong = false;
hasShort = false;
}
//
return result;
}
/**
* Detect SL Candidates based on Strategy and Conditions ...
*
* @param result: Double array reference ...
* @param entry: Double, Position Entry Price ...
* @param conditions: X121SMCStrategyConditions instance, Provides Configurations ...
* @param type: ENUM_X_POSITION_TYPES member, Specified Position Type ...
*/
void DetectSLCandidates(
double &result[],
double entry,
X121SMCStrategyConditions &conditions,
ENUM_X_POSITION_TYPES type //
) override
{
}
/**
* Customize Strategy Identifier ...
*/
string GetTag() override
{
return X121SMCStrategyToken;
}
//
// Protected ...
protected:
//
//
// Props ...
//
// XPV ...
XPVInputs xpvInputs;
XCXPVHelper *xpvHelper;
//
// X3MA ...
X3MAInputs x3maInputs;
XCX3MAHelper *x3maHelper;
//
// X3VWAP ...
X3VWAPInputs x3vwapInputs;
XCX3VWAPHelper *x3vwapHelper;
//
// Private ...
private:
//
// Props ...
/**
* Initial Required Indicators Helper ...
*/
void InitialHelpers()
{
//
string symbol = GetSymbol();
ENUM_TIMEFRAMES period = GetPeriod();
//
// Short ...
ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period
ENUM_TIMEFRAMES scPeriod = NULL; // Time Period
//
// Medium ...
ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period
ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period
//
// Long ...
ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period
ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period
//
// Hind ...
ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period
ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period
//
// XPV ...
//
xpvInputs.Default();
//
xpvInputs.scMethod = scMethod;
xpvInputs.scPeriod = scPeriod;
xpvInputs.mcMethod = mcMethod;
xpvInputs.mcPeriod = mcPeriod;
xpvInputs.lcMethod = lcMethod;
xpvInputs.lcPeriod = lcPeriod;
xpvInputs.hcMethod = hcMethod;
xpvInputs.hcPeriod = hcPeriod;
//
xpvInputs.showPeaksAndVales = true;
xpvInputs.showLevels = false;
xpvInputs.showConsolidations = false;
xpvInputs.showFibo1Levels = false;
xpvInputs.showFibo2Levels = false;
xpvInputs.showFibo3Levels = true;
xpvInputs.showFibo4Levels = false;
xpvInputs.showFibo5Levels = false;
//
xpvHelper = new XCXPVHelper();
xpvHelper.Init(
symbol,
period,
xpvInputs //
);
//
// X3MA ...
//
x3maInputs.Default();
x3maHelper = new XCX3MAHelper();
x3maHelper.Init(
symbol,
period,
x3maInputs //
);
//
// X3VWAP ...
//
x3vwapInputs.Default();
x3vwapHelper = new XCX3VWAPHelper();
x3vwapHelper.Init(
symbol,
period,
x3vwapInputs //
);
}
//
};
//