Backup Workspace ...
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,35 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "../../Classes/x-saherelm.x-cobject.class.mq5"
|
||||
#include "../Libraries/x-121.smc.lib.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
enum ENUM_X121SMC_CHARTOBJECTS
|
||||
{
|
||||
X_121_NONE_OBJ
|
||||
};
|
||||
|
||||
//
|
||||
// Implementations ...
|
||||
@@ -0,0 +1,63 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// --------------------------------------
|
||||
// Name: XC121Panel
|
||||
// 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-app-dialog.class.mq5"
|
||||
|
||||
//
|
||||
// Implementation ...
|
||||
|
||||
//
|
||||
class X121CAppDialog : public XCAppDialog
|
||||
{
|
||||
//
|
||||
public:
|
||||
//
|
||||
// Constructor(s) ...
|
||||
void X121CAppDialog()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~X121CAppDialog()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
void Configure()
|
||||
{
|
||||
//
|
||||
// Configure Dialog ...
|
||||
BackgroundColor(clrBlack);
|
||||
}
|
||||
|
||||
//
|
||||
protected:
|
||||
//
|
||||
|
||||
//
|
||||
private:
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
@@ -0,0 +1,779 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// --------------------------------------
|
||||
// Name: XC121SMCCycleHelper
|
||||
// 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-bar.analyser.class.mq5"
|
||||
#include "../../Classes/x-saherelm.x-poi.class.mq5"
|
||||
#include "../Libraries/x-121.smc.lib.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Implementations ...
|
||||
|
||||
enum ENUM_X_CYCLES
|
||||
{
|
||||
X_CYCLE_NONE,
|
||||
X_CYCLE_TRIGGER,
|
||||
X_CYCLE_DECISION,
|
||||
X_CYCLE_ANALYSE,
|
||||
X_CYCLE_VERIFICATION,
|
||||
X_CYCLE_CONSOLIDATION,
|
||||
X_CYCLE_VISION,
|
||||
};
|
||||
|
||||
string ToString(ENUM_X_CYCLES value)
|
||||
{
|
||||
//
|
||||
string result = EnumToString(value);
|
||||
|
||||
//
|
||||
StringReplace(result, "X_CYCLE_", "");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
enum ENUM_X_CYCLE_EVENTS
|
||||
{
|
||||
SAR_CHANGE_DETECTED,
|
||||
NEW_PEAK_DETECTED,
|
||||
NEW_VALE_DETECTED,
|
||||
PIVOT_POINT_DETECTED,
|
||||
VWAP_ORDER_CHANGE_ETECTED,
|
||||
VWAP_STATE_CHANGE_DETCTED,
|
||||
CONSOLIDATION_BREAKED_DETECTED,
|
||||
PEAK_PIVOT_STARTED,
|
||||
PEAK_PIVOT_ENDED,
|
||||
VALE_PIVOT_STARTED,
|
||||
VALE_PIVOT_ENDED,
|
||||
};
|
||||
|
||||
class XC121SMCCycleHelper : public XCBase
|
||||
{
|
||||
//
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// X121 ...
|
||||
XCX121Helper *mX121Helper;
|
||||
|
||||
//
|
||||
// POI Detector ...
|
||||
XCPOIDrawer *mPOIDrawer;
|
||||
XCPOIDetector *mPOIDetector;
|
||||
|
||||
//
|
||||
// Bar Analyser
|
||||
XCBarAnalyser *mBarAnalyser;
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
XC121SMCCycleHelper()
|
||||
{
|
||||
Default();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XC121SMCCycleHelper()
|
||||
{
|
||||
DeInit();
|
||||
}
|
||||
|
||||
//
|
||||
// Getter/Setter(s) ...
|
||||
|
||||
//
|
||||
// Actions ...
|
||||
|
||||
/**
|
||||
* Initialize ...
|
||||
*
|
||||
* @param symbol: String ...
|
||||
* @param period: ENUM_TIMEFRAMES member ...
|
||||
* @param x121Inputs: X121Inputs instance ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool Init(
|
||||
string symbol,
|
||||
ENUM_TIMEFRAMES period,
|
||||
X121Inputs &x121Inputs,
|
||||
int requiredPOIS = 50 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (requiredPOIS < 10)
|
||||
{
|
||||
requiredPOIS = 10;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValid(symbol) &&
|
||||
IsValid(period);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// X121 ...
|
||||
mX121Helper = new XCX121Helper();
|
||||
result = mX121Helper.Init(
|
||||
symbol,
|
||||
period,
|
||||
x121Inputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mPOIDetector = new XCPOIDetector(
|
||||
symbol,
|
||||
period //
|
||||
);
|
||||
mPOIDetector.MaxNumberOfRequiredPOIs(requiredPOIS);
|
||||
mPOIDetector.Init();
|
||||
|
||||
//
|
||||
// Initialize Bar Analyser Class Instance ...
|
||||
mBarAnalyser = new XCBarAnalyser();
|
||||
|
||||
//
|
||||
// Initial and Configure POI Drawer if Required ...
|
||||
mPOIDrawer = new XCPOIDrawer();
|
||||
mPOIDrawer.ChartIdentification(0);
|
||||
mPOIDrawer.SubWindowIdentification(0);
|
||||
|
||||
//
|
||||
mPOIDrawer.DemandZoneFill(false);
|
||||
mPOIDrawer.SupplyZoneFill(false);
|
||||
mPOIDrawer.BullishFVGFill(false);
|
||||
mPOIDrawer.BearishFVGFill(false);
|
||||
mPOIDrawer.SupportZoneFill(false);
|
||||
mPOIDrawer.ResistanceZoneFill(false);
|
||||
mPOIDrawer.BullishOrderBlockFill(false);
|
||||
mPOIDrawer.BearishOrderBlockFill(false);
|
||||
|
||||
//
|
||||
// Set Chart Style ...
|
||||
ApplyChartStyle();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Symbol ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GetSymbol()
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
result = mX121Helper.GetSymbol();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve TimeFrame (Period) ...
|
||||
*
|
||||
* @return ( ENUM_TIMEFRAMES )
|
||||
*/
|
||||
ENUM_TIMEFRAMES GetPeriod()
|
||||
{
|
||||
//
|
||||
ENUM_TIMEFRAMES result = NULL;
|
||||
|
||||
//
|
||||
result = mX121Helper.GetPeriod();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Specified Bar ...
|
||||
*
|
||||
* @param source: XOHCL instance, Source Bar ...
|
||||
* @param bar: XOHCL instance, Dest Bar ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool GetBar(
|
||||
XOHCL &source,
|
||||
XOHCL &bar //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bar.Clean();
|
||||
|
||||
//
|
||||
string symbol = GetSymbol();
|
||||
ENUM_TIMEFRAMES period = GetPeriod();
|
||||
|
||||
//
|
||||
result =
|
||||
IsValid(symbol) &&
|
||||
IsValid(period) &&
|
||||
source.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int index = iBarShift(
|
||||
symbol,
|
||||
period,
|
||||
source.time //
|
||||
);
|
||||
result = bar.Init(
|
||||
symbol,
|
||||
period,
|
||||
index //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
bar.Clean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Specified Bar ...
|
||||
*
|
||||
* @param bar: XOHCL instance ...
|
||||
* @param index: Integer ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool GetBar(
|
||||
XOHCL &bar,
|
||||
int index = 0 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bar.Clean();
|
||||
|
||||
//
|
||||
if (index < 0)
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
|
||||
//
|
||||
string symbol = GetSymbol();
|
||||
ENUM_TIMEFRAMES period = GetPeriod();
|
||||
|
||||
//
|
||||
result = bar.Init(
|
||||
symbol,
|
||||
period,
|
||||
index //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Specified Bar ...
|
||||
*
|
||||
* @param bar: XOHCL instance ...
|
||||
* @param time: Datetime ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool GetBar(
|
||||
XOHCL &bar,
|
||||
datetime time = NULL //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
int index = GetBarIndex(time);
|
||||
result = GetBar(bar,
|
||||
index //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Specified Time Bar Index ...
|
||||
*
|
||||
* @param time: DateTime ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int GetBarIndex(datetime time = NULL)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
time = NormalizeTime(time);
|
||||
|
||||
//
|
||||
string symbol = GetSymbol();
|
||||
ENUM_TIMEFRAMES period = GetPeriod();
|
||||
|
||||
//
|
||||
result = iBarShift(
|
||||
symbol,
|
||||
period,
|
||||
time //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect Market Structure Method 2 ...
|
||||
*
|
||||
* @param model: XMarketStructure instance Reference ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool DetectMarketStructure(
|
||||
ENUM_X_DIRECTION &dir,
|
||||
int pivotsCount = 3 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
int barIndex = 0;
|
||||
|
||||
//
|
||||
if (pivotsCount < 3)
|
||||
{
|
||||
pivotsCount = 3;
|
||||
}
|
||||
|
||||
//
|
||||
dir = X_DIRECTION_NONE;
|
||||
string symbol = GetSymbol();
|
||||
ENUM_TIMEFRAMES period = GetPeriod();
|
||||
|
||||
//
|
||||
int hpIndex = -1;
|
||||
int hpIndexes[];
|
||||
double hpValues[];
|
||||
|
||||
//
|
||||
int lvIndex = -1;
|
||||
int lvIndexes[];
|
||||
double lvValues[];
|
||||
|
||||
//
|
||||
for (int i = 0; i < pivotsCount; i++)
|
||||
{
|
||||
//
|
||||
hpIndex = barIndex;
|
||||
lvIndex = barIndex;
|
||||
|
||||
//
|
||||
double lastHP = 0;
|
||||
double lastLV = 0;
|
||||
|
||||
//
|
||||
int hpCount = ArraySize(hpIndexes);
|
||||
int lvCount = ArraySize(lvIndexes);
|
||||
|
||||
//
|
||||
if (IsValidSize(hpCount))
|
||||
{
|
||||
//
|
||||
lastHP = hpValues[hpCount - 1];
|
||||
hpIndex = hpIndexes[hpCount - 1];
|
||||
}
|
||||
|
||||
//
|
||||
if (IsValidSize(lvCount))
|
||||
{
|
||||
//
|
||||
lastLV = lvValues[lvCount - 1];
|
||||
lvIndex = lvIndexes[lvCount - 1];
|
||||
}
|
||||
|
||||
//
|
||||
if (lastHP == 0)
|
||||
{
|
||||
//
|
||||
lastHP = mX121Helper
|
||||
.xpvHelper
|
||||
.GetPeak(hpIndex);
|
||||
}
|
||||
|
||||
//
|
||||
if (lastLV == 0)
|
||||
{
|
||||
//
|
||||
lastLV = mX121Helper
|
||||
.xpvHelper
|
||||
.GetVale(lvIndex);
|
||||
}
|
||||
|
||||
//
|
||||
int highestPeakIndex = -1;
|
||||
double highesrPeak =
|
||||
mX121Helper
|
||||
.xpvHelper
|
||||
.GetHigherPeak(
|
||||
highestPeakIndex,
|
||||
lastHP,
|
||||
hpIndex //
|
||||
);
|
||||
if (IsValidIndex(highestPeakIndex))
|
||||
{
|
||||
//
|
||||
Add(
|
||||
highestPeakIndex,
|
||||
hpIndexes //
|
||||
);
|
||||
|
||||
//
|
||||
Add(
|
||||
highesrPeak,
|
||||
hpValues //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
int lowestValeIndex = -1;
|
||||
double lowestVale =
|
||||
mX121Helper
|
||||
.xpvHelper
|
||||
.GetLowerVale(
|
||||
lowestValeIndex,
|
||||
lastLV,
|
||||
lvIndex //
|
||||
);
|
||||
if (IsValidIndex(lowestValeIndex))
|
||||
{
|
||||
//
|
||||
Add(
|
||||
lowestValeIndex,
|
||||
lvIndexes //
|
||||
);
|
||||
|
||||
//
|
||||
Add(
|
||||
lowestVale,
|
||||
lvValues //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bool canBreak = ArraySize(hpIndexes) >= pivotsCount ||
|
||||
ArraySize(lvIndexes) >= pivotsCount;
|
||||
if (canBreak)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
ArrayReverse(hpValues);
|
||||
ArrayReverse(hpIndexes);
|
||||
int countHPs = ArraySize(hpIndexes);
|
||||
|
||||
//
|
||||
ArrayReverse(lvValues);
|
||||
ArrayReverse(lvIndexes);
|
||||
int countLVs = ArraySize(lvIndexes);
|
||||
|
||||
//
|
||||
bool isValidHPs = countHPs >= pivotsCount;
|
||||
bool isValidLVs = countLVs >= pivotsCount;
|
||||
|
||||
//
|
||||
result = isValidHPs ||
|
||||
isValidLVs;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (isValidHPs && isValidLVs)
|
||||
{
|
||||
//
|
||||
hpIndex = hpIndexes[countHPs - 1];
|
||||
lvIndex = lvIndexes[countLVs - 1];
|
||||
}
|
||||
|
||||
//
|
||||
dir =
|
||||
!isValidHPs && isValidLVs
|
||||
? X_DIRECTION_BULLISH
|
||||
: !isValidLVs && isValidHPs
|
||||
? X_DIRECTION_BEARISH
|
||||
: hpIndex < lvIndex
|
||||
? X_DIRECTION_BEARISH
|
||||
: lvIndex < hpIndex
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_ALL;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect Order Blocks ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
bool DetectOrderBlocks(
|
||||
XCOrderBlock *&bullishOrderBlocks[],
|
||||
XCOrderBlock *&bearishOrderBlocks[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
Clean(bullishOrderBlocks);
|
||||
Clean(bearishOrderBlocks);
|
||||
|
||||
//
|
||||
XPOIState state;
|
||||
mPOIDetector.GetState(state);
|
||||
bool isValid = state.IsValid() &&
|
||||
state.HasChild();
|
||||
if (!isValid)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int bullOBsCount = DetectDirectionOrderBlocks(
|
||||
X_DIRECTION_BULLISH,
|
||||
state,
|
||||
bullishOrderBlocks //
|
||||
);
|
||||
|
||||
//
|
||||
int bearOBsCount = DetectDirectionOrderBlocks(
|
||||
X_DIRECTION_BEARISH,
|
||||
state,
|
||||
bearishOrderBlocks //
|
||||
);
|
||||
|
||||
//
|
||||
result = IsValidSize(bullOBsCount +
|
||||
bearOBsCount);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Cycle Conditions ...
|
||||
*
|
||||
* @param events: ENUM_X_CYCLE_EVENTS member, Array ...
|
||||
* @param conditions: X121SMCCycleConditions instance ...
|
||||
* @param barIndex: Integer ...
|
||||
* @param loopback: Integer ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool GetConditions(
|
||||
ENUM_X_CYCLE_EVENTS &events[],
|
||||
ENUM_XPOI_EVENTS &poiEvents[],
|
||||
X121SMCCycleConditions &conditions,
|
||||
int barIndex = 0,
|
||||
int loopback = 7 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
if (loopback < 5)
|
||||
{
|
||||
loopback = 5;
|
||||
}
|
||||
|
||||
//
|
||||
Clean(events);
|
||||
Clean(poiEvents);
|
||||
conditions.Clean();
|
||||
|
||||
//
|
||||
result = mX121Helper.GetConditions(
|
||||
conditions.x121Conditions,
|
||||
barIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
conditions.Clean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mPOIDetector.Update(poiEvents);
|
||||
mPOIDetector.GetState(conditions.state);
|
||||
|
||||
//
|
||||
conditions.symbol = conditions.x121Conditions.symbol;
|
||||
conditions.period = conditions.x121Conditions.period;
|
||||
conditions.time = TimeCurrent();
|
||||
|
||||
//
|
||||
result = conditions.IsValid();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Virtuals ...
|
||||
|
||||
/**
|
||||
* Set Default Properties Values ...
|
||||
*/
|
||||
virtual void Default()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
protected:
|
||||
//
|
||||
|
||||
//
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Actions ...
|
||||
|
||||
/**
|
||||
* Release All Resources ...
|
||||
*/
|
||||
void DeInit()
|
||||
{
|
||||
//
|
||||
delete mX121Helper;
|
||||
delete mPOIDetector;
|
||||
delete mBarAnalyser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply Chart Style ...
|
||||
*/
|
||||
void ApplyChartStyle()
|
||||
{
|
||||
//
|
||||
// Retrieve Current Chart ID ...
|
||||
long chartId = ChartID();
|
||||
|
||||
//
|
||||
ENUM_CHART_MODE mMode = CHART_CANDLES; // chart's mMode
|
||||
bool mShowBidLine = true; // show bid line
|
||||
bool mShowAskLine = true; // show ask line
|
||||
bool mShowGrid = false; // show grids on chart
|
||||
bool mShowVolumes = false; // show volumes
|
||||
bool mShowTradeLevels = true; // Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders)
|
||||
bool mAutoScroll = true; // chart autoscroll
|
||||
bool mQuickNavigation = true; // chart quick navigation state
|
||||
color mForeGroundColor = clrWhite; // chart's foreground color
|
||||
color mBackGroundColor = clrBlack; // chart's background color
|
||||
color mUpColor = clrGreen; // Up Color
|
||||
color mDownColor = clrRed; // Down Color
|
||||
color mBullishColor = clrGreen; // Bullish color
|
||||
color mBearishColor = clrRed; // Bearish color
|
||||
color mGridColor = clrGray; // grid color
|
||||
color mBidLineColor = clrGray; // bid line color
|
||||
color mAskLineColor = clrRed; // ask line color
|
||||
color mLineColor = clrLime; // line mMode and doji candlestick color
|
||||
color mStopColor = clrGold; // Color of stop order levels (Stop Loss and Take Profit)
|
||||
color mVolumesColor = clrGreen; // volumes color
|
||||
|
||||
//
|
||||
ChartSetInteger(chartId, CHART_MODE, mMode);
|
||||
ChartSetInteger(chartId, CHART_SHOW_BID_LINE, mShowBidLine);
|
||||
ChartSetInteger(chartId, CHART_SHOW_ASK_LINE, mShowAskLine);
|
||||
ChartSetInteger(chartId, CHART_SHOW_GRID, mShowGrid);
|
||||
ChartSetInteger(chartId, CHART_SHOW_VOLUMES, mShowVolumes);
|
||||
ChartSetInteger(chartId, CHART_SHOW_TRADE_LEVELS, mShowTradeLevels);
|
||||
ChartSetInteger(chartId, CHART_AUTOSCROLL, mAutoScroll);
|
||||
ChartSetInteger(chartId, CHART_QUICK_NAVIGATION, mQuickNavigation);
|
||||
ChartSetInteger(chartId, CHART_COLOR_FOREGROUND, mForeGroundColor);
|
||||
ChartSetInteger(chartId, CHART_COLOR_BACKGROUND, mBackGroundColor);
|
||||
ChartSetInteger(chartId, CHART_COLOR_CHART_UP, mUpColor);
|
||||
ChartSetInteger(chartId, CHART_COLOR_CHART_DOWN, mDownColor);
|
||||
ChartSetInteger(chartId, CHART_COLOR_CANDLE_BULL, mBullishColor);
|
||||
ChartSetInteger(chartId, CHART_COLOR_CANDLE_BEAR, mBearishColor);
|
||||
ChartSetInteger(chartId, CHART_COLOR_GRID, mGridColor);
|
||||
ChartSetInteger(chartId, CHART_COLOR_BID, mBidLineColor);
|
||||
ChartSetInteger(chartId, CHART_COLOR_ASK, mAskLineColor);
|
||||
ChartSetInteger(chartId, CHART_COLOR_STOP_LEVEL, mStopColor);
|
||||
ChartSetInteger(chartId, CHART_COLOR_CHART_LINE, mLineColor);
|
||||
ChartSetInteger(chartId, CHART_COLOR_VOLUME, mVolumesColor);
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,749 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Common Library
|
||||
// --------------------------------------
|
||||
// Name: X121SMCLib
|
||||
// Description: provide all commonly used functions ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../../Classes/x-saherelm.base.class.mq5"
|
||||
#include "../../Classes/x-saherelm.x-poi.drawer.class.mq5"
|
||||
#include "../../Helpers/x-saherelm.x121.helper.mq5"
|
||||
#include "../../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../../Libraries/x-saherelm.x-poi.lib.mq5"
|
||||
#include "../../Libraries/x-saherelm.x-trade.lib.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
const string X121SMCStrategyToken = "X121SMC";
|
||||
|
||||
//
|
||||
const string X121SMCXToken = "X121X";
|
||||
const string X121SMCXOBPVToken = "X121XOBPV";
|
||||
|
||||
//
|
||||
// X121 SMC Providers ...
|
||||
enum ENUM_X_121_SMC_PROVIDERS
|
||||
{
|
||||
//
|
||||
X_121_SMC_PROVIDER_NONE,
|
||||
X_121_SMC_PROVIDER_X,
|
||||
X_121_SMC_PROVIDER_XOBPV,
|
||||
};
|
||||
|
||||
//
|
||||
// Guard Actions ...
|
||||
enum ENUM_X_121_SMC_GUARD_ACTIONS
|
||||
{
|
||||
X_121_SMC_GUARD_ACTION_NONE, // Nothing to Do
|
||||
X_121_SMC_GUARD_ACTION_CLOSE, // Close Specified Position
|
||||
X_121_SMC_GUARD_ACTION_CLOSE_ALL, // Close All Positions
|
||||
X_121_SMC_GUARD_ACTION_CLOSE_LONGS, // Close All Long Positions
|
||||
X_121_SMC_GUARD_ACTION_CLOSE_SHORTS, // Close All Short Position
|
||||
X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE, // Partial Close Specified Position
|
||||
X_121_SMC_GUARD_ACTION_TRAIL_STOP, // Trail Stop of Specified Position
|
||||
X_121_SMC_GUARD_ACTION_TRAIL_TARGET, // Trail Target of Specified Position
|
||||
X_121_SMC_GUARD_ACTION_HEDGE, // Hedge Specified Positions
|
||||
};
|
||||
|
||||
//
|
||||
// Each Market Cycle (Time Frame) Conditions
|
||||
// Model as this Structure ...
|
||||
struct X121SMCCycleConditions
|
||||
{
|
||||
//
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
X121Conditions x121Conditions;
|
||||
|
||||
//
|
||||
XPOIState state;
|
||||
|
||||
//
|
||||
void X121SMCStrategyConditions()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleanup ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
time = NULL;
|
||||
|
||||
//
|
||||
state.Clean();
|
||||
x121Conditions.Clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsSpecifiedValid(symbol) &&
|
||||
IsSpecifiedValid(period) &&
|
||||
IsSpecifiedValid(time);
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reporter Functions ...
|
||||
|
||||
/**
|
||||
* Generate Provided Scores ...
|
||||
*
|
||||
* @param bullishScore: Integer, reference ...
|
||||
* @param bearishScore: Integer, referenceF ...
|
||||
*/
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (!IsValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double bullScore = 0;
|
||||
double bearScore = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Summary ...
|
||||
*
|
||||
* @param onlyCommons: Boolean ...
|
||||
* @param onlyConditions: Boolean ...
|
||||
* @param includeScores: Boolean ...
|
||||
* @param ignoreFalseConditions: Boolean ...
|
||||
* @param separator: String ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GenerateSummary(
|
||||
bool onlyCommons = false,
|
||||
bool onlyConditions = false,
|
||||
bool includeScores = true,
|
||||
bool ignoreFalseConditions = true,
|
||||
string separator = "\n" //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
string commonStr = GenerateSpecifiedCommonSummary(
|
||||
this,
|
||||
separator,
|
||||
includeScores,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
string conditionsStr =
|
||||
//
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
"----------" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Unique Identifier ...
|
||||
*
|
||||
* @param forObject: Boolean ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GetTag(
|
||||
bool forObject = false //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
string typeName = GetTypeName(this);
|
||||
|
||||
//
|
||||
if (!forObject)
|
||||
{
|
||||
result = typeName;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
result = typeName + "_" +
|
||||
symbol + "_" + ToString(period) + "_" +
|
||||
ToMD5(time);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Model Signalling Conditions ...
|
||||
struct X121SMCStrategyConditions
|
||||
{
|
||||
//
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
double sl;
|
||||
double tp;
|
||||
double target;
|
||||
string provider;
|
||||
ENUM_X_DIRECTION signalDir;
|
||||
|
||||
//
|
||||
X121Conditions conditions;
|
||||
// XPriceZones priceZones;
|
||||
// XPriceZones decisionZones;
|
||||
// XMarketStructure marketStructure;
|
||||
|
||||
//
|
||||
void X121SMCStrategyConditions()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleanup ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
time = NULL;
|
||||
|
||||
//
|
||||
sl = 0;
|
||||
tp = 0;
|
||||
provider = NULL;
|
||||
signalDir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
conditions.Clean();
|
||||
// priceZones.Clean();
|
||||
// decisionZones.Clean();
|
||||
// marketStructure.Clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsSpecifiedValid(symbol) &&
|
||||
IsSpecifiedValid(period) &&
|
||||
IsSpecifiedValid(time);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Conditions Has Valid Bullish Signal ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HasBullishSignal()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
(sl > 0 ||
|
||||
tp > 0) &&
|
||||
IsValid() &&
|
||||
HasDirection(signalDir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
IsBullish(signalDir);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Conditions Has Valid Bearish Signal ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HasBearishSignal()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
(sl > 0 ||
|
||||
tp > 0) &&
|
||||
IsValid() &&
|
||||
HasDirection(signalDir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
IsBearish(signalDir);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reporter Functions ...
|
||||
|
||||
/**
|
||||
* Generate Provided Scores ...
|
||||
*
|
||||
* @param bullishScore: Integer, reference ...
|
||||
* @param bearishScore: Integer, referenceF ...
|
||||
*/
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (!IsValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double bullScore = 0;
|
||||
double bearScore = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Summary ...
|
||||
*
|
||||
* @param onlyCommons: Boolean ...
|
||||
* @param onlyConditions: Boolean ...
|
||||
* @param includeScores: Boolean ...
|
||||
* @param ignoreFalseConditions: Boolean ...
|
||||
* @param separator: String ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GenerateSummary(
|
||||
bool onlyCommons = false,
|
||||
bool onlyConditions = false,
|
||||
bool includeScores = true,
|
||||
bool ignoreFalseConditions = true,
|
||||
string separator = "\n" //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
string commonStr = GenerateSpecifiedCommonSummary(
|
||||
this,
|
||||
separator,
|
||||
includeScores,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
string conditionsStr =
|
||||
//
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
"----------" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Unique Identifier ...
|
||||
*
|
||||
* @param forObject: Boolean ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GetTag(
|
||||
bool forObject = false //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
string typeName = GetTypeName(this);
|
||||
|
||||
//
|
||||
if (!forObject)
|
||||
{
|
||||
result = typeName;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
result = typeName + "_" +
|
||||
symbol + "_" + ToString(period) + "_" +
|
||||
ToMD5(time);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Model a Guard Action ...
|
||||
struct X121SMCGuard
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
ENUM_X_121_SMC_GUARD_ACTIONS action;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
string symbol;
|
||||
string provider;
|
||||
|
||||
//
|
||||
// Specified Position ...
|
||||
ulong ticket;
|
||||
|
||||
//
|
||||
// Partial Close ...
|
||||
double volumeMultiplier;
|
||||
|
||||
//
|
||||
// SL Trial ...
|
||||
double sl;
|
||||
|
||||
//
|
||||
// TP Trial ...
|
||||
double tp;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
X121SMCGuard()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleanup ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
time = NULL;
|
||||
action = X_121_SMC_GUARD_ACTION_NONE;
|
||||
|
||||
//
|
||||
symbol = NULL;
|
||||
provider = NULL;
|
||||
|
||||
//
|
||||
ticket = 0;
|
||||
|
||||
//
|
||||
volumeMultiplier = 0;
|
||||
|
||||
//
|
||||
sl = 0;
|
||||
tp = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
IsValid(time) &&
|
||||
IsValid(symbol) &&
|
||||
IsValid(provider) &&
|
||||
action != X_121_SMC_GUARD_ACTION_NONE
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Model Based On Specified Guard Actions ...
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Add Guard to Collection ...
|
||||
*
|
||||
* @param guard: X121SMCGuard instance ...
|
||||
* @param guards: X121SMCGuard instance Collection ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int AddGuard(
|
||||
X121SMCGuard &guard,
|
||||
X121SMCGuard &guards[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
if (!guard.IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
AddRef(
|
||||
guard,
|
||||
guards //
|
||||
);
|
||||
|
||||
//
|
||||
result = ArraySize(guards);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
typedef void (*TOnX121SMCSignal)(
|
||||
XSignal &signal,
|
||||
X121SMCStrategyConditions &conditions //
|
||||
);
|
||||
|
||||
//
|
||||
// Extentions ...
|
||||
|
||||
/**
|
||||
* Validate a Signal Provider ...
|
||||
*
|
||||
* @param value: ENUM_X_121_SMC_PROVIDERS member ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsValid(ENUM_X_121_SMC_PROVIDERS value)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = value != X_121_SMC_PROVIDER_NONE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Signal Provider to String ...
|
||||
*
|
||||
* @param value: ENUM_X_121_SMC_PROVIDERS member ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string ToString(ENUM_X_121_SMC_PROVIDERS value)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
if (!IsValid(value))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
switch (value)
|
||||
{
|
||||
//
|
||||
case X_121_SMC_PROVIDER_X:
|
||||
result = X121SMCXToken;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_121_SMC_PROVIDER_XOBPV:
|
||||
result = X121SMCXOBPVToken;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse Specified String as a Signal Provider ...
|
||||
*
|
||||
* @param value: String ...
|
||||
*
|
||||
* @return ( ENUM_X_121_SMC_PROVIDERS )
|
||||
*/
|
||||
ENUM_X_121_SMC_PROVIDERS ParseProvider(string value)
|
||||
{
|
||||
//
|
||||
ENUM_X_121_SMC_PROVIDERS result = X_121_SMC_PROVIDER_NONE;
|
||||
|
||||
//
|
||||
if (!IsValid(value))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (Contains(X121SMCXToken, value))
|
||||
{
|
||||
result = X_121_SMC_PROVIDER_X;
|
||||
}
|
||||
else if (Contains(X121SMCXOBPVToken, value))
|
||||
{
|
||||
result = X_121_SMC_PROVIDER_XOBPV;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user