last ...
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,278 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
|
||||
//
|
||||
// Overrides ...
|
||||
|
||||
//
|
||||
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,967 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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"
|
||||
|
||||
//
|
||||
// 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;
|
||||
|
||||
//
|
||||
ZeroMemory(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 ....";
|
||||
|
||||
//
|
||||
SendAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Initial All Requirements ...
|
||||
result = InitEA();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initial All GUI Requirements ...
|
||||
result = InitGUI();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
message = "Initialized Successfully ...";
|
||||
SendAlert(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;
|
||||
SendAlert(errMessage);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initializers and DeInitializers ...
|
||||
|
||||
/**
|
||||
* Initial EA Requirements ...
|
||||
*
|
||||
* @return ( virtual bool )
|
||||
*/
|
||||
virtual bool InitEA()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator Helpers ...
|
||||
|
||||
//
|
||||
// Create Trader Instance and Configure it ...
|
||||
mTrader = new XCTrade(
|
||||
mSlippage,
|
||||
mMagicNumber //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Initialized Requirements ...
|
||||
*/
|
||||
virtual void DestroyEA()
|
||||
{
|
||||
//
|
||||
delete mTrader;
|
||||
|
||||
//
|
||||
ZeroMemory(mTrader);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ...
|
||||
|
||||
//
|
||||
// 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 ...";
|
||||
|
||||
//
|
||||
SendAlert(msg);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Weekly Report ....
|
||||
if (mTimeTracker.IsNewWeek())
|
||||
{
|
||||
//
|
||||
HandleOnNewWeek();
|
||||
|
||||
//
|
||||
if (mReportNewWeeks)
|
||||
{
|
||||
//
|
||||
string msg = "New Week ...";
|
||||
|
||||
//
|
||||
SendAlert(msg);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Daily Report ....
|
||||
if (mTimeTracker.IsNewDay())
|
||||
{
|
||||
//
|
||||
HandleOnNewDay();
|
||||
|
||||
//
|
||||
if (mReportNewDays)
|
||||
{
|
||||
//
|
||||
string msg = "New Day ...";
|
||||
|
||||
//
|
||||
SendAlert(msg);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Hourly Report ....
|
||||
if (mTimeTracker.IsNewHour())
|
||||
{
|
||||
//
|
||||
HandleOnNewHour();
|
||||
|
||||
//
|
||||
if (mReportNewHours)
|
||||
{
|
||||
//
|
||||
string msg = "New Hour ...";
|
||||
|
||||
//
|
||||
SendAlert(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 ...
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,151 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
|
||||
//
|
||||
virtual void Free() {}
|
||||
|
||||
//
|
||||
// Generate Tag ...
|
||||
virtual string GetTag()
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
GetToken() +
|
||||
"[" +
|
||||
GetSymbol() + "|" +
|
||||
ToString(GetPeriod()) +
|
||||
"]"
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Symbol ...
|
||||
string mSymbol;
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES mPeriod;
|
||||
|
||||
//
|
||||
// Indicator Handler ...
|
||||
int mHandler;
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ....
|
||||
@@ -0,0 +1,373 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCHttp
|
||||
// Description: provides all HTTP requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
enum X_HTTP_METHOD
|
||||
{
|
||||
X_HTTP_GET,
|
||||
X_HTTP_POST
|
||||
};
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Classes/x-saherelm.base.class.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// a Class for Manage Account ...
|
||||
class XCHttp : public XCBase
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XCHttp()
|
||||
{
|
||||
XCHttp("", 10000);
|
||||
}
|
||||
void XCHttp(
|
||||
string path, // Base Folder to Store Data
|
||||
int timeout // base timeout for Requests
|
||||
)
|
||||
{
|
||||
//
|
||||
Path(path);
|
||||
Timeout(timeout);
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XCHttp()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Properties Getter(s) / Setter(s) ...
|
||||
|
||||
//
|
||||
// Path ...
|
||||
void Path(string value)
|
||||
{
|
||||
//
|
||||
mPath = value;
|
||||
|
||||
//
|
||||
if (!IsValid(mPath))
|
||||
{
|
||||
mPath = GetTag();
|
||||
}
|
||||
}
|
||||
|
||||
string Path()
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
//
|
||||
// Timeout ...
|
||||
void Timeout(int value)
|
||||
{
|
||||
mTimeout = value;
|
||||
}
|
||||
|
||||
//
|
||||
int Timeout()
|
||||
{
|
||||
return mTimeout;
|
||||
}
|
||||
|
||||
//
|
||||
// Error ...
|
||||
int Error()
|
||||
{
|
||||
return mError;
|
||||
}
|
||||
|
||||
//
|
||||
// Response ...
|
||||
string Response()
|
||||
{
|
||||
return mResponse;
|
||||
}
|
||||
|
||||
//
|
||||
// Overrides ...
|
||||
string GetTag() override
|
||||
{
|
||||
return GetSpecificToken(this);
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Send Global Request ...
|
||||
int SendRequest(
|
||||
X_HTTP_METHOD method, // Httm Request Method
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
string strMethod = ToString(method);
|
||||
if (StringLen(strMethod) == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reset State ...
|
||||
ResetState();
|
||||
|
||||
//
|
||||
result = WebRequest(
|
||||
strMethod,
|
||||
url,
|
||||
headers,
|
||||
timeout,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders);
|
||||
|
||||
//
|
||||
if (result < 0)
|
||||
{
|
||||
mError = GetLastError();
|
||||
}
|
||||
else
|
||||
{
|
||||
mResponse = CharArrayToString(response);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Get Request ...
|
||||
int GetRequest(
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = SendRequest(
|
||||
X_HTTP_GET,
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Post Request ...
|
||||
int PostRequest(
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = SendRequest(
|
||||
X_HTTP_POST,
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Download Specific URL Content to Specific Path and File Name ...
|
||||
bool Download(
|
||||
string url, // the URL address which going to download
|
||||
string fileName // Specify Destination file name to Store Response
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
string filePath = GetFilePath(fileName);
|
||||
string cookie = NULL;
|
||||
string referer = NULL;
|
||||
int timeout = Timeout();
|
||||
|
||||
//
|
||||
char payload[];
|
||||
string headers;
|
||||
char response[];
|
||||
string responseHeaders;
|
||||
|
||||
//
|
||||
// Send Request ...
|
||||
int requestResult = GetRequest(
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout);
|
||||
|
||||
//
|
||||
// Define File Handler ...
|
||||
int mFileHandler = FileOpen(
|
||||
filePath,
|
||||
FILE_WRITE | FILE_BIN);
|
||||
if (mFileHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
mError = GetLastError();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Write Response to File ...
|
||||
uint writed = FileWriteArray(
|
||||
mFileHandler,
|
||||
response,
|
||||
0,
|
||||
ArraySize(response));
|
||||
FileFlush(mFileHandler);
|
||||
FileClose(mFileHandler);
|
||||
|
||||
//
|
||||
result = writed > 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Destintion Folder Path ...
|
||||
string mPath;
|
||||
|
||||
//
|
||||
// WEB Request Timeout Value ...
|
||||
int mTimeout;
|
||||
|
||||
//
|
||||
// WEB Request's Response ...
|
||||
string mResponse;
|
||||
|
||||
//
|
||||
// Error Value ...
|
||||
int mError;
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Reset Errors State ...
|
||||
void ResetState()
|
||||
{
|
||||
//
|
||||
// Reset Errors ...
|
||||
mError = -1;
|
||||
mResponse = "";
|
||||
ResetLastError();
|
||||
}
|
||||
|
||||
//
|
||||
// Generate Full File Path ...
|
||||
string GetFilePath(string fileName)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
Path() + "\\" + fileName
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Convert enum to String ...
|
||||
string ToString(X_HTTP_METHOD method)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
switch (method)
|
||||
{
|
||||
//
|
||||
case X_HTTP_GET:
|
||||
result = "GET";
|
||||
break;
|
||||
|
||||
//
|
||||
case X_HTTP_POST:
|
||||
result = "POST";
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,445 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCMD5
|
||||
// Description: Provides MD5 Hashing Requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
static uchar _md5_PADDING[64] =
|
||||
{
|
||||
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
|
||||
//
|
||||
#define _md5_F(x, y, z) (((x) & (y)) | ((~x) & (z)))
|
||||
#define _md5_G(x, y, z) (((x) & (z)) | ((y) & (~z)))
|
||||
#define _md5_H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
#define _md5_I(x, y, z) ((y) ^ ((x) | (~z)))
|
||||
#define _md5_ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
|
||||
|
||||
//
|
||||
#define _md5_FF(a, b, c, d, x, s, ac) \
|
||||
{ \
|
||||
(a) += _md5_F((b), (c), (d)) + (x) + (uint)(ac); \
|
||||
(a) = _md5_ROTATE_LEFT((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
//
|
||||
#define _md5_GG(a, b, c, d, x, s, ac) \
|
||||
{ \
|
||||
(a) += _md5_G((b), (c), (d)) + (x) + (uint)(ac); \
|
||||
(a) = _md5_ROTATE_LEFT((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
//
|
||||
#define _md5_HH(a, b, c, d, x, s, ac) \
|
||||
{ \
|
||||
(a) += _md5_H((b), (c), (d)) + (x) + (uint)(ac); \
|
||||
(a) = _md5_ROTATE_LEFT((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
//
|
||||
#define _md5_II(a, b, c, d, x, s, ac) \
|
||||
{ \
|
||||
(a) += _md5_I((b), (c), (d)) + (x) + (uint)(ac); \
|
||||
(a) = _md5_ROTATE_LEFT((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
//
|
||||
#define _md5_INIT_STATE_0 0x67452301
|
||||
#define _md5_INIT_STATE_1 0xefcdab89
|
||||
#define _md5_INIT_STATE_2 0x98badcfe
|
||||
#define _md5_INIT_STATE_3 0x10325476
|
||||
|
||||
//
|
||||
#define _md5_S11 7
|
||||
#define _md5_S12 12
|
||||
#define _md5_S13 17
|
||||
#define _md5_S14 22
|
||||
|
||||
//
|
||||
#define _md5_S21 5
|
||||
#define _md5_S22 9
|
||||
#define _md5_S23 14
|
||||
#define _md5_S24 20
|
||||
|
||||
//
|
||||
#define _md5_S31 4
|
||||
#define _md5_S32 11
|
||||
#define _md5_S33 16
|
||||
#define _md5_S34 23
|
||||
|
||||
//
|
||||
#define _md5_S41 6
|
||||
#define _md5_S42 10
|
||||
#define _md5_S43 15
|
||||
#define _md5_S44 21
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// XCMD5 a library for Hashing ...
|
||||
class XCMD5
|
||||
{
|
||||
//
|
||||
// Public Provides ...
|
||||
public:
|
||||
//
|
||||
// Protected Provides ...
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XCMD5(void)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCMD5(void)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Hash Specified Char Array ...
|
||||
string Hash(
|
||||
uchar &mSource[], // Specify Char Array to Hash
|
||||
int mLength = 0 // Specify Length of Char Array which required to hash
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
int sourceCount = ArraySize(mSource);
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
sourceCount <= 0 ||
|
||||
(sourceCount > 0 && mLength > sourceCount))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Normalize Args ...
|
||||
if (mLength == 0)
|
||||
{
|
||||
mLength = sourceCount;
|
||||
}
|
||||
|
||||
//
|
||||
// Init MD5 ...
|
||||
MD5Init();
|
||||
|
||||
//
|
||||
// Update Buffer ...
|
||||
MD5Update(mSource, mLength);
|
||||
|
||||
//
|
||||
// Calculate Result ...
|
||||
result = MD5Final();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Hash Specified String ...
|
||||
string Hash(
|
||||
string mSource // Specified String
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
// Converts String to Char Array ...
|
||||
uchar bytes[];
|
||||
StringToCharArray(
|
||||
mSource,
|
||||
bytes,
|
||||
0,
|
||||
StringLen(mSource));
|
||||
|
||||
//
|
||||
result = Hash(
|
||||
bytes,
|
||||
ArraySize(bytes));
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
protected:
|
||||
//
|
||||
// Private Provides ...
|
||||
private:
|
||||
//
|
||||
uint m_lMD5[4];
|
||||
uint m_nCount[2];
|
||||
uchar m_lpszBuffer[64];
|
||||
|
||||
//
|
||||
// Convert Byte to DWord ...
|
||||
void ByteToDWord(int &out[], uint &in[], uint len)
|
||||
{
|
||||
//
|
||||
uint i = 0;
|
||||
uint j = 0;
|
||||
|
||||
//
|
||||
for (; j < len; i++, j += 4)
|
||||
{
|
||||
out[i] = (int)in[j] | (int)in[j + 1] << 8 | (int)in[j + 2] << 16 | (int)in[j + 3] << 24;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Convert DWord to Byte ...
|
||||
void DWordToByte(uchar &out[], int &in[], uint len)
|
||||
{
|
||||
//
|
||||
uint i = 0;
|
||||
uint j = 0;
|
||||
|
||||
//
|
||||
for (; j < len; i++, j += 4)
|
||||
{
|
||||
//
|
||||
out[j] = (uchar)(in[i] & 0xff);
|
||||
out[j + 1] = (uchar)((in[i] >> 8) & 0xff);
|
||||
out[j + 2] = (uchar)((in[i] >> 16) & 0xff);
|
||||
out[j + 3] = (uchar)((in[i] >> 24) & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Init MD5 Array ...
|
||||
void MD5Init()
|
||||
{
|
||||
//
|
||||
ArrayInitialize(m_lpszBuffer, 64);
|
||||
|
||||
//
|
||||
m_nCount[0] = m_nCount[1] = 0;
|
||||
m_lMD5[0] = _md5_INIT_STATE_0;
|
||||
m_lMD5[1] = _md5_INIT_STATE_1;
|
||||
m_lMD5[2] = _md5_INIT_STATE_2;
|
||||
m_lMD5[3] = _md5_INIT_STATE_3;
|
||||
}
|
||||
|
||||
//
|
||||
// Update MD5 ...
|
||||
void MD5Update(uchar &inBuf[], uint inLen)
|
||||
{
|
||||
//
|
||||
int i, ii;
|
||||
int mdi;
|
||||
|
||||
//
|
||||
uint in[16];
|
||||
int i0 = 0;
|
||||
|
||||
//
|
||||
mdi = (int)((m_nCount[0] >> 3) & 0x3F);
|
||||
|
||||
//
|
||||
if ((m_nCount[0] + ((uint)inLen << 3)) < m_nCount[0])
|
||||
{
|
||||
m_nCount[1]++;
|
||||
}
|
||||
|
||||
//
|
||||
m_nCount[0] += ((uint)inLen << 3);
|
||||
m_nCount[1] += ((uint)inLen >> 29);
|
||||
|
||||
//
|
||||
while ((inLen--) > 0)
|
||||
{
|
||||
//
|
||||
m_lpszBuffer[mdi++] = inBuf[i0++];
|
||||
if (mdi == 0x40)
|
||||
{
|
||||
//
|
||||
for (i = 0, ii = 0; i < 16; i++, ii += 4)
|
||||
{
|
||||
in[i] = (((uint)m_lpszBuffer[ii + 3]) << 24) | (((uint)m_lpszBuffer[ii + 2]) << 16) | (((uint)m_lpszBuffer[ii + 1]) << 8) | ((uint)m_lpszBuffer[ii]);
|
||||
}
|
||||
|
||||
//
|
||||
Transform(m_lMD5, in);
|
||||
|
||||
//
|
||||
mdi = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Finalize an MD5 Expression ...
|
||||
string MD5Final()
|
||||
{
|
||||
//
|
||||
uchar bits[8];
|
||||
int nIndex;
|
||||
uint nPadLen;
|
||||
const int nMD5Size = 16;
|
||||
uchar lpszMD5[16];
|
||||
string temp;
|
||||
string out = "";
|
||||
int i;
|
||||
|
||||
//
|
||||
DWordToByte(bits, m_nCount, 8);
|
||||
nIndex = (int)((m_nCount[0] >> 3) & 0x3f);
|
||||
nPadLen = (nIndex < 56) ? (56 - nIndex) : (120 - nIndex);
|
||||
MD5Update(_md5_PADDING, nPadLen);
|
||||
MD5Update(bits, 8);
|
||||
DWordToByte(lpszMD5, m_lMD5, nMD5Size);
|
||||
|
||||
//
|
||||
for (i = 0; i < nMD5Size; i++)
|
||||
{
|
||||
//
|
||||
if (lpszMD5[i] == 0)
|
||||
{
|
||||
temp = "00";
|
||||
}
|
||||
else if (lpszMD5[i] <= 15)
|
||||
{
|
||||
temp = StringFormat("0%x", lpszMD5[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
temp = StringFormat("%x", lpszMD5[i]);
|
||||
}
|
||||
|
||||
//
|
||||
out += temp;
|
||||
}
|
||||
|
||||
//
|
||||
lpszMD5[0] = '\0';
|
||||
|
||||
//
|
||||
return (out);
|
||||
}
|
||||
|
||||
//
|
||||
// Transform Buffers ...
|
||||
void Transform(uint &buf[], uint &in[])
|
||||
{
|
||||
//
|
||||
uint a = buf[0], b = buf[1], c = buf[2], d = buf[3];
|
||||
|
||||
//
|
||||
_md5_FF(a, b, c, d, in[0], _md5_S11, 0xD76AA478);
|
||||
_md5_FF(d, a, b, c, in[1], _md5_S12, 0xE8C7B756);
|
||||
_md5_FF(c, d, a, b, in[2], _md5_S13, 0x242070DB);
|
||||
_md5_FF(b, c, d, a, in[3], _md5_S14, 0xC1BDCEEE);
|
||||
_md5_FF(a, b, c, d, in[4], _md5_S11, 0xF57C0FAF);
|
||||
_md5_FF(d, a, b, c, in[5], _md5_S12, 0x4787C62A);
|
||||
_md5_FF(c, d, a, b, in[6], _md5_S13, 0xA8304613);
|
||||
_md5_FF(b, c, d, a, in[7], _md5_S14, 0xFD469501);
|
||||
_md5_FF(a, b, c, d, in[8], _md5_S11, 0x698098D8);
|
||||
_md5_FF(d, a, b, c, in[9], _md5_S12, 0x8B44F7AF);
|
||||
_md5_FF(c, d, a, b, in[10], _md5_S13, 0xFFFF5BB1);
|
||||
_md5_FF(b, c, d, a, in[11], _md5_S14, 0x895CD7BE);
|
||||
_md5_FF(a, b, c, d, in[12], _md5_S11, 0x6B901122);
|
||||
_md5_FF(d, a, b, c, in[13], _md5_S12, 0xFD987193);
|
||||
_md5_FF(c, d, a, b, in[14], _md5_S13, 0xA679438E);
|
||||
_md5_FF(b, c, d, a, in[15], _md5_S14, 0x49B40821);
|
||||
|
||||
//
|
||||
_md5_GG(a, b, c, d, in[1], _md5_S21, 0xF61E2562);
|
||||
_md5_GG(d, a, b, c, in[6], _md5_S22, 0xC040B340);
|
||||
_md5_GG(c, d, a, b, in[11], _md5_S23, 0x265E5A51);
|
||||
_md5_GG(b, c, d, a, in[0], _md5_S24, 0xE9B6C7AA);
|
||||
_md5_GG(a, b, c, d, in[5], _md5_S21, 0xD62F105D);
|
||||
_md5_GG(d, a, b, c, in[10], _md5_S22, 0x02441453);
|
||||
_md5_GG(c, d, a, b, in[15], _md5_S23, 0xD8A1E681);
|
||||
_md5_GG(b, c, d, a, in[4], _md5_S24, 0xE7D3FBC8);
|
||||
_md5_GG(a, b, c, d, in[9], _md5_S21, 0x21E1CDE6);
|
||||
_md5_GG(d, a, b, c, in[14], _md5_S22, 0xC33707D6);
|
||||
_md5_GG(c, d, a, b, in[3], _md5_S23, 0xF4D50D87);
|
||||
_md5_GG(b, c, d, a, in[8], _md5_S24, 0x455A14ED);
|
||||
_md5_GG(a, b, c, d, in[13], _md5_S21, 0xA9E3E905);
|
||||
_md5_GG(d, a, b, c, in[2], _md5_S22, 0xFCEFA3F8);
|
||||
_md5_GG(c, d, a, b, in[7], _md5_S23, 0x676F02D9);
|
||||
_md5_GG(b, c, d, a, in[12], _md5_S24, 0x8D2A4C8A);
|
||||
|
||||
//
|
||||
_md5_HH(a, b, c, d, in[5], _md5_S31, 0xFFFA3942);
|
||||
_md5_HH(d, a, b, c, in[8], _md5_S32, 0x8771F681);
|
||||
_md5_HH(c, d, a, b, in[11], _md5_S33, 0x6D9D6122);
|
||||
_md5_HH(b, c, d, a, in[14], _md5_S34, 0xFDE5380C);
|
||||
_md5_HH(a, b, c, d, in[1], _md5_S31, 0xA4BEEA44);
|
||||
_md5_HH(d, a, b, c, in[4], _md5_S32, 0x4BDECFA9);
|
||||
_md5_HH(c, d, a, b, in[7], _md5_S33, 0xF6BB4B60);
|
||||
_md5_HH(b, c, d, a, in[10], _md5_S34, 0xBEBFBC70);
|
||||
_md5_HH(a, b, c, d, in[13], _md5_S31, 0x289B7EC6);
|
||||
_md5_HH(d, a, b, c, in[0], _md5_S32, 0xEAA127FA);
|
||||
_md5_HH(c, d, a, b, in[3], _md5_S33, 0xD4EF3085);
|
||||
_md5_HH(b, c, d, a, in[6], _md5_S34, 0x04881D05);
|
||||
_md5_HH(a, b, c, d, in[9], _md5_S31, 0xD9D4D039);
|
||||
_md5_HH(d, a, b, c, in[12], _md5_S32, 0xE6DB99E5);
|
||||
_md5_HH(c, d, a, b, in[15], _md5_S33, 0x1FA27CF8);
|
||||
_md5_HH(b, c, d, a, in[2], _md5_S34, 0xC4AC5665);
|
||||
|
||||
//
|
||||
_md5_II(a, b, c, d, in[0], _md5_S41, 0xF4292244);
|
||||
_md5_II(d, a, b, c, in[7], _md5_S42, 0x432AFF97);
|
||||
_md5_II(c, d, a, b, in[14], _md5_S43, 0xAB9423A7);
|
||||
_md5_II(b, c, d, a, in[5], _md5_S44, 0xFC93A039);
|
||||
_md5_II(a, b, c, d, in[12], _md5_S41, 0x655B59C3);
|
||||
_md5_II(d, a, b, c, in[3], _md5_S42, 0x8F0CCC92);
|
||||
_md5_II(c, d, a, b, in[10], _md5_S43, 0xFFEFF47D);
|
||||
_md5_II(b, c, d, a, in[1], _md5_S44, 0x85845DD1);
|
||||
_md5_II(a, b, c, d, in[8], _md5_S41, 0x6FA87E4F);
|
||||
_md5_II(d, a, b, c, in[15], _md5_S42, 0xFE2CE6E0);
|
||||
_md5_II(c, d, a, b, in[6], _md5_S43, 0xA3014314);
|
||||
_md5_II(b, c, d, a, in[13], _md5_S44, 0x4E0811A1);
|
||||
_md5_II(a, b, c, d, in[4], _md5_S41, 0xF7537E82);
|
||||
_md5_II(d, a, b, c, in[11], _md5_S42, 0xBD3AF235);
|
||||
_md5_II(c, d, a, b, in[2], _md5_S43, 0x2AD7D2BB);
|
||||
_md5_II(b, c, d, a, in[9], _md5_S44, 0xEB86D391);
|
||||
|
||||
//
|
||||
buf[0] += a;
|
||||
buf[1] += b;
|
||||
buf[2] += c;
|
||||
buf[3] += d;
|
||||
}
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,792 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// --------------------------------------
|
||||
// Name: XCVolume
|
||||
// Description: provides all Requirements for Volume Managing ...
|
||||
//
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// Template Variables of Inputs for Using ...
|
||||
// input group "Volume";
|
||||
// input ENUM_X_VOLUME_SELECT_TYPE eaVolumeSelect = X_VOLUME_STATIC; // Volume Applying Type
|
||||
// input double eaStaticVoluem = X_MIN_VOLUME; // Static Volume
|
||||
// input double eaDynamicVolumeStepBalance = 0.0; // Step of Balance for Increase Volume
|
||||
// input double eaDynamicVolumeStepVolume = X_MIN_VOLUME; // Step of Volume Increasing
|
||||
// input double eaConstantRiskBalance = 0.0; // Constant Risk Balance per Trade
|
||||
// input double eaConstantPercent = 0.0; // Constant Percent of Balance Per Trade
|
||||
// input double eaConstantBalance = 0.0; // Constant Balance for Calculations
|
||||
// XCVolume *eaVolume;
|
||||
// eaVolume = new XCVolume();
|
||||
// bool result = eaVolume.Init(
|
||||
// eaVolumeSelect,
|
||||
// eaStaticVoluem,
|
||||
// eaDynamicVolumeStepBalance,
|
||||
// eaDynamicVolumeStepVolume,
|
||||
// eaConstantRiskBalance,
|
||||
// eaConstantPercent,
|
||||
// eaConstantBalance //
|
||||
// );
|
||||
// if (!result) {
|
||||
// return INIT_FAILED;
|
||||
// }
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.x-account.class.mq5"
|
||||
#include "../Libraries/x-saherelm.x-trade.lib.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
#define X_MIN_VOLUME 0.01
|
||||
|
||||
//
|
||||
enum ENUM_X_VOLUME_SELECT_TYPE
|
||||
{
|
||||
X_VOLUME_NONE, // None
|
||||
X_VOLUME_STATIC, // Static Volume
|
||||
X_VOLUME_CURRENT, // Current Balance
|
||||
X_VOLUME_EQUITY, // Current Equity
|
||||
X_VOLUME_CONSTANT // Constant Value
|
||||
};
|
||||
|
||||
//
|
||||
bool IsValid(ENUM_X_VOLUME_SELECT_TYPE value)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = value != X_VOLUME_NONE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string ToString(ENUM_X_VOLUME_SELECT_TYPE value)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
result = EnumToString(value);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Implementation ...
|
||||
class XCVolume : public XCBase
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
XCAccount *account;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XCVolume()
|
||||
{
|
||||
//
|
||||
account = new XCAccount();
|
||||
|
||||
//
|
||||
Default();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCVolume()
|
||||
{
|
||||
//
|
||||
ZeroMemory(account);
|
||||
}
|
||||
|
||||
//
|
||||
bool Init(
|
||||
ENUM_X_VOLUME_SELECT_TYPE _SelectType,
|
||||
double _StaticVolume,
|
||||
double _DynamicVolumeStepBalance,
|
||||
double _DynamicVolumeStepVolume,
|
||||
double _ConstantRiskBalance,
|
||||
double _ConstantPercent,
|
||||
double _ConstantBalance //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mVolumeType = _SelectType;
|
||||
mStaticVolume = _StaticVolume;
|
||||
mConstantPercent = _ConstantPercent;
|
||||
mConstantBalance = _ConstantBalance;
|
||||
mConstantRiskBalance = _ConstantRiskBalance;
|
||||
mDynamicVolumeStepVolume = _DynamicVolumeStepVolume;
|
||||
mDynamicVolumeStepBalance = _DynamicVolumeStepBalance;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
CanUseStaticVolume() ||
|
||||
CanUseDynamicVolume() ||
|
||||
CanUseConstantRiskBalance() ||
|
||||
CanUseConstantBalancePercent()
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Prperties ...
|
||||
|
||||
/**
|
||||
* Get Volume Calculating Method ...
|
||||
*
|
||||
* @return (ENUM_X_VOLUME_SELECT_TYPE)
|
||||
*/
|
||||
ENUM_X_VOLUME_SELECT_TYPE VolumeType()
|
||||
{
|
||||
return mVolumeType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Volume Calculating Method ...
|
||||
*
|
||||
* @param value: ENUM_X_VOLUME_SELECT_TYPE member ...
|
||||
*/
|
||||
void VolumeType(ENUM_X_VOLUME_SELECT_TYPE value)
|
||||
{
|
||||
mVolumeType = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Static Volume ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double StaticVolume()
|
||||
{
|
||||
return mStaticVolume;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Static Volume ...
|
||||
*
|
||||
* @param value: double
|
||||
*/
|
||||
void StaticVolume(double value)
|
||||
{
|
||||
//
|
||||
value = NormalizeDouble(value, 0.01, 1);
|
||||
|
||||
//
|
||||
mStaticVolume = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Dynamic Volume Step Balance ...
|
||||
* used to Calculate Final Lottage ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double DynamicVolumeStepBalance()
|
||||
{
|
||||
return mDynamicVolumeStepBalance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Dynamic Volume Step Balance ...
|
||||
* used to Calculate Final Lottage ...
|
||||
*
|
||||
* @param value: Argument 1
|
||||
*/
|
||||
void DynamicVolumeStepBalance(double value)
|
||||
{
|
||||
//
|
||||
value = NormalizeDouble(value, 0);
|
||||
|
||||
//
|
||||
mDynamicVolumeStepBalance = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Dynamic Volume Step Volume ...
|
||||
* used to Calculate Final Lottage ...
|
||||
* how much increase Final Volume based oBalance Step ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double DynamicVolumeStepVolume()
|
||||
{
|
||||
return mDynamicVolumeStepVolume;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Dynamic Volume Step Volume ...
|
||||
* used to Calculate Final Lottage ...
|
||||
* how much increase Final Volume based oBalance Step ...
|
||||
*
|
||||
* @param value: double
|
||||
*/
|
||||
void DynamicVolumeStepVolume(double value)
|
||||
{
|
||||
//
|
||||
value = NormalizeDouble(value, 0.01, 0.1);
|
||||
|
||||
//
|
||||
mDynamicVolumeStepVolume = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Constant Balance Use for Dyamic Volume Calculation ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double ConstantBalance()
|
||||
{
|
||||
return mConstantBalance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Constant Balance Use for Dyamic Volume Calculation ...
|
||||
*
|
||||
* @param value: Argument 1
|
||||
*/
|
||||
void ConstantBalance(double value)
|
||||
{
|
||||
//
|
||||
value = NormalizeDouble(value, 0);
|
||||
|
||||
//
|
||||
mConstantBalance = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Constant Risk Value Based on Account Currency ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double ConstantRiskBalance()
|
||||
{
|
||||
return mConstantRiskBalance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Constant Risk Value Based on Account Currency ...
|
||||
*
|
||||
* @param value: double
|
||||
*/
|
||||
void ConstantRiskBalance(double value)
|
||||
{
|
||||
//
|
||||
value = NormalizeDouble(value, 0);
|
||||
|
||||
//
|
||||
mConstantRiskBalance = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Constant Percent Based On Selected Balance ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double ConstantPercent()
|
||||
{
|
||||
return mConstantPercent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Constant Percent Based On Selected Balance ...
|
||||
*
|
||||
* @param value: double ...
|
||||
*/
|
||||
void ConstantPercent(double value)
|
||||
{
|
||||
//
|
||||
value = NormalizeDouble(value, 0, 100);
|
||||
|
||||
//
|
||||
mConstantPercent = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Retrieve Balance based on Provided Volume Type ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double GetBalance()
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
if (!IsValid(mVolumeType))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (mConstantBalance > 0 &&
|
||||
mVolumeType == X_VOLUME_CONSTANT)
|
||||
{
|
||||
result = mConstantBalance;
|
||||
}
|
||||
else if (mVolumeType == X_VOLUME_CURRENT)
|
||||
{
|
||||
result = account.GetBalance();
|
||||
}
|
||||
else if (mVolumeType == X_VOLUME_EQUITY)
|
||||
{
|
||||
result = account.GetEquity();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Balance based on Provided Volume Type ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double GetBalance(ENUM_X_VOLUME_SELECT_TYPE type)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
if (!IsValid(type))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (mConstantBalance > 0 &&
|
||||
type == X_VOLUME_CONSTANT)
|
||||
{
|
||||
result = mConstantBalance;
|
||||
}
|
||||
else if (type == X_VOLUME_CURRENT)
|
||||
{
|
||||
result = account.GetBalance();
|
||||
}
|
||||
else if (type == X_VOLUME_EQUITY)
|
||||
{
|
||||
result = account.GetEquity();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Volume Based On Given Configuration ...
|
||||
*
|
||||
* @param symbol: string, Trading Symbol ...
|
||||
* @param entry: double, Entry Price ...
|
||||
* @param sl: double, Stop Loss Price ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double CalculateVolume(
|
||||
string symbol,
|
||||
double entry,
|
||||
double sl //
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = X_MIN_VOLUME;
|
||||
|
||||
//
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
has =
|
||||
sl > 0 &&
|
||||
entry > 0 &&
|
||||
IsValid(symbol);
|
||||
if (!has)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Balance Type ...
|
||||
double balance = GetBalance();
|
||||
double points = GetPoints(symbol);
|
||||
double riskPrice = MathAbs(entry - sl);
|
||||
double riskInPoints = riskPrice / points;
|
||||
|
||||
//
|
||||
has = CanUseStaticVolume();
|
||||
if (has)
|
||||
{
|
||||
result = mStaticVolume;
|
||||
}
|
||||
|
||||
//
|
||||
has = CanUseDynamicVolume();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
double multiplier = balance / mDynamicVolumeStepBalance;
|
||||
if (multiplier < 0)
|
||||
{
|
||||
multiplier = 1;
|
||||
}
|
||||
|
||||
//
|
||||
result = multiplier * mDynamicVolumeStepVolume;
|
||||
}
|
||||
|
||||
//
|
||||
has = CanUseConstantRiskBalance();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
result = account.CalculateVolume(
|
||||
symbol,
|
||||
mConstantRiskBalance,
|
||||
riskInPoints //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
has = CanUseConstantBalancePercent();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
double riskAmountPerBalance = (mConstantPercent * balance) / 100;
|
||||
|
||||
//
|
||||
result = account.CalculateVolume(
|
||||
symbol,
|
||||
riskAmountPerBalance,
|
||||
riskInPoints //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
if (result < X_MIN_VOLUME)
|
||||
{
|
||||
result = X_MIN_VOLUME;
|
||||
}
|
||||
|
||||
//
|
||||
// Normalize Volume ...
|
||||
result = NormalizeVolume(result, symbol);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Volume Based On Given Configuration ...
|
||||
*
|
||||
* @param signal: XSignal instance reference, provided required Data ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double CalculateVolume(XSignal &signal)
|
||||
{
|
||||
//
|
||||
double result = X_MIN_VOLUME;
|
||||
|
||||
//
|
||||
if (!signal.IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = CalculateVolume(
|
||||
signal.symbol,
|
||||
signal.entry,
|
||||
signal.sl //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Specified Percent of Selected Balance for Volume ...
|
||||
*
|
||||
* @param percent: double, percent of Balance Risking ...
|
||||
* @param symbol: string, Trading Symbol ...
|
||||
* @param entry: double, Entry Price ...
|
||||
* @param sl: double Stop Loss Price ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double CalculateVolume(
|
||||
ENUM_X_VOLUME_SELECT_TYPE selectType,
|
||||
double percent,
|
||||
string symbol,
|
||||
double entry,
|
||||
double sl //
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = X_MIN_VOLUME;
|
||||
|
||||
//
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
has =
|
||||
sl > 0 &&
|
||||
entry > 0 &&
|
||||
percent > 0 &&
|
||||
IsValid(symbol) &&
|
||||
IsValid(selectType) &&
|
||||
(selectType == X_VOLUME_EQUITY ||
|
||||
selectType == X_VOLUME_CURRENT);
|
||||
if (!has)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Balance Type ...
|
||||
double points = GetPoints(symbol);
|
||||
double riskPrice = MathAbs(entry - sl);
|
||||
double balance = GetBalance(selectType);
|
||||
double riskInPoints = riskPrice / points;
|
||||
|
||||
//
|
||||
double riskAmountPerBalance = (percent * balance) / 100;
|
||||
|
||||
//
|
||||
result = account.CalculateVolume(
|
||||
symbol,
|
||||
riskAmountPerBalance,
|
||||
riskInPoints //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Set Default Props ...
|
||||
*/
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
VolumeType(X_VOLUME_STATIC);
|
||||
StaticVolume(0.01);
|
||||
|
||||
//
|
||||
ConstantBalance(0);
|
||||
ConstantPercent(0);
|
||||
ConstantRiskBalance(0);
|
||||
|
||||
//
|
||||
DynamicVolumeStepBalance(0);
|
||||
DynamicVolumeStepVolume(0.01);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Configuration is Valid For Static Volume ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool CanUseStaticVolume()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid(mVolumeType);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Static Volume ...
|
||||
result =
|
||||
//
|
||||
mVolumeType == X_VOLUME_STATIC &&
|
||||
mStaticVolume > 0 &&
|
||||
//
|
||||
mDynamicVolumeStepBalance == 0 &&
|
||||
//
|
||||
mConstantBalance == 0 &&
|
||||
mConstantPercent == 0 &&
|
||||
mConstantRiskBalance == 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Configuration is Valid For Dynamic Volume ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool CanUseDynamicVolume()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid(mVolumeType);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
(mVolumeType == X_VOLUME_CURRENT ||
|
||||
mVolumeType == X_VOLUME_EQUITY ||
|
||||
(mVolumeType == X_VOLUME_CONSTANT &&
|
||||
mConstantBalance > 0)) &&
|
||||
//
|
||||
mDynamicVolumeStepBalance > 0 &&
|
||||
mDynamicVolumeStepVolume > 0 &&
|
||||
//
|
||||
mStaticVolume == 0 &&
|
||||
mConstantPercent == 0 &&
|
||||
mConstantRiskBalance == 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Configuration is Valid For Constant Risk Balance ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool CanUseConstantRiskBalance()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid(mVolumeType);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
(mVolumeType == X_VOLUME_CURRENT ||
|
||||
mVolumeType == X_VOLUME_EQUITY ||
|
||||
(mVolumeType == X_VOLUME_CONSTANT &&
|
||||
mConstantBalance > 0)) &&
|
||||
//
|
||||
mConstantRiskBalance > 0 &&
|
||||
//
|
||||
mStaticVolume == 0 &&
|
||||
mConstantPercent == 0 &&
|
||||
mDynamicVolumeStepBalance == 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Configuration is Valid For Constant Risk Percent ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool CanUseConstantBalancePercent()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid(mVolumeType);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
(mVolumeType == X_VOLUME_CURRENT ||
|
||||
mVolumeType == X_VOLUME_EQUITY ||
|
||||
(mVolumeType == X_VOLUME_CONSTANT &&
|
||||
mConstantBalance > 0)) &&
|
||||
//
|
||||
mConstantPercent > 0 &&
|
||||
//
|
||||
mStaticVolume == 0 &&
|
||||
mConstantRiskBalance == 0 &&
|
||||
mDynamicVolumeStepBalance == 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
ENUM_X_VOLUME_SELECT_TYPE mVolumeType; // Balance Type ...
|
||||
|
||||
//
|
||||
// Static Volume ...
|
||||
double mStaticVolume; // Static Volume ...
|
||||
|
||||
//
|
||||
double mDynamicVolumeStepBalance; // Step of Balance ...
|
||||
double mDynamicVolumeStepVolume; // Step of Volume ...
|
||||
|
||||
//
|
||||
double mConstantBalance; // Constant Balance ....
|
||||
double mConstantRiskBalance; // Constant Risk Balance ...
|
||||
double mConstantPercent; // Constant Percent of Balance ...
|
||||
};
|
||||
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,243 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| SpikeDetectorEA.mq5 |
|
||||
//| Copyright 2025, Your Name/Company |
|
||||
//| https://www.example.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2025, Your Name/Company"
|
||||
#property link "https://www.example.com"
|
||||
#property version "1.01" // Incremented version
|
||||
#property description "Expert Advisor to detect and draw price spikes (pin bars)."
|
||||
|
||||
//--- Input Parameters
|
||||
input group "Spike Definition" input double InpMinWickToBodyRatio = 2.0; // Minimum ratio of the main wick to the body (e.g., 2.0 means wick is 2x body)
|
||||
input double InpMaxOppositeWickToBodyRatio = 1.0; // Maximum ratio of the opposite wick to the body (e.g., 1.0 means opposite wick <= body)
|
||||
input double InpMaxBodyToTotalRangeRatio = 0.33; // Maximum ratio of body to total candle range (H-L) (e.g., 0.33 means body is < 1/3 of range)
|
||||
|
||||
input group "Drawing Settings" input int InpArrowOffsetPoints = 10; // Arrow offset from High/Low in points
|
||||
input color InpBullishSpikeColor = clrLimeGreen; // Color for bullish spike arrows
|
||||
input color InpBearishSpikeColor = clrRed; // Color for bearish spike arrows
|
||||
input int InpLookbackForDrawing = 200; // How many past bars to check on EA load/recompile
|
||||
|
||||
// Wingdings Arrow Codes (commonly used for OBJ_ARROW)
|
||||
#define WINGDINGS_ARROW_UP 241
|
||||
#define WINGDINGS_ARROW_DOWN 242
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//---
|
||||
// You can add any one-time initialization logic here if needed
|
||||
Print("SpikeDetectorEA initialized. Symbol: ", _Symbol, ", Timeframe: ", EnumToString((ENUM_TIMEFRAMES)Period()));
|
||||
//---
|
||||
return (INIT_SUCCEEDED);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert deinitialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//---
|
||||
// Optional: Clean up objects when EA is removed or chart is closed
|
||||
// For more targeted deletion, you might loop through objects and check names
|
||||
// ObjectsDeleteAll(0, "SpikeArrow_Bearish_" + _Symbol);
|
||||
// ObjectsDeleteAll(0, "SpikeArrow_Bullish_" + _Symbol);
|
||||
// A more robust way if you have many EAs or indicators:
|
||||
long chart_id = ChartID();
|
||||
for (int i = ObjectsTotal(chart_id, -1, OBJ_ARROW) - 1; i >= 0; i--)
|
||||
{
|
||||
string obj_name = ObjectName(chart_id, i, -1, OBJ_ARROW);
|
||||
if (StringFind(obj_name, "SpikeArrow_Bearish_" + _Symbol + "_" + EnumToString((ENUM_TIMEFRAMES)Period())) == 0 ||
|
||||
StringFind(obj_name, "SpikeArrow_Bullish_" + _Symbol + "_" + EnumToString((ENUM_TIMEFRAMES)Period())) == 0)
|
||||
{
|
||||
ObjectDelete(chart_id, obj_name);
|
||||
}
|
||||
}
|
||||
Print("SpikeDetectorEA deinitialized. Reason: ", reason);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert tick function (not used for bar analysis in this EA) |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnTick()
|
||||
{
|
||||
//---
|
||||
// We will use OnCalculate for bar-based analysis
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Chart event function (not strictly needed for this EA) |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnChartEvent(const int id,
|
||||
const long &lparam,
|
||||
const double &dparam,
|
||||
const string &sparam)
|
||||
{
|
||||
//---
|
||||
// Can be used to handle chart events if necessary
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert new bar function / Indicator calculation event |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total, // Size of the price[] arrays
|
||||
const int prev_calculated, // Bars calculated at the previous call
|
||||
const datetime &time[], // Time array
|
||||
const double &open[], // Open price array
|
||||
const double &high[], // High price array
|
||||
const double &low[], // Low price array
|
||||
const double &close[], // Close price array
|
||||
const long &tick_volume[], // Tick Volume array
|
||||
const long &volume[], // Real Volume array
|
||||
const int &spread[]) // Spread array
|
||||
{
|
||||
//--- Check for minimal rates_total
|
||||
if (rates_total < 2) // Need at least one closed bar to compare
|
||||
return (0);
|
||||
|
||||
//--- Determine how many bars to calculate
|
||||
int first_bar_to_calculate;
|
||||
// On the very first call of OnCalculate (prev_calculated == 0) or if history was changed drastically
|
||||
if (prev_calculated == 0 || prev_calculated > rates_total || rates_total - prev_calculated > InpLookbackForDrawing + 10) // Added a buffer for safety
|
||||
{
|
||||
first_bar_to_calculate = MathMax(0, rates_total - InpLookbackForDrawing);
|
||||
Print("SpikeDetectorEA: First run or history refresh. Processing up to ", InpLookbackForDrawing, " bars from bar index ", first_bar_to_calculate);
|
||||
// Clean up old arrows if doing a full refresh to avoid orphaned objects if bar times change
|
||||
long chart_id = ChartID();
|
||||
for (int k = ObjectsTotal(chart_id, -1, OBJ_ARROW) - 1; k >= 0; k--)
|
||||
{
|
||||
string obj_name_check = ObjectName(chart_id, k, -1, OBJ_ARROW);
|
||||
if (StringFind(obj_name_check, "SpikeArrow_Bearish_" + _Symbol + "_" + EnumToString((ENUM_TIMEFRAMES)Period())) == 0 ||
|
||||
StringFind(obj_name_check, "SpikeArrow_Bullish_" + _Symbol + "_" + EnumToString((ENUM_TIMEFRAMES)Period())) == 0)
|
||||
{
|
||||
ObjectDelete(chart_id, obj_name_check);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// prev_calculated is the number of bars calculated by the previous call.
|
||||
// We want to start from one bar before the last one calculated by the previous call,
|
||||
// to catch updates to the forming bar that has now closed, plus any new bars.
|
||||
// rates_total - prev_calculated gives the number of new bars.
|
||||
// We process (rates_total - prev_calculated) + 1 bars (the forming bar that closed + new bars)
|
||||
// So, start from rates_total - (rates_total - prev_calculated + 1) = prev_calculated - 1
|
||||
first_bar_to_calculate = prev_calculated - 1;
|
||||
}
|
||||
// Ensure we don't go out of bounds (e.g. if prev_calculated was 0 due to error or very few bars)
|
||||
first_bar_to_calculate = MathMax(0, first_bar_to_calculate);
|
||||
// We don't want to process the current, still-forming bar (index rates_total - 1 usually)
|
||||
// So loop up to rates_total - 1 (or < rates_total)
|
||||
// If we are processing historical bars, i can go up to rates_total - 1
|
||||
// If we are processing only new bars, the last bar is rates_total - 1.
|
||||
|
||||
//--- Main loop for processing bars
|
||||
// We iterate up to rates_total-1 because the last bar (rates_total-1) is the current forming bar
|
||||
// We are interested in closed bars. So, the last closed bar is at index rates_total-2 if rates_total > 1.
|
||||
// However, if we start from prev_calculated-1, this logic handles it correctly.
|
||||
// The loop should go up to `rates_total - 1` to process all available historical bars.
|
||||
// The current bar (index rates_total - 1) will be processed on the next tick once it closes and a new bar forms.
|
||||
for (int i = first_bar_to_calculate; i < rates_total; i++)
|
||||
{
|
||||
// Skip the current forming bar (bar 0 in terminal, index rates_total-1 in array if processing live)
|
||||
// This logic is implicitly handled by how OnCalculate is typically called.
|
||||
// The loop goes from an older bar up to the most recent *available* bar data.
|
||||
// The last bar in the `time`, `open`, etc. arrays is `rates_total - 1`.
|
||||
// If `i == rates_total - 1`, it's the current, potentially unclosed bar.
|
||||
// We generally want to analyze closed bars. Let's adjust the loop to `i < rates_total -1` if we only want confirmed closed bars.
|
||||
// However, for drawing on historical data, `i < rates_total` is fine.
|
||||
// The key is that `prev_calculated` helps us only recalculate what's necessary.
|
||||
// Let's assume we process up to the last available bar, and if it's the current forming bar,
|
||||
// its spike status might change. The object deletion logic handles this.
|
||||
|
||||
// If it's the very first bar available (index 0) and it has no history to form wicks properly, skip.
|
||||
// This check might be too simplistic, but helps avoid issues with incomplete data at the start of history.
|
||||
// if (i == 0 && rates_total < 3) continue; // This might be too restrictive.
|
||||
|
||||
// Define object names for this bar to manage them
|
||||
// Using time ensures uniqueness per bar. Adding symbol and timeframe for robustness.
|
||||
string obj_time_str = TimeToString(time[i], TIME_DATE | TIME_MINUTES | TIME_SECONDS); // Added seconds for more uniqueness
|
||||
string bearish_obj_name = StringFormat("SpikeArrow_Bearish_%s_%s_%s", _Symbol, EnumToString((ENUM_TIMEFRAMES)Period()), obj_time_str);
|
||||
string bullish_obj_name = StringFormat("SpikeArrow_Bullish_%s_%s_%s", _Symbol, EnumToString((ENUM_TIMEFRAMES)Period()), obj_time_str);
|
||||
|
||||
// Delete existing arrows for this bar before re-evaluating
|
||||
// This allows settings changes to reflect immediately and removes arrows if a spike no longer qualifies
|
||||
ObjectDelete(0, bearish_obj_name);
|
||||
ObjectDelete(0, bullish_obj_name);
|
||||
|
||||
// Get OHLC for the current bar i
|
||||
double O = open[i];
|
||||
double H = high[i];
|
||||
double L = low[i];
|
||||
double C = close[i];
|
||||
|
||||
// Calculate candle components
|
||||
double body_size = MathAbs(O - C);
|
||||
double total_range = H - L;
|
||||
double upper_wick = H - MathMax(O, C);
|
||||
double lower_wick = MathMin(O, C) - L;
|
||||
|
||||
// Avoid division by zero or issues with flat candles (doji, etc.)
|
||||
if (total_range < _Point * 0.1) // If candle range is very small, skip (e.g. less than 0.1 points)
|
||||
continue;
|
||||
|
||||
bool is_bearish_spike = false;
|
||||
bool is_bullish_spike = false;
|
||||
double body_plus_epsilon = body_size + (_Point * 0.01); // Add a very small value related to point size
|
||||
|
||||
// --- Bearish Spike Detection (Spike High) ---
|
||||
// 1. Body is a small part of the total range
|
||||
// 2. Upper wick is significantly larger than the body
|
||||
// 3. Lower wick is small compared to the body (or upper wick)
|
||||
if (body_size / total_range <= InpMaxBodyToTotalRangeRatio &&
|
||||
upper_wick / body_plus_epsilon >= InpMinWickToBodyRatio &&
|
||||
lower_wick / body_plus_epsilon <= InpMaxOppositeWickToBodyRatio &&
|
||||
upper_wick > lower_wick) // Ensure upper wick is dominant
|
||||
{
|
||||
is_bearish_spike = true;
|
||||
}
|
||||
|
||||
// --- Bullish Spike Detection (Spike Low) ---
|
||||
// 1. Body is a small part of the total range
|
||||
// 2. Lower wick is significantly larger than the body
|
||||
// 3. Upper wick is small compared to the body (or lower wick)
|
||||
if (body_size / total_range <= InpMaxBodyToTotalRangeRatio &&
|
||||
lower_wick / body_plus_epsilon >= InpMinWickToBodyRatio &&
|
||||
upper_wick / body_plus_epsilon <= InpMaxOppositeWickToBodyRatio &&
|
||||
lower_wick > upper_wick) // Ensure lower wick is dominant
|
||||
{
|
||||
is_bullish_spike = true;
|
||||
}
|
||||
|
||||
// --- Drawing ---
|
||||
double arrow_offset_actual = InpArrowOffsetPoints * _Point;
|
||||
|
||||
if (is_bearish_spike)
|
||||
{
|
||||
if (ObjectCreate(0, bearish_obj_name, OBJ_ARROW, 0, time[i], H + arrow_offset_actual))
|
||||
{
|
||||
ObjectSetInteger(0, bearish_obj_name, OBJPROP_ARROWCODE, WINGDINGS_ARROW_DOWN); // Corrected
|
||||
ObjectSetInteger(0, bearish_obj_name, OBJPROP_COLOR, InpBearishSpikeColor);
|
||||
ObjectSetInteger(0, bearish_obj_name, OBJPROP_WIDTH, 1);
|
||||
ObjectSetInteger(0, bearish_obj_name, OBJPROP_STYLE, STYLE_SOLID);
|
||||
ObjectSetString(0, bearish_obj_name, OBJPROP_TOOLTIP, "Bearish Spike");
|
||||
}
|
||||
// else { PrintFormat("Failed to create bearish spike arrow for bar at %s. Error: %d", TimeToString(time[i]), GetLastError()); }
|
||||
}
|
||||
|
||||
if (is_bullish_spike)
|
||||
{
|
||||
if (ObjectCreate(0, bullish_obj_name, OBJ_ARROW, 0, time[i], L - arrow_offset_actual))
|
||||
{
|
||||
ObjectSetInteger(0, bullish_obj_name, OBJPROP_ARROWCODE, WINGDINGS_ARROW_UP); // Corrected
|
||||
ObjectSetInteger(0, bullish_obj_name, OBJPROP_COLOR, InpBullishSpikeColor);
|
||||
ObjectSetInteger(0, bullish_obj_name, OBJPROP_WIDTH, 1);
|
||||
ObjectSetInteger(0, bullish_obj_name, OBJPROP_STYLE, STYLE_SOLID);
|
||||
ObjectSetString(0, bullish_obj_name, OBJPROP_TOOLTIP, "Bullish Spike");
|
||||
}
|
||||
// else { PrintFormat("Failed to create bullish spike arrow for bar at %s. Error: %d", TimeToString(time[i]), GetLastError()); }
|
||||
}
|
||||
}
|
||||
//--- Return value of prev_calculated for next call
|
||||
return (rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,233 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Consolidation Detector EA |
|
||||
//| Detects consolidations using multiple methods |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Your Name"
|
||||
#property link "https://www.example.com"
|
||||
#property version "1.01"
|
||||
|
||||
// Input Parameters
|
||||
input group "Consolidation Detection Settings"
|
||||
input bool UsePriceRange = true; // Enable Price Range Analysis
|
||||
input int PriceRangeBars = 20; // Bars for Price Range
|
||||
input double PriceRangeThreshold = 0.5; // Price Range Threshold (% of ATR)
|
||||
|
||||
input bool UseBollingerSqueeze = true; // Enable Bollinger Bands Squeeze
|
||||
input int BollingerPeriod = 20; // Bollinger Bands Period
|
||||
input double BollingerThreshold = 0.02; // Bollinger Bandwidth Threshold
|
||||
|
||||
input bool UseATRCrossover = true; // Enable ATR Crossover
|
||||
input int FastATRPeriod = 5; // Fast ATR Period
|
||||
input int SlowATRPeriod = 20; // Slow ATR Period
|
||||
|
||||
input bool UseVolumeAnalysis = true; // Enable Volume Analysis
|
||||
input int VolumeBars = 20; // Bars for Volume Analysis
|
||||
input double VolumeThreshold = 0.7; // Volume Threshold (% of Avg Volume)
|
||||
|
||||
input group "Visualization and Alerts"
|
||||
input bool DrawZones = true; // Draw Consolidation Zones
|
||||
input bool EnableAlerts = true; // Enable Alerts for Consolidation
|
||||
input color ZoneColor = clrPurple; // Color for Consolidation Zones
|
||||
|
||||
// Global Variables
|
||||
datetime lastBarTime; // Track last processed bar time
|
||||
int bollingerHandle; // Handle for Bollinger Bands
|
||||
int fastATRHandle; // Handle for Fast ATR
|
||||
int slowATRHandle; // Handle for Slow ATR
|
||||
int priceATRHandle; // Handle for Price Range ATR
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
// Initialize Bollinger Bands handle
|
||||
bollingerHandle = iBands(_Symbol, PERIOD_CURRENT, BollingerPeriod, 0, 2.0, PRICE_CLOSE);
|
||||
if (bollingerHandle == INVALID_HANDLE)
|
||||
{
|
||||
Print("Failed to initialize Bollinger Bands");
|
||||
return(INIT_FAILED);
|
||||
}
|
||||
|
||||
// Initialize ATR handles
|
||||
priceATRHandle = iATR(_Symbol, PERIOD_CURRENT, PriceRangeBars);
|
||||
fastATRHandle = iATR(_Symbol, PERIOD_CURRENT, FastATRPeriod);
|
||||
slowATRHandle = iATR(_Symbol, PERIOD_CURRENT, SlowATRPeriod);
|
||||
|
||||
if (priceATRHandle == INVALID_HANDLE || fastATRHandle == INVALID_HANDLE || slowATRHandle == INVALID_HANDLE)
|
||||
{
|
||||
Print("Failed to initialize ATR indicators");
|
||||
return(INIT_FAILED);
|
||||
}
|
||||
|
||||
// Set last bar time to avoid processing same bar multiple times
|
||||
lastBarTime = TimeCurrent();
|
||||
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert deinitialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
// Release indicator handles
|
||||
IndicatorRelease(bollingerHandle);
|
||||
IndicatorRelease(priceATRHandle);
|
||||
IndicatorRelease(fastATRHandle);
|
||||
IndicatorRelease(slowATRHandle);
|
||||
|
||||
// Clean up chart objects
|
||||
ObjectsDeleteAll(0, "Consolidation_");
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert tick function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnTick()
|
||||
{
|
||||
// Process only on new bar
|
||||
datetime currentBarTime = iTime(_Symbol, PERIOD_CURRENT, 0);
|
||||
if (currentBarTime == lastBarTime)
|
||||
return;
|
||||
lastBarTime = currentBarTime;
|
||||
|
||||
bool isConsolidation = false;
|
||||
string consolidationMethods = "";
|
||||
|
||||
// Get high and low for visualization
|
||||
double high = iHigh(_Symbol, PERIOD_CURRENT, 1);
|
||||
double low = iLow(_Symbol, PERIOD_CURRENT, 1);
|
||||
datetime startTime = iTime(_Symbol, PERIOD_CURRENT, PriceRangeBars);
|
||||
datetime endTime = currentBarTime;
|
||||
|
||||
// Check Price Range Consolidation
|
||||
// if (UsePriceRange && IsPriceRangeConsolidation(PriceRangeBars, PriceRangeThreshold))
|
||||
// {
|
||||
// isConsolidation = true;
|
||||
// consolidationMethods += "Price Range, ";
|
||||
// }
|
||||
|
||||
// // Check Bollinger Bands Squeeze
|
||||
// if (UseBollingerSqueeze && IsBollingerSqueeze(BollingerPeriod, BollingerThreshold))
|
||||
// {
|
||||
// isConsolidation = true;
|
||||
// consolidationMethods += "Bollinger Squeeze, ";
|
||||
// }
|
||||
|
||||
// // Check ATR Crossover
|
||||
// if (UseATRCrossover && IsATRConsolidation(FastATRPeriod, SlowATRPeriod))
|
||||
// {
|
||||
// isConsolidation = true;
|
||||
// consolidationMethods += "ATR Crossover, ";
|
||||
// }
|
||||
|
||||
// // Check Volume Analysis
|
||||
// if (UseVolumeAnalysis && IsVolumeConsolidation(VolumeBars, VolumeThreshold))
|
||||
// {
|
||||
// isConsolidation = true;
|
||||
// consolidationMethods += "Volume Analysis, ";
|
||||
// }
|
||||
|
||||
// Output and Visualization
|
||||
if (isConsolidation)
|
||||
{
|
||||
string message = "Consolidation detected by: " + consolidationMethods;
|
||||
Print(message);
|
||||
if (EnableAlerts)
|
||||
Alert(message);
|
||||
if (DrawZones)
|
||||
DrawConsolidationZone(high, low, startTime, endTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
Print("No consolidation detected");
|
||||
}
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Price Range Consolidation Detection |
|
||||
//+------------------------------------------------------------------+
|
||||
bool IsPriceRangeConsolidation(int bars, double threshold)
|
||||
{
|
||||
double rangeSum = 0.0;
|
||||
double high[], low[], atr[];
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(atr, true);
|
||||
|
||||
CopyHigh(_Symbol, PERIOD_CURRENT, 1, bars, high);
|
||||
CopyLow(_Symbol, PERIOD_CURRENT, 1, bars, low);
|
||||
CopyBuffer(priceATRHandle, 0, 1, 1, atr); // Get ATR for shift 1
|
||||
|
||||
for (int i = 0; i < bars; i++)
|
||||
rangeSum += high[i] - low[i];
|
||||
|
||||
double avgRange = rangeSum / bars;
|
||||
|
||||
return (avgRange < threshold * atr[0]);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Bollinger Bands Squeeze Detection |
|
||||
//+------------------------------------------------------------------+
|
||||
bool IsBollingerSqueeze(int period, double threshold)
|
||||
{
|
||||
double upper[], lower[], middle[];
|
||||
ArraySetAsSeries(upper, true);
|
||||
ArraySetAsSeries(lower, true);
|
||||
ArraySetAsSeries(middle, true);
|
||||
|
||||
CopyBuffer(bollingerHandle, 0, 0, 3, middle); // Middle band
|
||||
CopyBuffer(bollingerHandle, 1, 0, 3, upper); // Upper band
|
||||
CopyBuffer(bollingerHandle, 2, 0, 3, lower); // Lower band
|
||||
|
||||
double bandwidth = (upper[1] - lower[1]) / middle[1];
|
||||
return (bandwidth < threshold);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| ATR Crossover Consolidation Detection |
|
||||
//+------------------------------------------------------------------+
|
||||
bool IsATRConsolidation(int fastPeriod, int slowPeriod)
|
||||
{
|
||||
double fastATR[], slowATR[];
|
||||
ArraySetAsSeries(fastATR, true);
|
||||
ArraySetAsSeries(slowATR, true);
|
||||
|
||||
CopyBuffer(fastATRHandle, 0, 1, 1, fastATR); // Fast ATR for shift 1
|
||||
CopyBuffer(slowATRHandle, 0, 1, 1, slowATR); // Slow ATR for shift 1
|
||||
|
||||
return (fastATR[0] < slowATR[0]);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Volume Analysis Consolidation Detection |
|
||||
//+------------------------------------------------------------------+
|
||||
bool IsVolumeConsolidation(int bars, double threshold)
|
||||
{
|
||||
double volume[];
|
||||
ArraySetAsSeries(volume, true);
|
||||
CopyBuffer(iVolume(_Symbol, PERIOD_CURRENT, 0), 0, 0, bars, volume);
|
||||
|
||||
double avgVolume = 0.0;
|
||||
for (int i = 0; i < bars; i++)
|
||||
avgVolume += volume[i];
|
||||
avgVolume /= bars;
|
||||
|
||||
double currentVolume = volume[1];
|
||||
return (currentVolume < threshold * avgVolume);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Draw Consolidation Zone on Chart |
|
||||
//+------------------------------------------------------------------+
|
||||
void DrawConsolidationZone(double high, double low, datetime start, datetime end)
|
||||
{
|
||||
string objName = "Consolidation_" + TimeToString(start);
|
||||
ObjectCreate(0, objName, OBJ_RECTANGLE, 0, start, high, end, low);
|
||||
ObjectSetInteger(0, objName, OBJPROP_COLOR, ZoneColor);
|
||||
ObjectSetInteger(0, objName, OBJPROP_STYLE, STYLE_SOLID);
|
||||
ObjectSetInteger(0, objName, OBJPROP_FILL, true);
|
||||
ObjectSetInteger(0, objName, OBJPROP_BACK, true);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,647 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XCond2 MQL5 Script
|
||||
// -------------------------------------------------
|
||||
// Name: XCAEA
|
||||
// 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 XCAEA Cond2 Script"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
|
||||
//
|
||||
// Classes ...
|
||||
#include "../../Classes/x-saherelm.x-poi.class.mq5"
|
||||
|
||||
//
|
||||
// Libraries ...
|
||||
#include "../../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../../Libraries/x-saherelm.x-poi.lib.mq5"
|
||||
|
||||
//
|
||||
// Helpers ...
|
||||
#include "../Helpers/xcaea.helper.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Holds Drawn Objects ...
|
||||
CArrayObj mObjects;
|
||||
|
||||
//
|
||||
// Required Objects ...
|
||||
int mLoopback = 10;
|
||||
XCAEAInputs mInputs;
|
||||
XBarTracker mBarTracker;
|
||||
XCAEAConditions mConditions;
|
||||
XCXCAEAHelper *helper = NULL;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Script ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Initialize Helper ...
|
||||
bool isInited = InitHelper();
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Script ...
|
||||
*
|
||||
* @param reason: Argument 1
|
||||
*/
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
mInputs.Clean();
|
||||
mConditions.Clean();
|
||||
|
||||
//
|
||||
ZeroMemory(helper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Tick Event ...
|
||||
*/
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
// Run on New Bar ...
|
||||
bool isNewBar = mBarTracker.IsNewBar();
|
||||
if (!isNewBar)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Setting Bar Index ...
|
||||
int barIndex = 0;
|
||||
|
||||
//
|
||||
// Retrieve Conditions ...
|
||||
has = helper.GetConditions(
|
||||
mConditions,
|
||||
barIndex,
|
||||
mLoopback //
|
||||
);
|
||||
if (!has)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Handling Logic ...
|
||||
HandleLogic();
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
/**
|
||||
* Initialize Helper ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitHelper()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mInputs.Default();
|
||||
|
||||
//
|
||||
// Configure Inputs ...
|
||||
|
||||
//
|
||||
// Oscilators ...
|
||||
mInputs.showAC = false;
|
||||
mInputs.showAD = false;
|
||||
mInputs.showADX = false;
|
||||
mInputs.showATR = false;
|
||||
mInputs.showCCI = false;
|
||||
mInputs.showRSI = false;
|
||||
mInputs.showMFI = false;
|
||||
mInputs.showRVI = false;
|
||||
mInputs.showMACD = false;
|
||||
mInputs.showMomentum = false;
|
||||
mInputs.showStochastic = false;
|
||||
|
||||
//
|
||||
// XCT ...
|
||||
mInputs.ctInputs.showCandleTime = true;
|
||||
|
||||
//
|
||||
// XCC ...
|
||||
mInputs.ccInputs.showCandles = true;
|
||||
|
||||
//
|
||||
// X3MA ...
|
||||
mInputs.x3maInputs.showFast = false;
|
||||
mInputs.x3maInputs.showSlow = false;
|
||||
mInputs.x3maInputs.showMedium = false;
|
||||
|
||||
//
|
||||
// XOSC ...
|
||||
// mInputs.oscsInputs;
|
||||
|
||||
//
|
||||
// XCA ...
|
||||
mInputs.caInputs.showKI = false;
|
||||
mInputs.caInputs.showSar = false;
|
||||
mInputs.caInputs.showTKI = false;
|
||||
mInputs.caInputs.showMAH = true;
|
||||
mInputs.caInputs.showMAL = true;
|
||||
mInputs.caInputs.showMAC = true;
|
||||
mInputs.caInputs.showVidya = false;
|
||||
mInputs.caInputs.showTrend = false;
|
||||
mInputs.caInputs.showSwings = false;
|
||||
mInputs.caInputs.showLongCycle = false;
|
||||
mInputs.caInputs.showHindCycle = false;
|
||||
mInputs.caInputs.showShortCycle = false;
|
||||
mInputs.caInputs.showFiboLevel1 = true;
|
||||
mInputs.caInputs.showFiboLevel2 = false;
|
||||
mInputs.caInputs.showFiboLevel3 = true;
|
||||
mInputs.caInputs.showMediumCycle = false;
|
||||
mInputs.caInputs.showPeaksAndVales = false;
|
||||
mInputs.caInputs.showPeakAndValeGolden = false;
|
||||
mInputs.caInputs.showSupportAndResistance = true;
|
||||
|
||||
//
|
||||
// Initialize Helper ...
|
||||
helper = new XCXCAEAHelper();
|
||||
result = helper.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Bar Tracker ...
|
||||
result = mBarTracker.Init(
|
||||
_Symbol,
|
||||
_Period //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Logic of Script ...
|
||||
*/
|
||||
void HandleLogic()
|
||||
{
|
||||
//
|
||||
// Defining Requirements ...
|
||||
|
||||
//
|
||||
int zIDX = 0;
|
||||
int cIDX = zIDX + 1;
|
||||
int pIDX = cIDX + 1;
|
||||
int p2IDX = pIDX + 1;
|
||||
|
||||
//
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
// Reading Required Values ...
|
||||
|
||||
//
|
||||
// PEAK ...
|
||||
double zPeak = mConditions.peakBuffer[zIDX];
|
||||
double cPeak = mConditions.peakBuffer[cIDX];
|
||||
double pPeak = mConditions.peakBuffer[pIDX];
|
||||
double p2Peak = mConditions.peakBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// VALE ...
|
||||
double zVale = mConditions.valeBuffer[zIDX];
|
||||
double cVale = mConditions.valeBuffer[cIDX];
|
||||
double pVale = mConditions.valeBuffer[pIDX];
|
||||
double p2Vale = mConditions.valeBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
double zSar = mConditions.sarBuffer[zIDX];
|
||||
double cSar = mConditions.sarBuffer[cIDX];
|
||||
double pSar = mConditions.sarBuffer[pIDX];
|
||||
double p2Sar = mConditions.sarBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// KI ...
|
||||
double zKI = mConditions.kiBuffer[zIDX];
|
||||
double cKI = mConditions.kiBuffer[cIDX];
|
||||
double pKI = mConditions.kiBuffer[pIDX];
|
||||
double p2KI = mConditions.kiBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// KI State ...
|
||||
double zKIState = mConditions.kiStateBuffer[zIDX];
|
||||
double cKIState = mConditions.kiStateBuffer[cIDX];
|
||||
double pKIState = mConditions.kiStateBuffer[pIDX];
|
||||
double p2KIState = mConditions.kiStateBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// TKI ...
|
||||
double zTKI = mConditions.tkiBuffer[zIDX];
|
||||
double cTKI = mConditions.tkiBuffer[cIDX];
|
||||
double pTKI = mConditions.tkiBuffer[pIDX];
|
||||
double p2TKI = mConditions.tkiBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// TKI State ...
|
||||
double zTKIState = mConditions.tkiStateBuffer[zIDX];
|
||||
double cTKIState = mConditions.tkiStateBuffer[cIDX];
|
||||
double pTKIState = mConditions.tkiStateBuffer[pIDX];
|
||||
double p2TKIState = mConditions.tkiStateBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// MAH ...
|
||||
double zMAH = mConditions.mahBuffer[zIDX];
|
||||
double cMAH = mConditions.mahBuffer[cIDX];
|
||||
double pMAH = mConditions.mahBuffer[pIDX];
|
||||
double p2MAH = mConditions.mahBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// MAL ...
|
||||
double zMAL = mConditions.malBuffer[zIDX];
|
||||
double cMAL = mConditions.malBuffer[cIDX];
|
||||
double pMAL = mConditions.malBuffer[pIDX];
|
||||
double p2MAL = mConditions.malBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// MAC ...
|
||||
double zMAC = mConditions.macBuffer[zIDX];
|
||||
double cMAC = mConditions.macBuffer[cIDX];
|
||||
double pMAC = mConditions.macBuffer[pIDX];
|
||||
double p2MAC = mConditions.macBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// TREND ...
|
||||
double zTrend = mConditions.trendBuffer[zIDX];
|
||||
double cTrend = mConditions.trendBuffer[cIDX];
|
||||
double pTrend = mConditions.trendBuffer[pIDX];
|
||||
double p2Trend = mConditions.trendBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// TREND State ...
|
||||
double zTrendState = mConditions.trendStateBuffer[zIDX];
|
||||
double cTrendState = mConditions.trendStateBuffer[cIDX];
|
||||
double pTrendState = mConditions.trendStateBuffer[pIDX];
|
||||
double p2TrendState = mConditions.trendStateBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// RESISTANCE ...
|
||||
double zResistance = mConditions.resistanceBuffer[zIDX];
|
||||
double cResistance = mConditions.resistanceBuffer[cIDX];
|
||||
double pResistance = mConditions.resistanceBuffer[pIDX];
|
||||
double p2Resistance = mConditions.resistanceBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// SUPPORT ...
|
||||
double zSupport = mConditions.supportBuffer[zIDX];
|
||||
double cSupport = mConditions.supportBuffer[cIDX];
|
||||
double pSupport = mConditions.supportBuffer[pIDX];
|
||||
double p2Support = mConditions.supportBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// VIDYA ...
|
||||
double zVIDYA = mConditions.vidyaBuffer[zIDX];
|
||||
double cVIDYA = mConditions.vidyaBuffer[cIDX];
|
||||
double pVIDYA = mConditions.vidyaBuffer[pIDX];
|
||||
double p2VIDYA = mConditions.vidyaBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// VIDYA State ...
|
||||
double zVIDYAState = mConditions.vidyaStateBuffer[zIDX];
|
||||
double cVIDYAState = mConditions.vidyaStateBuffer[cIDX];
|
||||
double pVIDYAState = mConditions.vidyaStateBuffer[pIDX];
|
||||
double p2VIDYAState = mConditions.vidyaStateBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// SWING Low ...
|
||||
double zSwingLow = mConditions.swingLowBuffer[zIDX];
|
||||
double cSwingLow = mConditions.swingLowBuffer[cIDX];
|
||||
double pSwingLow = mConditions.swingLowBuffer[pIDX];
|
||||
double p2SwingLow = mConditions.swingLowBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// SWING High ...
|
||||
double zSwingHigh = mConditions.swingHighBuffer[zIDX];
|
||||
double cSwingHigh = mConditions.swingHighBuffer[cIDX];
|
||||
double pSwingHigh = mConditions.swingHighBuffer[pIDX];
|
||||
double p2SwingHigh = mConditions.swingHighBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// FIBO Level 1 ...
|
||||
double zFiboLevel1 = mConditions.fiboLevel1Buffer[zIDX];
|
||||
double cFiboLevel1 = mConditions.fiboLevel1Buffer[cIDX];
|
||||
double pFiboLevel1 = mConditions.fiboLevel1Buffer[pIDX];
|
||||
double p2FiboLevel1 = mConditions.fiboLevel1Buffer[p2IDX];
|
||||
|
||||
//
|
||||
// FIBO Level 2 ...
|
||||
double zFiboLevel2 = mConditions.fiboLevel2Buffer[zIDX];
|
||||
double cFiboLevel2 = mConditions.fiboLevel2Buffer[cIDX];
|
||||
double pFiboLevel2 = mConditions.fiboLevel2Buffer[pIDX];
|
||||
double p2FiboLevel2 = mConditions.fiboLevel2Buffer[p2IDX];
|
||||
|
||||
//
|
||||
// FIBO Level 3 ...
|
||||
double zFiboLevel3 = mConditions.fiboLevel3Buffer[zIDX];
|
||||
double cFiboLevel3 = mConditions.fiboLevel3Buffer[cIDX];
|
||||
double pFiboLevel3 = mConditions.fiboLevel3Buffer[pIDX];
|
||||
double p2FiboLevel3 = mConditions.fiboLevel3Buffer[p2IDX];
|
||||
|
||||
//
|
||||
// X3MA ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
|
||||
//
|
||||
double z3MAFast = mConditions.fastBuffer[zIDX];
|
||||
double c3MAFast = mConditions.fastBuffer[cIDX];
|
||||
double p3MAFast = mConditions.fastBuffer[pIDX];
|
||||
double p23MAFast = mConditions.fastBuffer[p2IDX];
|
||||
|
||||
//
|
||||
double z3MAFastState = mConditions.fastStateBuffer[zIDX];
|
||||
double c3MAFastState = mConditions.fastStateBuffer[cIDX];
|
||||
double p3MAFastState = mConditions.fastStateBuffer[pIDX];
|
||||
double p23MAFastState = mConditions.fastStateBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
|
||||
//
|
||||
double z3MAMedium = mConditions.mediumBuffer[zIDX];
|
||||
double c3MAMedium = mConditions.mediumBuffer[cIDX];
|
||||
double p3MAMedium = mConditions.mediumBuffer[pIDX];
|
||||
double p23MAMedium = mConditions.mediumBuffer[p2IDX];
|
||||
|
||||
//
|
||||
double z3MAMediumState = mConditions.mediumStateBuffer[zIDX];
|
||||
double c3MAMediumState = mConditions.mediumStateBuffer[cIDX];
|
||||
double p3MAMediumState = mConditions.mediumStateBuffer[pIDX];
|
||||
double p23MAMediumState = mConditions.mediumStateBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
|
||||
//
|
||||
double z3MASlow = mConditions.slowBuffer[zIDX];
|
||||
double c3MASlow = mConditions.slowBuffer[cIDX];
|
||||
double p3MASlow = mConditions.slowBuffer[pIDX];
|
||||
double p23MASlow = mConditions.slowBuffer[p2IDX];
|
||||
|
||||
//
|
||||
double z3MASlowState = mConditions.slowStateBuffer[zIDX];
|
||||
double c3MASlowState = mConditions.slowStateBuffer[cIDX];
|
||||
double p3MASlowState = mConditions.slowStateBuffer[pIDX];
|
||||
double p23MASlowState = mConditions.slowStateBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
double zRSI = mConditions.rsiBuffer[zIDX];
|
||||
double cRSI = mConditions.rsiBuffer[cIDX];
|
||||
double pRSI = mConditions.rsiBuffer[pIDX];
|
||||
double p2RSI = mConditions.rsiBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// Reading Bars ...
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
XOHCL cBar;
|
||||
XOHCL pBar;
|
||||
XOHCL p2Bar;
|
||||
XOHCL p3Bar;
|
||||
XOHCL p4Bar;
|
||||
has = zBar.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
zIDX //
|
||||
);
|
||||
has =
|
||||
has &&
|
||||
zBar.GetPreviousBar(cBar);
|
||||
has =
|
||||
has &&
|
||||
cBar.GetPreviousBar(pBar);
|
||||
has =
|
||||
has &&
|
||||
pBar.GetPreviousBar(p2Bar);
|
||||
has =
|
||||
has &&
|
||||
p2Bar.GetPreviousBar(p3Bar);
|
||||
has =
|
||||
has &&
|
||||
p3Bar.GetPreviousBar(p4Bar);
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
p2Bar.Clean();
|
||||
p3Bar.Clean();
|
||||
p4Bar.Clean();
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Bars Related Data ...
|
||||
|
||||
//
|
||||
// Score ...
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
mConditions.GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
bool isScoreBullish =
|
||||
bullishScore > bearishScore;
|
||||
|
||||
//
|
||||
bool isScoreBearish =
|
||||
bearishScore > bullishScore;
|
||||
|
||||
//
|
||||
// Generating Conditions Summary ...
|
||||
string summary =
|
||||
mConditions
|
||||
.GenerateSummary();
|
||||
|
||||
//
|
||||
// Calculating Range Volumes ...
|
||||
|
||||
//
|
||||
double bullishVolume = 0;
|
||||
double bearishVolume = 0;
|
||||
int volumeRangeLoopback = 5;
|
||||
helper.barAnalyser.CalculateRangeVolume(
|
||||
cBar,
|
||||
bullishVolume,
|
||||
bearishVolume,
|
||||
volumeRangeLoopback //
|
||||
);
|
||||
|
||||
//
|
||||
double rangeVolume = bullishVolume = bearishVolume;
|
||||
double rangeVolumeAvg = rangeVolume / volumeRangeLoopback;
|
||||
|
||||
//
|
||||
// Preparing Complex Conditions ...
|
||||
|
||||
//
|
||||
bool isRSIBullish =
|
||||
cRSI > pRSI &&
|
||||
!mConditions.isRSIOB;
|
||||
|
||||
//
|
||||
bool isRSIBearish =
|
||||
cRSI < pRSI &&
|
||||
!mConditions.isRSIOS;
|
||||
|
||||
//
|
||||
bool isVolumeBullish = bullishVolume > bearishVolume;
|
||||
bool isVolumeBearish = bullishVolume < bearishVolume;
|
||||
bool isVolumeOverLast = cBar.volume > pBar.volume;
|
||||
bool isVolumeOverAvg = cBar.volume > rangeVolumeAvg;
|
||||
|
||||
//
|
||||
// Cond2 ...
|
||||
|
||||
//
|
||||
bool isCond2Bullish =
|
||||
//
|
||||
mConditions.isUnderMal &&
|
||||
mConditions.isValeIsPivot &&
|
||||
// mConditions.swingLowBuffer[cIDX] > mConditions.valeBuffer[cIDX] &&
|
||||
mConditions.swingLowBuffer[cIDX] < mConditions.fiboLevel3Buffer[cIDX]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isCond2Bearish =
|
||||
//
|
||||
false // &&
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isCond2 = isCond2Bullish ||
|
||||
isCond2Bearish;
|
||||
if (isCond2)
|
||||
{
|
||||
//
|
||||
// Print("Cond2");
|
||||
// isCond2Bullish = false;
|
||||
// isCond2Bearish = false;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Results ...
|
||||
|
||||
//
|
||||
bool isBullish = isCond2Bullish;
|
||||
bool isBearish = isCond2Bearish;
|
||||
|
||||
//
|
||||
bool result = isBullish ||
|
||||
isBearish;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
datetime time = zBar.time;
|
||||
|
||||
//
|
||||
ENUM_X_DIRECTION iDir =
|
||||
isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
// Handle Works ...
|
||||
if (isCond2)
|
||||
{
|
||||
//
|
||||
string name = "Cond2_" + ToString(iDir);
|
||||
|
||||
//
|
||||
color clr = isBullish
|
||||
? clrAqua
|
||||
: clrMagenta;
|
||||
|
||||
//
|
||||
CChartObjectHLine *iObj;
|
||||
iObj = new CChartObjectHLine();
|
||||
has = iObj.Create(
|
||||
0,
|
||||
name,
|
||||
0,
|
||||
time //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Style Object ...
|
||||
iObj.Width(1);
|
||||
iObj.Color(clr);
|
||||
iObj.Style(STYLE_DOT);
|
||||
|
||||
//
|
||||
// Store Object ...
|
||||
mObjects.Add(iObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,167 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: XCXCAEADataCollector ...
|
||||
// Description: Class for XCAEA Data Collector ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm Class for XCAEA Data Collector"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../../Classes/x-saherelm.base.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Implementation ...
|
||||
class XCXCAEADataCollector : public XCBase
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructors ...
|
||||
XCXCAEADataCollector()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCXCAEADataCollector()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Properties ...
|
||||
|
||||
//
|
||||
string Path()
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
//
|
||||
void Path(string value)
|
||||
{
|
||||
//
|
||||
// Normalizing Collector Path ...
|
||||
if (IsValid(value))
|
||||
{
|
||||
mPath = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
mPath = "XCXCAEADataCollector";
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
string GetFilePath(string fileName)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
mPath + "\\" + fileName + ".x121.log"
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int GetFileHandlerForWrite(string filePath)
|
||||
{
|
||||
//
|
||||
int result = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
if (!IsValid(filePath))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = FileOpen(
|
||||
filePath,
|
||||
FILE_READ | FILE_WRITE | FILE_TXT //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Specified Content into Specified File Name ...
|
||||
*
|
||||
* @param fileName: string, file name ...
|
||||
* @param content: string, content ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool Save(
|
||||
string fileName,
|
||||
string content //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid(content);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
int mHandler = GetFileHandlerForWrite(fileName);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
FileWrite(mHandler, content);
|
||||
FileFlush(mHandler);
|
||||
FileClose(mHandler);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
string mPath; // Base Collector Path ...
|
||||
};
|
||||
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
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,961 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XCAEA MQL5 Expert Advisor
|
||||
// -------------------------------------------------
|
||||
// Name: XCAEA
|
||||
// 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 XCAEA EA"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.x-alert.class.mq5"
|
||||
#include "../Classes/x-saherelm.x-trade.class.mq5"
|
||||
#include "../Classes/x-saherelm.x-volume.class.mq5"
|
||||
#include "../XCAEA/Classes/xcaea.x-trade.manager.class.mq5"
|
||||
#include "../XCAEA/Signals/xcaea.signaller.class.mq5"
|
||||
|
||||
//
|
||||
#define ShortName "XCAEAEA"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Common ...
|
||||
input group "Common";
|
||||
input long eaMagicNumber = 78692110; // Magic Number
|
||||
input int eaSlippage = 10; // Slippgae
|
||||
input string eaLogSuffix = ""; // Log Suffix
|
||||
input ENUM_TIMEFRAMES eaAnalysisPeriod = PERIOD_H1; // Analysis Period
|
||||
|
||||
//
|
||||
// Symbols ...
|
||||
//
|
||||
// -------------------------------------------------------
|
||||
// ----------
|
||||
// eaSymbols:
|
||||
// ----------
|
||||
// - if EMPTY use Current Symbol;
|
||||
// - for Multi Symbol use Comma Separated Symbols:
|
||||
// EURUSDb,XAUUSDb
|
||||
//
|
||||
// ------------------
|
||||
// eaSymbolSessions:
|
||||
// ------------------
|
||||
// - if EMPTY use WHOLE Times;
|
||||
// - for each Symbol use Comma Separated:
|
||||
// (XEURS1_02:00_14:00),(XEURS2_19:00_23:00)|
|
||||
// -------------------------------------------------------
|
||||
input group "Symbols";
|
||||
input string eaSymbols = ""; // Symbols Description
|
||||
input string eaSymbolSessions = ""; // Symbols Sessions
|
||||
|
||||
//
|
||||
// Volume ...
|
||||
input group "Volume";
|
||||
input ENUM_X_VOLUME_SELECT_TYPE eaVolumeSelect = X_VOLUME_EQUITY; // Volume Applying Type
|
||||
input double eaStaticVoluem = 0.0; // Static Volume
|
||||
input double eaDynamicVolumeStepBalance = 0.0; // Step of Balance for Increase Volume
|
||||
input double eaDynamicVolumeStepVolume = X_MIN_VOLUME; // Step of Volume Increasing
|
||||
input double eaConstantRiskBalance = 0.0; // Constant Risk Balance per Trade
|
||||
input double eaConstantPercent = 0.5; // Constant Percent of Balance Per Trade
|
||||
input double eaConstantBalance = 0.0; // Constant Balance for Calculations
|
||||
|
||||
//
|
||||
// Management ...
|
||||
input group "Management";
|
||||
input bool eaAllowTrade = true; // Allow Trade on Signals
|
||||
input bool eaAllowLongs = true; // Allow Long Trades
|
||||
input bool eaAllowShorts = true; // Allow Short Trades
|
||||
input ENUM_XCAEA_TRADE_RESTRICTION_PERIOD eaRestrictionsPeriod = XCAEA_TRADE_RESTRICATION_DAILY; // Trade Restrictions Period
|
||||
input int eaMaxAllowedTPs = 2; // Max Allowed TP(s) per Day
|
||||
input int eaMaxAllowedSLs = 2; // Max Allowed SL(s) per Day
|
||||
input int eaMaxAllowedTrades = 3; // Max Allowed Trades per Day
|
||||
input int eaMaxAllowedPositions = 5; // Max Allowed Same Time Trades
|
||||
input double eaMaxAllowedSpread = 25; // Max Allowed Spread For Trade
|
||||
input double eaMaxAllowedDrawdownFactor = 0.3; // Max Allowed DrawDown for Trade
|
||||
input string eaCloseAllOpenTradesAt = ""; // Close All Open Trades per Day At Specified Time
|
||||
|
||||
//
|
||||
// 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
|
||||
input bool eaReportTrades = true; // Report Trades
|
||||
input bool eaReportSignals = true; // Report Signals
|
||||
input bool eaReportProtector = true; // Report Protector Actions
|
||||
input bool eaReportAfterTradesBalance = true; // Report Balance after a Trade Finished
|
||||
|
||||
//
|
||||
// Variables, Instances ...
|
||||
XCAlert *eaAlert;
|
||||
XCTrade *eaTrade;
|
||||
XSignal eaSignal;
|
||||
XCVolume *eaVolume;
|
||||
XTimeTracker eaTimeTracker;
|
||||
XCXCAEASignaller *eaSignallers[];
|
||||
XCXCAEATradeManager *eaTradeManager;
|
||||
XCAEAStrategyConditions eaConditions;
|
||||
|
||||
//
|
||||
string eaTag = "";
|
||||
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Requirements ...
|
||||
InitRequirements();
|
||||
|
||||
//
|
||||
// Initialize Volume Manger ...
|
||||
if (!InitVolume())
|
||||
{
|
||||
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
|
||||
|
||||
//
|
||||
|
||||
//
|
||||
ZeroMemory(eaAlert);
|
||||
ZeroMemory(eaTrade);
|
||||
ZeroMemory(eaVolume);
|
||||
|
||||
//
|
||||
eaSignal.Clean();
|
||||
eaConditions.Clean();
|
||||
eaTimeTracker.Clean();
|
||||
|
||||
//
|
||||
int count = ArraySize(eaSignallers);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
eaSignallers[i].DeInit();
|
||||
ZeroMemory(eaSignallers[i]);
|
||||
}
|
||||
Clean(eaSignallers);
|
||||
|
||||
//
|
||||
DestroyTimer();
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
int idx = -1;
|
||||
int count = 0;
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
HandleTimeReport();
|
||||
|
||||
//
|
||||
// Handle Position Management / Protections ...
|
||||
eaTradeManager.Manage();
|
||||
|
||||
//
|
||||
eaSignal.Clean();
|
||||
eaConditions.Clean();
|
||||
|
||||
//
|
||||
double r2r = 4;
|
||||
string provider = "XCAEA";
|
||||
datetime cTime = TimeCurrent();
|
||||
ENUM_POSITION_TYPE type = POSITION_TYPE_BUY;
|
||||
ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET;
|
||||
|
||||
//
|
||||
bool hasLong = false;
|
||||
bool hasShort = false;
|
||||
|
||||
//
|
||||
// Checking Signallers ...
|
||||
has = HasChild(eaSignallers);
|
||||
if (!has)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
int signallersCount = ArraySize(eaSignallers);
|
||||
for (int is = 0; is < signallersCount; is++)
|
||||
{
|
||||
//
|
||||
// Start Calculations ...
|
||||
|
||||
//
|
||||
// Retrieve Common Data ...
|
||||
string symbol = eaSignallers[is].GetSymbol();
|
||||
ENUM_TIMEFRAMES period = eaSignallers[is].GetPeriod();
|
||||
|
||||
//
|
||||
// Required Value For SL/TP Calculations ...
|
||||
double points = GetPoints(symbol);
|
||||
double pip = GetPipPrice(symbol);
|
||||
double pip2 = 2 * pip;
|
||||
|
||||
//
|
||||
// Detect Signal Setups ...
|
||||
has = eaSignallers[is].DetectSignalSetup(r2r);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
count = eaSignallers[is]
|
||||
.AddConditionsIfNotExists();
|
||||
|
||||
//
|
||||
eaSignallers[is].mConditions.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Check Setuped Conditions Exists ...
|
||||
count = ArraySize(eaSignallers[is].mConditionsCollection);
|
||||
has = IsValidSize(count);
|
||||
if (!has)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop through Setuped Conditions for
|
||||
// Validating or Looking up Triggers ...
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
// Check Signal Triggered or not ...
|
||||
has = eaSignallers[is]
|
||||
.DetectSignalTrigger(eaSignallers[is]
|
||||
.mConditionsCollection[i]);
|
||||
|
||||
//
|
||||
// If Triggered ...
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
idx = i;
|
||||
eaConditions = eaSignallers[is].mConditionsCollection[i];
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Condition Validation ...
|
||||
has = eaSignallers[is].mConditionsCollection[i].IsValid() &&
|
||||
eaSignallers[is].mConditionsCollection[i].IsSetuped();
|
||||
if (!has)
|
||||
{
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Remove Setuped Condition if provided IDX ...
|
||||
has = IsValidIndex(idx);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
ArrayRemove(
|
||||
eaSignallers[is].mConditionsCollection,
|
||||
idx,
|
||||
1 //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Check EA Conditions is Valid or not ...
|
||||
has = eaConditions.IsSetuped() &&
|
||||
eaConditions.CanTrigger();
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
eaSignal.Clean();
|
||||
eaConditions.Clean();
|
||||
|
||||
//
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Setting Time to Conditions ...
|
||||
eaConditions.time = cTime;
|
||||
has = ToPositionType(
|
||||
type,
|
||||
eaConditions.type //
|
||||
);
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
eaSignal.Clean();
|
||||
eaConditions.Clean();
|
||||
|
||||
//
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Checking Trigger Direction ...
|
||||
hasLong = eaConditions.HasBullishSignal();
|
||||
hasShort = eaConditions.HasBearishSignal();
|
||||
has = hasLong ||
|
||||
hasShort;
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
eaSignal.Clean();
|
||||
eaConditions.Clean();
|
||||
|
||||
//
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Preparing Signal ...
|
||||
eaSignal.mode = mode;
|
||||
eaSignal.type = type;
|
||||
eaSignal.entry = GetEntry(
|
||||
eaConditions.symbol,
|
||||
eaConditions.dir //
|
||||
);
|
||||
eaSignal.provider = provider;
|
||||
eaSignal.sl = eaConditions.sl;
|
||||
eaSignal.tp = eaConditions.tp;
|
||||
eaSignal.volume = X_MIN_VOLUME;
|
||||
eaSignal.time = eaConditions.time;
|
||||
eaSignal.symbol = eaConditions.symbol;
|
||||
eaSignal.period = eaConditions.period;
|
||||
|
||||
//
|
||||
// Handling Targets ...
|
||||
ApplyTargetsOnSignal(
|
||||
eaConditions.dir,
|
||||
eaConditions.targets,
|
||||
eaSignal //
|
||||
);
|
||||
|
||||
//
|
||||
// Validate Signal ...
|
||||
has = eaSignal.IsValid();
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
eaSignal.Clean();
|
||||
eaConditions.Clean();
|
||||
|
||||
//
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Volume Management ...
|
||||
double iVolume = eaVolume.CalculateVolume(eaSignal);
|
||||
if (iVolume > X_MIN_VOLUME &&
|
||||
iVolume != eaSignal.volume)
|
||||
{
|
||||
eaSignal.volume = iVolume;
|
||||
}
|
||||
|
||||
//
|
||||
// Execute Signal ...
|
||||
has = eaTradeManager.Execute(
|
||||
eaSignal,
|
||||
eaConditions //
|
||||
);
|
||||
|
||||
//
|
||||
eaSignal.Clean();
|
||||
eaConditions.Clean();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Handle On Trade Event ...
|
||||
void OnTrade()
|
||||
{
|
||||
eaTrade.HandleOnTrade();
|
||||
}
|
||||
|
||||
//
|
||||
// On Timer ...
|
||||
void OnTimer()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Chart Event Handler ...
|
||||
void OnChartEvent(
|
||||
const int id,
|
||||
const long &lparam,
|
||||
const double &dparam,
|
||||
const string &sparam //
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Event Listeners ...
|
||||
|
||||
/**
|
||||
* Handle StopLoss Triggered Positions ...
|
||||
*
|
||||
* @param deal: XDeal instance ...
|
||||
*/
|
||||
void OnStopLossTriggered(const XDeal &deal)
|
||||
{
|
||||
eaTradeManager.HandleSL(deal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Take Profit Triggered Positions ...
|
||||
*
|
||||
* @param deal: XDeal instance ...
|
||||
*/
|
||||
void OnTakeProfitTriggered(const XDeal &deal)
|
||||
{
|
||||
eaTradeManager.HandleTP(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 //
|
||||
)
|
||||
{
|
||||
eaTradeManager.HandleForceClose(position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Position Partially Closed Event ...
|
||||
*
|
||||
* @param ticket: ULONG ...
|
||||
* @param profit: double ...
|
||||
* @param comment: string ...
|
||||
*/
|
||||
void OnPositionPartiallyClosed(
|
||||
const ulong ticket,
|
||||
const double profit,
|
||||
const string comment //
|
||||
)
|
||||
{
|
||||
eaTradeManager.HandlePartiallyClosed(
|
||||
ticket,
|
||||
profit,
|
||||
comment //
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Deals Changes ...
|
||||
*
|
||||
* @param count: Integer, Number of Changes ...
|
||||
*/
|
||||
void OnDealsChanged(int count)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Orders Changes ...
|
||||
*
|
||||
* @param count: Integer, Number of Changes ...
|
||||
*/
|
||||
void OnOrdersChanged(int count)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Positions Changes ...
|
||||
*
|
||||
* @param count: Integer, Number of Changes ...
|
||||
*/
|
||||
void OnPositionsChanged(int 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initial Volume Manager Class Based on Given Configuration ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitVolume()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
eaVolume = new XCVolume();
|
||||
|
||||
//
|
||||
result = eaVolume.Init(
|
||||
eaVolumeSelect,
|
||||
eaStaticVoluem,
|
||||
eaDynamicVolumeStepBalance,
|
||||
eaDynamicVolumeStepVolume,
|
||||
eaConstantRiskBalance,
|
||||
eaConstantPercent,
|
||||
eaConstantBalance //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initial Requirements of EA ...
|
||||
*/
|
||||
void InitRequirements()
|
||||
{
|
||||
//
|
||||
// Preparing Tags ...
|
||||
eaTag =
|
||||
(IsValid(eaLogSuffix)
|
||||
? eaLogSuffix + "_"
|
||||
: "") +
|
||||
ShortName;
|
||||
|
||||
//
|
||||
// EA Alert ...
|
||||
eaAlert = new XCAlert(
|
||||
eaTag,
|
||||
eaEnableAlerts,
|
||||
eaLogAlerts,
|
||||
eaTerminalAlerts,
|
||||
eaMailAlerts,
|
||||
eaPushAlerts //
|
||||
);
|
||||
|
||||
//
|
||||
// EA Trade ...
|
||||
eaTrade = new XCTrade(
|
||||
eaSlippage,
|
||||
eaMagicNumber,
|
||||
eaMaxAllowedSpread,
|
||||
eaMaxAllowedPositions,
|
||||
eaMaxAllowedDrawdownFactor //
|
||||
);
|
||||
eaTrade.AddOnStopLossEventHandler(OnStopLossTriggered);
|
||||
eaTrade.AddOnTakeProfitEventHandler(OnTakeProfitTriggered);
|
||||
eaTrade.AddOnForceClosePositionEventHandler(OnPositionForceClosed);
|
||||
eaTrade.AddOnPartialClosePositionEventHandler(OnPositionPartiallyClosed);
|
||||
|
||||
//
|
||||
// EA Trae Manager ...
|
||||
eaTradeManager = new XCXCAEATradeManager(
|
||||
eaTrade //
|
||||
);
|
||||
eaTradeManager.SaveTrades(true);
|
||||
eaTradeManager.SetAlertEnableAlerts(eaEnableAlerts);
|
||||
eaTradeManager.SetAlertPrefix(eaTag);
|
||||
eaTradeManager.SetAlertLogAlerts(eaLogAlerts);
|
||||
eaTradeManager.SetAlertMailAlerts(eaMailAlerts);
|
||||
eaTradeManager.SetAlertPushAlerts(eaPushAlerts);
|
||||
eaTradeManager.SetAlertTerminalAlerts(eaTerminalAlerts);
|
||||
|
||||
//
|
||||
// Setting Trade Reports ...
|
||||
eaTradeManager
|
||||
.SetTradeReports(
|
||||
eaReportTrades,
|
||||
eaReportSignals,
|
||||
eaReportProtector,
|
||||
eaReportAfterTradesBalance //
|
||||
);
|
||||
|
||||
//
|
||||
// Setting Trade Permissions ...
|
||||
eaTradeManager
|
||||
.SetTradePermissions(
|
||||
eaAllowTrade,
|
||||
eaAllowLongs,
|
||||
eaAllowShorts //
|
||||
);
|
||||
|
||||
//
|
||||
// Setting Trade Restrictions ...
|
||||
eaTradeManager
|
||||
.SetTradeRestrictions(
|
||||
eaRestrictionsPeriod,
|
||||
eaMaxAllowedTPs,
|
||||
eaMaxAllowedSLs,
|
||||
eaMaxAllowedTrades //
|
||||
);
|
||||
|
||||
//
|
||||
InitSymbolSessions();
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Initial Symbols and Active Sessions of EA ...
|
||||
*/
|
||||
void InitSymbolSessions()
|
||||
{
|
||||
//
|
||||
string symbols[];
|
||||
string sessions[];
|
||||
string iSymbol = NULL;
|
||||
XCXCAEASignaller *iSignaller;
|
||||
|
||||
//
|
||||
// Parse Symbols ...
|
||||
int symbolsCount = 0;
|
||||
bool isMultiSymbol = IsValid(eaSymbols);
|
||||
if (isMultiSymbol)
|
||||
{
|
||||
//
|
||||
symbolsCount = SplitContent(
|
||||
symbols,
|
||||
eaSymbols //
|
||||
);
|
||||
isMultiSymbol = IsValidSize(symbolsCount);
|
||||
}
|
||||
if (!isMultiSymbol)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
_Symbol,
|
||||
symbols //
|
||||
);
|
||||
|
||||
//
|
||||
symbolsCount = 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Parse Sessions ...
|
||||
int sessionsCount = 0;
|
||||
bool hasSession = IsValid(eaSymbolSessions);
|
||||
if (hasSession)
|
||||
{
|
||||
//
|
||||
// Extract Per Symbol Sessions ...
|
||||
sessionsCount = SplitContent(
|
||||
sessions,
|
||||
eaSymbolSessions,
|
||||
"|" //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Setting Up Symbols ...
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
for (int i = 0; i < symbolsCount; i++)
|
||||
{
|
||||
//
|
||||
iSymbol = symbols[i];
|
||||
|
||||
//
|
||||
// EA Signaller ...
|
||||
iSignaller = new XCXCAEASignaller(
|
||||
iSymbol,
|
||||
_Period,
|
||||
eaAnalysisPeriod // Analysing Period ...
|
||||
);
|
||||
|
||||
//
|
||||
Add(
|
||||
iSignaller,
|
||||
eaSignallers //
|
||||
);
|
||||
|
||||
//
|
||||
ZeroMemory(iSignaller);
|
||||
}
|
||||
|
||||
//
|
||||
// Setting Up Sessions ...
|
||||
if (hasSession)
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < symbolsCount; i++)
|
||||
{
|
||||
//
|
||||
iSymbol = symbols[i];
|
||||
|
||||
//
|
||||
if (i < sessionsCount)
|
||||
{
|
||||
//
|
||||
// Extract Per Symbol Sessions ...
|
||||
string iSymbolSessionsStr[];
|
||||
int iSymbolSessionsCount = SplitContent(
|
||||
iSymbolSessionsStr,
|
||||
sessions[i],
|
||||
"," //
|
||||
);
|
||||
|
||||
//
|
||||
has = IsValidSize(iSymbolSessionsCount);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Loop through Symbols Sessions ...
|
||||
for (int j = 0; j < iSymbolSessionsCount; j++)
|
||||
{
|
||||
//
|
||||
string iSessionDescriptorStr = ExtractString(iSymbolSessionsStr[j]);
|
||||
has = IsValid(iSessionDescriptorStr);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Extract Session Descriptor Data ...
|
||||
string parts[];
|
||||
int partsCount = SplitContent(
|
||||
parts,
|
||||
iSessionDescriptorStr,
|
||||
"_" //
|
||||
);
|
||||
has = IsValidSize(partsCount) && partsCount == 3;
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
string iName = parts[0];
|
||||
string iStart = parts[1];
|
||||
string iEnd = parts[2];
|
||||
has = IsValid(iName) &&
|
||||
IsValid(iStart) &&
|
||||
IsValid(iEnd);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
eaTradeManager
|
||||
.SetTradeSession(
|
||||
iSymbol,
|
||||
iStart,
|
||||
iEnd,
|
||||
iName //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Clean(parts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Clean(iSymbolSessionsStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Clean(symbols);
|
||||
Clean(sessions);
|
||||
ZeroMemory(iSignaller);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handling Time Reporting ...
|
||||
*/
|
||||
void HandleTimeReport()
|
||||
{
|
||||
//
|
||||
// Monthly Report ....
|
||||
if (eaReportNewMonths &&
|
||||
eaTimeTracker.IsNewMonth())
|
||||
{
|
||||
//
|
||||
string msg = "New Month ...";
|
||||
|
||||
//
|
||||
eaAlert.SendAlert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Weekly Report ....
|
||||
if (eaReportNewWeeks &&
|
||||
eaTimeTracker.IsNewWeek())
|
||||
{
|
||||
//
|
||||
string msg = "New Week ...";
|
||||
|
||||
//
|
||||
eaAlert.SendAlert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Daily Report ....
|
||||
if (eaReportNewDays &&
|
||||
eaTimeTracker.IsNewDay())
|
||||
{
|
||||
//
|
||||
string msg = "New Day ...";
|
||||
|
||||
//
|
||||
eaAlert.SendAlert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Hourly Report ....
|
||||
if (eaReportNewHours &&
|
||||
eaTimeTracker.IsNewHour())
|
||||
{
|
||||
//
|
||||
string msg = "New Hour ...";
|
||||
|
||||
//
|
||||
eaAlert.SendAlert(msg);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,942 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XCATB MQL5 Expert Advisor
|
||||
// -------------------------------------------------
|
||||
// Name: XCAEA
|
||||
// Description: an Exper Advisor which used XCATB
|
||||
//
|
||||
// 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 "EA based on X121 XCATB indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Include Common Library ...
|
||||
#include "../Classes/x-saherelm.x-alert.class.mq5"
|
||||
#include "../Classes/x-saherelm.x-trade.class.mq5"
|
||||
#include "../Classes/x-saherelm.x-volume.class.mq5"
|
||||
#include "../Helpers/x-saherelm.x121.xcatb.helper.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.x121.xcatb.lib.mq5"
|
||||
#include "../XCAEA/Classes/xcaea.x-trade.manager.class.mq5"
|
||||
|
||||
//
|
||||
#define ShortName "XCATB_EA"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Common ...
|
||||
input group "Common";
|
||||
input long eaMagicNumber = 78692110; // Magic Number
|
||||
input int eaSlippage = 10; // Slippgae
|
||||
input string eaLogSuffix = ""; // Log Suffix
|
||||
|
||||
//
|
||||
// Detector ...
|
||||
input group "Detector";
|
||||
|
||||
//
|
||||
// Validating ...
|
||||
input group "Validations";
|
||||
input bool eaForceHasSwing = false; // Force Blocks to Have Swing
|
||||
input bool eaForceObBarType = false; // Force Block Has Reversal Bar
|
||||
input bool eaForceOBFVGBarType = false; // Force FVG Has Same Bars
|
||||
input bool eaForceHasFLiquidity = false; // Force Blocks to Have Following Liquidity
|
||||
input bool eaForceHasRLiquidity = false; // Force Blocks to Have Reversal Liquidity
|
||||
input bool eaValidateGapSequence = false; // Validate Block's Gap Sequence
|
||||
input bool eaValidateBlockEdgeBreakout = false; // Validate Block's Edge Breakout
|
||||
|
||||
//
|
||||
// Filtering ...
|
||||
input group "Filters";
|
||||
input bool eaFilterBasedOnPV = false; // Filter Based on Peak and Vale
|
||||
input bool eaFilterBasedOnSar = false; // Filter Based on Sar
|
||||
input bool eaFilterBasedOnRSI = false; // Filter Based on RSI
|
||||
input bool eaFilterBasedOnADX = false; // Filter Based on ADX
|
||||
input bool eaFilterBasedOnATR = false; // Filter Based on ATR
|
||||
input bool eaFilterBasedOnTrend = false; // Filter Based on Trend
|
||||
input bool eaFilterBasedOnDelta = false; // Filter Based on Delta
|
||||
input bool eaFilterBasedOnVolume = false; // Filter Based on Volume
|
||||
input bool eaFilterBasedOnSignalBar = false; // Filter Based on Signal Bar
|
||||
input bool eaFilterBasedOnHKSignalBar = false; // Filter Based on Hiken Ashi Signal Bar
|
||||
|
||||
//
|
||||
// Signal ...
|
||||
input group "Signal";
|
||||
input int eaSignalR2R = 3; // Risk Reward Ratio
|
||||
input double eaSLAtrMultiplier = 0.5; // ATR Multiplier for SL
|
||||
|
||||
//
|
||||
// Volume ...
|
||||
input group "Volume";
|
||||
input ENUM_X_VOLUME_SELECT_TYPE eaVolumeSelect = X_VOLUME_EQUITY; // Volume Applying Type
|
||||
input double eaStaticVoluem = 0.0; // Static Volume
|
||||
input double eaDynamicVolumeStepBalance = 0.0; // Step of Balance for Increase Volume
|
||||
input double eaDynamicVolumeStepVolume = X_MIN_VOLUME; // Step of Volume Increasing
|
||||
input double eaConstantRiskBalance = 0.0; // Constant Risk Balance per Trade
|
||||
input double eaConstantPercent = 0.5; // Constant Percent of Balance Per Trade
|
||||
input double eaConstantBalance = 0.0; // Constant Balance for Calculations
|
||||
|
||||
//
|
||||
// Management ...
|
||||
input group "Management";
|
||||
input bool eaAllowTrade = true; // Allow Trade on Signals
|
||||
input bool eaAllowLongs = true; // Allow Long Trades
|
||||
input bool eaAllowShorts = true; // Allow Short Trades
|
||||
input ENUM_XCAEA_TRADE_RESTRICTION_PERIOD eaRestrictionsPeriod = XCAEA_TRADE_RESTRICATION_NONE; // Trade Restrictions Period
|
||||
input int eaMaxAllowedTPs = 0; // Max Allowed TP(s) per Day
|
||||
input int eaMaxAllowedSLs = 0; // Max Allowed SL(s) per Day
|
||||
input int eaMaxAllowedTrades = 0; // Max Allowed Trades per Day
|
||||
input int eaMaxAllowedPositions = 5; // Max Allowed Same Time Trades
|
||||
input double eaMaxAllowedSpread = 25; // Max Allowed Spread For Trade
|
||||
input double eaMaxAllowedDrawdownFactor = 0.3; // Max Allowed DrawDown for Trade
|
||||
input string eaCloseAllOpenTradesAt = ""; // Close All Open Trades per Day At Specified Time
|
||||
|
||||
//
|
||||
// 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 = true; // Push Alerts
|
||||
input bool eaTerminalAlerts = true; // 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
|
||||
input bool eaReportTrades = true; // Report Trades
|
||||
input bool eaReportSignals = true; // Report Signals
|
||||
input bool eaReportProtector = true; // Report Protector Actions
|
||||
input bool eaReportAfterTradesBalance = true; // Report Balance after a Trade Finished
|
||||
|
||||
//
|
||||
// Variables ...
|
||||
|
||||
//
|
||||
XCAlert *eaAlert;
|
||||
XCTrade *eaTrade;
|
||||
XSignal eaSignal;
|
||||
XCVolume *eaVolume;
|
||||
X121XCatbInputs eaInputs;
|
||||
XCX121XCatbHelper *eaHelper;
|
||||
XBarTracker eaBarTraker;
|
||||
XTimeTracker eaTimeTracker;
|
||||
XCXCAEATradeManager *eaTradeManager;
|
||||
XCAEAStrategyConditions eaConditions;
|
||||
|
||||
//
|
||||
XTriggerBlock eaTB;
|
||||
|
||||
//
|
||||
CArrayObj *eaObjects;
|
||||
|
||||
//
|
||||
string eaTag = "";
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs and Required Parameters
|
||||
// for EA to Works fine ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Requirements ...
|
||||
InitRequirements();
|
||||
|
||||
//
|
||||
// Initialize Volume Manger ...
|
||||
if (!InitVolume())
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
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
|
||||
|
||||
//
|
||||
// eaObjects.Clear();
|
||||
|
||||
//
|
||||
delete eaHelper;
|
||||
ZeroMemory(eaHelper);
|
||||
|
||||
//
|
||||
delete eaAlert;
|
||||
ZeroMemory(eaAlert);
|
||||
|
||||
//
|
||||
delete eaTrade;
|
||||
ZeroMemory(eaTrade);
|
||||
|
||||
//
|
||||
delete eaVolume;
|
||||
ZeroMemory(eaVolume);
|
||||
|
||||
//
|
||||
eaSignal.Clean();
|
||||
eaBarTraker.Clean();
|
||||
eaConditions.Clean();
|
||||
eaTimeTracker.Clean();
|
||||
|
||||
//
|
||||
DestroyTimer();
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
HandleTimeReport();
|
||||
|
||||
//
|
||||
// Handle Position Management / Protections ...
|
||||
// eaTradeManager.Manage();
|
||||
|
||||
// //
|
||||
// eaSignal.Clean();
|
||||
// eaConditions.Clean();
|
||||
|
||||
//
|
||||
// Check Bar Processing ...
|
||||
if (!eaBarTraker.CanProcessBar())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
// Retrieve Bars ...
|
||||
// XOHCL zBar;
|
||||
// XOHCL cBar;
|
||||
// has = zBar.Init(
|
||||
// _Symbol,
|
||||
// _Period,
|
||||
// 0 //
|
||||
// );
|
||||
// has =
|
||||
// has &&
|
||||
// zBar.GetPreviousBar(cBar);
|
||||
// if (!has)
|
||||
// {
|
||||
// //
|
||||
// zBar.Clean();
|
||||
// cBar.Clean();
|
||||
|
||||
// //
|
||||
// return;
|
||||
// }
|
||||
|
||||
//
|
||||
// double bid = GetBid(zBar.symbol);
|
||||
|
||||
//
|
||||
// XTriggerBlock iTB;
|
||||
// has = GetNewestX121TriggerBlock(
|
||||
// _Symbol,
|
||||
// _Period,
|
||||
// iTB //
|
||||
// );
|
||||
// if (has)
|
||||
// {
|
||||
// //
|
||||
// // Check Newest TB is Newer Than Exists TB ...
|
||||
// bool canPass =
|
||||
// !eaTB.IsValid()
|
||||
// ? true
|
||||
// : iTB.ToIndex() < eaTB.ToIndex();
|
||||
// if (canPass)
|
||||
// {
|
||||
// //
|
||||
// eaTB = iTB;
|
||||
// eaSignal = iTB.signal;
|
||||
|
||||
// //
|
||||
// // Prepare eaConditions if Reuqired ...
|
||||
// }
|
||||
// }
|
||||
|
||||
//
|
||||
// has = eaSignal.IsValid();
|
||||
// if (has)
|
||||
// {
|
||||
// //
|
||||
// // Here we ensure which has a New Signal and must
|
||||
// // prepare and Execute it ...
|
||||
// Print("new Signal Detected ...");
|
||||
// }
|
||||
|
||||
//
|
||||
// eaTB.Clean();
|
||||
// zBar.Clean();
|
||||
// cBar.Clean();
|
||||
// eaSignal.Clean();
|
||||
// eaConditions.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Handle On Trade Event ...
|
||||
void OnTrade()
|
||||
{
|
||||
eaTrade.HandleOnTrade();
|
||||
}
|
||||
|
||||
//
|
||||
// On Timer ...
|
||||
void OnTimer()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Chart Event Handler ...
|
||||
void OnChartEvent(
|
||||
const int id,
|
||||
const long &lparam,
|
||||
const double &dparam,
|
||||
const string &sparam //
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Event Listeners ...
|
||||
|
||||
/**
|
||||
* Handle StopLoss Triggered Positions ...
|
||||
*
|
||||
* @param deal: XDeal instance ...
|
||||
*/
|
||||
void OnStopLossTriggered(const XDeal &deal)
|
||||
{
|
||||
eaTradeManager.HandleSL(deal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Take Profit Triggered Positions ...
|
||||
*
|
||||
* @param deal: XDeal instance ...
|
||||
*/
|
||||
void OnTakeProfitTriggered(const XDeal &deal)
|
||||
{
|
||||
eaTradeManager.HandleTP(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 //
|
||||
)
|
||||
{
|
||||
eaTradeManager.HandleForceClose(position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Position Partially Closed Event ...
|
||||
*
|
||||
* @param ticket: ULONG ...
|
||||
* @param profit: double ...
|
||||
* @param comment: string ...
|
||||
*/
|
||||
void OnPositionPartiallyClosed(
|
||||
const ulong ticket,
|
||||
const double profit,
|
||||
const string comment //
|
||||
)
|
||||
{
|
||||
eaTradeManager.HandlePartiallyClosed(
|
||||
ticket,
|
||||
profit,
|
||||
comment //
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Deals Changes ...
|
||||
*
|
||||
* @param count: Integer, Number of Changes ...
|
||||
*/
|
||||
void OnDealsChanged(int count)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Orders Changes ...
|
||||
*
|
||||
* @param count: Integer, Number of Changes ...
|
||||
*/
|
||||
void OnOrdersChanged(int count)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Positions Changes ...
|
||||
*
|
||||
* @param count: Integer, Number of Changes ...
|
||||
*/
|
||||
void OnPositionsChanged(int 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initial Volume Manager Class Based on Given Configuration ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitVolume()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
eaVolume = new XCVolume();
|
||||
|
||||
//
|
||||
result = eaVolume.Init(
|
||||
eaVolumeSelect,
|
||||
eaStaticVoluem,
|
||||
eaDynamicVolumeStepBalance,
|
||||
eaDynamicVolumeStepVolume,
|
||||
eaConstantRiskBalance,
|
||||
eaConstantPercent,
|
||||
eaConstantBalance //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initial Requirements of EA ...
|
||||
*/
|
||||
void InitRequirements()
|
||||
{
|
||||
//
|
||||
// Initial Bar Tracker ...
|
||||
eaBarTraker.Init(
|
||||
_Symbol,
|
||||
_Period //
|
||||
);
|
||||
|
||||
//
|
||||
// Preparing Tags ...
|
||||
eaTag =
|
||||
(IsValid(eaLogSuffix)
|
||||
? eaLogSuffix + "_"
|
||||
: "") +
|
||||
ShortName;
|
||||
|
||||
//
|
||||
eaAlert = new XCAlert();
|
||||
eaAlert.SetPrefix(eaLogSuffix);
|
||||
eaAlert.SetLogAlerts(eaLogAlerts);
|
||||
eaAlert.SetMailAlerts(eaMailAlerts);
|
||||
eaAlert.SetPushAlerts(eaPushAlerts);
|
||||
eaAlert.SetEnableAlerts(eaEnableAlerts);
|
||||
eaAlert.SetTerminalAlerts(eaTerminalAlerts);
|
||||
|
||||
//
|
||||
// Objects ...
|
||||
eaObjects = new CArrayObj();
|
||||
|
||||
//
|
||||
// Configure XCA ...
|
||||
eaInputs.Default();
|
||||
|
||||
//
|
||||
// Hide all Visible Buffers ...
|
||||
eaInputs.Hide();
|
||||
|
||||
//
|
||||
// we Can make Show all requirements here ...
|
||||
|
||||
//
|
||||
eaInputs.showATRBand = true;
|
||||
|
||||
// //
|
||||
// // Signal ...
|
||||
// eaInputs.signalR2R = eaSignalR2R;
|
||||
// eaInputs.slAtrMultiplier = eaSLAtrMultiplier;
|
||||
|
||||
// //
|
||||
// // Set Validators ...
|
||||
// eaInputs.forceHasSwing = eaForceHasSwing;
|
||||
// eaInputs.forceObBarType = eaForceObBarType;
|
||||
// eaInputs.forceOBFVGBarType = eaForceOBFVGBarType;
|
||||
// eaInputs.forceHasFLiquidity = eaForceHasFLiquidity;
|
||||
// eaInputs.forceHasRLiquidity = eaForceHasRLiquidity;
|
||||
// eaInputs.validateGapSequence = eaValidateGapSequence;
|
||||
// eaInputs.validateBlockEdgeBreakout = eaValidateBlockEdgeBreakout;
|
||||
|
||||
// //
|
||||
// // Set Filters ...
|
||||
// eaInputs.filterBasedOnPV = eaFilterBasedOnPV;
|
||||
// eaInputs.filterBasedOnSar = eaFilterBasedOnSar;
|
||||
// eaInputs.filterBasedOnRSI = eaFilterBasedOnRSI;
|
||||
// eaInputs.filterBasedOnADX = eaFilterBasedOnADX;
|
||||
// eaInputs.filterBasedOnATR = eaFilterBasedOnATR;
|
||||
// eaInputs.filterBasedOnTrend = eaFilterBasedOnTrend;
|
||||
// eaInputs.filterBasedOnDelta = eaFilterBasedOnDelta;
|
||||
// eaInputs.filterBasedOnVolume = eaFilterBasedOnVolume;
|
||||
// eaInputs.filterBasedOnSignalBar = eaFilterBasedOnSignalBar;
|
||||
// eaInputs.filterBasedOnHKSignalBar = eaFilterBasedOnHKSignalBar;
|
||||
|
||||
// //
|
||||
// // Alerts ...
|
||||
// // eaInputs.alertPrefix = eaTag;
|
||||
// // eaInputs.logAlerts = eaLogAlerts;
|
||||
// // eaInputs.pushAlerts = eaMailAlerts;
|
||||
// // eaInputs.mailAlerts = eaPushAlerts;
|
||||
// // eaInputs.terminalAlerts = eaTerminalAlerts;
|
||||
|
||||
//
|
||||
// eaHelper = new XCX121XCatbHelper();
|
||||
// bool isInited = eaHelper.Init(
|
||||
// _Symbol,
|
||||
// _Period,
|
||||
// eaInputs //
|
||||
// );
|
||||
|
||||
// //
|
||||
// // EA Trade ...
|
||||
// eaTrade = new XCTrade(
|
||||
// eaSlippage,
|
||||
// eaMagicNumber,
|
||||
// eaMaxAllowedSpread,
|
||||
// eaMaxAllowedPositions,
|
||||
// eaMaxAllowedDrawdownFactor //
|
||||
// );
|
||||
// eaTrade.AddOnStopLossEventHandler(OnStopLossTriggered);
|
||||
// eaTrade.AddOnTakeProfitEventHandler(OnTakeProfitTriggered);
|
||||
// eaTrade.AddOnForceClosePositionEventHandler(OnPositionForceClosed);
|
||||
// eaTrade.AddOnPartialClosePositionEventHandler(OnPositionPartiallyClosed);
|
||||
|
||||
// //
|
||||
// // EA Trae Manager ...
|
||||
// eaTradeManager = new XCXCAEATradeManager(
|
||||
// eaTrade //
|
||||
// );
|
||||
// eaTradeManager.SaveTrades(true);
|
||||
// eaTradeManager.SetAlertEnableAlerts(eaEnableAlerts);
|
||||
// eaTradeManager.SetAlertPrefix(eaTag);
|
||||
// eaTradeManager.SetAlertLogAlerts(eaLogAlerts);
|
||||
// eaTradeManager.SetAlertMailAlerts(eaMailAlerts);
|
||||
// eaTradeManager.SetAlertPushAlerts(eaPushAlerts);
|
||||
// eaTradeManager.SetAlertTerminalAlerts(eaTerminalAlerts);
|
||||
|
||||
// //
|
||||
// // Setting Trade Reports ...
|
||||
// eaTradeManager
|
||||
// .SetTradeReports(
|
||||
// eaReportTrades,
|
||||
// eaReportSignals,
|
||||
// eaReportProtector,
|
||||
// eaReportAfterTradesBalance //
|
||||
// );
|
||||
|
||||
// //
|
||||
// // Setting Trade Permissions ...
|
||||
// eaTradeManager
|
||||
// .SetTradePermissions(
|
||||
// eaAllowTrade,
|
||||
// eaAllowLongs,
|
||||
// eaAllowShorts //
|
||||
// );
|
||||
|
||||
// //
|
||||
// // Setting Trade Restrictions ...
|
||||
// eaTradeManager
|
||||
// .SetTradeRestrictions(
|
||||
// eaRestrictionsPeriod,
|
||||
// eaMaxAllowedTPs,
|
||||
// eaMaxAllowedSLs,
|
||||
// eaMaxAllowedTrades //
|
||||
// );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handling Time Reporting ...
|
||||
*/
|
||||
void HandleTimeReport()
|
||||
{
|
||||
//
|
||||
if (eaAlert == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Monthly Report ....
|
||||
if (eaReportNewMonths &&
|
||||
eaTimeTracker.IsNewMonth())
|
||||
{
|
||||
//
|
||||
string msg = "New Month ...";
|
||||
|
||||
//
|
||||
eaAlert.SendAlert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Weekly Report ....
|
||||
if (eaReportNewWeeks &&
|
||||
eaTimeTracker.IsNewWeek())
|
||||
{
|
||||
//
|
||||
string msg = "New Week ...";
|
||||
|
||||
//
|
||||
eaAlert.SendAlert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Daily Report ....
|
||||
if (eaReportNewDays &&
|
||||
eaTimeTracker.IsNewDay())
|
||||
{
|
||||
//
|
||||
string msg = "New Day ...";
|
||||
|
||||
//
|
||||
eaAlert.SendAlert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Hourly Report ....
|
||||
if (eaReportNewHours &&
|
||||
eaTimeTracker.IsNewHour())
|
||||
{
|
||||
//
|
||||
string msg = "New Hour ...";
|
||||
|
||||
//
|
||||
eaAlert.SendAlert(msg);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Apply Signal Targets ...
|
||||
// void ApplySignalTargets(XSignal &signal)
|
||||
// {
|
||||
// //
|
||||
// bool has = signal.IsValid();
|
||||
// if (!has)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Clean Signal Targets ...
|
||||
// Clean(signal.targets);
|
||||
|
||||
// //
|
||||
// // Calculate Requirements ...
|
||||
// double r2r = 1;
|
||||
// // maxAllowedR2R > 0
|
||||
// // ? maxAllowedR2R
|
||||
// // : 1;
|
||||
// double risk = signal.GetRisk();
|
||||
// double reward = risk * r2r;
|
||||
|
||||
// //
|
||||
// double isLong = IsLong(signal.type);
|
||||
|
||||
// //
|
||||
// // Handling Signal TP ...
|
||||
// signal.tp =
|
||||
// isLong
|
||||
// ? signal.entry + reward
|
||||
// : signal.entry - reward;
|
||||
|
||||
// //
|
||||
// // Try to Apply Money Management ...
|
||||
|
||||
// //
|
||||
// if (r2r <= 1)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// //
|
||||
// // XTarget iTarget;
|
||||
|
||||
// // //
|
||||
// // // Partial Close 0.5 of Position on Reward 1 ...
|
||||
// // reward = risk * 1;
|
||||
// // iTarget.target =
|
||||
// // isLong
|
||||
// // ? signal.entry + reward
|
||||
// // : signal.entry - reward;
|
||||
// // iTarget.volumeMultiplier = 0.5;
|
||||
|
||||
// // //
|
||||
// // AddRef(iTarget, signal.targets);
|
||||
// // iTarget.Clean();
|
||||
|
||||
// // //
|
||||
// // if (r2r <= 2)
|
||||
// // {
|
||||
// // return;
|
||||
// // }
|
||||
|
||||
// //
|
||||
// // Making Loop ...
|
||||
// // for (int i = 2; i < ((int)r2r - 1); i++)
|
||||
// // {
|
||||
// // //
|
||||
// // iTarget.Clean();
|
||||
|
||||
// // //
|
||||
// // reward = i * risk;
|
||||
// // iTarget.target =
|
||||
// // isLong
|
||||
// // ? signal.entry + reward
|
||||
// // : signal.entry - reward;
|
||||
// // iTarget.volumeMultiplier = 1 / (r2r - 2);
|
||||
|
||||
// // //
|
||||
// // AddRef(iTarget, signal.targets);
|
||||
// // }
|
||||
|
||||
// //
|
||||
// // Sort Targets ...
|
||||
// ENUM_X_DIRECTION sortingDir =
|
||||
// isLong
|
||||
// ? X_DIRECTION_BULLISH
|
||||
// : X_DIRECTION_BEARISH;
|
||||
// ApplySortOnTargets(
|
||||
// sortingDir,
|
||||
// signal.targets //
|
||||
// );
|
||||
// }
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//
|
||||
static XTriggerBlock mX121TriggerBlocks[];
|
||||
|
||||
//
|
||||
int HasX121TriggerBlocks()
|
||||
{
|
||||
return HasChild(mX121TriggerBlocks);
|
||||
}
|
||||
|
||||
//
|
||||
int CountX121TriggerBlocks()
|
||||
{
|
||||
return ArraySize(mX121TriggerBlocks);
|
||||
}
|
||||
|
||||
//
|
||||
void CleanX121TriggerBlocks(int maxAllowed = 0)
|
||||
{
|
||||
//
|
||||
if (maxAllowed <= 0)
|
||||
{
|
||||
Clean(mX121TriggerBlocks);
|
||||
}
|
||||
else if (maxAllowed > 0)
|
||||
{
|
||||
//
|
||||
CleanupArray(
|
||||
mX121TriggerBlocks,
|
||||
maxAllowed //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
bool GetNewestX121TriggerBlock(
|
||||
string forSymbol,
|
||||
ENUM_TIMEFRAMES forPeriod,
|
||||
XTriggerBlock &tb //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
tb.Clean();
|
||||
|
||||
//
|
||||
result =
|
||||
IsValid(forSymbol) &&
|
||||
IsValid(forPeriod) &&
|
||||
HasX121TriggerBlocks();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through Trigger Blocks to Find Filtered Newest ...
|
||||
int count = CountX121TriggerBlocks();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
bool canSet = !tb.IsValid()
|
||||
? true
|
||||
: tb.ToIndex() < mX121TriggerBlocks[i].ToIndex();
|
||||
if (canSet)
|
||||
{
|
||||
tb = mX121TriggerBlocks[i];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = tb.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
tb.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
|
||||
|
||||
//
|
||||
// Add Trigger Block to Collection
|
||||
// and Cleanup Unuseds ...
|
||||
AddRef(
|
||||
tb,
|
||||
mX121TriggerBlocks //
|
||||
);
|
||||
CleanX121TriggerBlocks(20);
|
||||
@@ -0,0 +1,218 @@
|
||||
|
||||
//
|
||||
// Detect Block Based Trigger ...
|
||||
XBoxZone ob;
|
||||
XOHCL swing;
|
||||
XOHCL breaker;
|
||||
XOHCL outSide;
|
||||
ENUM_X_DIRECTION passedDir;
|
||||
bool isPassed = helper.IsBlockBasedTriggerBar(
|
||||
ob,
|
||||
swing,
|
||||
breaker,
|
||||
outSide,
|
||||
passedDir,
|
||||
1, // Bar Index ...
|
||||
50, // Loopback ...
|
||||
3 // Swing Length ...
|
||||
);
|
||||
if (isPassed)
|
||||
{
|
||||
//
|
||||
// Draw Block Based Trigger ...
|
||||
|
||||
//
|
||||
// Draw OB ...
|
||||
XCBoxObject *obObject;
|
||||
has = helper.poiDrawer.DrawBox(
|
||||
ob,
|
||||
obObject //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
obObject.BoxWidth(2);
|
||||
obObject.BoxStyle(STYLE_SOLID);
|
||||
|
||||
//
|
||||
color obColor =
|
||||
ob.IsBullish()
|
||||
? clrAqua
|
||||
: clrMagenta;
|
||||
obObject.BoxColor(obColor);
|
||||
|
||||
//
|
||||
mObjects.Add(obObject);
|
||||
|
||||
//
|
||||
ZeroMemory(obObject);
|
||||
}
|
||||
|
||||
//
|
||||
double breakPrice =
|
||||
ob.IsBullish()
|
||||
? swing.high
|
||||
: swing.low;
|
||||
|
||||
//
|
||||
// Draw Swing and Breake ...
|
||||
CChartObjectTrend *tObj;
|
||||
tObj = new CChartObjectTrend();
|
||||
string tName = "Swing_For_" + ToString(ob.dir) + "_" + ToString(breakPrice);
|
||||
has = tObj.Create(
|
||||
0,
|
||||
tName,
|
||||
0,
|
||||
swing.time,
|
||||
breakPrice,
|
||||
breaker.time,
|
||||
breakPrice //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
tObj.Width(2);
|
||||
tObj.Style(STYLE_SOLID);
|
||||
|
||||
//
|
||||
color tColor = ob.IsBullish()
|
||||
? clrRed
|
||||
: clrLime;
|
||||
tObj.Color(tColor);
|
||||
|
||||
//
|
||||
mObjects.Add(tObj);
|
||||
|
||||
//
|
||||
ZeroMemory(tObj);
|
||||
}
|
||||
|
||||
//
|
||||
Print("Passed Bar ...");
|
||||
}
|
||||
ob.Clean();
|
||||
swing.Clean();
|
||||
breaker.Clean();
|
||||
outSide.Clean();
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* Check Specified Bar is Swing or not ...
|
||||
*
|
||||
* @param bar: XOHCL instance reference, Specified Swing Bar ...
|
||||
* @param forDir: ENUM_X_DIRECTION member, Specified Direction of Swing ...
|
||||
* @param barIndex: int, Specified Bar Index to Check ...
|
||||
* @param loopback: int, Specified Loopback for BothSide Checking ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsSwingSide(
|
||||
XOHCL &bar,
|
||||
ENUM_X_DIRECTION forDir,
|
||||
int loopback = 7 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = bar.IsValid() &&
|
||||
HasDirection(forDir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool isSwingLow = IsBullish(forDir);
|
||||
bool isSwingHigh = IsBearish(forDir);
|
||||
|
||||
//
|
||||
string symbol = bar.symbol;
|
||||
ENUM_TIMEFRAMES period = bar.period;
|
||||
|
||||
//
|
||||
int totalBars = iBars(
|
||||
symbol,
|
||||
period //
|
||||
);
|
||||
int barIndex = bar.Index();
|
||||
loopback = NormalizeInt(loopback, 3);
|
||||
result =
|
||||
barIndex - loopback > 0 &&
|
||||
barIndex + 1 + loopback <= totalBars;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < loopback; i++)
|
||||
{
|
||||
//
|
||||
XOHCL iPBar;
|
||||
XOHCL iNBar;
|
||||
result = iPBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
barIndex + i //
|
||||
);
|
||||
result =
|
||||
result &&
|
||||
iNBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
barIndex - i //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
iPBar.Clean();
|
||||
iNBar.Clean();
|
||||
|
||||
//
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
isSwingLow =
|
||||
isSwingLow &&
|
||||
bar.low < iPBar.low &&
|
||||
bar.low < iNBar.low;
|
||||
|
||||
//
|
||||
isSwingHigh =
|
||||
isSwingHigh &&
|
||||
bar.high > iPBar.high &&
|
||||
bar.high > iNBar.high;
|
||||
|
||||
//
|
||||
result = isSwingLow ||
|
||||
isSwingHigh;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
iPBar.Clean();
|
||||
iNBar.Clean();
|
||||
|
||||
//
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
iPBar.Clean();
|
||||
iNBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
bar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,317 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| RSI_Div.mq5 |
|
||||
//| Copyright 2023, MetaQuotes Software Corp. |
|
||||
//| https://www.metaquotes.net/ |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2023, MetaQuotes Software Corp."
|
||||
#property link "https://www.metaquotes.net/"
|
||||
#property version "1.00"
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 8
|
||||
#property indicator_plots 2
|
||||
#property indicator_label1 "RSI"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrDodgerBlue
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
#property indicator_label2 "Signal"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrOrange
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//--- Input parameters
|
||||
input int InpRSIPeriod = 14; // RSI Period
|
||||
input ENUM_APPLIED_PRICE InpRSIPrice = PRICE_CLOSE; // RSI Applied Price
|
||||
input int InpLeftBars = 5; // Left bars to check
|
||||
input int InpRightBars = 5; // Right bars to check
|
||||
input double InpMinDivergence = 5.0; // Minimum divergence in %
|
||||
input bool ShowRegularBullish = true; // Show Regular Bullish
|
||||
input bool ShowRegularBearish = true; // Show Regular Bearish
|
||||
input bool ShowHiddenBullish = true; // Show Hidden Bullish
|
||||
input bool ShowHiddenBearish = true; // Show Hidden Bearish
|
||||
|
||||
//--- Indicator buffers
|
||||
double RSIBuffer[];
|
||||
double SignalBuffer[];
|
||||
double HighBuffer[];
|
||||
double LowBuffer[];
|
||||
double BullishDivBuffer[];
|
||||
double BearishDivBuffer[];
|
||||
double HiddenBullishDivBuffer[];
|
||||
double HiddenBearishDivBuffer[];
|
||||
|
||||
//--- Handles
|
||||
int rsiHandle;
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//--- Indicator buffers mapping
|
||||
SetIndexBuffer(0, RSIBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(1, SignalBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(2, HighBuffer, INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(3, LowBuffer, INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(4, BullishDivBuffer, INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(5, BearishDivBuffer, INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(6, HiddenBullishDivBuffer, INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(7, HiddenBearishDivBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//--- Set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||
|
||||
//--- Set first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, InpRSIPeriod);
|
||||
|
||||
//--- Create RSI handle
|
||||
rsiHandle = iRSI(NULL, 0, InpRSIPeriod, InpRSIPrice);
|
||||
|
||||
if (rsiHandle == INVALID_HANDLE)
|
||||
{
|
||||
Print("Failed to create RSI handle");
|
||||
return (INIT_FAILED);
|
||||
}
|
||||
|
||||
//--- Set buffer names
|
||||
string short_name = "RSI Divergence(" + string(InpRSIPeriod) + ")";
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, short_name);
|
||||
|
||||
//--- Set empty value
|
||||
PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, 0.0);
|
||||
|
||||
//--- Initialize arrays as series
|
||||
ArraySetAsSeries(RSIBuffer, true);
|
||||
ArraySetAsSeries(SignalBuffer, true);
|
||||
ArraySetAsSeries(HighBuffer, true);
|
||||
ArraySetAsSeries(LowBuffer, true);
|
||||
ArraySetAsSeries(BullishDivBuffer, true);
|
||||
ArraySetAsSeries(BearishDivBuffer, true);
|
||||
ArraySetAsSeries(HiddenBullishDivBuffer, true);
|
||||
ArraySetAsSeries(HiddenBearishDivBuffer, true);
|
||||
|
||||
return (INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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[])
|
||||
{
|
||||
//--- Check for data sufficiency
|
||||
if (rates_total < InpRSIPeriod + InpLeftBars + InpRightBars)
|
||||
return (0);
|
||||
|
||||
//--- Get RSI values
|
||||
if (CopyBuffer(rsiHandle, 0, 0, rates_total, RSIBuffer) <= 0)
|
||||
{
|
||||
Print("Failed to copy RSI buffer");
|
||||
return (0);
|
||||
}
|
||||
|
||||
//--- Calculate signal line (just for visualization)
|
||||
for (int i = 0; i < rates_total; i++)
|
||||
SignalBuffer[i] = 30 + (70 - 30) / 2;
|
||||
|
||||
//--- Find divergences
|
||||
FindDivergences(rates_total, prev_calculated, high, low, close, time);
|
||||
|
||||
return (rates_total);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Find divergences between price and RSI |
|
||||
//+------------------------------------------------------------------+
|
||||
void FindDivergences(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const datetime &time[])
|
||||
{
|
||||
int start_bar = MathMax(InpRSIPeriod + InpLeftBars + InpRightBars, prev_calculated);
|
||||
|
||||
for (int i = start_bar; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//--- Reset buffers
|
||||
BullishDivBuffer[i] = 0;
|
||||
BearishDivBuffer[i] = 0;
|
||||
HiddenBullishDivBuffer[i] = 0;
|
||||
HiddenBearishDivBuffer[i] = 0;
|
||||
|
||||
//--- Check array boundaries
|
||||
if (i - InpLeftBars < 0 || i + InpRightBars >= rates_total)
|
||||
continue;
|
||||
|
||||
//--- Find highest high and lowest low in left bars
|
||||
int highest_high_bar = Highest(high, i - InpLeftBars, InpLeftBars + InpRightBars + 1);
|
||||
int lowest_low_bar = Lowest(low, i - InpLeftBars, InpLeftBars + InpRightBars + 1);
|
||||
|
||||
//--- Check for regular bullish divergence
|
||||
if (ShowRegularBullish && lowest_low_bar >= 0)
|
||||
{
|
||||
int rsi_lowest_bar = LowestRSI(i - InpLeftBars, InpLeftBars + InpRightBars + 1);
|
||||
|
||||
if (rsi_lowest_bar >= 0 && rsi_lowest_bar != lowest_low_bar &&
|
||||
low[i - lowest_low_bar] < low[i] &&
|
||||
RSIBuffer[i - rsi_lowest_bar] > RSIBuffer[i] &&
|
||||
MathAbs(RSIBuffer[i - rsi_lowest_bar] - RSIBuffer[i]) >= InpMinDivergence)
|
||||
{
|
||||
BullishDivBuffer[i] = RSIBuffer[i] - 5;
|
||||
if (i < ArraySize(time) && i < ArraySize(low))
|
||||
ObjectCreate(0, "BullDiv" + IntegerToString(i), OBJ_ARROW_UP, 0, time[i], low[i] - 50 * _Point);
|
||||
}
|
||||
}
|
||||
|
||||
//--- Check for regular bearish divergence
|
||||
if (ShowRegularBearish && highest_high_bar >= 0)
|
||||
{
|
||||
int rsi_highest_bar = HighestRSI(i - InpLeftBars, InpLeftBars + InpRightBars + 1);
|
||||
|
||||
if (rsi_highest_bar >= 0 && rsi_highest_bar != highest_high_bar &&
|
||||
high[i - highest_high_bar] > high[i] &&
|
||||
RSIBuffer[i - rsi_highest_bar] < RSIBuffer[i] &&
|
||||
MathAbs(RSIBuffer[i - rsi_highest_bar] - RSIBuffer[i]) >= InpMinDivergence)
|
||||
{
|
||||
BearishDivBuffer[i] = RSIBuffer[i] + 5;
|
||||
if (i < ArraySize(time) && i < ArraySize(high))
|
||||
ObjectCreate(0, "BearDiv" + IntegerToString(i), OBJ_ARROW_DOWN, 0, time[i], high[i] + 50 * _Point);
|
||||
}
|
||||
}
|
||||
|
||||
//--- Check for hidden bullish divergence
|
||||
if (ShowHiddenBullish && lowest_low_bar >= 0)
|
||||
{
|
||||
int rsi_lowest_bar = LowestRSI(i - InpLeftBars, InpLeftBars + InpRightBars + 1);
|
||||
|
||||
if (rsi_lowest_bar >= 0 && rsi_lowest_bar != lowest_low_bar &&
|
||||
low[i - lowest_low_bar] > low[i] &&
|
||||
RSIBuffer[i - rsi_lowest_bar] < RSIBuffer[i] &&
|
||||
MathAbs(RSIBuffer[i - rsi_lowest_bar] - RSIBuffer[i]) >= InpMinDivergence)
|
||||
{
|
||||
HiddenBullishDivBuffer[i] = RSIBuffer[i] - 8;
|
||||
if (i < ArraySize(time) && i < ArraySize(low))
|
||||
ObjectCreate(0, "HidBullDiv" + IntegerToString(i), OBJ_ARROW_UP, 0, time[i], low[i] - 80 * _Point);
|
||||
}
|
||||
}
|
||||
|
||||
//--- Check for hidden bearish divergence
|
||||
if (ShowHiddenBearish && highest_high_bar >= 0)
|
||||
{
|
||||
int rsi_highest_bar = HighestRSI(i - InpLeftBars, InpLeftBars + InpRightBars + 1);
|
||||
|
||||
if (rsi_highest_bar >= 0 && rsi_highest_bar != highest_high_bar &&
|
||||
high[i - highest_high_bar] < high[i] &&
|
||||
RSIBuffer[i - rsi_highest_bar] > RSIBuffer[i] &&
|
||||
MathAbs(RSIBuffer[i - rsi_highest_bar] - RSIBuffer[i]) >= InpMinDivergence)
|
||||
{
|
||||
HiddenBearishDivBuffer[i] = RSIBuffer[i] + 8;
|
||||
if (i < ArraySize(time) && i < ArraySize(high))
|
||||
ObjectCreate(0, "HidBearDiv" + IntegerToString(i), OBJ_ARROW_DOWN, 0, time[i], high[i] + 80 * _Point);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Find bar with highest price in range |
|
||||
//+------------------------------------------------------------------+
|
||||
int Highest(const double &price[], int start_pos, int count)
|
||||
{
|
||||
if (start_pos < 0 || count <= 0 || start_pos + count > ArraySize(price))
|
||||
return -1;
|
||||
|
||||
int highest_pos = start_pos;
|
||||
double highest_val = price[start_pos];
|
||||
|
||||
for (int i = start_pos + 1; i < start_pos + count; i++)
|
||||
{
|
||||
if (price[i] > highest_val)
|
||||
{
|
||||
highest_val = price[i];
|
||||
highest_pos = i;
|
||||
}
|
||||
}
|
||||
|
||||
return highest_pos - start_pos;
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Find bar with lowest price in range |
|
||||
//+------------------------------------------------------------------+
|
||||
int Lowest(const double &price[], int start_pos, int count)
|
||||
{
|
||||
if (start_pos < 0 || count <= 0 || start_pos + count > ArraySize(price))
|
||||
return -1;
|
||||
|
||||
int lowest_pos = start_pos;
|
||||
double lowest_val = price[start_pos];
|
||||
|
||||
for (int i = start_pos + 1; i < start_pos + count; i++)
|
||||
{
|
||||
if (price[i] < lowest_val)
|
||||
{
|
||||
lowest_val = price[i];
|
||||
lowest_pos = i;
|
||||
}
|
||||
}
|
||||
|
||||
return lowest_pos - start_pos;
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Find bar with highest RSI in range |
|
||||
//+------------------------------------------------------------------+
|
||||
int HighestRSI(int start_pos, int count)
|
||||
{
|
||||
if (start_pos < 0 || count <= 0 || start_pos + count > ArraySize(RSIBuffer))
|
||||
return -1;
|
||||
|
||||
int highest_pos = start_pos;
|
||||
double highest_val = RSIBuffer[start_pos];
|
||||
|
||||
for (int i = start_pos + 1; i < start_pos + count; i++)
|
||||
{
|
||||
if (RSIBuffer[i] > highest_val)
|
||||
{
|
||||
highest_val = RSIBuffer[i];
|
||||
highest_pos = i;
|
||||
}
|
||||
}
|
||||
|
||||
return highest_pos - start_pos;
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Find bar with lowest RSI in range |
|
||||
//+------------------------------------------------------------------+
|
||||
int LowestRSI(int start_pos, int count)
|
||||
{
|
||||
if (start_pos < 0 || count <= 0 || start_pos + count > ArraySize(RSIBuffer))
|
||||
return -1;
|
||||
|
||||
int lowest_pos = start_pos;
|
||||
double lowest_val = RSIBuffer[start_pos];
|
||||
|
||||
for (int i = start_pos + 1; i < start_pos + count; i++)
|
||||
{
|
||||
if (RSIBuffer[i] < lowest_val)
|
||||
{
|
||||
lowest_val = RSIBuffer[i];
|
||||
lowest_pos = i;
|
||||
}
|
||||
}
|
||||
|
||||
return lowest_pos - start_pos;
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| RSIDivergence.mq5|
|
||||
//| Custom RSI Divergence Detection Indicator |
|
||||
//+------------------------------------------------------------------+
|
||||
#property strict
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 0
|
||||
|
||||
//--- Input parameters
|
||||
input int RSI_Period = 14; // RSI Period
|
||||
input double Deviation = 0.0001; // Minimum price move to consider a swing
|
||||
input int MaxBarsBack = 300; // Number of bars to analyze
|
||||
|
||||
//--- Global handles
|
||||
double rsiBuffer[];
|
||||
int rsiHandle;
|
||||
|
||||
//--- For divergence detection
|
||||
struct SwingPoint
|
||||
{
|
||||
int index;
|
||||
double price;
|
||||
double rsi;
|
||||
};
|
||||
|
||||
SwingPoint priceSwings[];
|
||||
SwingPoint rsiSwings[];
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
SetIndexBuffer(0, rsiBuffer, INDICATOR_DATA);
|
||||
rsiHandle = iRSI(_Symbol, _Period, RSI_Period, PRICE_CLOSE);
|
||||
if (rsiHandle == INVALID_HANDLE)
|
||||
{
|
||||
Print("Could not create RSI handle");
|
||||
return (INIT_FAILED);
|
||||
}
|
||||
return (INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Main 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[])
|
||||
{
|
||||
//--- Get RSI values
|
||||
ArraySetAsSeries(rsiBuffer, true);
|
||||
CopyBuffer(rsiHandle, 0, 0, MaxBarsBack, rsiBuffer);
|
||||
|
||||
//--- Detect swings
|
||||
DetectSwingPoints(close, priceSwings);
|
||||
DetectSwingPoints(rsiBuffer, rsiSwings);
|
||||
|
||||
//--- Find and draw divergences
|
||||
FindAndDrawDivergences(time, close);
|
||||
|
||||
return (rates_total);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Detect swing highs/lows |
|
||||
//+------------------------------------------------------------------+
|
||||
void DetectSwingPoints(const double &values[], SwingPoint &swings[])
|
||||
{
|
||||
ArrayResize(swings, 0); // Clear previous swings
|
||||
int count = 0;
|
||||
|
||||
int size = ArraySize(values);
|
||||
if (size < 3)
|
||||
return; // Not enough data
|
||||
|
||||
// Pre-allocate a safe amount of space
|
||||
ArrayResize(swings, size / 2); // Max possible swings ~50% of total bars
|
||||
|
||||
for (int i = 2; i < size - 2; i++)
|
||||
{
|
||||
// Bounds check
|
||||
if (i - 1 < 0 || i + 1 >= size)
|
||||
continue;
|
||||
|
||||
// Check for swing high
|
||||
if (values[i] > values[i - 1] && values[i] > values[i + 1])
|
||||
{
|
||||
// Ensure we have space in the swings array
|
||||
if (count >= ArraySize(swings))
|
||||
ArrayResize(swings, ArraySize(swings) + 10);
|
||||
|
||||
swings[count].index = i;
|
||||
swings[count].price = values[i];
|
||||
count++;
|
||||
}
|
||||
// Check for swing low
|
||||
else if (values[i] < values[i - 1] && values[i] < values[i + 1])
|
||||
{
|
||||
// Ensure we have space in the swings array
|
||||
if (count >= ArraySize(swings))
|
||||
ArrayResize(swings, ArraySize(swings) + 10);
|
||||
|
||||
swings[count].index = i;
|
||||
swings[count].price = values[i];
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
// Final resize to actual number of swings found
|
||||
ArrayResize(swings, count);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Find and draw divergence |
|
||||
//+------------------------------------------------------------------+
|
||||
void FindAndDrawDivergences(const datetime &time[], const double &close[])
|
||||
{
|
||||
static int lastAlertBar = 0;
|
||||
int limit = MathMin(MaxBarsBack - 2, Bars(_Symbol, _Period));
|
||||
|
||||
for (int i = 0; i < ArraySize(priceSwings) - 1; i++)
|
||||
{
|
||||
for (int j = 0; j < ArraySize(rsiSwings) - 1; j++)
|
||||
{
|
||||
int p1 = priceSwings[i].index;
|
||||
int p2 = priceSwings[i + 1].index;
|
||||
int r1 = rsiSwings[j].index;
|
||||
int r2 = rsiSwings[j + 1].index;
|
||||
|
||||
if (MathAbs(p1 - r1) < 3 && MathAbs(p2 - r2) < 3)
|
||||
{
|
||||
double price1 = close[p1];
|
||||
double price2 = close[p2];
|
||||
double rsi1 = rsiBuffer[r1];
|
||||
double rsi2 = rsiBuffer[r2];
|
||||
|
||||
// Bullish Divergence
|
||||
if (price2 < price1 && rsi2 > rsi1)
|
||||
{
|
||||
string name;
|
||||
StringConcatenate(name, "BullishDiv", IntegerToString(p2));
|
||||
DrawArrow(name, time[p2], close[p2], clrLime);
|
||||
// DrawLine("BullishLineP" + IntegerToString(p2), time[p2], close[p2], time[p1], close[p1], clrLime);
|
||||
// DrawLine("BullishLineR" + IntegerToString(p2), time[p2], rsi2, time[p1], rsi1, clrLime);
|
||||
}
|
||||
|
||||
// Bearish Divergence
|
||||
if (price2 > price1 && rsi2 < rsi1)
|
||||
{
|
||||
string name;
|
||||
StringConcatenate(name, "BearishDiv", IntegerToString(p2));
|
||||
DrawArrow(name, time[p2], close[p2], clrRed);
|
||||
// DrawLine("BearishLineP" + IntegerToString(p2), time[p2], close[p2], time[p1], close[p1], clrRed);
|
||||
// DrawLine("BearishLineR" + IntegerToString(p2), time[p2], rsi2, time[p1], rsi1, clrRed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Draw arrow on chart |
|
||||
//+------------------------------------------------------------------+
|
||||
void DrawArrow(string name, datetime time, double price, color col)
|
||||
{
|
||||
ObjectCreate(0, name, OBJ_ARROW, 0, time, price);
|
||||
ObjectSetInteger(0, name, OBJPROP_ARROWCODE, 233); // Up arrow
|
||||
ObjectSetInteger(0, name, OBJPROP_COLOR, col);
|
||||
ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Draw line |
|
||||
//+------------------------------------------------------------------+
|
||||
void DrawLine(string name, datetime t1, double p1, datetime t2, double p2, color col)
|
||||
{
|
||||
// Delete existing object if any
|
||||
ObjectDelete(0, name);
|
||||
|
||||
// Create trendline (use 1 for OBJ_TRENDLINE if undefined)
|
||||
ObjectCreate(0, name, 1, 0, t1, p1, t2, p2);
|
||||
|
||||
ObjectSetInteger(0, name, OBJPROP_COLOR, col);
|
||||
ObjectSetInteger(0, name, OBJPROP_STYLE, STYLE_DASHDOT);
|
||||
ObjectSetInteger(0, name, OBJPROP_WIDTH, 1);
|
||||
ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false);
|
||||
}
|
||||
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,181 @@
|
||||
#property copyright "Your Name"
|
||||
#property link "https://www.yourwebsite.com"
|
||||
#property version "1.02"
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 2
|
||||
|
||||
//--- Input parameters
|
||||
input int atr_period = 14; // ATR Period
|
||||
input double atr_threshold = 0.0005; // ATR Threshold for Consolidation (e.g., 0.0005 for EURUSD, 5.0 for XAUUSD)
|
||||
input int range_period = 20; // Period to check price range
|
||||
input double range_multiplier = 2.0; // Price range multiplier (relative to ATR)
|
||||
input bool enable_alerts = true; // Enable breakout alerts
|
||||
input bool draw_rectangles = true; // Draw rectangles for consolidation zones
|
||||
|
||||
//--- Indicator buffers
|
||||
double UpperBuffer[];
|
||||
double LowerBuffer[];
|
||||
|
||||
//--- Global variables
|
||||
int atr_handle = INVALID_HANDLE;
|
||||
int zone_count = 0; // For unique rectangle names
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//--- Set indicator buffers
|
||||
SetIndexBuffer(0, UpperBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(1, LowerBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetString(0, PLOT_LABEL, "Upper Consolidation");
|
||||
PlotIndexSetString(1, PLOT_LABEL, "Lower Consolidation");
|
||||
PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_LINE);
|
||||
PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_LINE);
|
||||
PlotIndexSetInteger(0, PLOT_LINE_STYLE, STYLE_SOLID);
|
||||
PlotIndexSetInteger(1, PLOT_LINE_STYLE, STYLE_SOLID);
|
||||
PlotIndexSetInteger(0, PLOT_LINE_COLOR, clrRed);
|
||||
PlotIndexSetInteger(1, PLOT_LINE_COLOR, clrBlue);
|
||||
|
||||
//--- Create ATR handle
|
||||
atr_handle = iATR(_Symbol, _Period, atr_period);
|
||||
if(atr_handle == INVALID_HANDLE)
|
||||
{
|
||||
Print("Failed to create ATR handle, error: ", GetLastError());
|
||||
return(INIT_FAILED);
|
||||
}
|
||||
|
||||
//--- Check available bars
|
||||
int available_bars = Bars(_Symbol, _Period);
|
||||
if(available_bars < range_period + atr_period)
|
||||
{
|
||||
Print("Insufficient bars: ", available_bars, ", required: ", range_period + atr_period);
|
||||
return(INIT_FAILED);
|
||||
}
|
||||
|
||||
//--- Log initialization
|
||||
Print("Indicator initialized. Symbol: ", _Symbol, ", Timeframe: ", Period(),
|
||||
", ATR Period: ", atr_period, ", Range Period: ", range_period);
|
||||
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator deinitialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
if(atr_handle != INVALID_HANDLE)
|
||||
IndicatorRelease(atr_handle);
|
||||
ObjectsDeleteAll(0, "Consolidation_"); // Remove all rectangles
|
||||
Print("Indicator deinitialized, reason: ", reason);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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[])
|
||||
{
|
||||
//--- Ensure enough bars
|
||||
if(rates_total < range_period + atr_period)
|
||||
{
|
||||
Print("Not enough bars: ", rates_total, ", required: ", range_period + atr_period);
|
||||
return(0);
|
||||
}
|
||||
|
||||
//--- Set arrays as series
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(UpperBuffer, true);
|
||||
ArraySetAsSeries(LowerBuffer, true);
|
||||
|
||||
//--- Calculate ATR
|
||||
double atr[];
|
||||
ArraySetAsSeries(atr, true);
|
||||
ArrayResize(atr, rates_total);
|
||||
if(CopyBuffer(atr_handle, 0, 0, rates_total, atr) <= 0)
|
||||
{
|
||||
Print("Failed to copy ATR buffer, error: ", GetLastError());
|
||||
return(0);
|
||||
}
|
||||
|
||||
//--- Initialize buffers for first calculation
|
||||
if(prev_calculated == 0)
|
||||
{
|
||||
ArrayInitialize(UpperBuffer, EMPTY_VALUE);
|
||||
ArrayInitialize(LowerBuffer, EMPTY_VALUE);
|
||||
}
|
||||
|
||||
//--- Loop through bars
|
||||
int start = prev_calculated == 0 ? range_period : MathMax(range_period, prev_calculated - 1);
|
||||
for(int i = start; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//--- Calculate range over range_period
|
||||
int max_idx = ArrayMaximum(high, i - range_period + 1, range_period);
|
||||
int min_idx = ArrayMinimum(low, i - range_period + 1, range_period);
|
||||
if(max_idx == -1 || min_idx == -1)
|
||||
{
|
||||
Print("Error: Invalid array index at bar ", i);
|
||||
continue;
|
||||
}
|
||||
double max_high = high[max_idx];
|
||||
double min_low = low[min_idx];
|
||||
double price_range = max_high - min_low;
|
||||
|
||||
//--- Log values for debugging
|
||||
if(i == rates_total - 1) // Log only for the latest bar
|
||||
{
|
||||
Print("Bar ", i, ": ATR = ", DoubleToString(atr[i], _Digits),
|
||||
", Price Range = ", DoubleToString(price_range, _Digits),
|
||||
", Threshold = ", DoubleToString(atr_threshold, _Digits),
|
||||
", Range Limit = ", DoubleToString(atr[i] * range_multiplier, _Digits));
|
||||
}
|
||||
|
||||
//--- Check for consolidation
|
||||
if(atr[i] < atr_threshold && price_range < atr[i] * range_multiplier)
|
||||
{
|
||||
UpperBuffer[i] = max_high;
|
||||
LowerBuffer[i] = min_low;
|
||||
|
||||
//--- Draw rectangle for the consolidation zone
|
||||
if(draw_rectangles && i >= range_period)
|
||||
{
|
||||
string obj_name = "Consolidation_" + IntegerToString(zone_count++) + "_" + TimeToString(time[i]);
|
||||
ObjectCreate(0, obj_name, OBJ_RECTANGLE, 0, time[i], max_high, time[i - range_period + 1], min_low);
|
||||
ObjectSetInteger(0, obj_name, OBJPROP_COLOR, clrRed);
|
||||
ObjectSetInteger(0, obj_name, OBJPROP_STYLE, STYLE_SOLID);
|
||||
ObjectSetInteger(0, obj_name, OBJPROP_WIDTH, 1);
|
||||
ObjectSetInteger(0, obj_name, OBJPROP_FILL, false);
|
||||
ObjectSetInteger(0, obj_name, OBJPROP_BACK, false);
|
||||
}
|
||||
|
||||
//--- Check for breakout (on latest bar only)
|
||||
if(enable_alerts && i == rates_total - 1)
|
||||
{
|
||||
if(close[i] > UpperBuffer[i] && (i == 0 || close[i-1] <= UpperBuffer[i-1]))
|
||||
Alert("Breakout Up at ", TimeToString(time[i]), ": Price = ", DoubleToString(close[i], _Digits));
|
||||
if(close[i] < LowerBuffer[i] && (i == 0 || close[i-1] >= LowerBuffer[i-1]))
|
||||
Alert("Breakout Down at ", TimeToString(time[i]), ": Price = ", DoubleToString(close[i], _Digits));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UpperBuffer[i] = EMPTY_VALUE;
|
||||
LowerBuffer[i] = EMPTY_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
return(rates_total);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,137 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| VPattern.mq5 |
|
||||
//| Copyright 2023, MetaQuotes Software Corp. |
|
||||
//| https://www.metaquotes.net/ |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2023, MetaQuotes Software Corp."
|
||||
#property link "https://www.metaquotes.net/"
|
||||
#property version "1.00"
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 2
|
||||
#property indicator_label1 "V Pattern Top"
|
||||
#property indicator_type1 DRAW_ARROW
|
||||
#property indicator_color1 clrGreen
|
||||
#property indicator_width1 2
|
||||
#property indicator_label2 "V Pattern Bottom"
|
||||
#property indicator_type2 DRAW_ARROW
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_width2 2
|
||||
|
||||
//--- Input parameters
|
||||
input int LookbackPeriod=20; // Bars to analyze for pattern
|
||||
input double MinDeclinePercent=2.0; // Minimum decline percentage
|
||||
input double MinRisePercent=2.0; // Minimum rise percentage
|
||||
input bool ShowAlerts=true; // Show alert messages
|
||||
input color ArrowUpColor=clrGreen; // Up arrow color
|
||||
input color ArrowDownColor=clrRed; // Down arrow color
|
||||
|
||||
//--- Indicator buffers
|
||||
double VTopBuffer[];
|
||||
double VBottomBuffer[];
|
||||
double TempHighBuffer[];
|
||||
double TempLowBuffer[];
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0, VTopBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(1, VBottomBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(2, TempHighBuffer, INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(3, TempLowBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//--- setting arrow codes
|
||||
PlotIndexSetInteger(0, PLOT_ARROW, 233); // Up arrow
|
||||
PlotIndexSetInteger(1, PLOT_ARROW, 234); // Down arrow
|
||||
|
||||
//--- setting arrow colors
|
||||
PlotIndexSetInteger(0, PLOT_LINE_COLOR, ArrowUpColor);
|
||||
PlotIndexSetInteger(1, PLOT_LINE_COLOR, ArrowDownColor);
|
||||
|
||||
//--- setting buffer values as EMPTY_VALUE
|
||||
ArrayInitialize(VTopBuffer, EMPTY_VALUE);
|
||||
ArrayInitialize(VBottomBuffer, EMPTY_VALUE);
|
||||
|
||||
//--- name for DataWindow and indicator subwindow label
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, "V-Pattern Detector ("+string(LookbackPeriod)+")");
|
||||
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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[])
|
||||
{
|
||||
//--- check for minimum bars required
|
||||
if(rates_total < LookbackPeriod)
|
||||
return(0);
|
||||
|
||||
//--- start calculation from bar determined by prev_calculated
|
||||
int start;
|
||||
if(prev_calculated == 0)
|
||||
start = LookbackPeriod;
|
||||
else
|
||||
start = prev_calculated - 1;
|
||||
|
||||
//--- main calculation loop
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
// Reset buffers
|
||||
VTopBuffer[i] = EMPTY_VALUE;
|
||||
VBottomBuffer[i] = EMPTY_VALUE;
|
||||
|
||||
// Find the lowest low in the lookback period
|
||||
int lowestBar = iLowest(NULL, 0, MODE_LOW, LookbackPeriod, i-LookbackPeriod+1);
|
||||
double lowestLow = low[lowestBar];
|
||||
|
||||
// Find the highest high before the lowest low
|
||||
int highBeforeLow = iHighest(NULL, 0, MODE_HIGH, lowestBar-(i-LookbackPeriod+1)+1, i-LookbackPeriod+1);
|
||||
double highestBefore = high[highBeforeLow];
|
||||
|
||||
// Find the highest high after the lowest low
|
||||
int highAfterLow = iHighest(NULL, 0, MODE_HIGH, i-lowestBar, lowestBar+1);
|
||||
double highestAfter = high[highAfterLow];
|
||||
|
||||
// Calculate percentage moves
|
||||
double declinePercent = (highestBefore - lowestLow) / highestBefore * 100;
|
||||
double risePercent = (highestAfter - lowestLow) / lowestLow * 100;
|
||||
|
||||
// Check if we have a V pattern
|
||||
if(declinePercent >= MinDeclinePercent && risePercent >= MinRisePercent)
|
||||
{
|
||||
// Check if the low is in the middle third of the lookback period
|
||||
int lowPosition = lowestBar - (i-LookbackPeriod+1);
|
||||
if(lowPosition > LookbackPeriod/3 && lowPosition < 2*LookbackPeriod/3)
|
||||
{
|
||||
// Mark the pattern on chart
|
||||
VTopBuffer[highBeforeLow] = high[highBeforeLow];
|
||||
VBottomBuffer[lowestBar] = low[lowestBar];
|
||||
VTopBuffer[highAfterLow] = high[highAfterLow];
|
||||
|
||||
// Show alert if enabled
|
||||
if(ShowAlerts && i == rates_total-1)
|
||||
{
|
||||
string alertText = StringFormat("V-Pattern detected! Decline: %.2f%%, Rise: %.2f%%",
|
||||
declinePercent, risePercent);
|
||||
Alert(alertText);
|
||||
Comment(alertText);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,770 @@
|
||||
// hasTB &&
|
||||
// tb.IsBullish() &&
|
||||
//
|
||||
// isPeakOverLast &&
|
||||
// isSarBullishStart
|
||||
// &&
|
||||
// isTrendBullishStart &&
|
||||
// isADXBullishStart &&
|
||||
// &&
|
||||
// isSBarBullishStart
|
||||
// &&
|
||||
// isHKSBarBullishStart
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// hasTB &&
|
||||
// tb.IsBearish() &&
|
||||
//
|
||||
// isValeUnderLast &&
|
||||
// isSarBearishStart
|
||||
// &&
|
||||
// isTrendBearishStart &&
|
||||
// isADXBearishStart &&
|
||||
// &&
|
||||
// isSBarBearishStart
|
||||
// &&
|
||||
// isHKSBarBearishStart
|
||||
//
|
||||
|
||||
|
||||
|
||||
bool DetectTriggerBlock(
|
||||
XCPOIDrawer *drawer,
|
||||
XCX121XCatbHelper *helper,
|
||||
XCBarAnalyser *barAnalyser,
|
||||
X121XCatbConditions &conditions,
|
||||
XTriggerBlock &tb,
|
||||
int barIndex = 0,
|
||||
int loopback = 10 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Args ...
|
||||
tb.Clean();
|
||||
conditions.Clean();
|
||||
barIndex = NormalizeInt(barIndex, 0);
|
||||
loopback = NormalizeInt(loopback, 0);
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result = helper != NULL;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Market Conditions ...
|
||||
result = helper.GetConditions(
|
||||
conditions,
|
||||
barIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
tb.Clean();
|
||||
conditions.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
int zIDX = 0;
|
||||
int cIDX = zIDX + 1;
|
||||
int pIDX = cIDX + 1;
|
||||
int p2IDX = pIDX + 1;
|
||||
int p3IDX = p2IDX + 1;
|
||||
int p4IDX = p3IDX + 1;
|
||||
|
||||
//
|
||||
// Checking Conditions ...
|
||||
|
||||
//
|
||||
// Detect Bar Verifications ...
|
||||
|
||||
//
|
||||
ENUM_X_DIRECTION iDir;
|
||||
|
||||
//
|
||||
// Rejected ...
|
||||
bool isRejected =
|
||||
barAnalyser
|
||||
.IsRejected(
|
||||
conditions.bars[cIDX],
|
||||
iDir //
|
||||
);
|
||||
bool isBullishRejected =
|
||||
isRejected &&
|
||||
IsBullish(iDir);
|
||||
bool isBearishRejected =
|
||||
isRejected &&
|
||||
IsBearish(iDir);
|
||||
|
||||
//
|
||||
// Engulfed ...
|
||||
bool isEngulfed =
|
||||
barAnalyser
|
||||
.IsEngulfed(
|
||||
conditions.bars[cIDX],
|
||||
iDir //
|
||||
);
|
||||
bool isBullishEngulfed =
|
||||
isEngulfed &&
|
||||
IsBullish(iDir);
|
||||
bool isBearishEngulfed =
|
||||
isEngulfed &&
|
||||
IsBearish(iDir);
|
||||
|
||||
//
|
||||
// Momentum ...
|
||||
bool isMomentum =
|
||||
barAnalyser
|
||||
.IsMomentum(
|
||||
conditions.bars[cIDX],
|
||||
iDir //
|
||||
);
|
||||
bool isBullishMomentum =
|
||||
isMomentum &&
|
||||
IsBullish(iDir);
|
||||
bool isBearishMomentum =
|
||||
isMomentum &&
|
||||
IsBearish(iDir);
|
||||
|
||||
//
|
||||
bool isBarBullishPressured =
|
||||
isBullishRejected ||
|
||||
isBullishEngulfed ||
|
||||
isBullishMomentum;
|
||||
|
||||
//
|
||||
bool isBarBearishPressured =
|
||||
isBearishRejected ||
|
||||
isBearishEngulfed ||
|
||||
isBearishMomentum;
|
||||
|
||||
//
|
||||
// Detect Indicator Base Start Directional Movement ...
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
|
||||
//
|
||||
bool isSarBullishStart =
|
||||
//
|
||||
(
|
||||
//
|
||||
// Current SAR is Directional ...
|
||||
conditions.isSarBullish &&
|
||||
//
|
||||
// Previous InDirectional Sar Exists ...
|
||||
helper.lastSarBearish.IsValid() &&
|
||||
//
|
||||
// Current Close is Over previous Sar ...
|
||||
conditions.bars[cIDX].close > helper.lastSarBearish.after &&
|
||||
//
|
||||
// Before Close is not Over previous Sar ...
|
||||
conditions.bars[pIDX].close <= helper.lastSarBearish.after
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSarBearishStart =
|
||||
//
|
||||
(
|
||||
//
|
||||
// Current SAR is Directional ...
|
||||
conditions.isSarBearish &&
|
||||
//
|
||||
// Previous InDirectional Sar Exists ...
|
||||
helper.lastSarBullish.IsValid() &&
|
||||
//
|
||||
// Current Close is Under previous ...
|
||||
conditions.bars[cIDX].close < helper.lastSarBullish.after &&
|
||||
//
|
||||
// Before Close is not Under previous ...
|
||||
conditions.bars[pIDX].close >= helper.lastSarBullish.after
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// TREND ...
|
||||
|
||||
//
|
||||
bool isTrendBullishStart =
|
||||
//
|
||||
(
|
||||
//
|
||||
// Current Trend is Directional ...
|
||||
conditions.isTrendBullish &&
|
||||
//
|
||||
// Previous InDirectiona; Trend Exists ...
|
||||
helper.lastTrendBearish.IsValid() &&
|
||||
//
|
||||
// Current Close is Over previous ...
|
||||
conditions.bars[cIDX].close > helper.lastTrendBearish.after &&
|
||||
//
|
||||
// Before close is not Over previous ...
|
||||
conditions.bars[pIDX].close <= helper.lastTrendBearish.after
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isTrendBearishStart =
|
||||
//
|
||||
(
|
||||
//
|
||||
// Current Trend is Directional ...
|
||||
conditions.isTrendBearish &&
|
||||
//
|
||||
// Previous InDirectiona; Trend Exists ...
|
||||
helper.lastTrendBullish.IsValid() &&
|
||||
//
|
||||
// Current Close is Under previous ...
|
||||
conditions.bars[cIDX].close < helper.lastTrendBullish.after &&
|
||||
//
|
||||
// Before close is not Under previous ...
|
||||
conditions.bars[pIDX].close >= helper.lastTrendBullish.after
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// ADX ...
|
||||
|
||||
//
|
||||
bool isADXBullishStart =
|
||||
//
|
||||
(
|
||||
//
|
||||
// ADX Value is Switched to Strong ...
|
||||
conditions.adxBuffer[cIDX] > conditions.adxThreshold &&
|
||||
conditions.adxBuffer[pIDX] <= conditions.adxThreshold &&
|
||||
//
|
||||
// ADX must Up ...
|
||||
conditions.adxBuffer[cIDX] > conditions.adxBuffer[pIDX] &&
|
||||
//
|
||||
// ADX +DI is Bigger than -DI ...
|
||||
conditions.adxpBuffer[cIDX] > conditions.adxnBuffer[cIDX] &&
|
||||
//
|
||||
// ADX +DI is Up ...
|
||||
conditions.adxpBuffer[cIDX] > conditions.adxpBuffer[pIDX]
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isADXBearishStart =
|
||||
//
|
||||
(
|
||||
//
|
||||
// ADX Value is Switched to Strong ...
|
||||
conditions.adxBuffer[cIDX] > conditions.adxThreshold &&
|
||||
conditions.adxBuffer[pIDX] <= conditions.adxThreshold &&
|
||||
//
|
||||
// ADX must Up ...
|
||||
conditions.adxBuffer[cIDX] > conditions.adxBuffer[pIDX] &&
|
||||
//
|
||||
// ADX -DI is Bigger than +DI ...
|
||||
conditions.adxnBuffer[cIDX] > conditions.adxpBuffer[cIDX] &&
|
||||
//
|
||||
// ADX -DI is Up ...
|
||||
conditions.adxnBuffer[cIDX] > conditions.adxnBuffer[pIDX]
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// DELTA ...
|
||||
|
||||
//
|
||||
bool isDeltaBullishStart =
|
||||
//
|
||||
// Check State ...
|
||||
(
|
||||
//
|
||||
// Delta is Up ...
|
||||
conditions.deltaBuffer[cIDX] > conditions.deltaBuffer[pIDX] &&
|
||||
//
|
||||
// Delta Signal is Up ...
|
||||
conditions.deltaSignalBuffer[cIDX] > conditions.deltaSignalBuffer[pIDX] &&
|
||||
//
|
||||
// Delta Crossed Over Delta Signal ...
|
||||
conditions.deltaBuffer[cIDX] > conditions.deltaSignalBuffer[cIDX]
|
||||
//
|
||||
)
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Check Last InDirectional Exists ...
|
||||
helper.lastDeltaBearish.IsValid() &&
|
||||
//
|
||||
// Current Close is Over last ...
|
||||
conditions.bars[cIDX].close > helper.lastDeltaBearish.after &&
|
||||
//
|
||||
// Before Close is not Over last ...
|
||||
conditions.bars[pIDX].close <= helper.lastDeltaBearish.after
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isDeltaBearishStart =
|
||||
//
|
||||
// Check State ...
|
||||
(
|
||||
//
|
||||
// Delta is Down ...
|
||||
conditions.deltaBuffer[cIDX] < conditions.deltaBuffer[pIDX] &&
|
||||
//
|
||||
// Delta Signal is Down ...
|
||||
conditions.deltaSignalBuffer[cIDX] < conditions.deltaSignalBuffer[pIDX] &&
|
||||
//
|
||||
// Delta Crossed Under Delta Signal ...
|
||||
conditions.deltaBuffer[cIDX] < conditions.deltaSignalBuffer[cIDX]
|
||||
//
|
||||
)
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Check Last InDirectional Exists ...
|
||||
helper.lastDeltaBullish.IsValid() &&
|
||||
//
|
||||
// Current Close is Under last ...
|
||||
conditions.bars[cIDX].close < helper.lastDeltaBullish.after &&
|
||||
//
|
||||
// Before Close is not Under last ...
|
||||
conditions.bars[pIDX].close >= helper.lastDeltaBullish.after
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// VOLUME ...
|
||||
|
||||
//
|
||||
bool isVolumeBullishStart =
|
||||
//
|
||||
(
|
||||
//
|
||||
//
|
||||
// Volume is Up ...
|
||||
conditions.bullishVolumeBuffer[1] > conditions.bullishVolumeBuffer[2] &&
|
||||
//
|
||||
// Volume Signal is Up ...
|
||||
conditions.bullishVolumeSignalBuffer[1] > conditions.bullishVolumeSignalBuffer[2] &&
|
||||
//
|
||||
// Volume Signals Crossed Over ...
|
||||
conditions.bullishVolumeSignalBuffer[1] > conditions.bearishVolumeSignalBuffer[1]
|
||||
//
|
||||
)
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Check Last InDirectional Exists ...
|
||||
helper.lastVolumeBearish.IsValid() &&
|
||||
//
|
||||
// Current Close is Over last ...
|
||||
conditions.bars[cIDX].close > helper.lastVolumeBearish.after &&
|
||||
//
|
||||
// Before Close is not Over last ...
|
||||
conditions.bars[pIDX].close <= helper.lastVolumeBearish.after
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isVolumeBearishStart =
|
||||
//
|
||||
(
|
||||
//
|
||||
//
|
||||
// Volume is Up ...
|
||||
conditions.bearishVolumeBuffer[1] > conditions.bearishVolumeBuffer[2] &&
|
||||
//
|
||||
// Volume Signal is Up ...
|
||||
conditions.bearishVolumeSignalBuffer[1] > conditions.bearishVolumeSignalBuffer[2] &&
|
||||
//
|
||||
// Volume Signals Crossed Over ...
|
||||
conditions.bearishVolumeSignalBuffer[1] > conditions.bullishVolumeSignalBuffer[1]
|
||||
//
|
||||
)
|
||||
//
|
||||
&&
|
||||
//
|
||||
// Check Last InDirectional Exists ...
|
||||
helper.lastVolumeBullish.IsValid() &&
|
||||
//
|
||||
// Current Close is Over last ...
|
||||
conditions.bars[cIDX].close < helper.lastVolumeBullish.after &&
|
||||
//
|
||||
// Before Close is not Over last ...
|
||||
conditions.bars[pIDX].close >= helper.lastVolumeBullish.after
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// SIGNAL Bar ...
|
||||
|
||||
//
|
||||
bool isSBarBullishStart =
|
||||
//
|
||||
(
|
||||
//
|
||||
// Check Direction ...
|
||||
conditions.isSBarBullish &&
|
||||
//
|
||||
// Previous InDirectional Exists ...
|
||||
helper.lastSignalBarBearish.IsValid() &&
|
||||
//
|
||||
// Current Signal Bar close over prev ...
|
||||
conditions.sBarCloseBuffer[cIDX] > helper.lastSignalBarBearish.after &&
|
||||
//
|
||||
// Prev Signal Bar not close over prev ...
|
||||
conditions.sBarCloseBuffer[pIDX] <= helper.lastSignalBarBearish.after
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSBarBearishStart =
|
||||
//
|
||||
(
|
||||
//
|
||||
// Check Direction ...
|
||||
conditions.isSBarBearish &&
|
||||
//
|
||||
// Previous InDirectional Exists ...
|
||||
helper.lastSignalBarBullish.IsValid() &&
|
||||
//
|
||||
// Current Signal Bar close over prev ...
|
||||
conditions.sBarCloseBuffer[cIDX] < helper.lastSignalBarBullish.after &&
|
||||
//
|
||||
// Prev Signal Bar not close over prev ...
|
||||
conditions.sBarCloseBuffer[pIDX] >= helper.lastSignalBarBullish.after
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// HKSIGNAL Bar ...
|
||||
|
||||
//
|
||||
bool isHKSBarBullishStart =
|
||||
//
|
||||
(
|
||||
//
|
||||
// Check Direction ...
|
||||
conditions.isHKSBarBullish &&
|
||||
//
|
||||
// Previous InDirectional Exists ...
|
||||
helper.lastHKSignalBarBearish.IsValid() &&
|
||||
//
|
||||
// Current Signal Bar close over prev ...
|
||||
conditions.hkSBarCloseBuffer[cIDX] > helper.lastHKSignalBarBearish.after &&
|
||||
//
|
||||
// Prev Signal Bar not close over prev ...
|
||||
conditions.hkSBarCloseBuffer[pIDX] <= helper.lastHKSignalBarBearish.after
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isHKSBarBearishStart =
|
||||
//
|
||||
(
|
||||
//
|
||||
// Check Direction ...
|
||||
conditions.isHKSBarBearish &&
|
||||
//
|
||||
// Previous InDirectional Exists ...
|
||||
helper.lastHKSignalBarBullish.IsValid() &&
|
||||
//
|
||||
// Current Signal Bar close over prev ...
|
||||
conditions.hkSBarCloseBuffer[cIDX] < helper.lastHKSignalBarBullish.after &&
|
||||
//
|
||||
// Prev Signal Bar not close over prev ...
|
||||
conditions.hkSBarCloseBuffer[pIDX] >= helper.lastHKSignalBarBullish.after
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Check for Vale and Peak ...
|
||||
|
||||
//
|
||||
bool isPeakOverLast =
|
||||
//
|
||||
(conditions.peakBuffer[cIDX] > conditions.peakBuffer[pIDX] &&
|
||||
conditions.peakBuffer[pIDX] <= conditions.peakBuffer[p2IDX] &&
|
||||
conditions.bars[cIDX].close > conditions.peakBuffer[pIDX])
|
||||
//
|
||||
||
|
||||
//
|
||||
(conditions.peakBuffer[pIDX] > conditions.peakBuffer[p2IDX] &&
|
||||
conditions.peakBuffer[p2IDX] <= conditions.peakBuffer[p3IDX] &&
|
||||
conditions.bars[pIDX].close > conditions.peakBuffer[p2IDX])
|
||||
//
|
||||
||
|
||||
//
|
||||
(conditions.peakBuffer[p2IDX] > conditions.peakBuffer[p3IDX] &&
|
||||
conditions.peakBuffer[p3IDX] <= conditions.peakBuffer[p4IDX] &&
|
||||
conditions.bars[p2IDX].close > conditions.peakBuffer[p3IDX])
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isValeUnderLast =
|
||||
//
|
||||
(conditions.valeBuffer[cIDX] < conditions.valeBuffer[pIDX] &&
|
||||
conditions.valeBuffer[pIDX] >= conditions.valeBuffer[p2IDX] &&
|
||||
conditions.bars[cIDX].close < conditions.valeBuffer[pIDX])
|
||||
//
|
||||
||
|
||||
//
|
||||
(conditions.valeBuffer[pIDX] < conditions.valeBuffer[p2IDX] &&
|
||||
conditions.valeBuffer[p2IDX] >= conditions.valeBuffer[p3IDX] &&
|
||||
conditions.bars[pIDX].close < conditions.valeBuffer[p2IDX])
|
||||
//
|
||||
||
|
||||
//
|
||||
(conditions.valeBuffer[p2IDX] < conditions.valeBuffer[p3IDX] &&
|
||||
conditions.valeBuffer[p3IDX] >= conditions.valeBuffer[p4IDX] &&
|
||||
conditions.bars[p2IDX].close < conditions.valeBuffer[p3IDX])
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// if (isValeUnderLast)
|
||||
// {
|
||||
// Print("SALAM");
|
||||
// }
|
||||
|
||||
//
|
||||
// Try to Summarize Conditions ...
|
||||
|
||||
//
|
||||
bool isBullishPassed =
|
||||
//
|
||||
(isPeakOverLast &&
|
||||
isDeltaBullishStart &&
|
||||
isVolumeBullishStart &&
|
||||
isBarBullishPressured)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isBearishPassed =
|
||||
(isValeUnderLast &&
|
||||
isDeltaBearishStart &&
|
||||
isVolumeBearishStart &&
|
||||
isBarBearishPressured)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Try to Detect Trigger Block ...
|
||||
bool hasTB = false;
|
||||
int tbLoopback = 100;
|
||||
X121XCatbInputs mInputs = helper.GetInputs();
|
||||
for (int i = barIndex; i < barIndex + tbLoopback; i++)
|
||||
{
|
||||
//
|
||||
// Update Helper ...
|
||||
helper.Update(i);
|
||||
|
||||
//
|
||||
// Check TB ...
|
||||
hasTB = DetectTriggerBlock(
|
||||
//
|
||||
conditions.symbol,
|
||||
conditions.period,
|
||||
//
|
||||
tb,
|
||||
//
|
||||
drawer,
|
||||
barAnalyser,
|
||||
//
|
||||
// Required Buffers ...
|
||||
helper.atrBuffer,
|
||||
helper.rsiBuffer,
|
||||
helper.adxBuffer,
|
||||
helper.adxpBuffer,
|
||||
helper.adxnBuffer,
|
||||
helper.peakBuffer,
|
||||
helper.valeBuffer,
|
||||
helper.deltaBuffer,
|
||||
helper.sarBuffer,
|
||||
helper.sarStateBuffer,
|
||||
helper.trendBuffer,
|
||||
helper.trendStateBuffer,
|
||||
helper.atrUpperBuffer,
|
||||
helper.atrLowerBuffer,
|
||||
helper.sBarOpenBuffer,
|
||||
helper.sBarCloseBuffer,
|
||||
helper.hkSBarOpenBuffer,
|
||||
helper.hkSBarCloseBuffer,
|
||||
helper.peakGoldenBuffer,
|
||||
helper.valeGoldenBuffer,
|
||||
helper.deltaSignalBuffer,
|
||||
helper.bullishVolumeSignalBuffer,
|
||||
helper.bearishVolumeSignalBuffer,
|
||||
//
|
||||
i + 1,
|
||||
//
|
||||
// Signalling ...
|
||||
mInputs.signalR2R,
|
||||
mInputs.slAtrMultiplier,
|
||||
//
|
||||
// Configs ...
|
||||
mInputs.rsiOBLevel,
|
||||
mInputs.rsiOSLevel,
|
||||
mInputs.adxThreshold,
|
||||
//
|
||||
// Validators ...
|
||||
mInputs.forceObBarType,
|
||||
mInputs.forceOBFVGBarType,
|
||||
mInputs.forceHasSwing,
|
||||
mInputs.forceHasFLiquidity,
|
||||
mInputs.forceHasRLiquidity,
|
||||
mInputs.validateGapSequence,
|
||||
mInputs.validateBlockEdgeBreakout,
|
||||
//
|
||||
// Filters ...
|
||||
mInputs.filterBasedOnPV,
|
||||
mInputs.filterBasedOnSar,
|
||||
mInputs.filterBasedOnRSI,
|
||||
mInputs.filterBasedOnADX,
|
||||
mInputs.filterBasedOnATR,
|
||||
mInputs.filterBasedOnTrend,
|
||||
mInputs.filterBasedOnDelta,
|
||||
mInputs.filterBasedOnVolume,
|
||||
mInputs.filterBasedOnSignalBar,
|
||||
mInputs.filterBasedOnHKSignalBar //
|
||||
);
|
||||
|
||||
//
|
||||
// Checking Trigger Block Validation ...
|
||||
hasTB =
|
||||
//
|
||||
hasTB &&
|
||||
//
|
||||
(
|
||||
//
|
||||
(isBullishPassed &&
|
||||
tb.IsBullish())
|
||||
//
|
||||
||
|
||||
//
|
||||
(isBearishPassed &&
|
||||
tb.IsBearish())
|
||||
//
|
||||
);
|
||||
if (hasTB)
|
||||
{
|
||||
//
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
tb.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// isBullishPassed = false;
|
||||
// isBearishPassed = false;
|
||||
|
||||
//
|
||||
// Draw Line for Detect Conditions States on Chart ...
|
||||
if (hasTB && (isBullishPassed ||
|
||||
isBearishPassed))
|
||||
{
|
||||
//
|
||||
color iColor = isBullishPassed
|
||||
? clrAqua
|
||||
: clrMagenta;
|
||||
|
||||
//
|
||||
datetime iTime = conditions.bars[cIDX].time;
|
||||
|
||||
//
|
||||
string iName = "VL_" + ToFormatString(iTime);
|
||||
|
||||
//
|
||||
long chartID = drawer.ChartIdentification();
|
||||
int subWindow = drawer.SubWindowIdentification();
|
||||
|
||||
//
|
||||
CChartObjectVLine *iObj;
|
||||
iObj = new CChartObjectVLine();
|
||||
bool isDrawn = iObj.Create(
|
||||
chartID,
|
||||
iName,
|
||||
subWindow,
|
||||
iTime //
|
||||
);
|
||||
if (isDrawn)
|
||||
{
|
||||
//
|
||||
iObj.Color(iColor);
|
||||
}
|
||||
|
||||
//
|
||||
CArrayObj *tbObjects = new CArrayObj();
|
||||
DrawTriggerBlock(
|
||||
tb,
|
||||
drawer,
|
||||
tbObjects,
|
||||
conditions.bars[0].time //
|
||||
);
|
||||
|
||||
//
|
||||
tb.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Summarizing result ...
|
||||
|
||||
//
|
||||
result = (isBullishPassed ||
|
||||
isBearishPassed);
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
tb.Clean();
|
||||
conditions.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// has = DetectTriggerBlock(
|
||||
// eaDrawer,
|
||||
// eaHelper,
|
||||
// eaBarAnalyser,
|
||||
// iConditions,
|
||||
// iTB,
|
||||
// barIndex,
|
||||
// 10 //
|
||||
// );
|
||||
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,316 @@
|
||||
//
|
||||
// Market ...
|
||||
ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Short Period
|
||||
ENUM_TIMEFRAMES scPeriod = NULL; // Short Period
|
||||
ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Medium Period
|
||||
ENUM_TIMEFRAMES mcPeriod = NULL; // Medium Period
|
||||
ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Long Period
|
||||
ENUM_TIMEFRAMES lcPeriod = NULL; // Long Period
|
||||
ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Hind Period
|
||||
ENUM_TIMEFRAMES hcPeriod = NULL; // Hind Period
|
||||
ENUM_X_MARKET_CYCLES appliedCycle = X_MARKET_CYCLE_HIND; // Applied Cycle
|
||||
|
||||
//
|
||||
// Signal ...
|
||||
int signalR2R = 4; // Risk Reward Ratio
|
||||
bool drawSignals = true; // Draw Signal
|
||||
double slAtrMultiplier = 1.0; // ATR Multiplier for SL
|
||||
|
||||
//
|
||||
// Validating ...
|
||||
bool forceHasSwing = false; // Force Blocks to Have Swing
|
||||
bool forceObBarType = false; // Force Block Has Reversal Bar
|
||||
bool forceOBFVGBarType = false; // Force FVG Has Same Bars
|
||||
bool forceHasFLiquidity = false; // Force Blocks to Have Following Liquidity
|
||||
bool forceHasRLiquidity = false; // Force Blocks to Have Reversal Liquidity
|
||||
bool validateGapSequence = false; // Validate Block's Gap Sequence
|
||||
bool validateBlockEdgeBreakout = false; // Validate Block's Edge Breakout
|
||||
|
||||
//
|
||||
// Filtering ...
|
||||
bool filterBasedOnPV = false; // Filter Based on Peak and Vale
|
||||
bool filterBasedOnSar = false; // Filter Based on Sar
|
||||
bool filterBasedOnRSI = false; // Filter Based on RSI
|
||||
bool filterBasedOnADX = false; // Filter Based on ADX
|
||||
bool filterBasedOnATR = false; // Filter Based on ATR
|
||||
bool filterBasedOnTrend = false; // Filter Based on Trend
|
||||
bool filterBasedOnDelta = false; // Filter Based on Delta
|
||||
bool filterBasedOnVolume = false; // Filter Based on Volume
|
||||
bool filterBasedOnSignalBar = false; // Filter Based on Signal Bar
|
||||
bool filterBasedOnHKSignalBar = false; // Filter Based on Hiken Ashi Signal Bar
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
string mAlertPrefix = ""; // Alert Prefix
|
||||
bool _logAlerts = true; // Log Alerts
|
||||
bool _pushAlerts = false; // Push Alerts
|
||||
bool _mailAlerts = false; // Mail Alerts
|
||||
bool _terminalAlerts = true; // Terminal Alerts
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showBars = true; // Show Bars
|
||||
bool showPV = false; // Show PV
|
||||
bool showPVGolden = false; // Show PV Golden
|
||||
bool showSar = false; // Show Sar
|
||||
bool showTrend = false; // Show Trend
|
||||
bool showATRBand = false; // Show ATR Band
|
||||
bool showTrendBars = false; // Show Trend Bars
|
||||
bool showSignalBars = false; // Show Signal Bars
|
||||
bool showHKSignalBars = false; // Show Hiken Ashi Signal Bars
|
||||
|
||||
//
|
||||
int startCalculationForLastBars = 1500; // Calculate Last n Bars
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
// Market ...
|
||||
ENUM_X_PERIOD_METHOD scMethod; // How to Find Short Period
|
||||
ENUM_TIMEFRAMES scPeriod; // Short Period
|
||||
ENUM_X_PERIOD_METHOD mcMethod; // How to Find Medium Period
|
||||
ENUM_TIMEFRAMES mcPeriod; // Medium Period
|
||||
ENUM_X_PERIOD_METHOD lcMethod; // How to Find Long Period
|
||||
ENUM_TIMEFRAMES lcPeriod; // Long Period
|
||||
ENUM_X_PERIOD_METHOD hcMethod; // How to Find Hind Period
|
||||
ENUM_TIMEFRAMES hcPeriod; // Hind Period
|
||||
ENUM_X_MARKET_CYCLES appliedCycle; // Applied Cycle
|
||||
|
||||
//
|
||||
// Signal ...
|
||||
int signalR2R; // Risk Reward Ratio
|
||||
bool drawSignals; // Draw Signal
|
||||
double slAtrMultiplier; // ATR Multiplier for SL
|
||||
|
||||
//
|
||||
// Validating ...
|
||||
bool forceHasSwing; // Force Blocks to Have Swing
|
||||
bool forceObBarType; // Force Block Has Reversal Bar
|
||||
bool forceOBFVGBarType; // Force FVG Has Same Bars
|
||||
bool forceHasFLiquidity; // Force Blocks to Have Following Liquidity
|
||||
bool forceHasRLiquidity; // Force Blocks to Have Reversal Liquidity
|
||||
bool validateGapSequence; // Validate Block's Gap Sequence
|
||||
bool validateBlockEdgeBreakout; // Validate Block's Edge Breakout
|
||||
|
||||
//
|
||||
// Filtering ...
|
||||
bool filterBasedOnPV; // Filter Based on Peak and Vale
|
||||
bool filterBasedOnSar; // Filter Based on Sar
|
||||
bool filterBasedOnRSI; // Filter Based on RSI
|
||||
bool filterBasedOnADX; // Filter Based on ADX
|
||||
bool filterBasedOnATR; // Filter Based on ATR
|
||||
bool filterBasedOnTrend; // Filter Based on Trend
|
||||
bool filterBasedOnDelta; // Filter Based on Delta
|
||||
bool filterBasedOnVolume; // Filter Based on Volume
|
||||
bool filterBasedOnSignalBar; // Filter Based on Signal Bar
|
||||
bool filterBasedOnHKSignalBar; // Filter Based on Hiken Ashi Signal Bar
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
string alertPrefix; // Alert Prefix
|
||||
bool logAlerts; // Log Alerts
|
||||
bool pushAlerts; // Push Alerts
|
||||
bool mailAlerts; // Mail Alerts
|
||||
bool terminalAlerts; // Terminal Alerts
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showBars; // Show Bars
|
||||
bool showPV; // Show PV
|
||||
bool showPVGolden; // Show PV Golden
|
||||
bool showSar; // Show Sar
|
||||
bool showTrend; // Show Trend
|
||||
bool showATRBand; // Show ATR Band
|
||||
bool showTrendBars; // Show Trend Bars
|
||||
bool showSignalBars; // Show Signal Bars
|
||||
bool showHKSignalBars; // Show Hiken Ashi Signal Bars
|
||||
|
||||
//
|
||||
int startCalculationForLastBars; // Calculate Last n Bars
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
// Market ...
|
||||
scMethod = X_PERIOD_AUTO; // How to Find Short Period
|
||||
scPeriod = NULL; // Short Period
|
||||
mcMethod = X_PERIOD_AUTO; // How to Find Medium Period
|
||||
mcPeriod = NULL; // Medium Period
|
||||
lcMethod = X_PERIOD_AUTO; // How to Find Long Period
|
||||
lcPeriod = NULL; // Long Period
|
||||
hcMethod = X_PERIOD_AUTO; // How to Find Hind Period
|
||||
hcPeriod = NULL; // Hind Period
|
||||
appliedCycle = X_MARKET_CYCLE_HIND; // Applied Cycle
|
||||
|
||||
//
|
||||
// Signal ...
|
||||
signalR2R = 4; // Risk Reward Ratio
|
||||
drawSignals = true; // Draw Signal
|
||||
slAtrMultiplier = 1.0; // ATR Multiplier for SL
|
||||
|
||||
//
|
||||
// Validating ...
|
||||
forceHasSwing = false; // Force Blocks to Have Swing
|
||||
forceObBarType = false; // Force Block Has Reversal Bar
|
||||
forceOBFVGBarType = false; // Force FVG Has Same Bars
|
||||
forceHasFLiquidity = false; // Force Blocks to Have Following Liquidity
|
||||
forceHasRLiquidity = false; // Force Blocks to Have Reversal Liquidity
|
||||
validateGapSequence = false; // Validate Block's Gap Sequence
|
||||
validateBlockEdgeBreakout = false; // Validate Block's Edge Breakout
|
||||
|
||||
//
|
||||
// Filtering ...
|
||||
filterBasedOnPV = false; // Filter Based on Peak and Vale
|
||||
filterBasedOnSar = false; // Filter Based on Sar
|
||||
filterBasedOnRSI = false; // Filter Based on RSI
|
||||
filterBasedOnADX = false; // Filter Based on ADX
|
||||
filterBasedOnATR = false; // Filter Based on ATR
|
||||
filterBasedOnTrend = false; // Filter Based on Trend
|
||||
filterBasedOnDelta = false; // Filter Based on Delta
|
||||
filterBasedOnVolume = false; // Filter Based on Volume
|
||||
filterBasedOnSignalBar = false; // Filter Based on Signal Bar
|
||||
filterBasedOnHKSignalBar = false; // Filter Based on Hiken Ashi Signal Bar
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
mAlertPrefix = ""; // Alert Prefix
|
||||
_logAlerts = true; // Log Alerts
|
||||
_pushAlerts = false; // Push Alerts
|
||||
_mailAlerts = false; // Mail Alerts
|
||||
_terminalAlerts = true; // Terminal Alerts
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
showBars = true; // Show Bars
|
||||
showPV = false; // Show PV
|
||||
showPVGolden = false; // Show PV Golden
|
||||
showSar = false; // Show Sar
|
||||
showTrend = false; // Show Trend
|
||||
showATRBand = false; // Show ATR Band
|
||||
showTrendBars = false; // Show Trend Bars
|
||||
showSignalBars = false; // Show Signal Bars
|
||||
showHKSignalBars = false; // Show Hiken Ashi Signal Bars
|
||||
|
||||
//
|
||||
startCalculationForLastBars = 1500; // Calculate Last n Bars
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
X121_XCATB_SAR_LINE
|
||||
sarBuffer
|
||||
|
||||
X121_XCATB_SAR_STATE_LINE
|
||||
sarStateBuffer
|
||||
|
||||
X121_XCATB_PEAK_LINE
|
||||
peakBuffer
|
||||
|
||||
X121_XCATB_VALE_LINE
|
||||
valeBuffer
|
||||
|
||||
X121_XCATB_PEAK_GOLDEN_LINE
|
||||
peakGoldenBuffer
|
||||
|
||||
X121_XCATB_VALE_GOLDEN_LINE
|
||||
valeGoldenBuffer
|
||||
|
||||
X121_XCATB_ATR_BAND_UPPER_LINE
|
||||
atrUpperBuffer
|
||||
|
||||
X121_XCATB_ATR_BAND_LOWER_LINE
|
||||
atrLowerBuffer
|
||||
|
||||
X121_XCATB_TREND_LINE
|
||||
trendBuffer
|
||||
|
||||
X121_XCATB_TREND_STATE_LINE
|
||||
trendStateBuffer
|
||||
|
||||
X121_XCATB_SBAR_O_LINE
|
||||
sBarOpenSBuffer
|
||||
|
||||
X121_XCATB_SBAR_C_LINE
|
||||
sBarCloseBuffer
|
||||
|
||||
X121_XCATB_HK_SBAR_O_LINE
|
||||
hkSBarOpenBuffer
|
||||
|
||||
X121_XCATB_HK_SBAR_C_LINE
|
||||
hkSBarCloseBuffer
|
||||
|
||||
X121_XCATB_S_HH_LINE
|
||||
sHHBuffer
|
||||
|
||||
X121_XCATB_S_LL_LINE
|
||||
sLLBuffer
|
||||
|
||||
X121_XCATB_M_HH_LINE
|
||||
mHHBuffer
|
||||
|
||||
X121_XCATB_M_LL_LINE
|
||||
mLLBuffer
|
||||
|
||||
X121_XCATB_L_HH_LINE
|
||||
lHHBuffer
|
||||
|
||||
X121_XCATB_L_LL_LINE
|
||||
lLLBuffer
|
||||
|
||||
X121_XCATB_H_HH_LINE
|
||||
hHHBuffer
|
||||
|
||||
X121_XCATB_H_LL_LINE
|
||||
hLLBuffer
|
||||
|
||||
X121_XCATB_RSI_LINE
|
||||
rsiBuffer
|
||||
|
||||
X121_XCATB_ADX_LINE
|
||||
adxBuffer
|
||||
|
||||
X121_XCATB_ADXP_LINE
|
||||
adxpBuffer
|
||||
|
||||
X121_XCATB_ADXN_LINE
|
||||
adxnBuffer
|
||||
|
||||
X121_XCATB_DELTA_LINE
|
||||
deltaBuffer
|
||||
|
||||
X121_XCATB_DELTA_SIGNAL_LINE
|
||||
deltaSignalBuffer
|
||||
|
||||
X121_XCATB_VOLUME_BULLISH_LINE
|
||||
bullishVolumeBuffer
|
||||
|
||||
X121_XCATB_VOLUME_BEARISH_LINE
|
||||
bearishVolumeBuffer
|
||||
|
||||
X121_XCATB_VOLUME_VOLUME_BULLISH_SIGNAL_LINE
|
||||
bullishVolumeSignalBuffer
|
||||
|
||||
X121_XCATB_VOLUME_VOLUME_BEARISH_SIGNAL_LINE
|
||||
bearishVolumeSignalBuffer
|
||||
|
||||
X121_XCATB_ATR_LINE
|
||||
atrBuffer
|
||||
|
||||
X121_XCATB_ATR_BAND_RAW_UPPER_LINE
|
||||
atrUpperBuffer
|
||||
|
||||
X121_XCATB_ATR_BAND_RAW_LOWER_LINE
|
||||
atrLowerBuffer
|
||||
|
||||
X121_XCATB_HK_BAR_O_LINE
|
||||
hkOpenBuffer
|
||||
|
||||
X121_XCATB_HK_BAR_H_LINE
|
||||
hkHighBuffer
|
||||
|
||||
X121_XCATB_HK_BAR_L_LINE
|
||||
hkLowBuffer
|
||||
|
||||
X121_XCATB_HK_BAR_C_LINE
|
||||
hkCloseBuffer
|
||||
|
||||
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>
|
||||
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,259 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCX121XCCHelper
|
||||
// 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 X121XCCInputs
|
||||
{
|
||||
//
|
||||
// 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) ...
|
||||
X121XCCInputs()
|
||||
{
|
||||
//
|
||||
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;
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
mode = CHART_CANDLES;
|
||||
|
||||
//
|
||||
upColor = clrLime;
|
||||
downColor = clrRed;
|
||||
lineColor = clrLime;
|
||||
bearishColor = clrRed;
|
||||
bullishColor = clrLime;
|
||||
volumesColor = clrGreen;
|
||||
//
|
||||
showCandles = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Hide all Visible Buffers ...
|
||||
void Hide()
|
||||
{
|
||||
showCandles = false;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 XCX121XCCHelper : public XCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XCX121XCCHelper()
|
||||
: XCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCX121XCCHelper()
|
||||
{
|
||||
mInputs.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
X121XCCInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xcc",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Chart Style ...
|
||||
"",
|
||||
mInputs.mode, // Mode
|
||||
mInputs.upColor, // Up Color
|
||||
mInputs.downColor, // Down Color
|
||||
mInputs.lineColor, // Line mode and Doji candlestick Color
|
||||
mInputs.bullishColor, // Bearish Color
|
||||
mInputs.bearishColor, // Bullish Color
|
||||
mInputs.volumesColor, // Volumes Color
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
mInputs.showCandles // Show Candles
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
X121XCCInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
X121XCCInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
X121XCCInputs mInputs; // Inputs ...
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
@@ -0,0 +1,241 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCX121XCTHelper
|
||||
// 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 X121XCTInputs
|
||||
{
|
||||
//
|
||||
// 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) ...
|
||||
X121XCTInputs()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
font = NULL;
|
||||
fontSize = 15;
|
||||
clr = CLR_NONE;
|
||||
corner = CORNER_RIGHT_LOWER;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
showCandleTime = false;
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
font = "Arial";
|
||||
fontSize = 15;
|
||||
clr = clrYellow;
|
||||
corner = CORNER_RIGHT_LOWER;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
showCandleTime = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Hide all Visible Buffers ...
|
||||
void Hide()
|
||||
{
|
||||
showCandleTime = false;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 XCX121XCTHelper : public XCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XCX121XCTHelper()
|
||||
: XCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCX121XCTHelper()
|
||||
{
|
||||
mInputs.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
X121XCTInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.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 ...
|
||||
|
||||
//
|
||||
X121XCTInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
X121XCTInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
X121XCTInputs mInputs; // Inputs ...
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,788 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 X3MA
|
||||
// Description: X3MA ...
|
||||
//
|
||||
//
|
||||
// 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 X3MA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121 X3MA"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Fast ...
|
||||
input group "Fast";
|
||||
input int fastLength = 6; // Length
|
||||
input ENUM_MA_METHOD fastMethod = MODE_SMA; // Method
|
||||
input ENUM_APPLIED_PRICE fastAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// Medium ...
|
||||
input group "Medium";
|
||||
input int mediumLength = 21; // Length
|
||||
input ENUM_MA_METHOD mediumMethod = MODE_SMA; // Method
|
||||
input ENUM_APPLIED_PRICE mediumAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// Slow ...
|
||||
input group "Slow";
|
||||
input int slowLength = 34; // Length
|
||||
input ENUM_MA_METHOD slowMethod = MODE_SMA; // Method
|
||||
input ENUM_APPLIED_PRICE slowAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
|
||||
//
|
||||
input bool applyColor = false;
|
||||
|
||||
//
|
||||
input bool showFast = true; // Show Fast
|
||||
input bool showMedium = true; // Show Medium
|
||||
input bool showSlow = true; // Show Slow
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#define bullishState 1
|
||||
#define neuturalState 0
|
||||
#define bearishState -1
|
||||
|
||||
//
|
||||
#define emptyValue 0.0
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 9
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
|
||||
//
|
||||
#define fastBufferIndex 0
|
||||
double fastBuffer[];
|
||||
|
||||
//
|
||||
#define fastColorBufferIndex 1
|
||||
double fastColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121 X3MA Fast"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 CLR_NONE, clrYellow, clrChocolate, clrGray
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 2
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
|
||||
//
|
||||
#define mediumBufferIndex 2
|
||||
double mediumBuffer[];
|
||||
|
||||
//
|
||||
#define mediumColorBufferIndex 3
|
||||
double mediumColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121 X3MA Medium"
|
||||
#property indicator_type2 DRAW_COLOR_LINE
|
||||
#property indicator_color2 CLR_NONE, clrAqua, clrMagenta, clrGray
|
||||
#property indicator_style2 STYLE_DASHDOTDOT
|
||||
#property indicator_width2 2
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
|
||||
//
|
||||
#define slowBufferIndex 4
|
||||
double slowBuffer[];
|
||||
|
||||
//
|
||||
#define slowColorBufferIndex 5
|
||||
double slowColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "X121 X3MA Slow"
|
||||
#property indicator_type3 DRAW_COLOR_LINE
|
||||
#property indicator_color3 CLR_NONE, clrLime, clrRed, clrGray
|
||||
#property indicator_style3 STYLE_DASH
|
||||
#property indicator_width3 2
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
#define mLastBufferIndex 5
|
||||
|
||||
//
|
||||
#define fastStateBufferIndex mLastBufferIndex + 1
|
||||
double fastStateBuffer[];
|
||||
|
||||
//
|
||||
#define mediumStateBufferIndex mLastBufferIndex + 2
|
||||
double mediumStateBuffer[];
|
||||
|
||||
//
|
||||
#define slowStateBufferIndex mLastBufferIndex + 3
|
||||
double slowStateBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int fastHandler = INVALID_HANDLE;
|
||||
int mediumHandler = INVALID_HANDLE;
|
||||
int slowHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
fastHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
fastLength,
|
||||
0,
|
||||
fastMethod,
|
||||
fastAppliedTo //
|
||||
);
|
||||
bool isInited = fastHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
mediumHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mediumLength,
|
||||
0,
|
||||
mediumMethod,
|
||||
mediumAppliedTo //
|
||||
);
|
||||
isInited = mediumHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
slowHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slowLength,
|
||||
0,
|
||||
slowMethod,
|
||||
slowAppliedTo //
|
||||
);
|
||||
isInited = slowHandler != 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(fastHandler);
|
||||
IndicatorRelease(mediumHandler);
|
||||
IndicatorRelease(slowHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
int fastCalculatedBars = BarsCalculated(fastHandler);
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
int mediumCalculatedBars = BarsCalculated(mediumHandler);
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
int slowCalculatedBars = BarsCalculated(slowHandler);
|
||||
|
||||
//
|
||||
bool isPassedRequiredCalculatedBars =
|
||||
//
|
||||
// FAST ...
|
||||
fastCalculatedBars >= maxLength &&
|
||||
//
|
||||
// MEDIUM ...
|
||||
mediumCalculatedBars >= maxLength &&
|
||||
//
|
||||
// SLOW ...
|
||||
slowCalculatedBars >= maxLength
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCalculatedBars)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
int copiedFasts = CopyBuffer(fastHandler, 0, 0, limit, fastBuffer);
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
int copiedMediumss = CopyBuffer(mediumHandler, 0, 0, limit, mediumBuffer);
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
int copiedSlows = CopyBuffer(slowHandler, 0, 0, limit, slowBuffer);
|
||||
|
||||
//
|
||||
// Validate Copied Items ...
|
||||
bool isPassedRequiredCopiedItems =
|
||||
//
|
||||
// FAST ...
|
||||
copiedFasts >= limit &&
|
||||
//
|
||||
// MEDIUM ...
|
||||
copiedMediumss >= limit &&
|
||||
//
|
||||
// SLOW ...
|
||||
copiedSlows >= limit
|
||||
//
|
||||
;
|
||||
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 = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
fastLength > 2 &&
|
||||
mediumLength > 2 &&
|
||||
slowLength > 2 &&
|
||||
mediumLength > fastLength &&
|
||||
mediumLength < slowLength
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(fastLength, mediumLength);
|
||||
result = MathMax(result, slowLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fastBuffer, true);
|
||||
SetIndexBuffer(fastBufferIndex, fastBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(fastBufferIndex, PLOT_SHOW_DATA, showFast);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(fastBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fastColorBuffer, true);
|
||||
SetIndexBuffer(fastColorBufferIndex, fastColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(mediumBuffer, true);
|
||||
SetIndexBuffer(mediumBufferIndex, mediumBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(mediumBufferIndex, PLOT_SHOW_DATA, showMedium);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(mediumBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(mediumColorBuffer, true);
|
||||
SetIndexBuffer(mediumColorBufferIndex, mediumColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(slowBuffer, true);
|
||||
SetIndexBuffer(slowBufferIndex, slowBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(slowBufferIndex, PLOT_SHOW_DATA, showSlow);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(slowBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(slowColorBuffer, true);
|
||||
SetIndexBuffer(slowColorBufferIndex, slowColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
// FAST State ...
|
||||
ArraySetAsSeries(fastStateBuffer, true);
|
||||
SetIndexBuffer(fastStateBufferIndex, fastStateBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// MEDIUM State ...
|
||||
ArraySetAsSeries(mediumStateBuffer, true);
|
||||
SetIndexBuffer(mediumStateBufferIndex, mediumStateBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// SLOW State ...
|
||||
ArraySetAsSeries(slowStateBuffer, true);
|
||||
SetIndexBuffer(slowStateBufferIndex, slowStateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
|
||||
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 Values ...
|
||||
CalculateValues(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBuffersZero(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
// FAST ...
|
||||
fastBuffer[barIndex] = emptyValue;
|
||||
fastColorBuffer[barIndex] = hideColorIDX;
|
||||
fastStateBuffer[barIndex] = neuturalState;
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
mediumBuffer[barIndex] = emptyValue;
|
||||
mediumColorBuffer[barIndex] = hideColorIDX;
|
||||
mediumStateBuffer[barIndex] = neuturalState;
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
slowBuffer[barIndex] = emptyValue;
|
||||
slowColorBuffer[barIndex] = hideColorIDX;
|
||||
slowStateBuffer[barIndex] = neuturalState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Values ...
|
||||
*
|
||||
* @param bar_index: int, Specified Bar Index ...
|
||||
* @param prevCalculated: int, Provides Previous Calculated Bars ...
|
||||
* @param ratesTotal: int, Provides All Availabled Bars ...
|
||||
* @param open: double Collection, Provides Open Prices Time Series ...
|
||||
* @param high: double Collection, Provides High Prices Time Series ...
|
||||
* @param close: double Collection, Provides Close Prices Time Series ...
|
||||
* @param low: double Collection, Provides Low Prices Time Series ...
|
||||
* @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ...
|
||||
*/
|
||||
void CalculateValues(
|
||||
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[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Check Prev Bar ...
|
||||
|
||||
//
|
||||
int lastBarIndex = bar_index + 1;
|
||||
bool isFirstBar =
|
||||
startCalculationForLastBars > 0
|
||||
? bar_index == startCalculationForLastBars
|
||||
: bar_index == ratesTotal;
|
||||
|
||||
//
|
||||
double iLow = low[bar_index];
|
||||
double iHigh = high[bar_index];
|
||||
double iClose = close[bar_index];
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
|
||||
//
|
||||
double iFast = fastBuffer[bar_index];
|
||||
|
||||
//
|
||||
double iFastState =
|
||||
iLow > iFast
|
||||
? bullishState
|
||||
: iHigh < iFast
|
||||
? bearishState
|
||||
: neuturalState;
|
||||
double iFastColor = hideColorIDX;
|
||||
if (showFast)
|
||||
{
|
||||
//
|
||||
if (applyColor)
|
||||
{
|
||||
//
|
||||
iFastColor =
|
||||
iFastState == bullishState
|
||||
? bullishColorIDX
|
||||
: iFastState == bearishState
|
||||
? bearishColorIDX
|
||||
: neuturalColorIDX;
|
||||
}
|
||||
else
|
||||
{
|
||||
iFastColor = bullishColorIDX;
|
||||
}
|
||||
}
|
||||
fastColorBuffer[bar_index] = iFastColor;
|
||||
fastStateBuffer[bar_index] = iFastState;
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
|
||||
//
|
||||
double iMedium = mediumBuffer[bar_index];
|
||||
|
||||
//
|
||||
double iMediumState =
|
||||
iLow > iMedium
|
||||
? bullishState
|
||||
: iHigh < iMedium
|
||||
? bearishState
|
||||
: neuturalState;
|
||||
double iMediumColor = hideColorIDX;
|
||||
if (showMedium)
|
||||
{
|
||||
//
|
||||
if (applyColor)
|
||||
{
|
||||
//
|
||||
iMediumColor =
|
||||
iMediumState == bullishState
|
||||
? bullishColorIDX
|
||||
: iMediumState == bearishState
|
||||
? bearishColorIDX
|
||||
: neuturalColorIDX;
|
||||
}
|
||||
else
|
||||
{
|
||||
iMediumColor = bullishColorIDX;
|
||||
}
|
||||
}
|
||||
mediumColorBuffer[bar_index] = iMediumColor;
|
||||
mediumStateBuffer[bar_index] = iMediumState;
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
|
||||
//
|
||||
double iSlow = slowBuffer[bar_index];
|
||||
|
||||
//
|
||||
double iSlowState =
|
||||
iLow > iSlow
|
||||
? bullishState
|
||||
: iHigh < iSlow
|
||||
? bearishState
|
||||
: neuturalState;
|
||||
double iSlowColor = hideColorIDX;
|
||||
if (showSlow)
|
||||
{
|
||||
//
|
||||
if (applyColor)
|
||||
{
|
||||
//
|
||||
iSlowColor =
|
||||
iSlowState == bullishState
|
||||
? bullishColorIDX
|
||||
: iSlowState == bearishState
|
||||
? bearishColorIDX
|
||||
: neuturalColorIDX;
|
||||
}
|
||||
else
|
||||
{
|
||||
iSlowColor = bullishColorIDX;
|
||||
}
|
||||
}
|
||||
slowColorBuffer[bar_index] = iSlowColor;
|
||||
slowStateBuffer[bar_index] = iSlowState;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,882 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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_X_PRICE rsiPriceType = X_PRICE_CLOSE; // Applied To
|
||||
input ENUM_X_MA_METHOD rsiSmoothingMethod = X_MA_MODE_SMA; // Smoothing Method;
|
||||
|
||||
//
|
||||
input group "ATR Detection";
|
||||
input int atrLength = 14; // Length
|
||||
input double atrMultiplier = 1; // Multiplier
|
||||
input ENUM_X_PRICE atrUpperPriceType = X_PRICE_HIGH; // Upper Zone Applied To
|
||||
input ENUM_X_PRICE atrLowerPriceType = X_PRICE_LOW; // Lower Zone Applied To
|
||||
input ENUM_X_MA_METHOD atrSmoothingMethod = X_MA_MODE_SMA; // Smoothing Method
|
||||
|
||||
//
|
||||
input group "Price Change";
|
||||
input int priceChangeSmoothingLength = 14; // Length
|
||||
input ENUM_X_PRICE priceChangeType = X_PRICE_CLOSE; // Price Type
|
||||
input ENUM_X_MA_METHOD priceChangeSmoothingMethod = X_MA_MODE_SMA; // Moving Average Moethod
|
||||
|
||||
//
|
||||
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
|
||||
input bool showSmoothedAtrUpper = true; // Show Smoothed Upper Zone
|
||||
input bool showSmoothedAtrLower = true; // Show Smoothed Lower Zone
|
||||
input bool showRSIChange = true; // Show RSI Change
|
||||
input bool showSmoothedRSIChange = true; // ShowSmoothed RSI Change
|
||||
input bool showPriceChange = true; // Show Price Change
|
||||
input bool showSmoothedPriceChange = true; // ShowSmoothed Price Change
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 10
|
||||
#property indicator_plots 8
|
||||
|
||||
//
|
||||
// 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 1
|
||||
|
||||
//
|
||||
// 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 1
|
||||
|
||||
//
|
||||
// ATR Smoothed ...
|
||||
|
||||
//
|
||||
// Upper ...
|
||||
|
||||
//
|
||||
#define atrSmoothedUpperBufferIndex 2
|
||||
double atrSmoothedUpperBuffer[];
|
||||
|
||||
#property indicator_label3 "X121 ATRUSM"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrYellow
|
||||
#property indicator_style3 STYLE_DASH
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Lower ...
|
||||
|
||||
//
|
||||
#define atrSmoothedLowerBufferIndex 3
|
||||
double atrSmoothedLowerBuffer[];
|
||||
|
||||
#property indicator_label4 "X121 ATRLSM"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrYellow
|
||||
#property indicator_style4 STYLE_DASH
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// Price Change ...
|
||||
|
||||
//
|
||||
#define priceChangeBufferIndex 4
|
||||
double priceChangeBuffer[];
|
||||
|
||||
#property indicator_label5 "X121 PCH"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrOrchid
|
||||
#property indicator_style5 STYLE_SOLID
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
// Price Change Smoothed ...
|
||||
|
||||
//
|
||||
#define priceChangeSmoothedBufferIndex 5
|
||||
double priceChangeSmoothedBuffer[];
|
||||
|
||||
#property indicator_label6 "X121 PCHSM"
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_color6 clrOrchid
|
||||
#property indicator_style6 STYLE_SOLID
|
||||
#property indicator_width6 1
|
||||
|
||||
//
|
||||
// RSI Change ...
|
||||
|
||||
//
|
||||
#define rsiChangeBufferIndex 6
|
||||
double rsiChangeBuffer[];
|
||||
|
||||
#property indicator_label7 "X121 RSICH"
|
||||
#property indicator_type7 DRAW_LINE
|
||||
#property indicator_color7 clrCornflowerBlue
|
||||
#property indicator_style7 STYLE_SOLID
|
||||
#property indicator_width7 1
|
||||
|
||||
//
|
||||
// RSI Change Smoothed ...
|
||||
|
||||
//
|
||||
#define rsiChangeSmoothedBufferIndex 7
|
||||
double rsiChangeSmoothedBuffer[];
|
||||
|
||||
#property indicator_label8 "X121 RSICHSM"
|
||||
#property indicator_type8 DRAW_LINE
|
||||
#property indicator_color8 clrCornflowerBlue
|
||||
#property indicator_style8 STYLE_SOLID
|
||||
#property indicator_width8 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 7;
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
|
||||
#define atrBufferIndex mLastBufferIndex + 1
|
||||
double atrBuffer[];
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
#define rsiBufferIndex mLastBufferIndex + 2
|
||||
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;
|
||||
|
||||
//
|
||||
ENUM_APPLIED_PRICE rsiAppliedTo = ToAppliedPrice(rsiPriceType);
|
||||
|
||||
//
|
||||
// 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 &&
|
||||
//
|
||||
priceChangeSmoothingLength > 0 &&
|
||||
//
|
||||
IsValid(rsiPriceType) &&
|
||||
IsValid(priceChangeType) &&
|
||||
IsValid(atrUpperPriceType) &&
|
||||
IsValid(atrLowerPriceType)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(rsiLength, atrLength);
|
||||
result = MathMax(result, priceChangeSmoothingLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// ATR ...
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
ENUM_DRAW_TYPE atrUpperDrawType = showAtrUpper ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(atrUpperBuffer, true);
|
||||
SetIndexBuffer(atrUpperBufferIndex, atrUpperBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(atrUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(atrUpperBufferIndex, PLOT_SHOW_DATA, showAtrUpper);
|
||||
PlotIndexSetInteger(atrUpperBufferIndex, PLOT_DRAW_TYPE, atrUpperDrawType);
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
ENUM_DRAW_TYPE atrLowerDrawType = showAtrLower ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(atrLowerBuffer, true);
|
||||
SetIndexBuffer(atrLowerBufferIndex, atrLowerBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(atrLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(atrLowerBufferIndex, PLOT_SHOW_DATA, showAtrLower);
|
||||
PlotIndexSetInteger(atrLowerBufferIndex, PLOT_DRAW_TYPE, atrLowerDrawType);
|
||||
|
||||
//
|
||||
// ATR Smoothed ...
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
ENUM_DRAW_TYPE atrSmoothedUpperDrawType = showSmoothedAtrUpper ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(atrSmoothedUpperBuffer, true);
|
||||
SetIndexBuffer(atrSmoothedUpperBufferIndex, atrSmoothedUpperBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(atrSmoothedUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(atrSmoothedUpperBufferIndex, PLOT_SHOW_DATA, showSmoothedAtrUpper);
|
||||
PlotIndexSetInteger(atrSmoothedUpperBufferIndex, PLOT_DRAW_TYPE, atrSmoothedUpperDrawType);
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
ENUM_DRAW_TYPE atrSmoothedLowerDrawType = showSmoothedAtrLower ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(atrSmoothedLowerBuffer, true);
|
||||
SetIndexBuffer(atrSmoothedLowerBufferIndex, atrSmoothedLowerBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(atrSmoothedLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(atrSmoothedLowerBufferIndex, PLOT_SHOW_DATA, showSmoothedAtrLower);
|
||||
PlotIndexSetInteger(atrSmoothedLowerBufferIndex, PLOT_DRAW_TYPE, atrSmoothedLowerDrawType);
|
||||
|
||||
//
|
||||
// PriceChange ...
|
||||
ENUM_DRAW_TYPE priceChangeDrawType = showPriceChange ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(priceChangeBuffer, true);
|
||||
SetIndexBuffer(priceChangeBufferIndex, priceChangeBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(priceChangeBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(priceChangeBufferIndex, PLOT_SHOW_DATA, showPriceChange);
|
||||
PlotIndexSetInteger(priceChangeBufferIndex, PLOT_DRAW_TYPE, priceChangeDrawType);
|
||||
|
||||
//
|
||||
// PriceChange Smoothed ...
|
||||
ENUM_DRAW_TYPE priceChangeSmoothedaDrawType = showSmoothedPriceChange ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(priceChangeSmoothedBuffer, true);
|
||||
SetIndexBuffer(priceChangeSmoothedBufferIndex, priceChangeSmoothedBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(priceChangeSmoothedBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(priceChangeSmoothedBufferIndex, PLOT_SHOW_DATA, showSmoothedPriceChange);
|
||||
PlotIndexSetInteger(priceChangeSmoothedBufferIndex, PLOT_DRAW_TYPE, priceChangeSmoothedaDrawType);
|
||||
|
||||
//
|
||||
// RSIChange ...
|
||||
ENUM_DRAW_TYPE rsiChangeDrawType = showRSIChange ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(rsiChangeBuffer, true);
|
||||
SetIndexBuffer(rsiChangeBufferIndex, rsiChangeBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(rsiChangeBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(rsiChangeBufferIndex, PLOT_SHOW_DATA, showRSIChange);
|
||||
PlotIndexSetInteger(rsiChangeBufferIndex, PLOT_DRAW_TYPE, rsiChangeDrawType);
|
||||
|
||||
//
|
||||
// RSIChangeMa ...
|
||||
ENUM_DRAW_TYPE rsiChangeMaDrawType = showSmoothedRSIChange ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(rsiChangeSmoothedBuffer, true);
|
||||
SetIndexBuffer(rsiChangeSmoothedBufferIndex, rsiChangeSmoothedBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(rsiChangeSmoothedBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(rsiChangeSmoothedBufferIndex, PLOT_SHOW_DATA, showSmoothedRSIChange);
|
||||
PlotIndexSetInteger(rsiChangeSmoothedBufferIndex, PLOT_DRAW_TYPE, rsiChangeMaDrawType);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
ArraySetAsSeries(atrBuffer, true);
|
||||
SetIndexBuffer(atrBufferIndex, atrBuffer, 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);
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
//
|
||||
rsiBuffer[barIndex] = 0;
|
||||
atrBuffer[barIndex] = 0;
|
||||
atrUpperBuffer[barIndex] = 0;
|
||||
atrLowerBuffer[barIndex] = 0;
|
||||
rsiChangeBuffer[barIndex] = 0;
|
||||
priceChangeBuffer[barIndex] = 0;
|
||||
atrSmoothedUpperBuffer[barIndex] = 0;
|
||||
atrSmoothedLowerBuffer[barIndex] = 0;
|
||||
rsiChangeSmoothedBuffer[barIndex] = 0;
|
||||
priceChangeSmoothedBuffer[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[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
double points = GetPoints(_Symbol);
|
||||
|
||||
//
|
||||
// ATR Calculations ...
|
||||
double iAtr = atrBuffer[bar_index];
|
||||
double iMultiPliedAtr = iAtr * atrMultiplier;
|
||||
|
||||
//
|
||||
// Select Upper Price ...
|
||||
double iUpperPrice = GetAppliedPrice(
|
||||
atrUpperPriceType,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
|
||||
//
|
||||
// Select Lower Price ...
|
||||
double iLowerPrice = GetAppliedPrice(
|
||||
atrLowerPriceType,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Atrs ...
|
||||
|
||||
//
|
||||
double iAtrUpper = iUpperPrice + iMultiPliedAtr;
|
||||
double iAtrLower = iLowerPrice - iMultiPliedAtr;
|
||||
|
||||
//
|
||||
atrUpperBuffer[bar_index] = iAtrUpper;
|
||||
atrLowerBuffer[bar_index] = iAtrLower;
|
||||
|
||||
//
|
||||
bool canSmoothAtr = atrSmoothingMethod != X_MA_MODE_NONE;
|
||||
if (canSmoothAtr)
|
||||
{
|
||||
//
|
||||
// Upper ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
atrLength,
|
||||
atrUpperBuffer,
|
||||
atrSmoothedUpperBuffer,
|
||||
atrSmoothingMethod //
|
||||
);
|
||||
|
||||
//
|
||||
// Lower ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
atrLength,
|
||||
atrLowerBuffer,
|
||||
atrSmoothedLowerBuffer,
|
||||
atrSmoothingMethod //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
atrSmoothedUpperBuffer[bar_index] = iAtrUpper;
|
||||
atrSmoothedLowerBuffer[bar_index] = iAtrLower;
|
||||
}
|
||||
|
||||
//
|
||||
// RSI Change Calculations ...
|
||||
|
||||
//
|
||||
double iRsi = rsiBuffer[bar_index];
|
||||
double iRsiP = rsiBuffer[bar_index + 1];
|
||||
double iRsiPrice = GetAppliedPrice(
|
||||
rsiPriceType,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
|
||||
//
|
||||
double iRsiChanged = iRsi - iRsiP;
|
||||
double iRsiPointsChanged = iRsiChanged / points;
|
||||
|
||||
//
|
||||
double iRChange = iRsiPrice + (iRsiChanged * points);
|
||||
rsiChangeBuffer[bar_index] = iRChange;
|
||||
|
||||
//
|
||||
bool canSmoothRsi = rsiSmoothingMethod != X_MA_MODE_NONE;
|
||||
if (canSmoothRsi)
|
||||
{
|
||||
//
|
||||
// Upper ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
atrLength,
|
||||
rsiChangeBuffer,
|
||||
rsiChangeSmoothedBuffer,
|
||||
rsiSmoothingMethod //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
rsiChangeSmoothedBuffer[bar_index] = iRChange;
|
||||
}
|
||||
|
||||
//
|
||||
// PRICE Change Calculation ...
|
||||
|
||||
//
|
||||
double iPChangePrice = GetAppliedPrice(
|
||||
priceChangeType,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
double iPPChangePrice = GetAppliedPrice(
|
||||
priceChangeType,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index + 1 //
|
||||
);
|
||||
|
||||
//
|
||||
double iPriceChange = iPChangePrice - iPPChangePrice;
|
||||
double iPricePointsChanged = iPriceChange / points;
|
||||
double iVolatilityChange = iPriceChange / iAtr;
|
||||
|
||||
//
|
||||
double iPChange = iPChangePrice + (iPricePointsChanged * points);
|
||||
priceChangeBuffer[bar_index] = iPChange;
|
||||
|
||||
//
|
||||
bool canSmoothPriceChange = priceChangeSmoothingMethod != X_MA_MODE_NONE;
|
||||
if (canSmoothPriceChange)
|
||||
{
|
||||
//
|
||||
// Upper ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
atrLength,
|
||||
priceChangeBuffer,
|
||||
priceChangeSmoothedBuffer,
|
||||
priceChangeSmoothingMethod //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
priceChangeSmoothedBuffer[bar_index] = iPChange;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,437 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Candle Styles
|
||||
// ---------------------------------------------------
|
||||
// Name: X121 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 X121 XCC Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "X121 XCC"
|
||||
|
||||
//
|
||||
// Holds an SnapShot of Charts Configuration ...
|
||||
struct XChartStyle
|
||||
{
|
||||
//
|
||||
// chart's ID ...
|
||||
long chartId;
|
||||
//
|
||||
// chart's mode ...
|
||||
ENUM_CHART_MODE mode;
|
||||
//
|
||||
// show bid line ...
|
||||
bool showBidLine;
|
||||
//
|
||||
// show ask line ...
|
||||
bool showAskLine;
|
||||
//
|
||||
// show grids on chart ...
|
||||
bool showGrid;
|
||||
//
|
||||
// show volumes ...
|
||||
bool showVolumes;
|
||||
//
|
||||
// Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders) ...
|
||||
bool showTradeLevels;
|
||||
//
|
||||
// chart autoscroll ...
|
||||
bool autoScroll;
|
||||
//
|
||||
// chart quick navigation state ...
|
||||
bool quickNavigation;
|
||||
//
|
||||
// chart's foreground color ...
|
||||
color foreGroundColor;
|
||||
//
|
||||
// chart's background color ...
|
||||
color backGroundColor;
|
||||
//
|
||||
// Up Color ...
|
||||
color upColor;
|
||||
//
|
||||
// Down Color ...
|
||||
color downColor;
|
||||
//
|
||||
// Bullish color ...
|
||||
color bullishColor;
|
||||
//
|
||||
// Bearish color ...
|
||||
color bearishColor;
|
||||
//
|
||||
// grid color ...
|
||||
color gridColor;
|
||||
//
|
||||
// bid line color ...
|
||||
color bidLineColor;
|
||||
//
|
||||
// ask line color ...
|
||||
color askLineColor;
|
||||
//
|
||||
// line mode and doji candlestick color ...
|
||||
color lineColor;
|
||||
//
|
||||
// Color of stop order levels (Stop Loss and Take Profit) ...
|
||||
color stopColor;
|
||||
//
|
||||
// volumes color ...
|
||||
color volumesColor;
|
||||
};
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Chart Style";
|
||||
input ENUM_CHART_MODE mode = CHART_CANDLES; // Mode
|
||||
input color upColor = clrGreen; // Up Color
|
||||
input color downColor = clrRed; // Down Color
|
||||
input color lineColor = clrGreen; // Line mode and Doji candlestick Color
|
||||
input color bullishColor = clrGreen; // Bullish Color
|
||||
input color bearishColor = clrRed; // Bearish Color
|
||||
input color volumesColor = clrGreen; // Volumes Color
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showCandles = true; // Show Candles
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Draw Library ...
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 0
|
||||
#property indicator_plots 0
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
XChartStyle chartStyle;
|
||||
XChartStyle clearStyle;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Apply Chart Style ...
|
||||
ApplyCustomChartStyle();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index // Selected Bar Index
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Apply Custom Chart Style ...
|
||||
void ApplyCustomChartStyle()
|
||||
{
|
||||
//
|
||||
// Read Current Chart Config and Store it ...
|
||||
ReadChartStyle();
|
||||
|
||||
//
|
||||
// After Reading Current Chart Style ...
|
||||
// we have to Save Configs and Change Styles ...
|
||||
clearStyle = chartStyle;
|
||||
|
||||
//
|
||||
clearStyle.upColor = CLR_NONE;
|
||||
clearStyle.downColor = CLR_NONE;
|
||||
clearStyle.lineColor = CLR_NONE;
|
||||
clearStyle.bullishColor = CLR_NONE;
|
||||
clearStyle.bearishColor = CLR_NONE;
|
||||
|
||||
//
|
||||
// Decide to Show or not Candles based on User Input ...
|
||||
if (showCandles)
|
||||
{
|
||||
SetChartStyle(chartStyle);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetChartStyle(clearStyle);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Read Previous Chart Style ...
|
||||
void ReadChartStyle()
|
||||
{
|
||||
//
|
||||
// Retrieve Current Chart ID ...
|
||||
long chartId = ChartID();
|
||||
chartStyle.chartId = chartId;
|
||||
|
||||
//
|
||||
// Retrieve Chart Mode ...
|
||||
chartStyle.mode = (ENUM_CHART_MODE)ChartGetInteger(chartId, CHART_MODE);
|
||||
|
||||
//
|
||||
chartStyle.showBidLine = (bool)ChartGetInteger(chartId, CHART_SHOW_BID_LINE);
|
||||
chartStyle.showAskLine = (bool)ChartGetInteger(chartId, CHART_SHOW_ASK_LINE);
|
||||
chartStyle.showGrid = (bool)ChartGetInteger(chartId, CHART_SHOW_GRID);
|
||||
chartStyle.showVolumes = (bool)ChartGetInteger(chartId, CHART_SHOW_VOLUMES);
|
||||
chartStyle.showTradeLevels = (bool)ChartGetInteger(chartId, CHART_SHOW_TRADE_LEVELS);
|
||||
chartStyle.autoScroll = (bool)ChartGetInteger(chartId, CHART_AUTOSCROLL);
|
||||
chartStyle.quickNavigation = (bool)ChartGetInteger(chartId, CHART_QUICK_NAVIGATION);
|
||||
|
||||
//
|
||||
chartStyle.foreGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_FOREGROUND);
|
||||
chartStyle.backGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_BACKGROUND);
|
||||
chartStyle.upColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_UP);
|
||||
chartStyle.downColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_DOWN);
|
||||
chartStyle.bullishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BULL);
|
||||
chartStyle.bearishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BEAR);
|
||||
chartStyle.gridColor = (color)ChartGetInteger(chartId, CHART_COLOR_GRID);
|
||||
chartStyle.bidLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_BID);
|
||||
chartStyle.askLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_ASK);
|
||||
chartStyle.stopColor = (color)ChartGetInteger(chartId, CHART_COLOR_STOP_LEVEL);
|
||||
chartStyle.lineColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_LINE);
|
||||
chartStyle.volumesColor = (color)ChartGetInteger(chartId, CHART_COLOR_VOLUME);
|
||||
|
||||
//
|
||||
chartStyle.mode = mode;
|
||||
chartStyle.upColor = upColor;
|
||||
chartStyle.downColor = downColor;
|
||||
chartStyle.lineColor = lineColor;
|
||||
chartStyle.bearishColor = bearishColor;
|
||||
chartStyle.bullishColor = bullishColor;
|
||||
chartStyle.volumesColor = volumesColor;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Chart Style ...
|
||||
void SetChartStyle(
|
||||
XChartStyle &mChartStyle // Chart Style to Apply
|
||||
)
|
||||
{
|
||||
//
|
||||
ApplyChartStyle(
|
||||
mChartStyle.chartId,
|
||||
mChartStyle.mode,
|
||||
mChartStyle.showBidLine,
|
||||
mChartStyle.showAskLine,
|
||||
mChartStyle.showGrid,
|
||||
mChartStyle.showVolumes,
|
||||
mChartStyle.showTradeLevels,
|
||||
mChartStyle.autoScroll,
|
||||
mChartStyle.quickNavigation,
|
||||
mChartStyle.foreGroundColor,
|
||||
mChartStyle.backGroundColor,
|
||||
mChartStyle.upColor,
|
||||
mChartStyle.downColor,
|
||||
mChartStyle.bullishColor,
|
||||
mChartStyle.bearishColor,
|
||||
mChartStyle.gridColor,
|
||||
mChartStyle.bidLineColor,
|
||||
mChartStyle.askLineColor,
|
||||
mChartStyle.lineColor,
|
||||
mChartStyle.stopColor,
|
||||
mChartStyle.volumesColor);
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,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];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,262 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121 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 X121 XCT Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
#define ShortName "X121 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
@@ -0,0 +1,550 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Ocillator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XDelta
|
||||
// Description: Detect Comulative Volumes Delta ...
|
||||
//
|
||||
//
|
||||
// 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 XDelta Ocillator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121_XDELTA"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Makret ...
|
||||
input group "Market";
|
||||
input int maLength = 14; // Moving Averge Length
|
||||
input ENUM_X_MA_METHOD maMethod = X_MA_MODE_EMA; // Moving Averge Method
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
input bool showDeltaLine = true; // Show Delta Line
|
||||
input bool showDeltaHistogram = true; // Show Delta Histogram
|
||||
input bool showDeltaMa = true; // Show Delta Moving Average
|
||||
|
||||
//
|
||||
// Buffers Props ...
|
||||
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 6
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define deltaLineBufferIndex 0
|
||||
double deltaLineBuffer[];
|
||||
|
||||
#property indicator_label1 "Delta Line"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrYellow
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
#define deltaHistogramBufferIndex 1
|
||||
double deltaHistogramBuffer[];
|
||||
|
||||
//
|
||||
#define deltaHistogramColorBufferIndex 2
|
||||
double deltaHistogramColorBuffer[];
|
||||
|
||||
#property indicator_label2 "Delta Histogram"
|
||||
#property indicator_type2 DRAW_COLOR_HISTOGRAM
|
||||
#property indicator_color2 CLR_NONE, clrGreen, clrDarkRed
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#define deltaMaBufferIndex 3
|
||||
double deltaMaBuffer[];
|
||||
|
||||
#property indicator_label3 "Delta MA"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrOrchid
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
#define mLastBufferIndex 3
|
||||
|
||||
//
|
||||
#define rawDeltaBufferIndex mLastBufferIndex + 1
|
||||
double rawDeltaBuffer[];
|
||||
|
||||
//
|
||||
#define deltaStateBufferIndex mLastBufferIndex + 2
|
||||
double deltaStateBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int firstBarIndex;
|
||||
|
||||
//
|
||||
// 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();
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||
|
||||
//
|
||||
// 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);
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
//
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = maLength > 0 &&
|
||||
IsValid(maMethod);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(0, maLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// Delta Line ...
|
||||
ENUM_DRAW_TYPE deltaLineDrawType = showDeltaLine ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(deltaLineBuffer, true);
|
||||
SetIndexBuffer(deltaLineBufferIndex, deltaLineBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(deltaLineBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(deltaLineBufferIndex, PLOT_SHOW_DATA, showDeltaLine);
|
||||
PlotIndexSetInteger(deltaLineBufferIndex, PLOT_DRAW_TYPE, deltaLineDrawType);
|
||||
|
||||
//
|
||||
// Delta Histogram ...
|
||||
ENUM_DRAW_TYPE deltaHistogramDrawType = showDeltaHistogram ? DRAW_COLOR_HISTOGRAM : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(deltaHistogramBuffer, true);
|
||||
SetIndexBuffer(deltaHistogramBufferIndex, deltaHistogramBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(deltaHistogramBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(deltaHistogramBufferIndex, PLOT_SHOW_DATA, showDeltaHistogram);
|
||||
PlotIndexSetInteger(deltaHistogramBufferIndex, PLOT_DRAW_TYPE, deltaHistogramDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(deltaHistogramColorBuffer, true);
|
||||
SetIndexBuffer(deltaHistogramColorBufferIndex, deltaHistogramColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Delta Ma ...
|
||||
ENUM_DRAW_TYPE deltaMaDrawType = showDeltaMa ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(deltaMaBuffer, true);
|
||||
SetIndexBuffer(deltaMaBufferIndex, deltaMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(deltaMaBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(deltaMaBufferIndex, PLOT_SHOW_DATA, showDeltaMa);
|
||||
PlotIndexSetInteger(deltaMaBufferIndex, PLOT_DRAW_TYPE, deltaMaDrawType);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(rawDeltaBuffer, true);
|
||||
SetIndexBuffer(rawDeltaBufferIndex, rawDeltaBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(deltaStateBuffer, true);
|
||||
SetIndexBuffer(deltaStateBufferIndex, deltaStateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
if (barsLimit == 0)
|
||||
{
|
||||
//
|
||||
barsLimit = ratesTotal;
|
||||
firstBarIndex = barsLimit - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
firstBarIndex = startCalculationForLastBars;
|
||||
}
|
||||
|
||||
//
|
||||
// bool canCalculate = true;
|
||||
bool canCalculate =
|
||||
bar_index <= barsLimit;
|
||||
if (canCalculate)
|
||||
{
|
||||
//
|
||||
CalculateValues(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBuffersZero(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
rawDeltaBuffer[barIndex] = 0.0;
|
||||
deltaLineBuffer[barIndex] = 0.0;
|
||||
deltaStateBuffer[barIndex] = 0.0;
|
||||
deltaHistogramBuffer[barIndex] = 0.0;
|
||||
deltaMaBuffer[barIndex] = 0.0;
|
||||
deltaHistogramColorBuffer[barIndex] = hideColorIDX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Vales ...
|
||||
*
|
||||
* @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 CalculateValues(
|
||||
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[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Check Prev Bar ...
|
||||
int lastBarIndex = bar_index + 1;
|
||||
bool isFirstBar =
|
||||
startCalculationForLastBars > 0
|
||||
? bar_index == startCalculationForLastBars
|
||||
: bar_index == firstBarIndex;
|
||||
|
||||
//
|
||||
XOHCL bar;
|
||||
bool has = bar.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index //
|
||||
);
|
||||
if (!has)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double iDelta = 0.0;
|
||||
|
||||
//
|
||||
// Detecting Delta Volume ...
|
||||
if (bar.IsBullish())
|
||||
{
|
||||
iDelta = (double)bar.volume;
|
||||
}
|
||||
else if (bar.IsBearish())
|
||||
{
|
||||
iDelta = -(double)bar.volume;
|
||||
}
|
||||
|
||||
//
|
||||
// Setting iDelta Value ...
|
||||
if (isFirstBar)
|
||||
{
|
||||
//
|
||||
rawDeltaBuffer[bar_index] = iDelta;
|
||||
deltaLineBuffer[bar_index] = iDelta;
|
||||
deltaHistogramBuffer[bar_index] = iDelta;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
iDelta += deltaLineBuffer[bar_index + 1];
|
||||
|
||||
//
|
||||
rawDeltaBuffer[bar_index] = iDelta;
|
||||
deltaLineBuffer[bar_index] = iDelta;
|
||||
deltaHistogramBuffer[bar_index] = iDelta;
|
||||
}
|
||||
|
||||
//
|
||||
// Setting iDelta State ...
|
||||
double iState = iDelta > 0
|
||||
? bullishColorIDX
|
||||
: iDelta < 0
|
||||
? bearishColorIDX
|
||||
: hideColorIDX;
|
||||
//
|
||||
// Setting iDelta Color ...
|
||||
double iDeltaColor = iDelta > 0
|
||||
? bullishColorIDX
|
||||
: iDelta < 0
|
||||
? bearishColorIDX
|
||||
: hideColorIDX;
|
||||
|
||||
//
|
||||
deltaStateBuffer[bar_index] = iState;
|
||||
deltaHistogramColorBuffer[bar_index] = iDeltaColor;
|
||||
|
||||
//
|
||||
// Calculate Moving Averages ...
|
||||
int deltaMAsCount = iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
maLength,
|
||||
rawDeltaBuffer,
|
||||
deltaMaBuffer,
|
||||
maMethod //
|
||||
);
|
||||
|
||||
//
|
||||
bar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -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 //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,636 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XHK
|
||||
// Description: XHK ...
|
||||
//
|
||||
//
|
||||
// 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 XHK Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121 XHK"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int xhkSmoothingLength = 14; // Length
|
||||
input ENUM_X_MA_METHOD xhkSmoothingMode = X_MA_MODE_EMA; // Smoothing Method
|
||||
input bool xhkIgnoreSmoothingShadows = false; // Ignore Smoothed Bar Shadows
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
|
||||
//
|
||||
input bool drawRawXHKCandles = true; // Draw Raw Candle
|
||||
input bool drawSmoothedXHKCandles = true; // Draw Smoothed Candle
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 10
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
// PLOTTED Buffers ...
|
||||
|
||||
//
|
||||
#define openHKBufferIndex 0
|
||||
double openHKBuffer[];
|
||||
|
||||
//
|
||||
#define highHKBufferIndex 1
|
||||
double highHKBuffer[];
|
||||
|
||||
//
|
||||
#define lowHKBufferIndex 2
|
||||
double lowHKBuffer[];
|
||||
|
||||
//
|
||||
#define closeHKBufferIndex 3
|
||||
double closeHKBuffer[];
|
||||
|
||||
//
|
||||
#define rawHKColorBufferIndex 4
|
||||
double rawHKColorBuffer[];
|
||||
|
||||
//
|
||||
#define rawHKBufferIndex 0
|
||||
#property indicator_label1 "X121 XHK Open;X121 XHK High;X121 XHK Low;X121 XHK Close"
|
||||
#property indicator_type1 DRAW_COLOR_CANDLES
|
||||
#property indicator_color1 CLR_NONE, clrDodgerBlue, clrDarkGoldenrod
|
||||
|
||||
//
|
||||
// Open ...
|
||||
#define openBufferIndex 5
|
||||
double openBuffer[];
|
||||
|
||||
//
|
||||
// High ...
|
||||
#define highBufferIndex 6
|
||||
double highBuffer[];
|
||||
|
||||
//
|
||||
// Low ...
|
||||
#define lowBufferIndex 7
|
||||
double lowBuffer[];
|
||||
|
||||
//
|
||||
// Close ...
|
||||
#define closeBufferIndex 8
|
||||
double closeBuffer[];
|
||||
|
||||
//
|
||||
// Candle Color ...
|
||||
#define candleColorBufferIndex 9
|
||||
double candleColorBuffer[];
|
||||
|
||||
//
|
||||
#define candlesBufferIndex 1
|
||||
#property indicator_label2 "X121 XHKSM Open;X121 XHKSM High;X121 XHKSM Low;X121 XHKSM Close"
|
||||
#property indicator_type2 DRAW_COLOR_CANDLES
|
||||
#property indicator_color2 CLR_NONE, clrAqua, clrMagenta
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int firstBarIndex;
|
||||
|
||||
//
|
||||
// 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);
|
||||
|
||||
//
|
||||
// Fill All Buffers by Zero ...
|
||||
if (prev_calculated == 0)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
true
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(0, xhkSmoothingLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
|
||||
//
|
||||
// RAW ...
|
||||
|
||||
//
|
||||
// Raw Candles Color ...
|
||||
ArraySetAsSeries(rawHKColorBuffer, true);
|
||||
SetIndexBuffer(rawHKColorBufferIndex, rawHKColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Set EMPTY_VALUE on Candles Buffer ...
|
||||
PlotIndexSetDouble(rawHKBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(rawHKBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// Open ...
|
||||
ArraySetAsSeries(openHKBuffer, true);
|
||||
SetIndexBuffer(openHKBufferIndex, openHKBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// High ...
|
||||
ArraySetAsSeries(highHKBuffer, true);
|
||||
SetIndexBuffer(highHKBufferIndex, highHKBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// Close ...
|
||||
ArraySetAsSeries(closeHKBuffer, true);
|
||||
SetIndexBuffer(closeHKBufferIndex, closeHKBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
ArraySetAsSeries(lowHKBuffer, true);
|
||||
SetIndexBuffer(lowHKBufferIndex, lowHKBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// SMOOTHED ...
|
||||
|
||||
//
|
||||
// Candles Color ...
|
||||
ArraySetAsSeries(candleColorBuffer, true);
|
||||
SetIndexBuffer(candleColorBufferIndex, candleColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Set EMPTY_VALUE on Candles Buffer ...
|
||||
PlotIndexSetDouble(candlesBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(candlesBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// Open ...
|
||||
ArraySetAsSeries(openBuffer, true);
|
||||
SetIndexBuffer(openBufferIndex, openBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// High ...
|
||||
ArraySetAsSeries(highBuffer, true);
|
||||
SetIndexBuffer(highBufferIndex, highBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// Close ...
|
||||
ArraySetAsSeries(closeBuffer, true);
|
||||
SetIndexBuffer(closeBufferIndex, closeBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
ArraySetAsSeries(lowBuffer, true);
|
||||
SetIndexBuffer(lowBufferIndex, lowBuffer, INDICATOR_DATA);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
if (barsLimit == 0)
|
||||
{
|
||||
//
|
||||
barsLimit = ratesTotal;
|
||||
firstBarIndex = barsLimit - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
firstBarIndex = startCalculationForLastBars;
|
||||
}
|
||||
|
||||
//
|
||||
// bool canCalculate = true;
|
||||
bool canCalculate =
|
||||
bar_index <= barsLimit;
|
||||
if (canCalculate)
|
||||
{
|
||||
//
|
||||
CalculateXHK(
|
||||
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)
|
||||
{
|
||||
//
|
||||
lowHKBuffer[barIndex] = 0.0;
|
||||
openHKBuffer[barIndex] = 0.0;
|
||||
highHKBuffer[barIndex] = 0.0;
|
||||
closeHKBuffer[barIndex] = 0.0;
|
||||
rawHKColorBuffer[barIndex] = hideColorIDX;
|
||||
|
||||
//
|
||||
lowBuffer[barIndex] = 0.0;
|
||||
openBuffer[barIndex] = 0.0;
|
||||
highBuffer[barIndex] = 0.0;
|
||||
closeBuffer[barIndex] = 0.0;
|
||||
candleColorBuffer[barIndex] = hideColorIDX;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 CalculateXHK(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int lastBarIndex = bar_index + 1;
|
||||
bool isFirstBar =
|
||||
startCalculationForLastBars > 0
|
||||
? bar_index == startCalculationForLastBars
|
||||
: bar_index == firstBarIndex;
|
||||
|
||||
//
|
||||
double mPrevHKOpenValue;
|
||||
double mPrevHKCloseValue;
|
||||
|
||||
//
|
||||
if (ArraySize(open) <= bar_index + 1)
|
||||
{
|
||||
//
|
||||
mPrevHKOpenValue = 0;
|
||||
mPrevHKCloseValue = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
mPrevHKOpenValue = openHKBuffer[bar_index + 1];
|
||||
mPrevHKCloseValue = closeHKBuffer[bar_index + 1];
|
||||
}
|
||||
|
||||
//
|
||||
double mHKOpenValue = (mPrevHKOpenValue + mPrevHKCloseValue) / 2;
|
||||
double mHKCloseValue = (open[bar_index] + high[bar_index] + close[bar_index] + low[bar_index]) / 4;
|
||||
double mHKHighValue = MathMax(high[bar_index], MathMax(mHKOpenValue, mHKCloseValue));
|
||||
double mHKLowValue = MathMin(low[bar_index], MathMin(mHKOpenValue, mHKCloseValue));
|
||||
|
||||
//
|
||||
double candleColorValue =
|
||||
mHKOpenValue < mHKCloseValue ? bullishColorIDX : bearishColorIDX;
|
||||
|
||||
//
|
||||
// Raw HK Buffers ...
|
||||
openHKBuffer[bar_index] = mHKOpenValue;
|
||||
highHKBuffer[bar_index] = mHKHighValue;
|
||||
lowHKBuffer[bar_index] = mHKLowValue;
|
||||
closeHKBuffer[bar_index] = mHKCloseValue;
|
||||
rawHKColorBuffer[bar_index] = drawRawXHKCandles ? candleColorValue : hideColorIDX;
|
||||
|
||||
//
|
||||
// Apply Smoothing ...
|
||||
bool canSmooth = xhkSmoothingLength > 0 &&
|
||||
xhkSmoothingMode != X_MA_MODE_NONE;
|
||||
if (!canSmooth)
|
||||
{
|
||||
//
|
||||
double min = MathMin(mHKOpenValue, mHKCloseValue);
|
||||
double max = MathMax(mHKOpenValue, mHKCloseValue);
|
||||
|
||||
//
|
||||
openBuffer[bar_index] = mHKOpenValue;
|
||||
highBuffer[bar_index] = xhkIgnoreSmoothingShadows ? max : mHKHighValue;
|
||||
lowBuffer[bar_index] = xhkIgnoreSmoothingShadows ? min : mHKLowValue;
|
||||
closeBuffer[bar_index] = mHKCloseValue;
|
||||
candleColorBuffer[bar_index] = drawSmoothedXHKCandles ? candleColorValue : hideColorIDX;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Open ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
xhkSmoothingLength,
|
||||
openHKBuffer,
|
||||
openBuffer,
|
||||
xhkSmoothingMode //
|
||||
);
|
||||
|
||||
//
|
||||
// Close ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
xhkSmoothingLength,
|
||||
closeHKBuffer,
|
||||
closeBuffer,
|
||||
xhkSmoothingMode //
|
||||
);
|
||||
|
||||
//
|
||||
// Ignoring Shadows ...
|
||||
if (!xhkIgnoreSmoothingShadows)
|
||||
{
|
||||
//
|
||||
// High ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
xhkSmoothingLength,
|
||||
highHKBuffer,
|
||||
highBuffer,
|
||||
xhkSmoothingMode //
|
||||
);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
xhkSmoothingLength,
|
||||
lowHKBuffer,
|
||||
lowBuffer,
|
||||
xhkSmoothingMode //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
double min = MathMin(closeBuffer[bar_index], openBuffer[bar_index]);
|
||||
double max = MathMin(closeBuffer[bar_index], openBuffer[bar_index]);
|
||||
|
||||
//
|
||||
lowBuffer[bar_index] = min;
|
||||
highBuffer[bar_index] = max;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Smoothed Color ...
|
||||
candleColorValue =
|
||||
openBuffer[bar_index] < closeBuffer[bar_index] ? bullishColorIDX : bearishColorIDX;
|
||||
candleColorBuffer[bar_index] = drawSmoothedXHKCandles ? candleColorValue : hideColorIDX;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,625 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XWZ
|
||||
// Description: XWZ ...
|
||||
//
|
||||
//
|
||||
// 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 XWZ Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121_XICH"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input ENUM_X_PRICE chikouSpanMode = X_PRICE_CLOSE; // ChikouSpan Mode
|
||||
input int tenkanSenLength = 9; // TenkanSen Length
|
||||
input ENUM_X_BOUNDARY_PRICE tenkanSenMode = X_BOUNDARY_PRICE_HIGH_LOW; // TencanSen Mode
|
||||
input int kijunSenLength = 26; // KijunSen Length
|
||||
input ENUM_X_BOUNDARY_PRICE kijunSenMode = X_BOUNDARY_PRICE_HIGH_LOW; // KijunSen Mode
|
||||
input int senkouSpanBLength = 52; // SenkouSpan B Length
|
||||
input ENUM_X_BOUNDARY_PRICE senkouSpanBMode = X_BOUNDARY_PRICE_HIGH_LOW; // SenkouSpan B Mode
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
input bool shiftKumo = true; // Shift Kumo
|
||||
input bool showTenkanSen = true; // Show TenkanSen
|
||||
input bool showKijunSen = true; // Show KijunSen
|
||||
input bool showChikouSpan = true; // Show ChikouSpan
|
||||
input bool showSenkouSpanA = true; // Show Senkou Span A
|
||||
input bool showSenkouSpanB = true; // Show Senkou Span B
|
||||
input bool showKumo = true; // Show Kumo
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 8
|
||||
#property indicator_plots 6
|
||||
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
#define tenkanSenBufferIndex 0
|
||||
double tenkanSenBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XICH TK"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrBrown
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 2
|
||||
|
||||
//
|
||||
#define kijunSenBufferIndex 1
|
||||
double kijunSenBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "XICH KJ"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrDodgerBlue
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 2
|
||||
|
||||
//
|
||||
#define chikouSpanBufferIndex 2
|
||||
double chikouSpanBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "XICH CS"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrDarkGreen
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 2
|
||||
|
||||
//
|
||||
#define senkouSpanABufferIndex 3
|
||||
double senkouSpanABuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "XICH SSA"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrLightGray
|
||||
#property indicator_style4 STYLE_DASHDOTDOT
|
||||
#property indicator_width4 2
|
||||
|
||||
//
|
||||
#define senkouSpanBBufferIndex 4
|
||||
double senkouSpanBBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "XICH SSB"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrLightGray
|
||||
#property indicator_style5 STYLE_DASHDOTDOT
|
||||
#property indicator_width5 2
|
||||
|
||||
//
|
||||
#define senkouABufferIndex 5
|
||||
double senkouABuffer[];
|
||||
|
||||
//
|
||||
#define senkouBBufferIndex 6
|
||||
double senkouBBuffer[];
|
||||
|
||||
//
|
||||
#define kumoBufferIndex 5
|
||||
|
||||
//
|
||||
#property indicator_label6 "XICH Kumo"
|
||||
#property indicator_type6 DRAW_FILLING
|
||||
#property indicator_color6 clrAqua, clrMagenta
|
||||
#property indicator_style6 STYLE_SOLID
|
||||
#property indicator_width6 2
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 6;
|
||||
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
|
||||
//
|
||||
// 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();
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||
|
||||
//
|
||||
// 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);
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
//
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
kijunSenLength > 0 &&
|
||||
tenkanSenLength > 0 &&
|
||||
senkouSpanBLength > 0 &&
|
||||
IsValid(kijunSenMode) &&
|
||||
IsValid(tenkanSenMode) &&
|
||||
IsValid(chikouSpanMode) &&
|
||||
IsValid(senkouSpanBMode)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(kijunSenLength, tenkanSenLength);
|
||||
result = MathMax(result, senkouSpanBLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
ENUM_DRAW_TYPE tenkanSenDrawType = showTenkanSen ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(tenkanSenBuffer, true);
|
||||
SetIndexBuffer(tenkanSenBufferIndex, tenkanSenBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(tenkanSenBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(tenkanSenBufferIndex, PLOT_SHOW_DATA, showTenkanSen);
|
||||
PlotIndexSetInteger(tenkanSenBufferIndex, PLOT_DRAW_TYPE, tenkanSenDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE kijunSenDrawType = showKijunSen ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(kijunSenBuffer, true);
|
||||
SetIndexBuffer(kijunSenBufferIndex, kijunSenBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(kijunSenBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(kijunSenBufferIndex, PLOT_SHOW_DATA, showKijunSen);
|
||||
PlotIndexSetInteger(kijunSenBufferIndex, PLOT_DRAW_TYPE, kijunSenDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE chikouSpanDrawType = showChikouSpan ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(chikouSpanBuffer, true);
|
||||
SetIndexBuffer(chikouSpanBufferIndex, chikouSpanBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_SHIFT, -kijunSenLength);
|
||||
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_SHOW_DATA, showChikouSpan);
|
||||
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_DRAW_TYPE, chikouSpanDrawType);
|
||||
|
||||
//
|
||||
int shiftSize = shiftKumo ? kijunSenLength : 0;
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE senkouSpanADrawType = showSenkouSpanA ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(senkouSpanABuffer, true);
|
||||
SetIndexBuffer(senkouSpanABufferIndex, senkouSpanABuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(senkouSpanABufferIndex, PLOT_SHIFT, shiftSize);
|
||||
PlotIndexSetInteger(senkouSpanABufferIndex, PLOT_SHOW_DATA, showSenkouSpanA);
|
||||
PlotIndexSetInteger(senkouSpanABufferIndex, PLOT_DRAW_TYPE, senkouSpanADrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE senkouSpanBDrawType = showSenkouSpanB ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(senkouSpanBBuffer, true);
|
||||
SetIndexBuffer(senkouSpanBBufferIndex, senkouSpanBBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(senkouSpanBBufferIndex, PLOT_SHIFT, shiftSize);
|
||||
PlotIndexSetInteger(senkouSpanBBufferIndex, PLOT_SHOW_DATA, showSenkouSpanB);
|
||||
PlotIndexSetInteger(senkouSpanBBufferIndex, PLOT_DRAW_TYPE, senkouSpanBDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(senkouABuffer, true);
|
||||
SetIndexBuffer(senkouABufferIndex, senkouABuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(senkouABufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(senkouBBuffer, true);
|
||||
SetIndexBuffer(senkouBBufferIndex, senkouBBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(senkouBBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE kumoDrawType = showKumo ? DRAW_FILLING : DRAW_NONE;
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(kumoBufferIndex, PLOT_SHIFT, shiftSize);
|
||||
PlotIndexSetInteger(kumoBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(kumoBufferIndex, PLOT_DRAW_TYPE, kumoDrawType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
//
|
||||
CalculateValues(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBuffersZero(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
senkouABuffer[barIndex] = 0;
|
||||
senkouBBuffer[barIndex] = 0;
|
||||
kijunSenBuffer[barIndex] = 0;
|
||||
tenkanSenBuffer[barIndex] = 0;
|
||||
chikouSpanBuffer[barIndex] = 0;
|
||||
senkouSpanABuffer[barIndex] = 0;
|
||||
senkouSpanBBuffer[barIndex] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Vales ...
|
||||
*
|
||||
* @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 CalculateValues(
|
||||
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 uppers[];
|
||||
double lowers[];
|
||||
|
||||
//
|
||||
double uppersMax = 0;
|
||||
double uppersMin = 0;
|
||||
|
||||
//
|
||||
double lowersMax = 0;
|
||||
double lowersMin = 0;
|
||||
|
||||
//
|
||||
// Calculate ChikouSpan ...
|
||||
double iChikouSpan = GetAppliedPrice(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index,
|
||||
chikouSpanMode //
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate TenkanSen ...
|
||||
GetPriceBoundary(
|
||||
uppers,
|
||||
lowers,
|
||||
_Symbol,
|
||||
_Period,
|
||||
tenkanSenMode,
|
||||
tenkanSenLength,
|
||||
bar_index //
|
||||
);
|
||||
|
||||
//
|
||||
uppersMax = uppers[ArrayMaximum(uppers)];
|
||||
uppersMin = uppers[ArrayMinimum(uppers)];
|
||||
|
||||
//
|
||||
lowersMax = lowers[ArrayMaximum(lowers)];
|
||||
lowersMin = lowers[ArrayMinimum(lowers)];
|
||||
|
||||
//
|
||||
double iTenkanSen = (uppersMax + lowersMin) / 2;
|
||||
|
||||
//
|
||||
// Calculate KijunSen ...
|
||||
GetPriceBoundary(
|
||||
uppers,
|
||||
lowers,
|
||||
_Symbol,
|
||||
_Period,
|
||||
kijunSenMode,
|
||||
kijunSenLength,
|
||||
bar_index //
|
||||
);
|
||||
|
||||
//
|
||||
uppersMax = uppers[ArrayMaximum(uppers)];
|
||||
uppersMin = uppers[ArrayMinimum(uppers)];
|
||||
|
||||
//
|
||||
lowersMax = lowers[ArrayMaximum(lowers)];
|
||||
lowersMin = lowers[ArrayMinimum(lowers)];
|
||||
|
||||
//
|
||||
double iKijunSen = (uppersMax + lowersMin) / 2;
|
||||
|
||||
//
|
||||
// Calculate SenkouSpanB ...
|
||||
GetPriceBoundary(
|
||||
uppers,
|
||||
lowers,
|
||||
_Symbol,
|
||||
_Period,
|
||||
senkouSpanBMode,
|
||||
senkouSpanBLength,
|
||||
bar_index //
|
||||
);
|
||||
|
||||
//
|
||||
uppersMax = uppers[ArrayMaximum(uppers)];
|
||||
uppersMin = uppers[ArrayMinimum(uppers)];
|
||||
|
||||
//
|
||||
lowersMax = lowers[ArrayMaximum(lowers)];
|
||||
lowersMin = lowers[ArrayMinimum(lowers)];
|
||||
|
||||
//
|
||||
double iSenkouSpanB = (uppersMax + lowersMin) / 2;
|
||||
|
||||
//
|
||||
// Calculate SenkouSpanA ...
|
||||
double iSenkouSpanA = (iTenkanSen + iKijunSen) / 2;
|
||||
|
||||
//
|
||||
// Setting Buffers ...
|
||||
kijunSenBuffer[bar_index] = iKijunSen;
|
||||
senkouABuffer[bar_index] = iSenkouSpanA;
|
||||
senkouBBuffer[bar_index] = iSenkouSpanB;
|
||||
tenkanSenBuffer[bar_index] = iTenkanSen;
|
||||
chikouSpanBuffer[bar_index] = iChikouSpan;
|
||||
senkouSpanABuffer[bar_index] = iSenkouSpanA;
|
||||
senkouSpanBBuffer[bar_index] = iSenkouSpanB;
|
||||
}
|
||||
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,812 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 int vidyaLength = 14; // Smothing Length
|
||||
input ENUM_MA_METHOD strBoundaryMode = MODE_SMA; // Boundary Mode
|
||||
input ENUM_APPLIED_PRICE strAppliedTo = PRICE_MEDIAN; // Applied To
|
||||
input ENUM_APPLIED_PRICE vidyaAppliedTo = PRICE_CLOSE; // Smoothing Applied To
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showStr = true; // Show Str
|
||||
input bool showVidya = true; // Show Vidya
|
||||
input bool showStrUpper = true; // Show Str Upper
|
||||
input bool showStrLower = true; // Show Str Lower
|
||||
input bool showStrLowMa = true; // Show Low Smoothed Buffer
|
||||
input bool showStrHighMa = true; // Show High Smoothed Buffer
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#define emptyValue 0.0
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 10
|
||||
#property indicator_plots 6
|
||||
|
||||
//
|
||||
// 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 clrBlueViolet
|
||||
#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 clrBlueViolet
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// High MA ...
|
||||
#define strHighMaBufferIndex 4
|
||||
double strHighMaBuffer[];
|
||||
|
||||
//
|
||||
#define strHighMaPlotBufferIndex 3
|
||||
#property indicator_label4 "X121 STR HSM"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrAqua
|
||||
#property indicator_style4 STYLE_SOLID
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// Low Ma ...
|
||||
#define strLowMaBufferIndex 5
|
||||
double strLowMaBuffer[];
|
||||
|
||||
//
|
||||
#define strLowMaPlotBufferIndex 4
|
||||
#property indicator_label5 "X121 STR LSM"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrMagenta
|
||||
#property indicator_style5 STYLE_SOLID
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
// VIDYA ...
|
||||
#define vidyaBufferIndex 6
|
||||
double vidyaBuffer[];
|
||||
|
||||
//
|
||||
#define vidyaPlotBufferIndex 5
|
||||
#property indicator_label6 "X121 VIDYA"
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_color6 clrYellow
|
||||
#property indicator_style6 STYLE_SOLID
|
||||
#property indicator_width6 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 6;
|
||||
|
||||
//
|
||||
// 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;
|
||||
|
||||
//
|
||||
// MA Handler ...
|
||||
int lowMaHandler = INVALID_HANDLE;
|
||||
int highMaHandler = INVALID_HANDLE;
|
||||
int vidyaHandler = 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;
|
||||
}
|
||||
|
||||
//
|
||||
// Low Ma ...
|
||||
lowMaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
strLength,
|
||||
0,
|
||||
strBoundaryMode,
|
||||
PRICE_LOW //
|
||||
);
|
||||
isInited = lowMaHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// High Ma ...
|
||||
highMaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
strLength,
|
||||
0,
|
||||
strBoundaryMode,
|
||||
PRICE_HIGH //
|
||||
);
|
||||
isInited = highMaHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Vidya ...
|
||||
vidyaHandler = iVIDyA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
strLength,
|
||||
vidyaLength,
|
||||
0, // Shift ...
|
||||
vidyaAppliedTo //
|
||||
);
|
||||
isInited = vidyaHandler != 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);
|
||||
IndicatorRelease(vidyaHandler);
|
||||
IndicatorRelease(lowMaHandler);
|
||||
IndicatorRelease(highMaHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
//
|
||||
// VIDYA ...
|
||||
int vidyaCalculatedBars = BarsCalculated(vidyaHandler);
|
||||
|
||||
//
|
||||
// Low Ma ...
|
||||
int lowMaCalculatedBars = BarsCalculated(lowMaHandler);
|
||||
|
||||
//
|
||||
// High Ma ...
|
||||
int highMaCalculatedBars = BarsCalculated(highMaHandler);
|
||||
|
||||
//
|
||||
bool isPassedRequiredCalculatedBars =
|
||||
//
|
||||
// ATR ...
|
||||
atrCalculatedBars >= 0 &&
|
||||
//
|
||||
// VIDYA ...
|
||||
vidyaCalculatedBars >= 0 &&
|
||||
//
|
||||
// Low Ma ...
|
||||
lowMaCalculatedBars >= 0 &&
|
||||
//
|
||||
// High Ma ...
|
||||
highMaCalculatedBars >= 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);
|
||||
|
||||
//
|
||||
// VYDIA ...
|
||||
int copiedVidyas = CopyBuffer(vidyaHandler, 0, 0, rates_total, vidyaBuffer);
|
||||
|
||||
//
|
||||
// Low Ma ...
|
||||
int copiedLowMas = CopyBuffer(lowMaHandler, 0, 0, rates_total, strLowMaBuffer);
|
||||
|
||||
//
|
||||
// High Ma ...
|
||||
int copiedHighMas = CopyBuffer(highMaHandler, 0, 0, rates_total, strHighMaBuffer);
|
||||
|
||||
//
|
||||
// Validate Copied Items ...
|
||||
bool isPassedRequiredCopiedItems =
|
||||
//
|
||||
// ATR ...
|
||||
copiedAtrs >= 0 &&
|
||||
//
|
||||
// VIDYA ...
|
||||
copiedVidyas >= 0 &&
|
||||
//
|
||||
// Low Ma ...
|
||||
copiedLowMas >= 0 &&
|
||||
//
|
||||
// Hig Ma ...
|
||||
copiedHighMas >= 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, emptyValue);
|
||||
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, emptyValue);
|
||||
PlotIndexSetInteger(strDownPlotBufferIndex, PLOT_SHOW_DATA, showStrLower);
|
||||
PlotIndexSetInteger(strDownPlotBufferIndex, PLOT_DRAW_TYPE, strDownDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE strLowMaDrawType = showStrLowMa ? DRAW_LINE : DRAW_NONE;
|
||||
SetIndexBuffer(strLowMaBufferIndex, strLowMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(strLowMaPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(strLowMaPlotBufferIndex, PLOT_SHOW_DATA, showStrLowMa);
|
||||
PlotIndexSetInteger(strLowMaPlotBufferIndex, PLOT_DRAW_TYPE, strLowMaDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE strHighMaDrawType = showStrHighMa ? DRAW_LINE : DRAW_NONE;
|
||||
SetIndexBuffer(strHighMaBufferIndex, strHighMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(strHighMaPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(strHighMaPlotBufferIndex, PLOT_SHOW_DATA, showStrHighMa);
|
||||
PlotIndexSetInteger(strHighMaPlotBufferIndex, PLOT_DRAW_TYPE, strHighMaDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE vidyaDrawType = showVidya ? DRAW_LINE : DRAW_NONE;
|
||||
SetIndexBuffer(vidyaBufferIndex, vidyaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(vidyaPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(vidyaPlotBufferIndex, PLOT_SHOW_DATA, showVidya);
|
||||
PlotIndexSetInteger(vidyaPlotBufferIndex, PLOT_DRAW_TYPE, vidyaDrawType);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
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] = emptyValue;
|
||||
strUpBuffer[barIndex] = emptyValue;
|
||||
strDownBuffer[barIndex] = emptyValue;
|
||||
strPriceBuffer[barIndex] = emptyValue;
|
||||
strLowMaBuffer[barIndex] = emptyValue;
|
||||
strHighMaBuffer[barIndex] = emptyValue;
|
||||
|
||||
//
|
||||
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 ...
|
||||
ENUM_X_PRICE mPType = ToXPrice(strAppliedTo);
|
||||
double price = GetAppliedPrice(
|
||||
mPType,
|
||||
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;
|
||||
}
|
||||
|
||||
//
|
||||
// Str Mid ...
|
||||
|
||||
//
|
||||
double iStrMid = strDownBuffer[bar_index] + ((strUpBuffer[bar_index] - strDownBuffer[bar_index]) / 2);
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,567 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Ocillator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XVolume
|
||||
// Description: Detect Bullish/Bearish Volumes ...
|
||||
//
|
||||
//
|
||||
// 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 XVolume Ocillator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121_XVOLUME"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Makret ...
|
||||
input group "Market";
|
||||
input int maLength = 14; // Moving Averge Length
|
||||
input ENUM_X_MA_METHOD maMethod = X_MA_MODE_EMA; // Moving Averge Method
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
input bool showBullishVolume = true; // Show Bullish Volume
|
||||
input bool showBullishVolumeMa = true; // Show Bullish Volume Moving Average
|
||||
input bool showBearishVolume = true; // Show Bearish Volume
|
||||
input bool showBearishVolumeMa = true; // Show Bearish Volume Moving Average
|
||||
|
||||
//
|
||||
// Buffers Props ...
|
||||
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 6
|
||||
#property indicator_plots 4
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define bullishVolumeBufferIndex 0
|
||||
double bullishVolumeBuffer[];
|
||||
|
||||
#property indicator_label1 "Bullish Volume"
|
||||
#property indicator_type1 DRAW_HISTOGRAM
|
||||
#property indicator_color1 clrLime
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
#define bullishVolumeMaBufferIndex 1
|
||||
double bullishVolumeMaBuffer[];
|
||||
|
||||
#property indicator_label2 "Bullish Volume MA"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrLime
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#define bearishVolumeBufferIndex 2
|
||||
double bearishVolumeBuffer[];
|
||||
|
||||
#property indicator_label3 "Bearish Volume"
|
||||
#property indicator_type3 DRAW_HISTOGRAM
|
||||
#property indicator_color3 clrRed
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
#define bearishVolumeMaBufferIndex 3
|
||||
double bearishVolumeMaBuffer[];
|
||||
|
||||
#property indicator_label4 "Bearish Volume MA"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrRed
|
||||
#property indicator_style4 STYLE_SOLID
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
#define mLastBufferIndex 3
|
||||
|
||||
//
|
||||
#define rawBullishVolumeBufferIndex mLastBufferIndex + 1
|
||||
double rawBullishVolumeBuffer[];
|
||||
|
||||
//
|
||||
#define rawBearishVolumeBufferIndex mLastBufferIndex + 2
|
||||
double rawBearishVolumeBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int firstBarIndex;
|
||||
|
||||
//
|
||||
// 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();
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||
|
||||
//
|
||||
// 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);
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
//
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = maLength > 0 &&
|
||||
IsValid(maMethod);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(0, maLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
|
||||
//
|
||||
// Volume ...
|
||||
ENUM_DRAW_TYPE bullishVolumeDrawType = showBullishVolume ? DRAW_HISTOGRAM : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(bullishVolumeBuffer, true);
|
||||
SetIndexBuffer(bullishVolumeBufferIndex, bullishVolumeBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(bullishVolumeBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(bullishVolumeBufferIndex, PLOT_SHOW_DATA, showBullishVolume);
|
||||
PlotIndexSetInteger(bullishVolumeBufferIndex, PLOT_DRAW_TYPE, bullishVolumeDrawType);
|
||||
|
||||
//
|
||||
// Average ...
|
||||
ENUM_DRAW_TYPE bullishVolumeMaDrawType = showBullishVolumeMa ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(bullishVolumeMaBuffer, true);
|
||||
SetIndexBuffer(bullishVolumeMaBufferIndex, bullishVolumeMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(bullishVolumeMaBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(bullishVolumeMaBufferIndex, PLOT_SHOW_DATA, showBullishVolumeMa);
|
||||
PlotIndexSetInteger(bullishVolumeMaBufferIndex, PLOT_DRAW_TYPE, bullishVolumeMaDrawType);
|
||||
|
||||
//
|
||||
// Bearish ...
|
||||
|
||||
//
|
||||
// Volume ...
|
||||
ENUM_DRAW_TYPE bearishVolumeDrawType = showBearishVolume ? DRAW_HISTOGRAM : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(bearishVolumeBuffer, true);
|
||||
SetIndexBuffer(bearishVolumeBufferIndex, bearishVolumeBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(bearishVolumeBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(bearishVolumeBufferIndex, PLOT_SHOW_DATA, showBearishVolume);
|
||||
PlotIndexSetInteger(bearishVolumeBufferIndex, PLOT_DRAW_TYPE, bearishVolumeDrawType);
|
||||
|
||||
//
|
||||
// Average ...
|
||||
ENUM_DRAW_TYPE bearishVolumeMaDrawType = showBearishVolumeMa ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(bearishVolumeMaBuffer, true);
|
||||
SetIndexBuffer(bearishVolumeMaBufferIndex, bearishVolumeMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(bearishVolumeMaBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(bearishVolumeMaBufferIndex, PLOT_SHOW_DATA, showBearishVolumeMa);
|
||||
PlotIndexSetInteger(bearishVolumeMaBufferIndex, PLOT_DRAW_TYPE, bearishVolumeMaDrawType);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(rawBullishVolumeBuffer, true);
|
||||
SetIndexBuffer(rawBullishVolumeBufferIndex, rawBullishVolumeBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(rawBearishVolumeBuffer, true);
|
||||
SetIndexBuffer(rawBearishVolumeBufferIndex, rawBearishVolumeBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
if (barsLimit == 0)
|
||||
{
|
||||
//
|
||||
barsLimit = ratesTotal;
|
||||
firstBarIndex = barsLimit - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
firstBarIndex = startCalculationForLastBars;
|
||||
}
|
||||
|
||||
//
|
||||
// bool canCalculate = true;
|
||||
bool canCalculate =
|
||||
bar_index <= barsLimit;
|
||||
if (canCalculate)
|
||||
{
|
||||
//
|
||||
CalculateValues(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBuffersZero(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
bullishVolumeBuffer[barIndex] = EMPTY_VALUE;
|
||||
bullishVolumeMaBuffer[barIndex] = EMPTY_VALUE;
|
||||
rawBullishVolumeBuffer[barIndex] = 0;
|
||||
|
||||
//
|
||||
bearishVolumeBuffer[barIndex] = EMPTY_VALUE;
|
||||
bearishVolumeMaBuffer[barIndex] = EMPTY_VALUE;
|
||||
rawBearishVolumeBuffer[barIndex] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Vales ...
|
||||
*
|
||||
* @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 CalculateValues(
|
||||
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[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Check Prev Bar ...
|
||||
//
|
||||
int lastBarIndex = bar_index + 1;
|
||||
bool isFirstBar =
|
||||
startCalculationForLastBars > 0
|
||||
? bar_index == startCalculationForLastBars
|
||||
: bar_index == firstBarIndex;
|
||||
|
||||
//
|
||||
XOHCL bar;
|
||||
bool has = bar.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index //
|
||||
);
|
||||
if (!has)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double iBullishVolume = 0;
|
||||
double iBearishVolume = 0;
|
||||
|
||||
//
|
||||
if (bar.IsBullish())
|
||||
{
|
||||
//
|
||||
iBullishVolume = (double)bar.volume;
|
||||
iBearishVolume = 0;
|
||||
}
|
||||
else if (bar.IsBearish())
|
||||
{
|
||||
//
|
||||
iBearishVolume = (double)bar.volume;
|
||||
iBullishVolume = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
double volume = ((double)bar.volume) / 2.0;
|
||||
iBullishVolume = volume;
|
||||
iBearishVolume = volume;
|
||||
}
|
||||
|
||||
//
|
||||
bullishVolumeBuffer[bar_index] =
|
||||
iBullishVolume == 0
|
||||
? EMPTY_VALUE
|
||||
: iBullishVolume;
|
||||
rawBullishVolumeBuffer[bar_index] = iBullishVolume;
|
||||
|
||||
//
|
||||
bearishVolumeBuffer[bar_index] =
|
||||
iBearishVolume == 0
|
||||
? EMPTY_VALUE
|
||||
: iBearishVolume;
|
||||
rawBearishVolumeBuffer[bar_index] = iBearishVolume;
|
||||
|
||||
//
|
||||
// Calculate Moving Averages ...
|
||||
|
||||
//
|
||||
int bullishMAsCount = iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
maLength,
|
||||
rawBullishVolumeBuffer,
|
||||
bullishVolumeMaBuffer,
|
||||
maMethod //
|
||||
);
|
||||
|
||||
//
|
||||
int bearishMAsCount = iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
maLength,
|
||||
rawBearishVolumeBuffer,
|
||||
bearishVolumeMaBuffer,
|
||||
maMethod //
|
||||
);
|
||||
|
||||
//
|
||||
bar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,712 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
ENUM_X_PRICE mPType = ToXPrice(vwapAppliedTo);
|
||||
double price = GetAppliedPrice(
|
||||
mPType,
|
||||
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 //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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,140 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// EURUSD:
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
X121 XCZone > EURUSDb,M5> BEARISH Zone Detected at: 2024.01.17 12:30:00
|
||||
X121 XCZone > EURUSDb,M5> BULLISH Zone Detected at: 2024.05.03 14:00:00
|
||||
X121 XCZone > EURUSDb,M5> BULLISH Zone Detected at: 2024.05.23 03:05:00
|
||||
X121 XCZone > EURUSDb,M5> BEARISH Zone Detected at: 2024.06.05 09:10:00
|
||||
X121 XCZone > EURUSDb,M5> BEARISH Zone Detected at: 2024.07.01 12:05:00
|
||||
X121 XCZone > EURUSDb,M5> BEARISH Zone Detected at: 2024.07.22 13:05:00
|
||||
X121 XCZone > EURUSDb,M5> BEARISH Zone Detected at: 2024.08.15 19:35:00
|
||||
X121 XCZone > EURUSDb,M5> BULLISH Zone Detected at: 2024.09.24 06:05:00
|
||||
X121 XCZone > EURUSDb,M5> BEARISH Zone Detected at: 2024.09.24 12:50:00
|
||||
X121 XCZone > EURUSDb,M5> BEARISH Zone Detected at: 2024.10.31 15:50:00
|
||||
X121 XCZone > EURUSDb,M5> BULLISH Zone Detected at: 2024.11.06 20:15:00
|
||||
X121 XCZone > EURUSDb,M5> BEARISH Zone Detected at: 2024.12.02 09:10:00
|
||||
X121 XCZone > EURUSDb,M5> BULLISH Zone Detected at: 2024.12.26 20:05:00
|
||||
X121 XCZone > EURUSDb,M5> BULLISH Zone Detected at: 2024.12.30 00:05:00
|
||||
X121 XCZone > EURUSDb,M5> BEARISH Zone Detected at: 2024.12.30 03:55:00
|
||||
X121 XCZone > EURUSDb,M5> BEARISH Zone Detected at: 2025.01.03 17:15:00
|
||||
X121 XCZone > EURUSDb,M5> BEARISH Zone Detected at: 2025.01.22 13:30:00
|
||||
X121 XCZone > EURUSDb,M5> BEARISH Zone Detected at: 2025.03.28 08:15:00
|
||||
X121 XCZone > EURUSDb,M5> BULLISH Zone Detected at: 2025.04.01 16:25:00
|
||||
X121 XCZone > EURUSDb,M5> BULLISH Zone Detected at: 2025.04.23 11:30:00
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// GBPUSD:
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
X121 XCZone > GBPUSDb,M5> BULLISH Zone Detected at: 2024.03.26 10:30:00
|
||||
X121 XCZone > GBPUSDb,M5> BULLISH Zone Detected at: 2024.04.12 20:45:00
|
||||
X121 XCZone > GBPUSDb,M5> BULLISH Zone Detected at: 2024.04.19 16:25:00
|
||||
X121 XCZone > GBPUSDb,M5> BULLISH Zone Detected at: 2024.05.03 03:45:00
|
||||
X121 XCZone > GBPUSDb,M5> BULLISH Zone Detected at: 2024.05.09 12:35:00
|
||||
X121 XCZone > GBPUSDb,M5> BULLISH Zone Detected at: 2024.05.23 03:10:00
|
||||
X121 XCZone > GBPUSDb,M5> BULLISH Zone Detected at: 2024.06.11 19:40:00
|
||||
X121 XCZone > GBPUSDb,M5> BULLISH Zone Detected at: 2024.07.01 11:15:00
|
||||
X121 XCZone > GBPUSDb,M5> BULLISH Zone Detected at: 2024.08.12 16:05:00
|
||||
X121 XCZone > GBPUSDb,M5> BEARISH Zone Detected at: 2024.08.16 17:05:00
|
||||
X121 XCZone > GBPUSDb,M5> BULLISH Zone Detected at: 2024.09.02 03:25:00
|
||||
X121 XCZone > GBPUSDb,M5> BULLISH Zone Detected at: 2024.11.06 20:15:00
|
||||
X121 XCZone > GBPUSDb,M5> BULLISH Zone Detected at: 2024.11.11 02:25:00
|
||||
X121 XCZone > GBPUSDb,M5> BULLISH Zone Detected at: 2024.11.11 11:55:00
|
||||
X121 XCZone > GBPUSDb,M5> BULLISH Zone Detected at: 2024.12.26 20:05:00
|
||||
X121 XCZone > GBPUSDb,M5> BULLISH Zone Detected at: 2025.01.27 23:10:00
|
||||
X121 XCZone > GBPUSDb,M5> BEARISH Zone Detected at: 2025.01.31 15:25:00
|
||||
X121 XCZone > GBPUSDb,M5> BULLISH Zone Detected at: 2025.03.14 07:00:00
|
||||
X121 XCZone > GBPUSDb,M5> BEARISH Zone Detected at: 2025.03.26 17:20:00
|
||||
X121 XCZone > GBPUSDb,M5> BULLISH Zone Detected at: 2025.04.02 17:35:00
|
||||
X121 XCZone > GBPUSDb,M5> BULLISH Zone Detected at: 2025.04.04 03:35:00
|
||||
X121 XCZone > GBPUSDb,M5> BULLISH Zone Detected at: 2025.04.24 21:45:00
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// USDCHF:
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
X121 XCZone > USDCHFb,M5> BULLISH Zone Detected at: 2024.03.12 04:10:00
|
||||
X121 XCZone > USDCHFb,M5> BULLISH Zone Detected at: 2024.03.12 14:55:00
|
||||
X121 XCZone > USDCHFb,M5> BEARISH Zone Detected at: 2024.04.18 08:30:00
|
||||
X121 XCZone > USDCHFb,M5> BULLISH Zone Detected at: 2024.06.10 10:25:00
|
||||
X121 XCZone > USDCHFb,M5> BEARISH Zone Detected at: 2024.07.31 12:40:00
|
||||
X121 XCZone > USDCHFb,M5> BULLISH Zone Detected at: 2024.11.05 14:15:00
|
||||
X121 XCZone > USDCHFb,M5> BEARISH Zone Detected at: 2025.02.03 10:25:00
|
||||
X121 XCZone > USDCHFb,M5> BULLISH Zone Detected at: 2025.03.28 10:35:00
|
||||
X121 XCZone > USDCHFb,M5> BULLISH Zone Detected at: 2025.05.05 14:35:00
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// DJ30.spot:
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
X121 XCZone > DJ30.spot,M5> BEARISH Zone Detected at: 2024.01.23 16:00:00
|
||||
X121 XCZone > DJ30.spot,M5> BULLISH Zone Detected at: 2024.03.18 10:55:00
|
||||
X121 XCZone > DJ30.spot,M5> BEARISH Zone Detected at: 2024.04.09 16:45:00
|
||||
X121 XCZone > DJ30.spot,M5> BULLISH Zone Detected at: 2024.06.14 14:25:00
|
||||
X121 XCZone > DJ30.spot,M5> BULLISH Zone Detected at: 2024.06.25 04:35:00
|
||||
X121 XCZone > DJ30.spot,M5> BULLISH Zone Detected at: 2024.09.09 18:35:00
|
||||
X121 XCZone > DJ30.spot,M5> BEARISH Zone Detected at: 2024.09.11 16:35:00
|
||||
X121 XCZone > DJ30.spot,M5> BULLISH Zone Detected at: 2024.09.20 06:40:00
|
||||
X121 XCZone > DJ30.spot,M5> BULLISH Zone Detected at: 2024.10.22 17:50:00
|
||||
X121 XCZone > DJ30.spot,M5> BEARISH Zone Detected at: 2025.03.11 14:10:00
|
||||
X121 XCZone > DJ30.spot,M5> BEARISH Zone Detected at: 2025.03.11 18:00:00
|
||||
X121 XCZone > DJ30.spot,M5> BEARISH Zone Detected at: 2025.05.01 18:45:00
|
||||
X121 XCZone > DJ30.spot,M5> BULLISH Zone Detected at: 2025.05.15 05:40:00
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// XAGUSD:
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
X121 XCZone > XAGUSDb,M5> BULLISH Zone Detected at: 2024.01.08 16:05:00
|
||||
X121 XCZone > XAGUSDb,M5> BEARISH Zone Detected at: 2024.02.13 05:10:00
|
||||
X121 XCZone > XAGUSDb,M5> BEARISH Zone Detected at: 2024.03.19 03:35:00
|
||||
X121 XCZone > XAGUSDb,M5> BULLISH Zone Detected at: 2024.03.22 02:20:00
|
||||
X121 XCZone > XAGUSDb,M5> BEARISH Zone Detected at: 2024.04.01 10:50:00
|
||||
X121 XCZone > XAGUSDb,M5> BULLISH Zone Detected at: 2024.04.15 13:00:00
|
||||
X121 XCZone > XAGUSDb,M5> BEARISH Zone Detected at: 2024.04.22 18:05:00
|
||||
X121 XCZone > XAGUSDb,M5> BULLISH Zone Detected at: 2024.05.08 17:15:00
|
||||
X121 XCZone > XAGUSDb,M5> BEARISH Zone Detected at: 2024.07.11 22:55:00
|
||||
X121 XCZone > XAGUSDb,M5> BEARISH Zone Detected at: 2024.07.25 12:05:00
|
||||
X121 XCZone > XAGUSDb,M5> BEARISH Zone Detected at: 2024.07.26 09:15:00
|
||||
X121 XCZone > XAGUSDb,M5> BEARISH Zone Detected at: 2024.08.15 22:35:00
|
||||
X121 XCZone > XAGUSDb,M5> BEARISH Zone Detected at: 2024.08.29 22:50:00
|
||||
X121 XCZone > XAGUSDb,M5> BULLISH Zone Detected at: 2024.09.20 03:30:00
|
||||
X121 XCZone > XAGUSDb,M5> BEARISH Zone Detected at: 2024.10.01 10:10:00
|
||||
X121 XCZone > XAGUSDb,M5> BULLISH Zone Detected at: 2024.11.28 06:20:00
|
||||
X121 XCZone > XAGUSDb,M5> BEARISH Zone Detected at: 2025.01.15 04:35:00
|
||||
X121 XCZone > XAGUSDb,M5> BEARISH Zone Detected at: 2025.02.11 03:25:00
|
||||
X121 XCZone > XAGUSDb,M5> BULLISH Zone Detected at: 2025.02.17 18:55:00
|
||||
X121 XCZone > XAGUSDb,M5> BEARISH Zone Detected at: 2025.03.20 15:10:00
|
||||
X121 XCZone > XAGUSDb,M5> BULLISH Zone Detected at: 2025.05.05 05:30:00
|
||||
X121 XCZone > XAGUSDb,M5> BULLISH Zone Detected at: 2025.05.12 14:05:00
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// USDJPY:
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
X121 XCZone > USDJPYb,M5> BULLISH Zone Detected at: 2024.01.19 14:20:00
|
||||
X121 XCZone > USDJPYb,M5> BEARISH Zone Detected at: 2024.02.02 20:20:00
|
||||
X121 XCZone > USDJPYb,M5> BULLISH Zone Detected at: 2024.03.28 17:55:00
|
||||
X121 XCZone > USDJPYb,M5> BULLISH Zone Detected at: 2024.06.26 16:25:00
|
||||
X121 XCZone > USDJPYb,M5> BEARISH Zone Detected at: 2024.07.11 10:20:00
|
||||
X121 XCZone > USDJPYb,M5> BEARISH Zone Detected at: 2024.08.30 01:10:00
|
||||
X121 XCZone > USDJPYb,M5> BULLISH Zone Detected at: 2024.09.23 14:25:00
|
||||
X121 XCZone > USDJPYb,M5> BEARISH Zone Detected at: 2024.10.07 06:30:00
|
||||
X121 XCZone > USDJPYb,M5> BEARISH Zone Detected at: 2024.11.13 21:20:00
|
||||
X121 XCZone > USDJPYb,M5> BULLISH Zone Detected at: 2024.12.18 00:20:00
|
||||
X121 XCZone > USDJPYb,M5> BEARISH Zone Detected at: 2025.01.27 02:20:00
|
||||
X121 XCZone > USDJPYb,M5> BULLISH Zone Detected at: 2025.03.27 08:25:00
|
||||
X121 XCZone > USDJPYb,M5> BULLISH Zone Detected at: 2025.05.08 09:20:00
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// BTCUSD:
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
X121 XCZone > BTCUSD,M5> BULLISH Zone Detected at: 2024.06.05 15:45:00
|
||||
X121 XCZone > BTCUSD,M5> BULLISH Zone Detected at: 2024.06.12 05:00:00
|
||||
X121 XCZone > BTCUSD,M5> BEARISH Zone Detected at: 2024.06.19 18:30:00
|
||||
X121 XCZone > BTCUSD,M5> BULLISH Zone Detected at: 2024.07.30 00:40:00
|
||||
X121 XCZone > BTCUSD,M5> BEARISH Zone Detected at: 2024.08.08 21:50:00
|
||||
X121 XCZone > BTCUSD,M5> BULLISH Zone Detected at: 2024.08.19 19:55:00
|
||||
X121 XCZone > BTCUSD,M5> BULLISH Zone Detected at: 2024.10.06 00:15:00
|
||||
X121 XCZone > BTCUSD,M5> BULLISH Zone Detected at: 2024.10.17 03:35:00
|
||||
X121 XCZone > BTCUSD,M5> BULLISH Zone Detected at: 2024.11.12 16:50:00
|
||||
X121 XCZone > BTCUSD,M5> BULLISH Zone Detected at: 2024.11.18 16:15:00
|
||||
X121 XCZone > BTCUSD,M5> BULLISH Zone Detected at: 2024.12.17 01:50:00
|
||||
X121 XCZone > BTCUSD,M5> BEARISH Zone Detected at: 2024.12.17 17:15:00
|
||||
X121 XCZone > BTCUSD,M5> BEARISH Zone Detected at: 2024.12.27 04:45:00
|
||||
X121 XCZone > BTCUSD,M5> BEARISH Zone Detected at: 2025.01.22 09:35:00
|
||||
X121 XCZone > BTCUSD,M5> BULLISH Zone Detected at: 2025.02.12 18:45:00
|
||||
X121 XCZone > BTCUSD,M5> BULLISH Zone Detected at: 2025.03.19 09:25:00
|
||||
X121 XCZone > BTCUSD,M5> BEARISH Zone Detected at: 2025.03.19 22:35:00
|
||||
X121 XCZone > BTCUSD,M5> BEARISH Zone Detected at: 2025.04.13 15:25:00
|
||||
X121 XCZone > BTCUSD,M5> BULLISH Zone Detected at: 2025.04.15 03:35:00
|
||||
X121 XCZone > BTCUSD,M5> BULLISH Zone Detected at: 2025.05.16 02:35:00
|
||||
@@ -0,0 +1,221 @@
|
||||
|
||||
//
|
||||
// Detect Signals Based On XPV Indicator Golden Zones ...
|
||||
//
|
||||
bool HasTMPConditions(
|
||||
ENUM_X_CYCLES cycle,
|
||||
XBoxZone &box,
|
||||
ENUM_X_DIRECTION &dir,
|
||||
X121SMCStrategySignalProviderData &provider,
|
||||
int barIndex = 0 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
box.Clean();
|
||||
dir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
// Fil Selected Data ...
|
||||
XPOIState cState;
|
||||
X121Conditions cXConditions;
|
||||
XPOIStateEvents cStateEvents;
|
||||
XC121SMCCycleHelper *cHelper;
|
||||
X121SMCCycleConditions cConditions;
|
||||
result = provider.SelectCycle(
|
||||
cycle,
|
||||
cState,
|
||||
cStateEvents,
|
||||
cXConditions,
|
||||
cHelper,
|
||||
cConditions //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
cState.Clean();
|
||||
ZeroMemory(cHelper);
|
||||
cConditions.Clean();
|
||||
cXConditions.Clean();
|
||||
cStateEvents.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Normalize Args ...
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
int idx = -1;
|
||||
int count = 0;
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
int zIDX = barIndex;
|
||||
int cIDX = zIDX + 1;
|
||||
int pIDX = cIDX + 1;
|
||||
int ppIDX = pIDX + 1;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
XOHCL cBar;
|
||||
XOHCL pBar;
|
||||
XOHCL pPBar;
|
||||
|
||||
//
|
||||
// Initial Bars ...
|
||||
result = zBar.Init(
|
||||
cState.symbol,
|
||||
cState.period,
|
||||
barIndex //
|
||||
);
|
||||
result =
|
||||
result &&
|
||||
zBar.GetPreviousBar(cBar);
|
||||
result =
|
||||
result &&
|
||||
cBar.GetPreviousBar(pBar);
|
||||
result =
|
||||
result &&
|
||||
pBar.GetPreviousBar(pPBar);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
cState.Clean();
|
||||
ZeroMemory(cHelper);
|
||||
cConditions.Clean();
|
||||
cXConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Checking Conditions ...
|
||||
|
||||
//
|
||||
// Summarize Conditions ...
|
||||
|
||||
//
|
||||
isBullish =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Filling Requirements ...
|
||||
result =
|
||||
isBullish ||
|
||||
isBearish;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
dir =
|
||||
isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
box.dir = dir;
|
||||
box.from = pPBar.time;
|
||||
box.to = TimeCurrent();
|
||||
box.symbol = cBar.symbol;
|
||||
box.period = cBar.period;
|
||||
|
||||
//
|
||||
double points = GetPoints(box.symbol);
|
||||
|
||||
//
|
||||
// Usually is Preffered SL ...
|
||||
double pivot = 0;
|
||||
|
||||
//
|
||||
// Usually is Current Price or Entry Price ...
|
||||
double point = GetEntry(
|
||||
cBar.symbol,
|
||||
dir //
|
||||
);
|
||||
|
||||
//
|
||||
box.upper =
|
||||
isBullish
|
||||
? point
|
||||
: pivot;
|
||||
|
||||
//
|
||||
box.lower =
|
||||
isBullish
|
||||
? pivot
|
||||
: point;
|
||||
|
||||
//
|
||||
XCPOIDrawer *drawer = provider.visionCycleHelper.mPOIDrawer;
|
||||
bool drawBoxes = true;
|
||||
if (drawBoxes)
|
||||
{
|
||||
//
|
||||
if (box.IsValid()) {
|
||||
//
|
||||
XCBoxObject *iObj;
|
||||
bool isCreated = drawer.DrawBox(
|
||||
box,
|
||||
iObj //
|
||||
);
|
||||
|
||||
//
|
||||
if (isCreated) {
|
||||
//
|
||||
// TODO: ...
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check All Conditions ...
|
||||
result =
|
||||
box.IsValid() &&
|
||||
HasDirection(dir) &&
|
||||
(isBullish ||
|
||||
isBearish);
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
pPBar.Clean();
|
||||
cState.Clean();
|
||||
cConditions.Clean();
|
||||
cConditions.Clean();
|
||||
ZeroMemory(cHelper);
|
||||
cStateEvents.Clean();
|
||||
cXConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
|
||||
//
|
||||
bool DetectPivot(
|
||||
int barIndex,
|
||||
XOHCL &zBar,
|
||||
XOHCL &cBar,
|
||||
XOHCL &pBar,
|
||||
XOHCL &p2Bar,
|
||||
XCAEAConditions &conditions //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result =
|
||||
//
|
||||
barIndex >= 0 &&
|
||||
zBar.IsValid() &&
|
||||
cBar.IsValid() &&
|
||||
pBar.IsValid() &&
|
||||
p2Bar.IsValid() &&
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Requirements ...
|
||||
|
||||
//
|
||||
int zIDX = 0;
|
||||
int cIDX = zIDX + 1;
|
||||
int pIDX = cIDX + 1;
|
||||
int p2IDX = pIDX + 1;
|
||||
|
||||
//
|
||||
XCAPviot pivot;
|
||||
datetime cTime = zBar.time;
|
||||
string symbol = zBar.symbol;
|
||||
string period = zBar.period;
|
||||
|
||||
//
|
||||
// Reading Conditional Values ...
|
||||
|
||||
//
|
||||
// Prepare Conditinal Conditions ...
|
||||
|
||||
//
|
||||
bool hasStartCondition = false;
|
||||
bool hasContinuationCondition = false;
|
||||
bool hasEndCondition = false;
|
||||
|
||||
//
|
||||
// ReInstance Pivot ...
|
||||
if (hasStartConditions)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate and Fill Pivot Requirements ...
|
||||
if (hasContinuationCondition)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
// End up Pivot and Store it ...
|
||||
if (hasEndCondition)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
pivot.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
@@ -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.SendAlert(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.SendAlert(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.SendAlert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Weekly Report ....
|
||||
if (eaReportNewWeeks &&
|
||||
eaTimeTracker.IsNewWeek())
|
||||
{
|
||||
//
|
||||
string msg = "New Week ...";
|
||||
|
||||
//
|
||||
eaAlert.SendAlert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Daily Report ....
|
||||
if (eaReportNewDays &&
|
||||
eaTimeTracker.IsNewDay())
|
||||
{
|
||||
//
|
||||
string msg = "New Day ...";
|
||||
|
||||
//
|
||||
eaAlert.SendAlert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Hourly Report ....
|
||||
if (eaReportNewHours &&
|
||||
eaTimeTracker.IsNewHour())
|
||||
{
|
||||
//
|
||||
string msg = "New Hour ...";
|
||||
|
||||
//
|
||||
eaAlert.SendAlert(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.SendAlert(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.SendAlert(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.SendAlert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Weekly Report ....
|
||||
if (eaReportNewWeeks &&
|
||||
eaTimeTracker.IsNewWeek())
|
||||
{
|
||||
//
|
||||
string msg = "New Week ...";
|
||||
|
||||
//
|
||||
eaAlert.SendAlert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Daily Report ....
|
||||
if (eaReportNewDays &&
|
||||
eaTimeTracker.IsNewDay())
|
||||
{
|
||||
//
|
||||
string msg = "New Day ...";
|
||||
|
||||
//
|
||||
eaAlert.SendAlert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Hourly Report ....
|
||||
if (eaReportNewHours &&
|
||||
eaTimeTracker.IsNewHour())
|
||||
{
|
||||
//
|
||||
string msg = "New Hour ...";
|
||||
|
||||
//
|
||||
eaAlert.SendAlert(msg);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,187 @@
|
||||
|
||||
//
|
||||
// Senario 3:
|
||||
// ----------
|
||||
bool useSenario3 = false;
|
||||
bool isSenario3Happend = false;
|
||||
bool isSenario3Bullish = false;
|
||||
bool isSenario3Bearish = false;
|
||||
if (useSenario3)
|
||||
{
|
||||
//
|
||||
// Senario 3 Bullish Conditions ...
|
||||
isSenario3Bullish = false;
|
||||
|
||||
//
|
||||
// Senario 3 Bearish Conditions ...
|
||||
isSenario3Bearish = false;
|
||||
|
||||
//
|
||||
// Filling Requirements using Senario 3 ...
|
||||
isSenario3Happend =
|
||||
isSenario3Bullish ||
|
||||
isSenario3Bearish;
|
||||
if (isSenario3Happend)
|
||||
{
|
||||
//
|
||||
dir =
|
||||
isSenario3Bullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
box.dir = dir;
|
||||
box.to = TimeCurrent();
|
||||
box.symbol = provider
|
||||
.decisionXConditions
|
||||
.symbol;
|
||||
box.period = provider
|
||||
.decisionXConditions
|
||||
.period;
|
||||
|
||||
//
|
||||
int fromIDX = -1;
|
||||
if (isSenario3Bullish)
|
||||
{
|
||||
//
|
||||
double vale = provider
|
||||
.decisionXConditions
|
||||
.valesBuffer[cIDX];
|
||||
|
||||
//
|
||||
box.lower = vale;
|
||||
|
||||
//
|
||||
box.upper = provider
|
||||
.decisionXConditions
|
||||
.valesGoldenBuffer[cIDX];
|
||||
|
||||
//
|
||||
int lowerValeIDX = -1;
|
||||
double lowerVale = provider
|
||||
.decisionCycleHelper
|
||||
.mX121Helper
|
||||
.xpvHelper
|
||||
.GetLowerVale(
|
||||
lowerValeIDX,
|
||||
vale,
|
||||
cBar.Index() //
|
||||
);
|
||||
|
||||
//
|
||||
int higherValeIDX = -1;
|
||||
double higherVale = provider
|
||||
.decisionCycleHelper
|
||||
.mX121Helper
|
||||
.xpvHelper
|
||||
.GetHigherVale(
|
||||
higherValeIDX,
|
||||
vale,
|
||||
cBar.Index() //
|
||||
);
|
||||
|
||||
//
|
||||
if (IsValidIndex(lowerValeIDX) &&
|
||||
IsValidIndex(higherValeIDX))
|
||||
{
|
||||
//
|
||||
fromIDX =
|
||||
lowerValeIDX < higherValeIDX
|
||||
? lowerValeIDX
|
||||
: higherValeIDX;
|
||||
}
|
||||
else if (IsValidIndex(lowerValeIDX) &&
|
||||
!IsValidIndex(higherValeIDX))
|
||||
{
|
||||
//
|
||||
fromIDX = lowerValeIDX;
|
||||
}
|
||||
else if (!IsValidIndex(lowerValeIDX) &&
|
||||
IsValidIndex(higherValeIDX))
|
||||
{
|
||||
//
|
||||
fromIDX = higherValeIDX;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
double peak = provider
|
||||
.decisionXConditions
|
||||
.peaksBuffer[cIDX];
|
||||
|
||||
//
|
||||
box.upper = peak;
|
||||
|
||||
//
|
||||
box.lower = provider
|
||||
.decisionXConditions
|
||||
.peaksGoldenBuffer[cIDX];
|
||||
|
||||
//
|
||||
int lowerPeakIDX = -1;
|
||||
double lowerPeak = provider
|
||||
.decisionCycleHelper
|
||||
.mX121Helper
|
||||
.xpvHelper
|
||||
.GetLowerPeak(
|
||||
lowerPeakIDX,
|
||||
peak,
|
||||
cBar.Index() //
|
||||
);
|
||||
|
||||
//
|
||||
int higherPeakIDX = -1;
|
||||
double higherPeak = provider
|
||||
.decisionCycleHelper
|
||||
.mX121Helper
|
||||
.xpvHelper
|
||||
.GetHigherPeak(
|
||||
higherPeakIDX,
|
||||
peak,
|
||||
cBar.Index() //
|
||||
);
|
||||
|
||||
//
|
||||
if (IsValidIndex(lowerPeakIDX) &&
|
||||
IsValidIndex(higherPeakIDX))
|
||||
{
|
||||
//
|
||||
fromIDX =
|
||||
lowerPeakIDX < higherPeakIDX
|
||||
? lowerPeakIDX
|
||||
: higherPeakIDX;
|
||||
}
|
||||
else if (IsValidIndex(lowerPeakIDX) &&
|
||||
!IsValidIndex(higherPeakIDX))
|
||||
{
|
||||
//
|
||||
fromIDX = lowerPeakIDX;
|
||||
}
|
||||
else if (!IsValidIndex(lowerPeakIDX) &&
|
||||
IsValidIndex(higherPeakIDX))
|
||||
{
|
||||
//
|
||||
fromIDX = higherPeakIDX;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (IsValidIndex(fromIDX))
|
||||
{
|
||||
//
|
||||
box.from = iTime(
|
||||
zBar.symbol,
|
||||
zBar.period,
|
||||
fromIDX //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
box.from = pBar.time;
|
||||
}
|
||||
|
||||
//
|
||||
signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_BOX;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,431 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XTest MQL5 Expert Advisor
|
||||
// -------------------------------------------------
|
||||
// Name: XRRToolsEA
|
||||
// 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 XRRToolsEA"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "XRRTools"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.x-alert.class.mq5"
|
||||
#include "../Classes/x-saherelm.x-rm.panel.class.mq5"
|
||||
#include "../Classes/x-saherelm.x-trade.class.mq5"
|
||||
#include "../Helpers/x-saherelm.x121.xcc.helper.mq5"
|
||||
#include "../Helpers/x-saherelm.x121.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
|
||||
|
||||
//
|
||||
// Define Local Variables ...
|
||||
|
||||
//
|
||||
string eaLogTag; // EA Log Prefix ...
|
||||
XCAlert *eaAlert; // Alert Provider for Expert Adviser ...
|
||||
XCTrade *eaTrader; // Trader of Expert Adviser ...
|
||||
XCRMPanel eaMainWindow; // Main Window ...
|
||||
XCX121XCTHelper *eaCTHelper; // Bar Timer Indicator Helper class ...
|
||||
XCX121XCCHelper *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.SendAlert(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.SendAlert(msg);
|
||||
|
||||
//
|
||||
// Destroy all EA Requirements ...
|
||||
DestroyEA();
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
UpdateGUI();
|
||||
}
|
||||
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Event Handlers ...
|
||||
|
||||
/**
|
||||
* Handle StopLoss Triggered Positions ...
|
||||
*
|
||||
* @param deal: XDeal ...
|
||||
*/
|
||||
void OnStopLossTriggered(const XDeal &deal)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Take Profit Triggered Positions ...
|
||||
*
|
||||
* @param deal: XDeal ...
|
||||
*/
|
||||
void OnTakeProfitTriggered(const XDeal &deal)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 //
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
X121XCTInputs ctInputs;
|
||||
ctInputs.Default(); // Default Configurations ...
|
||||
eaCTHelper = new XCX121XCTHelper();
|
||||
result = eaCTHelper.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
ctInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Bar Styles ...
|
||||
X121XCCInputs ccInputs;
|
||||
ccInputs.Default(); // Default Configurations ...
|
||||
eaCCHelper = new XCX121XCCHelper();
|
||||
result = eaCCHelper.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
ccInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Create Instance of Alert Class and Configure it ...
|
||||
eaAlert = new XCAlert();
|
||||
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 XCTrade(
|
||||
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 ...
|
||||
);
|
||||
|
||||
//
|
||||
// Try To Run Main Window ...
|
||||
if (result)
|
||||
{
|
||||
eaMainWindow.Run();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update GUI based on Each Ticks ...
|
||||
*/
|
||||
void UpdateGUI()
|
||||
{
|
||||
//
|
||||
eaMainWindow.UpdateState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy all Initialized GUi Requirements ...
|
||||
*/
|
||||
void DestroyGUI()
|
||||
{
|
||||
//
|
||||
eaMainWindow.Destroy();
|
||||
}
|
||||
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,606 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Expert Advisor
|
||||
// -------------------------------------------------
|
||||
// Name: X121XCATB
|
||||
// Description: X121XCATB base Expert Advisor ...
|
||||
//
|
||||
// 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 X121XCATB based Expert Advisor"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "X121XCATBEA"
|
||||
|
||||
//
|
||||
// Importts ...
|
||||
#include "../XCATBEA/Classes/xcatbea.expert.class.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Common ...
|
||||
input group "Common";
|
||||
input long eaMagicNumber = 1694056; // Magic Number
|
||||
input int eaSlippage = 10; // Slippgae
|
||||
input string eaLogSuffix = ""; // Log Suffix
|
||||
|
||||
//
|
||||
// Detector ...
|
||||
input group "Detector";
|
||||
|
||||
//
|
||||
// Validating ...
|
||||
input group "Validations";
|
||||
input bool eaForceHasSwing = false; // Force Block to Has Propper Swing
|
||||
input bool eaForceOBBarType = false; // Force Order Block to Has InDirectional Bars
|
||||
input int eaMinRequiredOBBar = 0; // Min Required OB Bar
|
||||
input bool eaForceFVGBarType = false; // Force Fair Value Gaps Bars Type
|
||||
input int eaLiquidityLoopback = 0; // Liquidity Detection Loopback
|
||||
input double eaMaxAllowedRange = 0.0; // Max Allowed Order Block Range
|
||||
input double eaMinAllowedRange = 0.0; // Min Allowed Order Block Range
|
||||
input bool eaForceHasFLiquidity = false; // Force Order Block To Has Reversal Liquidity
|
||||
input bool eaForceHasRLiquidity = false; // Force Order Block to Has Following Liquidity
|
||||
input bool eaValidateGapSequence = false; // Validate Fair Value Gaps Bar Sequences
|
||||
input int eaMinAllowedBlockLength = 0; // Min Allowed Block Length
|
||||
input bool eaValidateBlockEdgeBreakout = false; // Validate Order Block Edge Breakeout
|
||||
|
||||
//
|
||||
// Filtering ...
|
||||
input group "Filters";
|
||||
input bool eaFilterBasedOnKI = false; // Filter Based On KI Flats
|
||||
input bool eaFilterBasedOnPV = false; // Filter Based On PV
|
||||
input int eaBosLoopback = 0; // PV Based Filtering BOS Lookup
|
||||
input bool eaFilterBasedOnSar = false; // Filter Based On SAR
|
||||
input bool eaForceSarSwitched = false; // SAR Switched on Sides for Filtering
|
||||
input bool eaForceSarOnBothSide = false; // SAR Check on Both Sides for Filtering
|
||||
input bool eaForceSarHasBreakout = false; // SAR Must Breakout
|
||||
input bool eaForceSarHasReversalSide = false; // SAR Must Has Reversal Direction
|
||||
input bool eaFilterBasedOnRSI = false; // Filter Based On RSI
|
||||
input bool eaForceHasRSITrending = false; // RSI Must Has Trending
|
||||
input bool eaForceHasRSIVPattern = false; // RSI Must Has Pattern
|
||||
input bool eaForceHasRSICrossing = false; // RSI Must Has Crossing Levels
|
||||
input bool eaFilterBasedOnADX = false; // Filter Based On ADX
|
||||
input bool eaForceHasADXTrending = false; // ADX Must Has Trending
|
||||
input bool eaForceHasADXCrossing = false; // ADX Must Has Crossing +DI/-DI
|
||||
input bool eaFilterBasedOnATR = false; // Filter Based On ATR
|
||||
input bool eaForceHasATRTrending = false; // ATR Must Has Trending
|
||||
input bool eaForceHasATRBreakout = false; // ATR Must Has Breakout
|
||||
input bool eaFilterBasedOnTrend = false; // Filter Based On Trend
|
||||
input bool eaForceHasTrendDir = false; // TREND Must Has Following Direction
|
||||
input bool eaForceHasTrendPlace = false; // TREND Place Based Filtering
|
||||
input bool eaForceHasTrendChange = false; // TREND Change Filtering
|
||||
input bool eaForceHasTrendTrending = false; // TREND Must Has Trending
|
||||
input bool eaForceHasTrendRejection = false; // TREND Line Must Rejected
|
||||
input bool eaForceHasTrendLineInside = false; // TREND Line has Inside
|
||||
input bool eaForceHasTrendDirOnBothSide = false; // TREND Must Has Following Direction in Both Side
|
||||
input bool eaFilterBasedOnDelta = false; // Filter Based On Delta
|
||||
input bool eaFilterBasedOnVolume = false; // Filter Based On Volume
|
||||
input bool eaFilterBasedOnSignalBar = false; // Filter Based on Signal Bar
|
||||
input bool eaFilterBasedOnHKSignalBar = false; // Filter Based On HK Signal Bar
|
||||
|
||||
//
|
||||
// Signal ...
|
||||
input group "Signal";
|
||||
input int eaSignalR2R = 2; // Risk Reward Ratio
|
||||
input double eaSLATRMultiplier = 0; // ATR Multiplier for SL
|
||||
|
||||
//
|
||||
// Volume ...
|
||||
input group "Volume";
|
||||
input ENUM_X_VOLUME_SELECT_TYPE eaVolumeSelect = X_VOLUME_EQUITY; // Volume Applying Type
|
||||
input double eaStaticVoluem = 0.0; // Static Volume
|
||||
input double eaDynamicVolumeStepBalance = 0.0; // Step of Balance for Increase Volume
|
||||
input double eaDynamicVolumeStepVolume = X_MIN_VOLUME; // Step of Volume Increasing
|
||||
input double eaConstantRiskBalance = 0.0; // Constant Risk Balance per Trade
|
||||
input double eaConstantPercent = 0.5; // Constant Percent of Balance Per Trade
|
||||
input double eaConstantBalance = 0.0; // Constant Balance for Calculations
|
||||
|
||||
//
|
||||
// Management ...
|
||||
// eaSymbols => comma separated Symbols for Trading, use Default if not Provided ...
|
||||
// eaSessions => (ST_04:00_08:30),(TL_10:30_12:00),(NY_16:00_19:00)
|
||||
input group "Management";
|
||||
input string eaSymbols = ""; // Allowed Trading Symbols
|
||||
input bool eaAllowGuards = false; // Allow Guards
|
||||
input bool eaAllowTrade = true; // Allow Trade on Signals
|
||||
input bool eaAllowLongs = true; // Allow Long Trades
|
||||
input bool eaAllowShorts = true; // Allow Short Trades
|
||||
input string eaSessions = ""; // Active Sessions
|
||||
input ENUM_XCATBEA_TRADE_RESTRICTION_PERIOD eaRestrictionsPeriod = XCATBEA_TRADE_RESTRICATION_NONE; // Restrictions Period
|
||||
input int eaMaxAllowedTPs = 0; // Max Allowed TP(s) in Restrictions Period
|
||||
input int eaMaxAllowedSLs = 0; // Max Allowed SL(s) in Restrictions Period
|
||||
input int eaMaxAllowedTrades = 0; // Max Allowed Trades in Restrictions Period
|
||||
input int eaMaxAllowedPositions = 5; // Max Allowed Same Time Trades
|
||||
input double eaMaxAllowedSpread = 25; // Max Allowed Spread For Trade
|
||||
input double eaMaxAllowedDrawdownFactor = 0.3; // Max Allowed DrawDown for Trade
|
||||
input string eaCloseAllOpenTradesAt = ""; // Close All Open Trades per Day At Specified Time
|
||||
|
||||
//
|
||||
// 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 = true; // 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
|
||||
input bool eaReportTrades = true; // Report Trades
|
||||
input bool eaReportSignals = true; // Report Signals
|
||||
input bool eaReportProtector = true; // Report Protector Actions
|
||||
input bool eaReportAfterTradesBalance = true; // Report Balance after a Trade Finished
|
||||
|
||||
//
|
||||
// Collector ...
|
||||
input group "Collector";
|
||||
input bool eaSaveTrades = false; // Save Trades
|
||||
input bool eaSaveSignals = false; // Save Signals
|
||||
input bool eaSaveWins = false; // Save Winning Conditions
|
||||
input bool eaSaveLosts = false; // Save Lost Conditions
|
||||
|
||||
//
|
||||
// Variables ...
|
||||
|
||||
//
|
||||
XCXCATBEAExpert *eaExpert;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Preparing Tags ...
|
||||
string eaTag =
|
||||
(IsValid(eaLogSuffix)
|
||||
? eaLogSuffix + "_"
|
||||
: "") +
|
||||
ShortName;
|
||||
|
||||
//
|
||||
// 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 XCXCATBEAExpert();
|
||||
|
||||
//
|
||||
// Setting All Inputs to Expert Adviser Class ...
|
||||
|
||||
//
|
||||
// Common ...
|
||||
eaExpert.eaMagicNumber = eaMagicNumber;
|
||||
eaExpert.eaSlippage = eaSlippage;
|
||||
eaExpert.eaLogSuffix = eaTag;
|
||||
|
||||
//
|
||||
// Detector ...
|
||||
|
||||
//
|
||||
// Validations ...
|
||||
eaExpert.eaForceHasSwing = eaForceHasSwing;
|
||||
eaExpert.eaForceOBBarType = eaForceOBBarType;
|
||||
eaExpert.eaMinRequiredOBBar = eaMinRequiredOBBar;
|
||||
eaExpert.eaForceFVGBarType = eaForceFVGBarType;
|
||||
eaExpert.eaLiquidityLoopback = eaLiquidityLoopback;
|
||||
eaExpert.eaMaxAllowedRange = eaMaxAllowedRange;
|
||||
eaExpert.eaMinAllowedRange = eaMinAllowedRange;
|
||||
eaExpert.eaForceHasFLiquidity = eaForceHasFLiquidity;
|
||||
eaExpert.eaForceHasRLiquidity = eaForceHasRLiquidity;
|
||||
eaExpert.eaValidateGapSequence = eaValidateGapSequence;
|
||||
eaExpert.eaMinAllowedBlockLength = eaMinAllowedBlockLength;
|
||||
eaExpert.eaValidateBlockEdgeBreakout = eaValidateBlockEdgeBreakout;
|
||||
|
||||
//
|
||||
// Filters ...
|
||||
eaExpert.eaFilterBasedOnKI = eaFilterBasedOnKI;
|
||||
eaExpert.eaFilterBasedOnPV = eaFilterBasedOnPV;
|
||||
eaExpert.eaBosLoopback = eaBosLoopback;
|
||||
eaExpert.eaFilterBasedOnSar = eaFilterBasedOnSar;
|
||||
eaExpert.eaForceSarSwitched = eaForceSarSwitched;
|
||||
eaExpert.eaForceSarOnBothSide = eaForceSarOnBothSide;
|
||||
eaExpert.eaForceSarHasBreakout = eaForceSarHasBreakout;
|
||||
eaExpert.eaForceSarHasReversalSide = eaForceSarHasReversalSide;
|
||||
eaExpert.eaFilterBasedOnRSI = eaFilterBasedOnRSI;
|
||||
eaExpert.eaForceHasRSITrending = eaForceHasRSITrending;
|
||||
eaExpert.eaForceHasRSIVPattern = eaForceHasRSIVPattern;
|
||||
eaExpert.eaForceHasRSICrossing = eaForceHasRSICrossing;
|
||||
eaExpert.eaFilterBasedOnADX = eaFilterBasedOnADX;
|
||||
eaExpert.eaForceHasADXTrending = eaForceHasADXTrending;
|
||||
eaExpert.eaForceHasADXCrossing = eaForceHasADXCrossing;
|
||||
eaExpert.eaFilterBasedOnATR = eaFilterBasedOnATR;
|
||||
eaExpert.eaForceHasATRTrending = eaForceHasATRTrending;
|
||||
eaExpert.eaForceHasATRBreakout = eaForceHasATRBreakout;
|
||||
eaExpert.eaFilterBasedOnTrend = eaFilterBasedOnTrend;
|
||||
eaExpert.eaForceHasTrendDir = eaForceHasTrendDir;
|
||||
eaExpert.eaForceHasTrendPlace = eaForceHasTrendPlace;
|
||||
eaExpert.eaForceHasTrendChange = eaForceHasTrendChange;
|
||||
eaExpert.eaForceHasTrendTrending = eaForceHasTrendTrending;
|
||||
eaExpert.eaForceHasTrendRejection = eaForceHasTrendRejection;
|
||||
eaExpert.eaForceHasTrendLineInside = eaForceHasTrendLineInside;
|
||||
eaExpert.eaForceHasTrendDirOnBothSide = eaForceHasTrendDirOnBothSide;
|
||||
eaExpert.eaFilterBasedOnDelta = eaFilterBasedOnDelta;
|
||||
eaExpert.eaFilterBasedOnVolume = eaFilterBasedOnVolume;
|
||||
eaExpert.eaFilterBasedOnSignalBar = eaFilterBasedOnSignalBar;
|
||||
eaExpert.eaFilterBasedOnHKSignalBar = eaFilterBasedOnHKSignalBar;
|
||||
|
||||
//
|
||||
// Signal ...
|
||||
eaExpert.eaSignalR2R = eaSignalR2R;
|
||||
eaExpert.eaSLATRMultiplier = eaSLATRMultiplier;
|
||||
|
||||
//
|
||||
// Volume ...
|
||||
eaExpert.eaVolumeSelect = eaVolumeSelect;
|
||||
eaExpert.eaStaticVoluem = eaStaticVoluem;
|
||||
eaExpert.eaDynamicVolumeStepBalance = eaDynamicVolumeStepBalance;
|
||||
eaExpert.eaDynamicVolumeStepVolume = eaDynamicVolumeStepVolume;
|
||||
eaExpert.eaConstantRiskBalance = eaConstantRiskBalance;
|
||||
eaExpert.eaConstantPercent = eaConstantPercent;
|
||||
eaExpert.eaConstantBalance = eaConstantBalance;
|
||||
|
||||
//
|
||||
// Management ...
|
||||
eaExpert.eaSymbols = eaSymbols;
|
||||
eaExpert.eaAllowGuards = eaAllowGuards;
|
||||
eaExpert.eaAllowTrade = eaAllowTrade;
|
||||
eaExpert.eaAllowLongs = eaAllowLongs;
|
||||
eaExpert.eaAllowShorts = eaAllowShorts;
|
||||
eaExpert.eaRestrictionsPeriod = eaRestrictionsPeriod;
|
||||
eaExpert.eaMaxAllowedTPs = eaMaxAllowedTPs;
|
||||
eaExpert.eaMaxAllowedSLs = eaMaxAllowedSLs;
|
||||
eaExpert.eaMaxAllowedTrades = eaMaxAllowedTrades;
|
||||
eaExpert.eaMaxAllowedPositions = eaMaxAllowedPositions;
|
||||
eaExpert.eaMaxAllowedSpread = eaMaxAllowedSpread;
|
||||
eaExpert.eaMaxAllowedDrawdownFactor = eaMaxAllowedDrawdownFactor;
|
||||
eaExpert.eaCloseAllOpenTradesAt = eaCloseAllOpenTradesAt;
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
eaExpert.eaEnableAlerts = eaEnableAlerts;
|
||||
eaExpert.eaLogAlerts = eaLogAlerts;
|
||||
eaExpert.eaMailAlerts = eaMailAlerts;
|
||||
eaExpert.eaPushAlerts = eaPushAlerts;
|
||||
eaExpert.eaTerminalAlerts = eaTerminalAlerts;
|
||||
|
||||
//
|
||||
// Reports ...
|
||||
eaExpert.eaReportNewMonths = eaReportNewMonths;
|
||||
eaExpert.eaReportNewWeeks = eaReportNewWeeks;
|
||||
eaExpert.eaReportNewDays = eaReportNewDays;
|
||||
eaExpert.eaReportNewHours = eaReportNewHours;
|
||||
eaExpert.eaReportTrades = eaReportTrades;
|
||||
eaExpert.eaReportSignals = eaReportSignals;
|
||||
eaExpert.eaReportProtector = eaReportProtector;
|
||||
eaExpert.eaReportAfterTradesBalance = eaReportAfterTradesBalance;
|
||||
|
||||
//
|
||||
// Collector ...
|
||||
eaExpert.eaSaveTrades = eaSaveTrades;
|
||||
eaExpert.eaSaveSignals = eaSaveSignals;
|
||||
eaExpert.eaSaveWins = eaSaveWins;
|
||||
eaExpert.eaSaveLosts = eaSaveLosts;
|
||||
|
||||
//
|
||||
// Attach Event Handlers ...
|
||||
eaExpert.OnModifyEventHandler = OnPositionModified;
|
||||
eaExpert.OnDealsChangedEventHandler = OnDealsChanged;
|
||||
eaExpert.OnStopLossEventHandler = OnStopLossTriggered;
|
||||
eaExpert.OnOrdersChangedEventHandler = OnOrdersChanged;
|
||||
eaExpert.OnForceCloseEventHandler = OnPositionForceClosed;
|
||||
eaExpert.OnTakeProfitEventHandler = OnTakeProfitTriggered;
|
||||
eaExpert.OnPositionsChangedEventHandler = OnPositionsChanged;
|
||||
eaExpert.OnPartialCloseEventHandler = OnPositionPartialClosed;
|
||||
eaExpert.OnTradeStateChangedEventHandler = OnTradeStateChanged;
|
||||
|
||||
//
|
||||
bool isInited = eaExpert.HandleOnInit();
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
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;
|
||||
ZeroMemory(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 ...
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Position Modified ...
|
||||
*
|
||||
* @param ticket: ulong, Position Ticket ...
|
||||
* @param profit: double, Position Profit ...
|
||||
* @param comment: string, Comment ...
|
||||
*/
|
||||
void OnPositionModified(
|
||||
const ulong ticket,
|
||||
const double profit,
|
||||
const string comment //
|
||||
)
|
||||
{
|
||||
//
|
||||
eaExpert.HandleOnPositionModified(
|
||||
ticket,
|
||||
profit,
|
||||
comment //
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Position Partial Closed ...
|
||||
*
|
||||
* @param ticket: ulong, Position Ticket ...
|
||||
* @param profit: double, Position Profit ...
|
||||
* @param comment: string, Comment ...
|
||||
*/
|
||||
void OnPositionPartialClosed(
|
||||
const ulong ticket,
|
||||
const double profit,
|
||||
const string comment //
|
||||
)
|
||||
{
|
||||
//
|
||||
eaExpert.HandleOnPositionPartialClosed(
|
||||
ticket,
|
||||
profit,
|
||||
comment //
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Trade State Changed ...
|
||||
*
|
||||
* @param state: XOnTradeHandlerState instance ...
|
||||
*/
|
||||
void OnTradeStateChanged(const XOnTradeHandlerState &state)
|
||||
{
|
||||
eaExpert.HandleOnTradeStateChanged(state);
|
||||
}
|
||||
|
||||
//
|
||||
// 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();
|
||||
}
|
||||
|
||||
//
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,259 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCX121XCCHelper
|
||||
// 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 X121XCCInputs
|
||||
{
|
||||
//
|
||||
// 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) ...
|
||||
X121XCCInputs()
|
||||
{
|
||||
//
|
||||
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;
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
mode = CHART_CANDLES;
|
||||
|
||||
//
|
||||
upColor = clrLime;
|
||||
downColor = clrRed;
|
||||
lineColor = clrLime;
|
||||
bearishColor = clrRed;
|
||||
bullishColor = clrLime;
|
||||
volumesColor = clrGreen;
|
||||
//
|
||||
showCandles = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Hide all Visible Buffers ...
|
||||
void Hide()
|
||||
{
|
||||
showCandles = false;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 XCX121XCCHelper : public XCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XCX121XCCHelper()
|
||||
: XCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCX121XCCHelper()
|
||||
{
|
||||
mInputs.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
X121XCCInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xcc",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Chart Style ...
|
||||
"",
|
||||
mInputs.mode, // Mode
|
||||
mInputs.upColor, // Up Color
|
||||
mInputs.downColor, // Down Color
|
||||
mInputs.lineColor, // Line mode and Doji candlestick Color
|
||||
mInputs.bullishColor, // Bearish Color
|
||||
mInputs.bearishColor, // Bullish Color
|
||||
mInputs.volumesColor, // Volumes Color
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
mInputs.showCandles // Show Candles
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
X121XCCInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
X121XCCInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
X121XCCInputs mInputs; // Inputs ...
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
@@ -0,0 +1,241 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCX121XCTHelper
|
||||
// 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 X121XCTInputs
|
||||
{
|
||||
//
|
||||
// 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) ...
|
||||
X121XCTInputs()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
font = NULL;
|
||||
fontSize = 15;
|
||||
clr = CLR_NONE;
|
||||
corner = CORNER_RIGHT_LOWER;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
showCandleTime = false;
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
font = "Arial";
|
||||
fontSize = 15;
|
||||
clr = clrYellow;
|
||||
corner = CORNER_RIGHT_LOWER;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
showCandleTime = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Hide all Visible Buffers ...
|
||||
void Hide()
|
||||
{
|
||||
showCandleTime = false;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 XCX121XCTHelper : public XCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XCX121XCTHelper()
|
||||
: XCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCX121XCTHelper()
|
||||
{
|
||||
mInputs.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
X121XCTInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.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 ...
|
||||
|
||||
//
|
||||
X121XCTInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
X121XCTInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
X121XCTInputs mInputs; // Inputs ...
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user