backup ...
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// --------------------------------------
|
||||
// Name: XBaseClass
|
||||
// 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
|
||||
|
||||
//
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// XBase Class ...
|
||||
class XCBase
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Protected ...
|
||||
|
||||
//
|
||||
// Represent Basic Unique Tag ...
|
||||
virtual string GetTag();
|
||||
|
||||
//
|
||||
// Retrieve Class Token ...
|
||||
virtual string GetToken();
|
||||
|
||||
//
|
||||
// Protected
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
};
|
||||
|
||||
//
|
||||
template <typename T>
|
||||
string GenerateSpecifiedCommonSummary(
|
||||
T &mItem,
|
||||
string separator = "\n",
|
||||
bool includeScores = true,
|
||||
bool setLabel = false //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
mItem.GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
(!setLabel
|
||||
? ""
|
||||
: "Commons:" + separator) +
|
||||
"---------------" + separator +
|
||||
"Symbol: " + mItem.symbol + separator +
|
||||
"Period: " + ToString(mItem.period) + separator +
|
||||
"Time: " + ToString(mItem.time) + separator +
|
||||
(includeScores
|
||||
? "---------------" + separator +
|
||||
"Scores:" + separator +
|
||||
"---------------" + separator +
|
||||
"Bullish: " + ToString(bullishScore) + separator +
|
||||
"Bearish: " + ToString(bearishScore) + separator +
|
||||
"---------------" + separator
|
||||
: "") +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,398 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCAccount
|
||||
// Description: provides all Account 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
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Classes/x-saherelm.base.class.mq5"
|
||||
#include <Trade/AccountInfo.mqh>
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Manage Account ...
|
||||
class XCAccount : public XCBase
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XCAccount()
|
||||
{
|
||||
//
|
||||
mAccountInfo = new CAccountInfo();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XCAccount()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// User Account ...
|
||||
long GetUserAccount()
|
||||
{
|
||||
return mAccountInfo.Login();
|
||||
}
|
||||
|
||||
//
|
||||
// Account Leverage ...
|
||||
long GetLeverage()
|
||||
{
|
||||
return mAccountInfo.Leverage();
|
||||
}
|
||||
|
||||
//
|
||||
// Get Trade Expert State ...
|
||||
bool CanExpertTrade()
|
||||
{
|
||||
return mAccountInfo.TradeExpert();
|
||||
}
|
||||
|
||||
//
|
||||
// User Account Trade Mopde (ENUM_ACCOUNT_TRADE_MODE) ...
|
||||
// --------------------------
|
||||
// ACCOUNT_TRADE_MODE_DEMO
|
||||
// ACCOUNT_TRADE_MODE_CONTEST
|
||||
// ACCOUNT_TRADE_MODE_REAL
|
||||
ENUM_ACCOUNT_TRADE_MODE GetTradeMode()
|
||||
{
|
||||
return mAccountInfo.TradeMode();
|
||||
}
|
||||
|
||||
//
|
||||
// Get Account Balance ...
|
||||
double GetBalance()
|
||||
{
|
||||
return mAccountInfo.Balance();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the amount of give Credit ...
|
||||
double GetCredit()
|
||||
{
|
||||
return mAccountInfo.Credit();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the amount of current Profit on account ...
|
||||
double GetProfit()
|
||||
{
|
||||
return mAccountInfo.Profit();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the amount of current Equity on account ...
|
||||
double GetEquity()
|
||||
{
|
||||
return mAccountInfo.Equity();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the amount of reserved Margin ...
|
||||
double GetMargin()
|
||||
{
|
||||
return mAccountInfo.Margin();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the amount of free Margin ...
|
||||
double GetFreeMargin()
|
||||
{
|
||||
return mAccountInfo.FreeMargin();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Level of Margin ...
|
||||
double GetMarginLevel()
|
||||
{
|
||||
return mAccountInfo.MarginLevel();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Level Of Margin for a Deposit ...
|
||||
double GetMarginCall()
|
||||
{
|
||||
return mAccountInfo.MarginCall();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Level of Margin for Stop out ...
|
||||
double GetMarginStopOut()
|
||||
{
|
||||
return mAccountInfo.MarginStopOut();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Client Name ...
|
||||
string GetName()
|
||||
{
|
||||
return mAccountInfo.Name();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Trade Server Name ...
|
||||
string GetServerName()
|
||||
{
|
||||
return mAccountInfo.Server();
|
||||
}
|
||||
|
||||
//
|
||||
// Get deposit Currency Name ...
|
||||
string GetCurrency()
|
||||
{
|
||||
return mAccountInfo.Currency();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Company Name that serves an Account ...
|
||||
string GetCompany()
|
||||
{
|
||||
return mAccountInfo.Company();
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Profits for the current account based on passed parameters ...
|
||||
double CalculateTradeProfit(
|
||||
const string symbol, // trading symbol
|
||||
ENUM_ORDER_TYPE type, // order type
|
||||
double volume, // volume
|
||||
double entry, // open price
|
||||
double exit // close price
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = mAccountInfo.OrderProfitCheck(
|
||||
symbol,
|
||||
type,
|
||||
volume,
|
||||
entry,
|
||||
exit);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate amount of margin which required for trade operation ...
|
||||
double CalculateMarging(
|
||||
const string symbol, // trading symbol
|
||||
ENUM_ORDER_TYPE type, // order type
|
||||
double volume, // volume
|
||||
double entry // open price
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = mAccountInfo.MarginCheck(
|
||||
symbol,
|
||||
type,
|
||||
volume,
|
||||
entry);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate amount of free margin left after trade operation ...
|
||||
double CalculateFreeMarging(
|
||||
const string symbol, // trading symbol
|
||||
ENUM_ORDER_TYPE type, // order type
|
||||
double volume, // volume
|
||||
double entry // open price
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = mAccountInfo.FreeMarginCheck(
|
||||
symbol,
|
||||
type,
|
||||
volume,
|
||||
entry);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate the Maximum possible volume of trade operation ...
|
||||
double CalculateMaxVolume(
|
||||
const string symbol, // trading symbol
|
||||
ENUM_ORDER_TYPE type, // order type
|
||||
double entry, // open price
|
||||
double percent = 100 // percent of available margin
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = mAccountInfo.MaxLotCheck(
|
||||
symbol,
|
||||
type,
|
||||
entry,
|
||||
percent);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Point Value for Given Symbol based on Account ...
|
||||
double GetPointValue(
|
||||
string symbol // trading symbol
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
double tickSize = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE);
|
||||
double tickValue = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_VALUE);
|
||||
double point = SymbolInfoDouble(symbol, SYMBOL_POINT);
|
||||
|
||||
//
|
||||
double ticksPerPoint = tickSize / point;
|
||||
|
||||
//
|
||||
result = tickValue / ticksPerPoint;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Risk Amount based on account Currency by Providing:
|
||||
// Points and Volume ...
|
||||
double CalculateRiskAmount(
|
||||
string symbol, // trading symbol
|
||||
double points, // amount of Risk Points
|
||||
double volume // position Volume
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
double pointValue = GetPointValue(symbol);
|
||||
|
||||
//
|
||||
result = pointValue * volume * points;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Risk Points based on account Currency by Providing:
|
||||
// Volume and Amount ...
|
||||
double CalculateRiskPoints(
|
||||
string symbol, // trading symbol
|
||||
double volume, // position Volume
|
||||
double amount // amount of Risk based on Account Currency
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
double pointValue = GetPointValue(symbol);
|
||||
|
||||
//
|
||||
result = amount / (pointValue * volume);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Volume based on account Currency by Providing:
|
||||
// Amount and Risk Points ...
|
||||
double CalculateVolume(
|
||||
string symbol, // trading symbol
|
||||
double amount, // amount of Risk based on Account Currency
|
||||
double points // amount of Risk Points
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
points =
|
||||
points <= 0
|
||||
? 10
|
||||
: points;
|
||||
|
||||
//
|
||||
double pointValue = GetPointValue(symbol);
|
||||
|
||||
//
|
||||
result = amount / (pointValue * points);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Account Info ...
|
||||
CAccountInfo mAccountInfo;
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,275 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// --------------------------------------
|
||||
// Name: XCPanel
|
||||
// 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 <Controls/Dialog.mqh>
|
||||
|
||||
//
|
||||
#include "../Classes/x-saherelm.base.class.mq5"
|
||||
|
||||
//
|
||||
// Extentions ...
|
||||
|
||||
/**
|
||||
* Check a Qery Contains in a Content or not ...
|
||||
*
|
||||
* @param mQuery: String ...
|
||||
* @param mContent: String ...
|
||||
* @param ignoreCase: Boolean ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool XContains(
|
||||
string mQuery, // Search String
|
||||
string mContent, // Search Content
|
||||
bool ignoreCase = true // Ignore Case
|
||||
)
|
||||
{
|
||||
return Contains(
|
||||
mQuery,
|
||||
mContent,
|
||||
ignoreCase //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Implementation ...
|
||||
|
||||
//
|
||||
// a Base App Dialog Class ...
|
||||
class XCAppDialog : public CAppDialog
|
||||
{
|
||||
public:
|
||||
//
|
||||
// Action ...
|
||||
|
||||
//
|
||||
// Virual ...
|
||||
|
||||
/**
|
||||
* Override Close Button Click Action ...
|
||||
*/
|
||||
void OnClickButtonClose()
|
||||
{
|
||||
//
|
||||
bool isClosed = ConfirmDialog("Close EA ?");
|
||||
|
||||
//
|
||||
if (isClosed)
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Configuration Actions ...
|
||||
|
||||
/**
|
||||
* Show or Hide Minimize Button ...
|
||||
*
|
||||
* @param show: boolean
|
||||
*/
|
||||
void MinimizeButton(bool show)
|
||||
{
|
||||
//
|
||||
int controlIDX = ControlFind("MinMax");
|
||||
if (!IsValidIndex(controlIDX))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
if (show)
|
||||
{
|
||||
Control(controlIDX).Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
Control(controlIDX).Hide();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show or Hide Close Button ...
|
||||
*
|
||||
* @param show: boolean
|
||||
*/
|
||||
void CloseButton(bool show)
|
||||
{
|
||||
//
|
||||
int controlIDX = ControlFind("Close");
|
||||
if (!IsValidIndex(controlIDX))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
if (show)
|
||||
{
|
||||
Control(controlIDX).Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
Control(controlIDX).Hide();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Minimize Functionality Implementation ...
|
||||
*/
|
||||
void Minimize()
|
||||
{
|
||||
//
|
||||
m_minimized = true;
|
||||
Rebound(m_min_rect);
|
||||
ClientAreaVisible(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Background Color ...
|
||||
*
|
||||
* @param clr: Color ...
|
||||
*/
|
||||
void BackgroundColor(color clr)
|
||||
{
|
||||
//
|
||||
int controlIDX = ControlFind("Client");
|
||||
if (!IsValidIndex(controlIDX))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
CWnd *obj = Control(controlIDX);
|
||||
CWndClient *wndclient = (CWndClient *)obj;
|
||||
|
||||
//
|
||||
wndclient.ColorBackground(clr);
|
||||
}
|
||||
|
||||
//
|
||||
protected:
|
||||
//
|
||||
|
||||
/**
|
||||
* Find Specific Control in Dialog ...
|
||||
*
|
||||
* @param name: String to Search
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ControlFind(string name)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
if (!IsValid(name))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int count = ControlsTotal();
|
||||
if (!IsValidSize(count))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
string iName = Control(i).Name();
|
||||
|
||||
//
|
||||
bool isContains = XContains(
|
||||
name,
|
||||
iName,
|
||||
true // Ignore Case ...
|
||||
);
|
||||
if (isContains)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and Run Confirm Dialog ...
|
||||
*
|
||||
* @param message: message for Message Box ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ConfirmDialog(string message = NULL)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (!IsValid(message))
|
||||
{
|
||||
message = "Confirm ?";
|
||||
}
|
||||
|
||||
//
|
||||
int dialogResult = MessageBox(message, NULL, MB_YESNO);
|
||||
|
||||
//
|
||||
// use 'switch' or 'if' as needed
|
||||
switch (dialogResult)
|
||||
{
|
||||
//
|
||||
// Yes ...
|
||||
case IDYES:
|
||||
result = true;
|
||||
break;
|
||||
//
|
||||
// No ...
|
||||
case IDNO:
|
||||
result = false;
|
||||
break;
|
||||
//
|
||||
// Cancel ...
|
||||
case IDCANCEL:
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
private:
|
||||
//
|
||||
|
||||
//
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,986 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// --------------------------------------
|
||||
// Name: XCBaseExpert
|
||||
// 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-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"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
string XCBaseExpertToken = "XCBaseEA";
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Implementations ...
|
||||
class XCBaseExpert : public XCBaseAlert
|
||||
{
|
||||
//
|
||||
public:
|
||||
//
|
||||
|
||||
//
|
||||
XCTrade *mTrader; // Trader of Expert Adviser ...
|
||||
|
||||
//
|
||||
// Constructur(s) ...
|
||||
void XCBaseExpert()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XCBaseExpert()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Getter(s) / Setter(s) ...
|
||||
|
||||
//
|
||||
// Common ...
|
||||
|
||||
/**
|
||||
* Get Magic Number ...
|
||||
*
|
||||
* @return ( long )
|
||||
*/
|
||||
long MagicNumber()
|
||||
{
|
||||
return mMagicNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Magic Number ...
|
||||
*
|
||||
* @param value: Long ...
|
||||
*/
|
||||
void MagicNumber(long value)
|
||||
{
|
||||
//
|
||||
mMagicNumber = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Slippage ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int Slippage()
|
||||
{
|
||||
return mSlippage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Slippage ...
|
||||
*
|
||||
* @param value: Integer ...
|
||||
*/
|
||||
void Slippage(int value)
|
||||
{
|
||||
//
|
||||
mSlippage = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Tag Prefix ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string TagPrefix()
|
||||
{
|
||||
return mTagPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Tag Prefix ...
|
||||
*
|
||||
* @param value: String ...
|
||||
*/
|
||||
void TagPrefix(string value)
|
||||
{
|
||||
//
|
||||
mTagPrefix = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
//
|
||||
// Symbol ...
|
||||
|
||||
/**
|
||||
* Get Period ...
|
||||
*
|
||||
* @return ( ENUM_TIMEFRAMES )
|
||||
*/
|
||||
ENUM_TIMEFRAMES GetPeriod()
|
||||
{
|
||||
return mPeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Period ...
|
||||
*
|
||||
* @param value: ENUM_TIMEFRAMES member ...
|
||||
*/
|
||||
void SetPeriod(ENUM_TIMEFRAMES value)
|
||||
{
|
||||
//
|
||||
mPeriod = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Symbol ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GetSymbol()
|
||||
{
|
||||
return mSymbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Symbol ...
|
||||
*
|
||||
* @param value: String ...
|
||||
*/
|
||||
void SetSymbol(string value)
|
||||
{
|
||||
//
|
||||
mSymbol = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Multi Symbol is Enable or Not ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool MultiSymbol()
|
||||
{
|
||||
return mMultiSymbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Multi Symbol is Enable or Not ...
|
||||
*
|
||||
* @param value: Boolean ...
|
||||
*/
|
||||
void MultiSymbol(bool value)
|
||||
{
|
||||
//
|
||||
mMultiSymbol = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Multi Provided Symbols ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string Symbols()
|
||||
{
|
||||
return mSymbols;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Multi Provided Symbols ...
|
||||
*
|
||||
* @param value: String ...
|
||||
*/
|
||||
void Symbols(string value)
|
||||
{
|
||||
//
|
||||
mSymbols = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
//
|
||||
// Signalling ...
|
||||
|
||||
/**
|
||||
* Get Force Disable Signalling ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool Disabled()
|
||||
{
|
||||
return mDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Force Disable Signalling ...
|
||||
*
|
||||
* @param value: Boolean ...
|
||||
*/
|
||||
void Disabled(bool value)
|
||||
{
|
||||
//
|
||||
mDisabled = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Allow Long Signals ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool AllowLong()
|
||||
{
|
||||
return mAllowLong;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Allow Long Signals ...
|
||||
*
|
||||
* @param value: Boolean ...
|
||||
*/
|
||||
void AllowLong(bool value)
|
||||
{
|
||||
//
|
||||
mAllowLong = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Allow Short Signalling ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool AllowShort()
|
||||
{
|
||||
return mAllowShort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Allow Short Signalling ...
|
||||
*
|
||||
* @param value: Boolean ...
|
||||
*/
|
||||
void AllowShort(bool value)
|
||||
{
|
||||
//
|
||||
mAllowShort = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
//
|
||||
// Reports ...
|
||||
|
||||
/**
|
||||
* Get Report New Month State ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ReportNewMonths()
|
||||
{
|
||||
return mReportNewMonths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Report New Month State ...
|
||||
*
|
||||
* @param value: Boolean ...
|
||||
*/
|
||||
void ReportNewMonths(bool value)
|
||||
{
|
||||
//
|
||||
mReportNewMonths = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Report New Weeks State ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ReportNewWeeks()
|
||||
{
|
||||
return mReportNewWeeks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Report New Weeks State ...
|
||||
*
|
||||
* @param value: Boolean ...
|
||||
*/
|
||||
void ReportNewWeeks(bool value)
|
||||
{
|
||||
//
|
||||
mReportNewWeeks = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Report New Days State ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ReportNewDays()
|
||||
{
|
||||
return mReportNewDays;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Report New Days State ...
|
||||
*
|
||||
* @param value: Boolean ...
|
||||
*/
|
||||
void ReportNewDays(bool value)
|
||||
{
|
||||
//
|
||||
mReportNewDays = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Report New Hours State ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ReportNewHours()
|
||||
{
|
||||
return mReportNewHours;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Report New Hours State ...
|
||||
*
|
||||
* @param value: Boolean ...
|
||||
*/
|
||||
void ReportNewHours(bool value)
|
||||
{
|
||||
//
|
||||
mReportNewHours = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
//
|
||||
// Actions ...
|
||||
|
||||
/**
|
||||
* Handle Expert OnInit Event ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HandleOnInit()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
string message = "";
|
||||
|
||||
//
|
||||
// Validate Input ...
|
||||
result = ValidateInputs();
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
message = "Invalid Inputs ....";
|
||||
|
||||
//
|
||||
Alert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Initial All Requirements ...
|
||||
result = InitEA();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initial All GUI Requirements ...
|
||||
result = InitGUI();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
message = "Initialized Successfully ...";
|
||||
Alert(message);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Expert OnDeInit Event ...
|
||||
*/
|
||||
void HandleOnDeInit()
|
||||
{
|
||||
//
|
||||
// Destroy all GUI Requirements ...
|
||||
DestroyGUI();
|
||||
|
||||
//
|
||||
// Alert De Initialization Succeeded ...
|
||||
string msg = "De Initialized Successfully ...";
|
||||
Alert(msg);
|
||||
|
||||
//
|
||||
// Destroy all EA Requirements ...
|
||||
DestroyEA();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Expert OnTick Event ...
|
||||
*/
|
||||
void HandleOnTick()
|
||||
{
|
||||
//
|
||||
UpdateGUI();
|
||||
HandleReportTime();
|
||||
HandleStrategiesOnTick();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Expert OnTrade Event ...
|
||||
*/
|
||||
void HandleOnTrade()
|
||||
{
|
||||
mTrader.HandleOnTrade();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Expert OnTimer Event ...
|
||||
*/
|
||||
void HandleOnTimer()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Expert OnChart Event ...
|
||||
*/
|
||||
void HandleOnChartEvent(
|
||||
const int id,
|
||||
const long &lparam,
|
||||
const double &dparam,
|
||||
const string &sparam //
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Virtual Actions ...
|
||||
|
||||
/**
|
||||
* Apply Default Configurations ...
|
||||
*/
|
||||
virtual void DefaultConfigure()
|
||||
{
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vaslidate Inputs ...
|
||||
*
|
||||
* @return ( virtual bool )
|
||||
*/
|
||||
virtual bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
string errMessage = "";
|
||||
|
||||
//
|
||||
bool isCommonValid = (
|
||||
//
|
||||
mSlippage > 0 &&
|
||||
mMagicNumber > 0
|
||||
//
|
||||
);
|
||||
if (!isCommonValid)
|
||||
{
|
||||
//
|
||||
errMessage += "common configurations error;" + "\n";
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
// Common ...
|
||||
isCommonValid &&
|
||||
//
|
||||
// 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 ( virtual bool )
|
||||
*/
|
||||
virtual bool InitEA()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator Helpers ...
|
||||
|
||||
//
|
||||
// Bar Timer ...
|
||||
XCTInputs ctInputs;
|
||||
ctInputs.Default(); // Default Configurations ...
|
||||
mCTHelper = new XCXCTHelper();
|
||||
result = mCTHelper.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
ctInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Bar Styles ...
|
||||
XCCInputs ccInputs;
|
||||
ccInputs.Default(); // Default Configurations ...
|
||||
mCCHelper = new XCXCCHelper();
|
||||
result = mCCHelper.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
ccInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Create Trader Instance and Configure it ...
|
||||
mTrader = new XCTrade(
|
||||
mSlippage,
|
||||
mMagicNumber //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Initialized Requirements ...
|
||||
*/
|
||||
virtual void DestroyEA()
|
||||
{
|
||||
//
|
||||
delete mCTHelper;
|
||||
delete mCCHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* GUI Initialize if required ...
|
||||
*
|
||||
* @return ( virtual bool )
|
||||
*/
|
||||
virtual bool InitGUI()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update All GUI Contents ...
|
||||
*/
|
||||
virtual void UpdateGUI()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy all Initialized GUi Elements ...
|
||||
*/
|
||||
virtual void DestroyGUI()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Calls When a Position's SL Triggered ...
|
||||
*
|
||||
* @param deal: XDeal instance ...
|
||||
*/
|
||||
virtual void HandleOnStopLossTriggered(const XDeal &deal)
|
||||
{
|
||||
HandleReportBalance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls When a Position's TP Triggered ...
|
||||
*
|
||||
* @param deal: XDeal instance ...
|
||||
*/
|
||||
virtual void HandleOnTakeProfitTriggered(const XDeal &deal)
|
||||
{
|
||||
HandleReportBalance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Force Close a Position ...
|
||||
*
|
||||
* @param ticket: Position Ticket ...
|
||||
* @param position: XPosition ...
|
||||
* @param comment: Closing Comment ...
|
||||
*/
|
||||
virtual void HandleOnPositionForceClosed(
|
||||
const ulong ticket,
|
||||
const XPosition &position,
|
||||
const string comment //
|
||||
)
|
||||
{
|
||||
HandleReportBalance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Position Modified ...
|
||||
*
|
||||
* @param ticket: ULONG ...
|
||||
* @param profit: Double ...
|
||||
* @param comment: String ...
|
||||
*/
|
||||
virtual void HandleOnPositionModified(
|
||||
const ulong ticket,
|
||||
const double profit,
|
||||
const string comment //
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Position Partially Closed ...
|
||||
*
|
||||
* @param ticket: ULONG ...
|
||||
* @param profit: Double ...
|
||||
* @param comment: String ...
|
||||
*/
|
||||
virtual void HandleOnPositionPartialClosed(
|
||||
const ulong ticket,
|
||||
const double profit,
|
||||
const string comment //
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Deals Changed ...
|
||||
*
|
||||
* @param count: Integer, Number of Changes ...
|
||||
*/
|
||||
virtual void HandleOnDealsChanged(int count)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Orders Changed ...
|
||||
*
|
||||
* @param count: Integer, Number of Changes ...
|
||||
*/
|
||||
virtual void HandleOnOrdersChanged(int count)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Positions Changed ...
|
||||
*
|
||||
* @param count: Integer, Number of Changes ...
|
||||
*/
|
||||
virtual void HandleOnPositionsChanged(int count)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Do All Signalling Processing Here ...
|
||||
*/
|
||||
virtual void HandleStrategiesOnTick()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Time Handlers ...
|
||||
|
||||
virtual void HandleOnNewMonth()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void HandleOnNewWeek()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void HandleOnNewDay()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void HandleOnNewHour()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void ReConfigure()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Identifier Tag ...
|
||||
*
|
||||
* @return ( virtual string )
|
||||
*/
|
||||
virtual string GetTag()
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
string tagPrefix = TagPrefix();
|
||||
if (IsValid(tagPrefix))
|
||||
{
|
||||
result = tagPrefix;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = "";
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
XCBaseExpertToken + result;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
protected:
|
||||
//
|
||||
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
XTimeTracker mTimeTracker; // Time Tracker for Providing Reports ...
|
||||
XCXCTHelper *mCTHelper; // Bar Timer Indicator Helper class ...
|
||||
XCXCCHelper *mCCHelper; // Chart Styler Indicator Helper Class ...
|
||||
|
||||
//
|
||||
// Actions ...
|
||||
|
||||
/**
|
||||
* Report Account Balance ...
|
||||
*/
|
||||
void HandleReportBalance()
|
||||
{
|
||||
//
|
||||
if (!IsRunningOnTestMode())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
string msg = "Balance: " + ToString(mTrader.mAccount.GetBalance());
|
||||
Log(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Time Reporting based on Inputs ...
|
||||
*/
|
||||
void HandleReportTime()
|
||||
{
|
||||
//
|
||||
// Monthly Report ....
|
||||
if (mTimeTracker.IsNewMonth())
|
||||
{
|
||||
//
|
||||
HandleOnNewMonth();
|
||||
|
||||
//
|
||||
if (mReportNewMonths)
|
||||
{
|
||||
//
|
||||
string msg = "New Month ...";
|
||||
|
||||
//
|
||||
Alert(msg);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Weekly Report ....
|
||||
if (mTimeTracker.IsNewWeek())
|
||||
{
|
||||
//
|
||||
HandleOnNewWeek();
|
||||
|
||||
//
|
||||
if (mReportNewWeeks)
|
||||
{
|
||||
//
|
||||
string msg = "New Week ...";
|
||||
|
||||
//
|
||||
Alert(msg);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Daily Report ....
|
||||
if (mTimeTracker.IsNewDay())
|
||||
{
|
||||
//
|
||||
HandleOnNewDay();
|
||||
|
||||
//
|
||||
if (mReportNewDays)
|
||||
{
|
||||
//
|
||||
string msg = "New Day ...";
|
||||
|
||||
//
|
||||
Alert(msg);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Hourly Report ....
|
||||
if (mTimeTracker.IsNewHour())
|
||||
{
|
||||
//
|
||||
HandleOnNewHour();
|
||||
|
||||
//
|
||||
if (mReportNewHours)
|
||||
{
|
||||
//
|
||||
string msg = "New Hour ...";
|
||||
|
||||
//
|
||||
Alert(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
private:
|
||||
//
|
||||
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Common ...
|
||||
long mMagicNumber; // Magic Number ...
|
||||
int mSlippage; // Slippage ...
|
||||
string mTagPrefix; // Tag Prefix ...
|
||||
|
||||
//
|
||||
// Symbol ...
|
||||
ENUM_TIMEFRAMES mPeriod; // Period ...
|
||||
string mSymbol; // Symbol ...
|
||||
bool mMultiSymbol; // Multi Symbol is Enable or Not ...
|
||||
string mSymbols; // Multi Provided Symbols ...
|
||||
|
||||
//
|
||||
// Signalling ...
|
||||
bool mDisabled; // Force Disable Signalling ...
|
||||
bool mAllowLong; // Allow Long Signals ...
|
||||
bool mAllowShort; // Allow Short Signals ...
|
||||
|
||||
//
|
||||
// Reports ...
|
||||
bool mReportNewMonths; // Report New Month ...
|
||||
bool mReportNewWeeks; // Report New Weeks ...
|
||||
bool mReportNewDays; // Report New Days ...
|
||||
bool mReportNewHours; // Report New Hours ...
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
@@ -0,0 +1,148 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCBaseHelper
|
||||
// Description: provides all Base 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
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Classes/x-saherelm.base.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// a Class for Handle base requirements ...
|
||||
// for indicators ...
|
||||
class XCBaseHelper : public XCBase
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XCBaseHelper(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period // Trading Time Frame
|
||||
)
|
||||
{
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XCBaseHelper()
|
||||
{
|
||||
//
|
||||
IndicatorRelease(mHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Setter(s) / Getter(s) ...
|
||||
|
||||
//
|
||||
// Symbol ...
|
||||
string GetSymbol()
|
||||
{
|
||||
return mSymbol;
|
||||
}
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES GetPeriod()
|
||||
{
|
||||
return mPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Bars ...
|
||||
int CountBars()
|
||||
{
|
||||
//
|
||||
int result =
|
||||
Bars(
|
||||
mSymbol,
|
||||
mPeriod
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Indicator Calculated Bars ...
|
||||
int CountCalculatedBars()
|
||||
{
|
||||
return BarsCalculated(mHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Generate Tag ...
|
||||
virtual string GetTag()
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
GetToken() +
|
||||
"[" +
|
||||
GetSymbol() + "|" +
|
||||
ToString(GetPeriod()) +
|
||||
"]"
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Symbol ...
|
||||
string mSymbol;
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES mPeriod;
|
||||
|
||||
//
|
||||
// Indicator Handler ...
|
||||
int mHandler;
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ....
|
||||
@@ -0,0 +1,373 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCHttp
|
||||
// Description: provides all HTTP 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
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
enum X_HTTP_METHOD
|
||||
{
|
||||
X_HTTP_GET,
|
||||
X_HTTP_POST
|
||||
};
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Classes/x-saherelm.base.class.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// a Class for Manage Account ...
|
||||
class XCHttp : public XCBase
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XCHttp()
|
||||
{
|
||||
XCHttp("", 10000);
|
||||
}
|
||||
void XCHttp(
|
||||
string path, // Base Folder to Store Data
|
||||
int timeout // base timeout for Requests
|
||||
)
|
||||
{
|
||||
//
|
||||
Path(path);
|
||||
Timeout(timeout);
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XCHttp()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Properties Getter(s) / Setter(s) ...
|
||||
|
||||
//
|
||||
// Path ...
|
||||
void Path(string value)
|
||||
{
|
||||
//
|
||||
mPath = value;
|
||||
|
||||
//
|
||||
if (!IsValid(mPath))
|
||||
{
|
||||
mPath = GetTag();
|
||||
}
|
||||
}
|
||||
|
||||
string Path()
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
//
|
||||
// Timeout ...
|
||||
void Timeout(int value)
|
||||
{
|
||||
mTimeout = value;
|
||||
}
|
||||
|
||||
//
|
||||
int Timeout()
|
||||
{
|
||||
return mTimeout;
|
||||
}
|
||||
|
||||
//
|
||||
// Error ...
|
||||
int Error()
|
||||
{
|
||||
return mError;
|
||||
}
|
||||
|
||||
//
|
||||
// Response ...
|
||||
string Response()
|
||||
{
|
||||
return mResponse;
|
||||
}
|
||||
|
||||
//
|
||||
// Overrides ...
|
||||
string GetTag() override
|
||||
{
|
||||
return GetSpecificToken(this);
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Send Global Request ...
|
||||
int SendRequest(
|
||||
X_HTTP_METHOD method, // Httm Request Method
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
string strMethod = ToString(method);
|
||||
if (StringLen(strMethod) == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reset State ...
|
||||
ResetState();
|
||||
|
||||
//
|
||||
result = WebRequest(
|
||||
strMethod,
|
||||
url,
|
||||
headers,
|
||||
timeout,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders);
|
||||
|
||||
//
|
||||
if (result < 0)
|
||||
{
|
||||
mError = GetLastError();
|
||||
}
|
||||
else
|
||||
{
|
||||
mResponse = CharArrayToString(response);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Get Request ...
|
||||
int GetRequest(
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = SendRequest(
|
||||
X_HTTP_GET,
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Post Request ...
|
||||
int PostRequest(
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = SendRequest(
|
||||
X_HTTP_POST,
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Download Specific URL Content to Specific Path and File Name ...
|
||||
bool Download(
|
||||
string url, // the URL address which going to download
|
||||
string fileName // Specify Destination file name to Store Response
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
string filePath = GetFilePath(fileName);
|
||||
string cookie = NULL;
|
||||
string referer = NULL;
|
||||
int timeout = Timeout();
|
||||
|
||||
//
|
||||
char payload[];
|
||||
string headers;
|
||||
char response[];
|
||||
string responseHeaders;
|
||||
|
||||
//
|
||||
// Send Request ...
|
||||
int requestResult = GetRequest(
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout);
|
||||
|
||||
//
|
||||
// Define File Handler ...
|
||||
int mFileHandler = FileOpen(
|
||||
filePath,
|
||||
FILE_WRITE | FILE_BIN);
|
||||
if (mFileHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
mError = GetLastError();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Write Response to File ...
|
||||
uint writed = FileWriteArray(
|
||||
mFileHandler,
|
||||
response,
|
||||
0,
|
||||
ArraySize(response));
|
||||
FileFlush(mFileHandler);
|
||||
FileClose(mFileHandler);
|
||||
|
||||
//
|
||||
result = writed > 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Destintion Folder Path ...
|
||||
string mPath;
|
||||
|
||||
//
|
||||
// WEB Request Timeout Value ...
|
||||
int mTimeout;
|
||||
|
||||
//
|
||||
// WEB Request's Response ...
|
||||
string mResponse;
|
||||
|
||||
//
|
||||
// Error Value ...
|
||||
int mError;
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Reset Errors State ...
|
||||
void ResetState()
|
||||
{
|
||||
//
|
||||
// Reset Errors ...
|
||||
mError = -1;
|
||||
mResponse = "";
|
||||
ResetLastError();
|
||||
}
|
||||
|
||||
//
|
||||
// Generate Full File Path ...
|
||||
string GetFilePath(string fileName)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
Path() + "\\" + fileName
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Convert enum to String ...
|
||||
string ToString(X_HTTP_METHOD method)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
switch (method)
|
||||
{
|
||||
//
|
||||
case X_HTTP_GET:
|
||||
result = "GET";
|
||||
break;
|
||||
|
||||
//
|
||||
case X_HTTP_POST:
|
||||
result = "POST";
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,445 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCMD5
|
||||
// Description: Provides MD5 Hashing 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
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
static uchar _md5_PADDING[64] =
|
||||
{
|
||||
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
|
||||
//
|
||||
#define _md5_F(x, y, z) (((x) & (y)) | ((~x) & (z)))
|
||||
#define _md5_G(x, y, z) (((x) & (z)) | ((y) & (~z)))
|
||||
#define _md5_H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
#define _md5_I(x, y, z) ((y) ^ ((x) | (~z)))
|
||||
#define _md5_ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
|
||||
|
||||
//
|
||||
#define _md5_FF(a, b, c, d, x, s, ac) \
|
||||
{ \
|
||||
(a) += _md5_F((b), (c), (d)) + (x) + (uint)(ac); \
|
||||
(a) = _md5_ROTATE_LEFT((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
//
|
||||
#define _md5_GG(a, b, c, d, x, s, ac) \
|
||||
{ \
|
||||
(a) += _md5_G((b), (c), (d)) + (x) + (uint)(ac); \
|
||||
(a) = _md5_ROTATE_LEFT((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
//
|
||||
#define _md5_HH(a, b, c, d, x, s, ac) \
|
||||
{ \
|
||||
(a) += _md5_H((b), (c), (d)) + (x) + (uint)(ac); \
|
||||
(a) = _md5_ROTATE_LEFT((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
//
|
||||
#define _md5_II(a, b, c, d, x, s, ac) \
|
||||
{ \
|
||||
(a) += _md5_I((b), (c), (d)) + (x) + (uint)(ac); \
|
||||
(a) = _md5_ROTATE_LEFT((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
//
|
||||
#define _md5_INIT_STATE_0 0x67452301
|
||||
#define _md5_INIT_STATE_1 0xefcdab89
|
||||
#define _md5_INIT_STATE_2 0x98badcfe
|
||||
#define _md5_INIT_STATE_3 0x10325476
|
||||
|
||||
//
|
||||
#define _md5_S11 7
|
||||
#define _md5_S12 12
|
||||
#define _md5_S13 17
|
||||
#define _md5_S14 22
|
||||
|
||||
//
|
||||
#define _md5_S21 5
|
||||
#define _md5_S22 9
|
||||
#define _md5_S23 14
|
||||
#define _md5_S24 20
|
||||
|
||||
//
|
||||
#define _md5_S31 4
|
||||
#define _md5_S32 11
|
||||
#define _md5_S33 16
|
||||
#define _md5_S34 23
|
||||
|
||||
//
|
||||
#define _md5_S41 6
|
||||
#define _md5_S42 10
|
||||
#define _md5_S43 15
|
||||
#define _md5_S44 21
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// XCMD5 a library for Hashing ...
|
||||
class XCMD5
|
||||
{
|
||||
//
|
||||
// Public Provides ...
|
||||
public:
|
||||
//
|
||||
// Protected Provides ...
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XCMD5(void)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCMD5(void)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Hash Specified Char Array ...
|
||||
string Hash(
|
||||
uchar &mSource[], // Specify Char Array to Hash
|
||||
int mLength = 0 // Specify Length of Char Array which required to hash
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
int sourceCount = ArraySize(mSource);
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
sourceCount <= 0 ||
|
||||
(sourceCount > 0 && mLength > sourceCount))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Normalize Args ...
|
||||
if (mLength == 0)
|
||||
{
|
||||
mLength = sourceCount;
|
||||
}
|
||||
|
||||
//
|
||||
// Init MD5 ...
|
||||
MD5Init();
|
||||
|
||||
//
|
||||
// Update Buffer ...
|
||||
MD5Update(mSource, mLength);
|
||||
|
||||
//
|
||||
// Calculate Result ...
|
||||
result = MD5Final();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Hash Specified String ...
|
||||
string Hash(
|
||||
string mSource // Specified String
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
// Converts String to Char Array ...
|
||||
uchar bytes[];
|
||||
StringToCharArray(
|
||||
mSource,
|
||||
bytes,
|
||||
0,
|
||||
StringLen(mSource));
|
||||
|
||||
//
|
||||
result = Hash(
|
||||
bytes,
|
||||
ArraySize(bytes));
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
protected:
|
||||
//
|
||||
// Private Provides ...
|
||||
private:
|
||||
//
|
||||
uint m_lMD5[4];
|
||||
uint m_nCount[2];
|
||||
uchar m_lpszBuffer[64];
|
||||
|
||||
//
|
||||
// Convert Byte to DWord ...
|
||||
void ByteToDWord(int &out[], uint &in[], uint len)
|
||||
{
|
||||
//
|
||||
uint i = 0;
|
||||
uint j = 0;
|
||||
|
||||
//
|
||||
for (; j < len; i++, j += 4)
|
||||
{
|
||||
out[i] = (int)in[j] | (int)in[j + 1] << 8 | (int)in[j + 2] << 16 | (int)in[j + 3] << 24;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Convert DWord to Byte ...
|
||||
void DWordToByte(uchar &out[], int &in[], uint len)
|
||||
{
|
||||
//
|
||||
uint i = 0;
|
||||
uint j = 0;
|
||||
|
||||
//
|
||||
for (; j < len; i++, j += 4)
|
||||
{
|
||||
//
|
||||
out[j] = (uchar)(in[i] & 0xff);
|
||||
out[j + 1] = (uchar)((in[i] >> 8) & 0xff);
|
||||
out[j + 2] = (uchar)((in[i] >> 16) & 0xff);
|
||||
out[j + 3] = (uchar)((in[i] >> 24) & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Init MD5 Array ...
|
||||
void MD5Init()
|
||||
{
|
||||
//
|
||||
ArrayInitialize(m_lpszBuffer, 64);
|
||||
|
||||
//
|
||||
m_nCount[0] = m_nCount[1] = 0;
|
||||
m_lMD5[0] = _md5_INIT_STATE_0;
|
||||
m_lMD5[1] = _md5_INIT_STATE_1;
|
||||
m_lMD5[2] = _md5_INIT_STATE_2;
|
||||
m_lMD5[3] = _md5_INIT_STATE_3;
|
||||
}
|
||||
|
||||
//
|
||||
// Update MD5 ...
|
||||
void MD5Update(uchar &inBuf[], uint inLen)
|
||||
{
|
||||
//
|
||||
int i, ii;
|
||||
int mdi;
|
||||
|
||||
//
|
||||
uint in[16];
|
||||
int i0 = 0;
|
||||
|
||||
//
|
||||
mdi = (int)((m_nCount[0] >> 3) & 0x3F);
|
||||
|
||||
//
|
||||
if ((m_nCount[0] + ((uint)inLen << 3)) < m_nCount[0])
|
||||
{
|
||||
m_nCount[1]++;
|
||||
}
|
||||
|
||||
//
|
||||
m_nCount[0] += ((uint)inLen << 3);
|
||||
m_nCount[1] += ((uint)inLen >> 29);
|
||||
|
||||
//
|
||||
while ((inLen--) > 0)
|
||||
{
|
||||
//
|
||||
m_lpszBuffer[mdi++] = inBuf[i0++];
|
||||
if (mdi == 0x40)
|
||||
{
|
||||
//
|
||||
for (i = 0, ii = 0; i < 16; i++, ii += 4)
|
||||
{
|
||||
in[i] = (((uint)m_lpszBuffer[ii + 3]) << 24) | (((uint)m_lpszBuffer[ii + 2]) << 16) | (((uint)m_lpszBuffer[ii + 1]) << 8) | ((uint)m_lpszBuffer[ii]);
|
||||
}
|
||||
|
||||
//
|
||||
Transform(m_lMD5, in);
|
||||
|
||||
//
|
||||
mdi = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Finalize an MD5 Expression ...
|
||||
string MD5Final()
|
||||
{
|
||||
//
|
||||
uchar bits[8];
|
||||
int nIndex;
|
||||
uint nPadLen;
|
||||
const int nMD5Size = 16;
|
||||
uchar lpszMD5[16];
|
||||
string temp;
|
||||
string out = "";
|
||||
int i;
|
||||
|
||||
//
|
||||
DWordToByte(bits, m_nCount, 8);
|
||||
nIndex = (int)((m_nCount[0] >> 3) & 0x3f);
|
||||
nPadLen = (nIndex < 56) ? (56 - nIndex) : (120 - nIndex);
|
||||
MD5Update(_md5_PADDING, nPadLen);
|
||||
MD5Update(bits, 8);
|
||||
DWordToByte(lpszMD5, m_lMD5, nMD5Size);
|
||||
|
||||
//
|
||||
for (i = 0; i < nMD5Size; i++)
|
||||
{
|
||||
//
|
||||
if (lpszMD5[i] == 0)
|
||||
{
|
||||
temp = "00";
|
||||
}
|
||||
else if (lpszMD5[i] <= 15)
|
||||
{
|
||||
temp = StringFormat("0%x", lpszMD5[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
temp = StringFormat("%x", lpszMD5[i]);
|
||||
}
|
||||
|
||||
//
|
||||
out += temp;
|
||||
}
|
||||
|
||||
//
|
||||
lpszMD5[0] = '\0';
|
||||
|
||||
//
|
||||
return (out);
|
||||
}
|
||||
|
||||
//
|
||||
// Transform Buffers ...
|
||||
void Transform(uint &buf[], uint &in[])
|
||||
{
|
||||
//
|
||||
uint a = buf[0], b = buf[1], c = buf[2], d = buf[3];
|
||||
|
||||
//
|
||||
_md5_FF(a, b, c, d, in[0], _md5_S11, 0xD76AA478);
|
||||
_md5_FF(d, a, b, c, in[1], _md5_S12, 0xE8C7B756);
|
||||
_md5_FF(c, d, a, b, in[2], _md5_S13, 0x242070DB);
|
||||
_md5_FF(b, c, d, a, in[3], _md5_S14, 0xC1BDCEEE);
|
||||
_md5_FF(a, b, c, d, in[4], _md5_S11, 0xF57C0FAF);
|
||||
_md5_FF(d, a, b, c, in[5], _md5_S12, 0x4787C62A);
|
||||
_md5_FF(c, d, a, b, in[6], _md5_S13, 0xA8304613);
|
||||
_md5_FF(b, c, d, a, in[7], _md5_S14, 0xFD469501);
|
||||
_md5_FF(a, b, c, d, in[8], _md5_S11, 0x698098D8);
|
||||
_md5_FF(d, a, b, c, in[9], _md5_S12, 0x8B44F7AF);
|
||||
_md5_FF(c, d, a, b, in[10], _md5_S13, 0xFFFF5BB1);
|
||||
_md5_FF(b, c, d, a, in[11], _md5_S14, 0x895CD7BE);
|
||||
_md5_FF(a, b, c, d, in[12], _md5_S11, 0x6B901122);
|
||||
_md5_FF(d, a, b, c, in[13], _md5_S12, 0xFD987193);
|
||||
_md5_FF(c, d, a, b, in[14], _md5_S13, 0xA679438E);
|
||||
_md5_FF(b, c, d, a, in[15], _md5_S14, 0x49B40821);
|
||||
|
||||
//
|
||||
_md5_GG(a, b, c, d, in[1], _md5_S21, 0xF61E2562);
|
||||
_md5_GG(d, a, b, c, in[6], _md5_S22, 0xC040B340);
|
||||
_md5_GG(c, d, a, b, in[11], _md5_S23, 0x265E5A51);
|
||||
_md5_GG(b, c, d, a, in[0], _md5_S24, 0xE9B6C7AA);
|
||||
_md5_GG(a, b, c, d, in[5], _md5_S21, 0xD62F105D);
|
||||
_md5_GG(d, a, b, c, in[10], _md5_S22, 0x02441453);
|
||||
_md5_GG(c, d, a, b, in[15], _md5_S23, 0xD8A1E681);
|
||||
_md5_GG(b, c, d, a, in[4], _md5_S24, 0xE7D3FBC8);
|
||||
_md5_GG(a, b, c, d, in[9], _md5_S21, 0x21E1CDE6);
|
||||
_md5_GG(d, a, b, c, in[14], _md5_S22, 0xC33707D6);
|
||||
_md5_GG(c, d, a, b, in[3], _md5_S23, 0xF4D50D87);
|
||||
_md5_GG(b, c, d, a, in[8], _md5_S24, 0x455A14ED);
|
||||
_md5_GG(a, b, c, d, in[13], _md5_S21, 0xA9E3E905);
|
||||
_md5_GG(d, a, b, c, in[2], _md5_S22, 0xFCEFA3F8);
|
||||
_md5_GG(c, d, a, b, in[7], _md5_S23, 0x676F02D9);
|
||||
_md5_GG(b, c, d, a, in[12], _md5_S24, 0x8D2A4C8A);
|
||||
|
||||
//
|
||||
_md5_HH(a, b, c, d, in[5], _md5_S31, 0xFFFA3942);
|
||||
_md5_HH(d, a, b, c, in[8], _md5_S32, 0x8771F681);
|
||||
_md5_HH(c, d, a, b, in[11], _md5_S33, 0x6D9D6122);
|
||||
_md5_HH(b, c, d, a, in[14], _md5_S34, 0xFDE5380C);
|
||||
_md5_HH(a, b, c, d, in[1], _md5_S31, 0xA4BEEA44);
|
||||
_md5_HH(d, a, b, c, in[4], _md5_S32, 0x4BDECFA9);
|
||||
_md5_HH(c, d, a, b, in[7], _md5_S33, 0xF6BB4B60);
|
||||
_md5_HH(b, c, d, a, in[10], _md5_S34, 0xBEBFBC70);
|
||||
_md5_HH(a, b, c, d, in[13], _md5_S31, 0x289B7EC6);
|
||||
_md5_HH(d, a, b, c, in[0], _md5_S32, 0xEAA127FA);
|
||||
_md5_HH(c, d, a, b, in[3], _md5_S33, 0xD4EF3085);
|
||||
_md5_HH(b, c, d, a, in[6], _md5_S34, 0x04881D05);
|
||||
_md5_HH(a, b, c, d, in[9], _md5_S31, 0xD9D4D039);
|
||||
_md5_HH(d, a, b, c, in[12], _md5_S32, 0xE6DB99E5);
|
||||
_md5_HH(c, d, a, b, in[15], _md5_S33, 0x1FA27CF8);
|
||||
_md5_HH(b, c, d, a, in[2], _md5_S34, 0xC4AC5665);
|
||||
|
||||
//
|
||||
_md5_II(a, b, c, d, in[0], _md5_S41, 0xF4292244);
|
||||
_md5_II(d, a, b, c, in[7], _md5_S42, 0x432AFF97);
|
||||
_md5_II(c, d, a, b, in[14], _md5_S43, 0xAB9423A7);
|
||||
_md5_II(b, c, d, a, in[5], _md5_S44, 0xFC93A039);
|
||||
_md5_II(a, b, c, d, in[12], _md5_S41, 0x655B59C3);
|
||||
_md5_II(d, a, b, c, in[3], _md5_S42, 0x8F0CCC92);
|
||||
_md5_II(c, d, a, b, in[10], _md5_S43, 0xFFEFF47D);
|
||||
_md5_II(b, c, d, a, in[1], _md5_S44, 0x85845DD1);
|
||||
_md5_II(a, b, c, d, in[8], _md5_S41, 0x6FA87E4F);
|
||||
_md5_II(d, a, b, c, in[15], _md5_S42, 0xFE2CE6E0);
|
||||
_md5_II(c, d, a, b, in[6], _md5_S43, 0xA3014314);
|
||||
_md5_II(b, c, d, a, in[13], _md5_S44, 0x4E0811A1);
|
||||
_md5_II(a, b, c, d, in[4], _md5_S41, 0xF7537E82);
|
||||
_md5_II(d, a, b, c, in[11], _md5_S42, 0xBD3AF235);
|
||||
_md5_II(c, d, a, b, in[2], _md5_S43, 0x2AD7D2BB);
|
||||
_md5_II(b, c, d, a, in[9], _md5_S44, 0xEB86D391);
|
||||
|
||||
//
|
||||
buf[0] += a;
|
||||
buf[1] += b;
|
||||
buf[2] += c;
|
||||
buf[3] += d;
|
||||
}
|
||||
};
|
||||
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
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,831 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 X121 SMC Signal Class
|
||||
// -------------------------------------------------
|
||||
// Name:
|
||||
// Description: provide all Signalling 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-121.smc.market.cycle.helper.class.mq5"
|
||||
#include "../Libraries/x-121.smc.lib.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
struct X121SMCStrategyTestSignalConditions
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
double sl;
|
||||
ENUM_X_DIRECTION dir;
|
||||
ENUM_X_POSITION_TYPES type;
|
||||
|
||||
//
|
||||
// Setup Props ...
|
||||
|
||||
//
|
||||
datetime setupTime;
|
||||
datetime triggerTime;
|
||||
|
||||
//
|
||||
XPVPivot pivot;
|
||||
|
||||
//
|
||||
// Trigger Props ...
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
X121SMCStrategyTestSignalConditions()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleaning Up ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
sl = 0;
|
||||
|
||||
//
|
||||
dir = X_DIRECTION_NONE;
|
||||
type = X_POSITION_TYPE_NONE;
|
||||
|
||||
//
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
setupTime = NULL;
|
||||
triggerTime = NULL;
|
||||
|
||||
//
|
||||
pivot.Clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Condition is Setting Up ...
|
||||
*
|
||||
* @param dir: ENUM_X_DIRECTION member, Setting Up Direction ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsSetuped()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid(setupTime) &&
|
||||
HasDirection(dir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect How we Can Trigger Signal ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool CanTrigger()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
sl > 0 &&
|
||||
IsValid(symbol) &&
|
||||
IsValid(period) &&
|
||||
IsValid(triggerTime) &&
|
||||
type != X_POSITION_TYPE_ALL &&
|
||||
type != X_POSITION_TYPE_NONE
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Extensions ...
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Extension Functions ...
|
||||
|
||||
//
|
||||
// Detect Setup Conditions ...
|
||||
bool DetectX121SMCTestSiganlSetup(
|
||||
string _symbol,
|
||||
ENUM_TIMEFRAMES _period,
|
||||
//
|
||||
X121SMCStrategyTestSignalConditions &conditions,
|
||||
//
|
||||
XC121SMCCycleHelper *triggerCycleHelper,
|
||||
XC121SMCCycleHelper *decisionCycleHelper,
|
||||
XC121SMCCycleHelper *analyseCycleHelper,
|
||||
XC121SMCCycleHelper *verificationCycleHelper,
|
||||
XC121SMCCycleHelper *consolidationCycleHelper,
|
||||
XC121SMCCycleHelper *visionCycleHelper
|
||||
//
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
int zIndex = 0;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
int loopback = 10;
|
||||
|
||||
//
|
||||
string symbol = _symbol;
|
||||
ENUM_TIMEFRAMES period = _period;
|
||||
|
||||
//
|
||||
conditions.symbol = symbol;
|
||||
conditions.period = period;
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
result = zBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
zIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL cBar;
|
||||
result = cBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
cIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double ask = GetAsk(symbol);
|
||||
double bid = GetBid(symbol);
|
||||
datetime cTime = TimeCurrent();
|
||||
|
||||
//
|
||||
double ll = cBar.FindLowest(9, MODE_LOW);
|
||||
double hh = cBar.FindHighest(9, MODE_HIGH);
|
||||
|
||||
//
|
||||
int zoneValidationDivider = 10;
|
||||
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
||||
.GetDonChainLength();
|
||||
|
||||
//
|
||||
double selectedSL = 0;
|
||||
|
||||
//
|
||||
// Cycles Conditions ...
|
||||
|
||||
//
|
||||
// Trigger ...
|
||||
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
||||
X121SMCCycleConditions triggerConditions;
|
||||
result = triggerCycleHelper.GetConditions(
|
||||
triggerCycleEvents,
|
||||
triggerPoiEvents,
|
||||
triggerConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Decision ...
|
||||
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
||||
X121SMCCycleConditions decisionConditions;
|
||||
result = decisionCycleHelper.GetConditions(
|
||||
decisionCycleEvents,
|
||||
decisionPoiEvents,
|
||||
decisionConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Analyse ...
|
||||
ENUM_XPOI_EVENTS analysePoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
||||
X121SMCCycleConditions analyseConditions;
|
||||
result = analyseCycleHelper.GetConditions(
|
||||
analyseCycleEvents,
|
||||
analysePoiEvents,
|
||||
analyseConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Verification ...
|
||||
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
||||
X121SMCCycleConditions verificationConditions;
|
||||
result = verificationCycleHelper.GetConditions(
|
||||
verificationCycleEvents,
|
||||
verificationPoiEvents,
|
||||
verificationConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Consolidation ...
|
||||
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
||||
X121SMCCycleConditions consolidationConditions;
|
||||
result = consolidationCycleHelper.GetConditions(
|
||||
consolidationCycleEvents,
|
||||
consolidationPoiEvents,
|
||||
consolidationConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Vision ...
|
||||
ENUM_XPOI_EVENTS visionPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
||||
X121SMCCycleConditions visionConditions;
|
||||
result = visionCycleHelper.GetConditions(
|
||||
visionCycleEvents,
|
||||
visionPoiEvents,
|
||||
visionConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Cycles POI States ...
|
||||
XPOIState triggerState = triggerConditions.state;
|
||||
XPOIState decisionState = decisionConditions.state;
|
||||
XPOIState analyseState = analyseConditions.state;
|
||||
XPOIState verificationState = verificationConditions.state;
|
||||
XPOIState consolidationState = consolidationConditions.state;
|
||||
XPOIState visionState = visionConditions.state;
|
||||
|
||||
//
|
||||
// Detect new Peak or new Vale ...
|
||||
|
||||
//
|
||||
bool isNewPeak = triggerConditions.x121Conditions.isNewPeak;
|
||||
double peak = triggerConditions.x121Conditions.peaksBuffer[1];
|
||||
bool isNewPeakOverLast = triggerConditions.x121Conditions.isNewPeakOverLast;
|
||||
bool isNewPeakUnderLast = triggerConditions.x121Conditions.isNewPeakUnderLast;
|
||||
|
||||
//
|
||||
bool isNewVale = triggerConditions.x121Conditions.isNewVale;
|
||||
double vale = triggerConditions.x121Conditions.valesBuffer[1];
|
||||
bool isNewValeOverLast = triggerConditions.x121Conditions.isNewValeOverLast;
|
||||
bool isNewValeUnderLast = triggerConditions.x121Conditions.isNewValeUnderLast;
|
||||
|
||||
//
|
||||
result = isNewPeak ||
|
||||
isNewVale;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Pivot ...
|
||||
bool hasPivot = conditions.pivot.IsValid();
|
||||
if (!hasPivot)
|
||||
{
|
||||
//
|
||||
XPVPivot pivot;
|
||||
hasPivot = triggerCycleHelper.DetectPivot(
|
||||
pivot,
|
||||
cBar //
|
||||
);
|
||||
result = hasPivot;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.pivot = pivot;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Order Block ...
|
||||
// TODO: Later ...
|
||||
// bool hasOrderBlock = conditions.HasOrderBlock();
|
||||
// if (hasOrderBlock)
|
||||
// {
|
||||
// //
|
||||
// DetectX121SMCTestSiganlOrderBlock(
|
||||
// zBar,
|
||||
// consolidationState,
|
||||
// conditions //
|
||||
// );
|
||||
// }
|
||||
|
||||
//
|
||||
bool isMarketBullish =
|
||||
//
|
||||
// VWap State ...
|
||||
decisionConditions.x121Conditions.isVWapBullishState &&
|
||||
analyseConditions.x121Conditions.isVWapBullishState &&
|
||||
verificationConditions.x121Conditions.isVWapBullishState
|
||||
//
|
||||
&&
|
||||
//
|
||||
// VWap Order ...
|
||||
decisionConditions.x121Conditions.isVWapBullishOrdered &&
|
||||
analyseConditions.x121Conditions.isVWapBullishOrdered &&
|
||||
verificationConditions.x121Conditions.isVWapBullishOrdered
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Sar ...
|
||||
decisionConditions.x121Conditions.isSarBullish &&
|
||||
analyseConditions.x121Conditions.isSarBullish &&
|
||||
verificationConditions.x121Conditions.isSarBullish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isMarketBearish =
|
||||
//
|
||||
// VWap State ...
|
||||
decisionConditions.x121Conditions.isVWapBearishState &&
|
||||
analyseConditions.x121Conditions.isVWapBearishState &&
|
||||
verificationConditions.x121Conditions.isVWapBearishState
|
||||
//
|
||||
&&
|
||||
//
|
||||
// VWap Order ...
|
||||
decisionConditions.x121Conditions.isVWapBearishOrdered &&
|
||||
analyseConditions.x121Conditions.isVWapBearishOrdered &&
|
||||
verificationConditions.x121Conditions.isVWapBearishOrdered
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Sar ...
|
||||
decisionConditions.x121Conditions.isSarBearish &&
|
||||
analyseConditions.x121Conditions.isSarBearish &&
|
||||
verificationConditions.x121Conditions.isSarBearish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Step 1
|
||||
// Detect Market Direction ...
|
||||
isBullish = isMarketBullish;
|
||||
isBearish = isMarketBearish;
|
||||
|
||||
//
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Step 2
|
||||
// VWap Switches or Sar Switches ...
|
||||
|
||||
//
|
||||
bool isSarBullish = triggerConditions.x121Conditions.isSarBullish;
|
||||
bool isSarBearish = triggerConditions.x121Conditions.isSarBearish;
|
||||
|
||||
//
|
||||
bool isSarSwitchedToBullish = triggerConditions.x121Conditions.isSarSwitchedToBullish;
|
||||
bool isSarSwitchedToBearish = triggerConditions.x121Conditions.isSarSwitchedToBearish;
|
||||
|
||||
//
|
||||
bool isVWapBullishState = triggerConditions.x121Conditions.isVWapBullishState;
|
||||
bool isVWapBearishState = triggerConditions.x121Conditions.isVWapBearishState;
|
||||
|
||||
//
|
||||
bool isVWapSwitchedToBullishState = triggerConditions.x121Conditions.isVWapSwitchedToBullishState;
|
||||
bool isVWapSwitchedToBearishState = triggerConditions.x121Conditions.isVWapSwitchedToBearishState;
|
||||
|
||||
//
|
||||
bool isVWapBullishOrdered = triggerConditions.x121Conditions.isVWapBullishOrdered;
|
||||
bool isVWapBearishOrdered = triggerConditions.x121Conditions.isVWapBearishOrdered;
|
||||
|
||||
//
|
||||
bool isVWapSwitchedToBullishOrdered = triggerConditions.x121Conditions.isVWapSwitchedToBullishOrdered;
|
||||
bool isVWapSwitchedToBearishOrdered = triggerConditions.x121Conditions.isVWapSwitchedToBearishOrdered;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//
|
||||
bool isSarStartedBullishStructure =
|
||||
//
|
||||
isSarSwitchedToBullish &&
|
||||
isVWapBullishState &&
|
||||
isVWapBullishOrdered
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSarStartedBearishStructure =
|
||||
//
|
||||
isSarSwitchedToBearish &&
|
||||
isVWapBearishState &&
|
||||
isVWapBearishOrdered
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//
|
||||
bool isVWapStateStartedBullishStructure =
|
||||
//
|
||||
isVWapSwitchedToBullishState &&
|
||||
isSarBullish &&
|
||||
isVWapBullishOrdered
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isVWapStateStartedBearishStructure =
|
||||
//
|
||||
isVWapSwitchedToBearishState &&
|
||||
isSarBearish &&
|
||||
isVWapBearishOrdered
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//
|
||||
bool isVWapOrderStartedBullishStructure =
|
||||
//
|
||||
isVWapSwitchedToBullishOrdered &&
|
||||
isSarBullish &&
|
||||
isVWapBullishState
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isVWapOrderStartedBearishStructure =
|
||||
//
|
||||
isVWapSwitchedToBearishOrdered &&
|
||||
isSarBearish &&
|
||||
isVWapBearishState
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//
|
||||
isBullish =
|
||||
//
|
||||
isBullish
|
||||
//
|
||||
&&
|
||||
//
|
||||
(
|
||||
//
|
||||
isSarStartedBullishStructure ||
|
||||
isVWapStateStartedBullishStructure ||
|
||||
isVWapOrderStartedBullishStructure
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
//
|
||||
isBearish
|
||||
//
|
||||
&&
|
||||
//
|
||||
(
|
||||
//
|
||||
isSarStartedBearishStructure ||
|
||||
isVWapStateStartedBearishStructure ||
|
||||
isVWapOrderStartedBearishStructure
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.setupTime = cTime;
|
||||
conditions.dir =
|
||||
isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Trigger Conditions ...
|
||||
bool DetectX121SMCTestSiganlTrigger(
|
||||
//
|
||||
X121SMCStrategyTestSignalConditions &conditions,
|
||||
//
|
||||
string _symbol,
|
||||
ENUM_TIMEFRAMES _period,
|
||||
//
|
||||
XC121SMCCycleHelper *triggerCycleHelper,
|
||||
XC121SMCCycleHelper *decisionCycleHelper,
|
||||
XC121SMCCycleHelper *analyseCycleHelper,
|
||||
XC121SMCCycleHelper *verificationCycleHelper,
|
||||
XC121SMCCycleHelper *consolidationCycleHelper,
|
||||
XC121SMCCycleHelper *visionCycleHelper
|
||||
//
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = conditions.IsSetuped();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
ENUM_X_DIRECTION setupDir = conditions.dir;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
int zIndex = 0;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
int loopback = 10;
|
||||
|
||||
//
|
||||
ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_SMPV;
|
||||
string providerStr = ToString(provider);
|
||||
|
||||
//
|
||||
string symbol = _symbol;
|
||||
ENUM_TIMEFRAMES period = _period;
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
result = zBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
zIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL cBar;
|
||||
result = cBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
cIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double ask = GetAsk(symbol);
|
||||
double bid = GetBid(symbol);
|
||||
datetime cTime = TimeCurrent();
|
||||
|
||||
//
|
||||
double ll = cBar.FindLowest(9, MODE_LOW);
|
||||
double hh = cBar.FindHighest(9, MODE_HIGH);
|
||||
|
||||
//
|
||||
int zoneValidationDivider = 10;
|
||||
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
||||
.GetDonChainLength();
|
||||
|
||||
//
|
||||
double selectedSL = 0;
|
||||
|
||||
//
|
||||
// Cycles Conditions ...
|
||||
|
||||
//
|
||||
// Trigger ...
|
||||
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
||||
X121SMCCycleConditions triggerConditions;
|
||||
result = triggerCycleHelper.GetConditions(
|
||||
triggerCycleEvents,
|
||||
triggerPoiEvents,
|
||||
triggerConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Decision ...
|
||||
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
||||
X121SMCCycleConditions decisionConditions;
|
||||
result = decisionCycleHelper.GetConditions(
|
||||
decisionCycleEvents,
|
||||
decisionPoiEvents,
|
||||
decisionConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Analyse ...
|
||||
ENUM_XPOI_EVENTS analysePoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
||||
X121SMCCycleConditions analyseConditions;
|
||||
result = analyseCycleHelper.GetConditions(
|
||||
analyseCycleEvents,
|
||||
analysePoiEvents,
|
||||
analyseConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Verification ...
|
||||
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
||||
X121SMCCycleConditions verificationConditions;
|
||||
result = verificationCycleHelper.GetConditions(
|
||||
verificationCycleEvents,
|
||||
verificationPoiEvents,
|
||||
verificationConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Consolidation ...
|
||||
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
||||
X121SMCCycleConditions consolidationConditions;
|
||||
result = consolidationCycleHelper.GetConditions(
|
||||
consolidationCycleEvents,
|
||||
consolidationPoiEvents,
|
||||
consolidationConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Vision ...
|
||||
ENUM_XPOI_EVENTS visionPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
||||
X121SMCCycleConditions visionConditions;
|
||||
result = visionCycleHelper.GetConditions(
|
||||
visionCycleEvents,
|
||||
visionPoiEvents,
|
||||
visionConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Cycles POI States ...
|
||||
XPOIState triggerState = triggerConditions.state;
|
||||
XPOIState decisionState = decisionConditions.state;
|
||||
XPOIState analyseState = analyseConditions.state;
|
||||
XPOIState verificationState = verificationConditions.state;
|
||||
XPOIState consolidationState = consolidationConditions.state;
|
||||
XPOIState visionState = visionConditions.state;
|
||||
|
||||
//
|
||||
result = false;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Tools Functions ...
|
||||
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,75 @@
|
||||
//
|
||||
// Decision ...
|
||||
|
||||
//
|
||||
// Peak ...
|
||||
bool isDecisionNewPeak = decisionConditions.x121Conditions.isNewPeak;
|
||||
bool isDecisionNewPeakOverLast = decisionConditions.x121Conditions.isNewPeakOverLast;
|
||||
bool isDecisionNewPeakUnderLast = decisionConditions.x121Conditions.isNewPeakUnderLast;
|
||||
double decisionPeak = decisionConditions.x121Conditions.peaksBuffer[1];
|
||||
XPVPivotPoint decisionPeakPivots[];
|
||||
XPVPivotPoint decisionLastPeakPivot;
|
||||
XPVPivotPoint decisionPrevPeakPivot;
|
||||
int decisionPeakPivotsCount = decisionCycleHelper
|
||||
.FillPeakPivotPoints(decisionPeakPivots);
|
||||
bool hasDecisionPeak = decisionPeakPivotsCount >= 2;
|
||||
if (hasDecisionPeak)
|
||||
{
|
||||
//
|
||||
decisionLastPeakPivot = decisionPeakPivots[decisionPeakPivotsCount - 1];
|
||||
decisionPrevPeakPivot = decisionPeakPivots[decisionPeakPivotsCount - 2];
|
||||
}
|
||||
|
||||
//
|
||||
// Vale ...
|
||||
bool isDecisionNewVale = decisionConditions.x121Conditions.isNewVale;
|
||||
bool isDecisionNewValeOverLast = decisionConditions.x121Conditions.isNewValeOverLast;
|
||||
bool isDecisionNewValeUnderLast = decisionConditions.x121Conditions.isNewValeUnderLast;
|
||||
double decisionVale = decisionConditions.x121Conditions.valesBuffer[1];
|
||||
XPVPivotPoint decisionValePivots[];
|
||||
XPVPivotPoint decisionLastValePivot;
|
||||
XPVPivotPoint decisionPrevValePivot;
|
||||
int decisionValePivotsCount = decisionCycleHelper
|
||||
.FillValePivotPoints(decisionValePivots);
|
||||
bool hasDecisionVale = decisionValePivotsCount >= 2;
|
||||
if (hasDecisionVale)
|
||||
{
|
||||
//
|
||||
decisionLastValePivot = decisionValePivots[decisionValePivotsCount - 1];
|
||||
decisionPrevValePivot = decisionValePivots[decisionValePivotsCount - 2];
|
||||
}
|
||||
|
||||
//
|
||||
bool isDecisionBullish =
|
||||
//
|
||||
hasDecisionVale &&
|
||||
isDecisionNewVale &&
|
||||
isDecisionNewValeUnderLast &&
|
||||
decisionLastValePivot.value > decisionPrevValePivot.value
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isDecisionBearish =
|
||||
//
|
||||
false &&
|
||||
hasDecisionPeak &&
|
||||
decisionLastPeakPivot.value
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (isDecisionBullish ||
|
||||
isDecisionBearish)
|
||||
{
|
||||
//
|
||||
conditions.pivot =
|
||||
isDecisionBullish
|
||||
? decisionVale
|
||||
: decisionPeak;
|
||||
conditions.dir =
|
||||
isDecisionBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
conditions.cycle = X_CYCLE_DECISION;
|
||||
}
|
||||
@@ -0,0 +1,830 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 X121 SMC Signal Class
|
||||
// -------------------------------------------------
|
||||
// Name:
|
||||
// Description: provide all Signalling 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-121.smc.market.cycle.helper.class.mq5"
|
||||
#include "../Libraries/x-121.smc.lib.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
struct X121SMCStrategyTestSignalConditions
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
double sl;
|
||||
ENUM_X_DIRECTION dir;
|
||||
ENUM_X_POSITION_TYPES type;
|
||||
|
||||
//
|
||||
// Setup Props ...
|
||||
|
||||
//
|
||||
datetime setupTime;
|
||||
datetime triggerTime;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
X121SMCStrategyTestSignalConditions()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleaning Up ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
sl = 0;
|
||||
|
||||
//
|
||||
dir = X_DIRECTION_NONE;
|
||||
type = X_POSITION_TYPE_NONE;
|
||||
|
||||
//
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
setupTime = NULL;
|
||||
triggerTime = NULL;
|
||||
|
||||
//
|
||||
ExtensionClean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Condition is Setting Up ...
|
||||
*
|
||||
* @param dir: ENUM_X_DIRECTION member, Setting Up Direction ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsSetuped()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid(setupTime) &&
|
||||
HasDirection(dir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Setup Age ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int GetSetupAge()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
if (!IsSetuped())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect How we Can Trigger Signal ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool CanTrigger()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
sl > 0 &&
|
||||
IsValid(symbol) &&
|
||||
IsValid(period) &&
|
||||
IsValid(triggerTime) &&
|
||||
type != X_POSITION_TYPE_ALL &&
|
||||
type != X_POSITION_TYPE_NONE
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Extensions ...
|
||||
|
||||
/**
|
||||
* Clean Additional Properties ...
|
||||
*/
|
||||
void ExtensionClean()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Extension Functions ...
|
||||
|
||||
//
|
||||
// Detect Setup Conditions ...
|
||||
bool DetectX121SMCTestSiganlSetup(
|
||||
string _symbol,
|
||||
ENUM_TIMEFRAMES _period,
|
||||
//
|
||||
X121SMCStrategyTestSignalConditions &conditions,
|
||||
//
|
||||
XC121SMCCycleHelper *triggerCycleHelper,
|
||||
XC121SMCCycleHelper *decisionCycleHelper,
|
||||
XC121SMCCycleHelper *analyseCycleHelper,
|
||||
XC121SMCCycleHelper *verificationCycleHelper,
|
||||
XC121SMCCycleHelper *consolidationCycleHelper,
|
||||
XC121SMCCycleHelper *visionCycleHelper
|
||||
//
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
int zIndex = 0;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
int loopback = 10;
|
||||
|
||||
//
|
||||
string symbol = _symbol;
|
||||
ENUM_TIMEFRAMES period = _period;
|
||||
|
||||
//
|
||||
conditions.symbol = symbol;
|
||||
conditions.period = period;
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
result = zBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
zIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL cBar;
|
||||
result = cBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
cIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double ask = GetAsk(symbol);
|
||||
double bid = GetBid(symbol);
|
||||
datetime cTime = TimeCurrent();
|
||||
|
||||
//
|
||||
double ll = cBar.FindLowest(9, MODE_LOW);
|
||||
double hh = cBar.FindHighest(9, MODE_HIGH);
|
||||
|
||||
//
|
||||
int zoneValidationDivider = 10;
|
||||
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
||||
.GetDonChainLength();
|
||||
|
||||
//
|
||||
double selectedSL = 0;
|
||||
|
||||
//
|
||||
// Cycles Conditions ...
|
||||
|
||||
//
|
||||
// Trigger ...
|
||||
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
||||
X121SMCCycleConditions triggerConditions;
|
||||
result = triggerCycleHelper.GetConditions(
|
||||
triggerCycleEvents,
|
||||
triggerPoiEvents,
|
||||
triggerConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Decision ...
|
||||
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
||||
X121SMCCycleConditions decisionConditions;
|
||||
result = decisionCycleHelper.GetConditions(
|
||||
decisionCycleEvents,
|
||||
decisionPoiEvents,
|
||||
decisionConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Analyse ...
|
||||
ENUM_XPOI_EVENTS analysePoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
||||
X121SMCCycleConditions analyseConditions;
|
||||
result = analyseCycleHelper.GetConditions(
|
||||
analyseCycleEvents,
|
||||
analysePoiEvents,
|
||||
analyseConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Verification ...
|
||||
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
||||
X121SMCCycleConditions verificationConditions;
|
||||
result = verificationCycleHelper.GetConditions(
|
||||
verificationCycleEvents,
|
||||
verificationPoiEvents,
|
||||
verificationConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Consolidation ...
|
||||
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
||||
X121SMCCycleConditions consolidationConditions;
|
||||
result = consolidationCycleHelper.GetConditions(
|
||||
consolidationCycleEvents,
|
||||
consolidationPoiEvents,
|
||||
consolidationConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Vision ...
|
||||
ENUM_XPOI_EVENTS visionPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
||||
X121SMCCycleConditions visionConditions;
|
||||
result = visionCycleHelper.GetConditions(
|
||||
visionCycleEvents,
|
||||
visionPoiEvents,
|
||||
visionConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Cycles POI States ...
|
||||
XPOIState triggerState = triggerConditions.state;
|
||||
XPOIState decisionState = decisionConditions.state;
|
||||
XPOIState analyseState = analyseConditions.state;
|
||||
XPOIState verificationState = verificationConditions.state;
|
||||
XPOIState consolidationState = consolidationConditions.state;
|
||||
XPOIState visionState = visionConditions.state;
|
||||
|
||||
//
|
||||
// Setup Conditions ...
|
||||
|
||||
//
|
||||
isBullish =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
// Clean Conditions for Regenerate ...
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.setupTime = cTime;
|
||||
conditions.dir =
|
||||
isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Trigger Conditions ...
|
||||
bool DetectX121SMCTestSiganlTrigger(
|
||||
//
|
||||
X121SMCStrategyTestSignalConditions &conditions,
|
||||
//
|
||||
string _symbol,
|
||||
ENUM_TIMEFRAMES _period,
|
||||
//
|
||||
XC121SMCCycleHelper *triggerCycleHelper,
|
||||
XC121SMCCycleHelper *decisionCycleHelper,
|
||||
XC121SMCCycleHelper *analyseCycleHelper,
|
||||
XC121SMCCycleHelper *verificationCycleHelper,
|
||||
XC121SMCCycleHelper *consolidationCycleHelper,
|
||||
XC121SMCCycleHelper *visionCycleHelper,
|
||||
//
|
||||
int maxAllowedSetupAge = 60 //
|
||||
//
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = conditions.IsSetuped();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
datetime setupTime = conditions.setupTime;
|
||||
ENUM_X_DIRECTION setupDir = conditions.dir;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
int zIndex = 0;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
int loopback = 10;
|
||||
|
||||
//
|
||||
string symbol = _symbol;
|
||||
ENUM_TIMEFRAMES period = _period;
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
result = zBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
zIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL cBar;
|
||||
result = cBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
cIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double ask = GetAsk(symbol);
|
||||
double bid = GetBid(symbol);
|
||||
datetime cTime = TimeCurrent();
|
||||
|
||||
//
|
||||
double ll = cBar.FindLowest(9, MODE_LOW);
|
||||
double hh = cBar.FindHighest(9, MODE_HIGH);
|
||||
|
||||
//
|
||||
int zoneValidationDivider = 10;
|
||||
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
||||
.GetDonChainLength();
|
||||
|
||||
//
|
||||
double selectedSL = 0;
|
||||
|
||||
//
|
||||
// Cycles Conditions ...
|
||||
|
||||
//
|
||||
// Trigger ...
|
||||
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
||||
X121SMCCycleConditions triggerConditions;
|
||||
result = triggerCycleHelper.GetConditions(
|
||||
triggerCycleEvents,
|
||||
triggerPoiEvents,
|
||||
triggerConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Decision ...
|
||||
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
||||
X121SMCCycleConditions decisionConditions;
|
||||
result = decisionCycleHelper.GetConditions(
|
||||
decisionCycleEvents,
|
||||
decisionPoiEvents,
|
||||
decisionConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Analyse ...
|
||||
ENUM_XPOI_EVENTS analysePoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
||||
X121SMCCycleConditions analyseConditions;
|
||||
result = analyseCycleHelper.GetConditions(
|
||||
analyseCycleEvents,
|
||||
analysePoiEvents,
|
||||
analyseConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Verification ...
|
||||
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
||||
X121SMCCycleConditions verificationConditions;
|
||||
result = verificationCycleHelper.GetConditions(
|
||||
verificationCycleEvents,
|
||||
verificationPoiEvents,
|
||||
verificationConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Consolidation ...
|
||||
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
||||
X121SMCCycleConditions consolidationConditions;
|
||||
result = consolidationCycleHelper.GetConditions(
|
||||
consolidationCycleEvents,
|
||||
consolidationPoiEvents,
|
||||
consolidationConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Vision ...
|
||||
ENUM_XPOI_EVENTS visionPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
||||
X121SMCCycleConditions visionConditions;
|
||||
result = visionCycleHelper.GetConditions(
|
||||
visionCycleEvents,
|
||||
visionPoiEvents,
|
||||
visionConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Cycles POI States ...
|
||||
XPOIState triggerState = triggerConditions.state;
|
||||
XPOIState decisionState = decisionConditions.state;
|
||||
XPOIState analyseState = analyseConditions.state;
|
||||
XPOIState verificationState = verificationConditions.state;
|
||||
XPOIState consolidationState = consolidationConditions.state;
|
||||
XPOIState visionState = visionConditions.state;
|
||||
|
||||
//
|
||||
// Trigger Conditions ...
|
||||
|
||||
//
|
||||
isBullish =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
// Cleanup Setup Conditions ...
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.triggerTime = cTime;
|
||||
conditions.sl = isBullish
|
||||
? 0
|
||||
: 0;
|
||||
conditions.type = isBullish
|
||||
? X_POSITION_TYPE_LONG
|
||||
: X_POSITION_TYPE_SHORT;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//
|
||||
// Test Signal ...
|
||||
X121SMCStrategyTestSignalConditions mTestConditions;
|
||||
bool DetectTestSignal(
|
||||
X121SMCStrategyConditions &conditions //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
string symbol = GetSymbol();
|
||||
ENUM_TIMEFRAMES period = GetPeriod();
|
||||
|
||||
//
|
||||
datetime cTime = TimeCurrent();
|
||||
|
||||
//
|
||||
ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XTEST;
|
||||
string providerStr = ToString(provider);
|
||||
|
||||
//
|
||||
// Detect Setup Conditions ...
|
||||
datetime setupTime = mTestConditions.setupTime;
|
||||
bool isSetuped = mTestConditions.IsSetuped();
|
||||
ENUM_X_DIRECTION setupDir = mTestConditions.dir;
|
||||
if (!isSetuped)
|
||||
{
|
||||
//
|
||||
// Detect Signal Setup ...
|
||||
isSetuped = DetectX121SMCTestSiganlSetup(
|
||||
symbol,
|
||||
period,
|
||||
mTestConditions,
|
||||
mTriggerCycleHelper,
|
||||
mDecisionCycleHelper,
|
||||
mAnalyseCycleHelper,
|
||||
mVerificationCycleHelper,
|
||||
mConsolidationCycleHelper,
|
||||
mVisionCycleHelper //
|
||||
);
|
||||
|
||||
//
|
||||
setupDir = mTestConditions.dir;
|
||||
setupTime = mTestConditions.setupTime;
|
||||
}
|
||||
|
||||
// ClearDraws();
|
||||
// ENUM_X_DIRECTION activeZoneDir;
|
||||
// bool hasTicksZone = mTestConditions.HasTicksZone();
|
||||
// bool hasActiveZone = mTestConditions.HasActiveZone(activeZoneDir);
|
||||
// if (hasActiveZone)
|
||||
// {
|
||||
// //
|
||||
// if (IsBullish(activeZoneDir))
|
||||
// {
|
||||
// //
|
||||
// mTestConditions.activeDemandZone.To(cTime);
|
||||
// XCDemandZoneObject *iObj;
|
||||
// bool isCreated = mPOIDrawer.CreateDemandZone(
|
||||
// mTestConditions.activeDemandZone,
|
||||
// iObj //
|
||||
// );
|
||||
// if (isCreated)
|
||||
// {
|
||||
// AddObjectIfNotExists(iObj);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //
|
||||
// mTestConditions.activeSupplyZone.To(cTime);
|
||||
// XCSupplyZoneObject *iObj;
|
||||
// bool isCreated = mPOIDrawer.CreateSupplyZone(
|
||||
// mTestConditions.activeSupplyZone,
|
||||
// iObj //
|
||||
// );
|
||||
// if (isCreated)
|
||||
// {
|
||||
// AddObjectIfNotExists(iObj);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (hasTicksZone)
|
||||
// {
|
||||
// //
|
||||
// XCTicksZoneObject *iObj;
|
||||
// bool isCreated = mPOIDrawer.CreateTicksZone(
|
||||
// mTestConditions.ticksZone,
|
||||
// iObj //
|
||||
// );
|
||||
// if (isCreated)
|
||||
// {
|
||||
// AddObjectIfNotExists(iObj);
|
||||
// }
|
||||
// }
|
||||
|
||||
//
|
||||
result = isSetuped;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Trigger Conditions ...
|
||||
bool canTrigger = mTestConditions.CanTrigger();
|
||||
datetime triggerTime = mTestConditions.triggerTime;
|
||||
if (!canTrigger)
|
||||
{
|
||||
//
|
||||
// Detect Signal Trigger ...
|
||||
canTrigger = DetectX121SMCTestSiganlTrigger(
|
||||
mTestConditions,
|
||||
symbol,
|
||||
period,
|
||||
mTriggerCycleHelper,
|
||||
mDecisionCycleHelper,
|
||||
mAnalyseCycleHelper,
|
||||
mVerificationCycleHelper,
|
||||
mConsolidationCycleHelper,
|
||||
mVisionCycleHelper //
|
||||
);
|
||||
|
||||
//
|
||||
result = canTrigger;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
triggerTime = mTestConditions.triggerTime;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Direction ...
|
||||
|
||||
//
|
||||
isBullish = IsBullish(setupDir);
|
||||
isBearish = IsBearish(setupDir);
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Issues Signal on Conditions ...
|
||||
conditions.signalDir = setupDir;
|
||||
conditions.provider = providerStr;
|
||||
conditions.sl = mTestConditions.sl;
|
||||
|
||||
//
|
||||
mTestConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,911 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
// Detect Signal Conditions ...
|
||||
bool hasSignal = false;
|
||||
|
||||
//
|
||||
bool useTestSignal = false;
|
||||
bool useXPVOBSignal = false;
|
||||
bool useXPVDPSignal = false;
|
||||
bool useXVWPBSignal = false;
|
||||
bool useXTWPVSignal = true;
|
||||
bool useXPVSUPDEMSignal = false;
|
||||
|
||||
//
|
||||
bool hasTestSignal = false;
|
||||
bool hasXPVOBSignal = false;
|
||||
bool hasXPVDPSignal = false;
|
||||
bool hasXVWPBSignal = false;
|
||||
bool hasXTWPVSignal = false;
|
||||
bool hasXPVSUPDEMSignal = false;
|
||||
|
||||
//
|
||||
// Test Signal ...
|
||||
if (useTestSignal && !hasSignal)
|
||||
{
|
||||
//
|
||||
hasTestSignal = DetectTestSignal(conditions);
|
||||
hasSignal = hasTestSignal;
|
||||
}
|
||||
|
||||
//
|
||||
// XPVOB Signal ...
|
||||
if (useXPVOBSignal && !hasSignal)
|
||||
{
|
||||
//
|
||||
hasXPVOBSignal = DetectXPVOBSignal(conditions);
|
||||
hasSignal = hasXPVOBSignal;
|
||||
}
|
||||
|
||||
//
|
||||
// XPVDP Signal ...
|
||||
if (useXPVDPSignal && !hasSignal)
|
||||
{
|
||||
//
|
||||
hasXPVDPSignal = DetectXPVDPSignal(conditions);
|
||||
hasSignal = hasXPVDPSignal;
|
||||
}
|
||||
|
||||
//
|
||||
// XVWPB Signal ...
|
||||
if (useXVWPBSignal && !hasSignal)
|
||||
{
|
||||
//
|
||||
hasXVWPBSignal = DetectXVWPBSignal(conditions);
|
||||
hasSignal = hasXVWPBSignal;
|
||||
}
|
||||
|
||||
//
|
||||
// XTWPV Signal ...
|
||||
if (useXTWPVSignal && !hasSignal)
|
||||
{
|
||||
//
|
||||
hasXTWPVSignal = DetectXTWPVSignal(conditions);
|
||||
hasSignal = hasXTWPVSignal;
|
||||
}
|
||||
|
||||
//
|
||||
// XPVSUPDEM Signal ...
|
||||
if (useXPVSUPDEMSignal && !hasSignal)
|
||||
{
|
||||
//
|
||||
hasXPVSUPDEMSignal = DetectXPVSUPDEMSignal(conditions);
|
||||
hasSignal = hasXPVSUPDEMSignal;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//
|
||||
// Test Signal ...
|
||||
X121SMCStrategyTestSignalConditions mTestConditions;
|
||||
bool DetectTestSignal(
|
||||
X121SMCStrategyConditions &conditions //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
string symbol = GetSymbol();
|
||||
ENUM_TIMEFRAMES period = GetPeriod();
|
||||
|
||||
//
|
||||
datetime cTime = TimeCurrent();
|
||||
|
||||
//
|
||||
ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XTEST;
|
||||
string providerStr = ToString(provider);
|
||||
|
||||
//
|
||||
// Detect Setup Conditions ...
|
||||
datetime setupTime = mTestConditions.setupTime;
|
||||
bool isSetuped = mTestConditions.IsSetuped();
|
||||
ENUM_X_DIRECTION setupDir = mTestConditions.dir;
|
||||
if (!isSetuped)
|
||||
{
|
||||
//
|
||||
// Detect Signal Setup ...
|
||||
isSetuped = DetectX121SMCTestSiganlSetup(
|
||||
symbol,
|
||||
period,
|
||||
mTestConditions,
|
||||
mTriggerCycleHelper,
|
||||
mDecisionCycleHelper,
|
||||
mAnalyseCycleHelper,
|
||||
mVerificationCycleHelper,
|
||||
mConsolidationCycleHelper,
|
||||
mVisionCycleHelper //
|
||||
);
|
||||
|
||||
//
|
||||
setupDir = mTestConditions.dir;
|
||||
setupTime = mTestConditions.setupTime;
|
||||
}
|
||||
|
||||
// ClearDraws();
|
||||
// ENUM_X_DIRECTION activeZoneDir;
|
||||
// bool hasTicksZone = mTestConditions.HasTicksZone();
|
||||
// bool hasActiveZone = mTestConditions.HasActiveZone(activeZoneDir);
|
||||
// if (hasActiveZone)
|
||||
// {
|
||||
// //
|
||||
// if (IsBullish(activeZoneDir))
|
||||
// {
|
||||
// //
|
||||
// mTestConditions.activeDemandZone.To(cTime);
|
||||
// XCDemandZoneObject *iObj;
|
||||
// bool isCreated = mPOIDrawer.CreateDemandZone(
|
||||
// mTestConditions.activeDemandZone,
|
||||
// iObj //
|
||||
// );
|
||||
// if (isCreated)
|
||||
// {
|
||||
// AddObjectIfNotExists(iObj);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //
|
||||
// mTestConditions.activeSupplyZone.To(cTime);
|
||||
// XCSupplyZoneObject *iObj;
|
||||
// bool isCreated = mPOIDrawer.CreateSupplyZone(
|
||||
// mTestConditions.activeSupplyZone,
|
||||
// iObj //
|
||||
// );
|
||||
// if (isCreated)
|
||||
// {
|
||||
// AddObjectIfNotExists(iObj);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (hasTicksZone)
|
||||
// {
|
||||
// //
|
||||
// XCTicksZoneObject *iObj;
|
||||
// bool isCreated = mPOIDrawer.CreateTicksZone(
|
||||
// mTestConditions.ticksZone,
|
||||
// iObj //
|
||||
// );
|
||||
// if (isCreated)
|
||||
// {
|
||||
// AddObjectIfNotExists(iObj);
|
||||
// }
|
||||
// }
|
||||
|
||||
//
|
||||
result = isSetuped;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Trigger Conditions ...
|
||||
bool canTrigger = mTestConditions.CanTrigger();
|
||||
datetime triggerTime = mTestConditions.triggerTime;
|
||||
if (!canTrigger)
|
||||
{
|
||||
//
|
||||
// Detect Signal Trigger ...
|
||||
canTrigger = DetectX121SMCTestSiganlTrigger(
|
||||
mTestConditions,
|
||||
symbol,
|
||||
period,
|
||||
mTriggerCycleHelper,
|
||||
mDecisionCycleHelper,
|
||||
mAnalyseCycleHelper,
|
||||
mVerificationCycleHelper,
|
||||
mConsolidationCycleHelper,
|
||||
mVisionCycleHelper //
|
||||
);
|
||||
|
||||
//
|
||||
result = canTrigger;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
triggerTime = mTestConditions.triggerTime;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Direction ...
|
||||
|
||||
//
|
||||
isBullish = IsBullish(setupDir);
|
||||
isBearish = IsBearish(setupDir);
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Issues Signal on Conditions ...
|
||||
conditions.signalDir = setupDir;
|
||||
conditions.provider = providerStr;
|
||||
conditions.sl = mTestConditions.sl;
|
||||
conditions.target = mTestConditions.target;
|
||||
|
||||
//
|
||||
mTestConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// XPVOB Signal ...
|
||||
X121SMCStrategyXPVOBSignalConditions mXPVOBConditions;
|
||||
bool DetectXPVOBSignal(
|
||||
X121SMCStrategyConditions &conditions //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
string symbol = GetSymbol();
|
||||
ENUM_TIMEFRAMES period = GetPeriod();
|
||||
|
||||
//
|
||||
datetime cTime = TimeCurrent();
|
||||
|
||||
//
|
||||
ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XPVOB;
|
||||
string providerStr = ToString(provider);
|
||||
|
||||
//
|
||||
// Detect Setup Conditions ...
|
||||
datetime setupTime = mXPVOBConditions.setupTime;
|
||||
bool isSetuped = mXPVOBConditions.IsSetuped();
|
||||
ENUM_X_DIRECTION setupDir = mXPVOBConditions.dir;
|
||||
if (!isSetuped)
|
||||
{
|
||||
//
|
||||
// Detect Signal Setup ...
|
||||
isSetuped = DetectX121SMCXPVOBSiganlSetup(
|
||||
symbol,
|
||||
period,
|
||||
mXPVOBConditions,
|
||||
mTriggerCycleHelper,
|
||||
mDecisionCycleHelper,
|
||||
mAnalyseCycleHelper,
|
||||
mVerificationCycleHelper,
|
||||
mConsolidationCycleHelper,
|
||||
mVisionCycleHelper //
|
||||
);
|
||||
|
||||
//
|
||||
result = isSetuped;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
setupDir = mXPVOBConditions.dir;
|
||||
setupTime = mXPVOBConditions.setupTime;
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Conditions Active FVG ...
|
||||
// if (isSetuped)
|
||||
// {
|
||||
// //
|
||||
// XCFVG *iFVG = mXPVOBConditions.activeFVG;
|
||||
// if (iFVG != NULL && iFVG.IsValid())
|
||||
// {
|
||||
// //
|
||||
// ClearDraws();
|
||||
// iFVG.To(cTime);
|
||||
// if (IsBullish(setupDir) && iFVG.IsBullish())
|
||||
// {
|
||||
// //
|
||||
// XCBullishFairValueGapObject *iObj;
|
||||
// bool isCreated = mPOIDrawer.CreateBullishFairValueGap(
|
||||
// iFVG,
|
||||
// iObj //
|
||||
// );
|
||||
// if (isCreated)
|
||||
// {
|
||||
// AddObjectIfNotExists(iObj);
|
||||
// }
|
||||
// }
|
||||
// else if (IsBearish(setupDir) && iFVG.IsBearish())
|
||||
// {
|
||||
// //
|
||||
// XCBearishFairValueGapObject *iObj;
|
||||
// bool isCreated = mPOIDrawer.CreateBearishFairValueGap(
|
||||
// iFVG,
|
||||
// iObj //
|
||||
// );
|
||||
// if (isCreated)
|
||||
// {
|
||||
// AddObjectIfNotExists(iObj);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
//
|
||||
// Detect Trigger Conditions ...
|
||||
bool canTrigger = mXPVOBConditions.CanTrigger();
|
||||
datetime triggerTime = mXPVOBConditions.triggerTime;
|
||||
if (!canTrigger)
|
||||
{
|
||||
//
|
||||
// Detect Signal Trigger ...
|
||||
canTrigger = DetectX121SMCXPVOBSiganlTrigger(
|
||||
mXPVOBConditions,
|
||||
symbol,
|
||||
period,
|
||||
mTriggerCycleHelper,
|
||||
mDecisionCycleHelper,
|
||||
mAnalyseCycleHelper,
|
||||
mVerificationCycleHelper,
|
||||
mConsolidationCycleHelper,
|
||||
mVisionCycleHelper //
|
||||
);
|
||||
|
||||
//
|
||||
result = canTrigger;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
triggerTime = mXPVOBConditions.triggerTime;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Direction ...
|
||||
|
||||
//
|
||||
isBullish = IsBullish(setupDir);
|
||||
isBearish = IsBearish(setupDir);
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Issues Signal on Conditions ...
|
||||
conditions.signalDir = setupDir;
|
||||
conditions.provider = providerStr;
|
||||
conditions.sl = mXPVOBConditions.sl;
|
||||
conditions.target = mXPVOBConditions.target;
|
||||
|
||||
//
|
||||
mXPVOBConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// XPVDP Signal ...
|
||||
X121SMCStrategyXPVDPSignalConditions mXPVDPConditions;
|
||||
bool DetectXPVDPSignal(
|
||||
X121SMCStrategyConditions &conditions //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
string symbol = GetSymbol();
|
||||
ENUM_TIMEFRAMES period = GetPeriod();
|
||||
|
||||
//
|
||||
datetime cTime = TimeCurrent();
|
||||
|
||||
//
|
||||
ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XPVDP;
|
||||
string providerStr = ToString(provider);
|
||||
|
||||
//
|
||||
// Detect Setup Conditions ...
|
||||
datetime setupTime = mXPVDPConditions.setupTime;
|
||||
bool isSetuped = mXPVDPConditions.IsSetuped();
|
||||
ENUM_X_DIRECTION setupDir = mXPVDPConditions.dir;
|
||||
if (!isSetuped)
|
||||
{
|
||||
//
|
||||
// Detect Signal Setup ...
|
||||
isSetuped = DetectX121SMCXPVDPSiganlSetup(
|
||||
symbol,
|
||||
period,
|
||||
mXPVDPConditions,
|
||||
mTriggerCycleHelper,
|
||||
mDecisionCycleHelper,
|
||||
mAnalyseCycleHelper,
|
||||
mVerificationCycleHelper,
|
||||
mConsolidationCycleHelper,
|
||||
mVisionCycleHelper //
|
||||
);
|
||||
|
||||
//
|
||||
setupDir = mXPVDPConditions.dir;
|
||||
setupTime = mXPVDPConditions.setupTime;
|
||||
}
|
||||
result = isSetuped;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Trigger Conditions ...
|
||||
bool canTrigger = mXPVDPConditions.CanTrigger();
|
||||
datetime triggerTime = mXPVDPConditions.triggerTime;
|
||||
if (!canTrigger)
|
||||
{
|
||||
//
|
||||
// Detect Signal Trigger ...
|
||||
canTrigger = DetectX121SMCXPVDPSiganlTrigger(
|
||||
mXPVDPConditions,
|
||||
symbol,
|
||||
period,
|
||||
mTriggerCycleHelper,
|
||||
mDecisionCycleHelper,
|
||||
mAnalyseCycleHelper,
|
||||
mVerificationCycleHelper,
|
||||
mConsolidationCycleHelper,
|
||||
mVisionCycleHelper //
|
||||
);
|
||||
|
||||
//
|
||||
result = canTrigger;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
triggerTime = mXPVDPConditions.triggerTime;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Direction ...
|
||||
|
||||
//
|
||||
isBullish = IsBullish(setupDir);
|
||||
isBearish = IsBearish(setupDir);
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Issues Signal on Conditions ...
|
||||
conditions.signalDir = setupDir;
|
||||
conditions.provider = providerStr;
|
||||
conditions.sl = mXPVDPConditions.sl;
|
||||
conditions.target = mXPVDPConditions.target;
|
||||
|
||||
//
|
||||
mXPVDPConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// XVWPB Signal ...
|
||||
X121SMCStrategyXVWPBSignalConditions mXVWPBConditions;
|
||||
bool DetectXVWPBSignal(
|
||||
X121SMCStrategyConditions &conditions //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
string symbol = GetSymbol();
|
||||
ENUM_TIMEFRAMES period = GetPeriod();
|
||||
|
||||
//
|
||||
datetime cTime = TimeCurrent();
|
||||
|
||||
//
|
||||
ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XVWPB;
|
||||
string providerStr = ToString(provider);
|
||||
|
||||
//
|
||||
// Detect Setup Conditions ...
|
||||
datetime setupTime = mXVWPBConditions.setupTime;
|
||||
bool isSetuped = mXVWPBConditions.IsSetuped();
|
||||
ENUM_X_DIRECTION setupDir = mXVWPBConditions.dir;
|
||||
if (!isSetuped)
|
||||
{
|
||||
//
|
||||
// Detect Signal Setup ...
|
||||
isSetuped = DetectX121SMCXVWPBSiganlSetup(
|
||||
symbol,
|
||||
period,
|
||||
mXVWPBConditions,
|
||||
mTriggerCycleHelper,
|
||||
mDecisionCycleHelper,
|
||||
mAnalyseCycleHelper,
|
||||
mVerificationCycleHelper,
|
||||
mConsolidationCycleHelper,
|
||||
mVisionCycleHelper //
|
||||
);
|
||||
|
||||
//
|
||||
setupDir = mXVWPBConditions.dir;
|
||||
setupTime = mXVWPBConditions.setupTime;
|
||||
}
|
||||
result = isSetuped;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Trigger Conditions ...
|
||||
bool canTrigger = mXVWPBConditions.CanTrigger();
|
||||
datetime triggerTime = mXVWPBConditions.triggerTime;
|
||||
if (!canTrigger)
|
||||
{
|
||||
//
|
||||
// Detect Signal Trigger ...
|
||||
canTrigger = DetectX121SMCXVWPBSiganlTrigger(
|
||||
mXVWPBConditions,
|
||||
symbol,
|
||||
period,
|
||||
mTriggerCycleHelper,
|
||||
mDecisionCycleHelper,
|
||||
mAnalyseCycleHelper,
|
||||
mVerificationCycleHelper,
|
||||
mConsolidationCycleHelper,
|
||||
mVisionCycleHelper //
|
||||
);
|
||||
|
||||
//
|
||||
result = canTrigger;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
triggerTime = mXVWPBConditions.triggerTime;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Direction ...
|
||||
|
||||
//
|
||||
isBullish = IsBullish(setupDir);
|
||||
isBearish = IsBearish(setupDir);
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Issues Signal on Conditions ...
|
||||
conditions.signalDir = setupDir;
|
||||
conditions.provider = providerStr;
|
||||
conditions.sl = mXVWPBConditions.sl;
|
||||
conditions.target = mXVWPBConditions.target;
|
||||
|
||||
//
|
||||
mXVWPBConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// XTWPV Signal ...
|
||||
X121SMCStrategyXTWPVSignalConditions mXTWPVConditions;
|
||||
bool DetectXTWPVSignal(
|
||||
X121SMCStrategyConditions &conditions //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
string symbol = GetSymbol();
|
||||
ENUM_TIMEFRAMES period = GetPeriod();
|
||||
|
||||
//
|
||||
datetime cTime = TimeCurrent();
|
||||
|
||||
//
|
||||
ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XTWPV;
|
||||
string providerStr = ToString(provider);
|
||||
|
||||
//
|
||||
// Detect Setup Conditions ...
|
||||
datetime setupTime = mXTWPVConditions.setupTime;
|
||||
bool isSetuped = mXTWPVConditions.IsSetuped();
|
||||
ENUM_X_DIRECTION setupDir = mXTWPVConditions.dir;
|
||||
if (!isSetuped)
|
||||
{
|
||||
//
|
||||
// Detect Signal Setup ...
|
||||
isSetuped = DetectX121SMCXTWPVSiganlSetup(
|
||||
symbol,
|
||||
period,
|
||||
mXTWPVConditions,
|
||||
mTriggerCycleHelper,
|
||||
mDecisionCycleHelper,
|
||||
mAnalyseCycleHelper,
|
||||
mVerificationCycleHelper,
|
||||
mConsolidationCycleHelper,
|
||||
mVisionCycleHelper //
|
||||
);
|
||||
|
||||
//
|
||||
setupDir = mXTWPVConditions.dir;
|
||||
setupTime = mXTWPVConditions.setupTime;
|
||||
}
|
||||
result = isSetuped;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Trigger Conditions ...
|
||||
bool canTrigger = mXTWPVConditions.CanTrigger();
|
||||
datetime triggerTime = mXTWPVConditions.triggerTime;
|
||||
if (!canTrigger)
|
||||
{
|
||||
//
|
||||
// Detect Signal Trigger ...
|
||||
canTrigger = DetectX121SMCXTWPVSiganlTrigger(
|
||||
mXTWPVConditions,
|
||||
symbol,
|
||||
period,
|
||||
mTriggerCycleHelper,
|
||||
mDecisionCycleHelper,
|
||||
mAnalyseCycleHelper,
|
||||
mVerificationCycleHelper,
|
||||
mConsolidationCycleHelper,
|
||||
mVisionCycleHelper //
|
||||
);
|
||||
|
||||
//
|
||||
result = canTrigger;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
triggerTime = mXTWPVConditions.triggerTime;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Direction ...
|
||||
|
||||
//
|
||||
isBullish = IsBullish(setupDir);
|
||||
isBearish = IsBearish(setupDir);
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Issues Signal on Conditions ...
|
||||
conditions.signalDir = setupDir;
|
||||
conditions.provider = providerStr;
|
||||
conditions.sl = mXTWPVConditions.sl;
|
||||
conditions.target = mXTWPVConditions.target;
|
||||
|
||||
//
|
||||
mXTWPVConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// XPVSUPDEM Signal ...
|
||||
X121SMCStrategyXPVSUPDEMSignalConditions mXPVSUPDEMConditions;
|
||||
bool DetectXPVSUPDEMSignal(
|
||||
X121SMCStrategyConditions &conditions //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
string symbol = GetSymbol();
|
||||
ENUM_TIMEFRAMES period = GetPeriod();
|
||||
|
||||
//
|
||||
datetime cTime = TimeCurrent();
|
||||
|
||||
//
|
||||
ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XPVSUPDEM;
|
||||
string providerStr = ToString(provider);
|
||||
|
||||
//
|
||||
// Detect Setup Conditions ...
|
||||
datetime setupTime = mXPVSUPDEMConditions.setupTime;
|
||||
bool isSetuped = mXPVSUPDEMConditions.IsSetuped();
|
||||
ENUM_X_DIRECTION setupDir = mXPVSUPDEMConditions.dir;
|
||||
if (!isSetuped)
|
||||
{
|
||||
//
|
||||
// Detect Signal Setup ...
|
||||
isSetuped = DetectX121SMCXPVSUPDEMSiganlSetup(
|
||||
symbol,
|
||||
period,
|
||||
mXPVSUPDEMConditions,
|
||||
mTriggerCycleHelper,
|
||||
mDecisionCycleHelper,
|
||||
mAnalyseCycleHelper,
|
||||
mVerificationCycleHelper,
|
||||
mConsolidationCycleHelper,
|
||||
mVisionCycleHelper //
|
||||
);
|
||||
|
||||
//
|
||||
setupDir = mXPVSUPDEMConditions.dir;
|
||||
setupTime = mXPVSUPDEMConditions.setupTime;
|
||||
}
|
||||
|
||||
// ClearDraws();
|
||||
// ENUM_X_DIRECTION activeZoneDir;
|
||||
// bool hasTicksZone = mXPVSUPDEMConditions.HasTicksZone();
|
||||
// bool hasActiveZone = mXPVSUPDEMConditions.HasActiveZone(activeZoneDir);
|
||||
// if (hasActiveZone)
|
||||
// {
|
||||
// //
|
||||
// if (IsBullish(activeZoneDir))
|
||||
// {
|
||||
// //
|
||||
// mXPVSUPDEMConditions.activeDemandZone.To(cTime);
|
||||
// XCDemandZoneObject *iObj;
|
||||
// bool isCreated = mPOIDrawer.CreateDemandZone(
|
||||
// mXPVSUPDEMConditions.activeDemandZone,
|
||||
// iObj //
|
||||
// );
|
||||
// if (isCreated)
|
||||
// {
|
||||
// AddObjectIfNotExists(iObj);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //
|
||||
// mXPVSUPDEMConditions.activeSupplyZone.To(cTime);
|
||||
// XCSupplyZoneObject *iObj;
|
||||
// bool isCreated = mPOIDrawer.CreateSupplyZone(
|
||||
// mXPVSUPDEMConditions.activeSupplyZone,
|
||||
// iObj //
|
||||
// );
|
||||
// if (isCreated)
|
||||
// {
|
||||
// AddObjectIfNotExists(iObj);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (hasTicksZone)
|
||||
// {
|
||||
// //
|
||||
// XCTicksZoneObject *iObj;
|
||||
// bool isCreated = mPOIDrawer.CreateTicksZone(
|
||||
// mXPVSUPDEMConditions.ticksZone,
|
||||
// iObj //
|
||||
// );
|
||||
// if (isCreated)
|
||||
// {
|
||||
// AddObjectIfNotExists(iObj);
|
||||
// }
|
||||
// }
|
||||
|
||||
//
|
||||
result = isSetuped;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Trigger Conditions ...
|
||||
bool canTrigger = mXPVSUPDEMConditions.CanTrigger();
|
||||
datetime triggerTime = mXPVSUPDEMConditions.triggerTime;
|
||||
if (!canTrigger)
|
||||
{
|
||||
//
|
||||
// Detect Signal Trigger ...
|
||||
canTrigger = DetectX121SMCXPVSUPDEMSiganlTrigger(
|
||||
mXPVSUPDEMConditions,
|
||||
symbol,
|
||||
period,
|
||||
mTriggerCycleHelper,
|
||||
mDecisionCycleHelper,
|
||||
mAnalyseCycleHelper,
|
||||
mVerificationCycleHelper,
|
||||
mConsolidationCycleHelper,
|
||||
mVisionCycleHelper //
|
||||
);
|
||||
|
||||
//
|
||||
result = canTrigger;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
triggerTime = mXPVSUPDEMConditions.triggerTime;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Direction ...
|
||||
|
||||
//
|
||||
isBullish = IsBullish(setupDir);
|
||||
isBearish = IsBearish(setupDir);
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Issues Signal on Conditions ...
|
||||
conditions.signalDir = setupDir;
|
||||
conditions.provider = providerStr;
|
||||
conditions.sl = mXPVSUPDEMConditions.sl;
|
||||
conditions.target = mXPVSUPDEMConditions.target;
|
||||
|
||||
//
|
||||
mXPVSUPDEMConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -0,0 +1,852 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 X121 SMC Signal Class
|
||||
// -------------------------------------------------
|
||||
// Name:
|
||||
// Description: provide all Signalling 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-121.smc.market.cycle.helper.class.mq5"
|
||||
#include "../Libraries/x-121.smc.lib.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
struct X121SMCStrategyXTWPVSignalConditions
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
double sl;
|
||||
double target;
|
||||
ENUM_X_DIRECTION dir;
|
||||
ENUM_X_POSITION_TYPES type;
|
||||
|
||||
//
|
||||
// Setup Props ...
|
||||
|
||||
//
|
||||
datetime setupTime;
|
||||
datetime triggerTime;
|
||||
|
||||
//
|
||||
XPVPivot parentPivot;
|
||||
XPVPivot childPivot;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
X121SMCStrategyXTWPVSignalConditions()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleaning Up ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
sl = 0;
|
||||
target = 0;
|
||||
|
||||
//
|
||||
dir = X_DIRECTION_NONE;
|
||||
type = X_POSITION_TYPE_NONE;
|
||||
|
||||
//
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
setupTime = NULL;
|
||||
triggerTime = NULL;
|
||||
|
||||
//
|
||||
ExtensionClean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Condition is Setting Up ...
|
||||
*
|
||||
* @param dir: ENUM_X_DIRECTION member, Setting Up Direction ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsSetuped()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid(setupTime) &&
|
||||
HasDirection(dir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Setup Age ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int GetSetupAge()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
if (!IsSetuped())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect How we Can Trigger Signal ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool CanTrigger()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
sl > 0 &&
|
||||
IsValid(symbol) &&
|
||||
IsValid(period) &&
|
||||
IsValid(triggerTime) &&
|
||||
type != X_POSITION_TYPE_ALL &&
|
||||
type != X_POSITION_TYPE_NONE
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Extensions ...
|
||||
|
||||
/**
|
||||
* Clean Additional Properties ...
|
||||
*/
|
||||
void ExtensionClean()
|
||||
{
|
||||
//
|
||||
CleanPivots();
|
||||
}
|
||||
|
||||
void CleanPivots()
|
||||
{
|
||||
//
|
||||
parentPivot.Clean();
|
||||
childPivot.Clean();
|
||||
}
|
||||
|
||||
bool HasParentPivot()
|
||||
{
|
||||
return parentPivot.IsValid();
|
||||
}
|
||||
|
||||
bool HasChildPivot()
|
||||
{
|
||||
return childPivot.IsValid();
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Extension Functions ...
|
||||
|
||||
//
|
||||
// Detect Setup Conditions ...
|
||||
bool DetectX121SMCXTWPVSiganlSetup(
|
||||
string _symbol,
|
||||
ENUM_TIMEFRAMES _period,
|
||||
//
|
||||
X121SMCStrategyXTWPVSignalConditions &conditions,
|
||||
//
|
||||
XC121SMCCycleHelper *triggerCycleHelper,
|
||||
XC121SMCCycleHelper *decisionCycleHelper,
|
||||
XC121SMCCycleHelper *analyseCycleHelper,
|
||||
XC121SMCCycleHelper *verificationCycleHelper,
|
||||
XC121SMCCycleHelper *consolidationCycleHelper,
|
||||
XC121SMCCycleHelper *visionCycleHelper
|
||||
//
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
int zIndex = 0;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
int loopback = 10;
|
||||
|
||||
//
|
||||
string symbol = _symbol;
|
||||
ENUM_TIMEFRAMES period = _period;
|
||||
|
||||
//
|
||||
conditions.symbol = symbol;
|
||||
conditions.period = period;
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
result = zBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
zIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL cBar;
|
||||
result = cBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
cIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double ask = GetAsk(symbol);
|
||||
double bid = GetBid(symbol);
|
||||
datetime cTime = TimeCurrent();
|
||||
|
||||
//
|
||||
double ll = cBar.FindLowest(9, MODE_LOW);
|
||||
double hh = cBar.FindHighest(9, MODE_HIGH);
|
||||
|
||||
//
|
||||
int zoneValidationDivider = 10;
|
||||
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
||||
.GetDonChainLength();
|
||||
|
||||
//
|
||||
double selectedSL = 0;
|
||||
|
||||
//
|
||||
// Cycles Conditions ...
|
||||
|
||||
//
|
||||
// Trigger ...
|
||||
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
||||
X121SMCCycleConditions triggerConditions;
|
||||
result = triggerCycleHelper.GetConditions(
|
||||
triggerCycleEvents,
|
||||
triggerPoiEvents,
|
||||
triggerConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Decision ...
|
||||
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
||||
X121SMCCycleConditions decisionConditions;
|
||||
result = decisionCycleHelper.GetConditions(
|
||||
decisionCycleEvents,
|
||||
decisionPoiEvents,
|
||||
decisionConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Analyse ...
|
||||
ENUM_XPOI_EVENTS analysePoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
||||
X121SMCCycleConditions analyseConditions;
|
||||
result = analyseCycleHelper.GetConditions(
|
||||
analyseCycleEvents,
|
||||
analysePoiEvents,
|
||||
analyseConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Verification ...
|
||||
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
||||
X121SMCCycleConditions verificationConditions;
|
||||
result = verificationCycleHelper.GetConditions(
|
||||
verificationCycleEvents,
|
||||
verificationPoiEvents,
|
||||
verificationConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Consolidation ...
|
||||
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
||||
X121SMCCycleConditions consolidationConditions;
|
||||
result = consolidationCycleHelper.GetConditions(
|
||||
consolidationCycleEvents,
|
||||
consolidationPoiEvents,
|
||||
consolidationConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Vision ...
|
||||
ENUM_XPOI_EVENTS visionPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
||||
X121SMCCycleConditions visionConditions;
|
||||
result = visionCycleHelper.GetConditions(
|
||||
visionCycleEvents,
|
||||
visionPoiEvents,
|
||||
visionConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Cycles POI States ...
|
||||
XPOIState triggerState = triggerConditions.state;
|
||||
XPOIState decisionState = decisionConditions.state;
|
||||
XPOIState analyseState = analyseConditions.state;
|
||||
XPOIState verificationState = verificationConditions.state;
|
||||
XPOIState consolidationState = consolidationConditions.state;
|
||||
XPOIState visionState = visionConditions.state;
|
||||
|
||||
//
|
||||
// Setup Conditions ...
|
||||
|
||||
//
|
||||
// Detect Market Trend ...
|
||||
// ENUM_X_DIRECTION trend;
|
||||
// bool hasTrend = verificationCycleHelper
|
||||
// .DetectTrend(trend);
|
||||
// bool hasBullishTrend = hasTrend &&
|
||||
// IsBullish(trend);
|
||||
// bool hasBearishTrend = hasTrend &&
|
||||
// IsBearish(trend);
|
||||
// result = hasBullishTrend ||
|
||||
// hasBearishTrend;
|
||||
// if (!result)
|
||||
// {
|
||||
// return result;
|
||||
// }
|
||||
|
||||
//
|
||||
// Retrieve Active Pivots ...
|
||||
|
||||
//
|
||||
XPVPivot peakPivot;
|
||||
bool hasPeakPivot = analyseCycleHelper
|
||||
.GetActivePeakPivot(peakPivot);
|
||||
|
||||
//
|
||||
XPVPivot valePivot;
|
||||
bool hasValePivot = analyseCycleHelper
|
||||
.GetActiveValePivot(valePivot);
|
||||
|
||||
//
|
||||
// Check Parent Pivot ...
|
||||
bool hasParentPivot = conditions.HasParentPivot();
|
||||
if (!hasParentPivot)
|
||||
{
|
||||
//
|
||||
if (hasPeakPivot && !hasValePivot)
|
||||
{
|
||||
conditions.parentPivot = peakPivot;
|
||||
}
|
||||
else if (hasValePivot && !hasPeakPivot)
|
||||
{
|
||||
conditions.parentPivot = valePivot;
|
||||
}
|
||||
else if (hasPeakPivot && hasValePivot)
|
||||
{
|
||||
//
|
||||
if (peakPivot.from < valePivot.from)
|
||||
{
|
||||
//
|
||||
conditions.parentPivot = peakPivot;
|
||||
conditions.childPivot = valePivot;
|
||||
}
|
||||
else if (valePivot.from < peakPivot.from)
|
||||
{
|
||||
//
|
||||
conditions.parentPivot = valePivot;
|
||||
conditions.childPivot = peakPivot;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
hasParentPivot = conditions.HasParentPivot();
|
||||
result = hasParentPivot;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check Child Pivot ...
|
||||
bool hasChildPivot = conditions.HasChildPivot();
|
||||
if (!hasChildPivot)
|
||||
{
|
||||
//
|
||||
if (hasPeakPivot && !hasValePivot)
|
||||
{
|
||||
conditions.childPivot = peakPivot;
|
||||
}
|
||||
else if (hasValePivot && !hasPeakPivot)
|
||||
{
|
||||
conditions.childPivot = valePivot;
|
||||
}
|
||||
else if (hasPeakPivot && hasValePivot)
|
||||
{
|
||||
//
|
||||
if (peakPivot.from < valePivot.from)
|
||||
{
|
||||
conditions.childPivot = peakPivot;
|
||||
}
|
||||
else if (valePivot.from < peakPivot.from)
|
||||
{
|
||||
conditions.childPivot = valePivot;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
hasChildPivot = conditions.HasChildPivot();
|
||||
result = hasChildPivot;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (hasParentPivot && hasChildPivot)
|
||||
{
|
||||
//
|
||||
bool isChildSame =
|
||||
conditions.childPivot.from == peakPivot.from ||
|
||||
conditions.childPivot.from == valePivot.from;
|
||||
result = isChildSame;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
conditions.CleanPivots();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Direction ...
|
||||
|
||||
//
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.setupTime = cTime;
|
||||
conditions.dir =
|
||||
isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Trigger Conditions ...
|
||||
bool DetectX121SMCXTWPVSiganlTrigger(
|
||||
//
|
||||
X121SMCStrategyXTWPVSignalConditions &conditions,
|
||||
//
|
||||
string _symbol,
|
||||
ENUM_TIMEFRAMES _period,
|
||||
//
|
||||
XC121SMCCycleHelper *triggerCycleHelper,
|
||||
XC121SMCCycleHelper *decisionCycleHelper,
|
||||
XC121SMCCycleHelper *analyseCycleHelper,
|
||||
XC121SMCCycleHelper *verificationCycleHelper,
|
||||
XC121SMCCycleHelper *consolidationCycleHelper,
|
||||
XC121SMCCycleHelper *visionCycleHelper,
|
||||
//
|
||||
int maxAllowedSetupAge = 60 //
|
||||
//
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = conditions.IsSetuped();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
datetime setupTime = conditions.setupTime;
|
||||
ENUM_X_DIRECTION setupDir = conditions.dir;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
int zIndex = 0;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
int loopback = 10;
|
||||
|
||||
//
|
||||
string symbol = _symbol;
|
||||
ENUM_TIMEFRAMES period = _period;
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
result = zBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
zIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL cBar;
|
||||
result = cBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
cIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double ask = GetAsk(symbol);
|
||||
double bid = GetBid(symbol);
|
||||
datetime cTime = TimeCurrent();
|
||||
|
||||
//
|
||||
double ll = cBar.FindLowest(9, MODE_LOW);
|
||||
double hh = cBar.FindHighest(9, MODE_HIGH);
|
||||
|
||||
//
|
||||
int zoneValidationDivider = 10;
|
||||
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
||||
.GetDonChainLength();
|
||||
|
||||
//
|
||||
double selectedSL = 0;
|
||||
|
||||
//
|
||||
// Cycles Conditions ...
|
||||
|
||||
//
|
||||
// Trigger ...
|
||||
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
||||
X121SMCCycleConditions triggerConditions;
|
||||
result = triggerCycleHelper.GetConditions(
|
||||
triggerCycleEvents,
|
||||
triggerPoiEvents,
|
||||
triggerConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Decision ...
|
||||
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
||||
X121SMCCycleConditions decisionConditions;
|
||||
result = decisionCycleHelper.GetConditions(
|
||||
decisionCycleEvents,
|
||||
decisionPoiEvents,
|
||||
decisionConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Analyse ...
|
||||
ENUM_XPOI_EVENTS analysePoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
||||
X121SMCCycleConditions analyseConditions;
|
||||
result = analyseCycleHelper.GetConditions(
|
||||
analyseCycleEvents,
|
||||
analysePoiEvents,
|
||||
analyseConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Verification ...
|
||||
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
||||
X121SMCCycleConditions verificationConditions;
|
||||
result = verificationCycleHelper.GetConditions(
|
||||
verificationCycleEvents,
|
||||
verificationPoiEvents,
|
||||
verificationConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Consolidation ...
|
||||
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
||||
X121SMCCycleConditions consolidationConditions;
|
||||
result = consolidationCycleHelper.GetConditions(
|
||||
consolidationCycleEvents,
|
||||
consolidationPoiEvents,
|
||||
consolidationConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Vision ...
|
||||
ENUM_XPOI_EVENTS visionPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
||||
X121SMCCycleConditions visionConditions;
|
||||
result = visionCycleHelper.GetConditions(
|
||||
visionCycleEvents,
|
||||
visionPoiEvents,
|
||||
visionConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Cycles POI States ...
|
||||
XPOIState triggerState = triggerConditions.state;
|
||||
XPOIState decisionState = decisionConditions.state;
|
||||
XPOIState analyseState = analyseConditions.state;
|
||||
XPOIState verificationState = verificationConditions.state;
|
||||
XPOIState consolidationState = consolidationConditions.state;
|
||||
XPOIState visionState = visionConditions.state;
|
||||
|
||||
//
|
||||
// Trigger Conditions ...
|
||||
|
||||
//
|
||||
// Check VWap State ...
|
||||
|
||||
//
|
||||
bool isVWapBullishState = triggerConditions.x121Conditions.isVWapBullishState;
|
||||
bool isVWapBearishState = triggerConditions.x121Conditions.isVWapBearishState;
|
||||
|
||||
//
|
||||
isBullish =
|
||||
IsBullish(setupDir) &&
|
||||
isVWapBullishState;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
IsBearish(setupDir) &&
|
||||
isVWapBearishState;
|
||||
|
||||
//
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Waitings For Sar Switched to Direction ...
|
||||
|
||||
//
|
||||
double sar = triggerConditions.x121Conditions.sarBuffer[1];
|
||||
|
||||
//
|
||||
bool isSarSwitchedToBullish = triggerConditions.x121Conditions.isSarSwitchedToBullish;
|
||||
bool isSarSwitchedToBearish = triggerConditions.x121Conditions.isSarSwitchedToBearish;
|
||||
|
||||
//
|
||||
isBullish =
|
||||
//
|
||||
isBullish &&
|
||||
isSarSwitchedToBullish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
//
|
||||
isBearish &&
|
||||
isSarSwitchedToBearish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
// Cleanup Setup Conditions ...
|
||||
int setupAge = conditions.GetSetupAge();
|
||||
if (IsValidSize(setupAge) &&
|
||||
IsValidSize(maxAllowedSetupAge) &&
|
||||
setupAge >= maxAllowedSetupAge)
|
||||
{
|
||||
conditions.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Nearest FVG or Supply Zone For Traget ...
|
||||
|
||||
//
|
||||
// Select Source State ...
|
||||
XPOIState state = triggerState;
|
||||
|
||||
//
|
||||
double target = CalculateTarget(
|
||||
cBar,
|
||||
state,
|
||||
setupDir //
|
||||
);
|
||||
|
||||
//
|
||||
result = target > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.target = target;
|
||||
conditions.triggerTime = cTime;
|
||||
conditions.sl = isBullish
|
||||
? sar
|
||||
: sar;
|
||||
conditions.type = isBullish
|
||||
? X_POSITION_TYPE_LONG
|
||||
: X_POSITION_TYPE_SHORT;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,73 @@
|
||||
//
|
||||
ClearDraws();
|
||||
XPVPivot peakPivot;
|
||||
bool hasActivePeakPivot =
|
||||
mTriggerCycleHelper
|
||||
.GetActivePeakPivot(peakPivot);
|
||||
if (hasActivePeakPivot)
|
||||
{
|
||||
//
|
||||
XCBaseObject *iPivotObjs[];
|
||||
int drawnCount = mPOIDrawer.DrawPivot(
|
||||
peakPivot,
|
||||
iPivotObjs //
|
||||
);
|
||||
|
||||
//
|
||||
if (IsValidSize(drawnCount))
|
||||
{
|
||||
AddObjectsIfNotExists(iPivotObjs);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
XPVPivot valePivot;
|
||||
bool hasActiveValePivot =
|
||||
mTriggerCycleHelper
|
||||
.GetActiveValePivot(valePivot);
|
||||
if (hasActiveValePivot)
|
||||
{
|
||||
//
|
||||
XCBaseObject *iPivotObjs[];
|
||||
int drawnCount = mPOIDrawer.DrawPivot(
|
||||
valePivot,
|
||||
iPivotObjs //
|
||||
);
|
||||
|
||||
//
|
||||
if (IsValidSize(drawnCount))
|
||||
{
|
||||
AddObjectsIfNotExists(iPivotObjs);
|
||||
}
|
||||
}
|
||||
|
||||
// XPVPivot pivots[];
|
||||
// int pivotsCount = mTriggerCycleHelper.FillPivots(pivots);
|
||||
// if (IsValidSize(pivotsCount))
|
||||
// {
|
||||
// //
|
||||
// for (int i = 0; i < pivotsCount; i++)
|
||||
// {
|
||||
// //
|
||||
// XPVPivot iPivot = pivots[i];
|
||||
|
||||
// //
|
||||
// XCBaseObject *iPivotObjects[];
|
||||
// mPOIDrawer.DrawPivot(
|
||||
// iPivot,
|
||||
// iPivotObjects,
|
||||
// false // Don't Draw State ...
|
||||
// );
|
||||
|
||||
// //
|
||||
// int iPivotObjectsCount = ArraySize(iPivotObjects);
|
||||
// if (IsValidSize(iPivotObjectsCount))
|
||||
// {
|
||||
// //
|
||||
// for (int j = 0; j < iPivotObjectsCount; j++)
|
||||
// {
|
||||
// AddObjectIfNotExists(iPivotObjects[j]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,995 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 X121 SMC Signal Lib
|
||||
// -------------------------------------------------
|
||||
// Name:
|
||||
// Description: provide all Signalling 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-121.smc.market.cycle.helper.class.mq5"
|
||||
#include "../Libraries/x-121.smc.lib.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
struct X121SMCStrategyXPVDPSignalConditions
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
double sl;
|
||||
double target;
|
||||
ENUM_X_DIRECTION dir;
|
||||
ENUM_X_POSITION_TYPES type;
|
||||
|
||||
//
|
||||
// Setup Props ...
|
||||
|
||||
//
|
||||
datetime setupTime;
|
||||
datetime triggerTime;
|
||||
|
||||
//
|
||||
double peak;
|
||||
double vale;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
X121SMCStrategyXPVDPSignalConditions()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleaning Up ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
sl = 0;
|
||||
target = 0;
|
||||
|
||||
//
|
||||
dir = X_DIRECTION_NONE;
|
||||
type = X_POSITION_TYPE_NONE;
|
||||
|
||||
//
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
setupTime = NULL;
|
||||
triggerTime = NULL;
|
||||
|
||||
//
|
||||
ExtensionClean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Condition is Setting Up ...
|
||||
*
|
||||
* @param dir: ENUM_X_DIRECTION member, Setting Up Direction ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsSetuped()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid(setupTime) &&
|
||||
HasDirection(dir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Setup Age ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int GetSetupAge()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
if (!IsSetuped())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect How we Can Trigger Signal ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool CanTrigger()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
sl > 0 &&
|
||||
IsValid(symbol) &&
|
||||
IsValid(period) &&
|
||||
IsValid(triggerTime) &&
|
||||
type != X_POSITION_TYPE_ALL &&
|
||||
type != X_POSITION_TYPE_NONE
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Extensions ...
|
||||
|
||||
/**
|
||||
* Clean Additional Properties ...
|
||||
*/
|
||||
void ExtensionClean()
|
||||
{
|
||||
//
|
||||
peak = 0;
|
||||
vale = 0;
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Extension Functions ...
|
||||
|
||||
//
|
||||
// Detect Setup Conditions ...
|
||||
bool DetectX121SMCXPVDPSiganlSetup(
|
||||
string _symbol,
|
||||
ENUM_TIMEFRAMES _period,
|
||||
//
|
||||
X121SMCStrategyXPVDPSignalConditions &conditions,
|
||||
//
|
||||
XC121SMCCycleHelper *triggerCycleHelper,
|
||||
XC121SMCCycleHelper *decisionCycleHelper,
|
||||
XC121SMCCycleHelper *analyseCycleHelper,
|
||||
XC121SMCCycleHelper *verificationCycleHelper,
|
||||
XC121SMCCycleHelper *consolidationCycleHelper,
|
||||
XC121SMCCycleHelper *visionCycleHelper
|
||||
//
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
int zIndex = 0;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
int loopback = 10;
|
||||
|
||||
//
|
||||
string symbol = _symbol;
|
||||
ENUM_TIMEFRAMES period = _period;
|
||||
|
||||
//
|
||||
conditions.symbol = symbol;
|
||||
conditions.period = period;
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
result = zBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
zIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL cBar;
|
||||
result = cBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
cIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double ask = GetAsk(symbol);
|
||||
double bid = GetBid(symbol);
|
||||
datetime cTime = TimeCurrent();
|
||||
|
||||
//
|
||||
double ll = cBar.FindLowest(9, MODE_LOW);
|
||||
double hh = cBar.FindHighest(9, MODE_HIGH);
|
||||
|
||||
//
|
||||
int zoneValidationDivider = 10;
|
||||
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
||||
.GetDonChainLength();
|
||||
|
||||
//
|
||||
double selectedSL = 0;
|
||||
|
||||
//
|
||||
// Cycles Conditions ...
|
||||
|
||||
//
|
||||
// Trigger ...
|
||||
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
||||
X121SMCCycleConditions triggerConditions;
|
||||
result = triggerCycleHelper.GetConditions(
|
||||
triggerCycleEvents,
|
||||
triggerPoiEvents,
|
||||
triggerConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Decision ...
|
||||
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
||||
X121SMCCycleConditions decisionConditions;
|
||||
result = decisionCycleHelper.GetConditions(
|
||||
decisionCycleEvents,
|
||||
decisionPoiEvents,
|
||||
decisionConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Analyse ...
|
||||
ENUM_XPOI_EVENTS analysePoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
||||
X121SMCCycleConditions analyseConditions;
|
||||
result = analyseCycleHelper.GetConditions(
|
||||
analyseCycleEvents,
|
||||
analysePoiEvents,
|
||||
analyseConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Verification ...
|
||||
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
||||
X121SMCCycleConditions verificationConditions;
|
||||
result = verificationCycleHelper.GetConditions(
|
||||
verificationCycleEvents,
|
||||
verificationPoiEvents,
|
||||
verificationConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Consolidation ...
|
||||
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
||||
X121SMCCycleConditions consolidationConditions;
|
||||
result = consolidationCycleHelper.GetConditions(
|
||||
consolidationCycleEvents,
|
||||
consolidationPoiEvents,
|
||||
consolidationConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Vision ...
|
||||
ENUM_XPOI_EVENTS visionPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
||||
X121SMCCycleConditions visionConditions;
|
||||
result = visionCycleHelper.GetConditions(
|
||||
visionCycleEvents,
|
||||
visionPoiEvents,
|
||||
visionConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Cycles POI States ...
|
||||
XPOIState triggerState = triggerConditions.state;
|
||||
XPOIState decisionState = decisionConditions.state;
|
||||
XPOIState analyseState = analyseConditions.state;
|
||||
XPOIState verificationState = verificationConditions.state;
|
||||
XPOIState consolidationState = consolidationConditions.state;
|
||||
XPOIState visionState = visionConditions.state;
|
||||
|
||||
//
|
||||
// Setup Conditions ...
|
||||
|
||||
//
|
||||
// Detect Market Trend ...
|
||||
ENUM_X_DIRECTION trend;
|
||||
bool hasTrend = consolidationCycleHelper
|
||||
.DetectTrend(trend);
|
||||
bool hasBullishTrend = hasTrend &&
|
||||
IsBullish(trend);
|
||||
bool hasBearishTrend = hasTrend &&
|
||||
IsBearish(trend);
|
||||
result = hasBullishTrend ||
|
||||
hasBearishTrend;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Select Source State ...
|
||||
XPOIState state = decisionState;
|
||||
|
||||
//
|
||||
// Detect High Equals to Peaks or Low Equals to Vale ...
|
||||
|
||||
//
|
||||
// Peak ...
|
||||
double peak = triggerConditions.x121Conditions.peaksBuffer[1];
|
||||
bool isNewPeak = triggerConditions.x121Conditions.isNewPeak;
|
||||
bool isNewPeakOverLast = triggerConditions.x121Conditions.isNewPeakOverLast;
|
||||
bool isNewPeakUnderLast = triggerConditions.x121Conditions.isNewPeakUnderLast;
|
||||
|
||||
//
|
||||
// Vale ...
|
||||
double vale = triggerConditions.x121Conditions.valesBuffer[1];
|
||||
bool isNewVale = triggerConditions.x121Conditions.isNewVale;
|
||||
bool isNewValeOverLast = triggerConditions.x121Conditions.isNewValeOverLast;
|
||||
bool isNewValeUnderLast = triggerConditions.x121Conditions.isNewValeUnderLast;
|
||||
|
||||
//
|
||||
bool isHighEqualsToPeak =
|
||||
isNewPeak &&
|
||||
peak == cBar.high;
|
||||
|
||||
//
|
||||
bool isLowEqualsToVale =
|
||||
isNewVale &&
|
||||
vale == cBar.low;
|
||||
|
||||
//
|
||||
result = isHighEqualsToPeak ||
|
||||
isLowEqualsToVale;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Now We Have To Check DONChain Status ...
|
||||
|
||||
//
|
||||
double donCUpper = triggerConditions.x121Conditions.donCloseUpperBuffer[1];
|
||||
double donCUpperPrev = triggerConditions.x121Conditions.donCloseUpperBuffer[2];
|
||||
|
||||
//
|
||||
double donCLower = triggerConditions.x121Conditions.donCloseLowerBuffer[1];
|
||||
double donCLowerPrev = triggerConditions.x121Conditions.donCloseLowerBuffer[2];
|
||||
|
||||
//
|
||||
double donOUpper = triggerConditions.x121Conditions.donOpenUpperBuffer[1];
|
||||
double donOUpperPrev = triggerConditions.x121Conditions.donOpenUpperBuffer[2];
|
||||
|
||||
//
|
||||
double donOLower = triggerConditions.x121Conditions.donOpenLowerBuffer[1];
|
||||
double donOLowerPrev = triggerConditions.x121Conditions.donOpenLowerBuffer[2];
|
||||
|
||||
//
|
||||
bool isDonUpperBullish = donCUpper > donOUpper;
|
||||
bool isDonUpperBullishPrev = donCUpperPrev > donOUpperPrev;
|
||||
|
||||
//
|
||||
bool isDonUpperBearish = donCUpper < donOUpper;
|
||||
bool isDonUpperBearishPrev = donCUpperPrev < donOUpperPrev;
|
||||
|
||||
//
|
||||
bool isDonUpperSwitchedToBullish = isDonUpperBullish &&
|
||||
!isDonUpperBullishPrev;
|
||||
|
||||
//
|
||||
bool isDonUpperSwitchedToBearish = isDonUpperBearish &&
|
||||
!isDonUpperBearishPrev;
|
||||
|
||||
//
|
||||
bool isDonLowerBullish = donCLower > donOLower;
|
||||
bool isDonLowerBullishPrev = donCLowerPrev > donOLowerPrev;
|
||||
|
||||
//
|
||||
bool isDonLowerBearish = donCLower < donOLower;
|
||||
bool isDonLowerBearishPrev = donCLowerPrev < donOLowerPrev;
|
||||
|
||||
//
|
||||
bool isDonLowerSwitchedToBullish = isDonLowerBullish &&
|
||||
!isDonLowerBullishPrev;
|
||||
|
||||
//
|
||||
bool isDonLowerSwitchedToBearish = isDonLowerBearish &&
|
||||
!isDonLowerBearishPrev;
|
||||
|
||||
//
|
||||
// Calculate State ...
|
||||
|
||||
//
|
||||
bool isDonInBullishState =
|
||||
//
|
||||
// Upper ...
|
||||
(isDonUpperBullish ||
|
||||
isDonUpperSwitchedToBullish)
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Lower ...
|
||||
(isDonLowerBullish ||
|
||||
isDonLowerSwitchedToBullish)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isDonInBearishState =
|
||||
//
|
||||
// Upper ...
|
||||
(isDonUpperBearish ||
|
||||
isDonUpperSwitchedToBearish)
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Lower ...
|
||||
(isDonLowerBearish ||
|
||||
isDonLowerSwitchedToBearish)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Summary DonChain State ...
|
||||
|
||||
//
|
||||
isBullish =
|
||||
//
|
||||
hasBullishTrend
|
||||
//
|
||||
&&
|
||||
//
|
||||
isDonInBullishState
|
||||
//
|
||||
&&
|
||||
//
|
||||
(isHighEqualsToPeak ||
|
||||
isLowEqualsToVale)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
//
|
||||
hasBearishTrend
|
||||
//
|
||||
&&
|
||||
//
|
||||
isDonInBearishState
|
||||
//
|
||||
&&
|
||||
//
|
||||
(isHighEqualsToPeak ||
|
||||
isLowEqualsToVale)
|
||||
//
|
||||
;
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check VWap Conditions ...
|
||||
|
||||
//
|
||||
double vwapFast = triggerConditions.x121Conditions.vwapFastBuffer[1];
|
||||
double vwapMid = triggerConditions.x121Conditions.vwapMidBuffer[1];
|
||||
double vwapSlow = triggerConditions.x121Conditions.vwapSlowBuffer[1];
|
||||
|
||||
//
|
||||
double vwaps[3] = {
|
||||
vwapFast,
|
||||
vwapMid,
|
||||
vwapSlow,
|
||||
};
|
||||
double vwapMax = GetMax(vwaps);
|
||||
double vwapMin = GetMin(vwaps);
|
||||
|
||||
//
|
||||
bool isCloseOverVwapMax =
|
||||
//
|
||||
ask > vwapMax &&
|
||||
bid > vwapMax &&
|
||||
(cBar.low > vwapMax ||
|
||||
cBar.close > vwapMax)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isCloseUnderVwapMin =
|
||||
//
|
||||
ask < vwapMin &&
|
||||
bid < vwapMin &&
|
||||
(cBar.high < vwapMin ||
|
||||
cBar.close < vwapMin)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isVWapFastBullish = triggerConditions.x121Conditions.isVWapFastBullish;
|
||||
bool isVWapFastBearish = triggerConditions.x121Conditions.isVWapFastBearish;
|
||||
bool isVWapMidBullish = triggerConditions.x121Conditions.isVWapMidBullish;
|
||||
bool isVWapMidBearish = triggerConditions.x121Conditions.isVWapMidBearish;
|
||||
bool isVWapSlowBullish = triggerConditions.x121Conditions.isVWapSlowBullish;
|
||||
bool isVWapSlowBearish = triggerConditions.x121Conditions.isVWapSlowBearish;
|
||||
bool isVWapFastOverMid = triggerConditions.x121Conditions.isVWapFastOverMid;
|
||||
bool isVWapMidOverSlow = triggerConditions.x121Conditions.isVWapMidOverSlow;
|
||||
bool isVWapFastUnderMid = triggerConditions.x121Conditions.isVWapFastUnderMid;
|
||||
bool isVWapMidUnderSlow = triggerConditions.x121Conditions.isVWapMidUnderSlow;
|
||||
|
||||
//
|
||||
bool isVwapBullishFormed =
|
||||
//
|
||||
// Order ...
|
||||
(isVWapFastOverMid ||
|
||||
isVWapMidOverSlow ||
|
||||
(isVWapFastOverMid &&
|
||||
isVWapMidOverSlow))
|
||||
//
|
||||
&&
|
||||
// State ...
|
||||
((isVWapFastBullish &&
|
||||
isVWapMidBullish) ||
|
||||
(isVWapMidBullish &&
|
||||
isVWapSlowBullish) ||
|
||||
(isVWapFastBullish &&
|
||||
isVWapMidBullish &&
|
||||
isVWapSlowBullish))
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isVwapBearishFormed =
|
||||
//
|
||||
// Order ...
|
||||
(isVWapFastUnderMid ||
|
||||
isVWapMidUnderSlow ||
|
||||
(isVWapFastUnderMid &&
|
||||
isVWapMidUnderSlow))
|
||||
//
|
||||
&&
|
||||
// State ...
|
||||
((isVWapFastBearish &&
|
||||
isVWapMidBearish) ||
|
||||
(isVWapMidBearish &&
|
||||
isVWapSlowBearish) ||
|
||||
(isVWapFastBearish &&
|
||||
isVWapMidBearish &&
|
||||
isVWapSlowBearish))
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Summar VWap State ...
|
||||
|
||||
//
|
||||
isBullish =
|
||||
isBullish &&
|
||||
isCloseOverVwapMax &&
|
||||
isVwapBullishFormed;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
isBearish &&
|
||||
isCloseUnderVwapMin &&
|
||||
isVwapBearishFormed;
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Sar State ...
|
||||
double sar = triggerConditions.x121Conditions.sarBuffer[1];
|
||||
|
||||
//
|
||||
bool isSarBullish = triggerConditions.x121Conditions.isSarBullish;
|
||||
bool isSarSwitchedToBullish = triggerConditions.x121Conditions.isSarSwitchedToBullish;
|
||||
|
||||
//
|
||||
bool isSarBearish = triggerConditions.x121Conditions.isSarBearish;
|
||||
bool isSarSwitchedToBearish = triggerConditions.x121Conditions.isSarSwitchedToBearish;
|
||||
|
||||
//
|
||||
// Summary Sar ...
|
||||
|
||||
//
|
||||
bool isSarBullishFormed = isSarBullish ||
|
||||
isSarSwitchedToBullish;
|
||||
|
||||
//
|
||||
bool isSarBearishFormed = isSarBearish ||
|
||||
isSarSwitchedToBearish;
|
||||
|
||||
//
|
||||
isBullish =
|
||||
isBullish &&
|
||||
isSarBullishFormed;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
isBearish &&
|
||||
isSarBearishFormed;
|
||||
|
||||
//
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.setupTime = cTime;
|
||||
conditions.dir =
|
||||
isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Trigger Conditions ...
|
||||
bool DetectX121SMCXPVDPSiganlTrigger(
|
||||
//
|
||||
X121SMCStrategyXPVDPSignalConditions &conditions,
|
||||
//
|
||||
string _symbol,
|
||||
ENUM_TIMEFRAMES _period,
|
||||
//
|
||||
XC121SMCCycleHelper *triggerCycleHelper,
|
||||
XC121SMCCycleHelper *decisionCycleHelper,
|
||||
XC121SMCCycleHelper *analyseCycleHelper,
|
||||
XC121SMCCycleHelper *verificationCycleHelper,
|
||||
XC121SMCCycleHelper *consolidationCycleHelper,
|
||||
XC121SMCCycleHelper *visionCycleHelper,
|
||||
//
|
||||
int maxAllowedSetupAge = 60 //
|
||||
//
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = conditions.IsSetuped();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
datetime setupTime = conditions.setupTime;
|
||||
ENUM_X_DIRECTION setupDir = conditions.dir;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
int zIndex = 0;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
int loopback = 10;
|
||||
|
||||
//
|
||||
string symbol = _symbol;
|
||||
ENUM_TIMEFRAMES period = _period;
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
result = zBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
zIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL cBar;
|
||||
result = cBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
cIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double ask = GetAsk(symbol);
|
||||
double bid = GetBid(symbol);
|
||||
datetime cTime = TimeCurrent();
|
||||
|
||||
//
|
||||
double ll = cBar.FindLowest(9, MODE_LOW);
|
||||
double hh = cBar.FindHighest(9, MODE_HIGH);
|
||||
|
||||
//
|
||||
int zoneValidationDivider = 10;
|
||||
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
||||
.GetDonChainLength();
|
||||
|
||||
//
|
||||
double selectedSL = 0;
|
||||
|
||||
//
|
||||
// Cycles Conditions ...
|
||||
|
||||
//
|
||||
// Trigger ...
|
||||
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
||||
X121SMCCycleConditions triggerConditions;
|
||||
result = triggerCycleHelper.GetConditions(
|
||||
triggerCycleEvents,
|
||||
triggerPoiEvents,
|
||||
triggerConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Decision ...
|
||||
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
||||
X121SMCCycleConditions decisionConditions;
|
||||
result = decisionCycleHelper.GetConditions(
|
||||
decisionCycleEvents,
|
||||
decisionPoiEvents,
|
||||
decisionConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Analyse ...
|
||||
ENUM_XPOI_EVENTS analysePoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
||||
X121SMCCycleConditions analyseConditions;
|
||||
result = analyseCycleHelper.GetConditions(
|
||||
analyseCycleEvents,
|
||||
analysePoiEvents,
|
||||
analyseConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Verification ...
|
||||
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
||||
X121SMCCycleConditions verificationConditions;
|
||||
result = verificationCycleHelper.GetConditions(
|
||||
verificationCycleEvents,
|
||||
verificationPoiEvents,
|
||||
verificationConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Consolidation ...
|
||||
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
||||
X121SMCCycleConditions consolidationConditions;
|
||||
result = consolidationCycleHelper.GetConditions(
|
||||
consolidationCycleEvents,
|
||||
consolidationPoiEvents,
|
||||
consolidationConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Vision ...
|
||||
ENUM_XPOI_EVENTS visionPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
||||
X121SMCCycleConditions visionConditions;
|
||||
result = visionCycleHelper.GetConditions(
|
||||
visionCycleEvents,
|
||||
visionPoiEvents,
|
||||
visionConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Cycles POI States ...
|
||||
XPOIState triggerState = triggerConditions.state;
|
||||
XPOIState decisionState = decisionConditions.state;
|
||||
XPOIState analyseState = analyseConditions.state;
|
||||
XPOIState verificationState = verificationConditions.state;
|
||||
XPOIState consolidationState = consolidationConditions.state;
|
||||
XPOIState visionState = visionConditions.state;
|
||||
|
||||
//
|
||||
// Trigger Conditions ...
|
||||
|
||||
//
|
||||
double vwapFast = triggerConditions.x121Conditions.vwapFastBuffer[1];
|
||||
double vwapMid = triggerConditions.x121Conditions.vwapMidBuffer[1];
|
||||
double vwapSlow = triggerConditions.x121Conditions.vwapSlowBuffer[1];
|
||||
|
||||
//
|
||||
double vwaps[3] = {
|
||||
vwapFast,
|
||||
vwapMid,
|
||||
vwapSlow,
|
||||
};
|
||||
double vwapMax = GetMax(vwaps);
|
||||
double vwapMin = GetMin(vwaps);
|
||||
|
||||
//
|
||||
double sar = triggerConditions.x121Conditions.sarBuffer[1];
|
||||
|
||||
//
|
||||
isBullish =
|
||||
//
|
||||
IsBullish(setupDir)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
//
|
||||
IsBearish(setupDir)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
// Cleanup Setup Conditions ...
|
||||
int setupAge = conditions.GetSetupAge();
|
||||
if (IsValidSize(setupAge) &&
|
||||
IsValidSize(maxAllowedSetupAge) &&
|
||||
setupAge >= maxAllowedSetupAge)
|
||||
{
|
||||
conditions.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.triggerTime = cTime;
|
||||
conditions.sl = isBullish
|
||||
? MathMin(sar, vwapMin)
|
||||
: MathMin(sar, vwapMax);
|
||||
conditions.type = isBullish
|
||||
? X_POSITION_TYPE_LONG
|
||||
: X_POSITION_TYPE_SHORT;
|
||||
|
||||
//
|
||||
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
@@ -0,0 +1,297 @@
|
||||
|
||||
//
|
||||
// Find a Support or Resistance Zone ...
|
||||
|
||||
// //
|
||||
// // Support Zone ...
|
||||
// bool hasSupportZone = conditions.HasSupportZone();
|
||||
// if (isLowEqualsToVale && !hasSupportZone)
|
||||
// {
|
||||
// //
|
||||
// int count = state.CountSupportZones();
|
||||
// if (IsValidSize(count))
|
||||
// {
|
||||
// //
|
||||
// for (int i = count - 1; i >= 0; i--)
|
||||
// {
|
||||
// //
|
||||
// XCSupportZone *iZone = state.supportZones[i];
|
||||
|
||||
// //
|
||||
// bool isValid =
|
||||
// vale >= iZone.Lower() &&
|
||||
// vale <= iZone.Upper();
|
||||
// if (isValid)
|
||||
// {
|
||||
// //
|
||||
// conditions.supportZone = iZone;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// //
|
||||
// hasSupportZone = conditions.HasSupportZone();
|
||||
// }
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Resistance Zone ...
|
||||
// bool hasResistanceZone = conditions.HasResistanceZone();
|
||||
// if (isHighEqualsToPeak && !hasResistanceZone)
|
||||
// {
|
||||
// //
|
||||
// int count = state.CountResistanceZones();
|
||||
// if (IsValidSize(count))
|
||||
// {
|
||||
// //
|
||||
// for (int i = count - 1; i >= 0; i--)
|
||||
// {
|
||||
// //
|
||||
// XCResistanceZone *iZone = state.resistanceZones[i];
|
||||
|
||||
// //
|
||||
// bool isValid =
|
||||
// peak >= iZone.Lower() &&
|
||||
// peak <= iZone.Upper();
|
||||
// if (isValid)
|
||||
// {
|
||||
// //
|
||||
// conditions.resistanceZone = iZone;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// //
|
||||
// hasResistanceZone = conditions.HasResistanceZone();
|
||||
// }
|
||||
// }
|
||||
|
||||
// //
|
||||
// isBullish =
|
||||
// isLowEqualsToVale &&
|
||||
// hasSupportZone;
|
||||
|
||||
// //
|
||||
// isBearish =
|
||||
// isHighEqualsToPeak &&
|
||||
// hasResistanceZone;
|
||||
|
||||
// //
|
||||
// result = isBullish ||
|
||||
// isBearish;
|
||||
// if (!result)
|
||||
// {
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Retrieve Active Zone ...
|
||||
// XCBarZone *activeZone;
|
||||
// result = conditions.HasActiveZone(activeZone);
|
||||
// if (!result)
|
||||
// {
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Draw ...
|
||||
// if (hasSupportZone)
|
||||
// {
|
||||
// //
|
||||
// XCSupportZoneObject *iObj;
|
||||
// bool isCreated = drawer.CreateSupportZone(
|
||||
// conditions.supportZone,
|
||||
// iObj //
|
||||
// );
|
||||
// }
|
||||
|
||||
// //
|
||||
// if (hasResistanceZone)
|
||||
// {
|
||||
// //
|
||||
// XCResistanceZoneObject *iObj;
|
||||
// bool isCreated = drawer.CreateResistanceZone(
|
||||
// conditions.resistanceZone,
|
||||
// iObj //
|
||||
// );
|
||||
// }
|
||||
|
||||
//
|
||||
XCSupportZone *supportZone;
|
||||
XCResistanceZone *resistanceZone;
|
||||
datetime activeZoneFoundedAt;
|
||||
|
||||
//
|
||||
supportZone = NULL;
|
||||
resistanceZone = NULL;
|
||||
activeZoneFoundedAt = NULL;
|
||||
|
||||
bool HasSupportZone()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
supportZone != NULL &&
|
||||
supportZone.IsValid();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
bool HasResistanceZone()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
resistanceZone != NULL &&
|
||||
resistanceZone.IsValid();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
bool HasActiveZone(XCBarZone *&zone)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
zone = NULL;
|
||||
|
||||
//
|
||||
bool hasSupportZone = HasSupportZone();
|
||||
bool hasResistanceZone = HasResistanceZone();
|
||||
|
||||
//
|
||||
result = hasSupportZone ||
|
||||
hasResistanceZone;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (hasSupportZone)
|
||||
{
|
||||
//
|
||||
supportZone.To(TimeCurrent());
|
||||
zone = supportZone;
|
||||
}
|
||||
|
||||
//
|
||||
if (hasResistanceZone)
|
||||
{
|
||||
//
|
||||
resistanceZone.To(TimeCurrent());
|
||||
zone = resistanceZone;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Detect Cycle Trend Based On Pivots ...
|
||||
*
|
||||
* @param dir: ENUM_X_DIRECTION member Reference ...
|
||||
* @param numberOfPivots: Integer ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool DetectTrend(
|
||||
ENUM_X_DIRECTION &dir,
|
||||
int numberOfPivots = 3 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
dir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
if (numberOfPivots < 2)
|
||||
{
|
||||
numberOfPivots = 2;
|
||||
}
|
||||
|
||||
//
|
||||
int verifications = 0;
|
||||
XValueChange changes[];
|
||||
|
||||
//
|
||||
// Bearish Trend ...
|
||||
int peaksChangesCount = CountPeaksChanges();
|
||||
if (!result &&
|
||||
peaksChangesCount > numberOfPivots)
|
||||
{
|
||||
//
|
||||
Clean(changes);
|
||||
FillPeaksChanges(changes);
|
||||
|
||||
//
|
||||
verifications = 0;
|
||||
for (int i = peaksChangesCount - 1 - numberOfPivots; i < peaksChangesCount - 2; i++)
|
||||
{
|
||||
//
|
||||
XValueChange cChange = changes[i];
|
||||
XValueChange nChange = changes[i + 1];
|
||||
|
||||
//
|
||||
if (cChange.after > nChange.after)
|
||||
{
|
||||
verifications++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = verifications == numberOfPivots - 1;
|
||||
if (result)
|
||||
{
|
||||
dir = X_DIRECTION_BEARISH;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Bullish Trend ...
|
||||
int valesChangesCount = CountValesChanges();
|
||||
if (!result &&
|
||||
valesChangesCount > numberOfPivots)
|
||||
{
|
||||
//
|
||||
Clean(changes);
|
||||
FillValesChanges(changes);
|
||||
|
||||
//
|
||||
verifications = 0;
|
||||
for (int i = valesChangesCount - 1 - numberOfPivots; i < valesChangesCount - 2; i++)
|
||||
{
|
||||
//
|
||||
XValueChange cChange = changes[i];
|
||||
XValueChange nChange = changes[i + 1];
|
||||
|
||||
//
|
||||
if (cChange.after < nChange.after)
|
||||
{
|
||||
verifications++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = verifications == numberOfPivots - 1;
|
||||
if (result)
|
||||
{
|
||||
dir = X_DIRECTION_BULLISH;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,787 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 X121 SMC Signal Class
|
||||
// -------------------------------------------------
|
||||
// Name:
|
||||
// Description: provide all Signalling 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-121.smc.market.cycle.helper.class.mq5"
|
||||
#include "../Libraries/x-121.smc.lib.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
struct X121SMCStrategyTestSignalConditions
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
double sl;
|
||||
ENUM_X_DIRECTION dir;
|
||||
ENUM_X_POSITION_TYPES type;
|
||||
|
||||
//
|
||||
// Setup Props ...
|
||||
|
||||
//
|
||||
datetime setupTime;
|
||||
datetime triggerTime;
|
||||
|
||||
//
|
||||
XPVPivot pivot;
|
||||
|
||||
//
|
||||
// Trigger Props ...
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
X121SMCStrategyTestSignalConditions()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleaning Up ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
sl = 0;
|
||||
|
||||
//
|
||||
dir = X_DIRECTION_NONE;
|
||||
type = X_POSITION_TYPE_NONE;
|
||||
|
||||
//
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
setupTime = NULL;
|
||||
triggerTime = NULL;
|
||||
|
||||
//
|
||||
pivot.Clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Condition is Setting Up ...
|
||||
*
|
||||
* @param dir: ENUM_X_DIRECTION member, Setting Up Direction ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsSetuped()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid(setupTime) &&
|
||||
HasDirection(dir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect How we Can Trigger Signal ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool CanTrigger()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
sl > 0 &&
|
||||
IsValid(symbol) &&
|
||||
IsValid(period) &&
|
||||
IsValid(triggerTime) &&
|
||||
type != X_POSITION_TYPE_ALL &&
|
||||
type != X_POSITION_TYPE_NONE
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Extensions ...
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Extension Functions ...
|
||||
|
||||
//
|
||||
// Detect Setup Conditions ...
|
||||
bool DetectX121SMCTestSiganlSetup(
|
||||
string _symbol,
|
||||
ENUM_TIMEFRAMES _period,
|
||||
//
|
||||
X121SMCStrategyTestSignalConditions &conditions,
|
||||
//
|
||||
XC121SMCCycleHelper *triggerCycleHelper,
|
||||
XC121SMCCycleHelper *decisionCycleHelper,
|
||||
XC121SMCCycleHelper *analyseCycleHelper,
|
||||
XC121SMCCycleHelper *verificationCycleHelper,
|
||||
XC121SMCCycleHelper *consolidationCycleHelper,
|
||||
XC121SMCCycleHelper *visionCycleHelper
|
||||
//
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
int zIndex = 0;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
int loopback = 10;
|
||||
|
||||
//
|
||||
string symbol = _symbol;
|
||||
ENUM_TIMEFRAMES period = _period;
|
||||
|
||||
//
|
||||
conditions.symbol = symbol;
|
||||
conditions.period = period;
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
result = zBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
zIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL cBar;
|
||||
result = cBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
cIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double ask = GetAsk(symbol);
|
||||
double bid = GetBid(symbol);
|
||||
datetime cTime = TimeCurrent();
|
||||
|
||||
//
|
||||
double ll = cBar.FindLowest(9, MODE_LOW);
|
||||
double hh = cBar.FindHighest(9, MODE_HIGH);
|
||||
|
||||
//
|
||||
int zoneValidationDivider = 10;
|
||||
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
||||
.GetDonChainLength();
|
||||
|
||||
//
|
||||
double selectedSL = 0;
|
||||
|
||||
//
|
||||
// Cycles Conditions ...
|
||||
|
||||
//
|
||||
// Trigger ...
|
||||
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
||||
X121SMCCycleConditions triggerConditions;
|
||||
result = triggerCycleHelper.GetConditions(
|
||||
triggerCycleEvents,
|
||||
triggerPoiEvents,
|
||||
triggerConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Decision ...
|
||||
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
||||
X121SMCCycleConditions decisionConditions;
|
||||
result = decisionCycleHelper.GetConditions(
|
||||
decisionCycleEvents,
|
||||
decisionPoiEvents,
|
||||
decisionConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Analyse ...
|
||||
ENUM_XPOI_EVENTS analysePoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
||||
X121SMCCycleConditions analyseConditions;
|
||||
result = analyseCycleHelper.GetConditions(
|
||||
analyseCycleEvents,
|
||||
analysePoiEvents,
|
||||
analyseConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Verification ...
|
||||
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
||||
X121SMCCycleConditions verificationConditions;
|
||||
result = verificationCycleHelper.GetConditions(
|
||||
verificationCycleEvents,
|
||||
verificationPoiEvents,
|
||||
verificationConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Consolidation ...
|
||||
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
||||
X121SMCCycleConditions consolidationConditions;
|
||||
result = consolidationCycleHelper.GetConditions(
|
||||
consolidationCycleEvents,
|
||||
consolidationPoiEvents,
|
||||
consolidationConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Vision ...
|
||||
ENUM_XPOI_EVENTS visionPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
||||
X121SMCCycleConditions visionConditions;
|
||||
result = visionCycleHelper.GetConditions(
|
||||
visionCycleEvents,
|
||||
visionPoiEvents,
|
||||
visionConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Cycles POI States ...
|
||||
XPOIState triggerState = triggerConditions.state;
|
||||
XPOIState decisionState = decisionConditions.state;
|
||||
XPOIState analyseState = analyseConditions.state;
|
||||
XPOIState verificationState = verificationConditions.state;
|
||||
XPOIState consolidationState = consolidationConditions.state;
|
||||
XPOIState visionState = visionConditions.state;
|
||||
|
||||
//
|
||||
// Check Order Block ...
|
||||
// TODO: Later ...
|
||||
// bool hasOrderBlock = conditions.HasOrderBlock();
|
||||
// if (hasOrderBlock)
|
||||
// {
|
||||
// //
|
||||
// DetectX121SMCTestSiganlOrderBlock(
|
||||
// zBar,
|
||||
// consolidationState,
|
||||
// conditions //
|
||||
// );
|
||||
// }
|
||||
|
||||
//
|
||||
bool isMarketBullish =
|
||||
//
|
||||
// VWap State ...
|
||||
decisionConditions.x121Conditions.isVWapBullishState &&
|
||||
analyseConditions.x121Conditions.isVWapBullishState &&
|
||||
verificationConditions.x121Conditions.isVWapBullishState
|
||||
//
|
||||
&&
|
||||
//
|
||||
// VWap Order ...
|
||||
decisionConditions.x121Conditions.isVWapBullishOrdered &&
|
||||
analyseConditions.x121Conditions.isVWapBullishOrdered &&
|
||||
verificationConditions.x121Conditions.isVWapBullishOrdered
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Sar ...
|
||||
decisionConditions.x121Conditions.isSarBullish &&
|
||||
analyseConditions.x121Conditions.isSarBullish &&
|
||||
verificationConditions.x121Conditions.isSarBullish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isMarketBearish =
|
||||
//
|
||||
// VWap State ...
|
||||
decisionConditions.x121Conditions.isVWapBearishState &&
|
||||
analyseConditions.x121Conditions.isVWapBearishState &&
|
||||
verificationConditions.x121Conditions.isVWapBearishState
|
||||
//
|
||||
&&
|
||||
//
|
||||
// VWap Order ...
|
||||
decisionConditions.x121Conditions.isVWapBearishOrdered &&
|
||||
analyseConditions.x121Conditions.isVWapBearishOrdered &&
|
||||
verificationConditions.x121Conditions.isVWapBearishOrdered
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Sar ...
|
||||
decisionConditions.x121Conditions.isSarBearish &&
|
||||
analyseConditions.x121Conditions.isSarBearish &&
|
||||
verificationConditions.x121Conditions.isSarBearish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Step 1
|
||||
// Detect Market Direction ...
|
||||
isBullish = isMarketBullish;
|
||||
isBearish = isMarketBearish;
|
||||
|
||||
//
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Step 2
|
||||
// VWap Switches or Sar Switches ...
|
||||
|
||||
//
|
||||
bool isSarBullish = triggerConditions.x121Conditions.isSarBullish;
|
||||
bool isSarBearish = triggerConditions.x121Conditions.isSarBearish;
|
||||
|
||||
//
|
||||
bool isSarSwitchedToBullish = triggerConditions.x121Conditions.isSarSwitchedToBullish;
|
||||
bool isSarSwitchedToBearish = triggerConditions.x121Conditions.isSarSwitchedToBearish;
|
||||
|
||||
//
|
||||
bool isVWapBullishState = triggerConditions.x121Conditions.isVWapBullishState;
|
||||
bool isVWapBearishState = triggerConditions.x121Conditions.isVWapBearishState;
|
||||
|
||||
//
|
||||
bool isVWapSwitchedToBullishState = triggerConditions.x121Conditions.isVWapSwitchedToBullishState;
|
||||
bool isVWapSwitchedToBearishState = triggerConditions.x121Conditions.isVWapSwitchedToBearishState;
|
||||
|
||||
//
|
||||
bool isVWapBullishOrdered = triggerConditions.x121Conditions.isVWapBullishOrdered;
|
||||
bool isVWapBearishOrdered = triggerConditions.x121Conditions.isVWapBearishOrdered;
|
||||
|
||||
//
|
||||
bool isVWapSwitchedToBullishOrdered = triggerConditions.x121Conditions.isVWapSwitchedToBullishOrdered;
|
||||
bool isVWapSwitchedToBearishOrdered = triggerConditions.x121Conditions.isVWapSwitchedToBearishOrdered;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//
|
||||
bool isSarStartedBullishStructure =
|
||||
//
|
||||
isSarSwitchedToBullish &&
|
||||
isVWapBullishState &&
|
||||
isVWapBullishOrdered
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSarStartedBearishStructure =
|
||||
//
|
||||
isSarSwitchedToBearish &&
|
||||
isVWapBearishState &&
|
||||
isVWapBearishOrdered
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//
|
||||
bool isVWapStateStartedBullishStructure =
|
||||
//
|
||||
isVWapSwitchedToBullishState &&
|
||||
isSarBullish &&
|
||||
isVWapBullishOrdered
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isVWapStateStartedBearishStructure =
|
||||
//
|
||||
isVWapSwitchedToBearishState &&
|
||||
isSarBearish &&
|
||||
isVWapBearishOrdered
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//
|
||||
bool isVWapOrderStartedBullishStructure =
|
||||
//
|
||||
isVWapSwitchedToBullishOrdered &&
|
||||
isSarBullish &&
|
||||
isVWapBullishState
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isVWapOrderStartedBearishStructure =
|
||||
//
|
||||
isVWapSwitchedToBearishOrdered &&
|
||||
isSarBearish &&
|
||||
isVWapBearishState
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//
|
||||
isBullish =
|
||||
//
|
||||
isBullish
|
||||
//
|
||||
&&
|
||||
//
|
||||
(
|
||||
//
|
||||
isSarStartedBullishStructure ||
|
||||
isVWapStateStartedBullishStructure ||
|
||||
isVWapOrderStartedBullishStructure
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
//
|
||||
isBearish
|
||||
//
|
||||
&&
|
||||
//
|
||||
(
|
||||
//
|
||||
isSarStartedBearishStructure ||
|
||||
isVWapStateStartedBearishStructure ||
|
||||
isVWapOrderStartedBearishStructure
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.setupTime = cTime;
|
||||
conditions.dir =
|
||||
isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Trigger Conditions ...
|
||||
bool DetectX121SMCTestSiganlTrigger(
|
||||
//
|
||||
X121SMCStrategyTestSignalConditions &conditions,
|
||||
//
|
||||
string _symbol,
|
||||
ENUM_TIMEFRAMES _period,
|
||||
//
|
||||
XC121SMCCycleHelper *triggerCycleHelper,
|
||||
XC121SMCCycleHelper *decisionCycleHelper,
|
||||
XC121SMCCycleHelper *analyseCycleHelper,
|
||||
XC121SMCCycleHelper *verificationCycleHelper,
|
||||
XC121SMCCycleHelper *consolidationCycleHelper,
|
||||
XC121SMCCycleHelper *visionCycleHelper
|
||||
//
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = conditions.IsSetuped();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
ENUM_X_DIRECTION setupDir = conditions.dir;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
int zIndex = 0;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
int loopback = 10;
|
||||
|
||||
//
|
||||
ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_SMPV;
|
||||
string providerStr = ToString(provider);
|
||||
|
||||
//
|
||||
string symbol = _symbol;
|
||||
ENUM_TIMEFRAMES period = _period;
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
result = zBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
zIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL cBar;
|
||||
result = cBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
cIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double ask = GetAsk(symbol);
|
||||
double bid = GetBid(symbol);
|
||||
datetime cTime = TimeCurrent();
|
||||
|
||||
//
|
||||
double ll = cBar.FindLowest(9, MODE_LOW);
|
||||
double hh = cBar.FindHighest(9, MODE_HIGH);
|
||||
|
||||
//
|
||||
int zoneValidationDivider = 10;
|
||||
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
||||
.GetDonChainLength();
|
||||
|
||||
//
|
||||
double selectedSL = 0;
|
||||
|
||||
//
|
||||
// Cycles Conditions ...
|
||||
|
||||
//
|
||||
// Trigger ...
|
||||
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
||||
X121SMCCycleConditions triggerConditions;
|
||||
result = triggerCycleHelper.GetConditions(
|
||||
triggerCycleEvents,
|
||||
triggerPoiEvents,
|
||||
triggerConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Decision ...
|
||||
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
||||
X121SMCCycleConditions decisionConditions;
|
||||
result = decisionCycleHelper.GetConditions(
|
||||
decisionCycleEvents,
|
||||
decisionPoiEvents,
|
||||
decisionConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Analyse ...
|
||||
ENUM_XPOI_EVENTS analysePoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
||||
X121SMCCycleConditions analyseConditions;
|
||||
result = analyseCycleHelper.GetConditions(
|
||||
analyseCycleEvents,
|
||||
analysePoiEvents,
|
||||
analyseConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Verification ...
|
||||
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
||||
X121SMCCycleConditions verificationConditions;
|
||||
result = verificationCycleHelper.GetConditions(
|
||||
verificationCycleEvents,
|
||||
verificationPoiEvents,
|
||||
verificationConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Consolidation ...
|
||||
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
||||
X121SMCCycleConditions consolidationConditions;
|
||||
result = consolidationCycleHelper.GetConditions(
|
||||
consolidationCycleEvents,
|
||||
consolidationPoiEvents,
|
||||
consolidationConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Vision ...
|
||||
ENUM_XPOI_EVENTS visionPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
||||
X121SMCCycleConditions visionConditions;
|
||||
result = visionCycleHelper.GetConditions(
|
||||
visionCycleEvents,
|
||||
visionPoiEvents,
|
||||
visionConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Cycles POI States ...
|
||||
XPOIState triggerState = triggerConditions.state;
|
||||
XPOIState decisionState = decisionConditions.state;
|
||||
XPOIState analyseState = analyseConditions.state;
|
||||
XPOIState verificationState = verificationConditions.state;
|
||||
XPOIState consolidationState = consolidationConditions.state;
|
||||
XPOIState visionState = visionConditions.state;
|
||||
|
||||
//
|
||||
result = false;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Tools Functions ...
|
||||
|
||||
//
|
||||
@@ -0,0 +1,279 @@
|
||||
<mxfile host="65bd71144e">
|
||||
<diagram id="QReEEfusIJtThQdlE9lK" name="Page-1">
|
||||
<mxGraphModel dx="1382" dy="987" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0"/>
|
||||
<mxCell id="1" parent="0"/>
|
||||
<mxCell id="15" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="2" target="3">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="420" y="100"/>
|
||||
<mxPoint x="100" y="100"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="16" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="2" target="6">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="420" y="100"/>
|
||||
<mxPoint x="780" y="100"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="2" value="Position" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="360" y="40" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="17" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="3" target="4">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="100" y="340"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="18" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="3" target="5">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="100" y="620"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="3" value="States" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="40" y="120" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="27" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="4" target="25">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="180" y="420"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="28" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="4" target="26">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="180" y="500"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="4" value="InDrawdown" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="120" y="320" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="29" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="5" target="23">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="180" y="700"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="30" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="5" target="24">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="180" y="780"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="5" value="InProfit" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="120" y="600" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="19" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="6" target="8">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="780" y="220"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="20" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="6" target="9">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="780" y="300"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="21" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="6" target="11">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="780" y="380"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="22" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="6" target="10">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="780" y="460"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="6" value="Events" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="720" y="120" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="31" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="8" target="25">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="260" y="220"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="38" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="8" target="26">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="520" y="220"/>
|
||||
<mxPoint x="520" y="560"/>
|
||||
<mxPoint x="260" y="560"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="39" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="8" target="23">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="560" y="220"/>
|
||||
<mxPoint x="560" y="640"/>
|
||||
<mxPoint x="260" y="640"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="43" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="8" target="24">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="560" y="220"/>
|
||||
<mxPoint x="560" y="840"/>
|
||||
<mxPoint x="260" y="840"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="8" value="Bullish Sign" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="640" y="200" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="32" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="9" target="25">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="260" y="300"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="37" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="9" target="26">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="520" y="300"/>
|
||||
<mxPoint x="520" y="560"/>
|
||||
<mxPoint x="260" y="560"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="40" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="9" target="23">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="560" y="300"/>
|
||||
<mxPoint x="560" y="640"/>
|
||||
<mxPoint x="260" y="640"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="44" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="9" target="24">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="560" y="300"/>
|
||||
<mxPoint x="560" y="840"/>
|
||||
<mxPoint x="260" y="840"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="9" value="Bearish Sign" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="640" y="280" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="34" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;" edge="1" parent="1" source="10">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="260" y="400" as="targetPoint"/>
|
||||
<Array as="points">
|
||||
<mxPoint x="520" y="460"/>
|
||||
<mxPoint x="520" y="360"/>
|
||||
<mxPoint x="260" y="360"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="35" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="10" target="26">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="520" y="460"/>
|
||||
<mxPoint x="520" y="560"/>
|
||||
<mxPoint x="260" y="560"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="42" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;" edge="1" parent="1" source="10">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="260" y="680" as="targetPoint"/>
|
||||
<Array as="points">
|
||||
<mxPoint x="560" y="460"/>
|
||||
<mxPoint x="560" y="640"/>
|
||||
<mxPoint x="260" y="640"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="46" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="10" target="24">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="260" y="810" as="targetPoint"/>
|
||||
<Array as="points">
|
||||
<mxPoint x="560" y="460"/>
|
||||
<mxPoint x="560" y="840"/>
|
||||
<mxPoint x="260" y="840"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="10" value="Bearish Pushed Tick" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="640" y="440" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="33" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="11" target="25">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="520" y="380"/>
|
||||
<mxPoint x="520" y="360"/>
|
||||
<mxPoint x="260" y="360"/>
|
||||
<mxPoint x="260" y="380"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="36" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="11" target="26">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="520" y="380"/>
|
||||
<mxPoint x="520" y="560"/>
|
||||
<mxPoint x="260" y="560"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="41" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="11" target="23">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="560" y="380"/>
|
||||
<mxPoint x="560" y="640"/>
|
||||
<mxPoint x="260" y="640"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="45" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="11" target="24">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="560" y="380"/>
|
||||
<mxPoint x="560" y="840"/>
|
||||
<mxPoint x="260" y="840"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="11" value="Bullish Pushed Tick" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="640" y="360" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="23" value="Long" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="200" y="680" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="24" value="Short" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="200" y="760" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="25" value="Long" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="200" y="400" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="26" value="Short" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="200" y="480" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
||||
@@ -0,0 +1,506 @@
|
||||
/**
|
||||
* XColor Tools Module ...
|
||||
* a module for handle colorify text contents in node js ...
|
||||
*
|
||||
* Maintainer
|
||||
*
|
||||
* Hadi Khazaee Asl <https://saherelm.ir> (hadi_khazaee_asl@yahoo.com)
|
||||
*/
|
||||
|
||||
//
|
||||
//#region Module Imports ...
|
||||
const XValueTools = require("./x-value.tools");
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Constants ...
|
||||
/**
|
||||
* these are available style which can applied to an string ...
|
||||
*/
|
||||
const AVAILABLE_STYLES = {
|
||||
//
|
||||
Bold: "\x1b[1m",
|
||||
Dim: "\x1b[2m",
|
||||
Underlined: "\x1b[4m",
|
||||
Blink: "\x1b[5m",
|
||||
ReverseFandB: "\x1b[7m",
|
||||
Hidden: "\x1b[8m",
|
||||
//
|
||||
// Commonly used for reset all Styles ...
|
||||
Reset: "\x1b[0m"
|
||||
};
|
||||
|
||||
/**
|
||||
* these are available foreground colors which can applied to an string ...
|
||||
*/
|
||||
const AVAILABLE_FOREGROUND_COLORS = {
|
||||
Default: "\x1b[39m",
|
||||
Black: "\x1b[30m",
|
||||
Red: "\x1b[31m",
|
||||
Green: "\x1b[32m",
|
||||
Yellow: "\x1b[33m",
|
||||
Blue: "\x1b[34m",
|
||||
Magenta: "\x1b[35m",
|
||||
Cyan: "\x1b[36m",
|
||||
LightGray: "\x1b[37m",
|
||||
DarkGray: "\x1b[90m",
|
||||
LightRed: "\x1b[91m",
|
||||
LightGreen: "\x1b[92m",
|
||||
LightYellow: "\x1b[93m",
|
||||
LightBlue: "\x1b[94m",
|
||||
LightMagenta: "\x1b[95m",
|
||||
LightCyan: "\x1b[96m",
|
||||
White: "\x1b[97m",
|
||||
};
|
||||
|
||||
/**
|
||||
* these are available background colors which can applied to an string ...
|
||||
*/
|
||||
const AVAILABLE_BACKGROUND_COLORS = {
|
||||
Default: "\x1b[49m",
|
||||
Black: "\x1b[40m",
|
||||
Red: "\x1b[41m",
|
||||
Green: "\x1b[42m",
|
||||
Yellow: "\x1b[43m",
|
||||
Blue: "\x1b[44m",
|
||||
Magenta: "\x1b[45m",
|
||||
Cyan: "\x1b[46m",
|
||||
LightGray: "\x1b[47m",
|
||||
DarkGray: "\x1b[100m",
|
||||
LightRed: "\x1b[101m",
|
||||
LightGreen: "\x1b[102m",
|
||||
LightYellow: "\x1b[103m",
|
||||
LightBlue: "\x1b[104m",
|
||||
LightMagenta: "\x1b[105m",
|
||||
LightCyan: "\x1b[106m",
|
||||
White: "\x1b[107m",
|
||||
};
|
||||
|
||||
/**
|
||||
* these are available style names, which exports from module and
|
||||
* users can use them ...
|
||||
*/
|
||||
const STYLE_NAMES = {
|
||||
Bold: "Bold",
|
||||
Dim: "Dim",
|
||||
Underlined: "Underlined",
|
||||
Blink: "Blink",
|
||||
ReverseFandB: "ReverseFandB",
|
||||
Hidden: "Hidden",
|
||||
Reset: "Reset",
|
||||
};
|
||||
|
||||
/**
|
||||
* these are available color names, which exports from module and
|
||||
* users can use them ...
|
||||
*/
|
||||
const COLOR_NAMES = {
|
||||
Default: "Default",
|
||||
Black: "Black",
|
||||
Red: "Red",
|
||||
Green: "Green",
|
||||
Yellow: "Yellow",
|
||||
Blue: "Blue",
|
||||
Magenta: "Magenta",
|
||||
Cyan: "Cyan",
|
||||
LightGray: "LightGray",
|
||||
DarkGray: "DarkGray",
|
||||
LightRed: "LightRed",
|
||||
LightGreen: "LightGreen",
|
||||
LightYellow: "LightYellow",
|
||||
LightBlue: "LightBlue",
|
||||
LightMagenta: "LightMagenta",
|
||||
LightCyan: "LightCyan",
|
||||
White: "White",
|
||||
};
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Actions ...
|
||||
/**
|
||||
* apply specified style and color on a content ...
|
||||
*
|
||||
* @param {string} content specified content for styling ...
|
||||
* @param {string} color specific color name for using to styling ...
|
||||
* @param {string} style soecufic style name to use ...
|
||||
* @param {boolean} toForeground apply specified color as foreground ...
|
||||
* @param {boolean} toBackground apply specified color as background ...
|
||||
* @returns {string} styled content ...
|
||||
*/
|
||||
function apply(
|
||||
content,
|
||||
color,
|
||||
style,
|
||||
toForeground = true,
|
||||
toBackground = false
|
||||
) {
|
||||
//
|
||||
let result = content;
|
||||
|
||||
//
|
||||
// Validate Arg ...
|
||||
if (!XValueTools.isValidArg(content)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect and Validate Style and Apply it ...
|
||||
let eStyle = AVAILABLE_STYLES[style];
|
||||
if (XValueTools.isValidArg(eStyle)) {
|
||||
result = `${eStyle}${result}${AVAILABLE_STYLES.Reset}`;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect and Validate Foreground Color and Apply it ...
|
||||
let eFColor = AVAILABLE_FOREGROUND_COLORS[color];
|
||||
if (
|
||||
!!toForeground
|
||||
&& XValueTools.isValidArg(eFColor)
|
||||
) {
|
||||
result = `${eFColor}${result}${AVAILABLE_STYLES.Reset}`;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect and Validate Background Color and Apply it ...
|
||||
let eBColor = AVAILABLE_BACKGROUND_COLORS[color];
|
||||
if (
|
||||
!!toBackground
|
||||
&& XValueTools.isValidArg(eBColor)
|
||||
) {
|
||||
result = `${eBColor}${result}${AVAILABLE_STYLES.Reset}`;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* apply specific style on a content ...
|
||||
*
|
||||
* @param {string} content specific content which going to styled ...
|
||||
* @param {string} style a member of STYLE_NAMES which specified that which style going to applied to content ...
|
||||
* @returns {string} styled content ...
|
||||
*/
|
||||
function applyStyle(content, style) {
|
||||
//
|
||||
// Validate Arg ...
|
||||
if (!XValueTools.isValidArg(content)) {
|
||||
return content;
|
||||
}
|
||||
|
||||
//
|
||||
let eStyle = AVAILABLE_STYLES[style];
|
||||
if (eStyle === undefined) {
|
||||
return content;
|
||||
}
|
||||
|
||||
//
|
||||
return `${eStyle}${content}${AVAILABLE_STYLES.Reset}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* apply specific foreground color on a content ...
|
||||
*
|
||||
* @param {string} content specific content which going to colorified ...
|
||||
* @param {string} color a member of COLOR_NAMES which specified that which color going to applied to content ...
|
||||
* @returns {string} colorified content ...
|
||||
*/
|
||||
function applyForegroundColor(content, color) {
|
||||
//
|
||||
// Validate Arg ...
|
||||
if (!XValueTools.isValidArg(content)) {
|
||||
return content;
|
||||
}
|
||||
|
||||
//
|
||||
let eColor = AVAILABLE_FOREGROUND_COLORS[color];
|
||||
if (eColor === undefined) {
|
||||
return content;
|
||||
}
|
||||
|
||||
//
|
||||
return `${eColor}${content}${AVAILABLE_STYLES.Reset}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* apply specific background color on a content ...
|
||||
*
|
||||
* @param {string} content specific content which going to colorified ...
|
||||
* @param {string} color a member of COLOR_NAMES which specified that which color going to applied to content ...
|
||||
* @returns {string} colorified content ...
|
||||
*/
|
||||
function applyBackgroundColor(content, color) {
|
||||
//
|
||||
// Validate Arg ...
|
||||
if (!XValueTools.isValidArg(content)) {
|
||||
return content;
|
||||
}
|
||||
|
||||
//
|
||||
let eColor = AVAILABLE_BACKGROUND_COLORS[color];
|
||||
if (eColor === undefined) {
|
||||
return content;
|
||||
}
|
||||
|
||||
//
|
||||
return `${eColor}${content}${AVAILABLE_STYLES.Reset}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate style and color applier expression ...
|
||||
*
|
||||
* @param {string} color specific color name for using to styling ...
|
||||
* @param {string} style soecufic style name to use ...
|
||||
* @param {boolean} reset close applier string by reset styles ...
|
||||
* @param {boolean} toForeground apply specified color as foreground ...
|
||||
* @param {boolean} toBackground apply specified color as background ...
|
||||
* @returns {string} style and color applier string ...
|
||||
*/
|
||||
function getApplier(
|
||||
style = "",
|
||||
color = "",
|
||||
reset = false,
|
||||
toForeground = true,
|
||||
toBackground = false
|
||||
) {
|
||||
//
|
||||
let result = "";
|
||||
|
||||
//
|
||||
// Detect and Validate Style and Apply it ...
|
||||
let eStyle = AVAILABLE_STYLES[style];
|
||||
if (XValueTools.isValidArg(eStyle)) {
|
||||
result = `${eStyle}`;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect and Validate Foreground Color and Apply it ...
|
||||
let eFColor = AVAILABLE_FOREGROUND_COLORS[color];
|
||||
if (
|
||||
!!toForeground
|
||||
&& XValueTools.isValidArg(eFColor)
|
||||
) {
|
||||
result = `${eFColor}`;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect and Validate Background Color and Apply it ...
|
||||
let eBColor = AVAILABLE_BACKGROUND_COLORS[color];
|
||||
if (
|
||||
!!toBackground
|
||||
&& XValueTools.isValidArg(eBColor)
|
||||
) {
|
||||
result = `${eBColor}`;
|
||||
}
|
||||
|
||||
//
|
||||
if (
|
||||
!!reset &&
|
||||
result.length > 0
|
||||
) {
|
||||
result = `${result}${AVAILABLE_STYLES.Reset}`;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate style applier expression ...
|
||||
*
|
||||
* @param {string} style soecufic style name to use ...
|
||||
* @param {boolean} reset close applier string by reset styles ...
|
||||
* @returns {string} style applier string ...
|
||||
*/
|
||||
function getStyleApplier(
|
||||
style = "",
|
||||
reset = false
|
||||
) {
|
||||
//
|
||||
let result = "";
|
||||
|
||||
//
|
||||
// Detect and Validate Style and Apply it ...
|
||||
let eStyle = AVAILABLE_STYLES[style];
|
||||
if (XValueTools.isValidArg(eStyle)) {
|
||||
result = `${eStyle}`;
|
||||
}
|
||||
|
||||
//
|
||||
if (
|
||||
!!reset &&
|
||||
result.length > 0
|
||||
) {
|
||||
result = `${result}${AVAILABLE_STYLES.Reset}`;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate color applier expression ...
|
||||
*
|
||||
* @param {string} color specific color name for using to styling ...
|
||||
* @param {boolean} reset close applier string by reset styles ...
|
||||
* @param {boolean} toForeground apply specified color as foreground ...
|
||||
* @param {boolean} toBackground apply specified color as background ...
|
||||
* @returns {string} color applier string ...
|
||||
*/
|
||||
function getColorApplier(
|
||||
color = "",
|
||||
reset = false,
|
||||
toForeground = true,
|
||||
toBackground = false
|
||||
) {
|
||||
//
|
||||
let result = "";
|
||||
|
||||
//
|
||||
// Detect and Validate Foreground Color and Apply it ...
|
||||
let eFColor = AVAILABLE_FOREGROUND_COLORS[color];
|
||||
if (
|
||||
!!toForeground
|
||||
&& XValueTools.isValidArg(eFColor)
|
||||
) {
|
||||
result = `${eFColor}`;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect and Validate Background Color and Apply it ...
|
||||
let eBColor = AVAILABLE_BACKGROUND_COLORS[color];
|
||||
if (
|
||||
!!toBackground
|
||||
&& XValueTools.isValidArg(eBColor)
|
||||
) {
|
||||
result = `${eBColor}`;
|
||||
}
|
||||
|
||||
//
|
||||
if (
|
||||
!!reset &&
|
||||
result.length > 0
|
||||
) {
|
||||
result = `${result}${AVAILABLE_STYLES.Reset}`;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* colorified specific content ...
|
||||
*
|
||||
* @param {string} content specified content for styling ...
|
||||
* @param {string} color specific color name for using to styling ...
|
||||
* @param {boolean} toForeground apply specified color as foreground ...
|
||||
* @param {boolean} toBackground apply specified color as background ...
|
||||
* @returns {string}
|
||||
*/
|
||||
function colorifyContent(
|
||||
content = "",
|
||||
color = "",
|
||||
toForeground = true,
|
||||
toBackground = false
|
||||
) {
|
||||
//
|
||||
let result = content;
|
||||
|
||||
//
|
||||
if (!XValueTools.isValidArg(content)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Finde Colors ...
|
||||
|
||||
//
|
||||
// Detect and Validate Foreground Color and Apply it ...
|
||||
let eFColor = AVAILABLE_FOREGROUND_COLORS[color];
|
||||
if (
|
||||
!!toForeground
|
||||
&& XValueTools.isValidArg(eFColor)
|
||||
) {
|
||||
result = `${eFColor}${result}`;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect and Validate Background Color and Apply it ...
|
||||
let eBColor = AVAILABLE_BACKGROUND_COLORS[color];
|
||||
if (
|
||||
!!toBackground
|
||||
&& XValueTools.isValidArg(eBColor)
|
||||
) {
|
||||
result = `${eBColor}${result}`;
|
||||
}
|
||||
|
||||
//
|
||||
if (
|
||||
result.length > 0
|
||||
&& (
|
||||
XValueTools.isValidArg(eFColor) ||
|
||||
XValueTools.isValidArg(eBColor)
|
||||
)
|
||||
) {
|
||||
result = `${result}${AVAILABLE_STYLES.Reset}`;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* apply style on specific content ...
|
||||
*
|
||||
* @param {string} content specified content for styling ...
|
||||
* @param {string} style soecufic style name to use ...
|
||||
* @returns {string}
|
||||
*/
|
||||
function stylifiyContent(
|
||||
content = "",
|
||||
style = "",
|
||||
) {
|
||||
//
|
||||
let result = content;
|
||||
|
||||
//
|
||||
if (!XValueTools.isValidArg(content)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect and Validate Style and Apply it ...
|
||||
let eStyle = AVAILABLE_STYLES[style];
|
||||
if (XValueTools.isValidArg(eStyle)) {
|
||||
result = `${eStyle}${result}`;
|
||||
}
|
||||
|
||||
//
|
||||
if (
|
||||
result.length > 0
|
||||
&& XValueTools.isValidArg(eStyle)
|
||||
) {
|
||||
result = `${result}${AVAILABLE_STYLES.Reset}`;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Module Exports ...
|
||||
module.exports = {
|
||||
//
|
||||
STYLE_NAMES,
|
||||
COLOR_NAMES,
|
||||
//
|
||||
apply,
|
||||
applyStyle,
|
||||
getApplier,
|
||||
getColorApplier,
|
||||
getStyleApplier,
|
||||
colorifyContent,
|
||||
stylifiyContent,
|
||||
applyForegroundColor,
|
||||
applyBackgroundColor,
|
||||
}
|
||||
//#endregion
|
||||
@@ -0,0 +1,887 @@
|
||||
/**
|
||||
* XFile Tools Module ...
|
||||
* a module for handle all file/folder manipulating task in node js ...
|
||||
*
|
||||
* Maintainer
|
||||
*
|
||||
* Hadi Khazaee Asl <https://saherelm.ir> (hadi_khazaee_asl@yahoo.com)
|
||||
*/
|
||||
|
||||
//
|
||||
//#region Module Imports ...
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const Path = require('path');
|
||||
const http = require('http');
|
||||
const https = require('https');
|
||||
const XValueTools = require('./x-value.tools');
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Constants ...
|
||||
/**
|
||||
* current os path separators ...
|
||||
*/
|
||||
const PathSeparator = Path.sep;
|
||||
|
||||
/**
|
||||
* current directory ...
|
||||
*/
|
||||
const CurrentDir = __dirname;
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Actions ...
|
||||
//
|
||||
//#region Global ...
|
||||
/**
|
||||
* retrieve a path status ...
|
||||
*
|
||||
* @param {string} path a path value to check ...
|
||||
* @returns an stat object ...
|
||||
*/
|
||||
function getStatus(path = '') {
|
||||
//
|
||||
if (!XValueTools.isValidArg(path)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
//
|
||||
return fs.statSync(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve user's Home path ...
|
||||
*
|
||||
* @returns {string} a path ...
|
||||
*/
|
||||
function getHomePath() {
|
||||
return os.homedir();
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Path ...
|
||||
/**
|
||||
* retrieve the base name of specific address path ...
|
||||
*
|
||||
* @param {string} path address of file or folder ...
|
||||
* @returns string ...
|
||||
*/
|
||||
function basename(path = '') {
|
||||
//
|
||||
if (!XValueTools.isValidArg(path)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
//
|
||||
const result = Path.basename(path);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* join several path segments together ...
|
||||
*
|
||||
* @param {...string} path path params ...
|
||||
* @returns a joined paths ...
|
||||
*/
|
||||
function joinPath(...path) {
|
||||
return Path.join(...path);
|
||||
}
|
||||
|
||||
/**
|
||||
* resolve a relative path to absolute ...
|
||||
*
|
||||
* @param {string[]} path a path value to check ...
|
||||
* @returns {string}
|
||||
*/
|
||||
function resolvePath(...path) {
|
||||
return Path.resolve(...path);
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region File ...
|
||||
/**
|
||||
* determines a path destination is a file or not ...
|
||||
*
|
||||
* @param {string} path a path value to check ...
|
||||
* @returns a boolean value ...
|
||||
*/
|
||||
function isFileExists(path = '') {
|
||||
//
|
||||
if (!XValueTools.isValidArg(path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
try {
|
||||
const stat = getStatus(path);
|
||||
if (!stat) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
return stat.isFile();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* remove a file ...
|
||||
*
|
||||
* @param {string} path a file path ...
|
||||
* @returns {Promise<boolean>} action done or not ...
|
||||
*/
|
||||
function removeFile(path = '') {
|
||||
return new Promise((resolve) => {
|
||||
//
|
||||
if (!isFileExists(path)) {
|
||||
resolve(false);
|
||||
}
|
||||
|
||||
//
|
||||
fs.unlink(path, (err) => {
|
||||
//
|
||||
if (err) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* copy a file to destination path ...
|
||||
*
|
||||
* @param {string} source source file path ...
|
||||
* @param {string} dest dest folder path ...
|
||||
* @returns {Promise<boolean>} action done or not ...
|
||||
*/
|
||||
function copyFile(
|
||||
source = '',
|
||||
dest = ''
|
||||
) {
|
||||
return new Promise((resolve) => {
|
||||
//
|
||||
if (
|
||||
!isFileExists(source) ||
|
||||
!isDirectoryExists(dest)
|
||||
) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
const destFilePath = Path.join(dest, Path.basename(source));
|
||||
fs.copyFile(source, destFilePath, (err) => {
|
||||
//
|
||||
if (err) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* reading specified file content ...
|
||||
*
|
||||
* @param {string} path a file path ...
|
||||
* @returns {Promise<string>} file content ...
|
||||
*/
|
||||
function readFile(path = '') {
|
||||
return new Promise((resolve) => {
|
||||
//
|
||||
if (!isFileExists(path)) {
|
||||
resolve('');
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
fs.readFile(path, 'utf8', (err, content) => {
|
||||
//
|
||||
if (err) {
|
||||
resolve(undefined);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
resolve(content);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* write content to a file ...
|
||||
*
|
||||
* @param {string} path a file path ...
|
||||
* @param {string} content the content which going to write to the file ...
|
||||
* @param {bool} overwrite determines file overwrite if exists ...
|
||||
* @returns {Promise<boolean>} action done or not ...
|
||||
*/
|
||||
function writeFile(
|
||||
path = '',
|
||||
content = '',
|
||||
overwrite = true
|
||||
) {
|
||||
return new Promise((resolve) => {
|
||||
//
|
||||
if (isFileExists(path) && !overwrite) {
|
||||
//
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Normalize Content ...
|
||||
content = XValueTools.isValidArg(content) ?
|
||||
content :
|
||||
'';
|
||||
|
||||
//
|
||||
fs.writeFile(path, content, (err) => {
|
||||
//
|
||||
if (err) {
|
||||
//
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* create a file ...
|
||||
*
|
||||
* @param {string} path file path ...
|
||||
* @param {string} fileName file name ...
|
||||
* @returns {Promise<boolean>} action done or not ...
|
||||
*/
|
||||
function createFile(
|
||||
path = '',
|
||||
fileName = ''
|
||||
) {
|
||||
return new Promise((resolve) => {
|
||||
//
|
||||
const filePath = Path.join(path, fileName);
|
||||
if (
|
||||
isFileExists(filePath) ||
|
||||
!XValueTools.isValidArg(path) ||
|
||||
!XValueTools.isValidArg(fileName)
|
||||
) {
|
||||
//
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
fs.writeFile(filePath, '', (err) => {
|
||||
//
|
||||
if (err) {
|
||||
//
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* remove a file name extension ...
|
||||
*
|
||||
* @param {string} name
|
||||
* @returns {string} name without extension ...
|
||||
*/
|
||||
function removeFileExtension(name = '') {
|
||||
return name.substring(0, name.lastIndexOf('.')) || name;
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve a file extension ...
|
||||
*
|
||||
* @param {string} path a path which locate a file ...
|
||||
* @returns {string}
|
||||
*/
|
||||
function getFileExtension(path = '') {
|
||||
//
|
||||
let result = "";
|
||||
|
||||
//
|
||||
// Validate Arg ...
|
||||
if (
|
||||
!XValueTools.isValidArg(path)
|
||||
|| !isFileExists(path)
|
||||
) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve just file name ...
|
||||
const fileName = basename(path);
|
||||
result = fileName.replace(
|
||||
removeFileExtension(fileName),
|
||||
""
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve all files list recursively from specific path ...
|
||||
*
|
||||
* @param {string} path a source folder path ...
|
||||
* @param {string[]} extensions which file extensions need to be listed, live empty for all files ...
|
||||
* @returns {Promise<string[]>}
|
||||
*/
|
||||
async function getRecursiveFilesList(
|
||||
path = "",
|
||||
extensions = []
|
||||
) {
|
||||
//
|
||||
let result = [];
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
!XValueTools.isValidArg(path)
|
||||
|| !isDirectoryExists(path)
|
||||
) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
const contents = await getDirectoryContents(path);
|
||||
for (const item of contents) {
|
||||
//
|
||||
const itemPath = joinPath(
|
||||
path,
|
||||
item
|
||||
);
|
||||
|
||||
//
|
||||
const isItemFile = isFileExists(itemPath);
|
||||
if (isItemFile) {
|
||||
//
|
||||
const itemFileExtension = getFileExtension(itemPath);
|
||||
const isFileInSupportedExtensions =
|
||||
extensions === undefined || extensions.length === 0
|
||||
? true
|
||||
: extensions.includes(itemFileExtension)
|
||||
;
|
||||
if (isFileInSupportedExtensions) {
|
||||
result.push(itemPath);
|
||||
}
|
||||
} else if (isDirectoryExists(itemPath)) {
|
||||
//
|
||||
const itemPathFiles = await getRecursiveFilesList(itemPath, extensions);
|
||||
result.push(...itemPathFiles);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Specific files from a folder and it's content ...
|
||||
*
|
||||
* @param {string} path Folder Path ...
|
||||
* @returns
|
||||
*/
|
||||
async function extractFiles(path = "", ext = [], excludeWorkspaceFolders = []) {
|
||||
//
|
||||
const result = [];
|
||||
|
||||
//
|
||||
if (!ext || ext.length == 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
const pathContent = await getDirectoryContents(path);
|
||||
if (!pathContent || pathContent.length == 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop through Content ...
|
||||
for (const c of pathContent) {
|
||||
//
|
||||
// Prepare full path ...
|
||||
const cPath = joinPath(path, c);
|
||||
|
||||
//
|
||||
// check content path is file or not ...
|
||||
const isCFile = isFileExists(cPath);
|
||||
const isCDirectory = isDirectoryExists(cPath);
|
||||
if (isCFile) {
|
||||
//
|
||||
// Check it is MQL file or not ...
|
||||
const cExt = getFileExtension(cPath);
|
||||
if (ext.includes(cExt)) {
|
||||
result.push(cPath);
|
||||
}
|
||||
} else if (isCDirectory) {
|
||||
//
|
||||
const destFolderName = basename(cPath);
|
||||
const isExcluded = excludeWorkspaceFolders.includes(destFolderName);
|
||||
if (isExcluded) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
const cFiles = await extractFiles(cPath, ext);
|
||||
if (cFiles && cFiles.length > 0) {
|
||||
result.push(...cFiles);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Directory ...
|
||||
/**
|
||||
* create a directory ...
|
||||
*
|
||||
* @param {string} path destination path including dir name ...
|
||||
* @param {boolean} recursive create directories recursively ...
|
||||
* @returns action done or not ...
|
||||
*/
|
||||
function createDirectory(
|
||||
path = '',
|
||||
recursive = true
|
||||
) {
|
||||
//
|
||||
let result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
isDirectoryExists(path) ||
|
||||
!XValueTools.isValidArg(path)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
try {
|
||||
//
|
||||
fs.mkdirSync(path, { recursive: recursive });
|
||||
result = true;
|
||||
return result;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* remove a directory ...
|
||||
*
|
||||
* @param {string} path destination path including dir name ...
|
||||
* @param {boolean} recursive removes directories recursively ...
|
||||
* @returns {Promise<boolean>} action done or not ...
|
||||
*/
|
||||
function removeDirectory(
|
||||
path = '',
|
||||
recursive = false
|
||||
) {
|
||||
return new Promise((resolve) => {
|
||||
//
|
||||
if (!isDirectoryExists(path)) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
fs.rm(path, {
|
||||
recursive
|
||||
}, (err) => {
|
||||
//
|
||||
if (err) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* determines a path destination is a directory or not ...
|
||||
*
|
||||
* @param {string} path a folder path ...
|
||||
* @returns represent destnation path is Directory or not ...
|
||||
*/
|
||||
function isDirectoryExists(path = '') {
|
||||
//
|
||||
if (!XValueTools.isValidArg(path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
try {
|
||||
//
|
||||
const isExists = fs.existsSync(path);
|
||||
if (!isExists) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
const stat = getStatus(path);
|
||||
if (!stat) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
const result = stat.isDirectory();
|
||||
return result;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve a directory content ...
|
||||
*
|
||||
* @param {string} path a folder path ...
|
||||
* @returns {Promise<string[]>} a collection of folder files ...
|
||||
*/
|
||||
function getDirectoryContents(path = '') {
|
||||
return new Promise((resolve) => {
|
||||
//
|
||||
if (!isDirectoryExists(path)) {
|
||||
resolve([]);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
fs.readdir(path, (err, content) => {
|
||||
//
|
||||
if (err) {
|
||||
resolve([]);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
resolve(content);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve a directory files ...
|
||||
*
|
||||
* @param {string} path a folder path ...
|
||||
* @returns {Promise<string[]>} a collection of folder files ...
|
||||
*/
|
||||
function getDirectoryFiles(
|
||||
path = '',
|
||||
containsHiddenFiles = false
|
||||
) {
|
||||
return new Promise((resolve) => {
|
||||
//
|
||||
if (!isDirectoryExists(path)) {
|
||||
resolve([]);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
fs.readdir(path, (err, content) => {
|
||||
//
|
||||
if (err) {
|
||||
resolve([]);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
if (!containsHiddenFiles) {
|
||||
content = content.filter(c => !c.startsWith('.'));
|
||||
}
|
||||
|
||||
//
|
||||
const result = [];
|
||||
content
|
||||
.forEach(c => {
|
||||
//
|
||||
const cPath = Path.join(path, c);
|
||||
if (isFileExists(cPath)) {
|
||||
result.push(c);
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve a directory folders ...
|
||||
*
|
||||
* @param {string} path a folder path ...
|
||||
* @returns {Promise<string[]>} a collection of folder names ...
|
||||
*/
|
||||
function getDirectoryFolders(path = '') {
|
||||
return new Promise((resolve) => {
|
||||
//
|
||||
if (!isDirectoryExists(path)) {
|
||||
resolve([]);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
fs.readdir(path, (err, content) => {
|
||||
//
|
||||
if (err) {
|
||||
resolve([]);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
const result = [];
|
||||
content.forEach(c => {
|
||||
//
|
||||
const cPath = Path.join(path, c);
|
||||
if (isDirectoryExists(cPath)) {
|
||||
result.push(c);
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* copy a folder with all of it's content to dest ...
|
||||
*
|
||||
* @param {string} source source folder path ...
|
||||
* @param {string} dest dest folder path ...
|
||||
* @returns {Promise<boolean>} action done or not ...
|
||||
*/
|
||||
async function copyFolder(
|
||||
source = '',
|
||||
dest = ''
|
||||
) {
|
||||
//
|
||||
if (
|
||||
!isDirectoryExists(source) ||
|
||||
!XValueTools.isValidArg(dest) ||
|
||||
!XValueTools.isValidArg(source)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
const folderName = Path.basename(source);
|
||||
const destPath = Path.join(dest, folderName);
|
||||
|
||||
//
|
||||
// Create Dest Path folder if not exists ...
|
||||
if (!isDirectoryExists(destPath)) {
|
||||
//
|
||||
let result = createDirectory(destPath, true);
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Files ...
|
||||
const files = await getDirectoryFiles(source);
|
||||
if (files && files.constructor === Array && files.length > 0) {
|
||||
//
|
||||
const filesPromises = files.map(file => copyFile(Path.join(source, file), destPath));
|
||||
const filesResult = (await Promise.all(filesPromises)).every(r => !!r);
|
||||
if (!filesResult) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Folders ...
|
||||
const folders = await getDirectoryFolders(source);
|
||||
if (folders && folders.constructor === Array && folders.length > 0) {
|
||||
//
|
||||
const folderPromises = folders.map(folder => copyFolder(Path.join(source, folder), destPath));
|
||||
const filesResult = (await Promise.all(folderPromises)).every(r => !!r);
|
||||
if (!filesResult) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return true;
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Downloader ...
|
||||
/**
|
||||
* download a file from specific url and store it ...
|
||||
*
|
||||
* @param {string} filepath the file name and path which required to put download file on it ...
|
||||
* @param {string} url the web url for downloading ...
|
||||
*/
|
||||
function download(filepath, url) {
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
!XValueTools.isValidArg(url)
|
||||
|| !XValueTools.isValidURL(url)
|
||||
|| !XValueTools.isValidArg(filepath)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
var file = fs.createWriteStream(filepath);
|
||||
|
||||
//
|
||||
if (url.startsWith('https:')) {
|
||||
https.get(url, function (response) {
|
||||
response.pipe(file);
|
||||
});
|
||||
} else if (url.startsWith('http:')) {
|
||||
http.get(url, function (response) {
|
||||
response.pipe(file);
|
||||
});
|
||||
}
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region JSON ...
|
||||
/**
|
||||
* read and parse a JSON content from a file ...
|
||||
*
|
||||
* @param {string} path source file path ...
|
||||
* @returns {any}
|
||||
*/
|
||||
function readJSON(path = "") {
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!isFileExists(path)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
//
|
||||
let result = undefined;
|
||||
try {
|
||||
result = require(path);
|
||||
} catch {
|
||||
result = undefined;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* write a JSON Object content into a file ...
|
||||
*
|
||||
* @param {string} path dest file path ...
|
||||
* @param {any} content an object which required to write to file ...
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
async function writeJSON(
|
||||
path = "",
|
||||
content = undefined
|
||||
) {
|
||||
//
|
||||
let result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!XValueTools.isValidArg(path)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Normallize Content ...
|
||||
if (content === undefined) {
|
||||
content = {};
|
||||
}
|
||||
|
||||
//
|
||||
const contentString = XValueTools.beautifyJSON(content);
|
||||
|
||||
//
|
||||
result = await writeFile(
|
||||
path,
|
||||
contentString,
|
||||
true
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//#endregion
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Module Exports ...
|
||||
module.exports = {
|
||||
//
|
||||
CurrentDir,
|
||||
PathSeparator,
|
||||
|
||||
//
|
||||
getStatus,
|
||||
getHomePath,
|
||||
|
||||
//
|
||||
basename,
|
||||
joinPath,
|
||||
resolvePath,
|
||||
|
||||
//
|
||||
download,
|
||||
|
||||
//
|
||||
readJSON,
|
||||
writeJSON,
|
||||
|
||||
//
|
||||
copyFile,
|
||||
readFile,
|
||||
writeFile,
|
||||
createFile,
|
||||
removeFile,
|
||||
isFileExists,
|
||||
getFileExtension,
|
||||
removeFileExtension,
|
||||
getRecursiveFilesList,
|
||||
extractFiles,
|
||||
|
||||
//
|
||||
copyFolder,
|
||||
createDirectory,
|
||||
removeDirectory,
|
||||
isDirectoryExists,
|
||||
getDirectoryFiles,
|
||||
getDirectoryFolders,
|
||||
getDirectoryContents,
|
||||
};
|
||||
//#endregion
|
||||
@@ -0,0 +1,219 @@
|
||||
/**
|
||||
* XShell Tools Module ...
|
||||
* a module for handling shell actions and retrieve OS Info in node js ...
|
||||
*
|
||||
* Maintainer
|
||||
*
|
||||
* Hadi Khazaee Asl <https://saherelm.ir> (hadi_khazaee_asl@yahoo.com)
|
||||
*/
|
||||
|
||||
//
|
||||
//#region Imports ...
|
||||
const os = require('os');
|
||||
const process = require('process');
|
||||
const { exec } = require("child_process");
|
||||
const XFileTools = require('./x-file.tools');
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Constants ...
|
||||
//
|
||||
const OS = {
|
||||
Aix: 'aix',
|
||||
Darwin: 'darwin',
|
||||
FreeBSD: 'freebsd',
|
||||
Linux: 'linux',
|
||||
OpenBSD: 'openbsd',
|
||||
SnOS: 'sunos',
|
||||
Windows: 'win32'
|
||||
};
|
||||
|
||||
//
|
||||
const isWindows = process.platform === OS.Windows;
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Actions ...
|
||||
//
|
||||
//#region Pure shell commands ...
|
||||
/**
|
||||
* execute a command using NodeJS on shell ...
|
||||
*
|
||||
* @param {string} cmd command to execute ...
|
||||
* @param {string} cwd working directory ...
|
||||
*
|
||||
* @returns Promise<any, errr> instance ...
|
||||
*/
|
||||
function execute(cmd, cwd) {
|
||||
return new Promise((resolve, reject) => {
|
||||
//
|
||||
if (!cmd || cmd.toString().length === 0 || (cwd && !XFileTools.isDirectoryExists(cwd))) {
|
||||
reject('invalid args ...');
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
exec(cmd, { cwd }, (err, result, stdError) => {
|
||||
//
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
if (stdError) {
|
||||
//
|
||||
// reject(stdError);
|
||||
// return;
|
||||
}
|
||||
|
||||
//
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* determines a command exists on host or not ...
|
||||
*
|
||||
* @param {string} name specific command name ...
|
||||
*
|
||||
* @returns boolean Promise ...
|
||||
*/
|
||||
function checkCommandExists(name) {
|
||||
return new Promise(resolve => {
|
||||
//
|
||||
if (!name) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
const cmd = isWindows ? `${name} >nul 2>&1` : `type ${name} >/dev/null 2>&1`;
|
||||
execute(cmd).then(result => {
|
||||
resolve(true);
|
||||
})
|
||||
.catch(err => {
|
||||
resolve(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region required commands state ...
|
||||
/**
|
||||
* check al required commands exists or not ...
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
async function isRequiredCommandsExists() {
|
||||
//
|
||||
let result = false;
|
||||
|
||||
//
|
||||
// const isTarExists = await isTarCommandExists();
|
||||
// const isCatExists = await isCatCommandExists();
|
||||
// const isGrepExists = await isGrepCommandExists();
|
||||
// const isSedExists = await isSedCommandExists();
|
||||
const isNpmExists = await isNpmCommandExists();
|
||||
const isNgExists = await isNgCommandExists();
|
||||
const isIonicExists = await isIonicCommandExists();
|
||||
const isCordovaExists = await isCordovaCommandExists();
|
||||
|
||||
//
|
||||
result = isNpmExists
|
||||
&& isNgExists
|
||||
&& isIonicExists
|
||||
&& isCordovaExists
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve required commands state object ...
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
async function getRequiredCommandsStates() {
|
||||
//
|
||||
const result = {};
|
||||
|
||||
//
|
||||
// const isTarExists = await isTarCommandExists();
|
||||
// const isCatExists = await isCatCommandExists();
|
||||
// const isGrepExists = await isGrepCommandExists();
|
||||
// const isSedExists = await isSedCommandExists();
|
||||
const isNpmExists = await isNpmCommandExists();
|
||||
const isNgExists = await isNgCommandExists();
|
||||
const isIonicExists = await isIonicCommandExists();
|
||||
const isCordovaExists = await isCordovaCommandExists();
|
||||
|
||||
//
|
||||
result['npm'] = isNpmExists;
|
||||
result['ng'] = isNgExists;
|
||||
result['ionic'] = isIonicExists;
|
||||
result['cordova'] = isCordovaExists;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Commonly used Command Checkers ...
|
||||
/**
|
||||
* determines npm command exists or not ...
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
function isNpmCommandExists() {
|
||||
return checkCommandExists('npm');
|
||||
}
|
||||
|
||||
/**
|
||||
* determines ng command exists or not ...
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
function isNgCommandExists() {
|
||||
return checkCommandExists('ng');
|
||||
}
|
||||
|
||||
/**
|
||||
* determines ionic command exists or not ...
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
function isIonicCommandExists() {
|
||||
return checkCommandExists('ionic');
|
||||
}
|
||||
|
||||
/**
|
||||
* determines cordova command exists or not ...
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
function isCordovaCommandExists() {
|
||||
return checkCommandExists('cordova');
|
||||
}
|
||||
//#endregion
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Module Exports ...
|
||||
module.exports = {
|
||||
//
|
||||
execute,
|
||||
checkCommandExists,
|
||||
isRequiredCommandsExists,
|
||||
getRequiredCommandsStates,
|
||||
|
||||
//
|
||||
isNgCommandExists,
|
||||
isIonicCommandExists,
|
||||
isCordovaCommandExists,
|
||||
}
|
||||
//#endregion
|
||||
@@ -0,0 +1,268 @@
|
||||
/**
|
||||
* DataType Tools Module ...
|
||||
* a module for manipulate and detect supported data types in node js ...
|
||||
*
|
||||
* Maintainer
|
||||
*
|
||||
* Hadi Khazaee Asl <https://saherelm.ir> (hadi_khazaee_asl@yahoo.com)
|
||||
*/
|
||||
|
||||
//
|
||||
//#region Constants ...
|
||||
/**
|
||||
* all supported data types ...
|
||||
*/
|
||||
const DataTypes = {
|
||||
Null: 'null',
|
||||
Date: 'date',
|
||||
Array: 'array',
|
||||
Object: 'object',
|
||||
String: 'string',
|
||||
Number: 'number',
|
||||
Unknown: 'unknown',
|
||||
Boolean: 'boolean',
|
||||
Function: 'function',
|
||||
Undefined: 'undefined',
|
||||
};
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Actions ...
|
||||
/**
|
||||
* detect type of a content ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function getType(value) {
|
||||
//
|
||||
const type = typeof value;
|
||||
|
||||
//
|
||||
let result = DataTypes.Unknown;
|
||||
let dateIdentifier = '[object Date]';
|
||||
let constructor = value && value.constructor ?
|
||||
value.constructor.toString() :
|
||||
'';
|
||||
|
||||
//
|
||||
switch (type) {
|
||||
//
|
||||
case 'undefined':
|
||||
result = DataTypes.Undefined;
|
||||
break;
|
||||
|
||||
//
|
||||
case 'boolean':
|
||||
result = DataTypes.Boolean;
|
||||
break;
|
||||
|
||||
//
|
||||
case 'string':
|
||||
result = DataTypes.String;
|
||||
break;
|
||||
|
||||
//
|
||||
case 'number':
|
||||
result = DataTypes.Number;
|
||||
break;
|
||||
|
||||
//
|
||||
case 'function':
|
||||
result = DataTypes.Function;
|
||||
break;
|
||||
|
||||
//
|
||||
case 'object':
|
||||
//
|
||||
// Null ...
|
||||
if (value === null) {
|
||||
result = DataTypes.Null;
|
||||
} else
|
||||
//
|
||||
// Array ...
|
||||
if (Array.isArray(value)) {
|
||||
result = DataTypes.Array;
|
||||
} else
|
||||
//
|
||||
// Data ...
|
||||
if (
|
||||
value instanceof Date ||
|
||||
isFunction(value.getMonth) ||
|
||||
constructor.includes(dateIdentifier) ||
|
||||
Object.prototype.toString.call(value) === dateIdentifier
|
||||
) {
|
||||
result = DataTypes.Date;
|
||||
} else
|
||||
//
|
||||
// Object ...
|
||||
{
|
||||
result = DataTypes.Object;
|
||||
}
|
||||
break;
|
||||
|
||||
//
|
||||
default:
|
||||
result = DataTypes.Unknown;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve an object constructor ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function getConstructor(value) {
|
||||
//
|
||||
const result = value && value.constructor ?
|
||||
value.constructor.toString() :
|
||||
'';
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve an object prototype ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function getPrototype(value) {
|
||||
//
|
||||
const result = value ?
|
||||
Object.prototype.toString.call(value) :
|
||||
'';
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* check an object is null or not ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function isNull(value) {
|
||||
return getType(value) === DataTypes.Null;
|
||||
}
|
||||
|
||||
/**
|
||||
* check an object is undefined or not ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function isUndefined(value) {
|
||||
return getType(value) === DataTypes.Undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* check an object is null or undefined or not ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function isNullOrUndefined(value) {
|
||||
return isNull(value) || isUndefined(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* check an object is a date or not ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function isDate(value) {
|
||||
return getType(value) === DataTypes.Date;
|
||||
}
|
||||
|
||||
/**
|
||||
* check an object is number or not ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function isNumber(value) {
|
||||
return getType(value) === DataTypes.Number;
|
||||
}
|
||||
|
||||
/**
|
||||
* check an object is string or not ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function isString(value) {
|
||||
return getType(value) === DataTypes.String;
|
||||
}
|
||||
|
||||
/**
|
||||
* check an object is boolean or not ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function isBoolean(value) {
|
||||
return getType(value) === DataTypes.Boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* check an object is an Array or not ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function isArray(value) {
|
||||
return getType(value) === DataTypes.Array;
|
||||
}
|
||||
|
||||
/**
|
||||
* check an object is and Object or not ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function isObject(value) {
|
||||
return getType(value) === DataTypes.Object;
|
||||
}
|
||||
|
||||
/**
|
||||
* check an object is a Function or not ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function isFunction(value) {
|
||||
return getType(value) === DataTypes.Function;
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Module Exports ...
|
||||
module.exports = {
|
||||
//
|
||||
DataTypes,
|
||||
|
||||
//
|
||||
getType,
|
||||
getConstructor,
|
||||
getPrototype,
|
||||
isNull,
|
||||
isUndefined,
|
||||
isNullOrUndefined,
|
||||
isDate,
|
||||
isNumber,
|
||||
isString,
|
||||
isBoolean,
|
||||
isArray,
|
||||
isObject,
|
||||
isFunction,
|
||||
}
|
||||
//#endregion
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,542 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XTest MQL5 Expert Advisor
|
||||
// -------------------------------------------------
|
||||
// Name: XEATemplate
|
||||
// Description: a Template For Exper Advisors
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////x
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XEATemplate"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "XEATemplate"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.xalert.class.mq5"
|
||||
#include "../Classes/x-saherelm.xtrade.class.mq5"
|
||||
#include "../Helpers/x-saherelm.xcc.helper.mq5"
|
||||
#include "../Helpers/x-saherelm.xct.helper.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Common ...
|
||||
input group "Common";
|
||||
input long eaMagicNumber = 78692110; // Magic Number
|
||||
input int eaSlippage = 10; // Slippgae
|
||||
input string eaLogSuffix = ""; // Log Suffix
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
// Here we Provider All Requirements for
|
||||
// Configuring Alert Provider ...
|
||||
input group "Alert";
|
||||
input bool eAEnableAlerts = true; // Enable Alerts
|
||||
input bool eALogAlerts = true; // Log Alerts
|
||||
input bool eAMailAlerts = false; // Mail Alerts
|
||||
input bool eAPushAlerts = false; // Push Alerts
|
||||
input bool eATerminalAlerts = false; // Terminal Alerts
|
||||
|
||||
//
|
||||
// Time Report ...
|
||||
input group "Reports";
|
||||
input bool eaReportNewMonths = false; // Report New Month
|
||||
input bool eaReportNewWeeks = false; // Report New Weeks
|
||||
input bool eaReportNewDays = false; // Report New Days
|
||||
input bool eaReportNewHours = false; // Report New Hours
|
||||
|
||||
//
|
||||
// Define Local Variables ...
|
||||
|
||||
//
|
||||
string eaLogTag; // EA Log Prefix ...
|
||||
XSCAlert *eaAlert; // Alert Provider for Expert Adviser ...
|
||||
XSCTrade *eaTrader; // Trader of Expert Adviser ...
|
||||
XTimeTracker eaTimeTracker; // Time Tracker for Providing Reports ...
|
||||
XSCXCTHelper *eaCHelper; // Bar Timer Indicator Helper class ...
|
||||
XSCXCCHelper *eaCCHelper; // Chart Styler Indicator Helper Class ...
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs and Required Parameters
|
||||
// for EA to Works fine ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Timer ...
|
||||
if (!InitTimer()) {
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize all Requirements ...
|
||||
if (!InitEA())
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize all GUI Objects and Classes ...
|
||||
if (!InitGUI())
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Alert Initialization ...
|
||||
string msg = "Initialized Successfully ...";
|
||||
eaAlert.Alert(msg);
|
||||
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// Destroy Timer ...
|
||||
DestroyTimer();
|
||||
|
||||
//
|
||||
// Destroy all GUI Requirements ...
|
||||
DestroyGUI();
|
||||
|
||||
//
|
||||
// Alert De Initialization Succeeded ...
|
||||
string msg = "De Initialized Successfully ...";
|
||||
eaAlert.Alert(msg);
|
||||
|
||||
//
|
||||
// Destroy all EA Requirements ...
|
||||
DestroyEA();
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
UpdateGUI();
|
||||
HandleReportTime();
|
||||
UpdatePositionsState();
|
||||
|
||||
//
|
||||
// TODO: Implemetn Tick Processors Algorithm ...
|
||||
}
|
||||
|
||||
//
|
||||
// Handle On Trade Event ...
|
||||
void OnTrade()
|
||||
{
|
||||
eaTrader.HandleOnTrade();
|
||||
}
|
||||
|
||||
//
|
||||
// On Timer ...
|
||||
void OnTimer()
|
||||
{
|
||||
//
|
||||
// TODO: Implement Time Based Functionalities ...
|
||||
}
|
||||
|
||||
//
|
||||
// Chart Event Handler ...
|
||||
void OnChartEvent(
|
||||
const int id,
|
||||
const long &lparam,
|
||||
const double &dparam,
|
||||
const string &sparam //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Handle OnClick Event ...
|
||||
if (id == CHARTEVENT_OBJECT_CLICK)
|
||||
{
|
||||
HandleOnClickEvent(sparam);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Event Handlers ...
|
||||
|
||||
/**
|
||||
* Handle StopLoss Triggered Positions ...
|
||||
*
|
||||
* @param deal: XDeal ...
|
||||
*/
|
||||
void OnStopLossTriggered(const XDeal &deal)
|
||||
{
|
||||
//
|
||||
HandleReportBalance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Take Profit Triggered Positions ...
|
||||
*
|
||||
* @param deal: XDeal ...
|
||||
*/
|
||||
void OnTakeProfitTriggered(const XDeal &deal)
|
||||
{
|
||||
//
|
||||
HandleReportBalance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Force Close a Position ...
|
||||
*
|
||||
* @param ticket: Position Ticket ...
|
||||
* @param position: XPosition ...
|
||||
* @param comment: Closing Comment ...
|
||||
*/
|
||||
void OnPositionForceClosed(
|
||||
const ulong ticket,
|
||||
const XPosition &position,
|
||||
const string comment //
|
||||
)
|
||||
{
|
||||
//
|
||||
HandleReportBalance();
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
/**
|
||||
* Validate all Inputs of Expert Adviser ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
string errMessage = "";
|
||||
|
||||
//
|
||||
bool isCommonValid = (
|
||||
//
|
||||
eaSlippage > 0 &&
|
||||
eaMagicNumber > 0
|
||||
//
|
||||
);
|
||||
if (!isCommonValid)
|
||||
{
|
||||
//
|
||||
errMessage += "common configurations error;" + "\n";
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
// Common ...
|
||||
isCommonValid &&
|
||||
//
|
||||
// Otere ...
|
||||
true
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
// Since here Logger not Initiallized, we Use Raw Print Command ...
|
||||
Print(ShortName + " Errors: \n", errMessage);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize Timer ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitTimer() {
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// TODO: Initialize Timer if necessary ...
|
||||
// result = EventSetTimer(1);
|
||||
// result = EventSetMillisecondTimer(100);
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Timer ...
|
||||
*/
|
||||
void DestroyTimer() {
|
||||
//
|
||||
// TODO: Use This ...
|
||||
// EventKillTimer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all Requirements for Working Fine ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitEA()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Locally Apply Changes on Prefix ...
|
||||
eaLogTag = ShortName + ">" + eaLogSuffix;
|
||||
|
||||
//
|
||||
// Bar Timer ...
|
||||
XCTInputs ctInputs;
|
||||
ctInputs.Default(); // Default Configurations ...
|
||||
eaCHelper = new XSCXCTHelper();
|
||||
result = eaCHelper.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
ctInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Bar Styles ...
|
||||
XCCInputs ccInputs;
|
||||
ccInputs.Default(); // Default Configurations ...
|
||||
eaCCHelper = new XSCXCCHelper();
|
||||
result = eaCCHelper.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
ccInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Create Instance of Alert Class and Configure it ...
|
||||
eaAlert = new XSCAlert();
|
||||
eaAlert.SetPrefix(eaLogTag);
|
||||
eaAlert.SetLogAlerts(eALogAlerts);
|
||||
eaAlert.SetMailAlerts(eAMailAlerts);
|
||||
eaAlert.SetPushAlerts(eAPushAlerts);
|
||||
eaAlert.SetEnableAlerts(eAEnableAlerts);
|
||||
eaAlert.SetTerminalAlerts(eATerminalAlerts);
|
||||
|
||||
//
|
||||
// Create Trader Instance and Configure it ...
|
||||
eaTrader = new XSCTrade(
|
||||
eaSlippage,
|
||||
eaMagicNumber //
|
||||
);
|
||||
eaTrader.AddOnStopLossEventHandler(OnStopLossTriggered);
|
||||
eaTrader.AddOnTakeProfitEventHandler(OnTakeProfitTriggered);
|
||||
eaTrader.AddOnForceClosePositionEventHandler(OnPositionForceClosed);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy all Initialized EA Requirements ...
|
||||
*/
|
||||
void DestroyEA()
|
||||
{
|
||||
//
|
||||
delete eaCHelper;
|
||||
delete eaCCHelper;
|
||||
|
||||
//
|
||||
delete eaAlert;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all GUI Requirements for EA ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitGUI()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// TODO: Fix This ...
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update GUI based on Each Ticks ...
|
||||
*/
|
||||
void UpdateGUI()
|
||||
{
|
||||
//
|
||||
// TODO: Implement this ...
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy all Initialized GUi Requirements ...
|
||||
*/
|
||||
void DestroyGUI()
|
||||
{
|
||||
//
|
||||
// TODO: Complete this ...
|
||||
}
|
||||
|
||||
//
|
||||
// Others ...
|
||||
|
||||
/**
|
||||
* Update Positions States ...
|
||||
*/
|
||||
void UpdatePositionsState()
|
||||
{
|
||||
//
|
||||
// TODO: Implement this ...
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle On Click Event for GUI Components ...
|
||||
*
|
||||
* @param name: Object Name ...
|
||||
*/
|
||||
void HandleOnClickEvent(string name)
|
||||
{
|
||||
//
|
||||
if (!IsValid(name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
bool isClicked = false;
|
||||
|
||||
//
|
||||
// TODO: Implement Chart Objects On Click ...
|
||||
|
||||
//
|
||||
if (isClicked)
|
||||
{
|
||||
UpdateGUI();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Report Account Balance ...
|
||||
*/
|
||||
void HandleReportBalance()
|
||||
{
|
||||
//
|
||||
if (!IsRunningOnTestMode())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
string msg = "Balance: " + ToString(eaTrader.mAccount.GetBalance());
|
||||
eaAlert.Log(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Time Reporting based on Inputs ...
|
||||
*/
|
||||
void HandleReportTime()
|
||||
{
|
||||
//
|
||||
// Monthly Report ....
|
||||
if (eaReportNewMonths &&
|
||||
eaTimeTracker.IsNewMonth())
|
||||
{
|
||||
//
|
||||
string msg = "New Month ...";
|
||||
|
||||
//
|
||||
eaAlert.Alert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Weekly Report ....
|
||||
if (eaReportNewWeeks &&
|
||||
eaTimeTracker.IsNewWeek())
|
||||
{
|
||||
//
|
||||
string msg = "New Week ...";
|
||||
|
||||
//
|
||||
eaAlert.Alert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Daily Report ....
|
||||
if (eaReportNewDays &&
|
||||
eaTimeTracker.IsNewDay())
|
||||
{
|
||||
//
|
||||
string msg = "New Day ...";
|
||||
|
||||
//
|
||||
eaAlert.Alert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Hourly Report ....
|
||||
if (eaReportNewHours &&
|
||||
eaTimeTracker.IsNewHour())
|
||||
{
|
||||
//
|
||||
string msg = "New Hour ...";
|
||||
|
||||
//
|
||||
eaAlert.Alert(msg);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,575 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XTest MQL5 Expert Advisor
|
||||
// -------------------------------------------------
|
||||
// Name: XPanelEA
|
||||
// Description: an Exper Advisor which used Panels
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////x
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XPanelEA"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "XPANELEA"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.x-app-dialog.class.mq5"
|
||||
#include "../Classes/x-saherelm.xalert.class.mq5"
|
||||
#include "../Classes/x-saherelm.xtrade.class.mq5"
|
||||
#include "../Helpers/x-saherelm.xcc.helper.mq5"
|
||||
#include "../Helpers/x-saherelm.xct.helper.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Common ...
|
||||
input group "Common";
|
||||
input long eaMagicNumber = 78692110; // Magic Number
|
||||
input int eaSlippage = 10; // Slippgae
|
||||
input string eaLogSuffix = ""; // Log Suffix
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
// Here we Provider All Requirements for
|
||||
// Configuring Alert Provider ...
|
||||
input group "Alert";
|
||||
input bool eAEnableAlerts = true; // Enable Alerts
|
||||
input bool eALogAlerts = true; // Log Alerts
|
||||
input bool eAMailAlerts = false; // Mail Alerts
|
||||
input bool eAPushAlerts = false; // Push Alerts
|
||||
input bool eATerminalAlerts = false; // Terminal Alerts
|
||||
|
||||
//
|
||||
// Time Report ...
|
||||
input group "Reports";
|
||||
input bool eaReportNewMonths = false; // Report New Month
|
||||
input bool eaReportNewWeeks = false; // Report New Weeks
|
||||
input bool eaReportNewDays = false; // Report New Days
|
||||
input bool eaReportNewHours = false; // Report New Hours
|
||||
|
||||
//
|
||||
// Define Local Variables ...
|
||||
|
||||
//
|
||||
string eaLogTag; // EA Log Prefix ...
|
||||
XSCAlert *eaAlert; // Alert Provider for Expert Adviser ...
|
||||
XSCTrade *eaTrader; // Trader of Expert Adviser ...
|
||||
XTimeTracker eaTimeTracker; // Time Tracker for Providing Reports ...
|
||||
XSCXCTHelper *eaCTHelper; // Bar Timer Indicator Helper class ...
|
||||
XSCXCCHelper *eaCCHelper; // Chart Styler Indicator Helper Class ...
|
||||
|
||||
//
|
||||
XCAppDialog eaMainWindow; // EA Main Dialog ...
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs and Required Parameters
|
||||
// for EA to Works fine ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Timer ...
|
||||
if (!InitTimer())
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize all Requirements ...
|
||||
if (!InitEA())
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize all GUI Objects and Classes ...
|
||||
if (!InitGUI())
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Alert Initialization ...
|
||||
string msg = "Initialized Successfully ...";
|
||||
eaAlert.Alert(msg);
|
||||
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// Destroy Timer ...
|
||||
DestroyTimer();
|
||||
|
||||
//
|
||||
// Destroy all GUI Requirements ...
|
||||
DestroyGUI();
|
||||
|
||||
//
|
||||
// Alert De Initialization Succeeded ...
|
||||
string msg = "De Initialized Successfully ...";
|
||||
eaAlert.Alert(msg);
|
||||
|
||||
//
|
||||
// Destroy all EA Requirements ...
|
||||
DestroyEA();
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
UpdateGUI();
|
||||
HandleReportTime();
|
||||
UpdatePositionsState();
|
||||
|
||||
//
|
||||
// TODO: Implemetn Tick Processors Algorithm ...
|
||||
}
|
||||
|
||||
//
|
||||
// Handle On Trade Event ...
|
||||
void OnTrade()
|
||||
{
|
||||
eaTrader.HandleOnTrade();
|
||||
}
|
||||
|
||||
//
|
||||
// On Timer ...
|
||||
void OnTimer()
|
||||
{
|
||||
//
|
||||
// TODO: Implement Time Based Functionalities ...
|
||||
}
|
||||
|
||||
//
|
||||
// Chart Event Handler ...
|
||||
void OnChartEvent(
|
||||
const int id,
|
||||
const long &lparam,
|
||||
const double &dparam,
|
||||
const string &sparam //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Apply Chart Event on Main Window ...
|
||||
eaMainWindow.ChartEvent(id, lparam, dparam, sparam);
|
||||
|
||||
//
|
||||
// Handle OnClick Event ...
|
||||
if (id == CHARTEVENT_OBJECT_CLICK)
|
||||
{
|
||||
HandleOnClickEvent(sparam);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Event Handlers ...
|
||||
|
||||
/**
|
||||
* Handle StopLoss Triggered Positions ...
|
||||
*
|
||||
* @param deal: XDeal ...
|
||||
*/
|
||||
void OnStopLossTriggered(const XDeal &deal)
|
||||
{
|
||||
//
|
||||
HandleReportBalance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Take Profit Triggered Positions ...
|
||||
*
|
||||
* @param deal: XDeal ...
|
||||
*/
|
||||
void OnTakeProfitTriggered(const XDeal &deal)
|
||||
{
|
||||
//
|
||||
HandleReportBalance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Force Close a Position ...
|
||||
*
|
||||
* @param ticket: Position Ticket ...
|
||||
* @param position: XPosition ...
|
||||
* @param comment: Closing Comment ...
|
||||
*/
|
||||
void OnPositionForceClosed(
|
||||
const ulong ticket,
|
||||
const XPosition &position,
|
||||
const string comment //
|
||||
)
|
||||
{
|
||||
//
|
||||
HandleReportBalance();
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
/**
|
||||
* Validate all Inputs of Expert Adviser ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
string errMessage = "";
|
||||
|
||||
//
|
||||
bool isCommonValid = (
|
||||
//
|
||||
eaSlippage > 0 &&
|
||||
eaMagicNumber > 0
|
||||
//
|
||||
);
|
||||
if (!isCommonValid)
|
||||
{
|
||||
//
|
||||
errMessage += "common configurations error;" + "\n";
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
// Common ...
|
||||
isCommonValid &&
|
||||
//
|
||||
// Otere ...
|
||||
true
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
// Since here Logger not Initiallized, we Use Raw Print Command ...
|
||||
Print(ShortName + " Errors: \n", errMessage);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize Timer ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitTimer()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// TODO: Initialize Timer if necessary ...
|
||||
// result = EventSetTimer(1);
|
||||
// result = EventSetMillisecondTimer(100);
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Timer ...
|
||||
*/
|
||||
void DestroyTimer()
|
||||
{
|
||||
//
|
||||
// TODO: Use This ...
|
||||
// EventKillTimer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all Requirements for Working Fine ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitEA()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Locally Apply Changes on Prefix ...
|
||||
eaLogTag = ShortName + ">" + eaLogSuffix;
|
||||
|
||||
//
|
||||
// Bar Timer ...
|
||||
XCTInputs ctInputs;
|
||||
ctInputs.Default(); // Default Configurations ...
|
||||
eaCTHelper = new XSCXCTHelper();
|
||||
result = eaCTHelper.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
ctInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Bar Styles ...
|
||||
XCCInputs ccInputs;
|
||||
ccInputs.Default(); // Default Configurations ...
|
||||
eaCCHelper = new XSCXCCHelper();
|
||||
result = eaCCHelper.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
ccInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Create Instance of Alert Class and Configure it ...
|
||||
eaAlert = new XSCAlert();
|
||||
eaAlert.SetPrefix(eaLogTag);
|
||||
eaAlert.SetLogAlerts(eALogAlerts);
|
||||
eaAlert.SetMailAlerts(eAMailAlerts);
|
||||
eaAlert.SetPushAlerts(eAPushAlerts);
|
||||
eaAlert.SetEnableAlerts(eAEnableAlerts);
|
||||
eaAlert.SetTerminalAlerts(eATerminalAlerts);
|
||||
|
||||
//
|
||||
// Create Trader Instance and Configure it ...
|
||||
eaTrader = new XSCTrade(
|
||||
eaSlippage,
|
||||
eaMagicNumber //
|
||||
);
|
||||
eaTrader.AddOnStopLossEventHandler(OnStopLossTriggered);
|
||||
eaTrader.AddOnTakeProfitEventHandler(OnTakeProfitTriggered);
|
||||
eaTrader.AddOnForceClosePositionEventHandler(OnPositionForceClosed);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy all Initialized EA Requirements ...
|
||||
*/
|
||||
void DestroyEA()
|
||||
{
|
||||
//
|
||||
delete eaCTHelper;
|
||||
delete eaCCHelper;
|
||||
|
||||
//
|
||||
delete eaAlert;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all GUI Requirements for EA ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitGUI()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Application Main Window ...
|
||||
result = eaMainWindow.Create(
|
||||
ChartID(),
|
||||
ShortName, // Dialog Name ...
|
||||
0, // SubWindow ...
|
||||
10, // X1 ...
|
||||
35, // Y1 ...
|
||||
300, // X2 ...
|
||||
200 // Y2 ...
|
||||
);
|
||||
|
||||
//
|
||||
// Configuring Dialog ...
|
||||
// eaMainWindow.MinimizeButton(false); // Hide Minimize Button ...
|
||||
// eaMainWindow.CloseButton(false); // Hide Close Button ...
|
||||
eaMainWindow.BackgroundColor(clrBlack);
|
||||
// result = true;
|
||||
|
||||
//
|
||||
// Try To Run Main Window ...
|
||||
if (result)
|
||||
{
|
||||
eaMainWindow.Run();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update GUI based on Each Ticks ...
|
||||
*/
|
||||
void UpdateGUI()
|
||||
{
|
||||
//
|
||||
// TODO: Implement this ...
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy all Initialized GUi Requirements ...
|
||||
*/
|
||||
void DestroyGUI()
|
||||
{
|
||||
//
|
||||
eaMainWindow.Destroy();
|
||||
}
|
||||
|
||||
//
|
||||
// Others ...
|
||||
|
||||
/**
|
||||
* Update Positions States ...
|
||||
*/
|
||||
void UpdatePositionsState()
|
||||
{
|
||||
//
|
||||
// TODO: Implement this ...
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle On Click Event for GUI Components ...
|
||||
*
|
||||
* @param name: Object Name ...
|
||||
*/
|
||||
void HandleOnClickEvent(string name)
|
||||
{
|
||||
//
|
||||
if (!IsValid(name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
bool isClicked = false;
|
||||
|
||||
//
|
||||
// TODO: Implement Chart Objects On Click ...
|
||||
|
||||
//
|
||||
if (isClicked)
|
||||
{
|
||||
UpdateGUI();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Report Account Balance ...
|
||||
*/
|
||||
void HandleReportBalance()
|
||||
{
|
||||
//
|
||||
if (!IsRunningOnTestMode())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
string msg = "Balance: " + ToString(eaTrader.mAccount.GetBalance());
|
||||
eaAlert.Log(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Time Reporting based on Inputs ...
|
||||
*/
|
||||
void HandleReportTime()
|
||||
{
|
||||
//
|
||||
// Monthly Report ....
|
||||
if (eaReportNewMonths &&
|
||||
eaTimeTracker.IsNewMonth())
|
||||
{
|
||||
//
|
||||
string msg = "New Month ...";
|
||||
|
||||
//
|
||||
eaAlert.Alert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Weekly Report ....
|
||||
if (eaReportNewWeeks &&
|
||||
eaTimeTracker.IsNewWeek())
|
||||
{
|
||||
//
|
||||
string msg = "New Week ...";
|
||||
|
||||
//
|
||||
eaAlert.Alert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Daily Report ....
|
||||
if (eaReportNewDays &&
|
||||
eaTimeTracker.IsNewDay())
|
||||
{
|
||||
//
|
||||
string msg = "New Day ...";
|
||||
|
||||
//
|
||||
eaAlert.Alert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Hourly Report ....
|
||||
if (eaReportNewHours &&
|
||||
eaTimeTracker.IsNewHour())
|
||||
{
|
||||
//
|
||||
string msg = "New Hour ...";
|
||||
|
||||
//
|
||||
eaAlert.Alert(msg);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,438 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XTest MQL5 Expert Advisor
|
||||
// -------------------------------------------------
|
||||
// Name: X121SMCEA
|
||||
// Description: an Exper Advisor which used Panels
|
||||
//
|
||||
// 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 X121SMCEA"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "X121SMCEA"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../X121SMCEA/Experts/x-121.smc.expert.class.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Common ...
|
||||
input group "Common";
|
||||
input long eaMagicNumber = 78692110; // Magic Number
|
||||
input int eaSlippage = 10; // Slippgae
|
||||
input string eaLogSuffix = ""; // Log Suffix
|
||||
|
||||
//
|
||||
// Symbols ...
|
||||
input group "Symbols";
|
||||
input bool eaMultiSymbol = false; // Use Multi Symbol
|
||||
input string eaSymbols = "EURUSDb,GBPUSDb,USDJPYb,USDCHFb"; // Trading Symbols
|
||||
|
||||
//
|
||||
// Signalling ...
|
||||
input group "Signalling";
|
||||
input bool eaAllowLong = true; // Allow Long Signals
|
||||
input bool eaAllowShort = true; // Allow Short Signals
|
||||
input int eaMaxAllowedLongs = 5; // Max Allowed Long Signals
|
||||
input int eaMaxAllowedShorts = 5; // Max Allowed Short Signals
|
||||
input bool eaUseMaxAllowedSignalsPerSymbol = true; // Use Max Allowed Signal Types Per Symbol
|
||||
input double eaLastPositionProfitForAcceptNextInPoint = 30; // Last Position Profit In Points for Accept new Signal
|
||||
input int eaDelaysBetweenTwoSignalsInBar = 10; // Delay between two Signals in Bars
|
||||
input double eaMaxAllowedSpread = 25; // Max Allowed Spread for Signalling
|
||||
input int eaMinRequiredVerificationForSpreadPass = 20; // Minimum Spread Verification for Signalling
|
||||
|
||||
//
|
||||
// Risk Management ...
|
||||
input group "Risk Management";
|
||||
input double eaR2R = 3; // Signallers Risk to Reward Ratio
|
||||
input double eaVolume = 0.05; // Static Volume
|
||||
input double eaRiskPercentPerBalance = 0.1; // Risk Percent Per Balance in Each Trade
|
||||
input bool eaDynamicRiskManagement = false; // Dynamic Risk Management
|
||||
input bool eaUseDynamicVolume = false; // Use Dynamic Volume
|
||||
input double eaDynamicVolumeStep = 0.01; // Increase Volume Step
|
||||
input double eaDynamicVolumeBalanceFactor = 200; // Balance Factor for Generate Dynamic Volume
|
||||
input double eaMaxAllowedDrawdownToOpenTrades = 3; // Max Allowed Drawdown for Open Trades
|
||||
input int eaMaxAllowedSLToPauseSignallingPerSymbol = 2; // Max Allowed SL for Pause Signalling Per Symbol
|
||||
input int eaPauseSignallingAfterReachesMaxAllowedSLInSecconds = 14400; // Pause Signalling Per Symbol afte Max Allowed SL Reached In Seconds
|
||||
|
||||
//
|
||||
// Protection ...
|
||||
input group "Protection";
|
||||
input bool eaAllowHedging = true; // Allow Hedge Positions
|
||||
input int eaMinOpenTradesFroHedging = 3; // Minimum Open Positions for Hedging
|
||||
input double eaHedgingMinVolumeStep = 0.01; // Minimum Volume Step for Hedging
|
||||
input double eaHedgeingMinRequiredProfitPerVolumeStep = 0.3; // Minimum Required Profit Per Volume Step for Hedging
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
// Here we Provider All Requirements for
|
||||
// Configuring Alert Provider ...
|
||||
input group "Alert";
|
||||
input bool eaEnableAlerts = true; // Enable Alerts
|
||||
input bool eaLogAlerts = true; // Log Alerts
|
||||
input bool eaMailAlerts = false; // Mail Alerts
|
||||
input bool eaPushAlerts = false; // Push Alerts
|
||||
input bool eaTerminalAlerts = false; // Terminal Alerts
|
||||
|
||||
//
|
||||
// Time Report ...
|
||||
input group "Reports";
|
||||
input bool eaReportNewMonths = false; // Report New Month
|
||||
input bool eaReportNewWeeks = false; // Report New Weeks
|
||||
input bool eaReportNewDays = true; // Report New Days
|
||||
input bool eaReportNewHours = false; // Report New Hours
|
||||
|
||||
//
|
||||
// Define Local Variables ...
|
||||
|
||||
XC121SMCExpert eaExpert;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs and Required Parameters
|
||||
// for EA to Works fine ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Timer ...
|
||||
if (!InitTimer())
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Configure EA Expert Class ...
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
eaExpert.OnSignalEventListener = OnSignalRecieved;
|
||||
eaExpert.OnDealsChangedEventListener = OnDealsChanged;
|
||||
eaExpert.OnOrdersChangedEventListener = OnOrdersChanged;
|
||||
eaExpert.OnPositionSLEventListener = OnStopLossTriggered;
|
||||
eaExpert.OnPositionTPEventListener = OnTakeProfitTriggered;
|
||||
eaExpert.OnPositionsChangedEventListener = OnPositionsChanged;
|
||||
eaExpert.OnPositionForceCloseEventListener = OnPositionForceClosed;
|
||||
|
||||
//
|
||||
// Common ...
|
||||
eaExpert.MagicNumber(eaMagicNumber);
|
||||
eaExpert.Slippage(eaSlippage);
|
||||
eaExpert.TagPrefix(eaLogSuffix);
|
||||
|
||||
//
|
||||
// Symbol ...
|
||||
eaExpert.SetSymbol(_Symbol);
|
||||
eaExpert.SetPeriod(_Period);
|
||||
eaExpert.Symbols(eaSymbols);
|
||||
eaExpert.MultiSymbol(eaMultiSymbol);
|
||||
|
||||
//
|
||||
// Signalling ...
|
||||
eaExpert.AllowLong(eaAllowLong);
|
||||
eaExpert.AllowShort(eaAllowShort);
|
||||
eaExpert.MaxAllowedLongs(eaMaxAllowedLongs);
|
||||
eaExpert.MaxAllowedShorts(eaMaxAllowedShorts);
|
||||
eaExpert.UseMaxAllowedSignalsPerSymbol(eaUseMaxAllowedSignalsPerSymbol);
|
||||
eaExpert.LastPositionProfitForAcceptNextInPoint(eaLastPositionProfitForAcceptNextInPoint);
|
||||
eaExpert.DelaysBetweenTwoSignalsInBar(eaDelaysBetweenTwoSignalsInBar);
|
||||
eaExpert.MaxAllowedSpread(eaMaxAllowedSpread);
|
||||
eaExpert.MinRequiredVerificationForSpreadPass(eaMinRequiredVerificationForSpreadPass);
|
||||
|
||||
//
|
||||
// Risk Management ...
|
||||
eaExpert.R2R(eaR2R);
|
||||
eaExpert.Volume(eaVolume);
|
||||
eaExpert.RiskPercentPerBalance(eaRiskPercentPerBalance);
|
||||
eaExpert.DynamicRiskManagement(eaDynamicRiskManagement);
|
||||
eaExpert.UseDynamicVolume(eaUseDynamicVolume);
|
||||
eaExpert.DynamicVolumeStep(eaDynamicVolumeStep);
|
||||
eaExpert.DynamicVolumeBalanceFactor(eaDynamicVolumeBalanceFactor);
|
||||
eaExpert.MaxAllowedDrawdownToOpenTrades(eaMaxAllowedDrawdownToOpenTrades);
|
||||
eaExpert.MaxAllowedSLToPauseSignallingPerSymbol(eaMaxAllowedSLToPauseSignallingPerSymbol);
|
||||
eaExpert.PauseSignallingAfterReachesMaxAllowedSLInSecconds(eaPauseSignallingAfterReachesMaxAllowedSLInSecconds);
|
||||
|
||||
//
|
||||
// Protection ...
|
||||
eaExpert.AllowHedging(eaAllowHedging);
|
||||
eaExpert.MinOpenTradesFroHedging(eaMinOpenTradesFroHedging);
|
||||
eaExpert.HedgingMinVolumeStep(eaHedgingMinVolumeStep);
|
||||
eaExpert.HedgeingMinRequiredProfitPerVolumeStep(eaHedgeingMinRequiredProfitPerVolumeStep);
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
eaExpert.SetAlertEnableAlerts(eaEnableAlerts);
|
||||
eaExpert.SetAlertLogAlerts(eaLogAlerts);
|
||||
eaExpert.SetAlertMailAlerts(eaMailAlerts);
|
||||
eaExpert.SetAlertPushAlerts(eaPushAlerts);
|
||||
eaExpert.SetAlertTerminalAlerts(eaTerminalAlerts);
|
||||
|
||||
//
|
||||
// Reports ...
|
||||
eaExpert.ReportNewMonths(eaReportNewMonths);
|
||||
eaExpert.ReportNewWeeks(eaReportNewWeeks);
|
||||
eaExpert.ReportNewDays(eaReportNewDays);
|
||||
eaExpert.ReportNewHours(eaReportNewHours);
|
||||
|
||||
//
|
||||
bool isInited = eaExpert.HandleOnInit();
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// Destroy Timer ...
|
||||
eaExpert.HandleOnDeInit();
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
eaExpert.HandleOnTick();
|
||||
}
|
||||
|
||||
//
|
||||
// Handle On Trade Event ...
|
||||
void OnTrade()
|
||||
{
|
||||
eaExpert.HandleOnTrade();
|
||||
}
|
||||
|
||||
//
|
||||
// On Timer ...
|
||||
void OnTimer()
|
||||
{
|
||||
eaExpert.HandleOnTimer();
|
||||
}
|
||||
|
||||
//
|
||||
// Chart Event Handler ...
|
||||
void OnChartEvent(
|
||||
const int id,
|
||||
const long &lparam,
|
||||
const double &dparam,
|
||||
const string &sparam //
|
||||
)
|
||||
{
|
||||
eaExpert.HandleOnChartEvent(id, lparam, dparam, sparam);
|
||||
}
|
||||
|
||||
//
|
||||
// Event Listeners ...
|
||||
|
||||
/**
|
||||
* Do What we Want by Specific Signal ...
|
||||
*
|
||||
* @param signal: XSignal instance ...
|
||||
* @param conditions: XStrategyConditions instance ...
|
||||
*/
|
||||
void OnSignalRecieved(
|
||||
XSignal &signal,
|
||||
X121SMCStrategyConditions &conditions //
|
||||
)
|
||||
{
|
||||
//
|
||||
eaExpert.HandleOnSignalRecieved(
|
||||
signal,
|
||||
conditions //
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle StopLoss Triggered Positions ...
|
||||
*
|
||||
* @param deal: XDeal instance ...
|
||||
*/
|
||||
void OnStopLossTriggered(const XDeal &deal)
|
||||
{
|
||||
eaExpert.HandleOnStopLossTriggered(deal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Take Profit Triggered Positions ...
|
||||
*
|
||||
* @param deal: XDeal instance ...
|
||||
*/
|
||||
void OnTakeProfitTriggered(const XDeal &deal)
|
||||
{
|
||||
eaExpert.HandleOnTakeProfitTriggered(deal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Force Close a Position ...
|
||||
*
|
||||
* @param ticket: ULONG ...
|
||||
* @param position: XPosition instance ...
|
||||
* @param comment: String ...
|
||||
*/
|
||||
void OnPositionForceClosed(
|
||||
const ulong ticket,
|
||||
const XPosition &position,
|
||||
const string comment //
|
||||
)
|
||||
{
|
||||
//
|
||||
eaExpert.HandleOnPositionForceClosed(
|
||||
ticket,
|
||||
position,
|
||||
comment //
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Deals Changes ...
|
||||
*
|
||||
* @param count: Integer, Number of Changes ...
|
||||
*/
|
||||
void OnDealsChanged(int count)
|
||||
{
|
||||
eaExpert.HandleOnDealsChanged(count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Orders Changes ...
|
||||
*
|
||||
* @param count: Integer, Number of Changes ...
|
||||
*/
|
||||
void OnOrdersChanged(int count)
|
||||
{
|
||||
eaExpert.HandleOnOrdersChanged(count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Positions Changes ...
|
||||
*
|
||||
* @param count: Integer, Number of Changes ...
|
||||
*/
|
||||
void OnPositionsChanged(int count)
|
||||
{
|
||||
eaExpert.HandleOnPositionsChanged(count);
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
/**
|
||||
* Validate all Inputs of Expert Adviser ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
string errMessage = "";
|
||||
|
||||
//
|
||||
bool isCommonValid = (
|
||||
//
|
||||
eaSlippage > 0 &&
|
||||
eaMagicNumber > 0
|
||||
//
|
||||
);
|
||||
if (!isCommonValid)
|
||||
{
|
||||
//
|
||||
errMessage += "common configurations error;" + "\n";
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
// Common ...
|
||||
isCommonValid &&
|
||||
//
|
||||
// Otere ...
|
||||
true
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
// Since here Logger not Initiallized, we Use Raw Print Command ...
|
||||
Print(ShortName + " Errors: \n", errMessage);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize Timer ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitTimer()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// TODO: Initialize Timer if necessary ...
|
||||
// result = EventSetTimer(1);
|
||||
// result = EventSetMillisecondTimer(100);
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Timer ...
|
||||
*/
|
||||
void DestroyTimer()
|
||||
{
|
||||
//
|
||||
// TODO: Use This ...
|
||||
// EventKillTimer();
|
||||
}
|
||||
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,758 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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.x-helper.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 X3MAConditions()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
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 XCX3MAHelper : public XCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XCX3MAHelper()
|
||||
: XCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCX3MAHelper()
|
||||
{
|
||||
//
|
||||
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
@@ -0,0 +1,245 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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.x-helper.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 XCXCCHelper : public XCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XCXCCHelper() : XCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCXCCHelper() {}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,230 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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.x-helper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct XCTInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
string font; // Font
|
||||
int fontSize; // Font Size;
|
||||
color clr; // Text Color
|
||||
ENUM_BASE_CORNER corner; // Text Position
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showCandleTime; // Show Candle Time
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
XCTInputs()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
font = NULL;
|
||||
fontSize = 15;
|
||||
clr = CLR_NONE;
|
||||
corner = CORNER_RIGHT_LOWER;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
showCandleTime = false;
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
font = "Arial";
|
||||
fontSize = 15;
|
||||
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 XCXCTHelper : public XCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XCXCTHelper()
|
||||
: XCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCXCTHelper()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// 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.fontSize, // Font Size ...
|
||||
mInputs.font, // Font ...
|
||||
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 ...
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,437 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 = clrGreen; // Up Color
|
||||
input color downColor = clrRed; // Down Color
|
||||
input color lineColor = clrGreen; // Line mode and Doji candlestick Color
|
||||
input color bullishColor = clrGreen; // Bullish Color
|
||||
input color bearishColor = clrRed; // 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 ...
|
||||
//
|
||||
@@ -0,0 +1,262 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 int fontSize = 15; // Font Size
|
||||
input string font = "Arial"; // Font
|
||||
input color clr = clrYellow; // Text Color
|
||||
input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER; // Text Position
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showTimer = 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 ...
|
||||
//
|
||||
bool isCreatedObject;
|
||||
string tag;
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
|
||||
//
|
||||
tag = ShortName + _Symbol + ToString(_Period);
|
||||
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// Delete Object ...
|
||||
ObjectDelete(0, tag);
|
||||
|
||||
//
|
||||
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 ...
|
||||
)
|
||||
{
|
||||
//
|
||||
if (!showTimer)
|
||||
{
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
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 = ".";
|
||||
|
||||
//
|
||||
string objText = "Spread: " + IntegerToString(mSpread) + _sp + ", Next Bar in: " + msg;
|
||||
|
||||
//
|
||||
if (IsValid(tag) && !isCreatedObject)
|
||||
{
|
||||
CreateIndicatorObject();
|
||||
}
|
||||
|
||||
//
|
||||
if (isCreatedObject)
|
||||
{
|
||||
ObjectSetString(0, tag, OBJPROP_TEXT, objText);
|
||||
}
|
||||
|
||||
//
|
||||
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 (!showTimer ||
|
||||
!IsValid(tag))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
isCreatedObject = ObjectCreate(0, tag, OBJ_LABEL, 0, 0, 0);
|
||||
ObjectSetInteger(0, tag, OBJPROP_CORNER, corner);
|
||||
ObjectSetInteger(0, tag, OBJPROP_XDISTANCE, 10);
|
||||
ObjectSetInteger(0, tag, 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;
|
||||
}
|
||||
|
||||
//
|
||||
int mFontSize = fontSize > 0
|
||||
? fontSize
|
||||
: 10;
|
||||
|
||||
//
|
||||
string mFont = IsValid(font)
|
||||
? font
|
||||
: "Arial";
|
||||
|
||||
//
|
||||
ObjectSetString(0, tag, OBJPROP_FONT, mFont);
|
||||
ObjectSetInteger(0, tag, OBJPROP_COLOR, clr);
|
||||
ObjectSetInteger(0, tag, OBJPROP_ANCHOR, Anchor);
|
||||
ObjectSetInteger(0, tag, OBJPROP_FONTSIZE, mFontSize);
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
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
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
# MQL5
|
||||
|
||||
this is a workspace which contains MetaTrader4 Data Folder Contents to Directly develop MQL5 using VSCode and test them.
|
||||
|
||||
## Maintainer
|
||||
|
||||
Hadi Khazaee asl
|
||||
|
||||
[https://www.saherelm.ir](https://www.saherelm.ir)
|
||||
|
||||
[hadi_khazaee_asl@yahoo.com](mailto:hadi_khazaee_asl@yahoo.com)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,195 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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_XPVPIVOT_OBJ, // XPVPivot Object ...
|
||||
};
|
||||
|
||||
//
|
||||
// Implementations ...
|
||||
|
||||
//
|
||||
// XPVPivot Object ...
|
||||
class XCXPVPivotObject : public XCBaseObject
|
||||
{
|
||||
//
|
||||
public:
|
||||
//
|
||||
|
||||
/**
|
||||
* Creator ...
|
||||
*
|
||||
* @param chart_id: Long, Specified Chart ID ...
|
||||
* @param window: Integer, Specified Chart Window ID ...
|
||||
* @param pivot: XPVPivot instance ...
|
||||
* @param prefix: String ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool Create(
|
||||
long chart_id,
|
||||
int window,
|
||||
XPVPivot &pivot,
|
||||
string prefix = NULL //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = pivot.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string name = pivot.GetTag();
|
||||
if (IsValid(prefix))
|
||||
{
|
||||
name = prefix + "_" + name;
|
||||
}
|
||||
|
||||
//
|
||||
result = mRect.Create(
|
||||
chart_id,
|
||||
name,
|
||||
window,
|
||||
pivot.from,
|
||||
pivot.upper,
|
||||
pivot.to,
|
||||
pivot.lower //
|
||||
);
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
ObjName(name);
|
||||
}
|
||||
|
||||
//
|
||||
string mTrendName = "MID_" + name;
|
||||
double mid = pivot.CalculateMid();
|
||||
result = mTrend.Create(
|
||||
chart_id,
|
||||
mTrendName,
|
||||
window,
|
||||
pivot.from,
|
||||
mid,
|
||||
pivot.to,
|
||||
mid //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
mRect.Delete();
|
||||
mRect.Detach();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Getter(s) / Setter(s) ...
|
||||
|
||||
/**
|
||||
* Set Pivot Width ...
|
||||
*
|
||||
* @param value: Integer ...
|
||||
*/
|
||||
void PivotWidth(int value)
|
||||
{
|
||||
//
|
||||
if (value < 1)
|
||||
{
|
||||
value = 1;
|
||||
}
|
||||
|
||||
//
|
||||
mRect.Width(value);
|
||||
mTrend.Width(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Pivot Color ...
|
||||
*
|
||||
* @param value: Color ...
|
||||
*/
|
||||
void PivotColor(color value)
|
||||
{
|
||||
//
|
||||
mRect.Color(value);
|
||||
mTrend.Color(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Pivot Style ...
|
||||
*
|
||||
* @param value: ENUM_LINE_STYLE member ...
|
||||
*/
|
||||
void PivotStyle(ENUM_LINE_STYLE value)
|
||||
{
|
||||
//
|
||||
mRect.Style(value);
|
||||
mTrend.Style(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Pivot Fill ...
|
||||
*
|
||||
* @param value: Boolean ...
|
||||
*/
|
||||
void PivotFill(bool value)
|
||||
{
|
||||
mRect.Fill(value);
|
||||
}
|
||||
|
||||
//
|
||||
// Virtual ...
|
||||
|
||||
/**
|
||||
* Retrieve Object Type ...
|
||||
*
|
||||
* @return ( ENUM_X121SMC_CHARTOBJECTS )
|
||||
*/
|
||||
virtual ENUM_X121SMC_CHARTOBJECTS Type()
|
||||
{
|
||||
return X_XPVPIVOT_OBJ;
|
||||
}
|
||||
|
||||
//
|
||||
private:
|
||||
//
|
||||
|
||||
//
|
||||
// Props ...
|
||||
CChartObjectRectangle mRect;
|
||||
CChartObjectTrend mTrend;
|
||||
};
|
||||
@@ -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:
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
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,688 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "../../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 X121SMCXTestToken = "X121XTest";
|
||||
const string X121SMCXPVOBToken = "X121XPVOB";
|
||||
const string X121SMCXPVDPToken = "X121XPVDP";
|
||||
const string X121SMCXVWPBToken = "X121XVWPB";
|
||||
const string X121SMCXTWPVToken = "X121XTWPV";
|
||||
const string X121SMCXOEPVToken = "X121XOEPV";
|
||||
const string X121SMCXPVSupDemToken = "X121XPVSUPDEM";
|
||||
|
||||
//
|
||||
// X121 SMC Providers ...
|
||||
enum ENUM_X_121_SMC_PROVIDERS
|
||||
{
|
||||
//
|
||||
X_121_SMC_PROVIDER_NONE,
|
||||
X_121_SMC_PROVIDER_XTEST,
|
||||
X_121_SMC_PROVIDER_XPVOB,
|
||||
X_121_SMC_PROVIDER_XPVDP,
|
||||
X_121_SMC_PROVIDER_XVWPB,
|
||||
X_121_SMC_PROVIDER_XTWPV,
|
||||
X_121_SMC_PROVIDER_XOEPV,
|
||||
X_121_SMC_PROVIDER_XPVSUPDEM,
|
||||
};
|
||||
|
||||
//
|
||||
// X121 SL Method ...
|
||||
enum ENUM_X_121_SMC_SL_TYPES
|
||||
{
|
||||
X_121_SMC_SL_TYPE_NONE,
|
||||
X_121_SMC_SL_TYPE_LAST_SAR_CHANGED_BAR,
|
||||
X_121_SMC_SL_TYPE_CURRENT_SAR_BOX,
|
||||
X_121_SMC_SL_TYPE_LAST_DIRECTIONAL_SAR,
|
||||
X_121_SMC_SL_TYPE_CURRENT_SAR,
|
||||
X_121_SMC_SL_TYPE_DON_CLOSE_BOX,
|
||||
X_121_SMC_SL_TYPE_FIBO_LEVEL_1_5,
|
||||
X_121_SMC_SL_TYPE_FIBO_LEVEL_3,
|
||||
X_121_SMC_SL_TYPE_VWAP_FAST,
|
||||
X_121_SMC_SL_TYPE_VWAP_MID,
|
||||
X_121_SMC_SL_TYPE_VWAP_SLOW,
|
||||
X_121_SMC_SL_TYPE_SWING,
|
||||
X_121_SMC_SL_TYPE_MOMENTUM,
|
||||
X_121_SMC_SL_TYPE_REJECTION,
|
||||
X_121_SMC_SL_TYPE_TENKAN_SEN,
|
||||
};
|
||||
|
||||
//
|
||||
// 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;
|
||||
|
||||
//
|
||||
// Cycles Conditions here ...
|
||||
X121SMCCycleConditions triggerConditions;
|
||||
X121SMCCycleConditions decisionConditions;
|
||||
X121SMCCycleConditions analyseConditions;
|
||||
X121SMCCycleConditions verificationConditions;
|
||||
X121SMCCycleConditions consolidationConditions;
|
||||
X121SMCCycleConditions visionConditions;
|
||||
|
||||
//
|
||||
double sl;
|
||||
double tp;
|
||||
double target;
|
||||
string provider;
|
||||
ENUM_X_DIRECTION signalDir;
|
||||
ENUM_X_DIRECTION marketStructureDir;
|
||||
|
||||
//
|
||||
|
||||
//
|
||||
void X121SMCStrategyConditions()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleanup ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
time = NULL;
|
||||
|
||||
//
|
||||
sl = 0;
|
||||
tp = 0;
|
||||
provider = NULL;
|
||||
signalDir = X_DIRECTION_NONE;
|
||||
marketStructureDir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
triggerConditions.Clean();
|
||||
decisionConditions.Clean();
|
||||
analyseConditions.Clean();
|
||||
verificationConditions.Clean();
|
||||
consolidationConditions.Clean();
|
||||
visionConditions.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;
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
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_XTEST:
|
||||
result = X121SMCXTestToken;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_121_SMC_PROVIDER_XPVOB:
|
||||
result = X121SMCXPVOBToken;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_121_SMC_PROVIDER_XPVDP:
|
||||
result = X121SMCXPVDPToken;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_121_SMC_PROVIDER_XVWPB:
|
||||
result = X121SMCXVWPBToken;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_121_SMC_PROVIDER_XTWPV:
|
||||
result = X121SMCXTWPVToken;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_121_SMC_PROVIDER_XOEPV:
|
||||
result = X121SMCXOEPVToken;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_121_SMC_PROVIDER_XPVSUPDEM:
|
||||
result = X121SMCXPVSupDemToken;
|
||||
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(X121SMCXTestToken, value))
|
||||
{
|
||||
result = X_121_SMC_PROVIDER_XTEST;
|
||||
}
|
||||
else if (Contains(X121SMCXPVOBToken, value))
|
||||
{
|
||||
result = X_121_SMC_PROVIDER_XPVOB;
|
||||
}
|
||||
else if (Contains(X121SMCXPVDPToken, value))
|
||||
{
|
||||
result = X_121_SMC_PROVIDER_XPVDP;
|
||||
}
|
||||
else if (Contains(X121SMCXVWPBToken, value))
|
||||
{
|
||||
result = X_121_SMC_PROVIDER_XVWPB;
|
||||
}
|
||||
else if (Contains(X121SMCXTWPVToken, value))
|
||||
{
|
||||
result = X_121_SMC_PROVIDER_XTWPV;
|
||||
}
|
||||
else if (Contains(X121SMCXOEPVToken, value))
|
||||
{
|
||||
result = X_121_SMC_PROVIDER_XOEPV;
|
||||
}
|
||||
else if (Contains(X121SMCXPVSupDemToken, value))
|
||||
{
|
||||
result = X_121_SMC_PROVIDER_XPVSUPDEM;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,664 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 X121 SMC Signal Class
|
||||
// -------------------------------------------------
|
||||
// Name:
|
||||
// Description: provide all Signalling 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-121.smc.market.cycle.helper.class.mq5"
|
||||
#include "../Libraries/x-121.smc.lib.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
struct X121SMCStrategyTestSignalConditions
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
double sl;
|
||||
double target;
|
||||
ENUM_X_DIRECTION dir;
|
||||
ENUM_X_POSITION_TYPES type;
|
||||
|
||||
//
|
||||
// Setup Props ...
|
||||
|
||||
//
|
||||
datetime setupTime;
|
||||
datetime triggerTime;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
X121SMCStrategyTestSignalConditions()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleaning Up ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
sl = 0;
|
||||
target = 0;
|
||||
|
||||
//
|
||||
dir = X_DIRECTION_NONE;
|
||||
type = X_POSITION_TYPE_NONE;
|
||||
|
||||
//
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
setupTime = NULL;
|
||||
triggerTime = NULL;
|
||||
|
||||
//
|
||||
ExtensionClean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Condition is Setting Up ...
|
||||
*
|
||||
* @param dir: ENUM_X_DIRECTION member, Setting Up Direction ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsSetuped()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid(setupTime) &&
|
||||
HasDirection(dir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Setup Age ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int GetSetupAge()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
if (!IsSetuped())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect How we Can Trigger Signal ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool CanTrigger()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
sl > 0 &&
|
||||
IsValid(symbol) &&
|
||||
IsValid(period) &&
|
||||
IsValid(triggerTime) &&
|
||||
type != X_POSITION_TYPE_ALL &&
|
||||
type != X_POSITION_TYPE_NONE
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Extensions ...
|
||||
|
||||
/**
|
||||
* Clean Additional Properties ...
|
||||
*/
|
||||
void ExtensionClean()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Extension Functions ...
|
||||
|
||||
//
|
||||
// Detect Setup Conditions ...
|
||||
bool DetectX121SMCTestSiganlSetup(
|
||||
string _symbol,
|
||||
ENUM_TIMEFRAMES _period,
|
||||
//
|
||||
X121SMCStrategyTestSignalConditions &conditions,
|
||||
//
|
||||
XC121SMCCycleHelper *triggerCycleHelper,
|
||||
XC121SMCCycleHelper *decisionCycleHelper,
|
||||
XC121SMCCycleHelper *analyseCycleHelper,
|
||||
XC121SMCCycleHelper *verificationCycleHelper,
|
||||
XC121SMCCycleHelper *consolidationCycleHelper,
|
||||
XC121SMCCycleHelper *visionCycleHelper
|
||||
//
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
int zIndex = 0;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
int loopback = 10;
|
||||
|
||||
//
|
||||
string symbol = _symbol;
|
||||
ENUM_TIMEFRAMES period = _period;
|
||||
|
||||
//
|
||||
conditions.symbol = symbol;
|
||||
conditions.period = period;
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
result = zBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
zIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL cBar;
|
||||
result = cBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
cIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double ask = GetAsk(symbol);
|
||||
double bid = GetBid(symbol);
|
||||
datetime cTime = TimeCurrent();
|
||||
|
||||
//
|
||||
double ll = cBar.FindLowest(9, MODE_LOW);
|
||||
double hh = cBar.FindHighest(9, MODE_HIGH);
|
||||
|
||||
//
|
||||
int zoneValidationDivider = 10;
|
||||
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
||||
.GetDonChainLength();
|
||||
|
||||
//
|
||||
double selectedSL = 0;
|
||||
|
||||
//
|
||||
// Cycles Conditions ...
|
||||
|
||||
//
|
||||
// Trigger ...
|
||||
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
||||
X121SMCCycleConditions triggerConditions;
|
||||
result = triggerCycleHelper.GetConditions(
|
||||
triggerCycleEvents,
|
||||
triggerPoiEvents,
|
||||
triggerConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Decision ...
|
||||
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
||||
X121SMCCycleConditions decisionConditions;
|
||||
result = decisionCycleHelper.GetConditions(
|
||||
decisionCycleEvents,
|
||||
decisionPoiEvents,
|
||||
decisionConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Analyse ...
|
||||
ENUM_XPOI_EVENTS analysePoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
||||
X121SMCCycleConditions analyseConditions;
|
||||
result = analyseCycleHelper.GetConditions(
|
||||
analyseCycleEvents,
|
||||
analysePoiEvents,
|
||||
analyseConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Verification ...
|
||||
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
||||
X121SMCCycleConditions verificationConditions;
|
||||
result = verificationCycleHelper.GetConditions(
|
||||
verificationCycleEvents,
|
||||
verificationPoiEvents,
|
||||
verificationConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Consolidation ...
|
||||
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
||||
X121SMCCycleConditions consolidationConditions;
|
||||
result = consolidationCycleHelper.GetConditions(
|
||||
consolidationCycleEvents,
|
||||
consolidationPoiEvents,
|
||||
consolidationConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Vision ...
|
||||
ENUM_XPOI_EVENTS visionPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
||||
X121SMCCycleConditions visionConditions;
|
||||
result = visionCycleHelper.GetConditions(
|
||||
visionCycleEvents,
|
||||
visionPoiEvents,
|
||||
visionConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Cycles POI States ...
|
||||
XPOIState triggerState = triggerConditions.state;
|
||||
XPOIState decisionState = decisionConditions.state;
|
||||
XPOIState analyseState = analyseConditions.state;
|
||||
XPOIState verificationState = verificationConditions.state;
|
||||
XPOIState consolidationState = consolidationConditions.state;
|
||||
XPOIState visionState = visionConditions.state;
|
||||
|
||||
//
|
||||
// Setup Conditions ...
|
||||
|
||||
//
|
||||
isBullish =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
// Clean Conditions for Regenerate ...
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.setupTime = cTime;
|
||||
conditions.dir =
|
||||
isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Trigger Conditions ...
|
||||
bool DetectX121SMCTestSiganlTrigger(
|
||||
//
|
||||
X121SMCStrategyTestSignalConditions &conditions,
|
||||
//
|
||||
string _symbol,
|
||||
ENUM_TIMEFRAMES _period,
|
||||
//
|
||||
XC121SMCCycleHelper *triggerCycleHelper,
|
||||
XC121SMCCycleHelper *decisionCycleHelper,
|
||||
XC121SMCCycleHelper *analyseCycleHelper,
|
||||
XC121SMCCycleHelper *verificationCycleHelper,
|
||||
XC121SMCCycleHelper *consolidationCycleHelper,
|
||||
XC121SMCCycleHelper *visionCycleHelper,
|
||||
//
|
||||
int maxAllowedSetupAge = 60 //
|
||||
//
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = conditions.IsSetuped();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
datetime setupTime = conditions.setupTime;
|
||||
ENUM_X_DIRECTION setupDir = conditions.dir;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
int zIndex = 0;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
int loopback = 10;
|
||||
|
||||
//
|
||||
string symbol = _symbol;
|
||||
ENUM_TIMEFRAMES period = _period;
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
result = zBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
zIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL cBar;
|
||||
result = cBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
cIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double ask = GetAsk(symbol);
|
||||
double bid = GetBid(symbol);
|
||||
datetime cTime = TimeCurrent();
|
||||
|
||||
//
|
||||
double ll = cBar.FindLowest(9, MODE_LOW);
|
||||
double hh = cBar.FindHighest(9, MODE_HIGH);
|
||||
|
||||
//
|
||||
int zoneValidationDivider = 10;
|
||||
int validPivotRepetition = triggerCycleHelper.mX121Helper
|
||||
.GetDonChainLength();
|
||||
|
||||
//
|
||||
double selectedSL = 0;
|
||||
|
||||
//
|
||||
// Cycles Conditions ...
|
||||
|
||||
//
|
||||
// Trigger ...
|
||||
ENUM_XPOI_EVENTS triggerPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS triggerCycleEvents[];
|
||||
X121SMCCycleConditions triggerConditions;
|
||||
result = triggerCycleHelper.GetConditions(
|
||||
triggerCycleEvents,
|
||||
triggerPoiEvents,
|
||||
triggerConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Decision ...
|
||||
ENUM_XPOI_EVENTS decisionPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS decisionCycleEvents[];
|
||||
X121SMCCycleConditions decisionConditions;
|
||||
result = decisionCycleHelper.GetConditions(
|
||||
decisionCycleEvents,
|
||||
decisionPoiEvents,
|
||||
decisionConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Analyse ...
|
||||
ENUM_XPOI_EVENTS analysePoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS analyseCycleEvents[];
|
||||
X121SMCCycleConditions analyseConditions;
|
||||
result = analyseCycleHelper.GetConditions(
|
||||
analyseCycleEvents,
|
||||
analysePoiEvents,
|
||||
analyseConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Verification ...
|
||||
ENUM_XPOI_EVENTS verificationPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS verificationCycleEvents[];
|
||||
X121SMCCycleConditions verificationConditions;
|
||||
result = verificationCycleHelper.GetConditions(
|
||||
verificationCycleEvents,
|
||||
verificationPoiEvents,
|
||||
verificationConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Consolidation ...
|
||||
ENUM_XPOI_EVENTS consolidationPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS consolidationCycleEvents[];
|
||||
X121SMCCycleConditions consolidationConditions;
|
||||
result = consolidationCycleHelper.GetConditions(
|
||||
consolidationCycleEvents,
|
||||
consolidationPoiEvents,
|
||||
consolidationConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Vision ...
|
||||
ENUM_XPOI_EVENTS visionPoiEvents[];
|
||||
ENUM_X_CYCLE_EVENTS visionCycleEvents[];
|
||||
X121SMCCycleConditions visionConditions;
|
||||
result = visionCycleHelper.GetConditions(
|
||||
visionCycleEvents,
|
||||
visionPoiEvents,
|
||||
visionConditions,
|
||||
zIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Cycles POI States ...
|
||||
XPOIState triggerState = triggerConditions.state;
|
||||
XPOIState decisionState = decisionConditions.state;
|
||||
XPOIState analyseState = analyseConditions.state;
|
||||
XPOIState verificationState = verificationConditions.state;
|
||||
XPOIState consolidationState = consolidationConditions.state;
|
||||
XPOIState visionState = visionConditions.state;
|
||||
|
||||
//
|
||||
// Trigger Conditions ...
|
||||
|
||||
//
|
||||
isBullish =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
// Cleanup Setup Conditions ...
|
||||
int setupAge = conditions.GetSetupAge();
|
||||
if (IsValidSize(setupAge) &&
|
||||
IsValidSize(maxAllowedSetupAge) &&
|
||||
setupAge >= maxAllowedSetupAge)
|
||||
{
|
||||
conditions.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.triggerTime = cTime;
|
||||
conditions.sl = isBullish
|
||||
? 0
|
||||
: 0;
|
||||
conditions.type = isBullish
|
||||
? X_POSITION_TYPE_LONG
|
||||
: X_POSITION_TYPE_SHORT;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,52 @@
|
||||
//
|
||||
// Import Requirements ...
|
||||
const execSync = require("child_process").execSync;
|
||||
const XFileTools = require("./Documents/JsModules/x-file.tools");
|
||||
const XShellTools = require("./Documents/JsModules/x-shell.tools");
|
||||
const XColorTools = require("./Documents/JsModules/x-color.tools");
|
||||
|
||||
//
|
||||
handleCleanup();
|
||||
async function handleCleanup() {
|
||||
//
|
||||
var foldersPath = [
|
||||
"Classes", // Required Classes
|
||||
"Experts", // Expert Advisers
|
||||
"Helpers", // Indicator's Helpers Classes
|
||||
"Indicators", // Required Indicators
|
||||
"Libraries", // Required Libraries
|
||||
"Parsers", // Strategies Filters based on Conditions
|
||||
"Strategies", // Strategies Classes which Provides Signals
|
||||
"X121SMCEA", // X121SMC EA Projects ...
|
||||
];
|
||||
|
||||
//
|
||||
for (const path of foldersPath) {
|
||||
//
|
||||
const fSourcePath = XFileTools.joinPath(".", path);
|
||||
const filesToRemove = await XFileTools.extractFiles(fSourcePath, [".ex5", ".ex4"]);
|
||||
for (const f of filesToRemove) {
|
||||
//
|
||||
// Log ...
|
||||
console.log(
|
||||
XColorTools.applyForegroundColor("try to Remove: ", XColorTools.COLOR_NAMES.Yellow),
|
||||
XColorTools.applyForegroundColor(f, XColorTools.COLOR_NAMES.Blue)
|
||||
);
|
||||
|
||||
//
|
||||
let result = await XFileTools.removeFile(f);
|
||||
if (result) {
|
||||
//
|
||||
const msg = "removed successfully ...";
|
||||
console.log(
|
||||
XColorTools.applyForegroundColor(msg, XColorTools.COLOR_NAMES.Green)
|
||||
);
|
||||
} else {
|
||||
//
|
||||
const msg = "removed failed ...";
|
||||
console.log(XColorTools.applyForegroundColor(msg, XColorTools.COLOR_NAMES.Red));
|
||||
throw msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
@echo off
|
||||
|
||||
set METAEDITOR="C:\Program Files\MetaTrader 5\MetaEditor64.exe"
|
||||
set "LOGFILE=%~dpn1.log"
|
||||
|
||||
if "%~1"=="" (
|
||||
echo "You must specify the first parameter to this batch file."
|
||||
goto end
|
||||
)
|
||||
|
||||
:: Compile the MQL5 way
|
||||
%METAEDITOR% /compile:%1 /log
|
||||
:: 0 = failed
|
||||
:: 1 = everything good
|
||||
echo "Error level %ERRORLEVEL%"
|
||||
|
||||
:: This dumps the log file to stdout so it can be seen.
|
||||
:: It's assumed to be in the same directory as the expert file.
|
||||
type "%LOGFILE%"
|
||||
|
||||
:: Once shown, get rid of the .log file.
|
||||
erase "%LOGFILE%"
|
||||
|
||||
:end
|
||||
:: If I want the CMD.exe window to go away, use exit
|
||||
::exit %ERRORLEVEL%
|
||||
@@ -0,0 +1,443 @@
|
||||
//
|
||||
// Import Requirements ...
|
||||
const execSync = require("child_process").execSync;
|
||||
const XFileTools = require("./Documents/JsModules/x-file.tools");
|
||||
const XShellTools = require("./Documents/JsModules/x-shell.tools");
|
||||
const XColorTools = require("./Documents/JsModules/x-color.tools");
|
||||
|
||||
//
|
||||
// define constants ...
|
||||
const projectsPath = XFileTools.joinPath(".", "Projects");
|
||||
const packsPath = XFileTools.joinPath(".", "Packs");
|
||||
const excludeWorkspaceFolders = [
|
||||
"BKP",
|
||||
"Documents",
|
||||
"Images",
|
||||
"Includes",
|
||||
"Logs",
|
||||
"Packs",
|
||||
"Profiles",
|
||||
"Projects",
|
||||
"Scripts",
|
||||
"Services",
|
||||
"Shared Projects",
|
||||
//
|
||||
// Exclude Defaults ...
|
||||
"Examples",
|
||||
"Free Indicators",
|
||||
"Advisors",
|
||||
"Free Robots"
|
||||
];
|
||||
|
||||
//
|
||||
// Read Command Arguments ...
|
||||
let projectName = process.argv[2];
|
||||
let doPackProject = process.argv[3] || false;
|
||||
|
||||
//
|
||||
// Make Decission to what to Do based on given args ...
|
||||
if (!projectName ||
|
||||
projectName == "" ||
|
||||
projectName.length == 0) {
|
||||
//
|
||||
// Compile Whole MQL Workspace ...
|
||||
doPackProject = false;
|
||||
const workSpacePath = XFileTools.joinPath(".", __dirname);
|
||||
|
||||
//
|
||||
doWorkspaceCompile(workSpacePath);
|
||||
} else if (projectName == "--experts" || projectName == "**experts") {
|
||||
//
|
||||
// Compile Experts on Workspace ...
|
||||
doPackProject = false;
|
||||
const workSpacePath = XFileTools.joinPath(".", __dirname, "Experts");
|
||||
|
||||
//
|
||||
doWorkspaceCompile(workSpacePath);
|
||||
} else if (projectName == "--helpers" || projectName == "**helpers") {
|
||||
//
|
||||
// Compile Helpers on Workspace ...
|
||||
doPackProject = false;
|
||||
const workSpacePath = XFileTools.joinPath(".", __dirname, "Helpers");
|
||||
|
||||
//
|
||||
doWorkspaceCompile(workSpacePath);
|
||||
} else if (projectName == "--classes" || projectName == "**classes") {
|
||||
//
|
||||
// Compile Classes on Workspace ...
|
||||
doPackProject = false;
|
||||
const workSpacePath = XFileTools.joinPath(".", __dirname, "Classes");
|
||||
|
||||
//
|
||||
doWorkspaceCompile(workSpacePath);
|
||||
} else if (projectName == "--indicators" || projectName == "**indicators") {
|
||||
//
|
||||
// Compile Indicators on Workspace ...
|
||||
doPackProject = false;
|
||||
const workSpacePath = XFileTools.joinPath(".", __dirname, "Indicators");
|
||||
|
||||
//
|
||||
doWorkspaceCompile(workSpacePath);
|
||||
} else if (projectName == "--libraries" || projectName == "**libraries") {
|
||||
//
|
||||
// Compile Libraries on Workspace ...
|
||||
doPackProject = false;
|
||||
const workSpacePath = XFileTools.joinPath(".", __dirname, "Libraries");
|
||||
|
||||
//
|
||||
doWorkspaceCompile(workSpacePath);
|
||||
}else if (projectName == "--strategies" || projectName == "**strategies") {
|
||||
//
|
||||
// Compile Libraries on Workspace ...
|
||||
doPackProject = false;
|
||||
const workSpacePath = XFileTools.joinPath(".", __dirname, "Strategies");
|
||||
|
||||
//
|
||||
doWorkspaceCompile(workSpacePath);
|
||||
}else if (projectName == "--parsers" || projectName == "**parsers") {
|
||||
//
|
||||
// Compile Libraries on Workspace ...
|
||||
doPackProject = false;
|
||||
const workSpacePath = XFileTools.joinPath(".", __dirname, "Parsers");
|
||||
|
||||
//
|
||||
doWorkspaceCompile(workSpacePath);
|
||||
} else {
|
||||
//
|
||||
// Compile Specific Projects ...
|
||||
//
|
||||
// Prepare Project Folder Path ...
|
||||
const prjPath = XFileTools.joinPath(projectsPath, projectName);
|
||||
|
||||
//
|
||||
// Check Project Folder Exists ...
|
||||
const isProjectFolderExists = XFileTools.isDirectoryExists(prjPath);
|
||||
if (!isProjectFolderExists) {
|
||||
//
|
||||
const msg = "Project doesn't Exists ...";
|
||||
console.log(XColorTools.applyForegroundColor(msg, XColorTools.COLOR_NAMES.Red));
|
||||
throw msg;
|
||||
}
|
||||
|
||||
//
|
||||
// Call Handler Function ...
|
||||
doProjectCompile(prjPath);
|
||||
}
|
||||
|
||||
//
|
||||
async function doProjectCompile(path = "") {
|
||||
//
|
||||
let result = await handleProjectCompile(path);
|
||||
if (result && doPackProject) {
|
||||
result = await handleProjectPack(path);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
async function doWorkspaceCompile(path = "") {
|
||||
//
|
||||
let mustCompileFiles = await readMQLFiles(path);
|
||||
|
||||
//
|
||||
if (mustCompileFiles && mustCompileFiles.length > 0) {
|
||||
//
|
||||
// Loop through items ...
|
||||
for (const f of mustCompileFiles) {
|
||||
//
|
||||
// Check Exclude ...
|
||||
const fBaseName = XFileTools.basename(f);
|
||||
let fPath = f.replace(fBaseName, "");
|
||||
let isExclude = false;
|
||||
for (const e of excludeWorkspaceFolders) {
|
||||
//
|
||||
isExclude = fPath.includes(e);
|
||||
if (isExclude) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (isExclude) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Log ...
|
||||
console.log(
|
||||
XColorTools.applyForegroundColor("try to compile: ", XColorTools.COLOR_NAMES.Yellow),
|
||||
XColorTools.applyForegroundColor(f, XColorTools.COLOR_NAMES.Blue)
|
||||
);
|
||||
|
||||
//
|
||||
const result = await compileMQLFile(f);
|
||||
|
||||
//
|
||||
if (result.includes("0 errors")) {
|
||||
//
|
||||
const msg = "compiled successfully ...";
|
||||
console.log(XColorTools.applyForegroundColor(msg, XColorTools.COLOR_NAMES.Green));
|
||||
} else {
|
||||
//
|
||||
const msg = "failed ...";
|
||||
console.log(XColorTools.applyForegroundColor(msg, XColorTools.COLOR_NAMES.Red));
|
||||
throw msg;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* read all content in project path and compile it one by one ...
|
||||
*
|
||||
* @param {string} path Project Path ...
|
||||
*/
|
||||
async function handleProjectCompile(path = "") {
|
||||
//
|
||||
let mustCompileFiles = await readMQLFiles(path);
|
||||
|
||||
//
|
||||
if (mustCompileFiles && mustCompileFiles.length > 0) {
|
||||
//
|
||||
// Loop through items ...
|
||||
for (const f of mustCompileFiles) {
|
||||
//
|
||||
// Log ...
|
||||
console.log(
|
||||
XColorTools.applyForegroundColor("try to compile: ", XColorTools.COLOR_NAMES.Yellow),
|
||||
XColorTools.applyForegroundColor(f, XColorTools.COLOR_NAMES.Blue)
|
||||
);
|
||||
|
||||
//
|
||||
const result = await compileMQLFile(f);
|
||||
|
||||
//
|
||||
if (result.includes("0 errors")) {
|
||||
//
|
||||
const msg = "compiled successfully ...";
|
||||
console.log(XColorTools.applyForegroundColor(msg, XColorTools.COLOR_NAMES.Green));
|
||||
} else {
|
||||
//
|
||||
const msg = "failed ...";
|
||||
console.log(XColorTools.applyForegroundColor(msg, XColorTools.COLOR_NAMES.Red));
|
||||
throw msg;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pack Compiled Project ...
|
||||
*
|
||||
* @param {string} path Project Path ...
|
||||
*/
|
||||
async function handleProjectPack(path = "") {
|
||||
//
|
||||
const projectName = XFileTools.basename(path);
|
||||
|
||||
//
|
||||
// check packs exists or not ...
|
||||
const isPacksExists = XFileTools.isDirectoryExists(packsPath);
|
||||
if (!isPacksExists) {
|
||||
XFileTools.createDirectory(packsPath);
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Compiled Files ...
|
||||
const mustCopyFiles = await readEXTFiles(path);
|
||||
if (!mustCopyFiles || mustCopyFiles.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
const prjPackPath = XFileTools.joinPath(packsPath, projectName);
|
||||
|
||||
//
|
||||
// Check Project Packs Folder ...
|
||||
const isProjectPackExists = XFileTools.isDirectoryExists(prjPackPath);
|
||||
if (isProjectPackExists) {
|
||||
await XFileTools.removeDirectory(prjPackPath, true);
|
||||
}
|
||||
|
||||
//
|
||||
// Create Empty Project Folder on Pack ...
|
||||
XFileTools.createDirectory(prjPackPath);
|
||||
|
||||
//
|
||||
// Loop through Files ...
|
||||
for (const f of mustCopyFiles) {
|
||||
//
|
||||
// Prepare Destination Path ...
|
||||
const fBasePath = XFileTools.basename(f);
|
||||
let fDestPath = f.replace(fBasePath, "")
|
||||
.replace(projectsPath, packsPath);
|
||||
fDestPath = fDestPath.substring(0, fDestPath.length - 1);
|
||||
|
||||
//
|
||||
const isFDestPathExists = XFileTools.isDirectoryExists(fDestPath);
|
||||
if (!isFDestPathExists) {
|
||||
XFileTools.createDirectory(fDestPath);
|
||||
}
|
||||
|
||||
//
|
||||
// Log ...
|
||||
console.log(
|
||||
XColorTools.applyForegroundColor("try to copy: ", XColorTools.COLOR_NAMES.Yellow),
|
||||
XColorTools.applyForegroundColor(f, XColorTools.COLOR_NAMES.Blue),
|
||||
XColorTools.applyForegroundColor(" to : ", XColorTools.COLOR_NAMES.Yellow),
|
||||
XColorTools.applyForegroundColor(fDestPath, XColorTools.COLOR_NAMES.Magenta)
|
||||
);
|
||||
|
||||
//
|
||||
let result = await XFileTools.copyFile(f, fDestPath);
|
||||
if (result) {
|
||||
//
|
||||
const msg = "copy successfully ...";
|
||||
console.log(
|
||||
XColorTools.applyForegroundColor(msg, XColorTools.COLOR_NAMES.Green)
|
||||
);
|
||||
} else {
|
||||
//
|
||||
const msg = "copy failed ...";
|
||||
console.log(XColorTools.applyForegroundColor(msg, XColorTools.COLOR_NAMES.Red));
|
||||
throw msg;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Project MQL files ...
|
||||
*
|
||||
* @param {string} path Folder Path ...
|
||||
* @returns
|
||||
*/
|
||||
async function readMQLFiles(path = "") {
|
||||
//
|
||||
const result = await extractFiles(path, [".mq5", ".mq4"]);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Project Compiled files ...
|
||||
*
|
||||
* @param {string} path Folder Path ...
|
||||
* @returns
|
||||
*/
|
||||
async function readEXTFiles(path = "") {
|
||||
//
|
||||
const result = await extractFiles(path, [".ex5", ".ex4"]);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile Specific MQL File ...
|
||||
*
|
||||
* @param {string} path MQL file path ...
|
||||
* @returns
|
||||
*/
|
||||
async function compileMQLFile(path = "") {
|
||||
//
|
||||
// Check File Exists ...
|
||||
const isExists = XFileTools.isFileExists(path);
|
||||
if (!isExists) {
|
||||
//
|
||||
const msg = "file not found ...";
|
||||
console.log(XColorTools.applyForegroundColor(msg, XColorTools.COLOR_NAMES.Red));
|
||||
throw msg;
|
||||
}
|
||||
|
||||
//
|
||||
const ext = XFileTools.getFileExtension(path);
|
||||
if (ext !== ".mq5" && ext !== "mq4") {
|
||||
//
|
||||
const msg = "invalid file extension ...";
|
||||
console.log(XColorTools.applyForegroundColor(msg, XColorTools.COLOR_NAMES.Red));
|
||||
throw msg;
|
||||
}
|
||||
|
||||
//
|
||||
const cwd = __dirname;
|
||||
const cmd = "compile.cmd " + path;
|
||||
|
||||
//
|
||||
const result = await XShellTools.execute(cmd, cwd);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract Specific files from a folder and it's content ...
|
||||
*
|
||||
* @param {string} path Folder Path ...
|
||||
* @returns
|
||||
*/
|
||||
async function extractFiles(path = "", ext = []) {
|
||||
//
|
||||
const result = [];
|
||||
|
||||
//
|
||||
if (!ext || ext.length == 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
const pathContent = await XFileTools.getDirectoryContents(path);
|
||||
if (!pathContent || pathContent.length == 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop through Content ...
|
||||
for (const c of pathContent) {
|
||||
//
|
||||
// Prepare full path ...
|
||||
const cPath = XFileTools.joinPath(path, c);
|
||||
|
||||
//
|
||||
// check content path is file or not ...
|
||||
const isCFile = XFileTools.isFileExists(cPath);
|
||||
const isCDirectory = XFileTools.isDirectoryExists(cPath);
|
||||
if (isCFile) {
|
||||
//
|
||||
// Check it is MQL file or not ...
|
||||
const cExt = XFileTools.getFileExtension(cPath);
|
||||
if (ext.includes(cExt)) {
|
||||
result.push(cPath);
|
||||
}
|
||||
} else if (isCDirectory) {
|
||||
//
|
||||
const destFolderName = XFileTools.basename(cPath);
|
||||
const isExcluded = excludeWorkspaceFolders.includes(destFolderName);
|
||||
if (isExcluded) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
const cFiles = await extractFiles(cPath, ext);
|
||||
if (cFiles && cFiles.length > 0) {
|
||||
result.push(...cFiles);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
//
|
||||
// Import Requirements ...
|
||||
const execSync = require("child_process").execSync;
|
||||
const XFileTools = require("./Documents/JsModules/x-file.tools");
|
||||
const XShellTools = require("./Documents/JsModules/x-shell.tools");
|
||||
const XColorTools = require("./Documents/JsModules/x-color.tools");
|
||||
|
||||
//
|
||||
handleCompile();
|
||||
async function handleCompile() {
|
||||
//
|
||||
var foldersPath = [
|
||||
"Libraries", // Required Libraries
|
||||
"Classes", // Required Classes
|
||||
"Indicators", // Required Indicators
|
||||
"Helpers", // Indicator's Helpers Classes
|
||||
"Parsers", // Strategies Filters based on Conditions
|
||||
"Strategies", // Strategies Classes which Provides Signals
|
||||
"Experts", // Expert Advisers
|
||||
];
|
||||
|
||||
//
|
||||
for (const path of foldersPath) {
|
||||
//
|
||||
const fSourcePath = XFileTools.joinPath(".", path);
|
||||
const filesToCompile = await XFileTools.extractFiles(fSourcePath, [".mq5", ".mq4"]);
|
||||
for (const f of filesToCompile) {
|
||||
//
|
||||
// Log ...
|
||||
console.log(
|
||||
XColorTools.applyForegroundColor("try to Compile: ", XColorTools.COLOR_NAMES.Yellow),
|
||||
XColorTools.applyForegroundColor(f, XColorTools.COLOR_NAMES.Blue)
|
||||
);
|
||||
|
||||
//
|
||||
await recursiveTriesToCompileFile(f, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* try to compile a file ...
|
||||
* @param {string} f
|
||||
* @param {number} numberOfTries
|
||||
*/
|
||||
async function recursiveTriesToCompileFile(f = "", numberOfTries = 0) {
|
||||
//
|
||||
let result = await handleFileCompile(f);
|
||||
if (result) {
|
||||
//
|
||||
const msg = "compiled successfully ...";
|
||||
console.log(XColorTools.applyForegroundColor(msg, XColorTools.COLOR_NAMES.Green));
|
||||
} else {
|
||||
//
|
||||
if (numberOfTries < 10) {
|
||||
//
|
||||
numberOfTries++;
|
||||
|
||||
//
|
||||
const msg = "retry (" + (numberOfTries + 1) + ") ...";
|
||||
console.log(XColorTools.applyForegroundColor(msg, XColorTools.COLOR_NAMES.LightMagenta));
|
||||
await recursiveTriesToCompileFile(f, numberOfTries);
|
||||
} else {
|
||||
//
|
||||
const msg = "failed ...";
|
||||
console.log(XColorTools.applyForegroundColor(msg, XColorTools.COLOR_NAMES.Red));
|
||||
throw msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* execute compile task on Specific File ...
|
||||
* @param {string} f file path to Execute Compile task ...
|
||||
* @returns
|
||||
*/
|
||||
async function handleFileCompile(f = "") {
|
||||
//
|
||||
let result = false;
|
||||
|
||||
//
|
||||
let exResult = await compileMQLFile(f);
|
||||
if (exResult.includes("0 errors")) {
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile Specific MQL File ...
|
||||
*
|
||||
* @param {string} path MQL file path ...
|
||||
* @returns
|
||||
*/
|
||||
async function compileMQLFile(path = "") {
|
||||
//
|
||||
// Check File Exists ...
|
||||
const isExists = XFileTools.isFileExists(path);
|
||||
if (!isExists) {
|
||||
//
|
||||
const msg = "file not found ...";
|
||||
console.log(XColorTools.applyForegroundColor(msg, XColorTools.COLOR_NAMES.Red));
|
||||
throw msg;
|
||||
}
|
||||
|
||||
//
|
||||
const ext = XFileTools.getFileExtension(path);
|
||||
if (ext !== ".mq5" && ext !== "mq4") {
|
||||
//
|
||||
const msg = "invalid file extension ...";
|
||||
console.log(XColorTools.applyForegroundColor(msg, XColorTools.COLOR_NAMES.Red));
|
||||
throw msg;
|
||||
}
|
||||
|
||||
//
|
||||
const cwd = __dirname;
|
||||
const cmd = "compile.cmd " + path;
|
||||
|
||||
//
|
||||
const result = await XShellTools.execute(cmd, cwd);
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
//
|
||||
// Import Requirements ...
|
||||
const execSync = require("child_process").execSync;
|
||||
const XFileTools = require("./Documents/JsModules/x-file.tools");
|
||||
const XShellTools = require("./Documents/JsModules/x-shell.tools");
|
||||
const XColorTools = require("./Documents/JsModules/x-color.tools");
|
||||
|
||||
//
|
||||
const packsPath = XFileTools.joinPath(".", "Packs");
|
||||
|
||||
//
|
||||
handlePack();
|
||||
async function handlePack() {
|
||||
//
|
||||
var date = new Date();
|
||||
|
||||
//
|
||||
var year = date.getFullYear();
|
||||
var month = date.getMonth() + 1;
|
||||
var day = date.getDate();
|
||||
var hour = date.getHours();
|
||||
var min = date.getMinutes();
|
||||
|
||||
//
|
||||
var folderName = year.toString() + "-" + month.toString() + "-" + day.toString() + "(" + hour.toString() + "_" + min.toString() + ")";
|
||||
|
||||
//
|
||||
const prjBasePath = XFileTools.joinPath(packsPath, folderName);
|
||||
|
||||
//
|
||||
const prjBaseSourcePath = XFileTools.joinPath(prjBasePath, "Source");
|
||||
const prjBaseCompiledPath = XFileTools.joinPath(prjBasePath, "Compile");
|
||||
|
||||
//
|
||||
const isPacksExists = XFileTools.isDirectoryExists(packsPath);
|
||||
if (!isPacksExists) {
|
||||
XFileTools.createDirectory(packsPath);
|
||||
}
|
||||
|
||||
//
|
||||
const isProjectExists = XFileTools.isDirectoryExists(prjBasePath);
|
||||
if (!isProjectExists) {
|
||||
XFileTools.createDirectory(prjBasePath);
|
||||
}
|
||||
|
||||
//
|
||||
const isPrjBaseSourcePathExists = XFileTools.isDirectoryExists(prjBaseSourcePath);
|
||||
if (!isPrjBaseSourcePathExists) {
|
||||
XFileTools.createDirectory(prjBaseSourcePath);
|
||||
}
|
||||
|
||||
//
|
||||
const isPrjBaseCompiledPathExists = XFileTools.isDirectoryExists(prjBaseCompiledPath);
|
||||
if (!isPrjBaseCompiledPathExists) {
|
||||
XFileTools.createDirectory(prjBaseCompiledPath);
|
||||
}
|
||||
|
||||
//
|
||||
var foldersPath = [
|
||||
"Classes", // Required Classes
|
||||
"Experts", // Expert Advisers
|
||||
"Helpers", // Indicator's Helpers Classes
|
||||
"Indicators", // Required Indicators
|
||||
"Libraries", // Required Libraries
|
||||
"Parsers", // Strategies Filters based on Conditions
|
||||
"Strategies", // Strategies Classes which Provides Signals
|
||||
];
|
||||
|
||||
//
|
||||
for (const path of foldersPath) {
|
||||
//
|
||||
const fSourcePath = XFileTools.joinPath(".", path);
|
||||
|
||||
//
|
||||
// Source Copy ...
|
||||
let fDestPath = XFileTools.joinPath(prjBaseSourcePath, path);
|
||||
|
||||
//
|
||||
// Log ...
|
||||
console.log(
|
||||
XColorTools.applyForegroundColor("try to copy: ", XColorTools.COLOR_NAMES.Yellow),
|
||||
XColorTools.applyForegroundColor(path, XColorTools.COLOR_NAMES.Blue),
|
||||
XColorTools.applyForegroundColor(" to : ", XColorTools.COLOR_NAMES.Yellow),
|
||||
XColorTools.applyForegroundColor(prjBaseSourcePath, XColorTools.COLOR_NAMES.Magenta)
|
||||
);
|
||||
|
||||
//
|
||||
// Copy Folder ...
|
||||
let result = await XFileTools.copyFolder(fSourcePath, prjBaseSourcePath);
|
||||
if (result) {
|
||||
//
|
||||
const msg = "copy successfully ...";
|
||||
console.log(
|
||||
XColorTools.applyForegroundColor(msg, XColorTools.COLOR_NAMES.Green)
|
||||
);
|
||||
} else {
|
||||
//
|
||||
const msg = "copy failed ...";
|
||||
console.log(XColorTools.applyForegroundColor(msg, XColorTools.COLOR_NAMES.Red));
|
||||
throw msg;
|
||||
}
|
||||
|
||||
//
|
||||
// Cleanup Folder ...
|
||||
const sourceFilesToRemove = await XFileTools.extractFiles(fDestPath, [".ex5", ".ex4"]);
|
||||
for (const f of sourceFilesToRemove) {
|
||||
await XFileTools.removeFile(f);
|
||||
}
|
||||
|
||||
//
|
||||
// Compile Copy ...
|
||||
fDestPath = XFileTools.joinPath(prjBaseCompiledPath, path);
|
||||
|
||||
//
|
||||
// Log ...
|
||||
console.log(
|
||||
XColorTools.applyForegroundColor("try to copy: ", XColorTools.COLOR_NAMES.Yellow),
|
||||
XColorTools.applyForegroundColor(path, XColorTools.COLOR_NAMES.Blue),
|
||||
XColorTools.applyForegroundColor(" to : ", XColorTools.COLOR_NAMES.Yellow),
|
||||
XColorTools.applyForegroundColor(prjBaseCompiledPath, XColorTools.COLOR_NAMES.Magenta)
|
||||
);
|
||||
|
||||
//
|
||||
// Copy Folder ...
|
||||
result = await XFileTools.copyFolder(fSourcePath, prjBaseCompiledPath);
|
||||
if (result) {
|
||||
//
|
||||
const msg = "copy successfully ...";
|
||||
console.log(
|
||||
XColorTools.applyForegroundColor(msg, XColorTools.COLOR_NAMES.Green)
|
||||
);
|
||||
} else {
|
||||
//
|
||||
const msg = "copy failed ...";
|
||||
console.log(XColorTools.applyForegroundColor(msg, XColorTools.COLOR_NAMES.Red));
|
||||
throw msg;
|
||||
}
|
||||
|
||||
//
|
||||
// Cleanup Folder ...
|
||||
const compileFilesToRemove = await XFileTools.extractFiles(fDestPath, [".mq5", ".mq4"]);
|
||||
for (const f of compileFilesToRemove) {
|
||||
await XFileTools.removeFile(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "mql5",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"true": "",
|
||||
"aaa": "|----------|",
|
||||
"aab": "| Commons |",
|
||||
"aac": "|----------|",
|
||||
"compile": "node compile.js",
|
||||
"pack": "node pack.js",
|
||||
"cleanupEx": "node cleanupEx.js",
|
||||
"compileEA": "node compileEA.js",
|
||||
"compileExperts": "npm run compile **experts",
|
||||
"compileLibraries": "npm run compile **libraries",
|
||||
"compileHelpers": "npm run compile **helpers",
|
||||
"compileClasses": "npm run compile **classes",
|
||||
"compileStrategies": "npm run compile **strategies",
|
||||
"compileIndicators": "npm run compile **indicators",
|
||||
"rmExpertsEx": "shx --silent rm -r ./Experts/*.ex5 || npm run true",
|
||||
"rmLibrariesEx": "shx --silent rm -r ./Libraries/*.ex5 || npm run true",
|
||||
"rmHelpersEx": "shx --silent rm -r ./Helpers/*.ex5 || npm run true",
|
||||
"rmStrategiesEx": "shx --silent rm -r ./Strategies/*.ex5 || npm run true",
|
||||
"rmClassesEx": "shx --silent rm -r ./Classes/*.ex5 || npm run true",
|
||||
"rmIndicatorsEx": "shx --silent rm -r ./Indicators/*.ex5 || npm run true",
|
||||
"prepareWorkspace": "npm run cleanupEx && npm run compileEA",
|
||||
"generatePack": "npm run prepareWorkspace && npm run pack && npm run cleanupEx && npm run compileLibraries && npm run compileIndicators"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.saherelmhub.ir/saherelm/MQL5TestWorkspace.git"
|
||||
},
|
||||
"author": "Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"shx": "^0.3.4"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user