cleanup and backup old styles and try toimplement new POI Detector ...

This commit is contained in:
2024-11-11 14:06:29 -08:00
parent 051ff51800
commit d239d9c580
35 changed files with 15195 additions and 16227 deletions
+4 -4
View File
@@ -24,11 +24,11 @@
//
// XBase Class ...
class XSCBase
class XCBase
{
//
// Public ...
public:
public:
//
// Protected ...
@@ -42,10 +42,10 @@ public:
//
// Protected
protected:
protected:
//
// Private ...
private:
private:
};
//
@@ -33,8 +33,8 @@
//
// Includes ...
#include <Trade/AccountInfo.mqh>
#include "../Classes/x-saherelm.base.class.mq5"
#include <Trade/AccountInfo.mqh>
//
// END Import and Inclused requirements ...
@@ -50,14 +50,14 @@
//
// a Class for Manage Account ...
class XSCAccount : public XSCBase
class XCAccount : public XCBase
{
//
// Public ...
public:
public:
//
// Constructor ...
void XSCAccount()
void XCAccount()
{
//
mAccountInfo = new CAccountInfo();
@@ -65,7 +65,7 @@ public:
//
// Deconstructor ...
void ~XSCAccount()
void ~XCAccount()
{
}
@@ -380,10 +380,10 @@ public:
//
// Protected ...
protected:
protected:
//
// Private ...
private:
private:
//
// Account Info ...
CAccountInfo mAccountInfo;
@@ -26,17 +26,17 @@
//
// Class Definition ...
class XSCAlert : public XSCBase
class XCAlert : public XCBase
{
//
// Public ...
public:
public:
//
// Props ...
//
// Constructor ...
XSCAlert(
XCAlert(
string prefix = "X-Alert", // Alerts Prefixe
bool enableAlerts = true, // Enable Alerts
bool logAlerts = true, // Log Alerts
@@ -63,7 +63,9 @@ public:
//
// Deconstructor ...
~XSCAlert() {}
~XCAlert()
{
}
//
// Override ...
@@ -1282,7 +1284,7 @@ public:
//
// Protected ...
protected:
protected:
//
// Private ...
@@ -1332,7 +1334,7 @@ protected:
return result;
}
private:
private:
//
// Props ...
string mPrefix; // Alerts Prefixe
@@ -1363,26 +1365,26 @@ private:
//
// a Base Class by Support Alert ...
class XSCBaseAlert : public XSCBase
class XCBaseAlert : public XCBase
{
//
// Public ...
public:
public:
//
// Props ...
//
// Constructor(s) ...
void XSCBaseAlert()
void XCBaseAlert()
{
//
// Instance Alert ...
mAlert = new XSCAlert();
mAlert = new XCAlert();
}
//
// Deconstructors ...
void ~XSCBaseAlert()
void ~XCBaseAlert()
{
//
delete mAlert;
@@ -1562,14 +1564,14 @@ public:
//
// Protected ...
protected:
protected:
//
// Alert ...
XSCAlert *mAlert;
XCAlert *mAlert;
//
// Private ...
private:
private:
};
//
+2 -1
View File
@@ -234,7 +234,8 @@ class XCAppDialog : public CAppDialog
bool result = false;
//
if (!IsValid(message)) {
if (!IsValid(message))
{
message = "Confirm ?";
}
+489
View File
@@ -0,0 +1,489 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XChartObjects
// Description: provides all require Chart Objects ...
//
//
// 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
//
#include "../Libraries/x-saherelm.x-poi.lib.mq5"
#include "../Libraries/x-saherelm.x-trade.lib.mq5"
//
#include <ChartObjects/ChartObject.mqh>
#include <ChartObjects/ChartObjectsArrows.mqh>
#include <ChartObjects/ChartObjectsLines.mqh>
#include <ChartObjects/ChartObjectsShapes.mqh>
//
// Definitions ...
enum ENUM_XCHARTOBJECTS
{
//
// Global ...
X_ZONE_OBJ = 7860,
X_FROM_TO_OBJ = 7861,
X_BAR_ARROW_OBJ = 7862,
//
X_SIGNAL_OBJ = 8860,
X_TREND_OBJ = 8861,
//
// Structured ...
X_TRADE_DAY_OBJ = 9860,
X_MARKET_SESSION_OBJ = 9861,
X_SWING_HIGH_OBJ = 9862,
X_SWING_LOW_OBJ = 9863,
X_BULLISH_MOMENTUM_BAR_OBJ = 9864,
X_BEARISH_MOMENTUM_BAR_OBJ = 9865,
X_BULLISH_REJECTION_BAR_OBJ = 9866,
X_BEARISH_REJECTION_BAR_OBJ = 9867,
X_SUPPORT_ZONE_OBJ = 9868,
X_RESISTANCE_ZONE_OBJ = 9869,
X_SUPPLY_ZONE_OBJ = 9870,
X_DEMAND_ZONE_OBJ = 9871,
X_BULLISH_ORDERBLOCK_OBJ = 9872,
X_BEARISH_ORDERBLOCK_OBJ = 9873,
X_BULLISH_FVG_OBJ = 9874,
X_BEARISH_FVG_OBJ = 9875,
};
enum ENUM_X_CHART_IDS
{
X_TO,
X_FROM,
X_UPPER,
X_LOWER,
X_ENTRY,
X_SL,
X_TP
};
//
// Implementation ...
//
// Global Chart Objects ...
//
// Bas Chart Object ...
class XCBaseObject : public CChartObject
{
//
public:
//
//
// Getter(s) / Setter(s) ...
/**
* Get Object Specified Name ...
*
* @return ( string )
*/
string ObjName()
{
return mObjName;
}
/**
* Set Object Specified Name ...
*
* @param value: String ...
*/
void ObjName(string value)
{
mObjName = value;
}
//
private:
//
//
// Props ...
string mObjName; // Object Specified Name ...
//
};
//
// Swing ...
class XCSwingObject : public XCBaseObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param swing: XCSwing instance ...
*
* @return ( bool )
*/
bool CreateBySwing(
long chart_id,
int window,
int arrow,
XCSwing &swing //
)
{
//
bool result = false;
//
result =
//
swing.IsValid()
//
;
if (!result)
{
return result;
}
//
string name = swing.GetTag();
//
XOHCL bar;
result = swing.FillBar(bar);
if (!result)
{
return result;
}
//
datetime time = bar.time;
double price = swing.IsSwingHigh()
? bar.high
: bar.low;
//
result = mArrow.Create(
chart_id,
name,
window,
time,
price,
(char)arrow //
);
//
if (result)
{
ObjName(name);
}
//
return result;
}
//
// Virtual ...
//
// Setter(s) ...
/**
* Set Arrow Anchor ...
*
* @param value: ENUM_ARROW_ANCHOR member ...
*/
void ArrowAnchor(ENUM_ARROW_ANCHOR value)
{
mArrow.Anchor(value);
}
/**
* Set Arrow Color ...
*
* @param value: Color ...
*/
void ArrowColor(color value)
{
mArrow.Color(value);
}
/**
* Set Arrow Width ...
*
* @param value: Integer ...
*/
void ArrowWidth(int value)
{
mArrow.Width(value);
}
//
private:
//
CChartObjectArrow mArrow;
//
};
//
// Swing High ...
class XCSwingHighObject : public XCSwingObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param swing: XCSwing instance ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
int arrow,
XCSwing &swing //
)
{
//
bool result = false;
//
result = swing.IsValid() &&
swing.IsSwingHigh();
if (!result)
{
return result;
}
//
result = CreateBySwing(
chart_id,
window,
arrow,
swing //
);
//
return result;
}
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_SWING_HIGH_OBJ;
}
//
};
//
// Swing Low ...
class XCSwingLowObject : public XCSwingObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param swing: XCSwing instance ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
int arrow,
XCSwing &swing //
)
{
//
bool result = false;
//
result = swing.IsValid() &&
swing.IsSwingLow();
if (!result)
{
return result;
}
//
result = CreateBySwing(
chart_id,
window,
arrow,
swing //
);
//
return result;
}
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_SWING_LOW_OBJ;
}
//
};
//
// XCZoneObject ...
class XCZoneObject : public XCBaseObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param name: String, Specified Object Identifier on Chart ...
* @param window: Integer, Specified Chart Window ID ...
* @param zone: XCZone instance ...
*
* @return ( bool )
*/
bool CreateByZone(
long chart_id,
string name,
int window,
XCZone &zone //
)
{
//
bool result = false;
//
result =
//
IsValid(name) &&
zone.IsValidFrom() &&
zone.IsValidBoundary()
//
;
if (!result)
{
return result;
}
//
datetime to = NormalizeTime(zone.To());
//
result = mRect.Create(
chart_id,
name,
window,
zone.From(),
zone.Upper(),
to,
zone.Lower() //
);
//
if (result)
{
ObjName(name);
}
//
return result;
}
//
// Virtual ...
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_ZONE_OBJ;
}
//
// Setter(s) ...
/**
* Set Zone Width ...
*
* @param value: Integer ...
*/
void ZoneWidth(int value)
{
//
if (value < 1)
{
value = 1;
}
//
mRect.Width(value);
}
/**
* Set Zone Color ...
*
* @param value: Color ...
*/
void ZoneColor(color value)
{
mRect.Color(value);
}
/**
* Set Zone Style ...
*
* @param value: ENUM_LINE_STYLE member ...
*/
void ZoneStyle(ENUM_LINE_STYLE value)
{
mRect.Style(value);
}
//
private:
//
CChartObjectRectangle mRect;
//
};
//
@@ -21,8 +21,8 @@
//
// Imports ...
#include "../Classes/x-saherelm.xalert.class.mq5"
#include "../Classes/x-saherelm.xtrade.class.mq5"
#include "../Classes/x-saherelm.x-alert.class.mq5"
#include "../Classes/x-saherelm.x-trade.class.mq5"
#include "../Helpers/x-saherelm.xcc.helper.mq5"
#include "../Helpers/x-saherelm.xct.helper.mq5"
@@ -35,14 +35,14 @@ string XCBaseExpertToken = "XCBaseEA";
//
// Implementations ...
class XCBaseExpert : public XSCBaseAlert
class XCBaseExpert : public XCBaseAlert
{
//
public:
//
//
XSCTrade *mTrader; // Trader of Expert Adviser ...
XCTrade *mTrader; // Trader of Expert Adviser ...
//
// Constructur(s) ...
@@ -577,7 +577,7 @@ class XCBaseExpert : public XSCBaseAlert
// Bar Timer ...
XCTInputs ctInputs;
ctInputs.Default(); // Default Configurations ...
mCTHelper = new XSCXCTHelper();
mCTHelper = new XCXCTHelper();
result = mCTHelper.Init(
_Symbol,
_Period,
@@ -592,7 +592,7 @@ class XCBaseExpert : public XSCBaseAlert
// Bar Styles ...
XCCInputs ccInputs;
ccInputs.Default(); // Default Configurations ...
mCCHelper = new XSCXCCHelper();
mCCHelper = new XCXCCHelper();
result = mCCHelper.Init(
_Symbol,
_Period,
@@ -605,7 +605,7 @@ class XCBaseExpert : public XSCBaseAlert
//
// Create Trader Instance and Configure it ...
mTrader = new XSCTrade(
mTrader = new XCTrade(
mSlippage,
mMagicNumber //
);
@@ -788,8 +788,8 @@ class XCBaseExpert : public XSCBaseAlert
//
XTimeTracker mTimeTracker; // Time Tracker for Providing Reports ...
XSCXCTHelper *mCTHelper; // Bar Timer Indicator Helper class ...
XSCXCCHelper *mCCHelper; // Chart Styler Indicator Helper Class ...
XCXCTHelper *mCTHelper; // Bar Timer Indicator Helper class ...
XCXCCHelper *mCCHelper; // Chart Styler Indicator Helper Class ...
//
// Actions ...
@@ -30,14 +30,14 @@
//
// a Class for Handle base requirements ...
// for indicators ...
class XSCBaseHelper : public XSCBase
class XCBaseHelper : public XCBase
{
//
// Public ...
public:
public:
//
// Constructor ...
void XSCBaseHelper(
void XCBaseHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period // Trading Time Frame
)
@@ -49,7 +49,7 @@ public:
//
// Deconstructor ...
void ~XSCBaseHelper()
void ~XCBaseHelper()
{
//
IndicatorRelease(mHandler);
@@ -122,7 +122,7 @@ public:
//
// Protected ...
protected:
protected:
//
// Props ...
@@ -140,7 +140,7 @@ protected:
//
// Private ...
private:
private:
//
};
@@ -39,18 +39,18 @@ enum X_HTTP_METHOD
//
// a Class for Manage Account ...
class XSCHttp : public XSCBase
class XCHttp : public XCBase
{
//
// Public ...
public:
public:
//
// Constructor ...
void XSCHttp()
void XCHttp()
{
XSCHttp("", 10000);
XCHttp("", 10000);
}
void XSCHttp(
void XCHttp(
string path, // Base Folder to Store Data
int timeout // base timeout for Requests
)
@@ -62,7 +62,7 @@ public:
//
// Deconstructor ...
void ~XSCHttp()
void ~XCHttp()
{
}
@@ -292,7 +292,7 @@ public:
//
// Protected ...
protected:
protected:
//
// Destintion Folder Path ...
string mPath;
@@ -311,7 +311,7 @@ protected:
//
// Private ...
private:
private:
//
// Reset Errors State ...
void ResetState()
@@ -110,21 +110,25 @@ static uchar _md5_PADDING[64] =
//
// XCMD5 a library for Hashing ...
class XSCMD5
class XCMD5
{
//
// Public Provides ...
public:
public:
//
// Protected Provides ...
//
// Constructor ...
XSCMD5(void) {}
XCMD5(void)
{
}
//
// Deconstructor ...
~XSCMD5(void) {}
~XCMD5(void)
{
}
//
// Hash Specified Char Array ...
@@ -198,10 +202,10 @@ public:
return result;
}
protected:
protected:
//
// Private Provides ...
private:
private:
//
uint m_lMD5[4];
uint m_nCount[2];
File diff suppressed because it is too large Load Diff
+16 -869
View File
@@ -22,11 +22,11 @@
//
// Imports ...
#include "../Classes/x-saherelm.base.class.mq5"
#include "../Classes/x-saherelm.x-chart-objects.class.mq5"
#include "../Classes/x-saherelm.x-cobject.class.mq5"
//
// Definitions ...
class XCPOIDrawer : public XSCBase
class XCPOIDrawer : public XCBase
{
//
public:
@@ -1283,7 +1283,7 @@ class XCPOIDrawer : public XSCBase
* @return ( bool )
*/
bool CreateSwingHigh(
XOHCL &swing,
XCSwing &swing,
XCSwingHighObject *&object //
)
{
@@ -1294,7 +1294,9 @@ class XCPOIDrawer : public XSCBase
object = NULL;
//
result = swing.IsValid();
result =
swing.IsValid() &&
swing.IsSwingHigh();
if (!result)
{
return result;
@@ -1304,9 +1306,6 @@ class XCPOIDrawer : public XSCBase
long chartID = ChartIdentification();
int window = SubWindowIdentification();
//
string name = swing.GetTag(ToString(X_POI_SWING_HIGH));
//
int arrow = SwingHighArrow();
int width = SwingHighWidth();
@@ -1314,12 +1313,11 @@ class XCPOIDrawer : public XSCBase
//
object = new XCSwingHighObject();
result = object.CreateBySwing(
result = object.Create(
chartID,
name,
window,
swing,
(char)arrow //
arrow,
swing //
);
//
@@ -1345,7 +1343,7 @@ class XCPOIDrawer : public XSCBase
* @return ( bool )
*/
bool CreateSwingLow(
XOHCL &swing,
XCSwing &swing,
XCSwingLowObject *&object //
)
{
@@ -1356,7 +1354,9 @@ class XCPOIDrawer : public XSCBase
object = NULL;
//
result = swing.IsValid();
result =
swing.IsValid() &&
swing.IsSwingLow();
if (!result)
{
return result;
@@ -1366,9 +1366,6 @@ class XCPOIDrawer : public XSCBase
long chartID = ChartIdentification();
int window = SubWindowIdentification();
//
string name = swing.GetTag(ToString(X_POI_SWING_LOW));
//
int arrow = SwingLowArrow();
int width = SwingLowWidth();
@@ -1376,12 +1373,11 @@ class XCPOIDrawer : public XSCBase
//
object = new XCSwingLowObject();
result = object.CreateBySwing(
result = object.Create(
chartID,
name,
window,
swing,
(char)arrow //
arrow,
swing //
);
//
@@ -1399,855 +1395,6 @@ class XCPOIDrawer : public XSCBase
return result;
}
//
// Momentum Bars ...
/**
* Create Bullish Momentum Bar Object ...
*
* @param bar: XOHCL instance ...
*
* @return ( bool )
*/
bool CreateBullishMomentumBar(
XOHCL &bar,
XCBullishMomentumBarObject *&object //
)
{
//
bool result = false;
//
object = NULL;
//
result = bar.IsValid();
if (!result)
{
return result;
}
//
long chartID = ChartIdentification();
int window = SubWindowIdentification();
//
string name = bar.GetTag(ToString(X_POI_MOMENTUM_BAR));
//
int arrow = BullishMomentumBarArrow();
int width = BullishMomentumBarWidth();
color crl = BullishMomentumBarColor();
//
object = new XCBullishMomentumBarObject();
result = object.CreateByBar(
chartID,
name,
window,
bar,
(char)arrow //
);
//
if (!result)
{
return result;
}
//
object.ArrowColor(crl);
object.ArrowWidth(width);
object.ArrowAnchor(ANCHOR_TOP);
//
return result;
}
/**
* Create Bearish Momentum Bar Object ...
*
* @param bar: XOHCL instance ...
*
* @return ( bool )
*/
bool CreateBearishMomentumBar(
XOHCL &bar,
XCBearishMomentumBarObject *&object //
)
{
//
bool result = false;
//
object = NULL;
//
result = bar.IsValid();
if (!result)
{
return result;
}
//
long chartID = ChartIdentification();
int window = SubWindowIdentification();
//
string name = bar.GetTag(ToString(X_POI_MOMENTUM_BAR));
//
int arrow = BearishMomentumBarArrow();
int width = BearishMomentumBarWidth();
color crl = BearishMomentumBarColor();
//
object = new XCBearishMomentumBarObject();
result = object.CreateByBar(
chartID,
name,
window,
bar,
(char)arrow //
);
//
if (!result)
{
return result;
}
//
object.ArrowColor(crl);
object.ArrowWidth(width);
object.ArrowAnchor(ANCHOR_TOP);
//
return result;
}
//
// Rejection Bars ...
/**
* Create Bullish Rejection Bar Object ...
*
* @param bar: XOHCL instance ...
*
* @return ( bool )
*/
bool CreateBullishRejectionBar(
XOHCL &bar,
XCBullishRejectionBarObject *&object //
)
{
//
bool result = false;
//
object = NULL;
//
result = bar.IsValid();
if (!result)
{
return result;
}
//
long chartID = ChartIdentification();
int window = SubWindowIdentification();
//
string name = bar.GetTag(ToString(X_POI_REJECTION_BAR));
//
int arrow = BullishRejectionBarArrow();
int width = BullishRejectionBarWidth();
color crl = BullishRejectionBarColor();
//
object = new XCBullishRejectionBarObject();
result = object.CreateByBar(
chartID,
name,
window,
bar,
(char)arrow //
);
//
if (!result)
{
return result;
}
//
object.ArrowColor(crl);
object.ArrowWidth(width);
object.ArrowAnchor(ANCHOR_TOP);
//
return result;
}
/**
* Create Bearish Rejection Bar Object ...
*
* @param bar: XOHCL instance ...
*
* @return ( bool )
*/
bool CreateBearishRejectionBar(
XOHCL &bar,
XCBearishRejectionBarObject *&object //
)
{
//
bool result = false;
//
object = NULL;
//
result = bar.IsValid();
if (!result)
{
return result;
}
//
long chartID = ChartIdentification();
int window = SubWindowIdentification();
//
string name = bar.GetTag(ToString(X_POI_REJECTION_BAR));
//
int arrow = BearishRejectionBarArrow();
int width = BearishRejectionBarWidth();
color crl = BearishRejectionBarColor();
//
object = new XCBearishRejectionBarObject();
result = object.CreateByBar(
chartID,
name,
window,
bar,
(char)arrow //
);
//
if (!result)
{
return result;
}
//
object.ArrowColor(crl);
object.ArrowWidth(width);
object.ArrowAnchor(ANCHOR_TOP);
//
return result;
}
//
// Support and Resistance Zones ...
/**
* Create Support Zone Object ...
*
* @param bar: XOHCL instance ...
* @param destTime: DateTime ...
*
* @return ( bool )
*/
bool CreateSupportZone(
XOHCL &bar,
XCSupportZoneObject *&object,
datetime destTime = NULL //
)
{
//
bool result = false;
//
object = NULL;
//
result = bar.IsValid();
if (!result)
{
return result;
}
//
long chartID = ChartIdentification();
int window = SubWindowIdentification();
//
string name = bar.GetTag(ToString(X_POI_SUPPORT_ZONE));
//
datetime time2 =
IsValid(destTime)
? destTime
: (datetime)((int)bar.time + (PeriodSeconds(bar.period) * 5));
//
bool fill = SupportZoneFill();
int width = SupportZoneWidth();
color crl = SupportZoneColor();
ENUM_LINE_STYLE style = SupportZoneStyle();
//
object = new XCSupportZoneObject();
result = object.CreateBySupport(
chartID,
name,
window,
bar,
time2,
true //
);
//
if (!result)
{
return result;
}
//
object.ZoneFill(fill);
object.ZoneColor(crl);
object.ZoneWidth(width);
object.ZoneStyle(style);
//
return result;
}
/**
* Create Resistance Zone Object ...
*
* @param bar: XOHCL instance ...
*
* @return ( bool )
*/
bool CreateResistanceZone(
XOHCL &bar,
XCResistanceZoneObject *&object,
datetime destTime = NULL //
)
{
//
bool result = false;
//
object = NULL;
//
result = bar.IsValid();
if (!result)
{
return result;
}
//
long chartID = ChartIdentification();
int window = SubWindowIdentification();
//
string name = bar.GetTag(ToString(X_POI_RESISTANCE_ZONE));
//
datetime time2 =
IsValid(destTime)
? destTime
: (datetime)((int)bar.time + (PeriodSeconds(bar.period) * 5));
//
bool fill = ResistanceZoneFill();
int width = ResistanceZoneWidth();
color crl = ResistanceZoneColor();
ENUM_LINE_STYLE style = ResistanceZoneStyle();
//
object = new XCResistanceZoneObject();
result = object.CreateByResistance(
chartID,
name,
window,
bar,
time2,
true //
);
//
if (!result)
{
return result;
}
//
object.ZoneFill(fill);
object.ZoneColor(crl);
object.ZoneWidth(width);
object.ZoneStyle(style);
//
return result;
}
//
// Supply and Demand Zones ...
/**
* Create Supply Zone Object ...
*
* @param zone: XZone instance ...
*
* @return ( bool )
*/
bool CreateSupplyZone(
XZone &zone,
XCSupplyZoneObject *&object //
)
{
//
bool result = false;
//
object = NULL;
//
result = zone.IsValid();
if (!result)
{
return result;
}
//
long chartID = ChartIdentification();
int window = SubWindowIdentification();
//
string name = zone.GetTag();
result = Contains(
ToString(X_POI_SUPPLY_ZONE),
name //
);
if (!result)
{
return result;
}
//
bool fill = SupplyZoneFill();
int width = SupplyZoneWidth();
color crl = SupplyZoneColor();
ENUM_LINE_STYLE style = SupplyZoneStyle();
//
object = new XCSupplyZoneObject();
result = object.CreateByZone(
chartID,
name,
window,
zone,
NULL,
true //
);
//
if (!result)
{
return result;
}
//
object.ZoneFill(fill);
object.ZoneColor(crl);
object.ZoneWidth(width);
object.ZoneStyle(style);
//
return result;
}
/**
* Create Demand Zone Object ...
*
* @param zone: XZone instance ...
*
* @return ( bool )
*/
bool CreateDemandZone(
XZone &zone,
XCDemandZoneObject *&object //
)
{
//
bool result = false;
//
object = NULL;
//
result = zone.IsValid();
if (!result)
{
return result;
}
//
long chartID = ChartIdentification();
int window = SubWindowIdentification();
//
string name = zone.GetTag();
result = Contains(
ToString(X_POI_DEMAND_ZONE),
name //
);
if (!result)
{
return result;
}
//
bool fill = DemandZoneFill();
int width = DemandZoneWidth();
color crl = DemandZoneColor();
ENUM_LINE_STYLE style = DemandZoneStyle();
//
object = new XCDemandZoneObject();
result = object.CreateByZone(
chartID,
name,
window,
zone,
NULL,
true //
);
//
if (!result)
{
return result;
}
//
object.ZoneFill(fill);
object.ZoneColor(crl);
object.ZoneWidth(width);
object.ZoneStyle(style);
//
return result;
}
//
// Order Blocks ...
/**
* Create Bullish Order Block Object ...
*
* @param zone: XZone instance ...
*
* @return ( bool )
*/
bool CreateBullishOrderBlock(
XZone &zone,
XCBullishOrderBlockObject *&object //
)
{
//
bool result = false;
//
object = NULL;
//
result = zone.IsValid();
if (!result)
{
return result;
}
//
long chartID = ChartIdentification();
int window = SubWindowIdentification();
//
string name = zone.GetTag();
result = Contains(
ToString(X_POI_BULLISH_ORDERBLOCK),
name //
);
if (!result)
{
return result;
}
//
bool fill = BullishOrderBlockFill();
int width = BullishOrderBlockWidth();
color crl = BullishOrderBlockColor();
ENUM_LINE_STYLE style = BullishOrderBlockStyle();
//
object = new XCBullishOrderBlockObject();
result = object.CreateByZone(
chartID,
name,
window,
zone,
NULL,
true //
);
//
if (!result)
{
return result;
}
//
object.ZoneFill(fill);
object.ZoneColor(crl);
object.ZoneWidth(width);
object.ZoneStyle(style);
//
return result;
}
/**
* Create Bearish Order Block Object ...
*
* @param zone: XZone instance ...
*
* @return ( bool )
*/
bool CreateBearishOrderBlock(
XZone &zone,
XCBearishOrderBlockObject *&object //
)
{
//
bool result = false;
//
object = NULL;
//
result = zone.IsValid();
if (!result)
{
return result;
}
//
long chartID = ChartIdentification();
int window = SubWindowIdentification();
//
string name = zone.GetTag();
result = Contains(
ToString(X_POI_BEARISH_ORDERBLOCK),
name //
);
if (!result)
{
return result;
}
//
bool fill = BearishOrderBlockFill();
int width = BearishOrderBlockWidth();
color crl = BearishOrderBlockColor();
ENUM_LINE_STYLE style = BearishOrderBlockStyle();
//
object = new XCBearishOrderBlockObject();
result = object.CreateByZone(
chartID,
name,
window,
zone,
NULL,
true //
);
//
if (!result)
{
return result;
}
//
object.ZoneFill(fill);
object.ZoneColor(crl);
object.ZoneWidth(width);
object.ZoneStyle(style);
//
return result;
}
//
// Order Blocks ...
/**
* Create Bullish FVG Object ...
*
* @param zone: XZone instance ...
*
* @return ( bool )
*/
bool CreateBullishFVG(
XZone &zone,
XCBullishFVGObject *&object //
)
{
//
bool result = false;
//
object = NULL;
//
result = zone.IsValid();
if (!result)
{
return result;
}
//
long chartID = ChartIdentification();
int window = SubWindowIdentification();
//
string name = zone.GetTag();
result = Contains(
ToString(X_POI_BULLISH_FVG),
name //
);
if (!result)
{
return result;
}
//
bool fill = BullishFVGFill();
int width = BullishFVGWidth();
color crl = BullishFVGColor();
ENUM_LINE_STYLE style = BullishFVGStyle();
//
object = new XCBullishFVGObject();
result = object.CreateByZone(
chartID,
name,
window,
zone,
NULL,
true //
);
//
if (!result)
{
return result;
}
//
object.ZoneFill(fill);
object.ZoneColor(crl);
object.ZoneWidth(width);
object.ZoneStyle(style);
//
return result;
}
/**
* Create Bearish FVG Object ...
*
* @param zone: XZone instance ...
*
* @return ( bool )
*/
bool CreateBearishFVG(
XZone &zone,
XCBearishFVGObject *&object //
)
{
//
bool result = false;
//
object = NULL;
//
result = zone.IsValid();
if (!result)
{
return result;
}
//
long chartID = ChartIdentification();
int window = SubWindowIdentification();
//
string name = zone.GetTag();
result = Contains(
ToString(X_POI_BEARISH_FVG),
name //
);
if (!result)
{
return result;
}
//
bool fill = BearishFVGFill();
int width = BearishFVGWidth();
color crl = BearishFVGColor();
ENUM_LINE_STYLE style = BearishFVGStyle();
//
object = new XCBearishFVGObject();
result = object.CreateByZone(
chartID,
name,
window,
zone,
NULL,
true //
);
//
if (!result)
{
return result;
}
//
object.ZoneFill(fill);
object.ZoneColor(crl);
object.ZoneWidth(width);
object.ZoneStyle(style);
//
return result;
}
//
protected:
//
File diff suppressed because it is too large Load Diff
+60
View File
@@ -0,0 +1,60 @@
//
string symbol = GetSymbol();
ENUM_TIMEFRAMES period = GetPeriod();
//
int zIndex = barIndex;
int cIndex = zIndex + 1;
int pIndex = cIndex + 1;
int ppIndex = pIndex + 1;
//
bool isInited = false;
//
XOHCL zBar;
isInited = zBar.Init(
symbol,
period,
zIndex //
);
if (!isInited)
{
return result;
}
//
XOHCL cBar;
isInited = cBar.Init(
symbol,
period,
cIndex //
);
if (!isInited)
{
return result;
}
//
XOHCL pBar;
isInited = pBar.Init(
symbol,
period,
pIndex //
);
if (!isInited)
{
return result;
}
//
XOHCL ppBar;
isInited = ppBar.Init(
symbol,
period,
ppIndex //
);
if (!isInited)
{
return result;
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+13 -13
View File
@@ -23,7 +23,7 @@
//
// Imports ...
#include "../X121SMCEA/Experts/x-121.smc.expert.class.mq5"
#include "../X121SMCEA/Experts/x-121.poi.expert.class.mq5"
//
// Inputs ...
@@ -105,7 +105,7 @@ int OnInit()
// Configure EA Expert Class ...
//
eaExpert.OnSignalEventListener = OnSignalRecieved;
// eaExpert.OnSignalEventListener = OnSignalRecieved;
eaExpert.OnPositionSLEventListener = OnStopLossTriggered;
eaExpert.OnPositionTPEventListener = OnTakeProfitTriggered;
eaExpert.OnPositionForceCloseEventListener = OnPositionForceClosed;
@@ -219,17 +219,17 @@ void OnChartEvent(
* @param signal: XSignal instance ...
* @param conditions: XStrategyConditions instance ...
*/
void OnSignalRecieved(
XSignal &signal,
X121SMCStrategyConditions &conditions //
)
{
//
eaExpert.HandleOnSignalRecieved(
signal,
conditions //
);
}
// void OnSignalRecieved(
// XSignal &signal,
// X121SMCStrategyConditions &conditions //
// )
// {
// //
// eaExpert.HandleOnSignalRecieved(
// signal,
// conditions //
// );
// }
/**
* Handle StopLoss Triggered Positions ...
+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 ...
@@ -131,7 +131,7 @@ struct XCCInputs
//
// Class ...
class XSCXCCHelper : public XSCBaseHelper
class XCXCCHelper : public XCBaseHelper
{
//
// Public ...
@@ -141,13 +141,13 @@ public:
//
// Constructors ...
XSCXCCHelper() : XSCBaseHelper(_Symbol, _Period)
XCXCCHelper() : XCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XSCXCCHelper() {}
~XCXCCHelper() {}
//
// Tools ...
+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 ...
@@ -114,7 +114,7 @@ struct XCTInputs
//
// Class ...
class XSCXCTHelper : public XSCBaseHelper
class XCXCTHelper : public XCBaseHelper
{
//
// Public ...
@@ -124,13 +124,13 @@ public:
//
// Constructors ...
XSCXCTHelper() : XSCBaseHelper(_Symbol, _Period)
XCXCTHelper() : XCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XSCXCTHelper() {}
~XCXCTHelper() {}
//
// Tools ...
+2 -2
View File
@@ -21,7 +21,7 @@
//
// Imports ...
#include "../Classes/x-saherelm.xmd5.class.mq5"
#include "../Classes/x-saherelm.x-md5.class.mq5"
//
// Models ...
@@ -10322,7 +10322,7 @@ string ToMD5(T content)
}
//
static XSCMD5 md5;
static XCMD5 md5;
//
result = md5.Hash(strContent);
File diff suppressed because it is too large Load Diff
+182 -8
View File
@@ -125,7 +125,7 @@ enum ENUM_XSESSION
//
// Base POI Model Class ...
class XCBasePOI : public XSCBase
class XCBasePOI : public XCBase
{
//
public:
@@ -300,11 +300,7 @@ class XCZone : public XCBasePOI
// Overrides ...
//
protected:
//
// Props ...
double mUpper; // Zone Upper ...
double mLower; // Zone Lower ...
// Validators ...
/**
* Validate Upper and Lower of Zone ...
@@ -339,6 +335,13 @@ class XCZone : public XCBasePOI
return IsSpecifiedValid(From());
}
//
protected:
//
// Props ...
double mUpper; // Zone Upper ...
double mLower; // Zone Lower ...
//
private:
//
@@ -1041,6 +1044,35 @@ class XCSwing : public XCBasePOI
//
// Getter(s) / Setter(s) ...
/**
* Fill Swing Bar as XOHCLstruct ...
*
* @param bar: XOHCL instance ...
*
* @return ( bool )
*/
bool FillBar(
XOHCL &bar //
)
{
//
bool result = false;
//
result = IsValid();
if (!result)
{
return result;
}
//
bar = mBar;
result = mBar.IsValid();
//
return result;
}
/**
* Check Swing High or not ...
*
@@ -1129,10 +1161,16 @@ class XCSwing : public XCBasePOI
//
string hash = ToMD5(mBar.GetTag());
//
string subType = IsSwingHigh()
? "High"
: "Low";
//
result =
//
TypeAsString() + mSep +
subType + mSep +
ToString(mBar.period) + mSep +
hash
//
@@ -2130,18 +2168,154 @@ class XCFVG : public XCTwoBarZone
};
//
// TODO: Implement this ...
// Trading Day ...
class XCDay : public XCFromToZone
{
//
public:
//
//
// Constructor ...
void XCDay()
{
}
//
// Deconstructor ...
void ~XCDay()
{
}
//
// Tools ...
/**
* Initialize POI ...
*
* @return ( bool )
*/
bool Init()
{
//
bool result = false;
//
result = IsValid();
//
return result;
}
//
// Getter(s) / Setter(s) ...
//
// Overrides ...
//
protected:
//
//
private:
//
//
};
//
// TODO: Implement this ...
// Trading Session ...
class XCSession : public XCFromToZone
{
//
public:
//
//
// Constructor ...
void XCSession()
{
}
//
// Deconstructor ...
void ~XCSession()
{
}
//
// Tools ...
/**
* Initialize POI ...
*
* @return ( bool )
*/
bool Init()
{
//
bool result = false;
//
result = IsValid();
//
return result;
}
//
// Getter(s) / Setter(s) ...
//
// Overrides ...
//
protected:
//
//
private:
//
//
};
//
//
// Model Exists Founded POIs ...
struct XPOIState
{
//
string symbol;
ENUM_TIMEFRAMES period;
datetime reportedAt;
//
//
// Constructor ...
void XPOIState()
{
Clean();
}
//
// Actions ...
/**
* Cleanup all props ...
*/
void Clean()
{
//
symbol = NULL;
period = NULL;
reportedAt = NULL;
}
//
};
//
// Extensions ...
@@ -22,7 +22,6 @@
//
// Imports ...
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Libraries/x-saherelm.draw.lib.mq5"
#include <Trade/Trade.mqh>
//
@@ -1463,162 +1462,6 @@ struct XSignal
return result;
}
//
// Draw Signal on Chart ...
bool Draw(
long chartID,
int subWindow = 0,
string prefix = NULL,
color entryColor = clrGold,
color bullishColor = clrSpringGreen,
color bearishColor = clrTomato //
)
{
//
bool result = false;
//
result = IsValid();
if (!result)
{
return result;
}
//
bool isLong = IsLong(this.type);
//
prefix =
//
(!IsValid(prefix) ? "" : prefix) +
this.symbol + "_" +
ToString(this.period) + "_" +
this.provider
//
;
//
int age = this.GetAge();
//
// Retrieve Time ...
datetime time0 = iTime(
this.symbol,
this.period,
age //
);
//
// Retrieve 3 Time ...
datetime time3 = iTime(
this.symbol,
this.period,
age + 3 //
);
//
color posColor = isLong
? bullishColor
: bearishColor;
color tpColor = bullishColor;
color slColor = bearishColor;
//
ENUM_LINE_STYLE vLineStyle = STYLE_DOT;
ENUM_LINE_STYLE tpLineStyle = STYLE_SOLID;
ENUM_LINE_STYLE slLineStyle = STYLE_SOLID;
ENUM_LINE_STYLE entryLineStyle = STYLE_SOLID;
//
int lineWidth = 2;
//
// Vertical Line ...
string vlName = prefix + "_" + (string)time;
//
result = DrawVerticalLine(
chartID,
vlName,
subWindow,
time0,
posColor,
vLineStyle,
lineWidth //
);
if (!result)
{
return result;
}
//
// TP ...
double profit = (MathAbs(this.tp - this.entry)) * this.volume;
string tpName = prefix + "_TP_" + (string)profit;
//
result = DrawTrendLine(
chartID,
tpName,
subWindow,
time3,
this.tp,
time0,
this.tp,
tpColor,
tpLineStyle,
lineWidth //
);
if (!result)
{
return result;
}
//
// SL ...
double lost = (MathAbs(this.sl - this.entry)) * this.volume;
string slName = prefix + "_SL_" + (string)lost;
//
result = DrawTrendLine(
chartID,
slName,
subWindow,
time3,
this.sl,
time0,
this.sl,
slColor,
slLineStyle,
lineWidth //
);
if (!result)
{
return result;
}
//
// ENTRY ...
string entryName = prefix + "_ENTRY_" + (string)lost;
//
result = DrawTrendLine(
chartID,
entryName,
subWindow,
time3,
this.entry,
time,
this.entry,
entryColor,
entryLineStyle,
lineWidth //
);
//
return result;
}
//
string GetTag()
{
@@ -5867,222 +5710,3 @@ int ExtractSymbolPositions(
}
//
// Custom Drawings ...
bool DrawTrendState(
long chartId,
string _prefix,
XOHCL &_bar,
double &support,
double &resistance,
int shoulders = 10,
int subWindow = 0,
color resistanceColor = clrRed,
color supportColor = clrGreen,
color swingHighColor = clrAqua,
color swingLowColor = clrMagenta //
)
{
//
bool result = false;
//
result =
//
IsValid(_prefix) &&
_bar.IsValid()
//
;
if (!result)
{
return result;
}
//
// Find Low Swings ...
//
int firstSwingLowIndex = FindSwing(
_bar.symbol,
_bar.period,
X_SWING_LOW,
shoulders,
_bar.Index() + 1 //
);
XOHCL firstSwingLowBar;
result = firstSwingLowBar.Init(
_bar.symbol,
_bar.period,
firstSwingLowIndex //
);
if (!result)
{
return result;
}
//
int secondSwingLowIndex = FindSwing(
_bar.symbol,
_bar.period,
X_SWING_LOW,
shoulders,
firstSwingLowIndex + 1 //
);
XOHCL secondSwingLowBar;
result = secondSwingLowBar.Init(
_bar.symbol,
_bar.period,
secondSwingLowIndex //
);
if (!result)
{
return result;
}
//
support = secondSwingLowBar.low;
//
string lowSwingTrendLineName = _prefix + "_Low_Swing_Trend";
//
result = DrawTrendLine(
chartId,
lowSwingTrendLineName,
subWindow,
secondSwingLowBar.time,
secondSwingLowBar.low,
firstSwingLowBar.time,
firstSwingLowBar.low,
swingLowColor,
STYLE_SOLID,
2,
false,
false,
true // Ray Right ...
);
if (!result)
{
return result;
}
//
string lowSwingSupportLineName = _prefix + "_Low_Swing_Support";
//
result = DrawTrendLine(
chartId,
lowSwingSupportLineName,
subWindow,
secondSwingLowBar.time,
secondSwingLowBar.low,
firstSwingLowBar.time,
secondSwingLowBar.low,
supportColor,
STYLE_SOLID,
2,
false,
false,
true // Ray Right ...
);
if (!result)
{
return result;
}
//
// Find High Swings ...
//
int firstSwingHighIndex = FindSwing(
_bar.symbol,
_bar.period,
X_SWING_HIGH,
shoulders,
_bar.Index() + 1 //
);
XOHCL firstSwingHighBar;
result = firstSwingHighBar.Init(
_bar.symbol,
_bar.period,
firstSwingHighIndex //
);
if (!result)
{
return result;
}
//
int secondSwingHighIndex = FindSwing(
_bar.symbol,
_bar.period,
X_SWING_HIGH,
shoulders,
firstSwingHighIndex + 1 //
);
XOHCL secondSwingHighBar;
result = secondSwingHighBar.Init(
_bar.symbol,
_bar.period,
secondSwingHighIndex //
);
if (!result)
{
return result;
}
//
resistance = secondSwingHighBar.high;
//
string highSwingTrendLineName = _prefix + "_High_Swing_Trend";
//
result = DrawTrendLine(
chartId,
highSwingTrendLineName,
subWindow,
secondSwingHighBar.time,
secondSwingHighBar.high,
firstSwingHighBar.time,
firstSwingHighBar.high,
swingHighColor,
STYLE_SOLID,
2,
false,
false,
true // Ray Right ...
);
if (!result)
{
return result;
}
//
string highSwingResistanceLineName = _prefix + "_High_Swing_Resistance";
//
result = DrawTrendLine(
chartId,
highSwingResistanceLineName,
subWindow,
secondSwingHighBar.time,
secondSwingHighBar.high,
firstSwingHighBar.time,
secondSwingHighBar.high,
resistanceColor,
STYLE_SOLID,
2,
false,
false,
true // Ray Right ...
);
if (!result)
{
return result;
}
//
return result;
}
//
@@ -23,9 +23,8 @@
// Imports ...
//
#include "../../Classes/x-saherelm.xalert.class.mq5"
#include "../../Classes/x-saherelm.xtrade.class.mq5"
#include "../Libraries/x-121.smc.lib.mq5"
#include "../../Classes/x-saherelm.x-alert.class.mq5"
#include "../../Classes/x-saherelm.x-trade.class.mq5"
//
// Definitions ...
@@ -700,7 +699,7 @@ class X121SMCTradeCollector
)
{
//
mAccount = new XSCAccount();
mAccount = new XCAccount();
//
if (IsValid(_path))
@@ -868,7 +867,7 @@ class X121SMCTradeCollector
string mPath; // Base Path ...
//
XSCAccount *mAccount;
XCAccount *mAccount;
//
string GetFilePath(X121SMCTradeData &item)
@@ -1085,7 +1084,7 @@ class X121SMCTradeCollector
//
// Trade Handler Class ...
class XC121SMCTradeHandler : public XSCBaseAlert
class XC121SMCTradeHandler : public XCBaseAlert
{
//
// Public ...
@@ -1094,7 +1093,7 @@ class XC121SMCTradeHandler : public XSCBaseAlert
//
// Constructor(s) ...
void XC121SMCTradeHandler(XSCTrade *trader)
void XC121SMCTradeHandler(XCTrade *trader)
{
//
mTrader = trader;
@@ -2743,7 +2742,7 @@ class XC121SMCTradeHandler : public XSCBaseAlert
// Protected ...
protected:
//
XSCTrade *mTrader; // Instance of Trader Class
XCTrade *mTrader; // Instance of Trader Class
X121SMCTradeCollector *mCollector; // Instance of Trade Collector Class
//
@@ -0,0 +1,830 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XC121SMCExpert
// 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 "../../Classes/x-saherelm.x-expert.class.mq5"
#include "../../Classes/x-saherelm.x-poi.class.mq5"
// #include "../Classes/x-121.smc.xtradehandler.class.mq5"
//
// Definitions ...
string XC121SMCExpertToken = "XC121SMCEA";
//
// Implementation ...
class XC121SMCExpert : public XCBaseExpert
{
//
public:
//
//
// Signal Event Listener ...
TOnStopLoss OnPositionSLEventListener;
TOnTakeProfit OnPositionTPEventListener;
TOnPartialClose OnPositionPartialCloseEventListener;
TOnModify OnPositionModifiedEventListener;
TOnForceClose OnPositionForceCloseEventListener;
//
// Getter(s) / Setter(s) ...
/**
* Get Use Dynamic Volume State ...
*
* @return ( bool )
*/
bool UseDynamicVolume()
{
return mUseDynamicVolume;
}
/**
* Set Use Dynamic Volume State ...
*
* @param value: Boolean ...
*/
void UseDynamicVolume(bool value)
{
mUseDynamicVolume = value;
}
/**
* Get Increase Volume Step ...
*
* @return ( double )
*/
double DynamicVolumeStep()
{
return mDynamicVolumeStep;
}
/**
* Set Increase Volume Step ...
*
* @param value: Double ...
*/
void DynamicVolumeStep(double value)
{
//
if (value < 0.01)
{
value = 0.01;
}
//
mDynamicVolumeStep = value;
}
/**
* Get Balance Factor for Generate Dynamic Volume ...
*
* @return ( double )
*/
double DynamicVolumeBalanceFactor()
{
return mDynamicVolumeBalanceFactor;
}
/**
* Set Balance Factor for Generate Dynamic Volume ...
*
* @param value: Double ...
*/
void DynamicVolumeBalanceFactor(double value)
{
//
if (value < 0)
{
value = 0;
}
//
mDynamicVolumeBalanceFactor = value;
}
/**
* Get Static Volume ...
*
* @return ( double )
*/
double Volume()
{
return mVolume;
}
/**
* Set Static Volume ...
*
* @param value: Double ...
*/
void Volume(double value)
{
//
if (value < 0.01)
{
value = 0.01;
}
//
mVolume = value;
}
//
// Actions ...
//
// Override Actions ...
/**
* Apply Default Configurations ...
*/
void DefaultConfigure() override
{
//
// Commons ...
Slippage(10);
TagPrefix("");
MagicNumber(1694056);
//
// Symbol ...
SetSymbol(_Symbol);
SetPeriod(_Period);
MultiSymbol(false);
Symbols("EURUSDb,GBPUSDb,USDJPYb,USDCHFb,DowJones30,XAUUSDb");
//
// Signalling ...
Disabled(false);
AllowLong(true);
AllowShort(true);
//
string tag = GetTag();
//
// Alert ...
SetAlertPrefix(tag);
SetAlertLogAlerts(true);
SetAlertPushAlerts(true);
SetAlertMailAlerts(false);
SetAlertEnableAlerts(true);
SetAlertTerminalAlerts(false);
//
// Reports ...
ReportNewDays(true);
ReportNewWeeks(false);
ReportNewHours(false);
ReportNewMonths(false);
//
// Volume Default Configurations ...
Volume(0.01);
UseDynamicVolume(false);
DynamicVolumeStep(0.01);
DynamicVolumeBalanceFactor(200);
}
/**
* Vaslidate Inputs ...
*
* @return ( bool )
*/
bool ValidateInputs() override
{
//
bool result = false;
//
string errMessage = "";
//
bool isCommonValid = (
//
Slippage() > 0 &&
MagicNumber() > 0
//
);
if (!isCommonValid)
{
//
errMessage += "common configurations error;" + "\n";
}
//
// Checking Volume ...
bool isVolumeValid = true;
if (UseDynamicVolume())
{
//
isVolumeValid =
DynamicVolumeStep() > 0 &&
DynamicVolumeBalanceFactor() > 0;
if (!isVolumeValid)
{
errMessage += "Dynamic Volume configurations error;" + "\n";
}
}
isVolumeValid = isVolumeValid &&
Volume() > 0;
if (!isVolumeValid)
{
errMessage += "Static Volume configurations error;" + "\n";
}
//
result =
//
// Common ...
isCommonValid &&
//
// Volume Coniguration ...
isVolumeValid &&
//
// Otere ...
true
//
;
//
if (!result)
{
//
// Since here Logger not Initiallized, we Use Raw Print Command ...
errMessage = " Errors: \n" + errMessage;
Alert(errMessage);
}
//
return result;
}
//
// Initializers and DeInitializers ...
/**
* Initial EA Requirements ...
*
* @return ( bool )
*/
bool InitEA() override
{
//
bool result = false;
//
// Initialize Indicator Helpers ...
//
string symbol = GetSymbol();
ENUM_TIMEFRAMES period = GetPeriod();
//
mPOIDetector = new XCPOIDetector(
symbol,
period //
);
mPOIDetector.Init();
//
// Bar Timer ...
XCTInputs ctInputs;
ctInputs.Default(); // Default Configurations ...
mCTHelper = new XCXCTHelper();
result = mCTHelper.Init(
GetSymbol(),
GetPeriod(),
ctInputs //
);
if (!result)
{
return result;
}
//
// Bar Styles ...
XCCInputs ccInputs;
ccInputs.Default(); // Default Configurations ...
mCCHelper = new XCXCCHelper();
result = mCCHelper.Init(
GetSymbol(),
GetPeriod(),
ccInputs //
);
if (!result)
{
return result;
}
//
// Create Trader Instance and Configure it ...
mTrader = new XCTrade(
Slippage(),
MagicNumber() //
);
mTrader.AddOnStopLossEventHandler(OnPositionSLEventListener);
mTrader.AddOnTakeProfitEventHandler(OnPositionTPEventListener);
mTrader.AddOnModifyPositionEventHandler(OnPositionModifiedEventListener);
mTrader.AddOnForceClosePositionEventHandler(OnPositionForceCloseEventListener);
mTrader.AddOnPartialClosePositionEventHandler(OnPositionPartialCloseEventListener);
// //
// // Initialize Trade Handler ...
// mTradeHandler = new XC121SMCTradeHandler(mTrader);
// mTradeHandler.SaveTrades(true);
// mTradeHandler.SaveSignals(true);
// mTradeHandler.SaveConditions(true);
// //
// // Configure Alerts ...
// mTradeHandler.SetAlertPrefix(GetTag());
// mTradeHandler.SetAlertEnableAlerts(GetAlertEnableAlerts());
// mTradeHandler.SetAlertLogAlerts(GetAlertLogAlerts());
// mTradeHandler.SetAlertMailAlerts(GetAlertMailAlerts());
// mTradeHandler.SetAlertPushAlerts(GetAlertPushAlerts());
// mTradeHandler.SetAlertTerminalAlerts(GetAlertTerminalAlerts());
// //
// // TODO: Make This Configurable Later ...
// //
// mTradeHandler.DelayBarBetweenTwoSignal(3);
// mTradeHandler.MaxAllowedSLToPause(0);
// mTradeHandler.MaxAllowedSLReachedPauseDelay(HoursToSeconds(24));
// //
// // Configure Trade Management ...
// mTradeHandler.AllowLong(AllowLong());
// mTradeHandler.AllowShort(AllowShort());
// mTradeHandler.MaxAllowedLongs(0);
// mTradeHandler.MaxAllowedShorts(0);
// mTradeHandler.UseMaxAllowedTradesPerSymbol(true);
// mTradeHandler.MaxDrawdownPercentForOpenTrades(5);
// //
// // Configure Position Protector ...
// //
// mTradeHandler.UseForceMomentumsInProtection(true);
// mTradeHandler.DelayBarBetweenTwoSignal(2);
// //
// // Configure Hedging ...
// mTradeHandler.AllowHedge(false);
// mTradeHandler.HedgeMinVolumeStep(0.01);
// mTradeHandler.MinimumOpenPositionsForHEHedge(2);
// mTradeHandler.HedgeHEMinProfitPerVolumeStep(0.2);
// mTradeHandler.HedgeBEMinProfitPerVolumeStep(0.06);
// //
// // In Profit Position Protecting ...
// //
// // Trail ...
// mTradeHandler.AllowTrail(false);
// mTradeHandler.TrailStep(15);
// mTradeHandler.TrailStartDistance(30);
// mTradeHandler.OnlyTrailUnprotected(true);
// mTradeHandler.RemoveTPAfterTrailedLevel(4);
// //
// // Partial Close (In Profit) ...
// mTradeHandler.PartialCloseInProfitDistance(0);
// mTradeHandler.PartialCloseInProfitVolume(0);
// //
// // In Drawdown Positions Protecting ...
// //
// // Protect ...
// mTradeHandler.AllowProtect(false);
// mTradeHandler.ProtectionDelay(20);
// mTradeHandler.MaxAllowedProtection(0);
// mTradeHandler.UseEntryAsProtectionSL(true);
// mTradeHandler.ProtectOnConditions(true);
// mTradeHandler.AllowDirectionProtct(false);
// mTradeHandler.ProtectionStartDistance(50);
// mTradeHandler.ProtectionVolumeMultiplier(2);
// //
// // Partial Close (In Profit) ...
// mTradeHandler.PartialCloseInDrawdownDistance(0);
// mTradeHandler.PartialCloseInDrawdownVolume(0);
//
// Parsers ...
XSymbolParser _symbolParser;
//
// Single Symbol ...
if (!MultiSymbol())
{
//
// Register Strategy ...
//
// Create Class Instance ...
// XCX121SMCBaseStrategy *iX121SMCStrategy;
// iX121SMCStrategy = new XCX121SMCTestStrategy(
// _Symbol,
// _Period //
// );
// //
// iX121SMCStrategy.AddXSignalEventHandler(OnSignalEventListener);
// //
// ConfigureStrategy(iX121SMCStrategy);
// RegisterStrategy(iX121SMCStrategy);
}
//
// Multi Symbol ...
else
{
//
// Parse Symbols ...
string symbols[];
int symbolsCount = SplitContent(
symbols,
Symbols() //
);
result = IsValidSize(symbolsCount);
if (!result)
{
return result;
}
//
for (int i = 0; i < symbolsCount; i++)
{
//
// Select Symbol ...
string iSymbol = symbols[i];
//
// Register Strategy Based On Symbol ...
//
// Parse Symbol ...
bool isEURUSD = _symbolParser.IsEURUSD(_Symbol);
bool isGBPUSD = _symbolParser.IsGBPUSD(_Symbol);
bool isEURGBP = _symbolParser.IsEURGBP(_Symbol);
bool isUSDCHF = _symbolParser.IsUSDCHF(_Symbol);
bool isEURCHF = _symbolParser.IsEURCHF(_Symbol);
bool isUSDJPY = _symbolParser.IsUSDJPY(_Symbol);
bool isEURJPY = _symbolParser.IsEURJPY(_Symbol);
bool isUSDCAD = _symbolParser.IsUSDCAD(_Symbol);
bool isEURCAD = _symbolParser.IsEURCAD(_Symbol);
bool isAUDUSD = _symbolParser.IsAUDUSD(_Symbol);
bool isEURAUD = _symbolParser.IsEURAUD(_Symbol);
bool isNZDUSD = _symbolParser.IsNZDUSD(_Symbol);
bool isEURNZD = _symbolParser.IsEURNZD(_Symbol);
//
// Check Symbol Can Register or not ...
bool canRegisterStrategy = true;
//
if (canRegisterStrategy)
{
// //
// // Create Class Instance ...
// XCX121SMCBaseStrategy *iX121SMCStrategy;
// iX121SMCStrategy = new XCX121SMCTestStrategy(
// iSymbol,
// _Period //
// );
// //
// iX121SMCStrategy.AddXSignalEventHandler(OnSignalEventListener);
// //
// // Register Strategy ...
// ConfigureStrategy(iX121SMCStrategy);
// RegisterStrategy(iX121SMCStrategy);
}
}
}
//
return result;
}
/**
* Destroy all Initialized EA Requirements ...
*/
void DestroyEA() override
{
//
delete mCTHelper;
delete mCCHelper;
// delete mTradeHandler;
//
// Clean(mStrategies);
}
/**
* Call all Registered Strategies On Tick ...
*/
void HandleStrategiesOnTick() override
{
//
ENUM_XPOI_EVENTS events[];
mPOIDetector.Update(events);
//
// int count = ArraySize(mStrategies);
// if (!IsValidSize(count))
// {
// return;
// }
// //
// for (int i = 0; i < count; i++)
// {
// //
// // Call Tick Handler Function ...
// mStrategies[i].HandleTick();
// }
}
//
// Event Handlers ...
/**
* Calls When a Position's SL Triggered ...
*
* @param deal: XDeal instance ...
*/
void HandleOnStopLossTriggered(const XDeal &deal) override
{
//
// Finish ...
// mTradeHandler.Finish(deal);
//
HandleReportBalance();
}
/**
* Calls When a Position's TP Triggered ...
*
* @param deal: XDeal instance ...
*/
void HandleOnTakeProfitTriggered(const XDeal &deal) override
{
//
// Finish ...
// mTradeHandler.Finish(deal);
//
HandleReportBalance();
}
/**
* Handle Force Close a Position ...
*
* @param ticket: Position Ticket ...
* @param position: XPosition ...
* @param comment: Closing Comment ...
*/
void HandleOnPositionForceClosed(
const ulong ticket,
const XPosition &position,
const string comment //
) override
{
//
// Finish ...
// mTradeHandler.Finish(
// ticket,
// position,
// comment //
// );
//
HandleReportBalance();
}
/**
* Reset All Paused Symbols on Each New Days ...
*/
void HandleOnNewDay() override
{
// mTradeHandler.ResumePausedSymbols();
}
/**
* Generate Identifier Tag ...
*
* @return ( string )
*/
string GetTag() override
{
//
string result = NULL;
//
string tagPrefix = TagPrefix();
if (IsValid(tagPrefix))
{
result = tagPrefix;
}
else
{
result = "";
}
//
result =
XCBaseExpertToken + result;
//
return result;
}
//
protected:
//
//
// Props ...
//
datetime mLastSignalOn;
//
XCPOIDetector *mPOIDetector;
//
// XC121SMCTradeHandler *mTradeHandler; // Trade Handler ...
// XCX121SMCBaseStrategy *mStrategies[]; // Registere Strategies in EA ...
//
// Actions ...
/**
* Apply Volume Based On Configurations on Signal ...
*
* @param signal: XSignal instance
*/
void ApplyVolumeOnSignal(XSignal &signal)
{
//
// Prepare Signal Dynamic Volume
// if Provided ...
if (UseDynamicVolume() &&
DynamicVolumeStep() > 0 &&
DynamicVolumeBalanceFactor() > 0)
{
//
double dVolume = mTrader.GetDynamicVolume(
signal.symbol,
DynamicVolumeBalanceFactor(),
DynamicVolumeStep() //
);
//
if (dVolume > 0)
{
signal.volume = dVolume;
}
else
{
signal.volume = Volume();
}
}
else
{
signal.volume = Volume();
}
//
// mTradeHandler.UpdateSignal(signal);
}
/**
* Configure Startegy ...
*/
// void ConfigureStrategy(XCX121SMCBaseStrategy *&strategy)
// {
// //
// if (strategy == NULL)
// {
// return;
// }
// //
// // Configure Alerts ...
// strategy.SetAlertPrefix(GetTag());
// strategy.SetAlertLogAlerts(GetAlertLogAlerts());
// strategy.SetAlertMailAlerts(GetAlertMailAlerts());
// strategy.SetAlertPushAlerts(GetAlertPushAlerts());
// strategy.SetAlertEnableAlerts(GetAlertEnableAlerts());
// strategy.SetAlertTerminalAlerts(GetAlertTerminalAlerts());
// //
// // Confiugre Signalling ...
// //
// strategy.R2R(2);
// strategy.AllowLong(AllowLong());
// strategy.AllowShort(AllowShort());
// //
// if (Disabled())
// {
// strategy.Disable();
// }
// else
// {
// strategy.Enable();
// }
// //
// }
/**
* Register an Strategy in EA ...
*
* @param strategy: XCX121SMCBaseStrategy instance ...
*/
// void RegisterStrategy(XCX121SMCBaseStrategy *strategy)
// {
// //
// if (strategy == NULL)
// {
// return;
// }
// //
// ArrayResize(
// mStrategies,
// ArraySize(mStrategies) + 1 //
// );
// //
// mStrategies[ArraySize(mStrategies) - 1] = strategy;
// }
/**
* Re Configure All Registered Strategies ...
*/
// void ReConfigureAllStrategies()
// {
// //
// int count = ArraySize(mStrategies);
// if (!IsValidSize(count))
// {
// return;
// }
// //
// for (int i = 0; i < count; i++)
// {
// //
// ConfigureStrategy(mStrategies[i]);
// }
// }
//
private:
//
//
// Props ...
//
// Volume Management ...
bool mUseDynamicVolume; // Use Dynamic Volume ...
double mDynamicVolumeStep; // Increase Volume Step ...
double mDynamicVolumeBalanceFactor; // Balance Factor for Generate Dynamic Volume ...
double mVolume; // Static Volume ...
//
};
//
@@ -1,752 +0,0 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCX3MAHelper
// Description: provides all Indicator
// Helper requirements ...
//
//
// 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.xhelper.class.mq5"
//
// Definitions ...
//
enum ENUM_X3MA_BUFFERS
{
//
X3MA_FAST_LINE = 0,
X3MA_MID_LINE = 1,
X3MA_SLOW_LINE = 2,
};
//
// Input Models ...
struct X3MAInputs
{
//
// Props ...
//
// Market ...
int fastLength; // Fast Length
int midLength; // Mid Length
int slowLength; // Slow Length
int shiftLength; // Shift
ENUM_MA_METHOD method; // Mode
ENUM_APPLIED_PRICE appliedTo; // Applied To
//
// Presentation ...
//
bool showFast; // Show Fast
bool showMid; // Show Mid
bool showSlow; // Show Slow
//
// Constructor(s) ...
X3MAInputs()
{
//
Clean();
}
//
// Tools ...
//
// Clean ...
void Clean()
{
//
fastLength = 0;
midLength = 0;
slowLength = 0;
shiftLength = 0;
method = MODE_SMA;
appliedTo = PRICE_CLOSE;
//
showFast = false;
showMid = false;
showSlow = false;
}
//
// Default ...
void Default()
{
//
fastLength = 50;
midLength = 100;
slowLength = 200;
shiftLength = 0;
method = MODE_SMA;
appliedTo = PRICE_CLOSE;
//
showFast = true;
showMid = true;
showSlow = true;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
fastLength > 2 &&
midLength > fastLength &&
slowLength > midLength &&
//
shiftLength >= 0
//
;
//
return result;
}
//
// Retrieve MAx Length ...
int Max()
{
//
int result = 0;
//
result = MathMax(fastLength, midLength);
result = MathMax(result, slowLength);
//
return result;
}
};
//
// Define Conditions ...
struct X3MAConditions
{
//
// Common ...
string symbol;
ENUM_TIMEFRAMES period;
datetime time;
//
// Buffers ...
//
double fasts[];
double mids[];
double slows[];
//
// Conditions ...
//
bool isFastOverMid;
bool isMidOverSlow;
//
bool isFastUnderMid;
bool isMidUnderSlow;
//
bool isBullishOrdered;
bool isBearishOrdered;
//
bool isSwitchedToBullishOrdered;
bool isSwitchedToBearishOrdered;
//
void Clean()
{
//
Clean(fasts);
Clean(mids);
Clean(slows);
//
ArraySetAsSeries(fasts, true);
ArraySetAsSeries(mids, true);
ArraySetAsSeries(slows, true);
//
isFastOverMid = false;
isMidOverSlow = false;
isFastUnderMid = false;
isMidUnderSlow = false;
isBullishOrdered = false;
isBearishOrdered = false;
isSwitchedToBullishOrdered = false;
isSwitchedToBearishOrdered = false;
}
//
void GenerateScore(
double &bullishScore,
double &bearishScore //
)
{
//
bullishScore = 0;
bearishScore = 0;
//
// Since We have to Use this
// Only for Filtering Signals ...
// We Can Ignore Scoring ...
// or Complete this later ...
}
//
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 scoresStr =
//
"Scores: " + separator +
"---------------" + separator +
"Bullish: " + ToString(bullishScore) + separator +
"Bearish: " + ToString(bearishScore) + separator +
""
//
;
//
string commonStr = GenerateSpecifiedCommonSummary(
this,
separator,
includeScores //
);
//
string conditionsStr =
//
""
//
;
//
result =
//
"[" + GetTag() + "]" + separator +
(onlyConditions
? ""
: commonStr) +
(!includeScores
? ""
: scoresStr) +
" " + separator +
(onlyCommons
? ""
: conditionsStr) +
""
//
;
//
return result;
}
//
string GetTag()
{
return "X3MA";
}
};
//
// Class ...
class XSCX3MAHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XSCX3MAHelper()
: XSCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XSCX3MAHelper()
{
//
Clean(fastBuffer);
Clean(midBuffer);
Clean(slowBuffer);
}
//
// Tools ...
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
X3MAInputs &inputs // Inputs
)
{
//
bool result = false;
//
mSymbol = symbol;
mPeriod = period;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
mInputs = inputs;
//
ArraySetAsSeries(fastBuffer, true);
ArraySetAsSeries(midBuffer, true);
ArraySetAsSeries(slowBuffer, true);
//
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.x3ma",
//
// Inputs ...
//
// Market ...
"",
mInputs.fastLength,
mInputs.midLength,
mInputs.slowLength,
mInputs.shiftLength,
mInputs.method,
mInputs.appliedTo,
//
// Presentation ...
"",
//
mInputs.showFast,
mInputs.showMid,
mInputs.showSlow
//
);
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
//
// Inputs ...
//
X3MAInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
X3MAInputs &inputs // Configs
)
{
//
return Init(
mSymbol,
mPeriod,
inputs
//
);
}
//
// Buffers ...
//
double GetFast(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(fastBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return fastBuffer[barIndex];
}
//
// Copy Required Items ...
int CopyFast(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
fastBuffer,
buffer,
forceClean
//
);
}
//
double GetMid(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(midBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return midBuffer[barIndex];
}
//
// Copy Required Items ...
int CopyMid(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
midBuffer,
buffer,
forceClean
//
);
}
//
double GetSlow(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(slowBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return slowBuffer[barIndex];
}
//
// Copy Required Items ...
int CopySlow(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
slowBuffer,
buffer,
forceClean
//
);
}
//
// Conditions ...
//
bool GetConditions(
X3MAConditions &conditions, //
int barIndex = 0, //
int loopback = 5 //
)
{
//
bool result = true;
//
if (loopback < 3)
{
loopback = 3;
}
//
conditions.Clean();
//
conditions.symbol = mSymbol;
conditions.period = mPeriod;
conditions.time = TimeCurrent();
//
int zIndex = barIndex;
int cIndex = zIndex + 1;
int pIndex = cIndex + 1;
int ppIndex = pIndex + 1;
//
// Buffers ...
//
// Fast ...
CopyFast(
zIndex,
loopback,
conditions.fasts //
);
//
// Mid ...
CopyMid(
zIndex,
loopback,
conditions.mids //
);
//
// Slow ...
CopySlow(
zIndex,
loopback,
conditions.slows //
);
//
// Conditions ...
//
bool isFastOverMid =
conditions.fasts[cIndex] > conditions.mids[cIndex];
bool isFastOverMidPrev =
conditions.fasts[pIndex] > conditions.mids[pIndex];
//
bool isMidOverSlow =
conditions.mids[cIndex] > conditions.slows[cIndex];
bool isMidOverSlowPrev =
conditions.mids[pIndex] > conditions.slows[pIndex];
//
bool isFastUnderMid =
conditions.fasts[cIndex] < conditions.mids[cIndex];
bool isFastUnderMidPrev =
conditions.fasts[pIndex] < conditions.mids[pIndex];
//
bool isMidUnderSlow =
conditions.mids[cIndex] < conditions.slows[cIndex];
bool isMidUnderSlowPrev =
conditions.mids[pIndex] < conditions.slows[pIndex];
//
bool isBullishOrdered = isFastOverMid &&
isMidOverSlow;
bool isBullishOrderedPrev = isFastOverMidPrev &&
isMidOverSlowPrev;
//
bool isBearishOrdered = isFastUnderMid &&
isMidUnderSlow;
bool isBearishOrderedPrev = isFastUnderMidPrev &&
isMidUnderSlowPrev;
//
bool isSwitchedToBullishOrdered = isBullishOrdered &&
!isBullishOrderedPrev;
bool isSwitchedToBearishOrdered = isBearishOrdered &&
!isBearishOrderedPrev;
//
conditions.isFastOverMid = isFastOverMid;
conditions.isMidOverSlow = isMidOverSlow;
conditions.isFastUnderMid = isFastUnderMid;
conditions.isMidUnderSlow = isMidUnderSlow;
conditions.isBullishOrdered = isBullishOrdered;
conditions.isBearishOrdered = isBearishOrdered;
conditions.isSwitchedToBullishOrdered = isSwitchedToBullishOrdered;
conditions.isSwitchedToBearishOrdered = isSwitchedToBearishOrdered;
//
return result;
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
X3MAInputs mInputs; // Inputs ...
//
// Buffers ...
double fastBuffer[];
double midBuffer[];
double slowBuffer[];
//
// Tools ...
//
// Calculate Values Until Now ...
void Calculate()
{
//
int totalBars = CountBars();
if (totalBars > 1000)
{
totalBars = 1000;
}
//
// Fast ...
CopyBuffer(
mHandler,
X3MA_FAST_LINE,
0,
totalBars,
fastBuffer
//
);
//
// Mid ...
CopyBuffer(
mHandler,
X3MA_MID_LINE,
0,
totalBars,
midBuffer
//
);
//
// Slow ...
CopyBuffer(
mHandler,
X3MA_SLOW_LINE,
0,
totalBars,
slowBuffer
//
);
}
};
//
File diff suppressed because it is too large Load Diff
-245
View File
@@ -1,245 +0,0 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXCCHelper
// Description: provides all Indicator
// Helper requirements ...
//
//
// 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.xhelper.class.mq5"
//
// Definitions ...
//
// Input Models ...
struct XCCInputs
{
//
// Props ...
//
// Chart Style ...
ENUM_CHART_MODE mode; // Mode
color upColor; // Up Color
color downColor; // Down Color
color lineColor; // Line mode and Doji candlestick Color
color bearishColor; // Bullish Color
color bullishColor; // Bearish Color
color volumesColor; // Volumes Color
//
// Presentation ...
bool showCandles; // Show Candles
//
// Constructor(s) ...
XCCInputs()
{
//
Clean();
}
//
// Tools ...
//
// Clean ...
void Clean()
{
//
mode = CHART_CANDLES;
//
upColor = CLR_NONE;
downColor = CLR_NONE;
lineColor = CLR_NONE;
bearishColor = CLR_NONE;
bullishColor = CLR_NONE;
volumesColor = CLR_NONE;
//
showCandles = false;
}
//
// Default ...
void Default()
{
//
mode = CHART_CANDLES;
//
upColor = clrLime;
downColor = clrRed;
lineColor = clrLime;
bearishColor = clrRed;
bullishColor = clrLime;
volumesColor = clrGreen;
//
showCandles = true;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
true
//
;
//
return result;
}
//
// Retrieve MAx Length ...
int Max()
{
//
int result = 0;
//
result = MathMax(0, 0);
//
return result;
}
};
//
// Class ...
class XSCXCCHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XSCXCCHelper() : XSCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XSCXCCHelper() {}
//
// Tools ...
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
XCCInputs &inputs // Inputs
)
{
//
bool result = false;
//
mSymbol = symbol;
mPeriod = period;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
mInputs = inputs;
//
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.xcc",
//
// Inputs ...
//
// Chart Style ...
"",
mInputs.mode, // Mode
mInputs.upColor, // Up Color
mInputs.downColor, // Down Color
mInputs.lineColor, // Line mode and Doji candlestick Color
mInputs.bearishColor, // Bullish Color
mInputs.bullishColor, // Bearish Color
mInputs.volumesColor, // Volumes Color
//
// Presentation ...
"",
mInputs.showCandles // Show Candles
//
);
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
//
// Inputs ...
//
XCCInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
XCCInputs &inputs // Configs
)
{
//
return Init(
mSymbol,
mPeriod,
inputs
//
);
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
XCCInputs mInputs; // Inputs ...
};
//
// Tools ...
-220
View File
@@ -1,220 +0,0 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXCTHelper
// Description: provides all Indicator
// Helper requirements ...
//
//
// 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.xhelper.class.mq5"
//
// Definitions ...
//
// Input Models ...
struct XCTInputs
{
//
// Props ...
//
color clr; // Text Color
ENUM_BASE_CORNER corner; // Text Position
//
// Presentation ...
bool showCandleTime; // Show Candle Time
//
// Constructor(s) ...
XCTInputs()
{
//
Clean();
}
//
// Tools ...
//
// Clean ...
void Clean()
{
//
clr = CLR_NONE;
corner = CORNER_RIGHT_LOWER;
//
// Presentation ...
showCandleTime = false;
}
//
// Default ...
void Default()
{
//
clr = clrYellow;
corner = CORNER_RIGHT_LOWER;
//
// Presentation ...
showCandleTime = true;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
true
//
;
//
return result;
}
//
// Retrieve MAx Length ...
int Max()
{
//
int result = 0;
//
result = MathMax(0, 0);
//
return result;
}
};
//
// Class ...
class XSCXCTHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XSCXCTHelper() : XSCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XSCXCTHelper() {}
//
// Tools ...
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
XCTInputs &inputs // Inputs
)
{
//
bool result = false;
//
mSymbol = symbol;
mPeriod = period;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
mInputs = inputs;
//
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.xct",
//
// Inputs ...
mInputs.clr, // Text Color
mInputs.corner, // Text Position
//
// Presentation ...
"",
mInputs.showCandleTime // Show Candle Time
//
);
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
//
// Inputs ...
//
XCTInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
XCTInputs &inputs // Configs
)
{
//
return Init(
mSymbol,
mPeriod,
inputs
//
);
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
XCTInputs mInputs; // Inputs ...
};
//
// Tools ...
-394
View File
@@ -1,394 +0,0 @@
///////////////////////////////////////////////////////
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------
// Name: X3MA
// Description: X3MA Trend Detector ...
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm X3MA Indicator"
#property strict
//
#define ShortName "X3MA"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
input int fastLength = 50; // Fast Length
input int midLength = 100; // Mid Length
input int slowLength = 200; // Slow Length
input int shiftLength = 0; // Shift
input ENUM_MA_METHOD method = MODE_SMA; // Mode
input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To
//
// Presentation ...
input group "Presentation";
//
// Parts ...
input bool showFast = true; // Show Fast
input bool showMid = true; // Show Mid
input bool showSlow = true; // Show Slow
//
// Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 3
#property indicator_plots 3
//
// Current ...
//
// Fast ...
#define fastBufferIndex 0
double fastBuffer[];
//
#property indicator_label1 "X3MA F"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrAqua
#property indicator_style1 STYLE_DOT
#property indicator_width1 1
//
// Mid ...
#define midBufferIndex 1
double midBuffer[];
//
#property indicator_label2 "X3MA M"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrOrange
#property indicator_style2 STYLE_DOT
#property indicator_width2 1
//
// Slow ...
#define slowBufferIndex 2
double slowBuffer[];
//
#property indicator_label3 "X3MA S"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrMagenta
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
//
// Variables ...
//
int maxLength;
//
// Handlers ...
int fastHandler = INVALID_HANDLE;
int midHandler = INVALID_HANDLE;
int slowHandler = INVALID_HANDLE;
//
// EVENT Handlers ...
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
if (!InitHandlers())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// because in some cases we may have more than one input for
// calculation and we must prevent any calculation
// untill we pass the biggest input length, here we get max Input length
// and then wait until pass it ...
maxLength = ExtractMaxLengthOfInputs();
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs changed by a user
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
// REASON_TEMPLATE 7 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
//
// Release Handlers ...
IndicatorRelease(fastHandler);
IndicatorRelease(midHandler);
IndicatorRelease(slowHandler);
}
//
// Calculating what we want ...
int OnCalculate(
const int rates_total, // Total Bars on Chart ...
const int prev_calculated, // Total Calculated Bars on Charts ...
const datetime &time[], // History of Open Time ...
const double &open[], // History of Open Price ...
const double &high[], // History of High Price ...
const double &low[], // History of Low Price ...
const double &close[], // History of Close Price ...
const long &tick_volume[], // History of Tick Volumes on Bar ...
const long &volume[], // History of Trade Volumes ...
const int &spread[] // History of Spread Price ...
)
{
//
ArraySetAsSeries(low, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(close, true);
//
// this counts Available Bars ...
int limit;
//
// Validate Calculated Bars ...
bool isPassedRequiredCalculatedBars =
//
BarsCalculated(fastHandler) >= maxLength &&
BarsCalculated(midHandler) >= maxLength &&
BarsCalculated(slowHandler) >= maxLength
//
;
if (!isPassedRequiredCalculatedBars)
{
return prev_calculated;
}
//
limit =
(prev_calculated > rates_total || prev_calculated <= 0)
? rates_total
: (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
//
int copiedFasts = CopyBuffer(fastHandler, 0, 0, limit, fastBuffer);
int copiedMids = CopyBuffer(midHandler, 0, 0, limit, midBuffer);
int copiedSlows = CopyBuffer(slowHandler, 0, 0, limit, slowBuffer);
//
// Validate Copied Items ...
bool isPassedRequiredCopiedItems =
//
copiedFasts > 0 &&
copiedMids > 0 &&
copiedSlows > 0
//
;
if (!isPassedRequiredCopiedItems)
{
return prev_calculated;
}
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
//
}
//
return rates_total;
}
//
// CUSTOM Functions ...
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result =
//
fastLength > 2 &&
midLength > fastLength &&
slowLength > midLength &&
//
shiftLength >= 0
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
// Current ...
result = MathMax(fastLength, midLength);
result = MathMax(result, slowLength);
//
return result;
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// Fast ...
bool canShowFast = showFast;
ENUM_DRAW_TYPE fastDrawType = canShowFast ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(fastBuffer, true);
SetIndexBuffer(fastBufferIndex, fastBuffer, INDICATOR_DATA);
PlotIndexSetDouble(fastBufferIndex, PLOT_EMPTY_VALUE, 0);
PlotIndexSetInteger(fastBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(fastBufferIndex, PLOT_SHOW_DATA, canShowFast);
PlotIndexSetInteger(fastBufferIndex, PLOT_DRAW_TYPE, fastDrawType);
//
// Mid ...
bool canShowMid = showMid;
ENUM_DRAW_TYPE midDrawType = canShowMid ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(midBuffer, true);
SetIndexBuffer(midBufferIndex, midBuffer, INDICATOR_DATA);
PlotIndexSetDouble(midBufferIndex, PLOT_EMPTY_VALUE, 0);
PlotIndexSetInteger(midBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(midBufferIndex, PLOT_SHOW_DATA, canShowMid);
PlotIndexSetInteger(midBufferIndex, PLOT_DRAW_TYPE, midDrawType);
//
// Slow ...
bool canShowSlow = showSlow;
ENUM_DRAW_TYPE slowDrawType = canShowSlow ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(slowBuffer, true);
SetIndexBuffer(slowBufferIndex, slowBuffer, INDICATOR_DATA);
PlotIndexSetDouble(slowBufferIndex, PLOT_EMPTY_VALUE, 0);
PlotIndexSetInteger(slowBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(slowBufferIndex, PLOT_SHOW_DATA, canShowSlow);
PlotIndexSetInteger(slowBufferIndex, PLOT_DRAW_TYPE, slowDrawType);
}
//
// Initial Indicator Handlers ...
bool InitHandlers()
{
//
bool result = false;
//
// Initialize Handlers ...
//
// Fast ...
fastHandler = iMA(
_Symbol,
_Period,
fastLength,
shiftLength,
method,
appliedTo //
);
//
// Mid ...
midHandler = iMA(
_Symbol,
_Period,
midLength,
shiftLength,
method,
appliedTo //
);
//
// Slow ...
slowHandler = iMA(
_Symbol,
_Period,
slowLength,
shiftLength,
method,
appliedTo //
);
//
result =
//
fastHandler != INVALID_HANDLE &&
midHandler != INVALID_HANDLE &&
slowHandler != INVALID_HANDLE
//
;
//
return result;
}
//
-564
View File
@@ -1,564 +0,0 @@
///////////////////////////////////////////////////////
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------
// Name: X3VWAP
// Description: X3VWAP Trend Detector ...
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm X3VWAP Indicator"
#property strict
//
#define ShortName "X3VWAP"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
input int fastLength = 50; // Fast Length
input int midLength = 100; // Mid Length
input int slowLength = 200; // Slow Length
input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To
//
// Presentation ...
input group "Presentation";
input bool showFast = true; // Show Fast
input bool showMid = true; // Show Mid
input bool showSlow = true; // Show Slow
//
// Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 11
#property indicator_plots 3
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
#define neuturalColorIDX 3
//
// Current ...
//
// Fast ...
#define fastBufferIndex 0
double fastBuffer[];
#define fastColorBufferIndex 1
double fastColorBuffer[];
//
#define fastPlotBufferIndex 0
#property indicator_label1 "X3VWAP F"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_style1 STYLE_DOT
#property indicator_width1 1
//
// Mid ...
#define midBufferIndex 2
double midBuffer[];
#define midColorBufferIndex 3
double midColorBuffer[];
//
#define midPlotBufferIndex 1
#property indicator_label2 "X3VWAP M"
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_color2 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_style2 STYLE_DOT
#property indicator_width2 1
//
// Slow ...
#define slowBufferIndex 4
double slowBuffer[];
#define slowColorBufferIndex 5
double slowColorBuffer[];
//
#define slowPlotBufferIndex 2
#property indicator_label3 "X3VWAP S"
#property indicator_type3 DRAW_COLOR_LINE
#property indicator_color3 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
//
// Data Buffers ...
//
// Volumes ...
#define volumeBufferIndex 6
double volumeBuffer[];
//
// Price ...
#define priceBufferIndex 7
double priceBuffer[];
//
// Fast State ...
#define fastStateBufferIndex 8
double fastStateBuffer[];
//
// Mid State ...
#define midStateBufferIndex 9
double midStateBuffer[];
//
// Slow State ...
#define slowStateBufferIndex 10
double slowStateBuffer[];
//
// Variables ...
//
int maxLength;
//
// EVENT Handlers ...
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// because in some cases we may have more than one input for
// calculation and we must prevent any calculation
// untill we pass the biggest input length, here we get max Input length
// and then wait until pass it ...
maxLength = ExtractMaxLengthOfInputs();
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs changed by a user
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
// REASON_TEMPLATE 7 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
}
//
// Calculating what we want ...
int OnCalculate(
const int rates_total, // Total Bars on Chart ...
const int prev_calculated, // Total Calculated Bars on Charts ...
const datetime &time[], // History of Open Time ...
const double &open[], // History of Open Price ...
const double &high[], // History of High Price ...
const double &low[], // History of Low Price ...
const double &close[], // History of Close Price ...
const long &tick_volume[], // History of Tick Volumes on Bar ...
const long &volume[], // History of Trade Volumes ...
const int &spread[] // History of Spread Price ...
)
{
//
ArraySetAsSeries(low, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);
//
// this counts Available Bars ...
int limit;
//
limit =
(prev_calculated > rates_total || prev_calculated <= 0)
? rates_total
: (rates_total - prev_calculated) + 1;
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
//
CalculateBuffers(
i,
prev_calculated,
rates_total,
//
open,
high,
close,
low,
tick_volume //
);
}
//
return rates_total;
}
//
// CUSTOM Functions ...
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result =
//
fastLength > 2 &&
midLength > fastLength &&
slowLength > midLength
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
// Current ...
result = MathMax(fastLength, midLength);
result = MathMax(result, slowLength);
//
return result;
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// Fast ...
ArraySetAsSeries(fastBuffer, true);
ArraySetAsSeries(fastColorBuffer, true);
SetIndexBuffer(fastBufferIndex, fastBuffer, INDICATOR_DATA);
SetIndexBuffer(fastColorBufferIndex, fastColorBuffer, INDICATOR_COLOR_INDEX);
//
// Mid ...
ArraySetAsSeries(midBuffer, true);
ArraySetAsSeries(midColorBuffer, true);
SetIndexBuffer(midBufferIndex, midBuffer, INDICATOR_DATA);
SetIndexBuffer(midColorBufferIndex, midColorBuffer, INDICATOR_COLOR_INDEX);
//
// Slow ...
ArraySetAsSeries(slowBuffer, true);
ArraySetAsSeries(slowColorBuffer, true);
SetIndexBuffer(slowBufferIndex, slowBuffer, INDICATOR_DATA);
SetIndexBuffer(slowColorBufferIndex, slowColorBuffer, INDICATOR_COLOR_INDEX);
//
// Data Buffers ...
//
// Volumes ...
ArraySetAsSeries(volumeBuffer, true);
SetIndexBuffer(volumeBufferIndex, volumeBuffer, INDICATOR_CALCULATIONS);
//
// Price ...
ArraySetAsSeries(priceBuffer, true);
SetIndexBuffer(priceBufferIndex, priceBuffer, INDICATOR_CALCULATIONS);
//
// Fast State ...
ArraySetAsSeries(fastStateBuffer, true);
SetIndexBuffer(fastStateBufferIndex, fastStateBuffer, INDICATOR_CALCULATIONS);
//
// Mid State ...
ArraySetAsSeries(midStateBuffer, true);
SetIndexBuffer(midStateBufferIndex, midStateBuffer, INDICATOR_CALCULATIONS);
//
// Slow State ...
ArraySetAsSeries(slowStateBuffer, true);
SetIndexBuffer(slowStateBufferIndex, slowStateBuffer, INDICATOR_CALCULATIONS);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
// Calculate Volumes and Price ...
//
if (ratesTotal - bar_index <= maxLength)
{
//
CalculateDataBuffers(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
return;
}
//
CalculateDataBuffers(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
//
CalculateVWAPS(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
}
//
// Calculate Required Data Buffers ...
void CalculateDataBuffers(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
double price = GetAppliedPrice(
appliedTo,
open,
high,
low,
close,
bar_index //
);
priceBuffer[bar_index] = price;
volumeBuffer[bar_index] = (double)tickVolume[bar_index];
}
//
// Calculate Different VWaps ...
void CalculateVWAPS(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
// Fast ...
CalculateVWAP(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
fastLength,
showFast,
fastBuffer,
fastColorBuffer,
fastStateBuffer //
);
//
// Mid ...
CalculateVWAP(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
midLength,
showMid,
midBuffer,
midColorBuffer,
midStateBuffer //
);
//
// Fast ...
CalculateVWAP(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
slowLength,
showSlow,
slowBuffer,
slowColorBuffer,
slowStateBuffer //
);
}
//
// Calculate VWAP ...
void CalculateVWAP(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[],
//
int _length, // Calculation Length
bool _show,
double &_buffer[],
double &_colorBuffer[],
double &_stateBuffer[] //
)
{
//
double vSum = 0;
double pSum = 0;
double mSum = 0;
for (int x = 0; x < _length; x++)
{
//
pSum += priceBuffer[x + bar_index];
vSum += volumeBuffer[x + bar_index];
mSum += priceBuffer[x + bar_index] * volumeBuffer[x + bar_index];
}
//
double iValue = mSum / vSum;
iValue = NormalizeDouble(iValue, _Digits);
//
_buffer[bar_index] = iValue;
//
bool isBullish = low[bar_index] > iValue;
bool isBearish = high[bar_index] < iValue;
//
double iColor =
isBullish
? bullishColorIDX
: isBearish
? bearishColorIDX
: neuturalColorIDX;
//
_colorBuffer[bar_index] = hideColorIDX;
_stateBuffer[bar_index] = iColor;
if (_show)
{
_colorBuffer[bar_index] = iColor;
}
}
//
-437
View File
@@ -1,437 +0,0 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Candle Styles
// ---------------------------------------------------
// Name: XCC
// Description: Candle Styles ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm XCC Indicator"
#property strict
//
// START Constants ...
//
//
// Indicator Short Name ...
#define ShortName "XCC"
//
// Holds an SnapShot of Charts Configuration ...
struct XChartStyle
{
//
// chart's ID ...
long chartId;
//
// chart's mode ...
ENUM_CHART_MODE mode;
//
// show bid line ...
bool showBidLine;
//
// show ask line ...
bool showAskLine;
//
// show grids on chart ...
bool showGrid;
//
// show volumes ...
bool showVolumes;
//
// Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders) ...
bool showTradeLevels;
//
// chart autoscroll ...
bool autoScroll;
//
// chart quick navigation state ...
bool quickNavigation;
//
// chart's foreground color ...
color foreGroundColor;
//
// chart's background color ...
color backGroundColor;
//
// Up Color ...
color upColor;
//
// Down Color ...
color downColor;
//
// Bullish color ...
color bullishColor;
//
// Bearish color ...
color bearishColor;
//
// grid color ...
color gridColor;
//
// bid line color ...
color bidLineColor;
//
// ask line color ...
color askLineColor;
//
// line mode and doji candlestick color ...
color lineColor;
//
// Color of stop order levels (Stop Loss and Take Profit) ...
color stopColor;
//
// volumes color ...
color volumesColor;
};
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Chart Style";
input ENUM_CHART_MODE mode = CHART_CANDLES; // Mode
input color upColor = clrLime; // Up Color
input color downColor = clrRed; // Down Color
input color lineColor = clrLime; // Line mode and Doji candlestick Color
input color bearishColor = clrRed; // Bullish Color
input color bullishColor = clrLime; // Bearish Color
input color volumesColor = clrGreen; // Volumes Color
//
input group "Presentation";
input bool showCandles = true; // Show Candles
//
// END Inputs ...
//
//
// START Includes and Imports ...
//
//
// Includes Draw Library ...
#include "../Libraries/x-saherelm.draw.lib.mq5"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes and Imports ...
//
//
// START Buffers ...
//
//
#property indicator_chart_window
//
#property indicator_buffers 0
#property indicator_plots 0
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
XChartStyle chartStyle;
XChartStyle clearStyle;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
drawPrefix = ShortName;
//
// because in some cases we may have more than one input for
// calculation and we must prevent any calculation
// untill we pass the biggest input length, here we get max Input length
// and then wait until pass it ...
maxLength = ExtractMaxLengthOfInputs();
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// Apply Chart Style ...
ApplyCustomChartStyle();
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs changed by a user
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
// REASON_TEMPLATE 7 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
}
//
// Calculating what we want ...
int OnCalculate(
const int rates_total, // Total Bars on Chart ...
const int prev_calculated, // Total Calculated Bars on Charts ...
const datetime &time[], // History of Open Time ...
const double &open[], // History of Open Price ...
const double &high[], // History of High Price ...
const double &low[], // History of Low Price ...
const double &close[], // History of Close Price ...
const long &tick_volume[], // History of Tick Volumes on Bar ...
const long &volume[], // History of Trade Volumes ...
const int &spread[] // History of Spread Price ...
)
{
//
// Prepare Buffers ...
ArraySetAsSeries(time, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);
ArraySetAsSeries(volume, true);
ArraySetAsSeries(spread, true);
//
// this counts Available Bars ...
int limit;
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
CalculateBuffers(i);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = true;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index // Selected Bar Index
)
{
}
//
// Apply Custom Chart Style ...
void ApplyCustomChartStyle()
{
//
// Read Current Chart Config and Store it ...
ReadChartStyle();
//
// After Reading Current Chart Style ...
// we have to Save Configs and Change Styles ...
clearStyle = chartStyle;
//
clearStyle.upColor = CLR_NONE;
clearStyle.downColor = CLR_NONE;
clearStyle.lineColor = CLR_NONE;
clearStyle.bullishColor = CLR_NONE;
clearStyle.bearishColor = CLR_NONE;
//
// Decide to Show or not Candles based on User Input ...
if (showCandles)
{
SetChartStyle(chartStyle);
}
else
{
SetChartStyle(clearStyle);
}
}
//
// Read Previous Chart Style ...
void ReadChartStyle()
{
//
// Retrieve Current Chart ID ...
long chartId = ChartID();
chartStyle.chartId = chartId;
//
// Retrieve Chart Mode ...
chartStyle.mode = (ENUM_CHART_MODE)ChartGetInteger(chartId, CHART_MODE);
//
chartStyle.showBidLine = (bool)ChartGetInteger(chartId, CHART_SHOW_BID_LINE);
chartStyle.showAskLine = (bool)ChartGetInteger(chartId, CHART_SHOW_ASK_LINE);
chartStyle.showGrid = (bool)ChartGetInteger(chartId, CHART_SHOW_GRID);
chartStyle.showVolumes = (bool)ChartGetInteger(chartId, CHART_SHOW_VOLUMES);
chartStyle.showTradeLevels = (bool)ChartGetInteger(chartId, CHART_SHOW_TRADE_LEVELS);
chartStyle.autoScroll = (bool)ChartGetInteger(chartId, CHART_AUTOSCROLL);
chartStyle.quickNavigation = (bool)ChartGetInteger(chartId, CHART_QUICK_NAVIGATION);
//
chartStyle.foreGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_FOREGROUND);
chartStyle.backGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_BACKGROUND);
chartStyle.upColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_UP);
chartStyle.downColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_DOWN);
chartStyle.bullishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BULL);
chartStyle.bearishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BEAR);
chartStyle.gridColor = (color)ChartGetInteger(chartId, CHART_COLOR_GRID);
chartStyle.bidLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_BID);
chartStyle.askLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_ASK);
chartStyle.stopColor = (color)ChartGetInteger(chartId, CHART_COLOR_STOP_LEVEL);
chartStyle.lineColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_LINE);
chartStyle.volumesColor = (color)ChartGetInteger(chartId, CHART_COLOR_VOLUME);
//
chartStyle.mode = mode;
chartStyle.upColor = upColor;
chartStyle.downColor = downColor;
chartStyle.lineColor = lineColor;
chartStyle.bearishColor = bearishColor;
chartStyle.bullishColor = bullishColor;
chartStyle.volumesColor = volumesColor;
}
//
// Set Chart Style ...
void SetChartStyle(
XChartStyle &mChartStyle // Chart Style to Apply
)
{
//
ApplyChartStyle(
mChartStyle.chartId,
mChartStyle.mode,
mChartStyle.showBidLine,
mChartStyle.showAskLine,
mChartStyle.showGrid,
mChartStyle.showVolumes,
mChartStyle.showTradeLevels,
mChartStyle.autoScroll,
mChartStyle.quickNavigation,
mChartStyle.foreGroundColor,
mChartStyle.backGroundColor,
mChartStyle.upColor,
mChartStyle.downColor,
mChartStyle.bullishColor,
mChartStyle.bearishColor,
mChartStyle.gridColor,
mChartStyle.bidLineColor,
mChartStyle.askLineColor,
mChartStyle.lineColor,
mChartStyle.stopColor,
mChartStyle.volumesColor);
}
//
// END Functions ...
//
-270
View File
@@ -1,270 +0,0 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// ---------------------------------------------
// Name: XCT
// Description: Trend Magic Indicator ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm XCT Indicator"
#property strict
//
// START Constants ...
//
//
#define ShortName "XCT"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Constants ...
//
//
// START Inputs ...
//
//
input color clr = clrYellow; // Text Color
input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER; // Text Position
//
input group "Presentation";
input bool showCandleTime = true; // Show Candle Time
//
// END Inputs ...
//
//
// START Buffers ...
//
//
#property indicator_chart_window
//
#property indicator_buffers 0
#property indicator_plots 0
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (showCandleTime)
{
CreateIndicatorObject();
}
else
{
ObjectDelete(0, ShortName);
}
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs changed by a user
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
// REASON_TEMPLATE 7 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
//
ulong chID = FindChartID(
_Symbol,
_Period
//
);
//
// Delete Object ...
ObjectDelete(chID, ShortName);
//
Comment("");
}
//
// Calculating what we want ...
int OnCalculate(
const int rates_total, // Total Bars on Chart ...
const int prev_calculated, // Total Calculated Bars on Charts ...
const datetime &time[], // History of Open Time ...
const double &open[], // History of Open Price ...
const double &high[], // History of High Price ...
const double &low[], // History of Low Price ...
const double &close[], // History of Close Price ...
const long &tick_volume[], // History of Tick Volumes on Bar ...
const long &volume[], // History of Trade Volumes ...
const int &spread[] // History of Spread Price ...
)
{
//
ArraySetAsSeries(time, true);
//
if (!showCandleTime)
{
return rates_total;
}
//
ulong chID = FindChartID(
_Symbol,
_Period
//
);
//
XBarRemainsTime barRemains;
barRemains.Init(
_Symbol,
_Period
//
);
//
string msg = barRemains
.ToString(
"",
"",
"",
"",
"",
":",
true
//
);
//
long mSpread = SymbolInfoInteger(Symbol(), SYMBOL_SPREAD);
//
string _sp = "";
if (mSpread < 10)
_sp = "..";
else if (mSpread < 100)
_sp = ".";
//
// int offset = TimeGMTOffset();
// string timeString =
// ", Time: " + string(TimeCurrent()) + "\n" +
// ", ServerTime: " + string(TimeTradeServer()) + "\n" +
// ", GMT Offset: " + (string)offset;
// timeString = timeString;
// Comment(timeString);
//
string objText = "Spread: " + IntegerToString(mSpread) + _sp + ", Next Bar in: " + msg;
//
ObjectSetInteger(chID, ShortName, OBJPROP_COLOR, clr);
ObjectSetString(chID, ShortName, OBJPROP_TEXT, objText);
ObjectSetInteger(chID, ShortName, OBJPROP_FONTSIZE, 10);
ObjectSetString(chID, ShortName, OBJPROP_FONT, "Courier");
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
void CreateIndicatorObject()
{
//
if (!showCandleTime)
{
return;
}
//
ObjectCreate(0, ShortName, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, ShortName, OBJPROP_CORNER, corner);
ObjectSetInteger(0, ShortName, OBJPROP_XDISTANCE, 10);
ObjectSetInteger(0, ShortName, OBJPROP_YDISTANCE, 2);
//
ENUM_ANCHOR_POINT Anchor = ANCHOR_LEFT_UPPER;
switch (corner)
{
case CORNER_LEFT_UPPER:
Anchor = ANCHOR_LEFT_UPPER;
break;
case CORNER_RIGHT_UPPER:
Anchor = ANCHOR_RIGHT_UPPER;
break;
case CORNER_LEFT_LOWER:
Anchor = ANCHOR_LEFT_LOWER;
break;
case CORNER_RIGHT_LOWER:
Anchor = ANCHOR_RIGHT_LOWER;
break;
}
//
ObjectSetInteger(0, ShortName, OBJPROP_ANCHOR, Anchor);
}
//
// END Functions ...
//
-856
View File
@@ -1,856 +0,0 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Seriallize Library
// ---------------------------------------
// Name: X121SMCLib
// Description: All models related to X121SMC ...
//
//
// 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.xtrade.lib.mq5"
//
// Definitions ...
//
// Specific Identifier(s) of XStrategy ...
string X121SMCStrategyToken = "X121SMC";
string X121SMCOBStrategyToken = "X121SMCOB";
string X121SMCSUPDEMStrategyToken = "X121SMCSUPDEM";
string X121SMCConditionsToken = "X121SMCConditions";
string X121SMCMarketStructureToken = "X121SMCMarketStructure";
//
// Condition Structure ...
struct X121SMCStrategyConditions
{
//
// Props ...
//
// Common ...
string symbol;
ENUM_TIMEFRAMES period;
datetime time;
//
// Conditions ...
//
XOHCL swingHigh;
XZone supplyZone;
XZone bearishFVG;
XOHCL resistance;
XZone bearishOrderBlock;
XOHCL bullishMomentumBar;
XOHCL bullishRejectionBar;
//
XZone demandZones[];
XZone bearishFVGs[];
XZone bearishOrderBlocks[];
XOHCL swingHighs[];
XOHCL resistances[];
XOHCL bearishMomentumBars[];
XOHCL bearishRejectionBars[];
//
XOHCL support;
XOHCL swingLow;
XZone demandZone;
XZone bullishFVG;
XZone bullishOrderBlock;
XOHCL bearishMomentumBar;
XOHCL bearishRejectionBar;
//
XZone supplyZones[];
XZone bullishFVGs[];
XZone bullishOrderBlocks[];
XOHCL supports[];
XOHCL swingLows[];
XOHCL bullishMomentumBars[];
XOHCL bullishRejectionBars[];
//
// Constructor ...
void XStrategyConditions()
{
Clean();
}
//
// Tools ...
/**
* Cleanup ...
*/
void Clean()
{
//
symbol = NULL;
period = NULL;
time = NULL;
//
CleanDemand();
CleanSupply();
}
/**
* Cleanup Demand Related ...
*/
void CleanDemand()
{
//
support.Clean();
swingLow.Clean();
demandZone.Clean();
bullishFVG.Clean();
bullishOrderBlock.Clean();
bullishMomentumBar.Clean();
bullishRejectionBar.Clean();
//
Clean(supports);
Clean(swingLows);
Clean(supplyZones);
Clean(bullishFVGs);
Clean(bullishOrderBlocks);
Clean(bullishMomentumBars);
Clean(bullishRejectionBars);
}
/**
* Cleanup Supply Related ...
*/
void CleanSupply()
{
//
swingHigh.Clean();
supplyZone.Clean();
bearishFVG.Clean();
resistance.Clean();
bearishOrderBlock.Clean();
bearishMomentumBar.Clean();
bearishRejectionBar.Clean();
//
Clean(swingHighs);
Clean(demandZones);
Clean(bearishFVGs);
Clean(resistances);
Clean(bearishOrderBlocks);
Clean(bearishMomentumBars);
Clean(bearishRejectionBars);
}
/**
* Validate Demand ...
*
* @return ( bool )
*/
bool ValidateDemand()
{
//
bool result = false;
//
result = IsValid();
if (!result)
{
return result;
}
//
result =
//
support.IsValid() &&
swingLow.IsValid() &&
demandZone.IsValid() &&
bullishFVG.IsValid() &&
bullishOrderBlock.IsValid() &&
bullishMomentumBar.IsValid() &&
bullishRejectionBar.IsValid() &&
//
(ArraySize(supports) > 0 ||
ArraySize(swingLows) > 0 ||
ArraySize(supplyZones) > 0 ||
ArraySize(bullishFVGs) > 0 ||
ArraySize(bullishOrderBlocks) > 0 ||
ArraySize(bullishMomentumBars) > 0 ||
ArraySize(bullishRejectionBars) > 0)
//
;
//
return result;
}
/**
* Validate Supply ...
*
* @return ( bool )
*/
bool ValidateSupply()
{
//
bool result = false;
//
result = IsValid();
if (!result)
{
return result;
}
//
result =
//
swingHigh.IsValid() &&
supplyZone.IsValid() &&
bearishFVG.IsValid() &&
resistance.IsValid() &&
bearishOrderBlock.IsValid() &&
bearishMomentumBar.IsValid() &&
bearishRejectionBar.IsValid() &&
//
(ArraySize(swingHighs) > 0 ||
ArraySize(demandZones) > 0 ||
ArraySize(bearishFVGs) > 0 ||
ArraySize(resistances) > 0 ||
ArraySize(bearishOrderBlocks) > 0 ||
ArraySize(bearishMomentumBars) > 0 ||
ArraySize(bearishRejectionBars) > 0)
//
;
//
return result;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
IsValid(time) &&
IsValid(symbol) &&
IsValid(period)
//
;
//
return result;
}
//
// Generate Provided Scores ...
void GenerateScore(
double &bullishScore,
double &bearishScore //
)
{
//
bullishScore = 0;
bearishScore = 0;
//
if (!IsValid())
{
return;
}
//
double bullScore = 0;
double bearScore = 0;
//
// Generate Helpers Conitions Scores ...
}
//
// Generate Summary ...
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 //
);
//
// Generate Helpers Conditions Strings ...
//
// Combine Helpers Conditions Strings ...
string conditionsStr =
//
"" + separator +
""
//
;
//
result =
//
"[" + GetTag() + "]" + separator +
"----------" + separator +
(onlyConditions
? ""
: commonStr) +
" " + separator +
(onlyCommons
? ""
: conditionsStr) +
""
//
;
//
return result;
}
//
string GetTag(
bool fullTag = false //
)
{
//
string result = NULL;
//
if (!IsValid())
{
return result;
}
//
if (fullTag)
{
//
result =
//
symbol + "," +
ToString(period) + "," +
ToFormatString(time) + "_" +
demandZone.GetTag() + "," +
supplyZone.GetTag() + "_" +
bullishOrderBlock.GetTag() + "," +
bearishOrderBlock.GetTag()
//
;
//
result = X121SMCConditionsToken + "_" + ToMD5(result);
}
else
{
result = X121SMCConditionsToken;
}
//
return result;
}
//
};
//
// Market Structure Models ...
struct X121SMCMarketStructure
{
//
XZone demandZone;
XZone supplyZone;
//
XZone bullishOrderBlock;
XZone bearishOrderBlock;
//
XZone demandZones[];
XZone supplyZones[];
//
XZone bearishOrderBlocks[];
XZone bearishFVGs[];
//
XOHCL swingHighs[];
XOHCL resistances[];
XOHCL bearishMomentumBars[];
XOHCL bearishRejectionBars[];
//
XZone bullishOrderBlocks[];
XZone bullishFVGs[];
//
XOHCL supports[];
XOHCL swingLows[];
XOHCL bullishMomentumBars[];
XOHCL bullishRejectionBars[];
//
void Clean()
{
//
demandZone.Clean();
supplyZone.Clean();
//
Clean(supports);
Clean(swingLows);
Clean(swingHighs);
Clean(demandZones);
Clean(supplyZones);
Clean(bearishFVGs);
Clean(resistances);
Clean(bullishFVGs);
Clean(bearishOrderBlocks);
Clean(bullishOrderBlocks);
Clean(bearishMomentumBars);
Clean(bearishRejectionBars);
Clean(bullishMomentumBars);
Clean(bullishRejectionBars);
}
//
string GetTag()
{
//
string result = NULL;
//
result =
//
demandZone.GetTag() + "," +
supplyZone.GetTag() + "_" +
bullishOrderBlock.GetTag() + "," +
bearishOrderBlock.GetTag()
//
;
result = X121SMCMarketStructureToken + "_" + ToMD5(X121SMCMarketStructureToken);
//
return result;
}
};
//
// On Signal Event Handler ...
typedef void (*TOnX121SMCSignal)(
XSignal &signal,
X121SMCStrategyConditions &conditions //
);
//
struct XRange
{
//
string symbol;
ENUM_TIMEFRAMES period;
//
double upper;
double lower;
//
datetime from;
datetime to;
//
void XRange()
{
Clean();
}
//
// Tools ...
/**
* Initial ...
*
* @param _symbol: String ...
* @param _period: ENUM_TIMEFRAMES member ...
* @param _upper: Double ...
* @param _lower: Double ...
* @param _from: DateTime ...
* @param _to: DateTime ...
*
* @return ( bool )
*/
bool Init(
string _symbol,
ENUM_TIMEFRAMES _period,
double _upper,
double _lower,
datetime _from,
datetime _to //
)
{
//
bool result = false;
//
result =
//
IsValid(_symbol) &&
IsValid(_period) &&
IsValid(_from) &&
IsValid(_to) &&
_upper > 0 &&
_lower > 0 &&
_to > _from
//
;
//
symbol = _symbol;
period = _period;
//
upper = _upper;
lower = _lower;
//
from = _from;
to = _to;
//
result = IsValid();
//
return result;
}
/**
* Cleanup ...
*/
void Clean()
{
//
symbol = NULL;
period = NULL;
//
upper = 0;
lower = 0;
//
from = NULL;
to = NULL;
}
/**
* Validate ...
*
* @return ( bool )
*/
bool IsValid()
{
//
bool result = false;
//
result =
//
IsValid(symbol) &&
IsValid(period) &&
IsValid(from) &&
IsValid(to) &&
upper > 0 &&
lower > 0 &&
to > from
//
;
//
return result;
}
/**
* Generate Unique Tag ...
*
* @return ( string )
*/
string GetTag()
{
//
string result = NULL;
//
string hash =
ToString(upper) + "," +
ToString(lower) +
ToFormatString(from);
hash = ToMD5(hash);
//
result =
//
"XRNG_" + symbol + "_" +
ToString(period) + "_" +
hash
//
;
//
return result;
}
/**
* Generate Tooltip ...
*
* @return ( string )
*/
string GetTooltip()
{
//
string result = NULL;
//
result =
//
"XRNG" + "\n" +
symbol + "\n" +
ToString(period) + "\n" +
ToString(from) + "\n" +
ToString(to)
//
;
//
return result;
}
//
};
//
struct XRangeStructure
{
//
XRange range;
//
XZone demandZones[];
XZone supplyZones[];
//
XZone bearishOrderBlocks[];
XZone bearishFVGs[];
//
XOHCL swingHighs[];
XOHCL resistances[];
XOHCL bearishMomentumBars[];
XOHCL bearishRejectionBars[];
//
XZone bullishOrderBlocks[];
XZone bullishFVGs[];
//
XOHCL supports[];
XOHCL swingLows[];
XOHCL bullishMomentumBars[];
XOHCL bullishRejectionBars[];
//
// Constructor ...
void XRangeStructure()
{
Clean();
}
//
// Tools ...
/**
* Cleanup ...
*/
void Clean()
{
//
range.Clean();
//
Clean(supports);
Clean(swingLows);
Clean(swingHighs);
Clean(demandZones);
Clean(supplyZones);
Clean(bearishFVGs);
Clean(resistances);
Clean(bullishFVGs);
Clean(bearishOrderBlocks);
Clean(bullishOrderBlocks);
Clean(bearishMomentumBars);
Clean(bearishRejectionBars);
Clean(bullishMomentumBars);
Clean(bullishRejectionBars);
}
/**
* Validate ...
*
* @return ( bool )
*/
bool IsValid()
{
//
bool result = false;
//
result = range.IsValid();
if (!result)
{
return result;
}
//
result =
//
ArraySize(supports) > 0 ||
ArraySize(swingLows) > 0 ||
ArraySize(swingHighs) > 0 ||
ArraySize(demandZones) > 0 ||
ArraySize(supplyZones) > 0 ||
ArraySize(bearishFVGs) > 0 ||
ArraySize(resistances) > 0 ||
ArraySize(bullishFVGs) > 0 ||
ArraySize(bearishOrderBlocks) > 0 ||
ArraySize(bullishOrderBlocks) > 0 ||
ArraySize(bearishMomentumBars) > 0 ||
ArraySize(bearishRejectionBars) > 0 ||
ArraySize(bullishMomentumBars) > 0 ||
ArraySize(bullishRejectionBars) > 0
//
;
//
return result;
}
/**
* Generate Tag ...
*
* @return ( string )
*/
string GetTag()
{
//
string result = NULL;
//
string hash = range.GetTag();
hash = ToMD5(hash);
//
result = X121SMCMarketStructureToken + "_" + hash;
//
return result;
}
};
/**
* Check a Zone is Between to other Zones ...
*
* @param source: XZone instance ...
* @param upper: XZone instance ...
* @param lower: XZone instance ...
*
* @return ( bool )
*/
bool IsBetween(
XZone &source,
XRange &range //
)
{
//
bool result = false;
//
result = source.IsValid() &&
range.IsValid();
if (!result)
{
return result;
}
//
result = source.upper <= range.upper &&
source.lower >= range.lower;
//
return result;
}
bool IsBetween(
XOHCL &source,
XRange &range //
)
{
//
bool result = false;
//
result = source.IsValid() &&
range.IsValid();
if (!result)
{
return result;
}
//
result = source.high <= range.upper &&
source.low >= range.lower;
//
return result;
}
//
Binary file not shown.