Backup Workspace ...
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Class Token ...
|
||||
virtual string GetToken() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// 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,997 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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()
|
||||
{
|
||||
//
|
||||
delete mTrader;
|
||||
}
|
||||
|
||||
//
|
||||
// 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();
|
||||
HandleStrategiesGuard();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 mTrader;
|
||||
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()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Strategies for Guards and then Apply Them ...
|
||||
*/
|
||||
virtual void HandleStrategiesGuard()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// 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
@@ -0,0 +1,580 @@
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: XSTR
|
||||
// Description: Super Trend 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 X121_XAMA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
#define ShortName "XSTR"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "ATR";
|
||||
input int atrLength = 14; // Length
|
||||
input double atrMultiplier = 3.0; // Multiplier
|
||||
input ENUM_APPLIED_PRICE atrAppliedTo = PRICE_MEDIAN; // Applied To
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
input bool showTrends = true; // Show Trends
|
||||
input bool fillTrends = true; // Fill Trends
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 9
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
#define fillUpBufferIndex 0
|
||||
double fillUpBuffer[];
|
||||
|
||||
#define fillDownBufferIndex 1
|
||||
double fillDownBuffer[];
|
||||
|
||||
//
|
||||
#define fillingPlotBufferIndex 0
|
||||
|
||||
//
|
||||
#property indicator_label1 "XSTR Filling"
|
||||
#property indicator_type1 DRAW_FILLING
|
||||
#property indicator_color1 clrBisque, clrPaleGreen
|
||||
|
||||
//
|
||||
#define mainBufferIndex 2
|
||||
#define mainPlotBufferIndex 1
|
||||
double mainBuffer[];
|
||||
|
||||
//
|
||||
#define mainColorBufferIndex 3
|
||||
double mainColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "XSTR"
|
||||
#property indicator_type2 DRAW_COLOR_LINE
|
||||
#property indicator_color2 CLR_NONE, clrGreen, clrDarkRed
|
||||
#property indicator_style2 STYLE_DOT
|
||||
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
#define atrBufferIndex 4
|
||||
double atrBuffer[];
|
||||
|
||||
//
|
||||
#define trendBufferIndex 5
|
||||
double trendBuffer[];
|
||||
|
||||
//
|
||||
#define upBufferIndex 6
|
||||
double upBuffer[];
|
||||
|
||||
//
|
||||
#define downBufferIndex 7
|
||||
double downBuffer[];
|
||||
|
||||
//
|
||||
#define priceBufferIndex 8
|
||||
double priceBuffer[];
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int atrHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
int changeOfTrend;
|
||||
int startBearishTrend;
|
||||
int startBullishTrend;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
atrHandler = iATR(
|
||||
_Symbol,
|
||||
_Period,
|
||||
atrLength);
|
||||
if (atrHandler == INVALID_HANDLE)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
IndicatorRelease(atrHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
int numOfRequiredAtrs;
|
||||
if (prev_calculated > rates_total || prev_calculated < 0)
|
||||
{
|
||||
numOfRequiredAtrs = rates_total;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
numOfRequiredAtrs = rates_total - prev_calculated;
|
||||
if (prev_calculated > 0)
|
||||
{
|
||||
numOfRequiredAtrs++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Checking for stop ...
|
||||
if (IsStopped())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Number of items Copy or not ...
|
||||
int copiedATRs = CopyBuffer(atrHandler, 0, 0, numOfRequiredAtrs, atrBuffer);
|
||||
if (copiedATRs <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
int limit;
|
||||
|
||||
//
|
||||
// checking for the limit start of calculation of an indicator ...
|
||||
if (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
{
|
||||
//
|
||||
// starting index for calculation of all bars ...
|
||||
limit = maxLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// starting number for calculation of new bars
|
||||
limit = prev_calculated - 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
// Calculated Price ...
|
||||
double price = getPrice(
|
||||
atrAppliedTo,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
i);
|
||||
// price = (high[i] + low[i]) / 2;
|
||||
priceBuffer[i] = price;
|
||||
|
||||
//
|
||||
double atr = atrBuffer[i];
|
||||
|
||||
//
|
||||
// Up ...
|
||||
upBuffer[i] = price + (atrMultiplier * atr);
|
||||
|
||||
//
|
||||
// Down ...
|
||||
downBuffer[i] = price - (atrMultiplier * atr);
|
||||
|
||||
//
|
||||
if (close[i] > upBuffer[i - 1])
|
||||
{
|
||||
//
|
||||
trendBuffer[i] = 1;
|
||||
if (trendBuffer[i - 1] == -1)
|
||||
{
|
||||
changeOfTrend = 1;
|
||||
}
|
||||
}
|
||||
else if (close[i] < downBuffer[i - 1])
|
||||
{
|
||||
//
|
||||
trendBuffer[i] = -1;
|
||||
if (trendBuffer[i - 1] == 1)
|
||||
{
|
||||
changeOfTrend = 1;
|
||||
}
|
||||
}
|
||||
else if (trendBuffer[i - 1] == 1)
|
||||
{
|
||||
//
|
||||
trendBuffer[i] = 1;
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
else if (trendBuffer[i - 1] == -1)
|
||||
{
|
||||
//
|
||||
trendBuffer[i] = -1;
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Down Trend Starting ...
|
||||
if (trendBuffer[i] < 0 && trendBuffer[i - 1] > 0)
|
||||
{
|
||||
startBearishTrend = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
startBearishTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Up Trend Starting ...
|
||||
if (trendBuffer[i] > 0 && trendBuffer[i - 1] < 0)
|
||||
{
|
||||
startBullishTrend = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
startBullishTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
if (trendBuffer[i] > 0 && downBuffer[i] < downBuffer[i - 1])
|
||||
{
|
||||
downBuffer[i] = downBuffer[i - 1];
|
||||
}
|
||||
|
||||
//
|
||||
if (trendBuffer[i] < 0 && upBuffer[i] > upBuffer[i - 1])
|
||||
{
|
||||
upBuffer[i] = upBuffer[i - 1];
|
||||
}
|
||||
|
||||
//
|
||||
if (startBearishTrend == 1)
|
||||
{
|
||||
upBuffer[i] = priceBuffer[i] + (atrMultiplier * atr);
|
||||
}
|
||||
|
||||
//
|
||||
if (startBullishTrend == 1)
|
||||
{
|
||||
downBuffer[i] = priceBuffer[i] - (atrMultiplier * atr);
|
||||
}
|
||||
|
||||
//
|
||||
// Draw the indicator ...
|
||||
|
||||
//
|
||||
double colorIDX = 0;
|
||||
mainColorBuffer[i] = colorIDX;
|
||||
|
||||
//
|
||||
if (trendBuffer[i] == 1)
|
||||
{
|
||||
//
|
||||
mainBuffer[i] = downBuffer[i];
|
||||
if (changeOfTrend == 1)
|
||||
{
|
||||
mainBuffer[i - 1] = mainBuffer[i - 2];
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
colorIDX = 1;
|
||||
}
|
||||
else if (trendBuffer[i] == -1)
|
||||
{
|
||||
//
|
||||
mainBuffer[i] = upBuffer[i];
|
||||
if (changeOfTrend == 1)
|
||||
{
|
||||
//
|
||||
mainBuffer[i - 1] = mainBuffer[i - 2];
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
colorIDX = 2;
|
||||
}
|
||||
|
||||
//
|
||||
if (showTrends)
|
||||
{
|
||||
mainColorBuffer[i] = colorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
// Filling ...
|
||||
if (fillTrends)
|
||||
{
|
||||
//
|
||||
fillUpBuffer[i] = mainBuffer[i];
|
||||
fillDownBuffer[i] = close[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
fillUpBuffer[i] = EMPTY_VALUE;
|
||||
fillDownBuffer[i] = EMPTY_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result =
|
||||
//
|
||||
atrLength >= 2
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = atrLength;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// PLOT Buffers ...
|
||||
|
||||
//
|
||||
// FILLINGS ...
|
||||
SetIndexBuffer(fillUpBufferIndex, fillUpBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(fillDownBufferIndex, fillDownBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fillingPlotBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// MAIN ...
|
||||
SetIndexBuffer(mainBufferIndex, mainBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(mainPlotBufferIndex, PLOT_SHOW_DATA, showTrends);
|
||||
SetIndexBuffer(mainColorBufferIndex, mainColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// TREND ...
|
||||
SetIndexBuffer(trendBufferIndex, trendBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// UP ...
|
||||
SetIndexBuffer(upBufferIndex, upBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// DOWN ...
|
||||
SetIndexBuffer(downBufferIndex, downBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// PRICE ...
|
||||
SetIndexBuffer(priceBufferIndex, priceBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// TEMPLATE Function ...
|
||||
|
||||
template <typename T>
|
||||
double getPrice(ENUM_APPLIED_PRICE tprice, T &open[], T &high[], T &low[], T &close[], int i)
|
||||
{
|
||||
switch (tprice)
|
||||
{
|
||||
case PRICE_CLOSE:
|
||||
return (close[i]);
|
||||
case PRICE_OPEN:
|
||||
return (open[i]);
|
||||
case PRICE_HIGH:
|
||||
return (high[i]);
|
||||
case PRICE_LOW:
|
||||
return (low[i]);
|
||||
case PRICE_MEDIAN:
|
||||
return ((high[i] + low[i]) / 2.0);
|
||||
case PRICE_TYPICAL:
|
||||
return ((high[i] + low[i] + close[i]) / 3.0);
|
||||
case PRICE_WEIGHTED:
|
||||
return ((high[i] + low[i] + close[i] + close[i]) / 4.0);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| SuperTrend.mq5 |
|
||||
//| Copyright 2011, FxGeek |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2011, FxGeek"
|
||||
#property link " http://www.mql5.com"
|
||||
#property version "1.00"
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 9
|
||||
#property indicator_plots 2
|
||||
|
||||
#property indicator_label1 "Filling"
|
||||
#property indicator_type1 DRAW_FILLING
|
||||
#property indicator_color1 clrBisque, clrPaleGreen
|
||||
|
||||
#property indicator_label2 "SuperTrend"
|
||||
#property indicator_type2 DRAW_COLOR_LINE
|
||||
#property indicator_color2 clrGreen, clrRed
|
||||
|
||||
input int Periode=10;
|
||||
input double Multiplier=3;
|
||||
input bool Show_Filling=true; // Show as DRAW_FILLING
|
||||
|
||||
double Filled_a[];
|
||||
double Filled_b[];
|
||||
double SuperTrend[];
|
||||
double ColorBuffer[];
|
||||
double Atr[];
|
||||
double Up[];
|
||||
double Down[];
|
||||
double Middle[];
|
||||
double trend[];
|
||||
|
||||
int atrHandle;
|
||||
int changeOfTrend;
|
||||
int flag;
|
||||
int flagh;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,Filled_a,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,Filled_b,INDICATOR_DATA);
|
||||
SetIndexBuffer(2,SuperTrend,INDICATOR_DATA);
|
||||
SetIndexBuffer(3,ColorBuffer,INDICATOR_COLOR_INDEX);
|
||||
SetIndexBuffer(4,Atr,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(5,Up,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(6,Down,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(7,Middle,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(8,trend,INDICATOR_CALCULATIONS);
|
||||
|
||||
atrHandle=iATR(_Symbol,_Period,Periode);
|
||||
//---
|
||||
return(0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
//---
|
||||
int to_copy;
|
||||
if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-prev_calculated;
|
||||
if(prev_calculated>0) to_copy++;
|
||||
}
|
||||
|
||||
if(IsStopped()) return(0); //Checking for stop flag
|
||||
if(CopyBuffer(atrHandle,0,0,to_copy,Atr)<=0)
|
||||
{
|
||||
Print("Getting Atr is failed! Error",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
|
||||
int first;
|
||||
if(prev_calculated>rates_total || prev_calculated<=0) // checking for the first start of calculation of an indicator
|
||||
{
|
||||
first=Periode; // starting index for calculation of all bars
|
||||
}
|
||||
else
|
||||
{
|
||||
first=prev_calculated-1; // starting number for calculation of new bars
|
||||
}
|
||||
for(int i=first; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
Middle[i]=(high[i]+low[i])/2;
|
||||
Up[i] = Middle[i] +(Multiplier*Atr[i]);
|
||||
Down[i]= Middle[i] -(Multiplier*Atr[i]);
|
||||
|
||||
if(close[i]>Up[i-1])
|
||||
{
|
||||
trend[i]=1;
|
||||
if(trend[i-1]==-1) changeOfTrend=1;
|
||||
|
||||
}
|
||||
else if(close[i]<Down[i-1])
|
||||
{
|
||||
trend[i]=-1;
|
||||
if(trend[i-1]==1) changeOfTrend=1;
|
||||
}
|
||||
else if(trend[i-1]==1)
|
||||
{
|
||||
trend[i]=1;
|
||||
changeOfTrend=0;
|
||||
}
|
||||
else if(trend[i-1]==-1)
|
||||
{
|
||||
trend[i]=-1;
|
||||
changeOfTrend=0;
|
||||
}
|
||||
|
||||
if(trend[i]<0 && trend[i-1]>0)
|
||||
{
|
||||
flag=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
flag=0;
|
||||
}
|
||||
|
||||
if(trend[i]>0 && trend[i-1]<0)
|
||||
{
|
||||
flagh=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
flagh=0;
|
||||
}
|
||||
|
||||
if(trend[i]>0 && Down[i]<Down[i-1])
|
||||
Down[i]=Down[i-1];
|
||||
|
||||
if(trend[i]<0 && Up[i]>Up[i-1])
|
||||
Up[i]=Up[i-1];
|
||||
|
||||
if(flag==1)
|
||||
Up[i]=Middle[i]+(Multiplier*Atr[i]);
|
||||
|
||||
if(flagh==1)
|
||||
Down[i]=Middle[i]-(Multiplier*Atr[i]);
|
||||
|
||||
//-- Draw the indicator
|
||||
if(trend[i]==1)
|
||||
{
|
||||
SuperTrend[i]=Down[i];
|
||||
if(changeOfTrend==1)
|
||||
{
|
||||
SuperTrend[i-1]=SuperTrend[i-2];
|
||||
changeOfTrend=0;
|
||||
}
|
||||
ColorBuffer[i]=0.0;
|
||||
}
|
||||
else if(trend[i]==-1)
|
||||
{
|
||||
SuperTrend[i]=Up[i];
|
||||
if(changeOfTrend==1)
|
||||
{
|
||||
SuperTrend[i-1]= SuperTrend[i-2];
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
ColorBuffer[i]=1.0;
|
||||
}
|
||||
|
||||
if(Show_Filling)
|
||||
{
|
||||
Filled_a[i]= SuperTrend[i];
|
||||
Filled_b[i]= close[i];
|
||||
}else{
|
||||
Filled_a[i]= EMPTY_VALUE;
|
||||
Filled_b[i]= EMPTY_VALUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
|
||||
|
||||
@@ -0,0 +1,319 @@
|
||||
|
||||
//
|
||||
// Reading Previous Conditions ...
|
||||
ENUM_XPOI_EVENTS consolidationPoiEventsPrev[];
|
||||
ENUM_X_CYCLE_EVENTS consolidationCycleEventsPrev[];
|
||||
X121SMCCycleConditions consolidationConditionsPrev;
|
||||
result = consolidationCycleHelper.GetConditions(
|
||||
consolidationCycleEventsPrev,
|
||||
consolidationPoiEventsPrev,
|
||||
consolidationConditionsPrev,
|
||||
cIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
X121SMCCycleConditions conditionState = consolidationConditions;
|
||||
X121SMCCycleConditions conditionStatePrev = consolidationConditionsPrev;
|
||||
|
||||
//
|
||||
XOHCL cCBar;
|
||||
result = cCBar.Init(
|
||||
conditionState.symbol,
|
||||
conditionState.period,
|
||||
cIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL cPBar;
|
||||
result = cCBar.GetPreviousBar(cPBar);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Engulf ...
|
||||
ENUM_X_DIRECTION cCBarEngulfDir;
|
||||
bool isCCBarEngulfed = consolidationCycleHelper
|
||||
.mBarAnalyser
|
||||
.IsEngulfBar(
|
||||
cCBar,
|
||||
cCBarEngulfDir,
|
||||
0 // Extended ...
|
||||
);
|
||||
bool isCCBarBullishEngulfed =
|
||||
isCCBarEngulfed &&
|
||||
IsBullish(cCBarEngulfDir);
|
||||
bool isCCBarBearishEngulfed =
|
||||
isCCBarEngulfed &&
|
||||
IsBearish(cCBarEngulfDir);
|
||||
|
||||
//
|
||||
// Momentum ...
|
||||
ENUM_X_DIRECTION cCBarMomentumDir;
|
||||
bool isCCBarMomentum = consolidationCycleHelper
|
||||
.mBarAnalyser
|
||||
.IsMomentumBar(
|
||||
cCBar,
|
||||
cCBarMomentumDir,
|
||||
1 // Extended ...
|
||||
);
|
||||
bool isCCBarBullishMomentum =
|
||||
isCCBarMomentum &&
|
||||
IsBullish(cCBarMomentumDir);
|
||||
bool isCCBarBearishMomentum =
|
||||
isCCBarMomentum &&
|
||||
IsBearish(cCBarMomentumDir);
|
||||
|
||||
//
|
||||
// Reject ...
|
||||
ENUM_X_DIRECTION cCBarRejectDir;
|
||||
bool isCCBarRejected = consolidationCycleHelper
|
||||
.mBarAnalyser
|
||||
.IsRejectionBar(
|
||||
cCBar,
|
||||
cCBarRejectDir,
|
||||
1 // Extended ...
|
||||
);
|
||||
bool isCCBarBullishRejected =
|
||||
isCCBarRejected &&
|
||||
IsBullish(cCBarRejectDir);
|
||||
bool isCCBarBearishRejected =
|
||||
isCCBarRejected &&
|
||||
IsBearish(cCBarRejectDir);
|
||||
|
||||
//
|
||||
// Bar Checking Summary ...
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
bool isCCBarPassedBullish =
|
||||
//
|
||||
isCCBarBullishEngulfed ||
|
||||
isCCBarBullishMomentum ||
|
||||
isCCBarBullishRejected
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Bearish ...
|
||||
bool isCCBarPassedBearish =
|
||||
//
|
||||
isCCBarBearishEngulfed ||
|
||||
isCCBarBearishMomentum ||
|
||||
isCCBarBearishRejected
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
double cPeakPrev = conditionStatePrev.x121Conditions.peaksBuffer[0];
|
||||
double cValePrev = conditionStatePrev.x121Conditions.valesBuffer[0];
|
||||
|
||||
//
|
||||
double cPeak = conditionState.x121Conditions.peaksBuffer[1];
|
||||
double cVale = conditionState.x121Conditions.valesBuffer[1];
|
||||
|
||||
//
|
||||
bool isCPeakSame = cPeak == cPeakPrev;
|
||||
bool isCValeSame = cVale == cValePrev;
|
||||
|
||||
//
|
||||
bool isCNewPeakPrev = conditionStatePrev.x121Conditions.isNewPeak;
|
||||
bool isCNewPeakOverLastPrev = conditionStatePrev.x121Conditions.isNewPeakOverLast;
|
||||
bool isCNewPeakUnderLastPrev = conditionStatePrev.x121Conditions.isNewPeakUnderLast;
|
||||
|
||||
//
|
||||
bool isCNewValePrev = conditionStatePrev.x121Conditions.isNewVale;
|
||||
bool isCNewValeOverLastPrev = conditionStatePrev.x121Conditions.isNewValeOverLast;
|
||||
bool isCNewValeUnderLastPrev = conditionStatePrev.x121Conditions.isNewValeUnderLast;
|
||||
|
||||
//
|
||||
bool isCRSIOverSold = conditionState.x121Conditions.isRSIOverSold;
|
||||
bool isCRSICrossedOverOverSold = conditionState.x121Conditions.isRSICrossedOverOverSold;
|
||||
bool isCRSICrossedUnderOverSold = conditionState.x121Conditions.isRSICrossedUnderOverSold;
|
||||
|
||||
//
|
||||
bool isCRSIOverBought = conditionState.x121Conditions.isRSIOverBought;
|
||||
bool isCRSICrossedOverOverBought = conditionState.x121Conditions.isRSICrossedOverOverBought;
|
||||
bool isCRSICrossedUnderOverBought = conditionState.x121Conditions.isRSICrossedUnderOverBought;
|
||||
|
||||
//
|
||||
bool isCRSIOverSoldPrev = conditionStatePrev.x121Conditions.isRSIOverSold;
|
||||
bool isCRSICrossedOverOverSoldPrev = conditionStatePrev.x121Conditions.isRSICrossedOverOverSold;
|
||||
bool isCRSICrossedUnderOverSoldPrev = conditionStatePrev.x121Conditions.isRSICrossedUnderOverSold;
|
||||
|
||||
//
|
||||
bool isCRSIOverBoughtPrev = conditionStatePrev.x121Conditions.isRSIOverBought;
|
||||
bool isCRSICrossedOverOverBoughtPrev = conditionStatePrev.x121Conditions.isRSICrossedOverOverBought;
|
||||
bool isCRSICrossedUnderOverBoughtPrev = conditionStatePrev.x121Conditions.isRSICrossedUnderOverBought;
|
||||
|
||||
//
|
||||
isBullish =
|
||||
//
|
||||
isCNewValePrev &&
|
||||
isCCBarPassedBullish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
//
|
||||
isCNewPeakPrev &&
|
||||
isCCBarPassedBearish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.pivot =
|
||||
isBullish
|
||||
? conditionState.x121Conditions.valesBuffer[1]
|
||||
: conditionState.x121Conditions.peaksBuffer[1];
|
||||
|
||||
//
|
||||
double peak = analyseConditions.x121Conditions.peaksBuffer[1];
|
||||
double vale = analyseConditions.x121Conditions.valesBuffer[1];
|
||||
|
||||
//
|
||||
double strUpper = analyseConditions.x121Conditions.strUpBuffer[1];
|
||||
double strLower = analyseConditions.x121Conditions.strDownBuffer[1];
|
||||
|
||||
//
|
||||
bool isStrSwitchedToBullish = analyseConditions.x121Conditions.isStrSwitchedToBullish;
|
||||
bool isStrSwitchedToBearish = analyseConditions.x121Conditions.isStrSwitchedToBearish;
|
||||
|
||||
//
|
||||
isBullish = isStrSwitchedToBullish;
|
||||
isBearish = isStrSwitchedToBearish;
|
||||
|
||||
//
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.pivot =
|
||||
isBullish
|
||||
? peak
|
||||
: vale;
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Looking For Sar Change ...
|
||||
|
||||
//
|
||||
double sar = analyseConditions.x121Conditions.sarBuffer[1];
|
||||
|
||||
//
|
||||
double peak = analyseConditions.x121Conditions.peaksBuffer[1];
|
||||
double vale = analyseConditions.x121Conditions.valesBuffer[1];
|
||||
|
||||
//
|
||||
bool isSarEqualsToPeak = analyseConditions.x121Conditions.isSarEqualsToPeak;
|
||||
bool isSarEqualsToVale = analyseConditions.x121Conditions.isSarEqualsToVale;
|
||||
|
||||
//
|
||||
bool isSarSwitchedToBullish = analyseConditions.x121Conditions.isSarSwitchedToBullish;
|
||||
bool isSarSwitchedToBearish = analyseConditions.x121Conditions.isSarSwitchedToBearish;
|
||||
|
||||
//
|
||||
isBullish =
|
||||
isBullish &&
|
||||
isSarEqualsToPeak &&
|
||||
isSarSwitchedToBullish;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
isBearish &&
|
||||
isSarEqualsToVale &&
|
||||
isSarSwitchedToBearish;
|
||||
|
||||
//
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
Print("Sar Switched ...");
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Detect a Zone Arround Price Zone ...
|
||||
int supplyZonesCount = consolidationState.CountSupplyZones();
|
||||
if (IsValidSize(supplyZonesCount)) {
|
||||
//
|
||||
for (int i = 0; i < supplyZonesCount; i++) {
|
||||
//
|
||||
XCSupplyZone *iZone = consolidationState.supplyZones[i];
|
||||
|
||||
//
|
||||
bool isOver = iZone.Lower() > pzUpper;
|
||||
bool isUnder = iZone.Upper() < pzLower;
|
||||
|
||||
//
|
||||
bool isValid =
|
||||
isOver ||
|
||||
isUnder;
|
||||
if (isValid) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Method 1 ...
|
||||
// VWap Switch Start ...
|
||||
|
||||
//
|
||||
bool bullishMethod1 =
|
||||
//
|
||||
isSarBullish &&
|
||||
isStrBullish &&
|
||||
isSlopesBullish &&
|
||||
hasBullishTrend &&
|
||||
cBar.IsBullish() &&
|
||||
isAtrBullishSlope &&
|
||||
isPVBullishFormed &&
|
||||
isRsiBullishFormed &&
|
||||
isVWapBullishFormed
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool bearishMethod1 =
|
||||
//
|
||||
isSarBearish &&
|
||||
isStrBearish &&
|
||||
isSlopesBearish &&
|
||||
hasBearishTrend &&
|
||||
cBar.IsBearish() &&
|
||||
isAtrBearishSlope &&
|
||||
isPVBearishFormed &&
|
||||
isRsiBearishFormed &&
|
||||
isVWapBearishFormed
|
||||
//
|
||||
;
|
||||
@@ -0,0 +1,530 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
////// Detect Price Zones :
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
XPriceZones priceZone;
|
||||
bool isPriceZoneValidForPeak;
|
||||
bool isPriceZoneValidForVale;
|
||||
|
||||
//
|
||||
priceZone.Clean();
|
||||
isPriceZoneValidForPeak = false;
|
||||
isPriceZoneValidForVale = false;
|
||||
|
||||
//
|
||||
// Detect Price Zone ...
|
||||
|
||||
//
|
||||
double pzPeak = decisionXConditions.peaksBuffer[1];
|
||||
double pzVale = decisionXConditions.valesBuffer[1];
|
||||
|
||||
//
|
||||
// Detecting Decision Price ones ...
|
||||
XPriceZones decisionPriceZone;
|
||||
bool hasDecisionPriceZone = CalculatePriceInsideZones(
|
||||
decisionPriceZone,
|
||||
decisionState,
|
||||
cBar //
|
||||
);
|
||||
double decisionPriceZoneUpper = 0;
|
||||
double decisionPriceZoneLower = 0;
|
||||
bool isDecisionPriceZoneValidForPeak = false;
|
||||
bool isDecisionPriceZoneValidForVale = false;
|
||||
if (hasDecisionPriceZone)
|
||||
{
|
||||
//
|
||||
bool hasBoundary = decisionPriceZone.GetBoundary(
|
||||
X_DIRECTION_ALL,
|
||||
decisionPriceZoneUpper,
|
||||
decisionPriceZoneLower //
|
||||
);
|
||||
|
||||
//
|
||||
isDecisionPriceZoneValidForPeak =
|
||||
hasBoundary &&
|
||||
pzPeak <= decisionPriceZoneUpper &&
|
||||
pzPeak >= decisionPriceZoneLower;
|
||||
|
||||
//
|
||||
isDecisionPriceZoneValidForVale =
|
||||
hasBoundary &&
|
||||
pzVale <= decisionPriceZoneUpper &&
|
||||
pzVale >= decisionPriceZoneLower;
|
||||
}
|
||||
|
||||
//
|
||||
// Detecting Analyse Price ones ...
|
||||
XPriceZones analysePriceZone;
|
||||
bool hasAnalysePriceZone = CalculatePriceInsideZones(
|
||||
analysePriceZone,
|
||||
analyseState,
|
||||
cBar //
|
||||
);
|
||||
double analysePriceZoneUpper = 0;
|
||||
double analysePriceZoneLower = 0;
|
||||
bool isAnalysePriceZoneValidForPeak = false;
|
||||
bool isAnalysePriceZoneValidForVale = false;
|
||||
if (hasAnalysePriceZone)
|
||||
{
|
||||
//
|
||||
bool hasBoundary = analysePriceZone.GetBoundary(
|
||||
X_DIRECTION_ALL,
|
||||
analysePriceZoneUpper,
|
||||
analysePriceZoneLower //
|
||||
);
|
||||
|
||||
//
|
||||
isAnalysePriceZoneValidForPeak =
|
||||
hasBoundary &&
|
||||
pzPeak <= analysePriceZoneUpper &&
|
||||
pzPeak >= analysePriceZoneLower;
|
||||
|
||||
//
|
||||
isAnalysePriceZoneValidForVale =
|
||||
hasBoundary &&
|
||||
pzVale <= analysePriceZoneUpper &&
|
||||
pzVale >= analysePriceZoneLower;
|
||||
}
|
||||
|
||||
//
|
||||
// Detecting Verification Price ones ...
|
||||
XPriceZones verificationPriceZone;
|
||||
bool hasVerificationPriceZone = CalculatePriceInsideZones(
|
||||
verificationPriceZone,
|
||||
verificationState,
|
||||
cBar //
|
||||
);
|
||||
double verificationPriceZoneUpper = 0;
|
||||
double verificationPriceZoneLower = 0;
|
||||
bool isVerificationPriceZoneValidForPeak = false;
|
||||
bool isVerificationPriceZoneValidForVale = false;
|
||||
if (hasVerificationPriceZone)
|
||||
{
|
||||
//
|
||||
bool hasBoundary = verificationPriceZone.GetBoundary(
|
||||
X_DIRECTION_ALL,
|
||||
verificationPriceZoneUpper,
|
||||
verificationPriceZoneLower //
|
||||
);
|
||||
|
||||
//
|
||||
isVerificationPriceZoneValidForPeak =
|
||||
hasBoundary &&
|
||||
pzPeak <= verificationPriceZoneUpper &&
|
||||
pzPeak >= verificationPriceZoneLower;
|
||||
|
||||
//
|
||||
isVerificationPriceZoneValidForVale =
|
||||
hasBoundary &&
|
||||
pzVale <= verificationPriceZoneUpper &&
|
||||
pzVale >= verificationPriceZoneLower;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
////// Detect Pivot Zones :
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
double X121SMCXPivotPeak;
|
||||
double X121SMCXPivotVale;
|
||||
datetime X121SMCXPivotEnd;
|
||||
datetime X121SMCXPivotStart;
|
||||
ENUM_XPV_PIVOTS X121SMCXPivotType = XPV_NONE;
|
||||
|
||||
//
|
||||
// Detect PV Pivot ...
|
||||
|
||||
//
|
||||
bool isPivotPeakZoneRejected = false;
|
||||
bool isPivotPeakZoneBreakedUp = false;
|
||||
bool isPivotPeakZoneBreakedDown = false;
|
||||
bool isPivotValeZoneRejected = false;
|
||||
bool isPivotValeZoneBreakedUp = false;
|
||||
bool isPivotValeZoneBreakedDown = false;
|
||||
bool hasPivot = conditions.pivotZone.IsValid();
|
||||
if (!hasPivot)
|
||||
{
|
||||
//
|
||||
hasPivot = IsValid(X121SMCXPivotStart);
|
||||
if (!hasPivot)
|
||||
{
|
||||
//
|
||||
bool isNewVale = decisionXConditions.isNewVale;
|
||||
bool isNewValeOverLast = decisionXConditions.isNewValeOverLast;
|
||||
bool isNewValeUnderLast = decisionXConditions.isNewValeUnderLast;
|
||||
bool isSameVales = decisionXConditions.valesBuffer[1] ==
|
||||
decisionXConditions.valesBuffer[2] &&
|
||||
decisionXConditions.valesBuffer[2] ==
|
||||
decisionXConditions.valesBuffer[3];
|
||||
bool isSameCycleVales = decisionXConditions.valesBuffer[1] ==
|
||||
analyseXConditions.valesBuffer[1] &&
|
||||
analyseXConditions.valesBuffer[1] ==
|
||||
verificationXConditions.valesBuffer[1];
|
||||
|
||||
//
|
||||
bool isNewPeak = decisionXConditions.isNewPeak;
|
||||
bool isNewPeakOverLast = decisionXConditions.isNewPeakOverLast;
|
||||
bool isNewPeakUnderLast = decisionXConditions.isNewPeakUnderLast;
|
||||
bool isSamePeaks = decisionXConditions.peaksBuffer[1] ==
|
||||
decisionXConditions.peaksBuffer[2] &&
|
||||
decisionXConditions.peaksBuffer[2] ==
|
||||
decisionXConditions.peaksBuffer[3];
|
||||
bool isSameCyclePeaks = decisionXConditions.peaksBuffer[1] ==
|
||||
analyseXConditions.peaksBuffer[1] &&
|
||||
analyseXConditions.peaksBuffer[1] ==
|
||||
verificationXConditions.peaksBuffer[1];
|
||||
|
||||
//
|
||||
bool isValeStart =
|
||||
isSameVales &&
|
||||
isSameCycleVales;
|
||||
bool isPeakStart =
|
||||
isSamePeaks &&
|
||||
isSameCyclePeaks;
|
||||
|
||||
//
|
||||
bool isStart = isPeakStart ||
|
||||
isValeStart;
|
||||
if (isStart)
|
||||
{
|
||||
//
|
||||
X121SMCXPivotStart = cTime;
|
||||
X121SMCXPivotType =
|
||||
isPeakStart
|
||||
? XPV_PEAK
|
||||
: XPV_VALE;
|
||||
|
||||
//
|
||||
X121SMCXPivotPeak = decisionXConditions.peaksBuffer[1];
|
||||
X121SMCXPivotVale = decisionXConditions.valesBuffer[1];
|
||||
}
|
||||
|
||||
//
|
||||
hasPivot = IsValid(X121SMCXPivotStart);
|
||||
|
||||
//
|
||||
// Create XPVPivot instance ...
|
||||
if (hasPivot)
|
||||
{
|
||||
//
|
||||
conditions.pivotZone.symbol = symbol;
|
||||
conditions.pivotZone.period = period;
|
||||
|
||||
//
|
||||
conditions.pivotZone.to = cTime;
|
||||
conditions.pivotZone.repetition = 3;
|
||||
|
||||
//
|
||||
conditions.pivotZone.upper = X121SMCXPivotPeak;
|
||||
conditions.pivotZone.lower = X121SMCXPivotVale;
|
||||
|
||||
//
|
||||
conditions.pivotZone.type = X121SMCXPivotType;
|
||||
conditions.pivotZone.from = X121SMCXPivotStart;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (hasPivot)
|
||||
{
|
||||
//
|
||||
bool isBreaked = X121SMCXPivotType == XPV_PEAK
|
||||
? decisionXConditions.isBreakedUpPrevPeak
|
||||
: decisionXConditions.isBreakedDownPrevVale;
|
||||
|
||||
//
|
||||
if (!isBreaked)
|
||||
{
|
||||
//
|
||||
X121SMCXPivotPeak = decisionXConditions.peaksBuffer[1];
|
||||
X121SMCXPivotVale = decisionXConditions.valesBuffer[1];
|
||||
|
||||
//
|
||||
conditions.pivotZone.to = cTime;
|
||||
conditions.pivotZone.repetition++;
|
||||
conditions.pivotZone.upper = X121SMCXPivotPeak;
|
||||
conditions.pivotZone.lower = X121SMCXPivotVale;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
X121SMCXPivotEnd = cTime;
|
||||
conditions.pivotZone.to = cTime;
|
||||
}
|
||||
|
||||
//
|
||||
// Fill Pivot State ...
|
||||
|
||||
//
|
||||
XPOIState analysePivotState;
|
||||
DetectPivotPOIs(
|
||||
conditions.pivotZone,
|
||||
analyseState,
|
||||
analysePivotState //
|
||||
);
|
||||
|
||||
//
|
||||
XPOIState decisionPivotState;
|
||||
DetectPivotPOIs(
|
||||
conditions.pivotZone,
|
||||
decisionState,
|
||||
decisionPivotState //
|
||||
);
|
||||
|
||||
//
|
||||
// Combine two State ...
|
||||
XPOIState combinedPivotState;
|
||||
XPOIState iStates[];
|
||||
AddRef(
|
||||
analysePivotState,
|
||||
iStates //
|
||||
);
|
||||
AddRef(
|
||||
decisionPivotState,
|
||||
iStates //
|
||||
);
|
||||
CombineStates(
|
||||
combinedPivotState,
|
||||
iStates //
|
||||
);
|
||||
combinedPivotState = decisionPivotState;
|
||||
|
||||
//
|
||||
ArrayFree(iStates);
|
||||
|
||||
//
|
||||
combinedPivotState.time = decisionPivotState.time;
|
||||
combinedPivotState.symbol = decisionPivotState.symbol;
|
||||
combinedPivotState.period = decisionPivotState.period;
|
||||
|
||||
//
|
||||
// Hold Only Areas Which on Upper or Lower bondary of Pivot Zone ...
|
||||
FilterPivotState(
|
||||
conditions.pivotZone,
|
||||
combinedPivotState //
|
||||
);
|
||||
|
||||
//
|
||||
conditions.pivotZone.state = combinedPivotState;
|
||||
|
||||
//
|
||||
double peakUpper = 0;
|
||||
double peakLower = 0;
|
||||
double valeUpper = 0;
|
||||
double valeLower = 0;
|
||||
|
||||
//
|
||||
datetime peakTo = NULL;
|
||||
datetime valeTo = NULL;
|
||||
datetime peakFrom = NULL;
|
||||
datetime valeFrom = NULL;
|
||||
|
||||
//
|
||||
bool hasBoxData = DetectPivotStateBoxData(
|
||||
conditions.pivotZone,
|
||||
peakUpper,
|
||||
peakLower,
|
||||
peakFrom,
|
||||
peakTo,
|
||||
valeUpper,
|
||||
valeLower,
|
||||
valeFrom,
|
||||
valeTo //
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Pivot Tick Zones ...
|
||||
|
||||
//
|
||||
int ticksLevels = decisionCycleHelper
|
||||
.mPOIDetector
|
||||
.TicksRangeZoneLevel();
|
||||
int ticksRange = decisionCycleHelper
|
||||
.mPOIDetector
|
||||
.TicksRangeZoneRange();
|
||||
|
||||
//
|
||||
CalculatePivotTickZone(
|
||||
conditions.pivotZone,
|
||||
ticksLevels,
|
||||
ticksRange //
|
||||
);
|
||||
|
||||
//
|
||||
isPivotPeakZoneRejected =
|
||||
hasBoxData &&
|
||||
(
|
||||
//
|
||||
IsBarReject(
|
||||
peakLower,
|
||||
X_DIRECTION_BEARISH,
|
||||
cBar //
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
IsBarReject(
|
||||
peakUpper,
|
||||
X_DIRECTION_BEARISH,
|
||||
cBar //
|
||||
)
|
||||
//
|
||||
);
|
||||
isPivotPeakZoneBreakedUp =
|
||||
hasBoxData &&
|
||||
IsBarBreak(
|
||||
peakUpper,
|
||||
X_DIRECTION_BULLISH,
|
||||
cBar //
|
||||
);
|
||||
isPivotPeakZoneBreakedDown =
|
||||
hasBoxData &&
|
||||
IsBarBreak(
|
||||
peakLower,
|
||||
X_DIRECTION_BEARISH,
|
||||
cBar //
|
||||
);
|
||||
|
||||
//
|
||||
isPivotValeZoneRejected =
|
||||
hasBoxData &&
|
||||
(
|
||||
//
|
||||
IsBarReject(
|
||||
valeLower,
|
||||
X_DIRECTION_BULLISH,
|
||||
cBar //
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
IsBarReject(
|
||||
valeUpper,
|
||||
X_DIRECTION_BULLISH,
|
||||
cBar //
|
||||
)
|
||||
//
|
||||
);
|
||||
isPivotValeZoneBreakedUp =
|
||||
hasBoxData &&
|
||||
IsBarBreak(
|
||||
valeUpper,
|
||||
X_DIRECTION_BULLISH,
|
||||
cBar //
|
||||
);
|
||||
isPivotValeZoneBreakedDown =
|
||||
hasBoxData &&
|
||||
IsBarBreak(
|
||||
valeLower,
|
||||
X_DIRECTION_BEARISH,
|
||||
cBar //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bool isPivotEnded = IsValid(X121SMCXPivotEnd);
|
||||
if (isPivotEnded)
|
||||
{
|
||||
//
|
||||
X121SMCXPivotPeak = 0;
|
||||
X121SMCXPivotVale = 0;
|
||||
X121SMCXPivotEnd = NULL;
|
||||
X121SMCXPivotStart = NULL;
|
||||
X121SMCXPivotType = XPV_NONE;
|
||||
|
||||
//
|
||||
conditions.pivotZone.Clean();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
////// Detect Pivot Zones :
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
bool isCondition1Bullish =
|
||||
//
|
||||
hasPivot &&
|
||||
//
|
||||
isCBarBullishFormed &&
|
||||
isCBarBullishPullbacked &&
|
||||
//
|
||||
hasAnalyseBullishTrend &&
|
||||
hasDecisionBullishTrend &&
|
||||
hasVerificationBullishTrend &&
|
||||
//
|
||||
decisionXConditions.isSarBullish &&
|
||||
analyseXConditions.isSarBullish &&
|
||||
verificationXConditions.isSarBullish &&
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isCondition1Bearish =
|
||||
//
|
||||
hasPivot &&
|
||||
//
|
||||
isCBarBearishFormed &&
|
||||
isCBarBearishPullbacked &&
|
||||
//
|
||||
hasAnalyseBearishTrend &&
|
||||
hasDecisionBearishTrend &&
|
||||
hasVerificationBearishTrend &&
|
||||
//
|
||||
decisionXConditions.isSarBearish &&
|
||||
analyseXConditions.isSarBearish &&
|
||||
verificationXConditions.isSarBearish &&
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool hasCondition1 = isCondition1Bullish ||
|
||||
isCondition1Bearish;
|
||||
if (hasCondition1)
|
||||
{
|
||||
//
|
||||
ENUM_X_DIRECTION pzDir =
|
||||
isCondition1Bullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
conditions.priceZone = analysePriceZone;
|
||||
conditions.isPriceZoneValidForPeak = isAnalysePriceZoneValidForPeak;
|
||||
conditions.isPriceZoneValidForVale = isAnalysePriceZoneValidForVale;
|
||||
|
||||
//
|
||||
pzPeak = analysePriceZoneUpper;
|
||||
pzVale = analysePriceZoneLower;
|
||||
|
||||
//
|
||||
double point = GetEntry(
|
||||
conditions.symbol,
|
||||
pzDir //
|
||||
);
|
||||
|
||||
//
|
||||
// Manipulate Conditions Point ...
|
||||
|
||||
//
|
||||
// point =
|
||||
// isCondition1Bullish ? pzPeak
|
||||
// : pzVale;
|
||||
conditions.point = point;
|
||||
|
||||
//
|
||||
// Manipulate Conditions Pivot ...
|
||||
|
||||
//
|
||||
conditions.pivot =
|
||||
isCondition1Bullish
|
||||
? pzVale
|
||||
: pzPeak;
|
||||
}
|
||||
@@ -0,0 +1,729 @@
|
||||
//
|
||||
double cPZoneUpper = 0;
|
||||
double cPZoneLower = 0;
|
||||
datetime cPZoneFrom = NULL;
|
||||
datetime cPZoneTo = NULL;
|
||||
result = consolidationPriceZone.GetBoxData(
|
||||
X_DIRECTION_ALL,
|
||||
cPZoneUpper,
|
||||
cPZoneLower,
|
||||
cPZoneFrom,
|
||||
cPZoneTo //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double aPZoneUpper = 0;
|
||||
double aPZoneLower = 0;
|
||||
datetime aPZoneFrom = NULL;
|
||||
datetime aPZoneTo = NULL;
|
||||
result = analysePriceZone.GetBoxData(
|
||||
X_DIRECTION_ALL,
|
||||
aPZoneUpper,
|
||||
aPZoneLower,
|
||||
aPZoneFrom,
|
||||
aPZoneTo //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
double rsi = decisionConditions.x121Conditions.rsiBuffer[1];
|
||||
|
||||
//
|
||||
bool isRSIOverBought = decisionConditions.x121Conditions.isRSIOverBought;
|
||||
bool isRSICrossedOverOverBought = decisionConditions.x121Conditions.isRSICrossedOverOverBought;
|
||||
bool isRSICrossedUnderOverBought = decisionConditions.x121Conditions.isRSICrossedUnderOverBought;
|
||||
|
||||
//
|
||||
bool isRSIOverSold = decisionConditions.x121Conditions.isRSIOverSold;
|
||||
bool isRSICrossedOverOverSold = decisionConditions.x121Conditions.isRSICrossedOverOverSold;
|
||||
bool isRSICrossedUnderOverSold = decisionConditions.x121Conditions.isRSICrossedUnderOverSold;
|
||||
|
||||
//
|
||||
// PV ...
|
||||
double peak = decisionConditions.x121Conditions.peaksBuffer[1];
|
||||
double vale = decisionConditions.x121Conditions.valesBuffer[1];
|
||||
|
||||
//
|
||||
bool isNewPeak = decisionConditions.x121Conditions.isNewPeak;
|
||||
bool isNewPeakOverLast = decisionConditions.x121Conditions.isNewPeakOverLast;
|
||||
bool isNewPeakUnderLast = decisionConditions.x121Conditions.isNewPeakUnderLast;
|
||||
|
||||
//
|
||||
bool isNewVale = decisionConditions.x121Conditions.isNewVale;
|
||||
bool isNewValeOverLast = decisionConditions.x121Conditions.isNewValeOverLast;
|
||||
bool isNewValeUnderLast = decisionConditions.x121Conditions.isNewValeUnderLast;
|
||||
|
||||
//
|
||||
// STR ...
|
||||
double str = decisionConditions.x121Conditions.strBuffer[1];
|
||||
|
||||
//
|
||||
bool isStrBullish = decisionConditions.x121Conditions.isStrBullish;
|
||||
bool isStrBearish = decisionConditions.x121Conditions.isStrBearish;
|
||||
|
||||
//
|
||||
bool isStrSwitchedToBullish = decisionConditions.x121Conditions.isStrSwitchedToBullish;
|
||||
bool isStrSwitchedToBearish = decisionConditions.x121Conditions.isStrSwitchedToBearish;
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
double atr = decisionConditions.x121Conditions.atrBuffer[1];
|
||||
double atrUpper = decisionConditions.x121Conditions.atrUpperBuffer[1];
|
||||
double atrLower = decisionConditions.x121Conditions.atrLowerBuffer[1];
|
||||
|
||||
//
|
||||
bool isCloseOverATRUpper = decisionConditions.x121Conditions.isCloseOverATRUpper;
|
||||
bool isCloseOverATRLower = decisionConditions.x121Conditions.isCloseOverATRLower;
|
||||
|
||||
//
|
||||
bool isCloseUnderATRUpper = decisionConditions.x121Conditions.isCloseUnderATRUpper;
|
||||
bool isCloseUnderATRLower = decisionConditions.x121Conditions.isCloseUnderATRLower;
|
||||
|
||||
//
|
||||
bool isRejectUpATRUpper = decisionConditions.x121Conditions.isRejectUpATRUpper;
|
||||
bool isRejectDownATRUpper = decisionConditions.x121Conditions.isRejectDownATRUpper;
|
||||
|
||||
//
|
||||
bool isRejectUpATRLower = decisionConditions.x121Conditions.isRejectUpATRLower;
|
||||
bool isRejectDownATRLower = decisionConditions.x121Conditions.isRejectDownATRLower;
|
||||
|
||||
//
|
||||
bool isBreakUpATRUpper = decisionConditions.x121Conditions.isBreakUpATRUpper;
|
||||
bool isBreakDownATRUpper = decisionConditions.x121Conditions.isBreakDownATRUpper;
|
||||
|
||||
//
|
||||
bool isBreakUpATRLower = decisionConditions.x121Conditions.isBreakUpATRLower;
|
||||
bool isBreakDownATRLower = decisionConditions.x121Conditions.isBreakDownATRLower;
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
double sar = decisionConditions.x121Conditions.sarBuffer[1];
|
||||
|
||||
//
|
||||
bool isSarBullish = decisionConditions.x121Conditions.isSarBullish;
|
||||
bool isSarBearish = decisionConditions.x121Conditions.isSarBearish;
|
||||
|
||||
//
|
||||
bool isSarSwitchedToBullish = decisionConditions.x121Conditions.isSarSwitchedToBullish;
|
||||
bool isSarSwitchedToBearish = decisionConditions.x121Conditions.isSarSwitchedToBearish;
|
||||
|
||||
//
|
||||
// DON ...
|
||||
|
||||
//
|
||||
double donOpenUpper = decisionConditions.x121Conditions.donOpenUpperBuffer[1];
|
||||
double donOpenLower = decisionConditions.x121Conditions.donOpenLowerBuffer[1];
|
||||
double donHighUpper = decisionConditions.x121Conditions.donHighUpperBuffer[1];
|
||||
double donHighLower = decisionConditions.x121Conditions.donHighLowerBuffer[1];
|
||||
double donLowUpper = decisionConditions.x121Conditions.donLowUpperBuffer[1];
|
||||
double donLowLower = decisionConditions.x121Conditions.donLowLowerBuffer[1];
|
||||
double donCloseUpper = decisionConditions.x121Conditions.donCloseUpperBuffer[1];
|
||||
double donCloseLower = decisionConditions.x121Conditions.donCloseLowerBuffer[1];
|
||||
|
||||
//
|
||||
bool isRejectDonOpenUpper = decisionConditions.x121Conditions.isRejectDonOpenUpper;
|
||||
bool isRejectDonHighUpper = decisionConditions.x121Conditions.isRejectDonHighUpper;
|
||||
bool isRejectDonLowUpper = decisionConditions.x121Conditions.isRejectDonLowUpper;
|
||||
bool isRejectDonCloseUpper = decisionConditions.x121Conditions.isRejectDonCloseUpper;
|
||||
|
||||
//
|
||||
bool isRejectDonOpenLower = decisionConditions.x121Conditions.isRejectDonOpenLower;
|
||||
bool isRejectDonHighLower = decisionConditions.x121Conditions.isRejectDonHighLower;
|
||||
bool isRejectDonLowLower = decisionConditions.x121Conditions.isRejectDonLowLower;
|
||||
bool isRejectDonCloseLower = decisionConditions.x121Conditions.isRejectDonCloseLower;
|
||||
|
||||
//
|
||||
bool isBreakDonOpenUpper = decisionConditions.x121Conditions.isBreakDonOpenUpper;
|
||||
bool isBreakDonHighUpper = decisionConditions.x121Conditions.isBreakDonHighUpper;
|
||||
bool isBreakDonLowUpper = decisionConditions.x121Conditions.isBreakDonLowUpper;
|
||||
bool isBreakDonCloseUpper = decisionConditions.x121Conditions.isBreakDonCloseUpper;
|
||||
|
||||
//
|
||||
bool isBreakDonOpenLower = decisionConditions.x121Conditions.isBreakDonOpenLower;
|
||||
bool isBreakDonHighLower = decisionConditions.x121Conditions.isBreakDonHighLower;
|
||||
bool isBreakDonLowLower = decisionConditions.x121Conditions.isBreakDonLowLower;
|
||||
bool isBreakDonCloseLower = decisionConditions.x121Conditions.isBreakDonCloseLower;
|
||||
|
||||
//
|
||||
// VWAP ...
|
||||
|
||||
//
|
||||
// COMPLEX ...
|
||||
// Complex Conditions ...
|
||||
|
||||
//
|
||||
bool isNewPeakOverATRUpper =
|
||||
isNewPeak &&
|
||||
peak > atrUpper;
|
||||
|
||||
//
|
||||
bool isNewValeUnderATRLower =
|
||||
isNewVale &&
|
||||
vale < atrLower;
|
||||
|
||||
//
|
||||
bool isDonHighUpperEqualsToPeak =
|
||||
donHighUpper == peak;
|
||||
|
||||
//
|
||||
bool isDonLowLowerEqualsToVale =
|
||||
donLowLower == vale;
|
||||
|
||||
//
|
||||
bool isBullishSign = (
|
||||
//
|
||||
triggerConditions.x121Conditions.isBreakUpATRLower ||
|
||||
triggerConditions.x121Conditions.isRejectUpATRLower ||
|
||||
triggerConditions.x121Conditions.isBreakDonHighLower ||
|
||||
triggerConditions.x121Conditions.isRejectDonHighLower ||
|
||||
triggerConditions.x121Conditions.isBreakDonCloseLower ||
|
||||
triggerConditions.x121Conditions.isRejectDonCloseLower
|
||||
//
|
||||
);
|
||||
bool isBearishSign = (
|
||||
//
|
||||
triggerConditions.x121Conditions.isBreakDownATRUpper ||
|
||||
triggerConditions.x121Conditions.isRejectDownATRUpper ||
|
||||
triggerConditions.x121Conditions.isBreakDonLowUpper ||
|
||||
triggerConditions.x121Conditions.isRejectDonLowUpper ||
|
||||
triggerConditions.x121Conditions.isBreakDonCloseUpper ||
|
||||
triggerConditions.x121Conditions.isRejectDonCloseUpper
|
||||
//
|
||||
);
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Check RSI in Over Bought or Over Sold ...
|
||||
|
||||
//
|
||||
bool isRSICrossedOverOverSold = consolidationConditions.x121Conditions.isRSICrossedOverOverSold;
|
||||
bool isRSICrossedUnderOverBought = consolidationConditions.x121Conditions.isRSICrossedUnderOverBought;
|
||||
|
||||
//
|
||||
result = isRSICrossedOverOverSold ||
|
||||
isRSICrossedUnderOverBought;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Draw X121 SMC Conditions ...
|
||||
*
|
||||
* @param conditions: X121SMCStrategyConditions instance Reference ...
|
||||
* @param drawMarketStructure: Boolean ...
|
||||
* @param drawPriceZones: Boolean ...
|
||||
* @param drawDecisionZones: Boolean ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int DrawX121SMCStrategyConditions(
|
||||
X121SMCStrategyConditions &conditions,
|
||||
XCBaseObject *&drawnObjects[],
|
||||
XCPOIDrawer *drawer,
|
||||
bool drawMarketStructure = true,
|
||||
bool drawPriceZones = true,
|
||||
bool drawDecisionZones = true,
|
||||
bool drawOnlyPriceZonesBoundary = true //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
Clean(drawnObjects);
|
||||
|
||||
//
|
||||
if (drawer == NULL ||
|
||||
!conditions.IsValid() ||
|
||||
!HasDirection(conditions.signalDir))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool isBullish = IsBullish(conditions.signalDir);
|
||||
|
||||
// //
|
||||
// bool hasPriceZones = conditions.priceZones.IsValid();
|
||||
// if (hasPriceZones &&
|
||||
// drawPriceZones)
|
||||
// {
|
||||
// //
|
||||
// XCBaseObject *objects[];
|
||||
// int objectsCount = drawer.DrawPriceZone(
|
||||
// conditions.priceZones,
|
||||
// objects,
|
||||
// conditions.signalDir,
|
||||
// drawOnlyPriceZonesBoundary //
|
||||
// );
|
||||
// if (IsValidSize(objectsCount))
|
||||
// {
|
||||
// //
|
||||
// Copy(
|
||||
// objects,
|
||||
// drawnObjects,
|
||||
// false //
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
// //
|
||||
// bool hasDecisionZones = conditions.decisionZones.IsValid();
|
||||
// if (hasDecisionZones &&
|
||||
// drawDecisionZones)
|
||||
// {
|
||||
// //
|
||||
// XCBaseObject *objects[];
|
||||
// int objectsCount = drawer.DrawPriceZone(
|
||||
// conditions.decisionZones,
|
||||
// objects,
|
||||
// conditions.signalDir,
|
||||
// drawOnlyPriceZonesBoundary //
|
||||
// );
|
||||
// if (IsValidSize(objectsCount))
|
||||
// {
|
||||
// //
|
||||
// Copy(
|
||||
// objects,
|
||||
// drawnObjects,
|
||||
// false //
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
// //
|
||||
// bool hasMarketStructure = conditions.marketStructure.IsValid();
|
||||
// if (hasMarketStructure &&
|
||||
// drawMarketStructure)
|
||||
// {
|
||||
// //
|
||||
// XCBaseObject *objects[];
|
||||
// int objectsCount = drawer.DrawMarketStructure(
|
||||
// conditions.marketStructure,
|
||||
// objects //
|
||||
// );
|
||||
// if (IsValidSize(objectsCount))
|
||||
// {
|
||||
// //
|
||||
// Copy(
|
||||
// objects,
|
||||
// drawnObjects,
|
||||
// false //
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
//
|
||||
result = ArraySize(drawnObjects);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
|
||||
// //
|
||||
// isCBarBearishFormed &&
|
||||
// (isPivotToDownRejected ||
|
||||
// isPivotToDownBreaked) &&
|
||||
// conditions.pivotZone.IsVale() &&
|
||||
// //
|
||||
// // SAR ...
|
||||
// isSarBearishFormed &&
|
||||
// // //
|
||||
// // // STR ...
|
||||
// // !(decisionXConditions.isStrBullish) &&
|
||||
// // //
|
||||
// // // VWAP ...
|
||||
// // !(decisionXConditions.isVWapBullishState ||
|
||||
// // decisionXConditions.isVWapBullishOrdered) &&
|
||||
// //
|
||||
|
||||
|
||||
// //
|
||||
// isCBarBullishFormed &&
|
||||
// (isPivotToUpRejected ||
|
||||
// isPivotToUpBreaked) &&
|
||||
// conditions.pivotZone.IsPeak() &&
|
||||
// //
|
||||
// // SAR ...
|
||||
// isSarBullishFormed &&
|
||||
// // //
|
||||
// // // STR ...
|
||||
// // !(decisionXConditions.isStrBearish) &&
|
||||
// // //
|
||||
// // // VWAP ...
|
||||
// // !(decisionXConditions.isVWapBearishState ||
|
||||
// // decisionXConditions.isVWapBearishOrdered) &&
|
||||
// //
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
visionXConditions.isBreakedUpPrevCheMax &&
|
||||
visionXConditions.isCheSwitchedToBullish
|
||||
|
||||
visionXConditions.isCheSwitchedToBearish &&
|
||||
visionXConditions.isBreakedDownPrevCheMin
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
bool hasOrderBlock = hasBullishOrderBlocks ||
|
||||
hasBearishOrderBlocks;
|
||||
if (hasOrderBlock)
|
||||
{
|
||||
//
|
||||
Print("Detect Order Block ...");
|
||||
|
||||
//
|
||||
XCBaseObject *drawnObjects[];
|
||||
|
||||
//
|
||||
if (hasBullishOrderBlocks)
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < bullishOrderBlocksCount; i++)
|
||||
{
|
||||
//
|
||||
XCOrderBlock *iOb = bullishOBs[i];
|
||||
|
||||
//
|
||||
XCBullishOrderBlockObject *iObObj;
|
||||
bool isCreated = triggerCycleHelper
|
||||
.mPOIDetector
|
||||
.mDrawer
|
||||
.CreateBullishOrderBlock(
|
||||
iOb,
|
||||
iObObj //
|
||||
);
|
||||
if (isCreated)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
(XCBaseObject *)iObObj,
|
||||
drawnObjects //
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (hasBearishOrderBlocks)
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < bearishOrderBlocksCount; i++)
|
||||
{
|
||||
//
|
||||
XCOrderBlock *iOb = bearishOBs[i];
|
||||
|
||||
//
|
||||
XCBearishOrderBlockObject *iObObj;
|
||||
bool isCreated = triggerCycleHelper
|
||||
.mPOIDetector
|
||||
.mDrawer
|
||||
.CreateBearishOrderBlock(
|
||||
iOb,
|
||||
iObObj //
|
||||
);
|
||||
if (isCreated)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
(XCBaseObject *)iObObj,
|
||||
drawnObjects //
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
int drawnCount = ArraySize(drawnObjects);
|
||||
if (IsValidSize(drawnCount))
|
||||
{
|
||||
Print("");
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//
|
||||
// Summarize Conditions ...
|
||||
|
||||
//
|
||||
bool isCondition1Bullish =
|
||||
//
|
||||
// Vision ...
|
||||
(
|
||||
//
|
||||
false
|
||||
//
|
||||
)
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Consolidation ...
|
||||
(
|
||||
//
|
||||
true
|
||||
//
|
||||
)
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Verification ...
|
||||
(
|
||||
//
|
||||
true
|
||||
//
|
||||
)
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Analyse ...
|
||||
(
|
||||
//
|
||||
true
|
||||
//
|
||||
)
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Decision ...
|
||||
(
|
||||
//
|
||||
true
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isCondition1Bearish =
|
||||
//
|
||||
// Vision ...
|
||||
(
|
||||
//
|
||||
false
|
||||
//
|
||||
)
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Consolidation ...
|
||||
(
|
||||
//
|
||||
true
|
||||
//
|
||||
)
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Verification ...
|
||||
(
|
||||
//
|
||||
true
|
||||
//
|
||||
)
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Analyse ...
|
||||
(
|
||||
//
|
||||
true
|
||||
//
|
||||
)
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Decision ...
|
||||
(
|
||||
//
|
||||
true
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool hasCondition1 = isCondition1Bullish ||
|
||||
isCondition1Bearish;
|
||||
if (hasCondition1)
|
||||
{
|
||||
//
|
||||
ENUM_X_DIRECTION pzDir =
|
||||
isCondition1Bullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
double point = GetEntry(
|
||||
conditions.symbol,
|
||||
pzDir //
|
||||
);
|
||||
|
||||
//
|
||||
// Manipulate Conditions Point ...
|
||||
|
||||
//
|
||||
conditions.point = point;
|
||||
|
||||
//
|
||||
// Manipulate Conditions Pivot ...
|
||||
|
||||
//
|
||||
// conditions.pivot =
|
||||
// isCondition1Bullish
|
||||
// ? conditions.pivotZone.upper
|
||||
// : conditions.pivotZone.lower;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
// DRAW ...
|
||||
//
|
||||
|
||||
//
|
||||
XCBaseObject *drawnObjects[];
|
||||
|
||||
//
|
||||
if (hasBullishOrderBlocks)
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < bullishOrderBlocksCount; i++)
|
||||
{
|
||||
//
|
||||
XCOrderBlock *iOb = conditions.bullishOBs[i];
|
||||
|
||||
//
|
||||
XCBullishOrderBlockObject *iObObj;
|
||||
bool isCreated = visionCycleHelper
|
||||
.mPOIDrawer
|
||||
.CreateBullishOrderBlock(
|
||||
iOb,
|
||||
iObObj //
|
||||
);
|
||||
if (isCreated)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
(XCBaseObject *)iObObj,
|
||||
drawnObjects //
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (hasBearishOrderBlocks)
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < bearishOrderBlocksCount; i++)
|
||||
{
|
||||
//
|
||||
XCOrderBlock *iOb = conditions.bearishOBs[i];
|
||||
|
||||
//
|
||||
XCBearishOrderBlockObject *iObObj;
|
||||
bool isCreated = visionCycleHelper
|
||||
.mPOIDrawer
|
||||
.CreateBearishOrderBlock(
|
||||
iOb,
|
||||
iObObj //
|
||||
);
|
||||
if (isCreated)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
(XCBaseObject *)iObObj,
|
||||
drawnObjects //
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// if (hasOldestBullishOB)
|
||||
// {
|
||||
// //
|
||||
// XCBullishOrderBlockObject *iObj;
|
||||
// bool isCreated = visionCycleHelper
|
||||
// .mPOIDrawer
|
||||
// .CreateBullishOrderBlock(
|
||||
// oldestBullishOB,
|
||||
// iObj //
|
||||
// );
|
||||
// if (isCreated)
|
||||
// {
|
||||
// }
|
||||
// }
|
||||
|
||||
// //
|
||||
// if (hasYoungestBullishOB)
|
||||
// {
|
||||
// //
|
||||
// XCBullishOrderBlockObject *iObj;
|
||||
// bool isCreated = visionCycleHelper
|
||||
// .mPOIDrawer
|
||||
// .CreateBullishOrderBlock(
|
||||
// youngestBullishOB,
|
||||
// iObj //
|
||||
// );
|
||||
// if (isCreated)
|
||||
// {
|
||||
// }
|
||||
// }
|
||||
|
||||
// //
|
||||
// if (hasOldestBearishOB)
|
||||
// {
|
||||
// //
|
||||
// XCBearishOrderBlockObject *iObj;
|
||||
// bool isCreated = visionCycleHelper
|
||||
// .mPOIDrawer
|
||||
// .CreateBearishOrderBlock(
|
||||
// oldestBearishOB,
|
||||
// iObj //
|
||||
// );
|
||||
// if (isCreated)
|
||||
// {
|
||||
// }
|
||||
// }
|
||||
|
||||
// //
|
||||
// if (hasYoungestBearishOB)
|
||||
// {
|
||||
// //
|
||||
// XCBearishOrderBlockObject *iObj;
|
||||
// bool isCreated = visionCycleHelper
|
||||
// .mPOIDrawer
|
||||
// .CreateBearishOrderBlock(
|
||||
// youngestBearishOB,
|
||||
// iObj //
|
||||
// );
|
||||
// if (isCreated)
|
||||
// {
|
||||
// }
|
||||
// }
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,137 @@
|
||||
|
||||
//
|
||||
// OPEN ...
|
||||
double triggerDonOpenUpper = triggerConditions.x121Conditions.donOpenUpperBuffer[1];
|
||||
double triggerDonOpenLower = triggerConditions.x121Conditions.donOpenLowerBuffer[1];
|
||||
double triggerDonOpenUpperPrev = triggerConditions.x121Conditions.donOpenUpperBuffer[2];
|
||||
double triggerDonOpenLowerPrev = triggerConditions.x121Conditions.donOpenLowerBuffer[2];
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
double triggerDonHighUpper = triggerConditions.x121Conditions.donHighUpperBuffer[1];
|
||||
double triggerDonHighLower = triggerConditions.x121Conditions.donHighLowerBuffer[1];
|
||||
double triggerDonHighUpperPrev = triggerConditions.x121Conditions.donHighUpperBuffer[2];
|
||||
double triggerDonHighLowerPrev = triggerConditions.x121Conditions.donHighLowerBuffer[2];
|
||||
|
||||
//
|
||||
// CLOSE ...
|
||||
double triggerDonCloseUpper = triggerConditions.x121Conditions.donCloseUpperBuffer[1];
|
||||
double triggerDonCloseLower = triggerConditions.x121Conditions.donCloseLowerBuffer[1];
|
||||
double triggerDonCloseUpperPrev = triggerConditions.x121Conditions.donCloseUpperBuffer[2];
|
||||
double triggerDonCloseLowerPrev = triggerConditions.x121Conditions.donCloseLowerBuffer[2];
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
double triggerDonLowUpper = triggerConditions.x121Conditions.donLowUpperBuffer[1];
|
||||
double triggerDonLowLower = triggerConditions.x121Conditions.donLowLowerBuffer[1];
|
||||
double triggerDonLowUpperPrev = triggerConditions.x121Conditions.donLowUpperBuffer[2];
|
||||
double triggerDonLowLowerPrev = triggerConditions.x121Conditions.donLowLowerBuffer[2];
|
||||
|
||||
//
|
||||
// Calculate PBar Rejected Don Upper and Lower ...
|
||||
|
||||
//
|
||||
bool isPBarRejectDonLowUpper = pBar.high > triggerDonLowUpperPrev;
|
||||
bool isPBarRejectDonOpenUpper = pBar.high > triggerDonOpenUpperPrev;
|
||||
bool isPBarRejectDonCloseUpper = pBar.high > triggerDonCloseUpperPrev;
|
||||
bool isPBarRejectedDonUpper = isPBarRejectDonLowUpper ||
|
||||
isPBarRejectDonOpenUpper ||
|
||||
isPBarRejectDonCloseUpper;
|
||||
|
||||
//
|
||||
bool isPBarRejectDonHighLower = pBar.low < triggerDonHighLowerPrev;
|
||||
bool isPBarRejectDonOpenLower = pBar.low < triggerDonOpenLowerPrev;
|
||||
bool isPBarRejectDonCloseLower = pBar.low < triggerDonCloseLowerPrev;
|
||||
bool isPBarRejectedDonLower = isPBarRejectDonHighLower ||
|
||||
isPBarRejectDonOpenLower ||
|
||||
isPBarRejectDonCloseLower;
|
||||
|
||||
//
|
||||
// Calculate PBar Breaked Don Upper and Lower ...
|
||||
|
||||
//
|
||||
bool isPBarBreakdDonLowUpper = pBar.GetUp() > triggerDonLowUpperPrev &&
|
||||
pBar.GetDown() < triggerDonLowUpperPrev;
|
||||
bool isPBarBreakdDonOpenUpper = pBar.GetUp() > triggerDonOpenUpperPrev &&
|
||||
pBar.GetDown() < triggerDonOpenUpperPrev;
|
||||
bool isPBarBreakdDonCloseUpper = pBar.GetUp() > triggerDonCloseUpperPrev &&
|
||||
pBar.GetDown() < triggerDonCloseUpperPrev;
|
||||
bool isPBarBreakedDonUpper = isPBarBreakdDonLowUpper ||
|
||||
isPBarBreakdDonOpenUpper ||
|
||||
isPBarBreakdDonCloseUpper;
|
||||
|
||||
//
|
||||
bool isPBarBreakdDonHighLower = pBar.GetUp() > triggerDonHighLowerPrev &&
|
||||
pBar.GetDown() < triggerDonHighLowerPrev;
|
||||
bool isPBarBreakdDonOpenLower = pBar.GetUp() > triggerDonOpenLowerPrev &&
|
||||
pBar.GetDown() < triggerDonOpenLowerPrev;
|
||||
bool isPBarBreakdDonCloseLower = pBar.GetUp() > triggerDonCloseLowerPrev &&
|
||||
pBar.GetDown() < triggerDonCloseLowerPrev;
|
||||
bool isPBarBreakedDonLower = isPBarBreakdDonHighLower ||
|
||||
isPBarBreakdDonOpenLower ||
|
||||
isPBarBreakdDonCloseLower;
|
||||
|
||||
//
|
||||
bool isRejectTriggerDonUpper =
|
||||
//
|
||||
// PBar ...
|
||||
isPBarBearishRejected &&
|
||||
isPBarRejectedDonUpper &&
|
||||
//
|
||||
// CBar ...
|
||||
isCBarBearishMomentumBar &&
|
||||
cBar.close < triggerDonLowUpper &&
|
||||
//
|
||||
triggerPeak == triggerDonHighUpper
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isRejectTriggerDonLower =
|
||||
//
|
||||
// PBar ...
|
||||
isPBarBullishRejected &&
|
||||
isPBarRejectedDonLower &&
|
||||
//
|
||||
// CBar ...
|
||||
isCBarBullishMomentumBar &&
|
||||
cBar.close > triggerDonHighLower &&
|
||||
//
|
||||
triggerVale == triggerDonLowLower
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (isRejectTriggerDonUpper ||
|
||||
isRejectTriggerDonLower)
|
||||
{
|
||||
Print("Don Rejected ...");
|
||||
}
|
||||
|
||||
//
|
||||
bool isBreakedDonUpper =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isBreakedDonLower =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isEngulfedDonUpper =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isEngulfedDonLower =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
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
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,957 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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;
|
||||
|
||||
//
|
||||
datetime newPeakOverATRUpperAt;
|
||||
datetime newValeUnderATRLowerAt;
|
||||
|
||||
//
|
||||
datetime donHighUpperEqualsToPeakAt;
|
||||
datetime donLowLowerEqualsToValeAt;
|
||||
|
||||
//
|
||||
datetime closeOverATRUpperAt;
|
||||
datetime closeUnderATRLowerAt;
|
||||
|
||||
//
|
||||
datetime rsiOverSoldAt;
|
||||
datetime rsiOverBoughtAt;
|
||||
|
||||
//
|
||||
datetime newPeakOverLastAt;
|
||||
datetime newValeUnderLastAt;
|
||||
|
||||
//
|
||||
datetime bullishBarSignAt;
|
||||
datetime bearishBarSignAt;
|
||||
|
||||
//
|
||||
XPriceZones priceZone;
|
||||
|
||||
//
|
||||
// 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()
|
||||
{
|
||||
//
|
||||
priceZone.Clean();
|
||||
|
||||
//
|
||||
newPeakOverATRUpperAt = NULL;
|
||||
newValeUnderATRLowerAt = NULL;
|
||||
|
||||
//
|
||||
donHighUpperEqualsToPeakAt = NULL;
|
||||
donLowLowerEqualsToValeAt = NULL;
|
||||
|
||||
//
|
||||
closeOverATRUpperAt = NULL;
|
||||
closeUnderATRLowerAt = NULL;
|
||||
|
||||
//
|
||||
rsiOverSoldAt = NULL;
|
||||
rsiOverBoughtAt = NULL;
|
||||
|
||||
//
|
||||
newPeakOverLastAt = NULL;
|
||||
newValeUnderLastAt = NULL;
|
||||
|
||||
//
|
||||
bullishBarSignAt = NULL;
|
||||
bearishBarSignAt = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Conditions Filled ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsFilled(ENUM_X_DIRECTION &fillDir)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
fillDir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
bool hasNewPeakOverATRUpper = IsValid(newPeakOverATRUpperAt);
|
||||
bool hasNewValeUnderATRLower = IsValid(newValeUnderATRLowerAt);
|
||||
|
||||
//
|
||||
bool hasDonHighUpperEqualsToPeak = IsValid(donHighUpperEqualsToPeakAt);
|
||||
bool hasDonLowLowerEqualsToVale = IsValid(donLowLowerEqualsToValeAt);
|
||||
|
||||
//
|
||||
bool hasCloseOverATRUpper = IsValid(closeOverATRUpperAt);
|
||||
bool hasCloseUnderATRLower = IsValid(closeUnderATRLowerAt);
|
||||
|
||||
//
|
||||
bool hasRsiOverSold = IsValid(rsiOverSoldAt);
|
||||
bool hasRsiOverBought = IsValid(rsiOverBoughtAt);
|
||||
|
||||
//
|
||||
bool hasNewPeakOverLast = IsValid(newPeakOverLastAt);
|
||||
bool hasNewValeUnderLast = IsValid(newValeUnderLastAt);
|
||||
|
||||
//
|
||||
bool hasBullishBarSign = IsValid(bullishBarSignAt);
|
||||
bool hasBearishBarSign = IsValid(bearishBarSignAt);
|
||||
|
||||
//
|
||||
bool isBullish =
|
||||
(
|
||||
//
|
||||
hasRsiOverSold &&
|
||||
hasBullishBarSign &&
|
||||
hasNewValeUnderLast &&
|
||||
hasCloseUnderATRLower &&
|
||||
hasNewValeUnderATRLower &&
|
||||
hasDonLowLowerEqualsToVale
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
bool isBearish =
|
||||
(
|
||||
//
|
||||
hasRsiOverBought &&
|
||||
hasBearishBarSign &&
|
||||
hasNewPeakOverLast &&
|
||||
hasCloseOverATRUpper &&
|
||||
hasNewPeakOverATRUpper &&
|
||||
hasDonHighUpperEqualsToPeak
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
result =
|
||||
(isBullish || isBearish) &&
|
||||
!(isBullish && isBearish);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
fillDir =
|
||||
isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
bool HasPriceZone()
|
||||
{
|
||||
return priceZone.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;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL pBar;
|
||||
result = pBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
pIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double ask = GetAsk(symbol);
|
||||
double bid = GetBid(symbol);
|
||||
datetime cTime = TimeCurrent();
|
||||
double points = GetPoints(symbol);
|
||||
|
||||
//
|
||||
int swingLoopback = 9;
|
||||
double ll = cBar.FindLowest(swingLoopback, MODE_LOW);
|
||||
double hh = cBar.FindHighest(swingLoopback, MODE_HIGH);
|
||||
double llDown = cBar.FindLowesttDown(swingLoopback);
|
||||
double hhUp = cBar.FindHighestUp(swingLoopback);
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
|
||||
//
|
||||
result = analyseConditions.x121Conditions.isStrSwitchedToBullish ||
|
||||
analyseConditions.x121Conditions.isStrSwitchedToBearish;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
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 = IsBullish(setupDir);
|
||||
bool isBearish = IsBearish(setupDir);
|
||||
|
||||
//
|
||||
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;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL pBar;
|
||||
result = pBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
pIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double ask = GetAsk(symbol);
|
||||
double bid = GetBid(symbol);
|
||||
datetime cTime = TimeCurrent();
|
||||
double points = GetPoints(symbol);
|
||||
|
||||
//
|
||||
int swingLoopback = 9;
|
||||
double ll = cBar.FindLowest(swingLoopback, MODE_LOW);
|
||||
double hh = cBar.FindHighest(swingLoopback, MODE_HIGH);
|
||||
double llDown = cBar.FindLowesttDown(swingLoopback);
|
||||
double hhUp = cBar.FindHighestUp(swingLoopback);
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
|
||||
//
|
||||
// Detect Bullish Conditions ...
|
||||
isBullish =
|
||||
isBullish &&
|
||||
cBar.IsBullish();
|
||||
|
||||
//
|
||||
// Detect Bearish Conditions ...
|
||||
isBearish =
|
||||
isBearish &&
|
||||
cBar.IsBearish();
|
||||
|
||||
//
|
||||
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 Pivot Point ...
|
||||
|
||||
//
|
||||
// Detect Target ...
|
||||
double target = CalculateTarget(
|
||||
cBar,
|
||||
analyseState,
|
||||
setupDir //
|
||||
);
|
||||
if (target == 0)
|
||||
{
|
||||
//
|
||||
target = CalculateTarget(
|
||||
cBar,
|
||||
verificationState,
|
||||
setupDir //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
double oppositTarget = CalculateTarget(
|
||||
cBar,
|
||||
analyseState,
|
||||
Opposit(setupDir) //
|
||||
);
|
||||
|
||||
//
|
||||
double entry = GetEntry(
|
||||
conditions.symbol,
|
||||
setupDir //
|
||||
);
|
||||
|
||||
//
|
||||
// Filling SL Candidates ...
|
||||
|
||||
//
|
||||
double sls[];
|
||||
|
||||
//
|
||||
double atr = triggerConditions.x121Conditions.atrBuffer[1];
|
||||
double peak = triggerConditions.x121Conditions.peaksBuffer[1];
|
||||
double vale = triggerConditions.x121Conditions.valesBuffer[1];
|
||||
|
||||
//
|
||||
if (isBullish)
|
||||
{
|
||||
//
|
||||
double lowerVale = triggerCycleHelper.mX121Helper.xpvHelper.GetLowerVale(vale);
|
||||
if (lowerVale > 0)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
lowerVale,
|
||||
sls //
|
||||
);
|
||||
}
|
||||
}
|
||||
else if (isBearish)
|
||||
{
|
||||
//
|
||||
double higherPeak = triggerCycleHelper.mX121Helper.xpvHelper.GetHigherPeak(peak);
|
||||
if (higherPeak > 0)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
higherPeak,
|
||||
sls //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (ArraySize(sls) == 0)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
double slsMin = GetMin(sls);
|
||||
double slsMax = GetMax(sls);
|
||||
|
||||
//
|
||||
double sl = isBullish
|
||||
? slsMin - atr
|
||||
: slsMax + atr;
|
||||
double risk = MathAbs(entry - sl);
|
||||
double targetDelta = 2 * (risk / 3);
|
||||
if (target == 0)
|
||||
{
|
||||
//
|
||||
int minTargetPint = 50;
|
||||
double minTargetPointValue = minTargetPint * points;
|
||||
if (targetDelta < minTargetPointValue)
|
||||
{
|
||||
targetDelta = minTargetPointValue;
|
||||
}
|
||||
|
||||
//
|
||||
// Force Target On Half Risk ...
|
||||
target =
|
||||
isBullish
|
||||
? entry + targetDelta
|
||||
: entry - targetDelta;
|
||||
|
||||
//
|
||||
target = 0;
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
// Ignore Target ...
|
||||
target = 0;
|
||||
|
||||
//
|
||||
// Filling Conditions Props ...
|
||||
conditions.sl = sl;
|
||||
conditions.target = target;
|
||||
conditions.triggerTime = cTime;
|
||||
conditions.type = isBullish
|
||||
? X_POSITION_TYPE_LONG
|
||||
: X_POSITION_TYPE_SHORT;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Signal ...
|
||||
int DrawX121SMCXTWPVSiganl(
|
||||
X121SMCStrategyXTWPVSignalConditions &conditions,
|
||||
XCBaseObject *&drawnObjects[],
|
||||
XCPOIDrawer *drawer //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
Clean(drawnObjects);
|
||||
|
||||
//
|
||||
if (drawer == NULL)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool isSetuped = conditions.IsSetuped();
|
||||
if (!isSetuped)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool isBullish = IsBullish(conditions.dir);
|
||||
|
||||
//
|
||||
result = ArraySize(drawnObjects);
|
||||
|
||||
//
|
||||
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
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,325 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 ???
|
||||
// Description: ??? ...
|
||||
//
|
||||
//
|
||||
// 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 X121 ??? Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121 ???"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 0
|
||||
#property indicator_plots 0
|
||||
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 20;
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// 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);
|
||||
|
||||
//
|
||||
// Validate Calculated Bars ...
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Custom Buffers ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int barsLimit = startCalculationForLastBars > 0
|
||||
? startCalculationForLastBars
|
||||
: 0;
|
||||
//
|
||||
// bool canCalculate = true;
|
||||
bool canCalculate =
|
||||
barsLimit == 0 ||
|
||||
bar_index <= barsLimit;
|
||||
if (canCalculate)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBuffersZero(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Custom ...
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
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
File diff suppressed because it is too large
Load Diff
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,461 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 = 0; // Last Position Profit In Points for Accept new Signal
|
||||
input int eaDelaysBetweenTwoSignalsInBar = 0; // Delay between two Signals in Bars
|
||||
input double eaMaxAllowedSpread = 25; // Max Allowed Spread for Signalling
|
||||
input int eaMinRequiredVerificationForSpreadPass = 20; // Minimum Spread Verification for Signalling
|
||||
|
||||
//
|
||||
// Trade ...
|
||||
input group "Trade";
|
||||
input bool eaAllowTrade = true; // Allow Open Trade On Signals
|
||||
input string eaStartTradeAt = "2:00"; // Enable Trade on Signals on Time
|
||||
input string eaStopTradeAt = "21:00"; // Enable Trade on Signals on Time
|
||||
input string eaCloseAllTradesAt = ""; // Enable Close All Trades on Signals on Time
|
||||
|
||||
//
|
||||
// Risk Management ...
|
||||
input group "Risk Management";
|
||||
input double eaR2R = 2; // Signallers Risk to Reward Ratio
|
||||
input double eaVolume = 0; // Static Volume
|
||||
input double eaStaticBalance = 1000; // Static Balance
|
||||
input double eaBalancePerTrade = 10; // Balance Used in Each Trade
|
||||
input double eaRiskPercentPerBalance = 0; // 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 = 7200; // 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 = 4; // Minimum Open Positions for Hedging
|
||||
input double eaHedgingMinVolumeStep = 0.01; // Minimum Volume Step for Hedging
|
||||
input double eaHedgeingMinRequiredProfitPerVolumeStep = 2.0; // 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 ...
|
||||
eaExpert = new XC121SMCExpert();
|
||||
|
||||
//
|
||||
// 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);
|
||||
|
||||
//
|
||||
// Trade ...
|
||||
eaExpert.AllowTrade(eaAllowTrade);
|
||||
eaExpert.StartTradeAt(eaStartTradeAt);
|
||||
eaExpert.StopTradeAt(eaStopTradeAt);
|
||||
eaExpert.CloseAllTradesAt(eaCloseAllTradesAt);
|
||||
|
||||
//
|
||||
// Risk Management ...
|
||||
eaExpert.R2R(eaR2R);
|
||||
eaExpert.Volume(eaVolume);
|
||||
eaExpert.StaticBalance(eaStaticBalance);
|
||||
eaExpert.BalancePerTrade(eaBalancePerTrade);
|
||||
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();
|
||||
|
||||
//
|
||||
delete eaExpert;
|
||||
}
|
||||
|
||||
//
|
||||
// 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
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
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,249 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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()
|
||||
{
|
||||
mInputs.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
@@ -0,0 +1,231 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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()
|
||||
{
|
||||
mInputs.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
Binary file not shown.
@@ -0,0 +1,648 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XATR
|
||||
// Description: XATR ...
|
||||
//
|
||||
//
|
||||
// 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 X121 XATR Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121 XATR"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
|
||||
//
|
||||
input group "RSI Detection";
|
||||
input int rsiLength = 14; // Length
|
||||
input ENUM_APPLIED_PRICE rsiAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
input group "ATR Detection";
|
||||
input int atrLength = 14; // Length
|
||||
input double atrMultiplier = 1; // Multiplier
|
||||
input ENUM_APPLIED_PRICE atrUpperAppliedTo = PRICE_HIGH; // Upper Zone Applied To
|
||||
input ENUM_APPLIED_PRICE atrLowerAppliedTo = PRICE_LOW; // Lower Zone Applied To
|
||||
input ENUM_X_MA_METHOD atrSmoothingMode = X_MA_MODE_EMA; // Smoothing Method
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
|
||||
//
|
||||
input bool showAtrUpper = true; // Show Upper Zone
|
||||
input bool showAtrLower = true; // Show Lower Zone
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 6
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
|
||||
//
|
||||
// Upper ...
|
||||
|
||||
//
|
||||
#define atrUpperBufferIndex 0
|
||||
double atrUpperBuffer[];
|
||||
|
||||
#property indicator_label1 "X121 ATRU"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrYellow
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 2
|
||||
|
||||
//
|
||||
// Lower ...
|
||||
|
||||
//
|
||||
#define atrLowerBufferIndex 1
|
||||
double atrLowerBuffer[];
|
||||
|
||||
#property indicator_label2 "X121 ATRL"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrYellow
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 2
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 1;
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
|
||||
#define atrBufferIndex mLastBufferIndex + 1
|
||||
double atrBuffer[];
|
||||
|
||||
#define atrUpperRawBufferIndex mLastBufferIndex + 2
|
||||
double atrUpperRawBuffer[];
|
||||
|
||||
#define atrLowerRawBufferIndex mLastBufferIndex + 3
|
||||
double atrLowerRawBuffer[];
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
#define rsiBufferIndex mLastBufferIndex + 4
|
||||
double rsiBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// RSI Handler ...
|
||||
int rsiHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// ATR Handler ...
|
||||
int atrHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
bool isStrTrendChanged;
|
||||
bool isStrStartBearishTrend;
|
||||
bool isStrStartBullishTrend;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
rsiHandler = iRSI(
|
||||
_Symbol,
|
||||
_Period,
|
||||
rsiLength,
|
||||
rsiAppliedTo //
|
||||
);
|
||||
bool isInited = rsiHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
atrHandler = iATR(
|
||||
_Symbol,
|
||||
_Period,
|
||||
atrLength //
|
||||
);
|
||||
isInited = atrHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
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
|
||||
|
||||
//
|
||||
IndicatorRelease(rsiHandler);
|
||||
IndicatorRelease(atrHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// 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);
|
||||
|
||||
//
|
||||
// Fill All Buffers by Zero ...
|
||||
if (prev_calculated == 0)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Calculated Bars ...
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
int rsiCalculatedBars = BarsCalculated(rsiHandler);
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
int atrCalculatedBars = BarsCalculated(atrHandler);
|
||||
|
||||
//
|
||||
bool isPassedRequiredCalculatedBars =
|
||||
//
|
||||
// RSI ...
|
||||
rsiCalculatedBars >= maxLength &&
|
||||
//
|
||||
// ATR ...
|
||||
atrCalculatedBars >= maxLength
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCalculatedBars)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
int copiedRsis = CopyBuffer(rsiHandler, 0, 0, limit, rsiBuffer);
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
int copiedAtrs = CopyBuffer(atrHandler, 0, 0, limit, atrBuffer);
|
||||
|
||||
//
|
||||
// Validate Copied Items ...
|
||||
bool isPassedRequiredCopiedItems =
|
||||
//
|
||||
//
|
||||
// RSI ...
|
||||
copiedRsis > 0 &&
|
||||
//
|
||||
// ATR ...
|
||||
copiedAtrs > 0
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCopiedItems)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
// RSI ...
|
||||
rsiLength > 0 &&
|
||||
//
|
||||
// ATR ...
|
||||
atrLength > 0 &&
|
||||
atrMultiplier > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(rsiLength, atrLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// ATR ...
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
bool canShowAtrUpper = showAtrUpper;
|
||||
ENUM_DRAW_TYPE atrUpperDrawType = canShowAtrUpper ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(atrUpperBuffer, true);
|
||||
SetIndexBuffer(atrUpperBufferIndex, atrUpperBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(atrUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(atrUpperBufferIndex, PLOT_SHOW_DATA, canShowAtrUpper);
|
||||
PlotIndexSetInteger(atrUpperBufferIndex, PLOT_DRAW_TYPE, atrUpperDrawType);
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
bool canShowAtrLower = showAtrLower;
|
||||
ENUM_DRAW_TYPE atrLowerDrawType = canShowAtrLower ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(atrLowerBuffer, true);
|
||||
SetIndexBuffer(atrLowerBufferIndex, atrLowerBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(atrLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(atrLowerBufferIndex, PLOT_SHOW_DATA, canShowAtrLower);
|
||||
PlotIndexSetInteger(atrLowerBufferIndex, PLOT_DRAW_TYPE, atrLowerDrawType);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(atrBuffer, true);
|
||||
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(atrUpperRawBuffer, true);
|
||||
SetIndexBuffer(atrUpperRawBufferIndex, atrUpperRawBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(atrLowerRawBuffer, true);
|
||||
SetIndexBuffer(atrLowerRawBufferIndex, atrLowerRawBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(rsiBuffer, true);
|
||||
SetIndexBuffer(rsiBufferIndex, rsiBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Custom Buffers ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int barsLimit = startCalculationForLastBars > 0
|
||||
? startCalculationForLastBars
|
||||
: 0;
|
||||
//
|
||||
// bool canCalculate = true;
|
||||
bool canCalculate =
|
||||
barsLimit == 0 ||
|
||||
bar_index <= barsLimit;
|
||||
if (canCalculate)
|
||||
{
|
||||
//
|
||||
CalculateAtrZones(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBuffersZero(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Custom ...
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
// RSIS ...
|
||||
rsiBuffer[barIndex] = 0;
|
||||
|
||||
//
|
||||
// ATRS ...
|
||||
atrBuffer[barIndex] = 0;
|
||||
atrUpperBuffer[barIndex] = 0;
|
||||
atrUpperRawBuffer[barIndex] = 0;
|
||||
atrUpperBuffer[barIndex] = 0;
|
||||
atrLowerRawBuffer[barIndex] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate ATR Zones ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
*/
|
||||
void CalculateAtrZones(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Select ATr Value ...
|
||||
double atrValue = atrBuffer[bar_index];
|
||||
double appliedAtrMultiplierValue = atrValue * atrMultiplier;
|
||||
|
||||
//
|
||||
// Select Upper Price ...
|
||||
double upperPrice = GetAppliedPrice(
|
||||
atrUpperAppliedTo,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
|
||||
//
|
||||
// Select Lower Price ...
|
||||
double lowerPrice = GetAppliedPrice(
|
||||
atrLowerAppliedTo,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Raw Atrs ...
|
||||
|
||||
//
|
||||
// Upper ...
|
||||
double atrUpperRawValue = upperPrice + appliedAtrMultiplierValue;
|
||||
atrUpperRawBuffer[bar_index] = atrUpperRawValue;
|
||||
|
||||
//
|
||||
// Lower ...
|
||||
double atrLowerRawValue = lowerPrice - appliedAtrMultiplierValue;
|
||||
atrLowerRawBuffer[bar_index] = atrLowerRawValue;
|
||||
|
||||
//
|
||||
bool canSmooth = atrSmoothingMode != X_MA_MODE_NONE;
|
||||
if (canSmooth)
|
||||
{
|
||||
//
|
||||
// Upper ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
atrLength,
|
||||
atrUpperRawBuffer,
|
||||
atrUpperBuffer,
|
||||
atrSmoothingMode //
|
||||
);
|
||||
|
||||
//
|
||||
// Lower ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
atrLength,
|
||||
atrLowerRawBuffer,
|
||||
atrLowerBuffer,
|
||||
atrSmoothingMode //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Use Raw Values ...
|
||||
atrUpperBuffer[bar_index] = atrUpperRawValue;
|
||||
atrLowerBuffer[bar_index] = atrLowerRawValue;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,624 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XCHE
|
||||
// Description: XCHE ...
|
||||
//
|
||||
//
|
||||
// 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 X121 XCHE Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121 XCHE"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int cheLength = 35; // Length
|
||||
input int cheLoopback = 26; // Loopback
|
||||
input double cheMultiplier1 = 3.0; // 1st Multiplier
|
||||
input double cheMultiplier2 = 3.5; // 2nd Multiplier
|
||||
input ENUM_APPLIED_PRICE cheUpperAppliedTo = PRICE_HIGH; // Upper Zone Applied to
|
||||
input ENUM_APPLIED_PRICE cheLowerAppliedTo = PRICE_LOW; // Lower Zone Applied to
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input int cheArrowCode = 159; // CHE Arrow Code
|
||||
|
||||
//
|
||||
input bool showLE1 = true; // Show 1st Long Exit
|
||||
input bool showSE1 = true; // Show 1st Short Exit
|
||||
input bool showLE2 = true; // Show 2st Long Exit
|
||||
input bool showSE2 = true; // Show 2st Short Exit
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 8
|
||||
#property indicator_plots 8
|
||||
|
||||
//
|
||||
// Exit 1 ...
|
||||
|
||||
//
|
||||
// LONG ...
|
||||
|
||||
//
|
||||
#define le1BufferIndex 0
|
||||
double le1Buffer[];
|
||||
|
||||
#property indicator_label1 "X121 LE1"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrAqua
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// SHORT ...
|
||||
|
||||
//
|
||||
#define se1BufferIndex 1
|
||||
double se1Buffer[];
|
||||
|
||||
#property indicator_label2 "X121 SE1"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrMagenta
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Exit 2 ...
|
||||
|
||||
//
|
||||
// LONG ...
|
||||
|
||||
//
|
||||
#define le2BufferIndex 2
|
||||
double le2Buffer[];
|
||||
|
||||
#property indicator_label3 "X121 LE2"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrAqua
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// SHORT ...
|
||||
|
||||
//
|
||||
#define se2BufferIndex 3
|
||||
double se2Buffer[];
|
||||
|
||||
#property indicator_label4 "X121 SE2"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrMagenta
|
||||
#property indicator_style4 STYLE_SOLID
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// Start Buffers ...
|
||||
|
||||
//
|
||||
#define le1StartBufferIndex 4
|
||||
double le1StartBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "X121 LE1 S"
|
||||
#property indicator_type5 DRAW_ARROW
|
||||
#property indicator_color5 clrLime
|
||||
|
||||
//
|
||||
#define se1StartBufferIndex 5
|
||||
double se1StartBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "X121 SE1 S"
|
||||
#property indicator_type6 DRAW_ARROW
|
||||
#property indicator_color6 clrRed
|
||||
|
||||
//
|
||||
#define le2StartBufferIndex 6
|
||||
double le2StartBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "X121 LE2 S"
|
||||
#property indicator_type7 DRAW_ARROW
|
||||
#property indicator_color7 clrLime
|
||||
|
||||
//
|
||||
#define se2StartBufferIndex 7
|
||||
double se2StartBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label8 "X121 SE2 S"
|
||||
#property indicator_type8 DRAW_ARROW
|
||||
#property indicator_color8 clrRed
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// Working Array ...
|
||||
double work[][6];
|
||||
#define hi1Idx 0
|
||||
#define lo1Idx 1
|
||||
#define hi2Idx 2
|
||||
#define lo2Idx 3
|
||||
#define trend1Idx 4
|
||||
#define trend2Idx 5
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input cheLength, here we get max Input cheLength
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
if (Bars(_Symbol, _Period) < rates_total)
|
||||
{
|
||||
return (prev_calculated);
|
||||
}
|
||||
|
||||
//
|
||||
if (ArrayRange(work, 0) != rates_total)
|
||||
{
|
||||
ArrayResize(work, rates_total);
|
||||
}
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
|
||||
//
|
||||
limit = prev_calculated - 1;
|
||||
if (limit < 0)
|
||||
{
|
||||
limit = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
result =
|
||||
cheLength >= 9 &&
|
||||
cheLoopback >= 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(cheLength, cheLoopback);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// LEVEL 1 ...
|
||||
|
||||
//
|
||||
// Long Exit 1 ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE le1DrawType = showLE1 ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE le1StartDrawType = showLE1 ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(le1BufferIndex, le1Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(le1BufferIndex, PLOT_SHOW_DATA, showLE1);
|
||||
PlotIndexSetInteger(le1BufferIndex, PLOT_DRAW_TYPE, le1DrawType);
|
||||
|
||||
//
|
||||
// Start Buffer ...
|
||||
SetIndexBuffer(le1StartBufferIndex, le1StartBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(le1StartBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(le1StartBufferIndex, PLOT_DRAW_TYPE, le1StartDrawType);
|
||||
PlotIndexSetInteger(le1StartBufferIndex, PLOT_ARROW, cheArrowCode);
|
||||
|
||||
//
|
||||
// Short Exit 1 ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE se1DrawType = showSE1 ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE se1StartDrawType = showSE1 ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(se1BufferIndex, se1Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(se1BufferIndex, PLOT_SHOW_DATA, showSE1);
|
||||
PlotIndexSetInteger(se1BufferIndex, PLOT_DRAW_TYPE, se1DrawType);
|
||||
|
||||
//
|
||||
// Start Buffer ...
|
||||
SetIndexBuffer(se1StartBufferIndex, se1StartBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(se1StartBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(se1StartBufferIndex, PLOT_DRAW_TYPE, se1StartDrawType);
|
||||
PlotIndexSetInteger(se1StartBufferIndex, PLOT_ARROW, cheArrowCode);
|
||||
|
||||
//
|
||||
// LEVEL 2 ...
|
||||
|
||||
//
|
||||
// Long Exit 2 ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE le2DrawType = showLE2 ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE le2StartDrawType = showLE2 ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(le2BufferIndex, le2Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(le2BufferIndex, PLOT_SHOW_DATA, showLE2);
|
||||
PlotIndexSetInteger(le2BufferIndex, PLOT_DRAW_TYPE, le2DrawType);
|
||||
|
||||
//
|
||||
// Start Buffer ...
|
||||
SetIndexBuffer(le2StartBufferIndex, le2StartBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(le2StartBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(le2StartBufferIndex, PLOT_DRAW_TYPE, le2StartDrawType);
|
||||
PlotIndexSetInteger(le2StartBufferIndex, PLOT_ARROW, cheArrowCode);
|
||||
|
||||
//
|
||||
// Short Exit 2 ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE se2DrawType = showSE2 ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE se2StartDrawType = showSE2 ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(se2BufferIndex, se2Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(se2BufferIndex, PLOT_SHOW_DATA, showSE2);
|
||||
PlotIndexSetInteger(se2BufferIndex, PLOT_DRAW_TYPE, se2DrawType);
|
||||
|
||||
//
|
||||
// Start Buffer ...
|
||||
SetIndexBuffer(se2StartBufferIndex, se2StartBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(se2StartBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(se2StartBufferIndex, PLOT_DRAW_TYPE, se2StartDrawType);
|
||||
PlotIndexSetInteger(se2StartBufferIndex, PLOT_ARROW, cheArrowCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
int prevCalculated, // Previous Calculated
|
||||
int ratesTotal, // Total Rates
|
||||
const double &open[], // Rates Open ...
|
||||
const double &high[], // Rates High ...
|
||||
const double &low[], // Rates Low ...
|
||||
const double &close[] // Rates Close ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// Cleanup Buffers ...
|
||||
le1Buffer[bar_index] = le1StartBuffer[bar_index] = se1Buffer[bar_index] = se1StartBuffer[bar_index] = EMPTY_VALUE;
|
||||
le2Buffer[bar_index] = le2StartBuffer[bar_index] = se2Buffer[bar_index] = se2StartBuffer[bar_index] = EMPTY_VALUE;
|
||||
|
||||
//
|
||||
int start = MathMax(bar_index - cheLoopback, 0);
|
||||
|
||||
//
|
||||
// Calculate ATR Value ...
|
||||
double atrValue = 0;
|
||||
for (int k = 1; k <= cheLength && (bar_index - k - 1) >= 0; k++)
|
||||
{
|
||||
//
|
||||
atrValue += MathMax(high[bar_index - k], close[MathMax(bar_index - k - 1, 0)]) -
|
||||
MathMin(low[bar_index - k], close[MathMax(bar_index - k - 1, 0)]);
|
||||
}
|
||||
atrValue /= (double)cheLength;
|
||||
|
||||
//
|
||||
// Retrieve Highest High and Lowest Lows ...
|
||||
double cheLoopbackMax = high[ArrayMaximum(high, start, cheLoopback)];
|
||||
double cheLoopbackMin = low[ArrayMinimum(low, start, cheLoopback)];
|
||||
|
||||
//
|
||||
// Fill Multi Dimesional Working Array ...
|
||||
work[bar_index][hi1Idx] = cheLoopbackMax - cheMultiplier1 * atrValue;
|
||||
work[bar_index][lo1Idx] = cheLoopbackMin + cheMultiplier1 * atrValue;
|
||||
work[bar_index][hi2Idx] = cheLoopbackMax - cheMultiplier2 * atrValue;
|
||||
work[bar_index][lo2Idx] = cheLoopbackMin + cheMultiplier2 * atrValue;
|
||||
work[bar_index][trend1Idx] = (bar_index > 0) ? work[bar_index - 1][trend1Idx] : 0;
|
||||
work[bar_index][trend2Idx] = (bar_index > 0) ? work[bar_index - 1][trend2Idx] : 0;
|
||||
|
||||
//
|
||||
if (bar_index > 0)
|
||||
{
|
||||
//
|
||||
// Calculate Trends ...
|
||||
if (close[bar_index] > work[bar_index - 1][lo1Idx])
|
||||
{
|
||||
work[bar_index][trend1Idx] = 1;
|
||||
}
|
||||
|
||||
//
|
||||
if (close[bar_index] < work[bar_index - 1][hi1Idx])
|
||||
{
|
||||
work[bar_index][trend1Idx] = -1;
|
||||
}
|
||||
|
||||
//
|
||||
if (close[bar_index] > work[bar_index - 1][lo2Idx])
|
||||
{
|
||||
work[bar_index][trend2Idx] = 1;
|
||||
}
|
||||
|
||||
//
|
||||
if (close[bar_index] < work[bar_index - 1][hi2Idx])
|
||||
{
|
||||
work[bar_index][trend2Idx] = -1;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Exit Values ...
|
||||
|
||||
//
|
||||
// Exit 1 ...
|
||||
|
||||
//
|
||||
// Long ...
|
||||
if (cheMultiplier1 > 0 && work[bar_index][trend1Idx] == 1)
|
||||
{
|
||||
//
|
||||
if (work[bar_index][hi1Idx] < work[bar_index - 1][hi1Idx])
|
||||
{
|
||||
work[bar_index][hi1Idx] = work[bar_index - 1][hi1Idx];
|
||||
}
|
||||
|
||||
//
|
||||
le1Buffer[bar_index] = work[bar_index][hi1Idx];
|
||||
|
||||
//
|
||||
if (le1Buffer[bar_index - 1] == EMPTY_VALUE)
|
||||
{
|
||||
le1StartBuffer[bar_index] = le1Buffer[bar_index];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Short ...
|
||||
if (cheMultiplier1 > 0 && work[bar_index][trend1Idx] == -1)
|
||||
{
|
||||
//
|
||||
if (work[bar_index][lo1Idx] > work[bar_index - 1][lo1Idx])
|
||||
{
|
||||
work[bar_index][lo1Idx] = work[bar_index - 1][lo1Idx];
|
||||
}
|
||||
|
||||
//
|
||||
se1Buffer[bar_index] = work[bar_index][lo1Idx];
|
||||
|
||||
//
|
||||
if (se1Buffer[bar_index - 1] == EMPTY_VALUE)
|
||||
{
|
||||
se1StartBuffer[bar_index] = se1Buffer[bar_index];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Exit 2 ...
|
||||
|
||||
//
|
||||
// Long ...
|
||||
if (cheMultiplier2 > 0 && work[bar_index][trend2Idx] == 1)
|
||||
{
|
||||
if (work[bar_index][hi2Idx] < work[bar_index - 1][hi2Idx])
|
||||
{
|
||||
work[bar_index][hi2Idx] = work[bar_index - 1][hi2Idx];
|
||||
}
|
||||
|
||||
//
|
||||
le2Buffer[bar_index] = work[bar_index][hi2Idx];
|
||||
|
||||
//
|
||||
if (le2Buffer[bar_index - 1] == EMPTY_VALUE)
|
||||
{
|
||||
le2StartBuffer[bar_index] = le2Buffer[bar_index];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Short ...
|
||||
if (cheMultiplier2 > 0 && work[bar_index][trend2Idx] == -1)
|
||||
{
|
||||
//
|
||||
if (work[bar_index][lo2Idx] > work[bar_index - 1][lo2Idx])
|
||||
{
|
||||
work[bar_index][lo2Idx] = work[bar_index - 1][lo2Idx];
|
||||
}
|
||||
|
||||
//
|
||||
se2Buffer[bar_index] = work[bar_index][lo2Idx];
|
||||
|
||||
//
|
||||
if (se2Buffer[bar_index - 1] == EMPTY_VALUE)
|
||||
{
|
||||
se2StartBuffer[bar_index] = se2Buffer[bar_index];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,692 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XDON
|
||||
// Description: XDON ...
|
||||
//
|
||||
//
|
||||
// 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 X121 XDON Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121 XDON"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int donchainLength = 40; // Donchain Length
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
|
||||
//
|
||||
input bool showUpper = true; // Show Upper Band
|
||||
input bool showLower = true; // Show Lower Band
|
||||
|
||||
//
|
||||
input bool showOpen = true; // Show Open
|
||||
input bool showHigh = true; // Show High
|
||||
input bool showClose = true; // Show Close
|
||||
input bool showLow = true; // Show Low
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 8
|
||||
#property indicator_plots 8
|
||||
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// Open ...
|
||||
|
||||
//
|
||||
#define donOpenUpperBufferIndex 0
|
||||
double donOpenUpperBuffer[];
|
||||
|
||||
//
|
||||
#define donOpenUpperPlotBufferIndex 0
|
||||
#property indicator_label1 "X121 O U"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrCornflowerBlue
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
#define donOpenLowerBufferIndex 1
|
||||
double donOpenLowerBuffer[];
|
||||
|
||||
//
|
||||
#define donOpenLowerPlotBufferIndex 1
|
||||
#property indicator_label2 "X121 O L"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrCornflowerBlue
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// High ...
|
||||
|
||||
//
|
||||
#define donHighUpperBufferIndex 2
|
||||
double donHighUpperBuffer[];
|
||||
|
||||
//
|
||||
#define donHighUpperPlotBufferIndex 2
|
||||
#property indicator_label3 "X121 H U"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrAquamarine
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
#define donHighLowerBufferIndex 3
|
||||
double donHighLowerBuffer[];
|
||||
|
||||
//
|
||||
#define donHighLowerPlotBufferIndex 3
|
||||
#property indicator_label4 "X121 H L"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrAquamarine
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// Low ...
|
||||
|
||||
//
|
||||
#define donLowUpperBufferIndex 4
|
||||
double donLowUpperBuffer[];
|
||||
|
||||
//
|
||||
#define donLowUpperPlotBufferIndex 4
|
||||
#property indicator_label5 "X121 L U"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrDarkOrchid
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
#define donLowLowerBufferIndex 5
|
||||
double donLowLowerBuffer[];
|
||||
|
||||
//
|
||||
#define donLowLowerPlotBufferIndex 5
|
||||
#property indicator_label6 "X121 L L"
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_color6 clrDarkOrchid
|
||||
#property indicator_width6 1
|
||||
|
||||
//
|
||||
// Close ...
|
||||
|
||||
//
|
||||
#define donCloseUpperBufferIndex 6
|
||||
double donCloseUpperBuffer[];
|
||||
|
||||
//
|
||||
#define donCloseUpperPlotBufferIndex 6
|
||||
#property indicator_label7 "X121 C U"
|
||||
#property indicator_type7 DRAW_LINE
|
||||
#property indicator_color7 clrCoral
|
||||
#property indicator_width7 1
|
||||
|
||||
//
|
||||
#define donCloseLowerBufferIndex 7
|
||||
double donCloseLowerBuffer[];
|
||||
|
||||
//
|
||||
#define donCloseLowerPlotBufferIndex 7
|
||||
#property indicator_label8 "X121 C L"
|
||||
#property indicator_type8 DRAW_LINE
|
||||
#property indicator_color8 clrCoral
|
||||
#property indicator_width8 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 7;
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// 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);
|
||||
|
||||
//
|
||||
// Validate Calculated Bars ...
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
donchainLength > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Plot Buffers ...
|
||||
//
|
||||
// Open ...
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
bool canShowCOpenUpper = showUpper && showOpen;
|
||||
ENUM_DRAW_TYPE donOpenUpperDrawType = canShowCOpenUpper ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(donOpenUpperBuffer, true);
|
||||
SetIndexBuffer(donOpenUpperBufferIndex, donOpenUpperBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(donOpenUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(donOpenUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCOpenUpper);
|
||||
PlotIndexSetInteger(donOpenUpperPlotBufferIndex, PLOT_DRAW_TYPE, donOpenUpperDrawType);
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
bool canShowCOpenLower = showLower && showOpen;
|
||||
ENUM_DRAW_TYPE donOpenLowerDrawType = canShowCOpenLower ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(donOpenLowerBuffer, true);
|
||||
SetIndexBuffer(donOpenLowerBufferIndex, donOpenLowerBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(donOpenLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(donOpenLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCOpenLower);
|
||||
PlotIndexSetInteger(donOpenLowerPlotBufferIndex, PLOT_DRAW_TYPE, donOpenLowerDrawType);
|
||||
|
||||
//
|
||||
// Close ...
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
bool canShowCCloseUpper = showUpper && showClose;
|
||||
ENUM_DRAW_TYPE donCloseUpperDrawType = canShowCCloseUpper ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(donCloseUpperBuffer, true);
|
||||
SetIndexBuffer(donCloseUpperBufferIndex, donCloseUpperBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(donCloseUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(donCloseUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCCloseUpper);
|
||||
PlotIndexSetInteger(donCloseUpperPlotBufferIndex, PLOT_DRAW_TYPE, donCloseUpperDrawType);
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
bool canShowCCloseLower = showLower && showClose;
|
||||
ENUM_DRAW_TYPE donCloseLowerDrawType = canShowCCloseLower ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(donCloseLowerBuffer, true);
|
||||
SetIndexBuffer(donCloseLowerBufferIndex, donCloseLowerBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(donCloseLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(donCloseLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCCloseLower);
|
||||
PlotIndexSetInteger(donCloseLowerPlotBufferIndex, PLOT_DRAW_TYPE, donCloseLowerDrawType);
|
||||
|
||||
//
|
||||
// High ...
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
bool canShowCHighUpper = showUpper && showHigh;
|
||||
ENUM_DRAW_TYPE donHighUpperDrawType = canShowCHighUpper ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(donHighUpperBuffer, true);
|
||||
SetIndexBuffer(donHighUpperBufferIndex, donHighUpperBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(donHighUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(donHighUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCHighUpper);
|
||||
PlotIndexSetInteger(donHighUpperPlotBufferIndex, PLOT_DRAW_TYPE, donHighUpperDrawType);
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
bool canShowCHighLower = showLower && showHigh;
|
||||
ENUM_DRAW_TYPE donHighLowerDrawType = canShowCHighLower ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(donHighLowerBuffer, true);
|
||||
SetIndexBuffer(donHighLowerBufferIndex, donHighLowerBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(donHighLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(donHighLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCHighLower);
|
||||
PlotIndexSetInteger(donHighLowerPlotBufferIndex, PLOT_DRAW_TYPE, donHighLowerDrawType);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
bool canShowCLowUpper = showUpper && showLow;
|
||||
ENUM_DRAW_TYPE donLowUpperDrawType = canShowCLowUpper ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(donLowUpperBuffer, true);
|
||||
SetIndexBuffer(donLowUpperBufferIndex, donLowUpperBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(donLowUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(donLowUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCLowUpper);
|
||||
PlotIndexSetInteger(donLowUpperPlotBufferIndex, PLOT_DRAW_TYPE, donLowUpperDrawType);
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
bool canShowCLowLower = showLower && showLow;
|
||||
ENUM_DRAW_TYPE donLowLowerDrawType = canShowCLowLower ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(donLowLowerBuffer, true);
|
||||
SetIndexBuffer(donLowLowerBufferIndex, donLowLowerBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(donLowLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(donLowLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCLowLower);
|
||||
PlotIndexSetInteger(donLowLowerPlotBufferIndex, PLOT_DRAW_TYPE, donLowLowerDrawType);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Custom Buffers ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int barsLimit = startCalculationForLastBars > 0
|
||||
? startCalculationForLastBars
|
||||
: 0;
|
||||
//
|
||||
// bool canCalculate = true;
|
||||
bool canCalculate =
|
||||
barsLimit == 0 ||
|
||||
bar_index <= barsLimit;
|
||||
if (canCalculate)
|
||||
{
|
||||
//
|
||||
CalculateDonchains(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBuffersZero(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Custom ...
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
donOpenUpperBuffer[barIndex] = EMPTY_VALUE;
|
||||
donOpenLowerBuffer[barIndex] = EMPTY_VALUE;
|
||||
donCloseUpperBuffer[barIndex] = EMPTY_VALUE;
|
||||
donCloseLowerBuffer[barIndex] = EMPTY_VALUE;
|
||||
donHighUpperBuffer[barIndex] = EMPTY_VALUE;
|
||||
donHighLowerBuffer[barIndex] = EMPTY_VALUE;
|
||||
donLowUpperBuffer[barIndex] = EMPTY_VALUE;
|
||||
donLowLowerBuffer[barIndex] = EMPTY_VALUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Donchain ...
|
||||
*
|
||||
* @param bar_index: Integer, Bar Index ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
* @param _length: Integer, Donchain Length ...
|
||||
* @param _ouBuffer: Double Array Reference ...
|
||||
* @param _olBuffer: Double Array Reference ...
|
||||
* @param _huBuffer: Double Array Reference ...
|
||||
* @param _hlBuffer: Double Array Reference ...
|
||||
* @param _luBuffer: Double Array Reference ...
|
||||
* @param _llBuffer: Double Array Reference ...
|
||||
* @param _cuBuffer: Double Array Reference ...
|
||||
* @param _clBuffer: Double Array Reference ...
|
||||
*/
|
||||
void CalculateDonchain(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
//
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[],
|
||||
//
|
||||
int _length,
|
||||
//
|
||||
double &_ouBuffer[],
|
||||
double &_olBuffer[],
|
||||
double &_huBuffer[],
|
||||
double &_hlBuffer[],
|
||||
double &_luBuffer[],
|
||||
double &_llBuffer[],
|
||||
double &_cuBuffer[],
|
||||
double &_clBuffer[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
double iUpper = 0;
|
||||
double iLower = 0;
|
||||
|
||||
//
|
||||
// OPEN ...
|
||||
|
||||
//
|
||||
int from = bar_index;
|
||||
|
||||
//
|
||||
iUpper = open[ArrayMaximum(open, from, _length)];
|
||||
iLower = open[ArrayMinimum(open, from, _length)];
|
||||
|
||||
//
|
||||
_ouBuffer[bar_index] = iUpper;
|
||||
_olBuffer[bar_index] = iLower;
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
|
||||
//
|
||||
iUpper = high[ArrayMaximum(high, from, _length)];
|
||||
iLower = high[ArrayMinimum(high, from, _length)];
|
||||
|
||||
//
|
||||
_huBuffer[bar_index] = iUpper;
|
||||
_hlBuffer[bar_index] = iLower;
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
|
||||
//
|
||||
iUpper = low[ArrayMaximum(low, from, _length)];
|
||||
iLower = low[ArrayMinimum(low, from, _length)];
|
||||
|
||||
//
|
||||
_luBuffer[bar_index] = iUpper;
|
||||
_llBuffer[bar_index] = iLower;
|
||||
|
||||
//
|
||||
// CLOSE ...
|
||||
|
||||
//
|
||||
iUpper = close[ArrayMaximum(close, from, _length)];
|
||||
iLower = close[ArrayMinimum(close, from, _length)];
|
||||
|
||||
//
|
||||
_cuBuffer[bar_index] = iUpper;
|
||||
_clBuffer[bar_index] = iLower;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Different VWaps ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateDonchains(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
CalculateDonchain(
|
||||
//
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
donchainLength,
|
||||
//
|
||||
donOpenUpperBuffer,
|
||||
donOpenLowerBuffer,
|
||||
donHighUpperBuffer,
|
||||
donHighLowerBuffer,
|
||||
donLowUpperBuffer,
|
||||
donLowLowerBuffer,
|
||||
donCloseUpperBuffer,
|
||||
donCloseLowerBuffer //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,636 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XSTR
|
||||
// Description: XSTR ...
|
||||
//
|
||||
//
|
||||
// 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 X121 XSTR Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121 XSTR"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int strLength = 14; // Length
|
||||
input double strMultiplier = 3; // Multiplier
|
||||
input ENUM_APPLIED_PRICE strAppliedTo = PRICE_MEDIAN; // Applied To
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input bool showStr = true; // Show Str
|
||||
input bool showStrUpper = true; // Show Str Upper
|
||||
input bool showStrLower = true; // Show Str Lower
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 7
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
// STR ...
|
||||
#define strBufferIndex 0
|
||||
double strBuffer[];
|
||||
|
||||
#define strColorBufferIndex 1
|
||||
double strColorBuffer[];
|
||||
|
||||
//
|
||||
#define strPlotBufferIndex 0
|
||||
#property indicator_label1 "X121 STR"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 CLR_NONE, clrLime, clrRed, clrGray
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 2
|
||||
|
||||
//
|
||||
// Up ...
|
||||
#define strUpBufferIndex 2
|
||||
double strUpBuffer[];
|
||||
|
||||
//
|
||||
#define strUpPlotBufferIndex 1
|
||||
#property indicator_label2 "X121 STR U"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 C'255,106,0'
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Down ...
|
||||
#define strDownBufferIndex 3
|
||||
double strDownBuffer[];
|
||||
|
||||
//
|
||||
#define strDownPlotBufferIndex 2
|
||||
#property indicator_label3 "X121 STR D"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 C'255,106,0'
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 3;
|
||||
|
||||
//
|
||||
// STR ...
|
||||
|
||||
//
|
||||
// Atr ...
|
||||
#define atrBufferIndex mLastBufferIndex + 1
|
||||
double atrBuffer[];
|
||||
|
||||
//
|
||||
// Price ...
|
||||
#define strPriceBufferIndex mLastBufferIndex + 2
|
||||
double strPriceBuffer[];
|
||||
|
||||
//
|
||||
// Trend ...
|
||||
#define strStateBufferIndex mLastBufferIndex + 3
|
||||
double strStateBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// ATR Handler ...
|
||||
int atrHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
bool isStrTrendChanged;
|
||||
bool isStrStartBearishTrend;
|
||||
bool isStrStartBullishTrend;
|
||||
|
||||
//
|
||||
int changeOfTrend;
|
||||
int startBearishTrend;
|
||||
int startBullishTrend;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
atrHandler = iATR(
|
||||
_Symbol,
|
||||
_Period,
|
||||
strLength //
|
||||
);
|
||||
bool isInited = atrHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
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
|
||||
|
||||
//
|
||||
IndicatorRelease(atrHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
|
||||
//
|
||||
// Validate Calculated Bars ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
int atrCalculatedBars = BarsCalculated(atrHandler);
|
||||
|
||||
//
|
||||
bool isPassedRequiredCalculatedBars =
|
||||
//
|
||||
// ATR ...
|
||||
atrCalculatedBars >= 0
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCalculatedBars)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// checking for the limit start of calculation of an indicator ...
|
||||
limit =
|
||||
(prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? maxLength
|
||||
: prev_calculated - 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
int copiedAtrs = CopyBuffer(atrHandler, 0, 0, rates_total, atrBuffer);
|
||||
|
||||
//
|
||||
// Validate Copied Items ...
|
||||
bool isPassedRequiredCopiedItems =
|
||||
//
|
||||
// ATR ...
|
||||
copiedAtrs >= 0
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCopiedItems)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
// STR ...
|
||||
strLength > 0 &&
|
||||
strMultiplier > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(1, strLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// STR ...
|
||||
SetIndexBuffer(strBufferIndex, strBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(strColorBufferIndex, strColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE strUpDrawType = showStrUpper ? DRAW_LINE : DRAW_NONE;
|
||||
SetIndexBuffer(strUpBufferIndex, strUpBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(strUpPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(strUpPlotBufferIndex, PLOT_SHOW_DATA, showStrUpper);
|
||||
PlotIndexSetInteger(strUpPlotBufferIndex, PLOT_DRAW_TYPE, strUpDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE strDownDrawType = showStrLower ? DRAW_LINE : DRAW_NONE;
|
||||
SetIndexBuffer(strDownBufferIndex, strDownBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(strDownPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(strDownPlotBufferIndex, PLOT_SHOW_DATA, showStrLower);
|
||||
PlotIndexSetInteger(strDownPlotBufferIndex, PLOT_DRAW_TYPE, strDownDrawType);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
// STR ...
|
||||
|
||||
//
|
||||
SetIndexBuffer(strPriceBufferIndex, strPriceBuffer, INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(strStateBufferIndex, strStateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Custom Buffers ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
CalculateStr(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Custom ...
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
// STR ...
|
||||
strBuffer[barIndex] = 0;
|
||||
strUpBuffer[barIndex] = 0;
|
||||
strDownBuffer[barIndex] = 0;
|
||||
strPriceBuffer[barIndex] = 0;
|
||||
strColorBuffer[barIndex] = hideColorIDX;
|
||||
strStateBuffer[barIndex] = hideColorIDX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate STR ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
*/
|
||||
void CalculateStr(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Calculated Price ...
|
||||
double price = GetAppliedPrice(
|
||||
strAppliedTo,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
strPriceBuffer[bar_index] = price;
|
||||
|
||||
//
|
||||
double atr = atrBuffer[bar_index];
|
||||
|
||||
//
|
||||
// Up ...
|
||||
strUpBuffer[bar_index] = price + (strMultiplier * atr);
|
||||
|
||||
//
|
||||
// Down ...
|
||||
strDownBuffer[bar_index] = price - (strMultiplier * atr);
|
||||
|
||||
//
|
||||
if (close[bar_index] > strUpBuffer[bar_index - 1])
|
||||
{
|
||||
//
|
||||
strStateBuffer[bar_index] = 1;
|
||||
if (strStateBuffer[bar_index - 1] == -1)
|
||||
{
|
||||
changeOfTrend = 1;
|
||||
}
|
||||
}
|
||||
else if (close[bar_index] < strDownBuffer[bar_index - 1])
|
||||
{
|
||||
//
|
||||
strStateBuffer[bar_index] = -1;
|
||||
if (strStateBuffer[bar_index - 1] == 1)
|
||||
{
|
||||
changeOfTrend = 1;
|
||||
}
|
||||
}
|
||||
else if (strStateBuffer[bar_index - 1] == 1)
|
||||
{
|
||||
//
|
||||
strStateBuffer[bar_index] = 1;
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
else if (strStateBuffer[bar_index - 1] == -1)
|
||||
{
|
||||
//
|
||||
strStateBuffer[bar_index] = -1;
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Down Trend Starting ...
|
||||
if (strStateBuffer[bar_index] < 0 && strStateBuffer[bar_index - 1] > 0)
|
||||
{
|
||||
startBearishTrend = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
startBearishTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Up Trend Starting ...
|
||||
if (strStateBuffer[bar_index] > 0 && strStateBuffer[bar_index - 1] < 0)
|
||||
{
|
||||
startBullishTrend = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
startBullishTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
if (strStateBuffer[bar_index] > 0 && strDownBuffer[bar_index] < strDownBuffer[bar_index - 1])
|
||||
{
|
||||
strDownBuffer[bar_index] = strDownBuffer[bar_index - 1];
|
||||
}
|
||||
|
||||
//
|
||||
if (strStateBuffer[bar_index] < 0 && strUpBuffer[bar_index] > strUpBuffer[bar_index - 1])
|
||||
{
|
||||
strUpBuffer[bar_index] = strUpBuffer[bar_index - 1];
|
||||
}
|
||||
|
||||
//
|
||||
if (startBearishTrend == 1)
|
||||
{
|
||||
strUpBuffer[bar_index] = strPriceBuffer[bar_index] + (strMultiplier * atr);
|
||||
}
|
||||
|
||||
//
|
||||
if (startBullishTrend == 1)
|
||||
{
|
||||
strDownBuffer[bar_index] = strPriceBuffer[bar_index] - (strMultiplier * atr);
|
||||
}
|
||||
|
||||
//
|
||||
// Draw the indicator ...
|
||||
|
||||
//
|
||||
double colorIDX = hideColorIDX;
|
||||
strColorBuffer[bar_index] = colorIDX;
|
||||
|
||||
//
|
||||
if (strStateBuffer[bar_index] == 1)
|
||||
{
|
||||
//
|
||||
strBuffer[bar_index] = strDownBuffer[bar_index];
|
||||
if (changeOfTrend == 1)
|
||||
{
|
||||
strBuffer[bar_index - 1] = strBuffer[bar_index - 2];
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
colorIDX = bullishColorIDX;
|
||||
}
|
||||
else if (strStateBuffer[bar_index] == -1)
|
||||
{
|
||||
//
|
||||
strBuffer[bar_index] = strUpBuffer[bar_index];
|
||||
if (changeOfTrend == 1)
|
||||
{
|
||||
//
|
||||
strBuffer[bar_index - 1] = strBuffer[bar_index - 2];
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
colorIDX = bearishColorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
if (showStr)
|
||||
{
|
||||
strColorBuffer[bar_index] = colorIDX;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,711 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XVWAP
|
||||
// Description: XVWAP ...
|
||||
//
|
||||
//
|
||||
// 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 X121 XVWAP Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121 XVWAP"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int vwapFastLength = 20; // Fast Length
|
||||
input int vwapMidLength = 40; // Mid Length
|
||||
input int vwapSlowLength = 60; // Slow Length
|
||||
input ENUM_APPLIED_PRICE vwapAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
|
||||
//
|
||||
input bool showVWapFast = true; // Show VWap Fast
|
||||
input bool showVWapMedium = true; // Show VWap Medium
|
||||
input bool showVWapSlow = true; // Show VWap Slow
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 11
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
#define vwapFastBufferIndex 0
|
||||
double vwapFastBuffer[];
|
||||
|
||||
#define vwapFastColorBufferIndex 1
|
||||
double vwapFastColorBuffer[];
|
||||
|
||||
//
|
||||
#define vwapFastPlotBufferIndex 0
|
||||
#property indicator_label1 "X121 VWF"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 CLR_NONE, clrAqua, clrMagenta, clrGray
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 2
|
||||
|
||||
//
|
||||
// MID ...
|
||||
#define vwapMidBufferIndex 2
|
||||
double vwapMidBuffer[];
|
||||
|
||||
#define vwapMidColorBufferIndex 3
|
||||
double vwapMidColorBuffer[];
|
||||
|
||||
//
|
||||
#define vwapMidPlotBufferIndex 1
|
||||
#property indicator_label2 "X121 VWM"
|
||||
#property indicator_type2 DRAW_COLOR_LINE
|
||||
#property indicator_color2 CLR_NONE, clrGreen, clrRed, clrGray
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 2
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
#define vwapSlowBufferIndex 4
|
||||
double vwapSlowBuffer[];
|
||||
|
||||
#define vwapSlowColorBufferIndex 5
|
||||
double vwapSlowColorBuffer[];
|
||||
|
||||
//
|
||||
#define vwapSlowPlotBufferIndex 2
|
||||
#property indicator_label3 "X121 VWS"
|
||||
#property indicator_type3 DRAW_COLOR_LINE
|
||||
#property indicator_color3 CLR_NONE, clrSteelBlue, clrDarkRed, clrGray
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 2
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 5;
|
||||
|
||||
//
|
||||
// Volume ...
|
||||
#define vwapVolumeBufferIndex mLastBufferIndex + 1
|
||||
double vwapVolumeBuffer[];
|
||||
|
||||
//
|
||||
// Price ...
|
||||
#define vwapPriceBufferIndex mLastBufferIndex + 2
|
||||
double vwapPriceBuffer[];
|
||||
|
||||
//
|
||||
// Fast State ...
|
||||
#define vwapFastStateBufferIndex mLastBufferIndex + 3
|
||||
double vwapFastStateBuffer[];
|
||||
|
||||
//
|
||||
// Mid State ...
|
||||
#define vwapMidStateBufferIndex mLastBufferIndex + 4
|
||||
double vwapMidStateBuffer[];
|
||||
|
||||
//
|
||||
// Slow State ...
|
||||
#define vwapSlowStateBufferIndex mLastBufferIndex + 5
|
||||
double vwapSlowStateBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// 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);
|
||||
|
||||
//
|
||||
// Validate Calculated Bars ...
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
vwapFastLength > 2 &&
|
||||
vwapMidLength > vwapFastLength &&
|
||||
vwapSlowLength > vwapMidLength
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// XVWAP ...
|
||||
result = MathMax(result, vwapFastLength);
|
||||
result = MathMax(result, vwapMidLength);
|
||||
result = MathMax(result, vwapSlowLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// Fast ...
|
||||
ArraySetAsSeries(vwapFastBuffer, true);
|
||||
ArraySetAsSeries(vwapFastColorBuffer, true);
|
||||
SetIndexBuffer(vwapFastBufferIndex, vwapFastBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(vwapFastColorBufferIndex, vwapFastColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
ArraySetAsSeries(vwapMidBuffer, true);
|
||||
ArraySetAsSeries(vwapMidColorBuffer, true);
|
||||
SetIndexBuffer(vwapMidBufferIndex, vwapMidBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(vwapMidColorBufferIndex, vwapMidColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Slow ...
|
||||
ArraySetAsSeries(vwapSlowBuffer, true);
|
||||
ArraySetAsSeries(vwapSlowColorBuffer, true);
|
||||
SetIndexBuffer(vwapSlowBufferIndex, vwapSlowBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(vwapSlowColorBufferIndex, vwapSlowColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
// Volumes ...
|
||||
ArraySetAsSeries(vwapVolumeBuffer, true);
|
||||
SetIndexBuffer(vwapVolumeBufferIndex, vwapVolumeBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Price ...
|
||||
ArraySetAsSeries(vwapPriceBuffer, true);
|
||||
SetIndexBuffer(vwapPriceBufferIndex, vwapPriceBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Fast State ...
|
||||
ArraySetAsSeries(vwapFastStateBuffer, true);
|
||||
SetIndexBuffer(vwapFastStateBufferIndex, vwapFastStateBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Mid State ...
|
||||
ArraySetAsSeries(vwapMidStateBuffer, true);
|
||||
SetIndexBuffer(vwapMidStateBufferIndex, vwapMidStateBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Slow State ...
|
||||
ArraySetAsSeries(vwapSlowStateBuffer, true);
|
||||
SetIndexBuffer(vwapSlowStateBufferIndex, vwapSlowStateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Custom Buffers ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int barsLimit = startCalculationForLastBars > 0
|
||||
? startCalculationForLastBars
|
||||
: 0;
|
||||
//
|
||||
// bool canCalculate = true;
|
||||
bool canCalculate =
|
||||
barsLimit == 0 ||
|
||||
bar_index <= barsLimit;
|
||||
if (canCalculate)
|
||||
{
|
||||
//
|
||||
// Calculate Required VWAP Data Buffers ...
|
||||
if (ratesTotal - bar_index <= maxLength)
|
||||
{
|
||||
//
|
||||
CalculateVWAPDataBuffers(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
|
||||
//
|
||||
// Prevent Moving Forward ...
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
CalculateVWAPDataBuffers(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
|
||||
//
|
||||
CalculateVWAPS(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBuffersZero(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Custom ...
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
vwapFastBuffer[barIndex] = EMPTY_VALUE;
|
||||
vwapMidBuffer[barIndex] = EMPTY_VALUE;
|
||||
vwapSlowBuffer[barIndex] = EMPTY_VALUE;
|
||||
vwapVolumeBuffer[barIndex] = EMPTY_VALUE;
|
||||
vwapPriceBuffer[barIndex] = EMPTY_VALUE;
|
||||
|
||||
//
|
||||
vwapFastColorBuffer[barIndex] = hideColorIDX;
|
||||
vwapMidColorBuffer[barIndex] = hideColorIDX;
|
||||
vwapSlowColorBuffer[barIndex] = hideColorIDX;
|
||||
vwapFastStateBuffer[barIndex] = hideColorIDX;
|
||||
vwapMidStateBuffer[barIndex] = hideColorIDX;
|
||||
vwapSlowStateBuffer[barIndex] = hideColorIDX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate VWAP Value for Specified Bar ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
* @param _length: Integer, Specified VWAP Length ...
|
||||
* @param _show: Boolean, Specified Show Buffer or not ...
|
||||
* @param _buffer: Double Array Reference, Points to Buffer ...
|
||||
* @param _colorBuffer: Double Array Reference, Points to Color Buffer ...
|
||||
* @param _stateBuffer: Double Array Reference, Points to State Buffer ...
|
||||
*/
|
||||
void CalculateVWAP(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[],
|
||||
//
|
||||
int _length, // Calculation Length
|
||||
bool _show,
|
||||
double &_buffer[],
|
||||
double &_colorBuffer[],
|
||||
double &_stateBuffer[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
double vSum = 0;
|
||||
double pSum = 0;
|
||||
double mSum = 0;
|
||||
for (int x = 0; x < _length; x++)
|
||||
{
|
||||
//
|
||||
pSum += vwapPriceBuffer[x + bar_index];
|
||||
vSum += vwapVolumeBuffer[x + bar_index];
|
||||
mSum += vwapPriceBuffer[x + bar_index] * vwapVolumeBuffer[x + bar_index];
|
||||
}
|
||||
|
||||
//
|
||||
double iValue = mSum / vSum;
|
||||
iValue = NormalizeDouble(iValue, _Digits);
|
||||
|
||||
//
|
||||
_buffer[bar_index] = iValue;
|
||||
|
||||
//
|
||||
bool isBullish = low[bar_index] > iValue;
|
||||
bool isBearish = high[bar_index] < iValue;
|
||||
|
||||
//
|
||||
double iColor =
|
||||
isBullish
|
||||
? bullishColorIDX
|
||||
: isBearish
|
||||
? bearishColorIDX
|
||||
: neuturalColorIDX;
|
||||
|
||||
//
|
||||
_colorBuffer[bar_index] = hideColorIDX;
|
||||
_stateBuffer[bar_index] = iColor;
|
||||
if (_show)
|
||||
{
|
||||
_colorBuffer[bar_index] = iColor;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate VWAP Required Data Buffers ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateVWAPDataBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
double price = GetAppliedPrice(
|
||||
vwapAppliedTo,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
vwapPriceBuffer[bar_index] = price;
|
||||
vwapVolumeBuffer[bar_index] = (double)tickVolume[bar_index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Different VWaps ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateVWAPS(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Fast ...
|
||||
CalculateVWAP(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
vwapFastLength,
|
||||
showVWapFast,
|
||||
vwapFastBuffer,
|
||||
vwapFastColorBuffer,
|
||||
vwapFastStateBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
CalculateVWAP(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
vwapMidLength,
|
||||
showVWapMedium,
|
||||
vwapMidBuffer,
|
||||
vwapMidColorBuffer,
|
||||
vwapMidStateBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
// Fast ...
|
||||
CalculateVWAP(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
vwapSlowLength,
|
||||
showVWapSlow,
|
||||
vwapSlowBuffer,
|
||||
vwapSlowColorBuffer,
|
||||
vwapSlowStateBuffer //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
Binary file not shown.
@@ -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 ...
|
||||
//
|
||||
Binary file not shown.
@@ -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
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,35 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// --------------------------------------
|
||||
// Name: XChartObjects
|
||||
// Description: provides all require Chart Objects ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#include "../../Classes/x-saherelm.x-cobject.class.mq5"
|
||||
#include "../Libraries/x-121.smc.lib.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
enum ENUM_X121SMC_CHARTOBJECTS
|
||||
{
|
||||
X_121_NONE_OBJ
|
||||
};
|
||||
|
||||
//
|
||||
// Implementations ...
|
||||
@@ -0,0 +1,63 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// --------------------------------------
|
||||
// Name: XC121Panel
|
||||
// Description: provides all based classes for use ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../../Classes/x-saherelm.x-app-dialog.class.mq5"
|
||||
|
||||
//
|
||||
// Implementation ...
|
||||
|
||||
//
|
||||
class X121CAppDialog : public XCAppDialog
|
||||
{
|
||||
//
|
||||
public:
|
||||
//
|
||||
// Constructor(s) ...
|
||||
void X121CAppDialog()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~X121CAppDialog()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
void Configure()
|
||||
{
|
||||
//
|
||||
// Configure Dialog ...
|
||||
BackgroundColor(clrBlack);
|
||||
}
|
||||
|
||||
//
|
||||
protected:
|
||||
//
|
||||
|
||||
//
|
||||
private:
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
@@ -0,0 +1,779 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// --------------------------------------
|
||||
// Name: XC121SMCCycleHelper
|
||||
// Description: provides all based classes for use ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../../Classes/x-saherelm.x-bar.analyser.class.mq5"
|
||||
#include "../../Classes/x-saherelm.x-poi.class.mq5"
|
||||
#include "../Libraries/x-121.smc.lib.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Implementations ...
|
||||
|
||||
enum ENUM_X_CYCLES
|
||||
{
|
||||
X_CYCLE_NONE,
|
||||
X_CYCLE_TRIGGER,
|
||||
X_CYCLE_DECISION,
|
||||
X_CYCLE_ANALYSE,
|
||||
X_CYCLE_VERIFICATION,
|
||||
X_CYCLE_CONSOLIDATION,
|
||||
X_CYCLE_VISION,
|
||||
};
|
||||
|
||||
string ToString(ENUM_X_CYCLES value)
|
||||
{
|
||||
//
|
||||
string result = EnumToString(value);
|
||||
|
||||
//
|
||||
StringReplace(result, "X_CYCLE_", "");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
enum ENUM_X_CYCLE_EVENTS
|
||||
{
|
||||
SAR_CHANGE_DETECTED,
|
||||
NEW_PEAK_DETECTED,
|
||||
NEW_VALE_DETECTED,
|
||||
PIVOT_POINT_DETECTED,
|
||||
VWAP_ORDER_CHANGE_ETECTED,
|
||||
VWAP_STATE_CHANGE_DETCTED,
|
||||
CONSOLIDATION_BREAKED_DETECTED,
|
||||
PEAK_PIVOT_STARTED,
|
||||
PEAK_PIVOT_ENDED,
|
||||
VALE_PIVOT_STARTED,
|
||||
VALE_PIVOT_ENDED,
|
||||
};
|
||||
|
||||
class XC121SMCCycleHelper : public XCBase
|
||||
{
|
||||
//
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// X121 ...
|
||||
XCX121Helper *mX121Helper;
|
||||
|
||||
//
|
||||
// POI Detector ...
|
||||
XCPOIDrawer *mPOIDrawer;
|
||||
XCPOIDetector *mPOIDetector;
|
||||
|
||||
//
|
||||
// Bar Analyser
|
||||
XCBarAnalyser *mBarAnalyser;
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
XC121SMCCycleHelper()
|
||||
{
|
||||
Default();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XC121SMCCycleHelper()
|
||||
{
|
||||
DeInit();
|
||||
}
|
||||
|
||||
//
|
||||
// Getter/Setter(s) ...
|
||||
|
||||
//
|
||||
// Actions ...
|
||||
|
||||
/**
|
||||
* Initialize ...
|
||||
*
|
||||
* @param symbol: String ...
|
||||
* @param period: ENUM_TIMEFRAMES member ...
|
||||
* @param x121Inputs: X121Inputs instance ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool Init(
|
||||
string symbol,
|
||||
ENUM_TIMEFRAMES period,
|
||||
X121Inputs &x121Inputs,
|
||||
int requiredPOIS = 50 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (requiredPOIS < 10)
|
||||
{
|
||||
requiredPOIS = 10;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValid(symbol) &&
|
||||
IsValid(period);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// X121 ...
|
||||
mX121Helper = new XCX121Helper();
|
||||
result = mX121Helper.Init(
|
||||
symbol,
|
||||
period,
|
||||
x121Inputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mPOIDetector = new XCPOIDetector(
|
||||
symbol,
|
||||
period //
|
||||
);
|
||||
mPOIDetector.MaxNumberOfRequiredPOIs(requiredPOIS);
|
||||
mPOIDetector.Init();
|
||||
|
||||
//
|
||||
// Initialize Bar Analyser Class Instance ...
|
||||
mBarAnalyser = new XCBarAnalyser();
|
||||
|
||||
//
|
||||
// Initial and Configure POI Drawer if Required ...
|
||||
mPOIDrawer = new XCPOIDrawer();
|
||||
mPOIDrawer.ChartIdentification(0);
|
||||
mPOIDrawer.SubWindowIdentification(0);
|
||||
|
||||
//
|
||||
mPOIDrawer.DemandZoneFill(false);
|
||||
mPOIDrawer.SupplyZoneFill(false);
|
||||
mPOIDrawer.BullishFVGFill(false);
|
||||
mPOIDrawer.BearishFVGFill(false);
|
||||
mPOIDrawer.SupportZoneFill(false);
|
||||
mPOIDrawer.ResistanceZoneFill(false);
|
||||
mPOIDrawer.BullishOrderBlockFill(false);
|
||||
mPOIDrawer.BearishOrderBlockFill(false);
|
||||
|
||||
//
|
||||
// Set Chart Style ...
|
||||
ApplyChartStyle();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Symbol ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GetSymbol()
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
result = mX121Helper.GetSymbol();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve TimeFrame (Period) ...
|
||||
*
|
||||
* @return ( ENUM_TIMEFRAMES )
|
||||
*/
|
||||
ENUM_TIMEFRAMES GetPeriod()
|
||||
{
|
||||
//
|
||||
ENUM_TIMEFRAMES result = NULL;
|
||||
|
||||
//
|
||||
result = mX121Helper.GetPeriod();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Specified Bar ...
|
||||
*
|
||||
* @param source: XOHCL instance, Source Bar ...
|
||||
* @param bar: XOHCL instance, Dest Bar ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool GetBar(
|
||||
XOHCL &source,
|
||||
XOHCL &bar //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bar.Clean();
|
||||
|
||||
//
|
||||
string symbol = GetSymbol();
|
||||
ENUM_TIMEFRAMES period = GetPeriod();
|
||||
|
||||
//
|
||||
result =
|
||||
IsValid(symbol) &&
|
||||
IsValid(period) &&
|
||||
source.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int index = iBarShift(
|
||||
symbol,
|
||||
period,
|
||||
source.time //
|
||||
);
|
||||
result = bar.Init(
|
||||
symbol,
|
||||
period,
|
||||
index //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
bar.Clean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Specified Bar ...
|
||||
*
|
||||
* @param bar: XOHCL instance ...
|
||||
* @param index: Integer ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool GetBar(
|
||||
XOHCL &bar,
|
||||
int index = 0 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bar.Clean();
|
||||
|
||||
//
|
||||
if (index < 0)
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
|
||||
//
|
||||
string symbol = GetSymbol();
|
||||
ENUM_TIMEFRAMES period = GetPeriod();
|
||||
|
||||
//
|
||||
result = bar.Init(
|
||||
symbol,
|
||||
period,
|
||||
index //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Specified Bar ...
|
||||
*
|
||||
* @param bar: XOHCL instance ...
|
||||
* @param time: Datetime ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool GetBar(
|
||||
XOHCL &bar,
|
||||
datetime time = NULL //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
int index = GetBarIndex(time);
|
||||
result = GetBar(bar,
|
||||
index //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Specified Time Bar Index ...
|
||||
*
|
||||
* @param time: DateTime ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int GetBarIndex(datetime time = NULL)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
time = NormalizeTime(time);
|
||||
|
||||
//
|
||||
string symbol = GetSymbol();
|
||||
ENUM_TIMEFRAMES period = GetPeriod();
|
||||
|
||||
//
|
||||
result = iBarShift(
|
||||
symbol,
|
||||
period,
|
||||
time //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect Market Structure Method 2 ...
|
||||
*
|
||||
* @param model: XMarketStructure instance Reference ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool DetectMarketStructure(
|
||||
ENUM_X_DIRECTION &dir,
|
||||
int pivotsCount = 3 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
int barIndex = 0;
|
||||
|
||||
//
|
||||
if (pivotsCount < 3)
|
||||
{
|
||||
pivotsCount = 3;
|
||||
}
|
||||
|
||||
//
|
||||
dir = X_DIRECTION_NONE;
|
||||
string symbol = GetSymbol();
|
||||
ENUM_TIMEFRAMES period = GetPeriod();
|
||||
|
||||
//
|
||||
int hpIndex = -1;
|
||||
int hpIndexes[];
|
||||
double hpValues[];
|
||||
|
||||
//
|
||||
int lvIndex = -1;
|
||||
int lvIndexes[];
|
||||
double lvValues[];
|
||||
|
||||
//
|
||||
for (int i = 0; i < pivotsCount; i++)
|
||||
{
|
||||
//
|
||||
hpIndex = barIndex;
|
||||
lvIndex = barIndex;
|
||||
|
||||
//
|
||||
double lastHP = 0;
|
||||
double lastLV = 0;
|
||||
|
||||
//
|
||||
int hpCount = ArraySize(hpIndexes);
|
||||
int lvCount = ArraySize(lvIndexes);
|
||||
|
||||
//
|
||||
if (IsValidSize(hpCount))
|
||||
{
|
||||
//
|
||||
lastHP = hpValues[hpCount - 1];
|
||||
hpIndex = hpIndexes[hpCount - 1];
|
||||
}
|
||||
|
||||
//
|
||||
if (IsValidSize(lvCount))
|
||||
{
|
||||
//
|
||||
lastLV = lvValues[lvCount - 1];
|
||||
lvIndex = lvIndexes[lvCount - 1];
|
||||
}
|
||||
|
||||
//
|
||||
if (lastHP == 0)
|
||||
{
|
||||
//
|
||||
lastHP = mX121Helper
|
||||
.xpvHelper
|
||||
.GetPeak(hpIndex);
|
||||
}
|
||||
|
||||
//
|
||||
if (lastLV == 0)
|
||||
{
|
||||
//
|
||||
lastLV = mX121Helper
|
||||
.xpvHelper
|
||||
.GetVale(lvIndex);
|
||||
}
|
||||
|
||||
//
|
||||
int highestPeakIndex = -1;
|
||||
double highesrPeak =
|
||||
mX121Helper
|
||||
.xpvHelper
|
||||
.GetHigherPeak(
|
||||
highestPeakIndex,
|
||||
lastHP,
|
||||
hpIndex //
|
||||
);
|
||||
if (IsValidIndex(highestPeakIndex))
|
||||
{
|
||||
//
|
||||
Add(
|
||||
highestPeakIndex,
|
||||
hpIndexes //
|
||||
);
|
||||
|
||||
//
|
||||
Add(
|
||||
highesrPeak,
|
||||
hpValues //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
int lowestValeIndex = -1;
|
||||
double lowestVale =
|
||||
mX121Helper
|
||||
.xpvHelper
|
||||
.GetLowerVale(
|
||||
lowestValeIndex,
|
||||
lastLV,
|
||||
lvIndex //
|
||||
);
|
||||
if (IsValidIndex(lowestValeIndex))
|
||||
{
|
||||
//
|
||||
Add(
|
||||
lowestValeIndex,
|
||||
lvIndexes //
|
||||
);
|
||||
|
||||
//
|
||||
Add(
|
||||
lowestVale,
|
||||
lvValues //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bool canBreak = ArraySize(hpIndexes) >= pivotsCount ||
|
||||
ArraySize(lvIndexes) >= pivotsCount;
|
||||
if (canBreak)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
ArrayReverse(hpValues);
|
||||
ArrayReverse(hpIndexes);
|
||||
int countHPs = ArraySize(hpIndexes);
|
||||
|
||||
//
|
||||
ArrayReverse(lvValues);
|
||||
ArrayReverse(lvIndexes);
|
||||
int countLVs = ArraySize(lvIndexes);
|
||||
|
||||
//
|
||||
bool isValidHPs = countHPs >= pivotsCount;
|
||||
bool isValidLVs = countLVs >= pivotsCount;
|
||||
|
||||
//
|
||||
result = isValidHPs ||
|
||||
isValidLVs;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (isValidHPs && isValidLVs)
|
||||
{
|
||||
//
|
||||
hpIndex = hpIndexes[countHPs - 1];
|
||||
lvIndex = lvIndexes[countLVs - 1];
|
||||
}
|
||||
|
||||
//
|
||||
dir =
|
||||
!isValidHPs && isValidLVs
|
||||
? X_DIRECTION_BULLISH
|
||||
: !isValidLVs && isValidHPs
|
||||
? X_DIRECTION_BEARISH
|
||||
: hpIndex < lvIndex
|
||||
? X_DIRECTION_BEARISH
|
||||
: lvIndex < hpIndex
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_ALL;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect Order Blocks ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
bool DetectOrderBlocks(
|
||||
XCOrderBlock *&bullishOrderBlocks[],
|
||||
XCOrderBlock *&bearishOrderBlocks[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
Clean(bullishOrderBlocks);
|
||||
Clean(bearishOrderBlocks);
|
||||
|
||||
//
|
||||
XPOIState state;
|
||||
mPOIDetector.GetState(state);
|
||||
bool isValid = state.IsValid() &&
|
||||
state.HasChild();
|
||||
if (!isValid)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int bullOBsCount = DetectDirectionOrderBlocks(
|
||||
X_DIRECTION_BULLISH,
|
||||
state,
|
||||
bullishOrderBlocks //
|
||||
);
|
||||
|
||||
//
|
||||
int bearOBsCount = DetectDirectionOrderBlocks(
|
||||
X_DIRECTION_BEARISH,
|
||||
state,
|
||||
bearishOrderBlocks //
|
||||
);
|
||||
|
||||
//
|
||||
result = IsValidSize(bullOBsCount +
|
||||
bearOBsCount);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Cycle Conditions ...
|
||||
*
|
||||
* @param events: ENUM_X_CYCLE_EVENTS member, Array ...
|
||||
* @param conditions: X121SMCCycleConditions instance ...
|
||||
* @param barIndex: Integer ...
|
||||
* @param loopback: Integer ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool GetConditions(
|
||||
ENUM_X_CYCLE_EVENTS &events[],
|
||||
ENUM_XPOI_EVENTS &poiEvents[],
|
||||
X121SMCCycleConditions &conditions,
|
||||
int barIndex = 0,
|
||||
int loopback = 7 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
if (loopback < 5)
|
||||
{
|
||||
loopback = 5;
|
||||
}
|
||||
|
||||
//
|
||||
Clean(events);
|
||||
Clean(poiEvents);
|
||||
conditions.Clean();
|
||||
|
||||
//
|
||||
result = mX121Helper.GetConditions(
|
||||
conditions.x121Conditions,
|
||||
barIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
conditions.Clean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mPOIDetector.Update(poiEvents);
|
||||
mPOIDetector.GetState(conditions.state);
|
||||
|
||||
//
|
||||
conditions.symbol = conditions.x121Conditions.symbol;
|
||||
conditions.period = conditions.x121Conditions.period;
|
||||
conditions.time = TimeCurrent();
|
||||
|
||||
//
|
||||
result = conditions.IsValid();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Virtuals ...
|
||||
|
||||
/**
|
||||
* Set Default Properties Values ...
|
||||
*/
|
||||
virtual void Default()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
protected:
|
||||
//
|
||||
|
||||
//
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Actions ...
|
||||
|
||||
/**
|
||||
* Release All Resources ...
|
||||
*/
|
||||
void DeInit()
|
||||
{
|
||||
//
|
||||
delete mX121Helper;
|
||||
delete mPOIDetector;
|
||||
delete mBarAnalyser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply Chart Style ...
|
||||
*/
|
||||
void ApplyChartStyle()
|
||||
{
|
||||
//
|
||||
// Retrieve Current Chart ID ...
|
||||
long chartId = ChartID();
|
||||
|
||||
//
|
||||
ENUM_CHART_MODE mMode = CHART_CANDLES; // chart's mMode
|
||||
bool mShowBidLine = true; // show bid line
|
||||
bool mShowAskLine = true; // show ask line
|
||||
bool mShowGrid = false; // show grids on chart
|
||||
bool mShowVolumes = false; // show volumes
|
||||
bool mShowTradeLevels = true; // Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders)
|
||||
bool mAutoScroll = true; // chart autoscroll
|
||||
bool mQuickNavigation = true; // chart quick navigation state
|
||||
color mForeGroundColor = clrWhite; // chart's foreground color
|
||||
color mBackGroundColor = clrBlack; // chart's background color
|
||||
color mUpColor = clrGreen; // Up Color
|
||||
color mDownColor = clrRed; // Down Color
|
||||
color mBullishColor = clrGreen; // Bullish color
|
||||
color mBearishColor = clrRed; // Bearish color
|
||||
color mGridColor = clrGray; // grid color
|
||||
color mBidLineColor = clrGray; // bid line color
|
||||
color mAskLineColor = clrRed; // ask line color
|
||||
color mLineColor = clrLime; // line mMode and doji candlestick color
|
||||
color mStopColor = clrGold; // Color of stop order levels (Stop Loss and Take Profit)
|
||||
color mVolumesColor = clrGreen; // volumes color
|
||||
|
||||
//
|
||||
ChartSetInteger(chartId, CHART_MODE, mMode);
|
||||
ChartSetInteger(chartId, CHART_SHOW_BID_LINE, mShowBidLine);
|
||||
ChartSetInteger(chartId, CHART_SHOW_ASK_LINE, mShowAskLine);
|
||||
ChartSetInteger(chartId, CHART_SHOW_GRID, mShowGrid);
|
||||
ChartSetInteger(chartId, CHART_SHOW_VOLUMES, mShowVolumes);
|
||||
ChartSetInteger(chartId, CHART_SHOW_TRADE_LEVELS, mShowTradeLevels);
|
||||
ChartSetInteger(chartId, CHART_AUTOSCROLL, mAutoScroll);
|
||||
ChartSetInteger(chartId, CHART_QUICK_NAVIGATION, mQuickNavigation);
|
||||
ChartSetInteger(chartId, CHART_COLOR_FOREGROUND, mForeGroundColor);
|
||||
ChartSetInteger(chartId, CHART_COLOR_BACKGROUND, mBackGroundColor);
|
||||
ChartSetInteger(chartId, CHART_COLOR_CHART_UP, mUpColor);
|
||||
ChartSetInteger(chartId, CHART_COLOR_CHART_DOWN, mDownColor);
|
||||
ChartSetInteger(chartId, CHART_COLOR_CANDLE_BULL, mBullishColor);
|
||||
ChartSetInteger(chartId, CHART_COLOR_CANDLE_BEAR, mBearishColor);
|
||||
ChartSetInteger(chartId, CHART_COLOR_GRID, mGridColor);
|
||||
ChartSetInteger(chartId, CHART_COLOR_BID, mBidLineColor);
|
||||
ChartSetInteger(chartId, CHART_COLOR_ASK, mAskLineColor);
|
||||
ChartSetInteger(chartId, CHART_COLOR_STOP_LEVEL, mStopColor);
|
||||
ChartSetInteger(chartId, CHART_COLOR_CHART_LINE, mLineColor);
|
||||
ChartSetInteger(chartId, CHART_COLOR_VOLUME, mVolumesColor);
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,749 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Common Library
|
||||
// --------------------------------------
|
||||
// Name: X121SMCLib
|
||||
// Description: provide all commonly used functions ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../../Classes/x-saherelm.base.class.mq5"
|
||||
#include "../../Classes/x-saherelm.x-poi.drawer.class.mq5"
|
||||
#include "../../Helpers/x-saherelm.x121.helper.mq5"
|
||||
#include "../../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../../Libraries/x-saherelm.x-poi.lib.mq5"
|
||||
#include "../../Libraries/x-saherelm.x-trade.lib.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
const string X121SMCStrategyToken = "X121SMC";
|
||||
|
||||
//
|
||||
const string X121SMCXToken = "X121X";
|
||||
const string X121SMCXOBPVToken = "X121XOBPV";
|
||||
|
||||
//
|
||||
// X121 SMC Providers ...
|
||||
enum ENUM_X_121_SMC_PROVIDERS
|
||||
{
|
||||
//
|
||||
X_121_SMC_PROVIDER_NONE,
|
||||
X_121_SMC_PROVIDER_X,
|
||||
X_121_SMC_PROVIDER_XOBPV,
|
||||
};
|
||||
|
||||
//
|
||||
// Guard Actions ...
|
||||
enum ENUM_X_121_SMC_GUARD_ACTIONS
|
||||
{
|
||||
X_121_SMC_GUARD_ACTION_NONE, // Nothing to Do
|
||||
X_121_SMC_GUARD_ACTION_CLOSE, // Close Specified Position
|
||||
X_121_SMC_GUARD_ACTION_CLOSE_ALL, // Close All Positions
|
||||
X_121_SMC_GUARD_ACTION_CLOSE_LONGS, // Close All Long Positions
|
||||
X_121_SMC_GUARD_ACTION_CLOSE_SHORTS, // Close All Short Position
|
||||
X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE, // Partial Close Specified Position
|
||||
X_121_SMC_GUARD_ACTION_TRAIL_STOP, // Trail Stop of Specified Position
|
||||
X_121_SMC_GUARD_ACTION_TRAIL_TARGET, // Trail Target of Specified Position
|
||||
X_121_SMC_GUARD_ACTION_HEDGE, // Hedge Specified Positions
|
||||
};
|
||||
|
||||
//
|
||||
// Each Market Cycle (Time Frame) Conditions
|
||||
// Model as this Structure ...
|
||||
struct X121SMCCycleConditions
|
||||
{
|
||||
//
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
X121Conditions x121Conditions;
|
||||
|
||||
//
|
||||
XPOIState state;
|
||||
|
||||
//
|
||||
void X121SMCStrategyConditions()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleanup ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
time = NULL;
|
||||
|
||||
//
|
||||
state.Clean();
|
||||
x121Conditions.Clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsSpecifiedValid(symbol) &&
|
||||
IsSpecifiedValid(period) &&
|
||||
IsSpecifiedValid(time);
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reporter Functions ...
|
||||
|
||||
/**
|
||||
* Generate Provided Scores ...
|
||||
*
|
||||
* @param bullishScore: Integer, reference ...
|
||||
* @param bearishScore: Integer, referenceF ...
|
||||
*/
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (!IsValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double bullScore = 0;
|
||||
double bearScore = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Summary ...
|
||||
*
|
||||
* @param onlyCommons: Boolean ...
|
||||
* @param onlyConditions: Boolean ...
|
||||
* @param includeScores: Boolean ...
|
||||
* @param ignoreFalseConditions: Boolean ...
|
||||
* @param separator: String ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GenerateSummary(
|
||||
bool onlyCommons = false,
|
||||
bool onlyConditions = false,
|
||||
bool includeScores = true,
|
||||
bool ignoreFalseConditions = true,
|
||||
string separator = "\n" //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
string commonStr = GenerateSpecifiedCommonSummary(
|
||||
this,
|
||||
separator,
|
||||
includeScores,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
string conditionsStr =
|
||||
//
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
"----------" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Unique Identifier ...
|
||||
*
|
||||
* @param forObject: Boolean ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GetTag(
|
||||
bool forObject = false //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
string typeName = GetTypeName(this);
|
||||
|
||||
//
|
||||
if (!forObject)
|
||||
{
|
||||
result = typeName;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
result = typeName + "_" +
|
||||
symbol + "_" + ToString(period) + "_" +
|
||||
ToMD5(time);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Model Signalling Conditions ...
|
||||
struct X121SMCStrategyConditions
|
||||
{
|
||||
//
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
double sl;
|
||||
double tp;
|
||||
double target;
|
||||
string provider;
|
||||
ENUM_X_DIRECTION signalDir;
|
||||
|
||||
//
|
||||
X121Conditions conditions;
|
||||
// XPriceZones priceZones;
|
||||
// XPriceZones decisionZones;
|
||||
// XMarketStructure marketStructure;
|
||||
|
||||
//
|
||||
void X121SMCStrategyConditions()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleanup ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
time = NULL;
|
||||
|
||||
//
|
||||
sl = 0;
|
||||
tp = 0;
|
||||
provider = NULL;
|
||||
signalDir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
conditions.Clean();
|
||||
// priceZones.Clean();
|
||||
// decisionZones.Clean();
|
||||
// marketStructure.Clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsSpecifiedValid(symbol) &&
|
||||
IsSpecifiedValid(period) &&
|
||||
IsSpecifiedValid(time);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Conditions Has Valid Bullish Signal ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HasBullishSignal()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
(sl > 0 ||
|
||||
tp > 0) &&
|
||||
IsValid() &&
|
||||
HasDirection(signalDir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
IsBullish(signalDir);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Conditions Has Valid Bearish Signal ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HasBearishSignal()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
(sl > 0 ||
|
||||
tp > 0) &&
|
||||
IsValid() &&
|
||||
HasDirection(signalDir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
IsBearish(signalDir);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reporter Functions ...
|
||||
|
||||
/**
|
||||
* Generate Provided Scores ...
|
||||
*
|
||||
* @param bullishScore: Integer, reference ...
|
||||
* @param bearishScore: Integer, referenceF ...
|
||||
*/
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (!IsValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double bullScore = 0;
|
||||
double bearScore = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Summary ...
|
||||
*
|
||||
* @param onlyCommons: Boolean ...
|
||||
* @param onlyConditions: Boolean ...
|
||||
* @param includeScores: Boolean ...
|
||||
* @param ignoreFalseConditions: Boolean ...
|
||||
* @param separator: String ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GenerateSummary(
|
||||
bool onlyCommons = false,
|
||||
bool onlyConditions = false,
|
||||
bool includeScores = true,
|
||||
bool ignoreFalseConditions = true,
|
||||
string separator = "\n" //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
string commonStr = GenerateSpecifiedCommonSummary(
|
||||
this,
|
||||
separator,
|
||||
includeScores,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
string conditionsStr =
|
||||
//
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
"----------" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Unique Identifier ...
|
||||
*
|
||||
* @param forObject: Boolean ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GetTag(
|
||||
bool forObject = false //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
string typeName = GetTypeName(this);
|
||||
|
||||
//
|
||||
if (!forObject)
|
||||
{
|
||||
result = typeName;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
result = typeName + "_" +
|
||||
symbol + "_" + ToString(period) + "_" +
|
||||
ToMD5(time);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Model a Guard Action ...
|
||||
struct X121SMCGuard
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
ENUM_X_121_SMC_GUARD_ACTIONS action;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
string symbol;
|
||||
string provider;
|
||||
|
||||
//
|
||||
// Specified Position ...
|
||||
ulong ticket;
|
||||
|
||||
//
|
||||
// Partial Close ...
|
||||
double volumeMultiplier;
|
||||
|
||||
//
|
||||
// SL Trial ...
|
||||
double sl;
|
||||
|
||||
//
|
||||
// TP Trial ...
|
||||
double tp;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
X121SMCGuard()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleanup ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
time = NULL;
|
||||
action = X_121_SMC_GUARD_ACTION_NONE;
|
||||
|
||||
//
|
||||
symbol = NULL;
|
||||
provider = NULL;
|
||||
|
||||
//
|
||||
ticket = 0;
|
||||
|
||||
//
|
||||
volumeMultiplier = 0;
|
||||
|
||||
//
|
||||
sl = 0;
|
||||
tp = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
IsValid(time) &&
|
||||
IsValid(symbol) &&
|
||||
IsValid(provider) &&
|
||||
action != X_121_SMC_GUARD_ACTION_NONE
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Model Based On Specified Guard Actions ...
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Add Guard to Collection ...
|
||||
*
|
||||
* @param guard: X121SMCGuard instance ...
|
||||
* @param guards: X121SMCGuard instance Collection ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int AddGuard(
|
||||
X121SMCGuard &guard,
|
||||
X121SMCGuard &guards[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
if (!guard.IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
AddRef(
|
||||
guard,
|
||||
guards //
|
||||
);
|
||||
|
||||
//
|
||||
result = ArraySize(guards);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
typedef void (*TOnX121SMCSignal)(
|
||||
XSignal &signal,
|
||||
X121SMCStrategyConditions &conditions //
|
||||
);
|
||||
|
||||
//
|
||||
// Extentions ...
|
||||
|
||||
/**
|
||||
* Validate a Signal Provider ...
|
||||
*
|
||||
* @param value: ENUM_X_121_SMC_PROVIDERS member ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsValid(ENUM_X_121_SMC_PROVIDERS value)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = value != X_121_SMC_PROVIDER_NONE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Signal Provider to String ...
|
||||
*
|
||||
* @param value: ENUM_X_121_SMC_PROVIDERS member ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string ToString(ENUM_X_121_SMC_PROVIDERS value)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
if (!IsValid(value))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
switch (value)
|
||||
{
|
||||
//
|
||||
case X_121_SMC_PROVIDER_X:
|
||||
result = X121SMCXToken;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_121_SMC_PROVIDER_XOBPV:
|
||||
result = X121SMCXOBPVToken;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse Specified String as a Signal Provider ...
|
||||
*
|
||||
* @param value: String ...
|
||||
*
|
||||
* @return ( ENUM_X_121_SMC_PROVIDERS )
|
||||
*/
|
||||
ENUM_X_121_SMC_PROVIDERS ParseProvider(string value)
|
||||
{
|
||||
//
|
||||
ENUM_X_121_SMC_PROVIDERS result = X_121_SMC_PROVIDER_NONE;
|
||||
|
||||
//
|
||||
if (!IsValid(value))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (Contains(X121SMCXToken, value))
|
||||
{
|
||||
result = X_121_SMC_PROVIDER_X;
|
||||
}
|
||||
else if (Contains(X121SMCXOBPVToken, value))
|
||||
{
|
||||
result = X_121_SMC_PROVIDER_XOBPV;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user