backup x121 setup ...
This commit is contained in:
@@ -0,0 +1,216 @@
|
||||
|
||||
//
|
||||
// Level 1 ...
|
||||
|
||||
//
|
||||
ENUM_XMAN_STATES scHState = (ENUM_XMAN_STATES)sHHStateBuffer[barIndex];
|
||||
ENUM_XMAN_STATES scHStatePrev = (ENUM_XMAN_STATES)sHHStateBuffer[barIndex + 1];
|
||||
ENUM_XMAN_STATES scLState = (ENUM_XMAN_STATES)sLLStateBuffer[barIndex];
|
||||
ENUM_XMAN_STATES scLStatePrev = (ENUM_XMAN_STATES)sLLStateBuffer[barIndex + 1];
|
||||
|
||||
//
|
||||
bool isSCHBullish =
|
||||
//
|
||||
scHState = XMAN_STATE_BULLISH
|
||||
//
|
||||
;
|
||||
//
|
||||
bool isSCHPrevBullish =
|
||||
//
|
||||
scHStatePrev = XMAN_STATE_BULLISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCLBullish =
|
||||
//
|
||||
scLState == XMAN_STATE_BULLISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCLPrevBullish =
|
||||
//
|
||||
scLStatePrev == XMAN_STATE_BULLISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCBullish =
|
||||
//
|
||||
isSCHBullish &&
|
||||
isSCLBullish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCPrevBullish =
|
||||
//
|
||||
isSCHPrevBullish &&
|
||||
isSCLPrevBullish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCSwitchedToBullish =
|
||||
//
|
||||
isSCBullish &&
|
||||
!isSCPrevBullish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCHSwitchedToBullish =
|
||||
//
|
||||
isSCHBullish &&
|
||||
!isSCHPrevBullish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCLSwitchedToBullish =
|
||||
//
|
||||
isSCLBullish &&
|
||||
!isSCLPrevBullish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCHBearish =
|
||||
//
|
||||
scHState == XMAN_STATE_BEARISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCHPrevBearish =
|
||||
//
|
||||
scHStatePrev == XMAN_STATE_BEARISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCLBearish =
|
||||
//
|
||||
scLState == XMAN_STATE_BEARISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCLPrevBearish =
|
||||
//
|
||||
scLStatePrev == XMAN_STATE_BEARISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCBearish =
|
||||
//
|
||||
isSCHBearish &&
|
||||
isSCLBearish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCPrevBearish =
|
||||
//
|
||||
isSCHPrevBearish &&
|
||||
isSCLPrevBearish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCSwitchedToBearish =
|
||||
//
|
||||
isSCBearish &&
|
||||
!isSCPrevBearish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCHSwitchedToBearish =
|
||||
//
|
||||
isSCHBearish &&
|
||||
!isSCHPrevBearish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCLSwitchedToBearish =
|
||||
//
|
||||
isSCLBearish &&
|
||||
!isSCLPrevBearish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCNeutural =
|
||||
//
|
||||
!isSCBullish &&
|
||||
!isSCBearish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCPrevNeutural =
|
||||
//
|
||||
!isSCPrevBullish &&
|
||||
!isSCPrevBearish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCHNeutural =
|
||||
//
|
||||
!isSCHBullish &&
|
||||
!isSCHBearish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCHPrevNeutural =
|
||||
//
|
||||
!isSCHPrevBullish &&
|
||||
!isSCHPrevBearish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCLNeutural =
|
||||
//
|
||||
!isSCLBullish &&
|
||||
!isSCLBearish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCLPrevNeutural =
|
||||
//
|
||||
!isSCLPrevBullish &&
|
||||
!isSCLPrevBearish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCSwitchedToNeutural =
|
||||
//
|
||||
isSCNeutural &&
|
||||
!isSCPrevNeutural
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCHSwitchedToNeutural =
|
||||
//
|
||||
isSCHNeutural &&
|
||||
!isSCHPrevNeutural
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSCLSwitchedToNeutural =
|
||||
//
|
||||
isSCLNeutural &&
|
||||
!isSCLPrevNeutural
|
||||
//
|
||||
;
|
||||
Binary file not shown.
@@ -0,0 +1,385 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
enum X_HTTP_METHOD
|
||||
{
|
||||
X_HTTP_GET,
|
||||
X_HTTP_POST
|
||||
};
|
||||
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Manage Account ...
|
||||
class XSCHttp
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCHttp()
|
||||
{
|
||||
XSCHttp("", 10000);
|
||||
}
|
||||
void XSCHttp(
|
||||
string path, // Base Folder to Store Data
|
||||
int timeout // base timeout for Requests
|
||||
)
|
||||
{
|
||||
//
|
||||
Path(path);
|
||||
Timeout(timeout);
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCHttp()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Getter(s)/Setter(s) ...
|
||||
//
|
||||
|
||||
//
|
||||
// Path ...
|
||||
void Path(string value)
|
||||
{
|
||||
mPath = value;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//
|
||||
// END Getter(s)/Setter(s) ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
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
Binary file not shown.
@@ -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 <Trade/AccountInfo.mqh>
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Manage Account ...
|
||||
class XSCAccount
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCAccount()
|
||||
{
|
||||
//
|
||||
mAccountInfo = new CAccountInfo();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCAccount()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
//
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,209 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Handle base requirements ...
|
||||
// for indicators ...
|
||||
class XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCBaseHelper(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period // Trading Time Frame
|
||||
)
|
||||
{
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
LoopBack(52);
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCBaseHelper()
|
||||
{
|
||||
IndicatorRelease(mHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// Loopback Bars ...
|
||||
void LoopBack(int value)
|
||||
{
|
||||
mLoopbackBars = value;
|
||||
}
|
||||
|
||||
int Loopback()
|
||||
{
|
||||
return mLoopbackBars;
|
||||
}
|
||||
|
||||
//
|
||||
// Symbol ...
|
||||
string GetSymbol()
|
||||
{
|
||||
return mSymbol;
|
||||
}
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES GetPeriod()
|
||||
{
|
||||
return mPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
// Tag ...
|
||||
string GetTag()
|
||||
{
|
||||
return mTag;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Bars ...
|
||||
int GetBars()
|
||||
{
|
||||
//
|
||||
int result =
|
||||
Bars(
|
||||
mSymbol,
|
||||
mPeriod);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int GetCalculatedBars()
|
||||
{
|
||||
return BarsCalculated(mHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Prepare Tag ...
|
||||
virtual void PrepareTag() {}
|
||||
|
||||
//
|
||||
// Reading Buffers based on Given Bar Index ...
|
||||
virtual void Calculate(
|
||||
int barIndex // Given Bar Index
|
||||
);
|
||||
|
||||
//
|
||||
// Retrieve MAx Required Length for Calculations ...
|
||||
virtual int GetMaxLength();
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
string GetTagPrefix()
|
||||
{
|
||||
//
|
||||
string result = "(" + mSymbol + ")(" + ToString(mPeriod) + ")";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Symbol ...
|
||||
string mSymbol;
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES mPeriod;
|
||||
|
||||
//
|
||||
// Indicator Handler ...
|
||||
int mHandler;
|
||||
|
||||
//
|
||||
// Number Of Items Read Per Tick ...
|
||||
int mLoopbackBars;
|
||||
|
||||
//
|
||||
// Tag Identifier ...
|
||||
string mTag;
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,304 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCEABaseProvider
|
||||
// Description: provides base requirements for
|
||||
// Specific Sgnal Provider ...
|
||||
//
|
||||
//
|
||||
// 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 Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.models.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Notified a Signal was Appears ...
|
||||
typedef void (*OnSignal)(
|
||||
XSignal &signal);
|
||||
|
||||
//
|
||||
// Notified a Guard Appears ...
|
||||
typedef void (*OnGuard)(XGuard &guard);
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Base Class for All of our EA's ...
|
||||
class XSCEABaseProvider
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCEABaseProvider()
|
||||
{
|
||||
mSymbol = _Symbol;
|
||||
mPeriod = _Period;
|
||||
}
|
||||
void XSCEABaseProvider(
|
||||
string symbol,
|
||||
ENUM_TIMEFRAMES period)
|
||||
{
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
mTag = mSymbol + "," + ToString(mPeriod);
|
||||
|
||||
//
|
||||
mIsInTestMode = IsRunningOnTestMode();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCEABaseProvider()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
bool CanIgnoreTick() {
|
||||
//
|
||||
mIsNewCandle = IsNewCandle(
|
||||
mSymbol,
|
||||
mPeriod);
|
||||
bool result = mIsInTestMode
|
||||
? !mIsNewCandle
|
||||
: !mIsNewCandle && mWaitUntilNewCandle;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare State ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
mIsNewCandle = IsNewCandle(
|
||||
mSymbol,
|
||||
mPeriod);
|
||||
mCanIgnoreTick = mIsInTestMode
|
||||
? !mIsNewCandle
|
||||
: !mIsNewCandle && mWaitUntilNewCandle;
|
||||
|
||||
//
|
||||
ProcessBuffers();
|
||||
|
||||
//
|
||||
if (mCanIgnoreTick)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
mWaitUntilNewCandle = false;
|
||||
|
||||
//
|
||||
ProcessTick();
|
||||
}
|
||||
|
||||
//
|
||||
virtual void PrepareTag();
|
||||
|
||||
//
|
||||
// Initialize Indicators and Requirements ...
|
||||
virtual bool Init();
|
||||
|
||||
//
|
||||
virtual int GetMaxLength();
|
||||
|
||||
//
|
||||
virtual int GetCalculatedBars();
|
||||
|
||||
//
|
||||
// Handle Update Buffers ...
|
||||
virtual void ProcessBuffers()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle On Tick Event ...
|
||||
virtual void ProcessTick()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Check for Guards ...
|
||||
virtual bool GuardCheck(XGuard &guards[]);
|
||||
|
||||
//
|
||||
// Add Specific On Signal Event Handler ...
|
||||
int AddOnSignalEventHandler(OnSignal handler)
|
||||
{
|
||||
//
|
||||
ArrayResize(
|
||||
mSignalEventHandlers,
|
||||
ArraySize(mSignalEventHandlers) + 1);
|
||||
|
||||
//
|
||||
int result = ArraySize(mSignalEventHandlers) - 1;
|
||||
mSignalEventHandlers[result] = handler;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Remove All On Signal Event Handler ...
|
||||
void ReoveOnSignalEventHandlers()
|
||||
{
|
||||
//
|
||||
ArrayFree(mSignalEventHandlers);
|
||||
}
|
||||
|
||||
//
|
||||
// Notify a Signal Found on all Event Listeners ...
|
||||
void NotifyOnSignalEvent(XSignal &info)
|
||||
{
|
||||
//
|
||||
int listenerCount = ArraySize(mSignalEventHandlers);
|
||||
if (listenerCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through Listeners ...
|
||||
for (int i = 0; i < listenerCount; i++)
|
||||
{
|
||||
//
|
||||
OnSignal listener = mSignalEventHandlers[i];
|
||||
|
||||
//
|
||||
listener(info);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
string mSymbol;
|
||||
|
||||
//
|
||||
ENUM_TIMEFRAMES mPeriod;
|
||||
|
||||
//
|
||||
string mTag;
|
||||
|
||||
//
|
||||
bool mIsNewCandle;
|
||||
bool mIsInTestMode;
|
||||
bool mCanIgnoreTick;
|
||||
bool mWaitUntilNewCandle;
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Signal Event Handlers ...
|
||||
OnSignal mSignalEventHandlers[];
|
||||
};
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Model Signal Providers Definitions ...
|
||||
struct XBaseSignalProvider
|
||||
{
|
||||
//
|
||||
// Provider use Which Symbol ...
|
||||
string symbol;
|
||||
|
||||
//
|
||||
// Provider use Which Time Frame ...
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
// Risk Amount Per Trades Related to Time Frames ...
|
||||
// Percent of Available Balance ...
|
||||
double riskAmount;
|
||||
|
||||
//
|
||||
// Desired Magic Number ...
|
||||
ulong magicNumber;
|
||||
};
|
||||
|
||||
//
|
||||
struct XLastSignal
|
||||
{
|
||||
datetime at;
|
||||
string provider;
|
||||
};
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Add Specific Provider to List ...
|
||||
void Add(
|
||||
XBaseSignalProvider &item, // item want to add
|
||||
XBaseSignalProvider &buffer[] // Destination buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
ArrayResize(
|
||||
buffer,
|
||||
ArraySize(buffer) + 1);
|
||||
|
||||
//
|
||||
buffer[ArraySize(buffer) - 1] = item;
|
||||
}
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,378 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Expert Advisor
|
||||
// ----------------------------------------
|
||||
// Name: X121EA
|
||||
// Description: this is an expert controller
|
||||
// advisors which provides a mechanism for use them ...
|
||||
//
|
||||
//
|
||||
// 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 X121EA"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
#define ShortName "X121EA"
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// EA ...
|
||||
input group "Common";
|
||||
input bool xEAEnable = true; // Enable EA
|
||||
input int xEASlippage = 10; // Slippgae
|
||||
input ulong xEAMagicNumber = 1604056; // Magic Number
|
||||
|
||||
//
|
||||
// Providers ...
|
||||
input group "Providers";
|
||||
input bool xEAUseCurrentConfig = true; // Use Only Current Config
|
||||
input string xEAProvidersConfiguration = ""; // Providers Configuration
|
||||
input string xEADefaultSignalProviders = "X786,X92,X110,X121,X128"; // Default Allowed Signal Providers
|
||||
|
||||
//
|
||||
// Signals ...
|
||||
input group "Signals";
|
||||
input bool xEAEnableLongs = true; // Enable Long Trades
|
||||
input bool xEAEnableShorts = true; // Enable Short Trades
|
||||
|
||||
//
|
||||
// Risk Management ...
|
||||
input group "Risk Management";
|
||||
input int xEAMaxOpenPositions = 15; // Max Allowed Open Trades
|
||||
input double xEAMinRiskAmountPerTrade = 0.001; // Min Risk Amount Per Trade
|
||||
input double xEAMaxAllowedDrawDownFactor = 0.001; // Max Allowed Drawdown Factor
|
||||
|
||||
//
|
||||
// Alerts ...
|
||||
input group "Alerts";
|
||||
input bool xEAEnableAlerts = true; // Enable Events Alert
|
||||
input bool xEAEnableHourlyAlerts = false; // Send Alert on each new Hour
|
||||
input bool xEAEnableDailyAlerts = false; // Send Alert on each new Day
|
||||
input bool xEAEnableWeeklyAlerts = false; // Send Alert on each new Week
|
||||
input bool xEAEnableMonthlyAlerts = false; // Send Alert on each new Month
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Including Providers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Logger Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
#include "../Classes/x-saherelm.x121.xea.class.mq5"
|
||||
|
||||
//
|
||||
// END Including Providers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
XSCX121EA *mX121EA;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
logTag = ShortName;
|
||||
drawPrefix = logTag;
|
||||
alertPrefix = logTag;
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
bool isInit = InitEAInstance();
|
||||
if (!isInit)
|
||||
{
|
||||
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
|
||||
|
||||
//
|
||||
// De Initialize XEA Providers ...
|
||||
delete mX121EA;
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
// Prevent Going Forward if user Disable it ...
|
||||
if (xEAEnable)
|
||||
{
|
||||
mX121EA.OnTick();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Trade Events ...
|
||||
void OnTrade()
|
||||
{
|
||||
mX121EA.OnTrade();
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Signal Event ...
|
||||
void OnSignalConditionsRecieved(X121MarketConditions &info)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Handle StopLoss Event ...
|
||||
void OnStopLossTriggered(const XDeal &deal)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Handle TakeProfit Event ...
|
||||
void OnTakeProfitTriggered(const XDeal &deal)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Deals Changed Event ...
|
||||
void OnDealsChangedHandler(int count)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Order Changed Event ...
|
||||
void OnOrdersChangedHandler(int count)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Position Changed Event ...
|
||||
void OnPositionsChangedHandler(int count)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Trade State Changed ...
|
||||
void OnTradeStateChangedHandler(const XOnTradeHandlerState &state)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result =
|
||||
//
|
||||
xEASlippage > 0 &&
|
||||
xEAMagicNumber > 0 &&
|
||||
xEAMinRiskAmountPerTrade > 0 &&
|
||||
StringLen(xEADefaultSignalProviders) > 0
|
||||
//
|
||||
// TODO: add new validations here ...
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Validate Providers ...
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
string providers[];
|
||||
SplitContent(
|
||||
providers,
|
||||
xEADefaultSignalProviders);
|
||||
|
||||
//
|
||||
int providersCount = ArraySize(providers);
|
||||
if (providersCount <= 0)
|
||||
{
|
||||
//
|
||||
result = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string allProviders[];
|
||||
GetAllProviders(allProviders);
|
||||
|
||||
//
|
||||
bool hasError = false;
|
||||
for (int i = 0; i < providersCount; i++)
|
||||
{
|
||||
//
|
||||
string iProvider = providers[i];
|
||||
if (!Contains(iProvider, allProviders))
|
||||
{
|
||||
//
|
||||
hasError = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (hasError)
|
||||
{
|
||||
//
|
||||
result = false;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Logging State ...
|
||||
string message = "Validation of (" + logTag + ") Inputs " + (result ? "Succeeded" : "Failed") + " ...";
|
||||
LogMessage(message);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize X121EA Class Instances ...
|
||||
bool InitEAInstance()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
X121SignalProvider providers[];
|
||||
|
||||
//
|
||||
// Validatie Providers Configuration ...
|
||||
if (xEAUseCurrentConfig)
|
||||
{
|
||||
//
|
||||
// Here we Ignore xEAProvidersConfiguration ...
|
||||
// Have to Create a Default Provider Structure and Attached it to X121EA Instance ...
|
||||
X121SignalProvider provider;
|
||||
|
||||
//
|
||||
provider.symbol = _Symbol;
|
||||
provider.period = _Period;
|
||||
provider.riskAmount = xEAMinRiskAmountPerTrade;
|
||||
|
||||
//
|
||||
string signalProviders[];
|
||||
SplitContent(
|
||||
signalProviders,
|
||||
xEADefaultSignalProviders);
|
||||
|
||||
//
|
||||
Copy(
|
||||
signalProviders,
|
||||
provider.providers);
|
||||
|
||||
//
|
||||
// Now add Default Provider to Providers Array ...
|
||||
Add(
|
||||
provider,
|
||||
providers);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// TODO: Here we must Implement all mechanism to Extract Provider Configurations and
|
||||
// Add them one by one to XEA Instance ...
|
||||
}
|
||||
|
||||
//
|
||||
mX121EA = new XSCX121EA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
xEAMagicNumber,
|
||||
xEASlippage,
|
||||
OnStopLossTriggered,
|
||||
OnTakeProfitTriggered,
|
||||
OnDealsChangedHandler,
|
||||
OnOrdersChangedHandler,
|
||||
OnPositionsChangedHandler,
|
||||
OnTradeStateChangedHandler,
|
||||
OnSignalConditionsRecieved);
|
||||
|
||||
//
|
||||
mX121EA.EnableLongs(xEAEnableLongs);
|
||||
mX121EA.EnableShorts(xEAEnableShorts);
|
||||
mX121EA.MaxAllowedPositions(xEAMaxOpenPositions);
|
||||
mX121EA.MaxAllowedDrawDownFactor(xEAMaxAllowedDrawDownFactor);
|
||||
|
||||
//
|
||||
// Attach Providers to EA Instance ...
|
||||
int providersCount = ArraySize(providers);
|
||||
int addedProviders = mX121EA.AddProviders(providers);
|
||||
result = addedProviders == providersCount;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,446 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXAMAHelper
|
||||
// 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
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
struct XAMAInputs
|
||||
{
|
||||
//
|
||||
// Makret ...
|
||||
int length; // Length
|
||||
int fastEMA; // Fast EMA Length
|
||||
int slowEMA; // Slow EMA Length
|
||||
int maShift; // Shift
|
||||
ENUM_APPLIED_PRICE appliedTo; // Applied To
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showLine; // Show Line
|
||||
};
|
||||
|
||||
//
|
||||
// Index of Lines ...
|
||||
enum ENUM_XAMA_BUFFERS
|
||||
{
|
||||
//
|
||||
// Main Requirements ...
|
||||
XAMA_LINE = 0,
|
||||
XAMA_STATE_LINE = 1,
|
||||
};
|
||||
|
||||
//
|
||||
// XAMA Indicator States ...
|
||||
enum ENUM_XAMA_STATES
|
||||
{
|
||||
X_XAMA_BULLISH = 0,
|
||||
X_XAMA_BEARISH = 2,
|
||||
X_XAMA_NEUTURAL = 1,
|
||||
};
|
||||
|
||||
//
|
||||
// Retrieve Info Model ...
|
||||
struct XAMAInfo
|
||||
{
|
||||
//
|
||||
// Symbol ...
|
||||
string symbol;
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
// Bar Time ...
|
||||
datetime barTime;
|
||||
|
||||
//
|
||||
// Bar Index ...
|
||||
int barIndex;
|
||||
|
||||
//
|
||||
// Values ...
|
||||
double value;
|
||||
|
||||
//
|
||||
double values[];
|
||||
double states[];
|
||||
|
||||
//
|
||||
// State ...
|
||||
ENUM_XAMA_STATES state;
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
// Detect Trend is Bullish or not ...
|
||||
bool isBullish;
|
||||
|
||||
//
|
||||
// Detect Trend is Switched to Bullish Or not ...
|
||||
bool isSwitchedBullish;
|
||||
|
||||
//
|
||||
// Detect Trend is Bearish or not ...
|
||||
bool isBearish;
|
||||
|
||||
//
|
||||
// Detect Trend is Switched to Bearish Or not ...
|
||||
bool isSwitchedBearish;
|
||||
|
||||
//
|
||||
// Detect Trend is Neutural or not ...
|
||||
bool isNeutural;
|
||||
|
||||
//
|
||||
// Detect Trend is Switched to Neutural Or not ...
|
||||
bool isSwitchedNeutural;
|
||||
};
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Helping Indicators Requirements ...
|
||||
class XSCXAMAHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Buffers ...
|
||||
double valueBuffer[];
|
||||
double stateBuffer[];
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCXAMAHelper(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period // Trading Time Frame
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
PrepareTag();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCXAMAHelper()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Prepare Tag ...
|
||||
virtual void PrepareTag()
|
||||
{
|
||||
mTag = "XAMA" + GetTagPrefix();
|
||||
}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
result = mLength;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Indicator Handler ...
|
||||
bool Init()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result =
|
||||
//
|
||||
(mLength >= 2)
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Handler ...
|
||||
mHandler = iCustom(
|
||||
//
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xama",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Makret ...
|
||||
"",
|
||||
//
|
||||
// Length ...
|
||||
mLength,
|
||||
//
|
||||
// Fast EMA Length ...
|
||||
mFastEMA,
|
||||
//
|
||||
// Slow EMA Length ...
|
||||
mSlowEMA,
|
||||
//
|
||||
// Shift ...
|
||||
mMaShift,
|
||||
//
|
||||
// Applied To ...
|
||||
mAppliedTo,
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
//
|
||||
// Show Line ...
|
||||
mShowLine
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Current Config ...
|
||||
XAMAInputs GetConfig()
|
||||
{
|
||||
//
|
||||
XAMAInputs result;
|
||||
|
||||
//
|
||||
result.length = mLength;
|
||||
result.fastEMA = mFastEMA;
|
||||
result.slowEMA = mSlowEMA;
|
||||
result.maShift = mMaShift;
|
||||
result.appliedTo = mAppliedTo;
|
||||
result.showLine = mShowLine;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Config ...
|
||||
bool SetConfig(XAMAInputs &config)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mLength = config.length;
|
||||
mFastEMA = config.fastEMA;
|
||||
mSlowEMA = config.slowEMA;
|
||||
mMaShift = config.maShift;
|
||||
mAppliedTo = config.appliedTo;
|
||||
mShowLine = config.showLine;
|
||||
|
||||
//
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Buffers based on Given Bar Index ...
|
||||
virtual void Calculate(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// VALUE ...
|
||||
ArraySetAsSeries(valueBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XAMA_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
valueBuffer);
|
||||
|
||||
//
|
||||
// STATE ...
|
||||
ArraySetAsSeries(stateBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XAMA_STATE_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
stateBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Info at Specific Bar Index ...
|
||||
XAMAInfo GetInfo(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
XAMAInfo result;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculations ...
|
||||
Calculate(barIndex);
|
||||
|
||||
//
|
||||
// Generate Candle Time ...
|
||||
datetime barTime = GetCandleTime(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
barIndex);
|
||||
|
||||
//
|
||||
// Fill Result ...
|
||||
result.symbol = mSymbol;
|
||||
result.period = mPeriod;
|
||||
result.barTime = barTime;
|
||||
result.barIndex = barIndex;
|
||||
|
||||
//
|
||||
result.value = valueBuffer[barIndex];
|
||||
|
||||
//
|
||||
Copy(
|
||||
valueBuffer,
|
||||
result.values);
|
||||
|
||||
//
|
||||
Copy(
|
||||
stateBuffer,
|
||||
result.states);
|
||||
|
||||
//
|
||||
ENUM_XAMA_STATES state = (ENUM_XAMA_STATES)stateBuffer[barIndex];
|
||||
ENUM_XAMA_STATES prevState = (ENUM_XAMA_STATES)stateBuffer[barIndex + 1];
|
||||
result.state = state;
|
||||
|
||||
//
|
||||
result.isBullish = state == X_XAMA_BULLISH;
|
||||
result.isBearish = state == X_XAMA_BEARISH;
|
||||
result.isNeutural = state == X_XAMA_NEUTURAL;
|
||||
|
||||
//
|
||||
result.isSwitchedBullish =
|
||||
state == X_XAMA_BULLISH && prevState != X_XAMA_BULLISH;
|
||||
result.isSwitchedBearish =
|
||||
state == X_XAMA_BEARISH && prevState != X_XAMA_BEARISH;
|
||||
result.isSwitchedNeutural =
|
||||
state == X_XAMA_NEUTURAL && prevState != X_XAMA_NEUTURAL;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Indicator Properties ...
|
||||
//
|
||||
// Market ...
|
||||
//
|
||||
// Length ...
|
||||
int mLength;
|
||||
//
|
||||
// Fast EMA Length ...
|
||||
int mFastEMA;
|
||||
//
|
||||
// Slow EMA Length ...
|
||||
int mSlowEMA;
|
||||
//
|
||||
// Shift ...
|
||||
int mMaShift;
|
||||
//
|
||||
// Applied To ...
|
||||
ENUM_APPLIED_PRICE mAppliedTo;
|
||||
//
|
||||
// Presentation ...
|
||||
//
|
||||
// Show Line ...
|
||||
bool mShowLine;
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,293 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXCCHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
struct XCCInputs
|
||||
{
|
||||
//
|
||||
// Chart Style ...
|
||||
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
|
||||
};
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Helping Indicators Requirements ...
|
||||
class XSCXCCHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCXCCHelper(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period // Trading Time Frame
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
PrepareTag();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCXCCHelper()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// Show Candles ...
|
||||
bool ShowCandles(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowCandles == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowCandles = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Prepare Tag ...
|
||||
virtual void PrepareTag()
|
||||
{
|
||||
mTag = "XCC" + GetTagPrefix();
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Buffers based on Given Bar Index ...
|
||||
virtual void Calculate(
|
||||
int barIndex // Given Bar Index
|
||||
) {}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
result = 2;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Indicator Handler ...
|
||||
bool Init()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Handler ...
|
||||
mHandler = iCustom(
|
||||
//
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xcc",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Chart Style ...
|
||||
"",
|
||||
//
|
||||
// Up Color ...
|
||||
mUpColor,
|
||||
//
|
||||
// Down Color ...
|
||||
mDownColor,
|
||||
//
|
||||
// Line mode and Doji candlestick Color ...
|
||||
mLineColor,
|
||||
//
|
||||
// Bullish Color ...
|
||||
mBearishColor,
|
||||
//
|
||||
// Bearish Color ...
|
||||
mBullishColor,
|
||||
//
|
||||
// Volumes Color ...
|
||||
mVolumesColor,
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
//
|
||||
// Show Candles ...
|
||||
mShowCandles
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Current Config ...
|
||||
XCCInputs GetConfig()
|
||||
{
|
||||
//
|
||||
XCCInputs result;
|
||||
|
||||
//
|
||||
result.upColor = mUpColor;
|
||||
result.downColor = mDownColor;
|
||||
result.lineColor = mLineColor;
|
||||
result.bearishColor = mBearishColor;
|
||||
result.bullishColor = mBullishColor;
|
||||
result.volumesColor = mVolumesColor;
|
||||
result.showCandles = mShowCandles;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Config ...
|
||||
bool SetConfig(XCCInputs &config)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mUpColor = config.upColor;
|
||||
mDownColor = config.downColor;
|
||||
mLineColor = config.lineColor;
|
||||
mBearishColor = config.bearishColor;
|
||||
mBullishColor = config.bullishColor;
|
||||
mVolumesColor = config.volumesColor;
|
||||
mShowCandles = config.showCandles;
|
||||
|
||||
//
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Indicator Properties ...
|
||||
//
|
||||
// Chart Style ...
|
||||
//
|
||||
// Up Color ...
|
||||
color mUpColor;
|
||||
//
|
||||
// Down Color ...
|
||||
color mDownColor;
|
||||
//
|
||||
// Line mode and Doji candlestick Color ...
|
||||
color mLineColor;
|
||||
//
|
||||
// Bullish Color ...
|
||||
color mBearishColor;
|
||||
//
|
||||
// Bearish Color ...
|
||||
color mBullishColor;
|
||||
//
|
||||
// Volumes Color ...
|
||||
color mVolumesColor;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
//
|
||||
// Show Candles ...
|
||||
bool mShowCandles;
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,612 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXCHEHelper
|
||||
// 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
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
struct XCHEInputs
|
||||
{
|
||||
//
|
||||
// Market ...
|
||||
int length; // Length
|
||||
int loopback; // Loopback
|
||||
double multiplier1; // 1st Multiplier
|
||||
double multiplier2; // 2nd Multiplier
|
||||
|
||||
//
|
||||
// Calculation ...
|
||||
ENUM_APPLIED_PRICE upAppliedTo; // Up Zone Applied to
|
||||
ENUM_APPLIED_PRICE downAppliedTo; // Down Zone Applied to
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showLongExit1Line; // Show 1st Long Exit
|
||||
bool showShortExit1Line; // Show 1st Short Exit
|
||||
bool showLongExit2Line; // Show 2st Long Exit
|
||||
bool showShortExit2Line; // Show 2st Short Exit
|
||||
};
|
||||
|
||||
//
|
||||
// Index of Lines ...
|
||||
enum ENUM_XCHE_BUFFERS
|
||||
{
|
||||
//
|
||||
// Main Requirements ...
|
||||
XCHE_1ST_LONG_EXIT_LINE = 0,
|
||||
XCHE_1ST_SHORT_EXIT_LINE = 1,
|
||||
XCHE_2ND_LONG_EXIT_LINE = 2,
|
||||
XCHE_2ND_SHORT_EXIT_LINE = 3,
|
||||
};
|
||||
|
||||
//
|
||||
// Retrieve Info Model ...
|
||||
struct XCHEInfo
|
||||
{
|
||||
//
|
||||
// Symbol ...
|
||||
string symbol;
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
// Bar Time ...
|
||||
datetime barTime;
|
||||
|
||||
//
|
||||
// Bar Index ...
|
||||
int barIndex;
|
||||
|
||||
//
|
||||
// Values ...
|
||||
double longExit1;
|
||||
double longExit2;
|
||||
double shortExit1;
|
||||
double shortExit2;
|
||||
|
||||
//
|
||||
double le1[];
|
||||
double le2[];
|
||||
|
||||
//
|
||||
double se1[];
|
||||
double se2[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
//
|
||||
bool isLongExit1Start;
|
||||
bool isShortExit1Start;
|
||||
|
||||
//
|
||||
bool isLongExit2Start;
|
||||
bool isShortExit2Start;
|
||||
};
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Helping Indicators Requirements ...
|
||||
class XSCXCHEHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Buffers ...
|
||||
double longExit1Buffer[];
|
||||
double shortExit1Buffer[];
|
||||
double longExit2Buffer[];
|
||||
double shortExit2Buffer[];
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCXCHEHelper(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period // Trading Time Frame
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
PrepareTag();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCXCHEHelper()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// Show 1st Long Exit ...
|
||||
bool ShowLongExit1Line(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowLongExit1Line == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowLongExit1Line = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show 1st Short Exit ...
|
||||
bool ShowShortExit1Line(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowShortExit1Line == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowShortExit1Line = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show 2st Long Exit ...
|
||||
bool ShowLongExit2Line(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowLongExit2Line == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowLongExit2Line = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show 2st Short Exit ...
|
||||
bool ShowShortExit2Line(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowShortExit1Line == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowShortExit1Line = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Prepare Tag ...
|
||||
virtual void PrepareTag()
|
||||
{
|
||||
mTag = "XCHE" + GetTagPrefix();
|
||||
}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
result = MathMax(mLength, mLoopback);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Indicator Handler ...
|
||||
bool Init()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
//
|
||||
//
|
||||
result =
|
||||
mLength >= 9 &&
|
||||
mLoopback >= 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Handler ...
|
||||
mHandler = iCustom(
|
||||
//
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xche",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Market ...
|
||||
"",
|
||||
//
|
||||
// Length ...
|
||||
mLength,
|
||||
//
|
||||
// Loopback ...
|
||||
mLoopback,
|
||||
//
|
||||
// 1st Multiplier ...
|
||||
mMultiplier1,
|
||||
//
|
||||
// 2nd Multiplier ...
|
||||
mMultiplier2,
|
||||
//
|
||||
// Calculation ...
|
||||
"",
|
||||
//
|
||||
// Up Zone Applied to ...
|
||||
mUpAppliedTo,
|
||||
//
|
||||
// Down Zone Applied to ...
|
||||
mDownAppliedTo,
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
//
|
||||
// Show 1st Long Exit ...
|
||||
mShowLongExit1Line,
|
||||
//
|
||||
// Show 1st Short Exit ...
|
||||
mShowShortExit1Line,
|
||||
//
|
||||
// Show 2st Long Exit ...
|
||||
mShowLongExit2Line,
|
||||
//
|
||||
// Show 2st Short Exit ...
|
||||
mShowShortExit2Line
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Current Config ...
|
||||
XCHEInputs GetConfig()
|
||||
{
|
||||
//
|
||||
XCHEInputs result;
|
||||
|
||||
//
|
||||
result.length = mLength;
|
||||
result.loopback = mLoopback;
|
||||
result.multiplier1 = mMultiplier1;
|
||||
result.multiplier2 = mMultiplier2;
|
||||
result.upAppliedTo = mUpAppliedTo;
|
||||
result.downAppliedTo = mDownAppliedTo;
|
||||
result.showLongExit1Line = mShowLongExit1Line;
|
||||
result.showShortExit1Line = mShowShortExit1Line;
|
||||
result.showLongExit2Line = mShowLongExit2Line;
|
||||
result.showShortExit2Line = mShowShortExit2Line;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Config ...
|
||||
bool SetConfig(XCHEInputs &config)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mLength = config.length;
|
||||
mLoopback = config.loopback;
|
||||
mMultiplier1 = config.multiplier1;
|
||||
mMultiplier2 = config.multiplier2;
|
||||
mUpAppliedTo = config.upAppliedTo;
|
||||
mDownAppliedTo = config.downAppliedTo;
|
||||
mShowLongExit1Line = config.showLongExit1Line;
|
||||
mShowShortExit1Line = config.showShortExit1Line;
|
||||
mShowLongExit2Line = config.showLongExit2Line;
|
||||
mShowShortExit2Line = config.showShortExit2Line;
|
||||
|
||||
//
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Buffers based on Given Bar Index ...
|
||||
virtual void Calculate(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// LEVEL 1 ..
|
||||
|
||||
//
|
||||
// LONG Exit ...
|
||||
ArraySetAsSeries(longExit1Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XCHE_1ST_LONG_EXIT_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
longExit1Buffer);
|
||||
|
||||
//
|
||||
// SHORT Exit ...
|
||||
ArraySetAsSeries(shortExit1Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XCHE_1ST_SHORT_EXIT_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
shortExit1Buffer);
|
||||
|
||||
//
|
||||
// LEVEL 2 ..
|
||||
|
||||
//
|
||||
// LONG Exit ...
|
||||
ArraySetAsSeries(longExit2Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XCHE_2ND_LONG_EXIT_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
longExit2Buffer);
|
||||
|
||||
//
|
||||
// SHORT Exit ...
|
||||
ArraySetAsSeries(shortExit2Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XCHE_2ND_SHORT_EXIT_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
shortExit2Buffer);
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Info at Specific Bar Index ...
|
||||
XCHEInfo GetInfo(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
XCHEInfo result;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculations ...
|
||||
Calculate(barIndex);
|
||||
|
||||
//
|
||||
// Generate Candle Time ...
|
||||
datetime barTime = GetCandleTime(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
barIndex);
|
||||
|
||||
//
|
||||
// Fill Result ...
|
||||
result.symbol = mSymbol;
|
||||
result.period = mPeriod;
|
||||
result.barTime = barTime;
|
||||
result.barIndex = barIndex;
|
||||
|
||||
//
|
||||
double longExit1 = longExit1Buffer[barIndex];
|
||||
double longExit1Prev = longExit1Buffer[barIndex + 1];
|
||||
double shortExit1 = shortExit1Buffer[barIndex];
|
||||
double shortExit1Prev = shortExit1Buffer[barIndex + 1];
|
||||
|
||||
//
|
||||
double longExit2 = longExit2Buffer[barIndex];
|
||||
double longExit2Prev = longExit2Buffer[barIndex + 1];
|
||||
double shortExit2 = shortExit2Buffer[barIndex];
|
||||
double shortExit2Prev = shortExit2Buffer[barIndex + 1];
|
||||
|
||||
//
|
||||
Copy(
|
||||
longExit1Buffer,
|
||||
result.le1);
|
||||
Copy(
|
||||
longExit2Buffer,
|
||||
result.le2);
|
||||
|
||||
//
|
||||
Copy(
|
||||
shortExit1Buffer,
|
||||
result.se1);
|
||||
Copy(
|
||||
shortExit2Buffer,
|
||||
result.se2);
|
||||
|
||||
//
|
||||
result.longExit1 = longExit1;
|
||||
result.shortExit1 = shortExit1;
|
||||
result.longExit2 = longExit2;
|
||||
result.shortExit2 = shortExit2;
|
||||
|
||||
//
|
||||
result.isLongExit1Start =
|
||||
longExit1 != EMPTY_VALUE &&
|
||||
longExit1Prev == EMPTY_VALUE;
|
||||
|
||||
//
|
||||
result.isShortExit1Start =
|
||||
shortExit1 != EMPTY_VALUE &&
|
||||
shortExit1Prev == EMPTY_VALUE;
|
||||
|
||||
//
|
||||
result.isLongExit2Start =
|
||||
longExit2 != EMPTY_VALUE &&
|
||||
longExit2Prev == EMPTY_VALUE;
|
||||
|
||||
//
|
||||
result.isShortExit2Start =
|
||||
shortExit2 != EMPTY_VALUE &&
|
||||
shortExit2Prev == EMPTY_VALUE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Indicator Properties ...
|
||||
//
|
||||
// Market ...
|
||||
//
|
||||
// Length ...
|
||||
int mLength;
|
||||
//
|
||||
// Loopback ...
|
||||
int mLoopback;
|
||||
//
|
||||
// 1st Multiplier ...
|
||||
double mMultiplier1;
|
||||
//
|
||||
// 2nd Multiplier ...
|
||||
double mMultiplier2;
|
||||
//
|
||||
// Calculation ...
|
||||
//
|
||||
// Up Zone Applied to ...
|
||||
ENUM_APPLIED_PRICE mUpAppliedTo;
|
||||
//
|
||||
// Down Zone Applied to ...
|
||||
ENUM_APPLIED_PRICE mDownAppliedTo;
|
||||
//
|
||||
// Presentation ...
|
||||
//
|
||||
// Show 1st Long Exit ...
|
||||
bool mShowLongExit1Line;
|
||||
//
|
||||
// Show 1st Short Exit ...
|
||||
bool mShowShortExit1Line;
|
||||
//
|
||||
// Show 2st Long Exit ...
|
||||
bool mShowLongExit2Line;
|
||||
//
|
||||
// Show 2st Short Exit ...
|
||||
bool mShowShortExit2Line;
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,248 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXCTHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
struct XCTInputs
|
||||
{
|
||||
//
|
||||
color clr;
|
||||
ENUM_BASE_CORNER corner;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showCandleTime; // Show Candle Time
|
||||
};
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Helping Indicators Requirements ...
|
||||
class XSCXCTHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCXCTHelper(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period // Trading Time Frame
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
PrepareTag();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCXCTHelper()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// Show Candles ...
|
||||
bool ShowCandleTime(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowCandleTime == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowCandleTime = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Prepare Tag ...
|
||||
virtual void PrepareTag()
|
||||
{
|
||||
mTag = "XCT" + GetTagPrefix();
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Buffers based on Given Bar Index ...
|
||||
virtual void Calculate(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
result = 1;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Indicator Handler ...
|
||||
bool Init()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Handler ...
|
||||
mHandler = iCustom(
|
||||
//
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xct",
|
||||
//
|
||||
// Inputs ...
|
||||
mClr,
|
||||
mCorner,
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
mShowCandleTime
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Current Config ...
|
||||
XCTInputs GetConfig()
|
||||
{
|
||||
//
|
||||
XCTInputs result;
|
||||
|
||||
//
|
||||
result.clr = mClr;
|
||||
result.corner = mCorner;
|
||||
result.showCandleTime = mShowCandleTime;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Config ...
|
||||
bool SetConfig(XCTInputs &config)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mClr = config.clr;
|
||||
mCorner = config.corner;
|
||||
mShowCandleTime = config.showCandleTime;
|
||||
|
||||
//
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Indicator Properties ...
|
||||
|
||||
//
|
||||
// Text Color ...
|
||||
color mClr;
|
||||
//
|
||||
// Text Position ...
|
||||
ENUM_BASE_CORNER mCorner;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
//
|
||||
// Show Candles ...
|
||||
bool mShowCandleTime;
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,470 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXDEMAHelper
|
||||
// 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
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
struct XDEMAInputs
|
||||
{
|
||||
//
|
||||
// Makret ...
|
||||
int length; // Length
|
||||
int shift; // Shift
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showDema; // Show Dema
|
||||
bool showEMA; // Show EMA
|
||||
bool showEMAOfEMA; // Show EMA of EMA
|
||||
};
|
||||
|
||||
//
|
||||
// Index of Lines ...
|
||||
enum ENUM_XDEMA_BUFFERS
|
||||
{
|
||||
//
|
||||
// Main Requirements ...
|
||||
XDEMA_LINE = 0,
|
||||
XDEMA_EMA_LINE = 2,
|
||||
XDEMA_EMA_OF_EMA_LINE = 4,
|
||||
};
|
||||
|
||||
//
|
||||
// Retrieve Info Model ...
|
||||
struct XDEMAInfo
|
||||
{
|
||||
//
|
||||
// Symbol ...
|
||||
string symbol;
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
// Bar Time ...
|
||||
datetime barTime;
|
||||
|
||||
//
|
||||
// Bar Index ...
|
||||
int barIndex;
|
||||
|
||||
//
|
||||
// Values ...
|
||||
double dema;
|
||||
double ema;
|
||||
double emaOfEma;
|
||||
|
||||
//
|
||||
double demas[];
|
||||
double emas[];
|
||||
double emaOfEMAs[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
};
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Helping Indicators Requirements ...
|
||||
class XSCXDEMAHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Buffers ...
|
||||
double demaBuffer[];
|
||||
double emaBuffer[];
|
||||
double emaOfEMABuffer[];
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCXDEMAHelper(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period // Trading Time Frame
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
PrepareTag();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCXDEMAHelper()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Prepare Tag ...
|
||||
virtual void PrepareTag()
|
||||
{
|
||||
mTag = "XDEMA" + GetTagPrefix();
|
||||
}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
result = mLength;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Indicator Handler ...
|
||||
bool Init()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result =
|
||||
//
|
||||
(mLength >= 2 &&
|
||||
mShift >= 0)
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Handler ...
|
||||
mHandler = iCustom(
|
||||
//
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xdema",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Makret ...
|
||||
"",
|
||||
//
|
||||
// Length ...
|
||||
mLength,
|
||||
//
|
||||
// Shift ...
|
||||
mShift,
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
//
|
||||
// Show Dema ...
|
||||
mShowDema,
|
||||
//
|
||||
// Show EMA ...
|
||||
mShowEMA,
|
||||
//
|
||||
// Show EMA of EMA ...
|
||||
mShowEMAOfEMA
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Current Config ...
|
||||
XDEMAInputs GetConfig()
|
||||
{
|
||||
//
|
||||
XDEMAInputs result;
|
||||
|
||||
//
|
||||
result.length = mLength;
|
||||
result.shift = mShift;
|
||||
result.showDema = mShowDema;
|
||||
result.showEMA = mShowEMA;
|
||||
result.showEMAOfEMA = mShowEMAOfEMA;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Config ...
|
||||
bool SetConfig(XDEMAInputs &config)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mLength = config.length;
|
||||
mShift = config.shift;
|
||||
mShowDema = config.showDema;
|
||||
mShowEMA = config.showEMA;
|
||||
mShowEMAOfEMA = config.showEMAOfEMA;
|
||||
|
||||
//
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show Dema ...
|
||||
bool ShowDema(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowDema == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowDema = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show EMA ...
|
||||
bool ShowEMA(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowEMA == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowEMA = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show EMA of EMA ...
|
||||
bool ShowEMAOfEMA(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowEMAOfEMA == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowEMAOfEMA = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Buffers based on Given Bar Index ...
|
||||
virtual void Calculate(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// DEMA ...
|
||||
ArraySetAsSeries(demaBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XDEMA_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
demaBuffer);
|
||||
|
||||
//
|
||||
// EMA ...
|
||||
ArraySetAsSeries(emaBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XDEMA_EMA_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
emaBuffer);
|
||||
|
||||
//
|
||||
// EMAOFEMA ...
|
||||
ArraySetAsSeries(emaOfEMABuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XDEMA_EMA_OF_EMA_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
emaOfEMABuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Info at Specific Bar Index ...
|
||||
XDEMAInfo GetInfo(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
XDEMAInfo result;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculations ...
|
||||
Calculate(barIndex);
|
||||
|
||||
//
|
||||
// Generate Candle Time ...
|
||||
datetime barTime = GetCandleTime(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
barIndex);
|
||||
|
||||
//
|
||||
// Fill Result ...
|
||||
result.symbol = mSymbol;
|
||||
result.period = mPeriod;
|
||||
result.barTime = barTime;
|
||||
result.barIndex = barIndex;
|
||||
|
||||
//
|
||||
result.ema = emaBuffer[barIndex];
|
||||
result.dema = demaBuffer[barIndex];
|
||||
result.emaOfEma = emaOfEMABuffer[barIndex];
|
||||
|
||||
//
|
||||
Copy(
|
||||
emaBuffer,
|
||||
result.demas);
|
||||
Copy(
|
||||
demaBuffer,
|
||||
result.emas);
|
||||
Copy(
|
||||
emaOfEMABuffer,
|
||||
result.emaOfEMAs);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Indicator Properties ...
|
||||
//
|
||||
// Market ...
|
||||
//
|
||||
// Length ...
|
||||
int mLength;
|
||||
//
|
||||
// Shift ...
|
||||
int mShift;
|
||||
//
|
||||
// Presentation ...
|
||||
//
|
||||
// Show Dema ...
|
||||
bool mShowDema;
|
||||
//
|
||||
// Show EMA ...
|
||||
bool mShowEMA;
|
||||
//
|
||||
// Show EMA of EMA ...
|
||||
bool mShowEMAOfEMA;
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,733 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXFBBHelper
|
||||
// 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
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
struct XFBBInputs
|
||||
{
|
||||
//
|
||||
// Market ...
|
||||
//
|
||||
// Length ...
|
||||
int length;
|
||||
//
|
||||
// Multiplier ...
|
||||
double multiplier;
|
||||
//
|
||||
// Applied To ...
|
||||
ENUM_APPLIED_PRICE appliedTo;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
//
|
||||
// Show Base ...
|
||||
bool showBase;
|
||||
//
|
||||
// Show Band ...
|
||||
bool showBand;
|
||||
//
|
||||
// Show Golden Area ...
|
||||
bool showGoldenArea;
|
||||
//
|
||||
// Show Other Levels ...
|
||||
bool showOthers;
|
||||
};
|
||||
|
||||
//
|
||||
// Index of Lines ...
|
||||
enum ENUM_XFBB_BUFFERS
|
||||
{
|
||||
//
|
||||
// Main Requirements ...
|
||||
XFBB_BASE_LINE = 0,
|
||||
XFBB_BASE_STATE_LINE = 1,
|
||||
XFBB_UP_BAND_LINE = 13,
|
||||
XFBB_DOWN_BAND_LINE = 24,
|
||||
//
|
||||
XFBB_UP_1_LINE = 2,
|
||||
XFBB_UP_2_LINE = 4,
|
||||
XFBB_UP_3_LINE = 6,
|
||||
XFBB_UP_4_LINE = 8,
|
||||
XFBB_UP_5_LINE = 10,
|
||||
//
|
||||
XFBB_DOWN_1_LINE = 14,
|
||||
XFBB_DOWN_2_LINE = 16,
|
||||
XFBB_DOWN_3_LINE = 18,
|
||||
XFBB_DOWN_4_LINE = 20,
|
||||
XFBB_DOWN_5_LINE = 22,
|
||||
};
|
||||
|
||||
//
|
||||
// Retrieve Info Model ...
|
||||
struct XFBBInfo
|
||||
{
|
||||
//
|
||||
// Symbol ...
|
||||
string symbol;
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
// Bar Time ...
|
||||
datetime barTime;
|
||||
|
||||
//
|
||||
// Bar Index ...
|
||||
int barIndex;
|
||||
|
||||
//
|
||||
// Values ...
|
||||
double base;
|
||||
double baseState;
|
||||
|
||||
//
|
||||
double upBand;
|
||||
double downBand;
|
||||
|
||||
//
|
||||
double up1;
|
||||
double up2;
|
||||
double up3;
|
||||
double up4;
|
||||
double up5;
|
||||
|
||||
//
|
||||
double down1;
|
||||
double down2;
|
||||
double down3;
|
||||
double down4;
|
||||
double down5;
|
||||
|
||||
//
|
||||
double bases[];
|
||||
double baseStates[];
|
||||
double upBands[];
|
||||
double downBands[];
|
||||
double up1s[];
|
||||
double up2s[];
|
||||
double up3s[];
|
||||
double up4s[];
|
||||
double up5s[];
|
||||
double down1s[];
|
||||
double down2s[];
|
||||
double down3s[];
|
||||
double down4s[];
|
||||
double down5s[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
};
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Helping Indicators Requirements ...
|
||||
class XSCXFBBHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Buffers ...
|
||||
double baseBuffer[];
|
||||
double baseStateBuffer[];
|
||||
double upBandBuffer[];
|
||||
double downBandBuffer[];
|
||||
double up1Buffer[];
|
||||
double up2Buffer[];
|
||||
double up3Buffer[];
|
||||
double up4Buffer[];
|
||||
double up5Buffer[];
|
||||
double down1Buffer[];
|
||||
double down2Buffer[];
|
||||
double down3Buffer[];
|
||||
double down4Buffer[];
|
||||
double down5Buffer[];
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCXFBBHelper(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period // Trading Time Frame
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
PrepareTag();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCXFBBHelper()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Prepare Tag ...
|
||||
virtual void PrepareTag()
|
||||
{
|
||||
mTag = "XFBB" + GetTagPrefix();
|
||||
}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
result = mLength;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Indicator Handler ...
|
||||
bool Init()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result =
|
||||
//
|
||||
(mLength >= 2 &&
|
||||
mMultiplier >= 0)
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Handler ...
|
||||
mHandler = iCustom(
|
||||
//
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xfbb",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Market ...
|
||||
"",
|
||||
//
|
||||
// Length ...
|
||||
mLength,
|
||||
//
|
||||
// Multiplier ...
|
||||
mMultiplier,
|
||||
//
|
||||
// Applied To ...
|
||||
mApliedTo,
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
//
|
||||
// Show Base ...
|
||||
mShowBase,
|
||||
//
|
||||
// Show Band ...
|
||||
mShowBand,
|
||||
//
|
||||
// Show Golden Area ...
|
||||
mShowGoldenArea,
|
||||
//
|
||||
// Show Other Levels ...
|
||||
mShowOthers
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Current Config ...
|
||||
XFBBInputs GetConfig()
|
||||
{
|
||||
//
|
||||
XFBBInputs result;
|
||||
|
||||
//
|
||||
result.length = mLength;
|
||||
result.multiplier = mMultiplier;
|
||||
result.appliedTo = mApliedTo;
|
||||
result.showBase = mShowBase;
|
||||
result.showBand = mShowBand;
|
||||
result.showGoldenArea = mShowGoldenArea;
|
||||
result.showOthers = mShowOthers;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Config ...
|
||||
bool SetConfig(XFBBInputs &config)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mLength = config.length;
|
||||
mMultiplier = config.multiplier;
|
||||
mApliedTo = config.appliedTo;
|
||||
mShowBase = config.showBase;
|
||||
mShowBand = config.showBand;
|
||||
mShowGoldenArea = config.showGoldenArea;
|
||||
mShowOthers = config.showOthers;
|
||||
|
||||
//
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show Base ...
|
||||
bool ShowBase(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowBase == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowBase = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show Band ...
|
||||
bool ShowBand(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowBand == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowBand = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show Golden Area ...
|
||||
bool ShowGoldenArea(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowGoldenArea == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowGoldenArea = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show Other Levels ...
|
||||
bool ShowOthers(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowOthers == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowOthers = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Buffers based on Given Bar Index ...
|
||||
virtual void Calculate(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// BASE ...
|
||||
ArraySetAsSeries(baseBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XFBB_BASE_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
baseBuffer);
|
||||
|
||||
//
|
||||
// BASE STATE ...
|
||||
ArraySetAsSeries(baseStateBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XFBB_BASE_STATE_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
baseStateBuffer);
|
||||
|
||||
//
|
||||
// UPBAND ...
|
||||
ArraySetAsSeries(upBandBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XFBB_UP_BAND_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
upBandBuffer);
|
||||
|
||||
//
|
||||
// DOWNBAND ...
|
||||
ArraySetAsSeries(downBandBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XFBB_DOWN_BAND_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
downBandBuffer);
|
||||
|
||||
//
|
||||
// UP 1 ...
|
||||
ArraySetAsSeries(up1Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XFBB_UP_1_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
up1Buffer);
|
||||
|
||||
//
|
||||
// UP 2 ...
|
||||
ArraySetAsSeries(up2Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XFBB_UP_2_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
up2Buffer);
|
||||
|
||||
//
|
||||
// UP 3 ...
|
||||
ArraySetAsSeries(up3Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XFBB_UP_3_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
up3Buffer);
|
||||
|
||||
//
|
||||
// UP 4 ...
|
||||
ArraySetAsSeries(up4Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XFBB_UP_4_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
up4Buffer);
|
||||
|
||||
//
|
||||
// UP 5 ...
|
||||
ArraySetAsSeries(up5Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XFBB_UP_5_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
up5Buffer);
|
||||
|
||||
//
|
||||
// DOWN 1 ...
|
||||
ArraySetAsSeries(down1Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XFBB_DOWN_1_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
down1Buffer);
|
||||
|
||||
//
|
||||
// DOWN 2 ...
|
||||
ArraySetAsSeries(down2Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XFBB_DOWN_2_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
down2Buffer);
|
||||
|
||||
//
|
||||
// DOWN 3 ...
|
||||
ArraySetAsSeries(down3Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XFBB_DOWN_3_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
down3Buffer);
|
||||
|
||||
//
|
||||
// DOWN 4 ...
|
||||
ArraySetAsSeries(down4Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XFBB_DOWN_4_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
down4Buffer);
|
||||
|
||||
//
|
||||
// DOWN 5 ...
|
||||
ArraySetAsSeries(down5Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XFBB_DOWN_5_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
down5Buffer);
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Info at Specific Bar Index ...
|
||||
XFBBInfo GetInfo(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
XFBBInfo result;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculations ...
|
||||
Calculate(barIndex);
|
||||
|
||||
//
|
||||
// Generate Candle Time ...
|
||||
datetime barTime = GetCandleTime(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
barIndex);
|
||||
|
||||
//
|
||||
// Fill Result ...
|
||||
result.symbol = mSymbol;
|
||||
result.period = mPeriod;
|
||||
result.barTime = barTime;
|
||||
result.barIndex = barIndex;
|
||||
|
||||
//
|
||||
// values ...
|
||||
result.base = baseBuffer[barIndex];
|
||||
result.baseState = baseStateBuffer[barIndex];
|
||||
result.upBand = upBandBuffer[barIndex];
|
||||
result.downBand = downBandBuffer[barIndex];
|
||||
result.up1 = up1Buffer[barIndex];
|
||||
result.up2 = up2Buffer[barIndex];
|
||||
result.up3 = up3Buffer[barIndex];
|
||||
result.up4 = up4Buffer[barIndex];
|
||||
result.up5 = up5Buffer[barIndex];
|
||||
result.down1 = down1Buffer[barIndex];
|
||||
result.down2 = down2Buffer[barIndex];
|
||||
result.down3 = down3Buffer[barIndex];
|
||||
result.down4 = down4Buffer[barIndex];
|
||||
result.down5 = down5Buffer[barIndex];
|
||||
|
||||
//
|
||||
Copy(
|
||||
baseBuffer,
|
||||
result.bases);
|
||||
Copy(
|
||||
baseStateBuffer,
|
||||
result.baseStates);
|
||||
Copy(
|
||||
upBandBuffer,
|
||||
result.upBands);
|
||||
Copy(
|
||||
downBandBuffer,
|
||||
result.downBands);
|
||||
Copy(
|
||||
up1Buffer,
|
||||
result.up1s);
|
||||
Copy(
|
||||
up2Buffer,
|
||||
result.up2s);
|
||||
Copy(
|
||||
up3Buffer,
|
||||
result.up3s);
|
||||
Copy(
|
||||
up4Buffer,
|
||||
result.up4s);
|
||||
Copy(
|
||||
up5Buffer,
|
||||
result.up5s);
|
||||
Copy(
|
||||
down1Buffer,
|
||||
result.down1s);
|
||||
Copy(
|
||||
down2Buffer,
|
||||
result.down2s);
|
||||
Copy(
|
||||
down3Buffer,
|
||||
result.down3s);
|
||||
Copy(
|
||||
down4Buffer,
|
||||
result.down4s);
|
||||
Copy(
|
||||
down5Buffer,
|
||||
result.down5s);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Indicator Properties ...
|
||||
//
|
||||
// Market ...
|
||||
//
|
||||
// Length ...
|
||||
int mLength;
|
||||
//
|
||||
// Multiplier ...
|
||||
double mMultiplier;
|
||||
//
|
||||
// Applied To ...
|
||||
ENUM_APPLIED_PRICE mApliedTo;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
//
|
||||
// Show Base ...
|
||||
bool mShowBase;
|
||||
//
|
||||
// Show Band ...
|
||||
bool mShowBand;
|
||||
//
|
||||
// Show Golden Area ...
|
||||
bool mShowGoldenArea;
|
||||
//
|
||||
// Show Other Levels ...
|
||||
bool mShowOthers;
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,441 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXHKHelper
|
||||
// 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
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
struct XHKInputs
|
||||
{
|
||||
//
|
||||
// Presentation ...
|
||||
bool drawCandles; // Draw Hiken Ashi Candle
|
||||
bool drawCandleLines; // Show HikenAshi Lines
|
||||
};
|
||||
|
||||
//
|
||||
// Index of Lines ...
|
||||
enum ENUM_XHK_BUFFERS
|
||||
{
|
||||
//
|
||||
// Main Requirements ...
|
||||
XHK_OPEN_LINE = 0,
|
||||
XHK_HIGH_LINE = 1,
|
||||
XHK_LOW_LINE = 2,
|
||||
XHK_CLOSE_LINE = 3,
|
||||
};
|
||||
|
||||
//
|
||||
// Retrieve Info Model ...
|
||||
struct XHKInfo
|
||||
{
|
||||
//
|
||||
// Symbol ...
|
||||
string symbol;
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
// Bar Time ...
|
||||
datetime barTime;
|
||||
|
||||
//
|
||||
// Bar Index ...
|
||||
int barIndex;
|
||||
|
||||
//
|
||||
// Values ...
|
||||
double open;
|
||||
double high;
|
||||
double low;
|
||||
double close;
|
||||
|
||||
//
|
||||
double opens[];
|
||||
double highs[];
|
||||
double lows[];
|
||||
double closes[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
// Detect Candle is Bullish or not ...
|
||||
bool isBullish;
|
||||
|
||||
//
|
||||
// Detect Candle is Bearish or not ...
|
||||
bool isBearish;
|
||||
};
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Helping Indicators Requirements ...
|
||||
class XSCXHKHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Buffers ...
|
||||
double openBuffer[];
|
||||
double highBuffer[];
|
||||
double lowBuffer[];
|
||||
double closeBuffer[];
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCXHKHelper(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period // Trading Time Frame
|
||||
//
|
||||
// Indicator Properties ...
|
||||
//
|
||||
// Presentation ...
|
||||
//
|
||||
// Draw Hiken Ashi Candle ...
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
PrepareTag();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCXHKHelper()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// Draw Candles ...
|
||||
bool DrawCandles(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mDrawCandles == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mDrawCandles = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show HikenAshi Lines ...
|
||||
bool DrawCandleLines(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mDrawCandleLines == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mDrawCandleLines = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Prepare Tag ...
|
||||
virtual void PrepareTag()
|
||||
{
|
||||
mTag = "XHK" + GetTagPrefix();
|
||||
}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
result = 2;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Indicator Handler ...
|
||||
bool Init()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Handler ...
|
||||
mHandler = iCustom(
|
||||
//
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xhk",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
//
|
||||
// Draw Hiken Ashi Candle ...
|
||||
mDrawCandles,
|
||||
//
|
||||
// Show HikenAshi Lines ...
|
||||
mDrawCandleLines
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Current Config ...
|
||||
XHKInputs GetConfig()
|
||||
{
|
||||
//
|
||||
XHKInputs result;
|
||||
|
||||
//
|
||||
result.drawCandles = mDrawCandles;
|
||||
result.drawCandleLines = mDrawCandleLines;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Config ...
|
||||
bool SetConfig(XHKInputs &config)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mDrawCandles = config.drawCandles;
|
||||
mDrawCandleLines = config.drawCandleLines;
|
||||
|
||||
//
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Buffers based on Given Bar Index ...
|
||||
virtual void Calculate(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// OPEN ...
|
||||
ArraySetAsSeries(openBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XHK_OPEN_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
openBuffer);
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
ArraySetAsSeries(highBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XHK_HIGH_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
highBuffer);
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
ArraySetAsSeries(lowBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XHK_LOW_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
lowBuffer);
|
||||
|
||||
//
|
||||
// CLOSE ...
|
||||
ArraySetAsSeries(closeBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XHK_CLOSE_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
closeBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Info at Specific Bar Index ...
|
||||
XHKInfo GetInfo(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
XHKInfo result;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculations ...
|
||||
Calculate(barIndex);
|
||||
|
||||
//
|
||||
// Generate Candle Time ...
|
||||
datetime barTime = GetCandleTime(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
barIndex);
|
||||
|
||||
//
|
||||
// Fill Result ...
|
||||
result.symbol = mSymbol;
|
||||
result.period = mPeriod;
|
||||
result.barTime = barTime;
|
||||
result.barIndex = barIndex;
|
||||
|
||||
//
|
||||
double open = openBuffer[barIndex];
|
||||
double high = highBuffer[barIndex];
|
||||
double low = lowBuffer[barIndex];
|
||||
double close = closeBuffer[barIndex];
|
||||
|
||||
//
|
||||
result.open = open;
|
||||
result.high = high;
|
||||
result.low = low;
|
||||
result.close = close;
|
||||
|
||||
//
|
||||
Copy(
|
||||
openBuffer,
|
||||
result.opens);
|
||||
Copy(
|
||||
highBuffer,
|
||||
result.highs);
|
||||
Copy(
|
||||
lowBuffer,
|
||||
result.lows);
|
||||
Copy(
|
||||
closeBuffer,
|
||||
result.closes);
|
||||
|
||||
//
|
||||
result.isBullish = open < close;
|
||||
result.isBearish = open >= close;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Indicator Properties ...
|
||||
//
|
||||
// Presentation ...
|
||||
//
|
||||
// Draw Hiken Ashi Candle ...
|
||||
bool mDrawCandles;
|
||||
//
|
||||
// Show HikenAshi Lines ...
|
||||
bool mDrawCandleLines;
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,544 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXHULLHelper
|
||||
// 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
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
struct XHULLInputs
|
||||
{
|
||||
//
|
||||
// Market ...
|
||||
int length; // Length
|
||||
double divisor; // Divisor (Speed)
|
||||
|
||||
//
|
||||
// Calculation ...
|
||||
ENUM_APPLIED_PRICE upAppliedTo; // Up Zone Applied to
|
||||
ENUM_APPLIED_PRICE downAppliedTo; // Down Zone Applied to
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showUpZone; // Show Up Zone
|
||||
bool showDownZone; // Show Down Zone
|
||||
};
|
||||
|
||||
//
|
||||
// Index of Lines ...
|
||||
enum ENUM_XHULL_BUFFERS
|
||||
{
|
||||
//
|
||||
// Main Requirements ...
|
||||
XHULL_UP_ZONE_LINE = 0,
|
||||
XHULL_UP_ZONE_STATE_LINE = 1,
|
||||
XHULL_DOWN_ZONE_LINE = 2,
|
||||
XHULL_DOWN_ZONE_STATE_LINE = 3,
|
||||
};
|
||||
|
||||
//
|
||||
// Hull States ...
|
||||
enum XHULL_ZONE_STATES
|
||||
{
|
||||
XHULL_STATE_NEUTURAL = 0,
|
||||
XHULL_STATE_BULLISH = 1,
|
||||
XHULL_STATE_BEARISH = 2
|
||||
};
|
||||
|
||||
//
|
||||
// Retrieve Info Model ...
|
||||
struct XHULLInfo
|
||||
{
|
||||
//
|
||||
// Symbol ...
|
||||
string symbol;
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
// Bar Time ...
|
||||
datetime barTime;
|
||||
|
||||
//
|
||||
// Bar Index ...
|
||||
int barIndex;
|
||||
|
||||
//
|
||||
// Values ...
|
||||
double up;
|
||||
XHULL_ZONE_STATES upState;
|
||||
double down;
|
||||
XHULL_ZONE_STATES downState;
|
||||
|
||||
//
|
||||
double ups[];
|
||||
double upStates[];
|
||||
double downs[];
|
||||
double downStates[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isUpBullish;
|
||||
bool isUpNeutural;
|
||||
bool isUpBearish;
|
||||
|
||||
//
|
||||
bool isUpSwitchedToBullish;
|
||||
bool isUpSwitchedToBearish;
|
||||
bool isUpSwitchedToNeutural;
|
||||
|
||||
//
|
||||
bool isDownBullish;
|
||||
bool isDownBearish;
|
||||
bool isDownNeutural;
|
||||
|
||||
//
|
||||
bool isDownSwitchedToBullish;
|
||||
bool isDownSwitchedToBearish;
|
||||
bool isDownSwitchedToNeutural;
|
||||
};
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Helping Indicators Requirements ...
|
||||
class XSCXHULLHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Buffers ...
|
||||
double upBuffer[];
|
||||
double upStateBuffer[];
|
||||
double downBuffer[];
|
||||
double downStateBuffer[];
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCXHULLHelper(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period // Trading Time Frame
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
PrepareTag();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCXHULLHelper()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// Show Up Zone ...
|
||||
bool ShowUpZone(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowUpZone == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowUpZone = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show Down Zone ...
|
||||
bool ShowDownZone(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowDownZone == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowDownZone = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Prepare Tag ...
|
||||
virtual void PrepareTag()
|
||||
{
|
||||
mTag = "XHULL" + GetTagPrefix();
|
||||
}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
//
|
||||
result = mLength;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Indicator Handler ...
|
||||
bool Init()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
//
|
||||
result =
|
||||
mLength >= 9 &&
|
||||
mDivisor >= 0.5;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Handler ...
|
||||
mHandler = iCustom(
|
||||
//
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xhull",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Market ...
|
||||
"",
|
||||
//
|
||||
// Length ...
|
||||
mLength,
|
||||
//
|
||||
// Divisor (Speed) ...
|
||||
mDivisor,
|
||||
//
|
||||
// Calculation ...
|
||||
"",
|
||||
//
|
||||
// Up Zone Applied to ...
|
||||
mUpAppliedTo,
|
||||
//
|
||||
// Down Zone Applied to ...
|
||||
mDownAppliedTo,
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
//
|
||||
// Show Up Zone ...
|
||||
mShowUpZone,
|
||||
//
|
||||
// Show Down Zone ...
|
||||
mShowDownZone
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Current Config ...
|
||||
XHULLInputs GetConfig()
|
||||
{
|
||||
//
|
||||
XHULLInputs result;
|
||||
|
||||
//
|
||||
result.length = mLength;
|
||||
result.divisor = mDivisor;
|
||||
result.upAppliedTo = mUpAppliedTo;
|
||||
result.downAppliedTo = mDownAppliedTo;
|
||||
result.showUpZone = mShowUpZone;
|
||||
result.showDownZone = mShowDownZone;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Config ...
|
||||
bool SetConfig(XHULLInputs &config)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mLength = config.length;
|
||||
mDivisor = config.divisor;
|
||||
mUpAppliedTo = config.upAppliedTo;
|
||||
mDownAppliedTo = config.downAppliedTo;
|
||||
mShowUpZone = config.showUpZone;
|
||||
mShowDownZone = config.showDownZone;
|
||||
|
||||
//
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Buffers based on Given Bar Index ...
|
||||
virtual void Calculate(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// UP ...
|
||||
ArraySetAsSeries(upBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XHULL_UP_ZONE_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
upBuffer);
|
||||
|
||||
//
|
||||
// UP State ...
|
||||
ArraySetAsSeries(upStateBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XHULL_UP_ZONE_STATE_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
upStateBuffer);
|
||||
|
||||
//
|
||||
// DOWN ...
|
||||
ArraySetAsSeries(downBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XHULL_DOWN_ZONE_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
downBuffer);
|
||||
|
||||
//
|
||||
// DOWN State ...
|
||||
ArraySetAsSeries(downStateBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XHULL_DOWN_ZONE_STATE_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
downStateBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Info at Specific Bar Index ...
|
||||
XHULLInfo GetInfo(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
XHULLInfo result;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculations ...
|
||||
Calculate(barIndex);
|
||||
|
||||
//
|
||||
// Generate Candle Time ...
|
||||
datetime barTime = GetCandleTime(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
barIndex);
|
||||
|
||||
//
|
||||
// Fill Result ...
|
||||
result.symbol = mSymbol;
|
||||
result.period = mPeriod;
|
||||
result.barTime = barTime;
|
||||
result.barIndex = barIndex;
|
||||
|
||||
//
|
||||
double up = upBuffer[barIndex];
|
||||
XHULL_ZONE_STATES upState = (XHULL_ZONE_STATES)upStateBuffer[barIndex];
|
||||
XHULL_ZONE_STATES upStatePrev = (XHULL_ZONE_STATES)upStateBuffer[barIndex + 1];
|
||||
|
||||
//
|
||||
double down = downBuffer[barIndex];
|
||||
XHULL_ZONE_STATES downState = (XHULL_ZONE_STATES)downStateBuffer[barIndex];
|
||||
XHULL_ZONE_STATES downStatePrev = (XHULL_ZONE_STATES)downStateBuffer[barIndex + 1];
|
||||
|
||||
//
|
||||
result.up = up;
|
||||
result.upState = upState;
|
||||
result.down = down;
|
||||
result.downState = downState;
|
||||
|
||||
//
|
||||
Copy(
|
||||
upBuffer,
|
||||
result.ups);
|
||||
Copy(
|
||||
upStateBuffer,
|
||||
result.upStates);
|
||||
Copy(
|
||||
downBuffer,
|
||||
result.downs);
|
||||
Copy(
|
||||
downStateBuffer,
|
||||
result.downStates);
|
||||
|
||||
//
|
||||
result.isUpBullish = upState = XHULL_STATE_BULLISH;
|
||||
result.isUpBearish = upState = XHULL_STATE_BEARISH;
|
||||
result.isUpNeutural = upState = XHULL_STATE_NEUTURAL;
|
||||
|
||||
//
|
||||
result.isUpSwitchedToBullish = upState == XHULL_STATE_BULLISH &&
|
||||
upStatePrev != XHULL_STATE_BULLISH;
|
||||
result.isUpSwitchedToBearish = upState == XHULL_STATE_BEARISH &&
|
||||
upStatePrev != XHULL_STATE_BEARISH;
|
||||
result.isUpSwitchedToNeutural = upState == XHULL_STATE_NEUTURAL &&
|
||||
upStatePrev != XHULL_STATE_NEUTURAL;
|
||||
|
||||
//
|
||||
result.isDownBullish = downState = XHULL_STATE_BULLISH;
|
||||
result.isDownBearish = downState = XHULL_STATE_BEARISH;
|
||||
result.isDownNeutural = downState = XHULL_STATE_NEUTURAL;
|
||||
|
||||
//
|
||||
result.isDownSwitchedToBullish = downState == XHULL_STATE_BULLISH &&
|
||||
downStatePrev != XHULL_STATE_BULLISH;
|
||||
result.isDownSwitchedToBearish = downState == XHULL_STATE_BEARISH &&
|
||||
downStatePrev != XHULL_STATE_BEARISH;
|
||||
result.isDownSwitchedToNeutural = downState == XHULL_STATE_NEUTURAL &&
|
||||
downStatePrev != XHULL_STATE_NEUTURAL;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Indicator Properties ...
|
||||
//
|
||||
// Market ...
|
||||
//
|
||||
// Length ...
|
||||
int mLength;
|
||||
//
|
||||
// Divisor (Speed) ...
|
||||
double mDivisor;
|
||||
//
|
||||
// Calculation ...
|
||||
//
|
||||
// Up Zone Applied to ...
|
||||
ENUM_APPLIED_PRICE mUpAppliedTo;
|
||||
//
|
||||
// Down Zone Applied to ...
|
||||
ENUM_APPLIED_PRICE mDownAppliedTo;
|
||||
//
|
||||
// Presentation ...
|
||||
//
|
||||
// Show Up Zone ...
|
||||
bool mShowUpZone;
|
||||
//
|
||||
// Show Down Zone ...
|
||||
bool mShowDownZone;
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
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
Binary file not shown.
@@ -0,0 +1,895 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXMRBHelper
|
||||
// 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
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
struct XMRBInputs
|
||||
{
|
||||
//
|
||||
// Ribbon 1 ...
|
||||
int fast1Length; // Fast
|
||||
int slow1Length; // Slow
|
||||
|
||||
//
|
||||
// Ribbon 2 ...
|
||||
int fast2Length; // Fast
|
||||
int slow2Length; // Slow
|
||||
|
||||
//
|
||||
// Ribbon 3 ...
|
||||
int fast3Length; // Fast
|
||||
int slow3Length; // Slow
|
||||
|
||||
//
|
||||
// Ribbon 4 ...
|
||||
int fast4Length; // Fast
|
||||
int slow4Length; // Slow
|
||||
|
||||
//
|
||||
// Ribbon 5 ...
|
||||
int fast5Length; // Fast
|
||||
int slow5Length; // Slow
|
||||
|
||||
//
|
||||
// Calculation ...
|
||||
ENUM_MA_METHOD ribbonMode; // Mode
|
||||
ENUM_APPLIED_PRICE ribbonAppliedTo; // Applied To
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showFastMa; // Show Fast
|
||||
bool showSlowMa; // Show Slow
|
||||
bool showRibbon; // Show Ribbon
|
||||
};
|
||||
|
||||
//
|
||||
// Index of Lines ...
|
||||
enum ENUM_XMRB_BUFFERS
|
||||
{
|
||||
//
|
||||
// Main Requirements ...
|
||||
XMRB_FAST_LINE = 0,
|
||||
XMRB_SLOW_LINE = 1,
|
||||
//
|
||||
// RIBBON 1 ...
|
||||
XMRB_R1_FAST_LINE = 2,
|
||||
XMRB_R1_SLOW_LINE = 3,
|
||||
//
|
||||
// RIBBON 2 ...
|
||||
XMRB_R2_FAST_LINE = 4,
|
||||
XMRB_R2_SLOW_LINE = 5,
|
||||
//
|
||||
// RIBBON 3 ...
|
||||
XMRB_R3_FAST_LINE = 6,
|
||||
XMRB_R3_SLOW_LINE = 7,
|
||||
//
|
||||
// RIBBON 4 ...
|
||||
XMRB_R4_FAST_LINE = 8,
|
||||
XMRB_R4_SLOW_LINE = 9,
|
||||
//
|
||||
// RIBBON 5 ...
|
||||
XMRB_R5_FAST_LINE = 10,
|
||||
XMRB_R5_SLOW_LINE = 11,
|
||||
};
|
||||
|
||||
//
|
||||
// Retrieve Info Model ...
|
||||
struct XMRBInfo
|
||||
{
|
||||
//
|
||||
// Symbol ...
|
||||
string symbol;
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
// Bar Time ...
|
||||
datetime barTime;
|
||||
|
||||
//
|
||||
// Bar Index ...
|
||||
int barIndex;
|
||||
|
||||
//
|
||||
// Values ...
|
||||
double fast;
|
||||
double slow;
|
||||
double fastR1;
|
||||
double slowR1;
|
||||
double fastR2;
|
||||
double slowR2;
|
||||
double fastR3;
|
||||
double slowR3;
|
||||
double fastR4;
|
||||
double slowR4;
|
||||
double fastR5;
|
||||
double slowR5;
|
||||
|
||||
//
|
||||
double fasts[];
|
||||
double slows[];
|
||||
double fastR1s[];
|
||||
double slowR1s[];
|
||||
double fastR2s[];
|
||||
double slowR2s[];
|
||||
double fastR3s[];
|
||||
double slowR3s[];
|
||||
double fastR4s[];
|
||||
double slowR4s[];
|
||||
double fastR5s[];
|
||||
double slowR5s[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isFastOverSlow;
|
||||
bool isFastCrossedOverSlow;
|
||||
bool isFastUnderSlow;
|
||||
bool isFastCrossedUnderSlow;
|
||||
|
||||
//
|
||||
bool isR1FastOverSlow;
|
||||
bool isR1FastCrossedOverSlow;
|
||||
bool isR1FastUnderSlow;
|
||||
bool isR1FastCrossedUnderSlow;
|
||||
|
||||
//
|
||||
bool isR2FastOverSlow;
|
||||
bool isR2FastCrossedOverSlow;
|
||||
bool isR2FastUnderSlow;
|
||||
bool isR2FastCrossedUnderSlow;
|
||||
|
||||
//
|
||||
bool isR3FastOverSlow;
|
||||
bool isR3FastCrossedOverSlow;
|
||||
bool isR3FastUnderSlow;
|
||||
bool isR3FastCrossedUnderSlow;
|
||||
|
||||
//
|
||||
bool isR4FastOverSlow;
|
||||
bool isR4FastCrossedOverSlow;
|
||||
bool isR4FastUnderSlow;
|
||||
bool isR4FastCrossedUnderSlow;
|
||||
|
||||
//
|
||||
bool isR5FastOverSlow;
|
||||
bool isR5FastCrossedOverSlow;
|
||||
bool isR5FastUnderSlow;
|
||||
bool isR5FastCrossedUnderSlow;
|
||||
};
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Helping Indicators Requirements ...
|
||||
class XSCXMRBHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Buffers ...
|
||||
double fastBuffer[];
|
||||
double slowBuffer[];
|
||||
double fastR1Buffer[];
|
||||
double slowR1Buffer[];
|
||||
double fastR2Buffer[];
|
||||
double slowR2Buffer[];
|
||||
double fastR3Buffer[];
|
||||
double slowR3Buffer[];
|
||||
double fastR4Buffer[];
|
||||
double slowR4Buffer[];
|
||||
double fastR5Buffer[];
|
||||
double slowR5Buffer[];
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCXMRBHelper(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period // Trading Time Frame
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
PrepareTag();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCXMRBHelper()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// Show Fast ...
|
||||
bool ShowFast(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowFastMa == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowFastMa = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show Slow ...
|
||||
bool ShowSlow(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowSlowMa == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowSlowMa = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show Ribbon ...
|
||||
bool ShowRibbon(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowRibbon == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowRibbon = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Prepare Tag ...
|
||||
virtual void PrepareTag()
|
||||
{
|
||||
mTag = "XMRB" + GetTagPrefix();
|
||||
}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
result = MathMax(mFast1Length, mFast2Length);
|
||||
result = MathMax(result, mFast3Length);
|
||||
result = MathMax(result, mFast4Length);
|
||||
result = MathMax(result, mFast5Length);
|
||||
|
||||
//
|
||||
result = MathMax(result, mSlow1Length);
|
||||
result = MathMax(result, mSlow2Length);
|
||||
result = MathMax(result, mSlow3Length);
|
||||
result = MathMax(result, mSlow4Length);
|
||||
result = MathMax(result, mSlow5Length);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Indicator Handler ...
|
||||
bool Init()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
result =
|
||||
//
|
||||
(mFast1Length > 2 &&
|
||||
mFast2Length > mFast1Length &&
|
||||
mFast3Length > mFast2Length &&
|
||||
mFast4Length > mFast3Length &&
|
||||
mFast5Length > mFast4Length &&
|
||||
mSlow1Length > mFast1Length &&
|
||||
mSlow2Length > mFast2Length &&
|
||||
mSlow3Length > mFast3Length &&
|
||||
mSlow4Length > mFast4Length &&
|
||||
mSlow5Length > mFast5Length &&
|
||||
mSlow2Length > mSlow1Length &&
|
||||
mSlow3Length > mSlow2Length &&
|
||||
mSlow4Length > mSlow3Length &&
|
||||
mSlow5Length > mSlow4Length
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Handler ...
|
||||
mHandler = iCustom(
|
||||
//
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xmrb",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Ribbon 1 ...
|
||||
"",
|
||||
mFast1Length,
|
||||
mSlow1Length,
|
||||
//
|
||||
// Ribbon 2 ...
|
||||
"",
|
||||
mFast2Length,
|
||||
mSlow2Length,
|
||||
//
|
||||
// Ribbon 3 ...
|
||||
"",
|
||||
mFast3Length,
|
||||
mSlow3Length,
|
||||
//
|
||||
// Ribbon 4 ...
|
||||
"",
|
||||
mFast4Length,
|
||||
mSlow4Length,
|
||||
//
|
||||
// Ribbon 5 ...
|
||||
"",
|
||||
mFast5Length,
|
||||
mSlow5Length,
|
||||
//
|
||||
// Calculation ...
|
||||
"",
|
||||
//
|
||||
// Mode ...
|
||||
mRibbonMode,
|
||||
//
|
||||
// Applied To ...
|
||||
mRibbonAppliedTo,
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
//
|
||||
// Show Fast ...
|
||||
mShowFastMa,
|
||||
//
|
||||
// Show Slow ...
|
||||
mShowSlowMa,
|
||||
//
|
||||
// Show Ribbon ...
|
||||
mShowRibbon
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Current Config ...
|
||||
XMRBInputs GetConfig()
|
||||
{
|
||||
//
|
||||
XMRBInputs result;
|
||||
|
||||
//
|
||||
result.fast1Length = mFast1Length;
|
||||
result.slow1Length = mSlow1Length;
|
||||
result.fast2Length = mFast2Length;
|
||||
result.slow2Length = mSlow2Length;
|
||||
result.fast3Length = mFast3Length;
|
||||
result.slow3Length = mSlow3Length;
|
||||
result.fast4Length = mFast4Length;
|
||||
result.slow4Length = mSlow4Length;
|
||||
result.fast5Length = mFast5Length;
|
||||
result.slow5Length = mSlow5Length;
|
||||
result.ribbonMode = mRibbonMode;
|
||||
result.ribbonAppliedTo = mRibbonAppliedTo;
|
||||
result.showFastMa = mShowFastMa;
|
||||
result.showSlowMa = mShowSlowMa;
|
||||
result.showRibbon = mShowRibbon;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Config ...
|
||||
bool SetConfig(XMRBInputs &config)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mFast1Length = config.fast1Length;
|
||||
mSlow1Length = config.slow1Length;
|
||||
mFast2Length = config.fast2Length;
|
||||
mSlow2Length = config.slow2Length;
|
||||
mFast3Length = config.fast3Length;
|
||||
mSlow3Length = config.slow3Length;
|
||||
mFast4Length = config.fast4Length;
|
||||
mSlow4Length = config.slow4Length;
|
||||
mFast5Length = config.fast5Length;
|
||||
mSlow5Length = config.slow5Length;
|
||||
mRibbonMode = config.ribbonMode;
|
||||
mRibbonAppliedTo = config.ribbonAppliedTo;
|
||||
mShowFastMa = config.showFastMa;
|
||||
mShowSlowMa = config.showSlowMa;
|
||||
mShowRibbon = config.showRibbon;
|
||||
|
||||
//
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Buffers based on Given Bar Index ...
|
||||
virtual void Calculate(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// FAST ...
|
||||
ArraySetAsSeries(fastBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XMRB_FAST_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
fastBuffer);
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
ArraySetAsSeries(slowBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XMRB_SLOW_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
slowBuffer);
|
||||
|
||||
//
|
||||
// RIBBON 1 ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
ArraySetAsSeries(fastR1Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XMRB_R1_FAST_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
fastR1Buffer);
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
ArraySetAsSeries(slowR1Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XMRB_R1_SLOW_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
slowR1Buffer);
|
||||
|
||||
//
|
||||
// RIBBON 2 ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
ArraySetAsSeries(fastR2Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XMRB_R2_FAST_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
fastR2Buffer);
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
ArraySetAsSeries(slowR2Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XMRB_R2_SLOW_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
slowR2Buffer);
|
||||
|
||||
//
|
||||
// RIBBON 3 ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
ArraySetAsSeries(fastR3Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XMRB_R3_FAST_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
fastR3Buffer);
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
ArraySetAsSeries(slowR3Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XMRB_R3_SLOW_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
slowR3Buffer);
|
||||
|
||||
//
|
||||
// RIBBON 4 ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
ArraySetAsSeries(fastR4Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XMRB_R4_FAST_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
fastR4Buffer);
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
ArraySetAsSeries(slowR4Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XMRB_R4_SLOW_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
slowR4Buffer);
|
||||
|
||||
//
|
||||
// RIBBON 5 ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
ArraySetAsSeries(fastR5Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XMRB_R5_FAST_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
fastR5Buffer);
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
ArraySetAsSeries(slowR5Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XMRB_R5_SLOW_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
slowR5Buffer);
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Info at Specific Bar Index ...
|
||||
XMRBInfo GetInfo(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
XMRBInfo result;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculations ...
|
||||
Calculate(barIndex);
|
||||
|
||||
//
|
||||
// Generate Candle Time ...
|
||||
datetime barTime = GetCandleTime(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
barIndex);
|
||||
|
||||
//
|
||||
// Fill Result ...
|
||||
result.symbol = mSymbol;
|
||||
result.period = mPeriod;
|
||||
result.barTime = barTime;
|
||||
result.barIndex = barIndex;
|
||||
|
||||
//
|
||||
double fast = fastBuffer[barIndex];
|
||||
double fastPrev = fastBuffer[barIndex + 1];
|
||||
double slow = slowBuffer[barIndex];
|
||||
double slowPrev = slowBuffer[barIndex + 1];
|
||||
double fastR1 = fastR1Buffer[barIndex];
|
||||
double fastR1Prev = fastR1Buffer[barIndex + 1];
|
||||
double slowR1 = slowR1Buffer[barIndex];
|
||||
double slowR1Prev = slowR1Buffer[barIndex + 1];
|
||||
double fastR2 = fastR2Buffer[barIndex];
|
||||
double fastR2Prev = fastR2Buffer[barIndex + 1];
|
||||
double slowR2 = slowR2Buffer[barIndex];
|
||||
double slowR2Prev = slowR2Buffer[barIndex + 1];
|
||||
double fastR3 = fastR3Buffer[barIndex];
|
||||
double fastR3Prev = fastR3Buffer[barIndex + 1];
|
||||
double slowR3 = slowR3Buffer[barIndex];
|
||||
double slowR3Prev = slowR3Buffer[barIndex + 1];
|
||||
double fastR4 = fastR4Buffer[barIndex];
|
||||
double fastR4Prev = fastR4Buffer[barIndex + 1];
|
||||
double slowR4 = slowR4Buffer[barIndex];
|
||||
double slowR4Prev = slowR4Buffer[barIndex + 1];
|
||||
double fastR5 = fastR5Buffer[barIndex];
|
||||
double fastR5Prev = fastR5Buffer[barIndex + 1];
|
||||
double slowR5 = slowR5Buffer[barIndex];
|
||||
double slowR5Prev = slowR5Buffer[barIndex + 1];
|
||||
|
||||
//
|
||||
Copy(
|
||||
fastBuffer,
|
||||
result.fasts);
|
||||
Copy(
|
||||
slowBuffer,
|
||||
result.slows);
|
||||
Copy(
|
||||
fastR1Buffer,
|
||||
result.fastR1s);
|
||||
Copy(
|
||||
slowR1Buffer,
|
||||
result.slowR1s);
|
||||
Copy(
|
||||
fastR2Buffer,
|
||||
result.fastR2s);
|
||||
Copy(
|
||||
slowR2Buffer,
|
||||
result.slowR2s);
|
||||
Copy(
|
||||
fastR3Buffer,
|
||||
result.fastR3s);
|
||||
Copy(
|
||||
slowR3Buffer,
|
||||
result.slowR3s);
|
||||
Copy(
|
||||
fastR4Buffer,
|
||||
result.fastR4s);
|
||||
Copy(
|
||||
slowR4Buffer,
|
||||
result.slowR4s);
|
||||
Copy(
|
||||
fastR5Buffer,
|
||||
result.fastR5s);
|
||||
Copy(
|
||||
slowR5Buffer,
|
||||
result.slowR5s);
|
||||
|
||||
//
|
||||
result.fast = fast;
|
||||
result.slow = slow;
|
||||
result.fastR1 = fastR1;
|
||||
result.slowR1 = slowR1;
|
||||
result.fastR2 = fastR2;
|
||||
result.slowR2 = slowR2;
|
||||
result.fastR3 = fastR3;
|
||||
result.slowR3 = slowR3;
|
||||
result.fastR4 = fastR4;
|
||||
result.slowR4 = slowR4;
|
||||
result.fastR5 = fastR5;
|
||||
result.slowR5 = slowR5;
|
||||
|
||||
//
|
||||
result.isFastOverSlow =
|
||||
fast > slow;
|
||||
result.isFastCrossedOverSlow =
|
||||
fast > slow && fastPrev <= slowPrev;
|
||||
result.isFastUnderSlow =
|
||||
fast < slow;
|
||||
result.isFastCrossedUnderSlow =
|
||||
fast < slow && fastPrev >= slowPrev;
|
||||
|
||||
//
|
||||
result.isR1FastOverSlow =
|
||||
fastR1 > slowR1;
|
||||
result.isR1FastCrossedOverSlow =
|
||||
fastR1 > slowR1 && fastR1Prev <= slowR1Prev;
|
||||
result.isR1FastUnderSlow =
|
||||
fastR1 < slowR1;
|
||||
result.isR1FastCrossedUnderSlow =
|
||||
fastR1 < slowR1 && fastR1Prev >= slowR1Prev;
|
||||
|
||||
//
|
||||
result.isR2FastOverSlow =
|
||||
fastR2 > slowR2;
|
||||
result.isR2FastCrossedOverSlow =
|
||||
fastR2 > slowR2 && fastR2Prev <= slowR2Prev;
|
||||
result.isR2FastUnderSlow =
|
||||
fastR2 < slowR2;
|
||||
result.isR2FastCrossedUnderSlow =
|
||||
fastR2 < slowR2 && fastR2Prev >= slowR2Prev;
|
||||
|
||||
//
|
||||
result.isR3FastOverSlow =
|
||||
fastR3 > slowR3;
|
||||
result.isR3FastCrossedOverSlow =
|
||||
fastR3 > slowR3 && fastR3Prev <= slowR3Prev;
|
||||
result.isR3FastUnderSlow =
|
||||
fastR3 < slowR3;
|
||||
result.isR3FastCrossedUnderSlow =
|
||||
fastR3 < slowR3 && fastR3Prev >= slowR3Prev;
|
||||
|
||||
//
|
||||
result.isR4FastOverSlow =
|
||||
fastR4 > slowR4;
|
||||
result.isR4FastCrossedOverSlow =
|
||||
fastR4 > slowR4 && fastR4Prev <= slowR4Prev;
|
||||
result.isR4FastUnderSlow =
|
||||
fastR4 < slowR4;
|
||||
result.isR4FastCrossedUnderSlow =
|
||||
fastR4 < slowR4 && fastR4Prev >= slowR4Prev;
|
||||
|
||||
//
|
||||
result.isR5FastOverSlow =
|
||||
fastR5 > slowR5;
|
||||
result.isR5FastCrossedOverSlow =
|
||||
fastR5 > slowR5 && fastR5Prev <= slowR5Prev;
|
||||
result.isR5FastUnderSlow =
|
||||
fastR5 < slowR5;
|
||||
result.isR5FastCrossedUnderSlow =
|
||||
fastR5 < slowR5 && fastR5Prev >= slowR5Prev;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Indicator Properties ...
|
||||
//
|
||||
// Market ...
|
||||
//
|
||||
// Ribbon 1 ...
|
||||
int mFast1Length;
|
||||
int mSlow1Length;
|
||||
//
|
||||
// Ribbon 2 ...
|
||||
int mFast2Length;
|
||||
int mSlow2Length;
|
||||
//
|
||||
// Ribbon 3 ...
|
||||
int mFast3Length;
|
||||
int mSlow3Length;
|
||||
//
|
||||
// Ribbon 4 ...
|
||||
int mFast4Length;
|
||||
int mSlow4Length;
|
||||
//
|
||||
// Ribbon 5 ...
|
||||
int mFast5Length;
|
||||
int mSlow5Length;
|
||||
//
|
||||
// Calculation ...
|
||||
//
|
||||
// Mode ...
|
||||
ENUM_MA_METHOD mRibbonMode;
|
||||
//
|
||||
// Applied To ...
|
||||
ENUM_APPLIED_PRICE mRibbonAppliedTo;
|
||||
//
|
||||
// Presentation ...
|
||||
//
|
||||
// Show Fast ...
|
||||
bool mShowFastMa;
|
||||
//
|
||||
// Show Slow ...
|
||||
bool mShowSlowMa;
|
||||
//
|
||||
// Show Ribbon ...
|
||||
bool mShowRibbon;
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,830 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXOSCHelper
|
||||
// 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
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
struct XOSCInputs
|
||||
{
|
||||
//
|
||||
// ATR ...
|
||||
int atrLength;
|
||||
|
||||
//
|
||||
// RVI ...
|
||||
int rviLength;
|
||||
|
||||
//
|
||||
// BULLPOWER ...
|
||||
int bullpLength;
|
||||
|
||||
//
|
||||
// BEARPOWER ...
|
||||
int bearpLength;
|
||||
|
||||
//
|
||||
// VOLUME ...
|
||||
ENUM_APPLIED_VOLUME volumeAppliedTo;
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
int rsiLength;
|
||||
ENUM_APPLIED_PRICE rsiAppliedTo;
|
||||
|
||||
//
|
||||
// CCI ...
|
||||
int cciLength;
|
||||
ENUM_APPLIED_PRICE cciAppliedTo;
|
||||
|
||||
//
|
||||
// MOMENTUM ...
|
||||
int momentumLength;
|
||||
ENUM_APPLIED_PRICE momentumAppliedTo;
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
double sarStep;
|
||||
double sarMaximum;
|
||||
|
||||
//
|
||||
// MACD ...
|
||||
int macdFastLength;
|
||||
int macdSlowLength;
|
||||
int macdSignaLength;
|
||||
ENUM_APPLIED_PRICE macdAppliedTo;
|
||||
|
||||
//
|
||||
// STOCHASTIC ...
|
||||
int stochKLength;
|
||||
int stochDLength;
|
||||
int stochSlowing;
|
||||
ENUM_MA_METHOD stochMaMethod;
|
||||
ENUM_STO_PRICE stochMode;
|
||||
|
||||
//
|
||||
// STANDARDDEVIATION ...
|
||||
int stddevLength;
|
||||
int stddevShift;
|
||||
ENUM_MA_METHOD stddevMethod;
|
||||
ENUM_APPLIED_PRICE stddevAppliedTo;
|
||||
};
|
||||
|
||||
//
|
||||
// Index of Lines ...
|
||||
enum ENUM_XOSC_BUFFERS
|
||||
{
|
||||
//
|
||||
// Main Requirements ...
|
||||
XOSC_ATR_LINE = 0,
|
||||
XOSC_RVI_MAIN_LINE = 1,
|
||||
XOSC_RVI_SIGNAL_LINE = 2,
|
||||
XOSC_BULLP_LINE = 3,
|
||||
XOSC_BEARP_LINE = 4,
|
||||
XOSC_VOLUME_LINE = 5,
|
||||
XOSC_RSI_LINE = 6,
|
||||
XOSC_CCI_LINE = 7,
|
||||
XOSC_MOMENTUM_LINE = 8,
|
||||
XOSC_SAR_LINE = 9,
|
||||
XOSC_MACD_MAIN_LINE = 10,
|
||||
XOSC_MACD_SIGNAL_LINE = 11,
|
||||
XOSC_STOCH_MAIN_LINE = 12,
|
||||
XOSC_STOCH_SIGNAL_LINE = 13,
|
||||
XOSC_STDDEV_LINE = 14,
|
||||
};
|
||||
|
||||
//
|
||||
// Retrieve Info Model ...
|
||||
struct XOSCInfo
|
||||
{
|
||||
//
|
||||
// Symbol ...
|
||||
string symbol;
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
// Bar Time ...
|
||||
datetime barTime;
|
||||
|
||||
//
|
||||
// Bar Index ...
|
||||
int barIndex;
|
||||
|
||||
//
|
||||
// Values ...
|
||||
double atr;
|
||||
double rviMain;
|
||||
double rviSignal;
|
||||
double bullPower;
|
||||
double bearPower;
|
||||
double volume;
|
||||
double rsi;
|
||||
double cci;
|
||||
double momentum;
|
||||
double sar;
|
||||
double macdMain;
|
||||
double macdSignal;
|
||||
double stochMain;
|
||||
double stochSignal;
|
||||
double stddev;
|
||||
|
||||
//
|
||||
double atrs[];
|
||||
double rviMains[];
|
||||
double rviSignals[];
|
||||
double bullPs[];
|
||||
double bearPs[];
|
||||
double volumes[];
|
||||
double rsis[];
|
||||
double ccis[];
|
||||
double momentums[];
|
||||
double sars[];
|
||||
double macdMains[];
|
||||
double macdSignals[];
|
||||
double stochMains[];
|
||||
double stochSignals[];
|
||||
double stddevs[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
// TODO: Implement it Later ...
|
||||
};
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Helping Indicators Requirements ...
|
||||
class XSCXOSCHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Buffers ...
|
||||
double atrBuffer[];
|
||||
double rviMainBuffer[];
|
||||
double rviSignalBuffer[];
|
||||
double bullPBuffer[];
|
||||
double bearPBuffer[];
|
||||
double volumeBuffer[];
|
||||
double rsiBuffer[];
|
||||
double cciBuffer[];
|
||||
double momentumBuffer[];
|
||||
double sarBuffer[];
|
||||
double macdMainBuffer[];
|
||||
double macdSignalBuffer[];
|
||||
double stochMainBuffer[];
|
||||
double stochSignalBuffer[];
|
||||
double stddevBuffer[];
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCXOSCHelper(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period // Trading Time Frame
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
PrepareTag();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCXOSCHelper()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Prepare Tag ...
|
||||
virtual void PrepareTag()
|
||||
{
|
||||
mTag = "XOSC" + GetTagPrefix();
|
||||
}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
result = MathMax(mAtrLength, mRviLength);
|
||||
result = MathMax(result, mBullpLength);
|
||||
result = MathMax(result, mBearpLength);
|
||||
result = MathMax(result, mRsiLength);
|
||||
result = MathMax(result, mCciLength);
|
||||
result = MathMax(result, mMomentumLength);
|
||||
result = MathMax(result, mMacdFastLength);
|
||||
result = MathMax(result, mMacdSlowLength);
|
||||
result = MathMax(result, mMacdSignaLength);
|
||||
result = MathMax(result, mStochKLength);
|
||||
result = MathMax(result, mStochDLength);
|
||||
result = MathMax(result, mStochSlowing);
|
||||
result = MathMax(result, mStddevLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Indicator Handler ...
|
||||
bool Init()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result =
|
||||
//
|
||||
mAtrLength >= 2 &&
|
||||
mRviLength >= 2 &&
|
||||
mBullpLength >= 2 &&
|
||||
mBearpLength >= 2 &&
|
||||
mRsiLength >= 2 &&
|
||||
mCciLength >= 2 &&
|
||||
mMomentumLength >= 2 &&
|
||||
mSarStep > 0 &&
|
||||
mSarStep < mSarMaximum &&
|
||||
mMacdFastLength >= 2 &&
|
||||
mMacdSlowLength > mMacdFastLength &&
|
||||
mMacdSignaLength >= 2 &&
|
||||
mStochKLength >= 2 &&
|
||||
mStochDLength >= 2 &&
|
||||
mStochSlowing >= 2 &&
|
||||
mStddevLength >= 2 &&
|
||||
mStddevShift >= 0
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Handler ...
|
||||
mHandler = iCustom(
|
||||
//
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xosc",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// ATR ...
|
||||
"",
|
||||
mAtrLength,
|
||||
//
|
||||
// RVI ...
|
||||
"",
|
||||
mRviLength,
|
||||
//
|
||||
// BULLPOWER ...
|
||||
"",
|
||||
mBullpLength,
|
||||
//
|
||||
// BEARPOWER ...
|
||||
"",
|
||||
mBearpLength,
|
||||
//
|
||||
// VOLUME ...
|
||||
"",
|
||||
mVolumeAppliedTo,
|
||||
//
|
||||
// RSI ...
|
||||
"",
|
||||
mRsiLength,
|
||||
mRsiAppliedTo,
|
||||
//
|
||||
// CCI ...
|
||||
"",
|
||||
mCciLength,
|
||||
mCciAppliedTo,
|
||||
//
|
||||
// STANDARDDEVIATION ...
|
||||
"",
|
||||
mStddevLength,
|
||||
mStddevShift,
|
||||
mStddevMethod,
|
||||
mStddevAppliedTo,
|
||||
//
|
||||
// MOMENTUM ...
|
||||
"",
|
||||
mMomentumLength,
|
||||
mMomentumAppliedTo,
|
||||
//
|
||||
// SAR ...
|
||||
"",
|
||||
mSarStep,
|
||||
mSarMaximum,
|
||||
//
|
||||
// MACD ...
|
||||
"",
|
||||
mMacdFastLength,
|
||||
mMacdSlowLength,
|
||||
mMacdSignaLength,
|
||||
mMacdAppliedTo,
|
||||
//
|
||||
// STOCHASTIC ...
|
||||
"",
|
||||
mStochKLength,
|
||||
mStochDLength,
|
||||
mStochSlowing,
|
||||
mStochMaMethod,
|
||||
mStochMode
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Current Config ...
|
||||
XOSCInputs GetConfig()
|
||||
{
|
||||
//
|
||||
XOSCInputs result;
|
||||
|
||||
//
|
||||
result.atrLength = mAtrLength;
|
||||
result.rviLength = mRviLength;
|
||||
result.bullpLength = mBullpLength;
|
||||
result.bearpLength = mBearpLength;
|
||||
result.volumeAppliedTo = mVolumeAppliedTo;
|
||||
result.rsiLength = mRsiLength;
|
||||
result.rsiAppliedTo = mRsiAppliedTo;
|
||||
result.cciLength = mCciLength;
|
||||
result.cciAppliedTo = mCciAppliedTo;
|
||||
result.momentumLength = mMomentumLength;
|
||||
result.momentumAppliedTo = mMomentumAppliedTo;
|
||||
result.sarStep = mSarStep;
|
||||
result.sarMaximum = mSarMaximum;
|
||||
result.macdFastLength = mMacdFastLength;
|
||||
result.macdSlowLength = mMacdSlowLength;
|
||||
result.macdSignaLength = mMacdSignaLength;
|
||||
result.macdAppliedTo = mMacdAppliedTo;
|
||||
result.stochKLength = mStochKLength;
|
||||
result.stochDLength = mStochDLength;
|
||||
result.stochSlowing = mStochSlowing;
|
||||
result.stochMaMethod = mStochMaMethod;
|
||||
result.stochMode = mStochMode;
|
||||
result.stddevLength = mStddevLength;
|
||||
result.stddevShift = mStddevShift;
|
||||
result.stddevMethod = mStddevMethod;
|
||||
result.stddevAppliedTo = mStddevAppliedTo;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Config ...
|
||||
bool SetConfig(XOSCInputs &config)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mAtrLength = config.atrLength;
|
||||
mRviLength = config.rviLength;
|
||||
mBullpLength = config.bullpLength;
|
||||
mBearpLength = config.bearpLength;
|
||||
mVolumeAppliedTo = config.volumeAppliedTo;
|
||||
mRsiLength = config.rsiLength;
|
||||
mRsiAppliedTo = config.rsiAppliedTo;
|
||||
mCciLength = config.cciLength;
|
||||
mCciAppliedTo = config.cciAppliedTo;
|
||||
mMomentumLength = config.momentumLength;
|
||||
mMomentumAppliedTo = config.momentumAppliedTo;
|
||||
mSarStep = config.sarStep;
|
||||
mSarMaximum = config.sarMaximum;
|
||||
mMacdFastLength = config.macdFastLength;
|
||||
mMacdSlowLength = config.macdSlowLength;
|
||||
mMacdSignaLength = config.macdSignaLength;
|
||||
mMacdAppliedTo = config.macdAppliedTo;
|
||||
mStochKLength = config.stochKLength;
|
||||
mStochDLength = config.stochDLength;
|
||||
mStochSlowing = config.stochSlowing;
|
||||
mStochMaMethod = config.stochMaMethod;
|
||||
mStochMode = config.stochMode;
|
||||
mStddevLength = config.stddevLength;
|
||||
mStddevShift = config.stddevShift;
|
||||
mStddevMethod = config.stddevMethod;
|
||||
mStddevAppliedTo = config.stddevAppliedTo;
|
||||
|
||||
//
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Buffers based on Given Bar Index ...
|
||||
virtual void Calculate(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// ATR ...
|
||||
ArraySetAsSeries(atrBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XOSC_ATR_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
atrBuffer);
|
||||
|
||||
//
|
||||
// RVI ...
|
||||
|
||||
//
|
||||
// MAIN ...
|
||||
ArraySetAsSeries(rviMainBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XOSC_RVI_MAIN_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
rviMainBuffer);
|
||||
|
||||
//
|
||||
// SIGNAL ...
|
||||
ArraySetAsSeries(rviSignalBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XOSC_RVI_SIGNAL_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
rviSignalBuffer);
|
||||
|
||||
//
|
||||
// BULLPOWER ...
|
||||
ArraySetAsSeries(bullPBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XOSC_BULLP_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
bullPBuffer);
|
||||
|
||||
//
|
||||
// BEARPOWER ...
|
||||
ArraySetAsSeries(bearPBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XOSC_BEARP_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
bearPBuffer);
|
||||
|
||||
//
|
||||
// VOLUME ...
|
||||
ArraySetAsSeries(volumeBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XOSC_BEARP_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
volumeBuffer);
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
ArraySetAsSeries(rsiBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XOSC_VOLUME_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
rsiBuffer);
|
||||
|
||||
//
|
||||
// CCI ...
|
||||
ArraySetAsSeries(cciBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XOSC_CCI_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
cciBuffer);
|
||||
|
||||
//
|
||||
// MOMENTUM ...
|
||||
ArraySetAsSeries(momentumBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XOSC_MOMENTUM_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
momentumBuffer);
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
ArraySetAsSeries(sarBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XOSC_SAR_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
sarBuffer);
|
||||
|
||||
//
|
||||
// MACD ...
|
||||
|
||||
//
|
||||
// MAIN ...
|
||||
ArraySetAsSeries(macdMainBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XOSC_MACD_MAIN_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
macdMainBuffer);
|
||||
|
||||
//
|
||||
// SIGNAL ...
|
||||
ArraySetAsSeries(macdSignalBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XOSC_MACD_SIGNAL_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
macdSignalBuffer);
|
||||
|
||||
//
|
||||
// STOCHASTIC ...
|
||||
|
||||
//
|
||||
// MAIN ...
|
||||
ArraySetAsSeries(stochMainBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XOSC_STOCH_MAIN_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
stochMainBuffer);
|
||||
|
||||
//
|
||||
// SIGNAL ...
|
||||
ArraySetAsSeries(stochSignalBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XOSC_STOCH_SIGNAL_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
stochSignalBuffer);
|
||||
|
||||
//
|
||||
// STANDARDDEVIATION ...
|
||||
ArraySetAsSeries(stddevBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XOSC_STDDEV_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
stddevBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Info at Specific Bar Index ...
|
||||
XOSCInfo GetInfo(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
XOSCInfo result;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculations ...
|
||||
Calculate(barIndex);
|
||||
|
||||
//
|
||||
// Generate Candle Time ...
|
||||
datetime barTime = GetCandleTime(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
barIndex);
|
||||
|
||||
//
|
||||
// Fill Result ...
|
||||
result.symbol = mSymbol;
|
||||
result.period = mPeriod;
|
||||
result.barTime = barTime;
|
||||
result.barIndex = barIndex;
|
||||
|
||||
//
|
||||
result.atr = atrBuffer[barIndex];
|
||||
result.rviMain = rviMainBuffer[barIndex];
|
||||
result.rviSignal = rviSignalBuffer[barIndex];
|
||||
result.bullPower = bullPBuffer[barIndex];
|
||||
result.bearPower = bearPBuffer[barIndex];
|
||||
result.volume = volumeBuffer[barIndex];
|
||||
result.rsi = rsiBuffer[barIndex];
|
||||
result.cci = cciBuffer[barIndex];
|
||||
result.momentum = momentumBuffer[barIndex];
|
||||
result.sar = sarBuffer[barIndex];
|
||||
result.macdMain = macdMainBuffer[barIndex];
|
||||
result.macdSignal = macdMainBuffer[barIndex];
|
||||
result.stochMain = stochMainBuffer[barIndex];
|
||||
result.stochSignal = stochSignalBuffer[barIndex];
|
||||
result.stddev = stddevBuffer[barIndex];
|
||||
|
||||
//
|
||||
Copy(
|
||||
atrBuffer,
|
||||
result.atrs);
|
||||
Copy(
|
||||
rviMainBuffer,
|
||||
result.rviMains);
|
||||
Copy(
|
||||
rviSignalBuffer,
|
||||
result.rviSignals);
|
||||
Copy(
|
||||
bullPBuffer,
|
||||
result.bullPs);
|
||||
Copy(
|
||||
bearPBuffer,
|
||||
result.bearPs);
|
||||
Copy(
|
||||
volumeBuffer,
|
||||
result.volumes);
|
||||
Copy(
|
||||
rsiBuffer,
|
||||
result.rsis);
|
||||
Copy(
|
||||
cciBuffer,
|
||||
result.ccis);
|
||||
Copy(
|
||||
momentumBuffer,
|
||||
result.momentums);
|
||||
Copy(
|
||||
sarBuffer,
|
||||
result.sars);
|
||||
Copy(
|
||||
macdMainBuffer,
|
||||
result.macdMains);
|
||||
Copy(
|
||||
macdSignalBuffer,
|
||||
result.macdSignals);
|
||||
Copy(
|
||||
stochMainBuffer,
|
||||
result.stochMains);
|
||||
Copy(
|
||||
stochSignalBuffer,
|
||||
result.stochSignals);
|
||||
Copy(
|
||||
stddevBuffer,
|
||||
result.stddevs);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Indicator Properties ...
|
||||
//
|
||||
// ATR ...
|
||||
int mAtrLength;
|
||||
|
||||
//
|
||||
// RVI ...
|
||||
int mRviLength;
|
||||
|
||||
//
|
||||
// BULLPOWER ...
|
||||
int mBullpLength;
|
||||
|
||||
//
|
||||
// BEARPOWER ...
|
||||
int mBearpLength;
|
||||
|
||||
//
|
||||
// VOLUME ...
|
||||
ENUM_APPLIED_VOLUME mVolumeAppliedTo;
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
int mRsiLength;
|
||||
ENUM_APPLIED_PRICE mRsiAppliedTo;
|
||||
|
||||
//
|
||||
// CCI ...
|
||||
int mCciLength;
|
||||
ENUM_APPLIED_PRICE mCciAppliedTo;
|
||||
|
||||
//
|
||||
// MOMENTUM ...
|
||||
int mMomentumLength;
|
||||
ENUM_APPLIED_PRICE mMomentumAppliedTo;
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
double mSarStep;
|
||||
double mSarMaximum;
|
||||
|
||||
//
|
||||
// MACD ...
|
||||
int mMacdFastLength;
|
||||
int mMacdSlowLength;
|
||||
int mMacdSignaLength;
|
||||
ENUM_APPLIED_PRICE mMacdAppliedTo;
|
||||
|
||||
//
|
||||
// STOCHASTIC ...
|
||||
int mStochKLength;
|
||||
int mStochDLength;
|
||||
int mStochSlowing;
|
||||
ENUM_MA_METHOD mStochMaMethod;
|
||||
ENUM_STO_PRICE mStochMode;
|
||||
|
||||
//
|
||||
// STANDARDDEVIATION ...
|
||||
int mStddevLength;
|
||||
int mStddevShift;
|
||||
ENUM_MA_METHOD mStddevMethod;
|
||||
ENUM_APPLIED_PRICE mStddevAppliedTo;
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,946 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXPVHelper
|
||||
// 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
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
struct XPVInputs
|
||||
{
|
||||
//
|
||||
// Makret Cycles ...
|
||||
int shortLength; // Short Length
|
||||
int mediumLength; // Medium Length
|
||||
int longLength; // Long Length
|
||||
int hindLength; // Hind Length
|
||||
double fiboLevel1; // Fibio 1st Level
|
||||
double fiboLevel2; // Fibio 2st Level
|
||||
double fiboLevel3; // Fibio 3rd Level
|
||||
|
||||
//
|
||||
// Detection Modes ...
|
||||
ENUM_SERIESMODE hhMode; // Highest High Calculation Method
|
||||
ENUM_SERIESMODE llMode; // Lowest Low Calculation Method
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showPeaksAndVales; // Show Peaks and Vales
|
||||
bool showLevels; // Show Levels
|
||||
bool showFibo1Levels; // Show Fibo 1st Level
|
||||
bool showFibo2Levels; // Show Fibo 2nd Level
|
||||
bool showFibo3Levels; // Show Fibo 3rd Level
|
||||
};
|
||||
|
||||
//
|
||||
// Index of Lines ...
|
||||
enum ENUM_XPV_BUFFERS
|
||||
{
|
||||
//
|
||||
// Main Requirements ...
|
||||
XPV_PEAKS_LINE = 0,
|
||||
XPV_VALES_LINE = 1,
|
||||
//
|
||||
XPV_RESISTANCE_LINE = 2,
|
||||
XPV_RESISTANCE_STATE_LINE = 3,
|
||||
//
|
||||
XPV_SUPPORT_LINE = 4,
|
||||
XPV_SUPPORT_STATE_LINE = 5,
|
||||
//
|
||||
XPV_FL1_LINE = 6,
|
||||
XPV_FL2_LINE = 8,
|
||||
XPV_FL3_LINE = 10,
|
||||
//
|
||||
// SHORT ...
|
||||
XPV_SHORT_HIGH_LINE = 12,
|
||||
XPV_SHORT_LOW_LINE = 13,
|
||||
//
|
||||
// MEDIUM ...
|
||||
XPV_MEDIUM_HIGH_LINE = 14,
|
||||
XPV_MEDIUM_LOW_LINE = 15,
|
||||
//
|
||||
// LONG ...
|
||||
XPV_LONG_HIGH_LINE = 16,
|
||||
XPV_LONG_LOW_LINE = 17,
|
||||
//
|
||||
// HIND ...
|
||||
XPV_HIND_HIGH_LINE = 18,
|
||||
XPV_HIND_LOW_LINE = 19,
|
||||
};
|
||||
|
||||
//
|
||||
// Retrieve Info Model ...
|
||||
struct XPVInfo
|
||||
{
|
||||
//
|
||||
// Symbol ...
|
||||
string symbol;
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
// Bar Time ...
|
||||
datetime barTime;
|
||||
|
||||
//
|
||||
// Bar Index ...
|
||||
int barIndex;
|
||||
|
||||
//
|
||||
// Values ...
|
||||
double peak;
|
||||
double vale;
|
||||
double fl1;
|
||||
double fl2;
|
||||
double fl3;
|
||||
|
||||
//
|
||||
double r;
|
||||
double rState;
|
||||
double s;
|
||||
double sSate;
|
||||
|
||||
//
|
||||
// SHORT ...
|
||||
double sl;
|
||||
double sh;
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
double ml;
|
||||
double mh;
|
||||
|
||||
//
|
||||
// LONG ...
|
||||
double ll;
|
||||
double lh;
|
||||
|
||||
//
|
||||
// HIND ...
|
||||
double hl;
|
||||
double hh;
|
||||
|
||||
//
|
||||
double peakss[];
|
||||
double valess[];
|
||||
double fl1s[];
|
||||
double fl2s[];
|
||||
double fl3s[];
|
||||
double rs[];
|
||||
double rStates[];
|
||||
double ss[];
|
||||
double sStates[];
|
||||
double sls[];
|
||||
double shs[];
|
||||
double mls[];
|
||||
double mhs[];
|
||||
double lls[];
|
||||
double lhs[];
|
||||
double hls[];
|
||||
double hhs[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
// Determines New Peaks Happens ...
|
||||
bool isNewPeak;
|
||||
|
||||
//
|
||||
// Determines New Vales Happens ...
|
||||
bool isNewVale;
|
||||
};
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Helping Indicators Requirements ...
|
||||
class XSCXPVHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Buffers ...
|
||||
double peaksBuffer[];
|
||||
double valesBuffer[];
|
||||
double fl1Buffer[];
|
||||
double fl2Buffer[];
|
||||
double fl3Buffer[];
|
||||
|
||||
//
|
||||
// Support and Resistance ...
|
||||
double rBuffer[];
|
||||
double rStateBuffer[];
|
||||
|
||||
//
|
||||
double sBuffer[];
|
||||
double sStateBuffer[];
|
||||
|
||||
//
|
||||
// SHORT ...
|
||||
double slBuffer[];
|
||||
double shBuffer[];
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
double mlBuffer[];
|
||||
double mhBuffer[];
|
||||
|
||||
//
|
||||
// LONG ...
|
||||
double llBuffer[];
|
||||
double lhBuffer[];
|
||||
|
||||
//
|
||||
// HIND ...
|
||||
double hlBuffer[];
|
||||
double hhBuffer[];
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCXPVHelper(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period // Trading Time Frame
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
PrepareTag();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCXPVHelper()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// Show Levels ...
|
||||
bool ShowLevels(
|
||||
bool show // Show or Hide Levels
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowLevels == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowLevels = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show Peaks and Vales ...
|
||||
bool ShowPeaksAnVales(
|
||||
bool show // Show or Hide Levels
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowPeaksAndVales == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowPeaksAndVales = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show Fibo 1st Level ...
|
||||
bool ShowFibo1Levels(
|
||||
bool show // Show or Hide Levels
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowFibo1Levels == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowFibo1Levels = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show Fibo 2nd Level ...
|
||||
bool ShowFibo2Levels(
|
||||
bool show // Show or Hide Levels
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowFibo2Levels == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowFibo2Levels = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show Fibo 3rd Level ...
|
||||
bool ShowFibo3Levels(
|
||||
bool show // Show or Hide Levels
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowFibo3Levels == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowFibo3Levels = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Prepare Tag ...
|
||||
virtual void PrepareTag()
|
||||
{
|
||||
mTag = "XPV" + GetTagPrefix();
|
||||
}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
result = MathMax(mShortLength, mMediumLength);
|
||||
result = MathMax(result, mLongLength);
|
||||
result = MathMax(result, mHindLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Indicator Handler ...
|
||||
bool Init()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result =
|
||||
//
|
||||
(mShortLength > 2 &&
|
||||
mMediumLength > mShortLength &&
|
||||
mLongLength > mMediumLength &&
|
||||
mHindLength > mLongLength)
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Handler ...
|
||||
mHandler = iCustom(
|
||||
//
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xpv",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Market ...
|
||||
"",
|
||||
//
|
||||
// Short Length ...
|
||||
mShortLength,
|
||||
//
|
||||
// Medium Length
|
||||
mMediumLength,
|
||||
//
|
||||
// Long Length ...
|
||||
mLongLength,
|
||||
//
|
||||
// Hind Length ...
|
||||
mHindLength,
|
||||
//
|
||||
// Fibio 1st Level ...
|
||||
mFiboLevel1,
|
||||
//
|
||||
// Fibio 2st Level ...
|
||||
mFiboLevel2,
|
||||
//
|
||||
// Fibio 3rd Level ...
|
||||
mFiboLevel3,
|
||||
//
|
||||
// Detection Mode ...
|
||||
"",
|
||||
//
|
||||
// Highest High Calculation Method ...
|
||||
mHHMode,
|
||||
//
|
||||
// Lowest Low Calculation Method ...
|
||||
mLLMode,
|
||||
//
|
||||
// Presentations ...
|
||||
"",
|
||||
//
|
||||
// Show Peaks and Vales ...
|
||||
mShowPeaksAndVales,
|
||||
//
|
||||
// Show Levels ...
|
||||
mShowLevels,
|
||||
//
|
||||
// Show Fibo 1st Level ...
|
||||
mShowFibo1Levels,
|
||||
//
|
||||
// Show Fibo 2nd Level ...
|
||||
mShowFibo2Levels,
|
||||
//
|
||||
// Show Fibo 3rd Level ...
|
||||
mShowFibo3Levels
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Current Config ...
|
||||
XPVInputs GetConfig()
|
||||
{
|
||||
//
|
||||
XPVInputs result;
|
||||
|
||||
//
|
||||
result.shortLength = mShortLength;
|
||||
result.mediumLength = mMediumLength;
|
||||
result.longLength = mLongLength;
|
||||
result.hindLength = mHindLength;
|
||||
result.fiboLevel1 = mFiboLevel1;
|
||||
result.fiboLevel2 = mFiboLevel2;
|
||||
result.fiboLevel3 = mFiboLevel3;
|
||||
result.hhMode = mHHMode;
|
||||
result.llMode = mLLMode;
|
||||
result.showPeaksAndVales = mShowPeaksAndVales;
|
||||
result.showLevels = mShowLevels;
|
||||
result.showFibo1Levels = mShowFibo1Levels;
|
||||
result.showFibo2Levels = mShowFibo2Levels;
|
||||
result.showFibo3Levels = mShowFibo3Levels;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Config ...
|
||||
bool SetConfig(XPVInputs &config)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mShortLength = config.shortLength;
|
||||
mMediumLength = config.mediumLength;
|
||||
mLongLength = config.longLength;
|
||||
mHindLength = config.hindLength;
|
||||
mFiboLevel1 = config.fiboLevel1;
|
||||
mFiboLevel2 = config.fiboLevel2;
|
||||
mFiboLevel3 = config.fiboLevel3;
|
||||
mHHMode = config.hhMode;
|
||||
mLLMode = config.llMode;
|
||||
mShowPeaksAndVales = config.showPeaksAndVales;
|
||||
mShowLevels = config.showLevels;
|
||||
mShowFibo1Levels = config.showFibo1Levels;
|
||||
mShowFibo2Levels = config.showFibo2Levels;
|
||||
mShowFibo3Levels = config.showFibo3Levels;
|
||||
|
||||
//
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Buffers based on Given Bar Index ...
|
||||
virtual void Calculate(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// PEAKS ...
|
||||
ArraySetAsSeries(peaksBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XPV_PEAKS_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
peaksBuffer);
|
||||
|
||||
//
|
||||
// VALES ...
|
||||
ArraySetAsSeries(valesBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XPV_VALES_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
valesBuffer);
|
||||
|
||||
//
|
||||
// FIBBO LEVELS ...
|
||||
|
||||
//
|
||||
// LEVEL 1 ...
|
||||
ArraySetAsSeries(fl1Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XPV_FL1_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
fl1Buffer);
|
||||
|
||||
//
|
||||
// LEVEL 2 ...
|
||||
ArraySetAsSeries(fl2Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XPV_FL2_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
fl2Buffer);
|
||||
|
||||
//
|
||||
// LEVEL 3 ...
|
||||
ArraySetAsSeries(fl3Buffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XPV_FL3_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
fl3Buffer);
|
||||
|
||||
//
|
||||
// Support and Resistance ...
|
||||
|
||||
//
|
||||
// Resistance ...
|
||||
ArraySetAsSeries(rBuffer, true);
|
||||
ArraySetAsSeries(rStateBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XPV_RESISTANCE_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
rBuffer);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XPV_RESISTANCE_STATE_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
rStateBuffer);
|
||||
|
||||
//
|
||||
// Support ...
|
||||
ArraySetAsSeries(sBuffer, true);
|
||||
ArraySetAsSeries(sStateBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XPV_SUPPORT_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
sBuffer);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XPV_SUPPORT_STATE_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
sStateBuffer);
|
||||
|
||||
//
|
||||
// CYCLES ...
|
||||
|
||||
//
|
||||
// SHORT ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
ArraySetAsSeries(shBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XPV_SHORT_HIGH_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
shBuffer);
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
ArraySetAsSeries(slBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XPV_SHORT_LOW_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
slBuffer);
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
ArraySetAsSeries(mhBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XPV_MEDIUM_HIGH_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
mhBuffer);
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
ArraySetAsSeries(mlBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XPV_MEDIUM_LOW_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
mlBuffer);
|
||||
|
||||
//
|
||||
// LONG ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
ArraySetAsSeries(lhBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XPV_LONG_HIGH_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
lhBuffer);
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
ArraySetAsSeries(llBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XPV_LONG_LOW_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
llBuffer);
|
||||
|
||||
//
|
||||
// HIND ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
ArraySetAsSeries(hhBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XPV_HIND_HIGH_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
hhBuffer);
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
ArraySetAsSeries(hlBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XPV_HIND_LOW_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
hlBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Info at Specific Bar Index ...
|
||||
XPVInfo GetInfo(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
XPVInfo result;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculations ...
|
||||
Calculate(barIndex);
|
||||
|
||||
//
|
||||
// Generate Candle Time ...
|
||||
datetime barTime = GetCandleTime(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
barIndex);
|
||||
|
||||
//
|
||||
// Fill Result ...
|
||||
result.symbol = mSymbol;
|
||||
result.period = mPeriod;
|
||||
result.barTime = barTime;
|
||||
result.barIndex = barIndex;
|
||||
|
||||
//
|
||||
result.peak = peaksBuffer[barIndex];
|
||||
result.vale = valesBuffer[barIndex];
|
||||
result.fl1 = fl1Buffer[barIndex];
|
||||
result.fl2 = fl2Buffer[barIndex];
|
||||
result.fl3 = fl3Buffer[barIndex];
|
||||
|
||||
//
|
||||
result.r = rBuffer[barIndex];
|
||||
result.rState = rStateBuffer[barIndex];
|
||||
result.s = sBuffer[barIndex];
|
||||
result.sSate = sStateBuffer[barIndex];
|
||||
|
||||
//
|
||||
// SHORT ...
|
||||
result.sl = slBuffer[barIndex];
|
||||
result.sh = shBuffer[barIndex];
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
result.ml = mlBuffer[barIndex];
|
||||
result.mh = mhBuffer[barIndex];
|
||||
|
||||
//
|
||||
// LONG ...
|
||||
result.ll = llBuffer[barIndex];
|
||||
result.lh = lhBuffer[barIndex];
|
||||
|
||||
//
|
||||
// HIND ...
|
||||
result.hl = hlBuffer[barIndex];
|
||||
result.hh = hhBuffer[barIndex];
|
||||
|
||||
//
|
||||
Copy(
|
||||
peaksBuffer,
|
||||
result.peakss);
|
||||
Copy(
|
||||
valesBuffer,
|
||||
result.valess);
|
||||
Copy(
|
||||
fl1Buffer,
|
||||
result.fl1s);
|
||||
Copy(
|
||||
fl2Buffer,
|
||||
result.fl2s);
|
||||
Copy(
|
||||
fl3Buffer,
|
||||
result.fl3s);
|
||||
Copy(
|
||||
rBuffer,
|
||||
result.rs);
|
||||
Copy(
|
||||
rStateBuffer,
|
||||
result.rStates);
|
||||
Copy(
|
||||
sBuffer,
|
||||
result.ss);
|
||||
Copy(
|
||||
sStateBuffer,
|
||||
result.sStates);
|
||||
Copy(
|
||||
slBuffer,
|
||||
result.sls);
|
||||
Copy(
|
||||
shBuffer,
|
||||
result.shs);
|
||||
Copy(
|
||||
mlBuffer,
|
||||
result.mls);
|
||||
Copy(
|
||||
mhBuffer,
|
||||
result.mhs);
|
||||
Copy(
|
||||
llBuffer,
|
||||
result.lls);
|
||||
Copy(
|
||||
lhBuffer,
|
||||
result.lhs);
|
||||
Copy(
|
||||
hlBuffer,
|
||||
result.hls);
|
||||
Copy(
|
||||
hhBuffer,
|
||||
result.hhs);
|
||||
|
||||
//
|
||||
result.isNewPeak =
|
||||
peaksBuffer[barIndex] != peaksBuffer[barIndex + 1];
|
||||
result.isNewVale =
|
||||
valesBuffer[barIndex] != valesBuffer[barIndex + 1];
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Indicator Properties ...
|
||||
//
|
||||
// Market ...
|
||||
//
|
||||
// Short Length ...
|
||||
int mShortLength;
|
||||
//
|
||||
// Medium Length
|
||||
int mMediumLength;
|
||||
//
|
||||
// Long Length ...
|
||||
int mLongLength;
|
||||
//
|
||||
// Hind Length ...
|
||||
int mHindLength;
|
||||
//
|
||||
// Fibio 1st Level ...
|
||||
double mFiboLevel1;
|
||||
//
|
||||
// Fibio 2st Level ...
|
||||
double mFiboLevel2;
|
||||
//
|
||||
// Fibio 3rd Level ...
|
||||
double mFiboLevel3;
|
||||
//
|
||||
// Detection Mode ...
|
||||
//
|
||||
// Highest High Calculation Method ...
|
||||
ENUM_SERIESMODE mHHMode;
|
||||
//
|
||||
// Lowest Low Calculation Method ...
|
||||
ENUM_SERIESMODE mLLMode;
|
||||
//
|
||||
// Presentations ...
|
||||
//
|
||||
// Show Peaks and Vales ...
|
||||
bool mShowPeaksAndVales;
|
||||
//
|
||||
// Show Levels ...
|
||||
bool mShowLevels;
|
||||
//
|
||||
// Show Fibo 1st Level ...
|
||||
bool mShowFibo1Levels;
|
||||
//
|
||||
// Show Fibo 2nd Level ...
|
||||
bool mShowFibo2Levels;
|
||||
//
|
||||
// Show Fibo 3rd Level ...
|
||||
bool mShowFibo3Levels;
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,481 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXSSLCHelper
|
||||
// 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
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
struct XSSLCInputs
|
||||
{
|
||||
//
|
||||
// Market ...
|
||||
int length; // Length
|
||||
|
||||
//
|
||||
// Calculation ...
|
||||
ENUM_MA_METHOD method; // Method
|
||||
ENUM_APPLIED_PRICE upAppliedTo; // Up Applied To
|
||||
ENUM_APPLIED_PRICE downAppliedTo; // Down Applied To
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showUp; // Show Up
|
||||
bool showDown; // Show Down
|
||||
};
|
||||
|
||||
//
|
||||
// Index of Lines ...
|
||||
enum ENUM_XSSLC_BUFFERS
|
||||
{
|
||||
//
|
||||
// Main Requirements ...
|
||||
XSSLC_UP_LINE = 0,
|
||||
XSSLC_DOWN_LINE = 1,
|
||||
};
|
||||
|
||||
//
|
||||
// Retrieve Info Model ...
|
||||
struct XSSLCInfo
|
||||
{
|
||||
//
|
||||
// Symbol ...
|
||||
string symbol;
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
// Bar Time ...
|
||||
datetime barTime;
|
||||
|
||||
//
|
||||
// Bar Index ...
|
||||
int barIndex;
|
||||
|
||||
//
|
||||
// Values ...
|
||||
double up;
|
||||
double down;
|
||||
|
||||
//
|
||||
double ups[];
|
||||
double downs[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
// Detect Trend is Bullish or not ...
|
||||
bool isBullish;
|
||||
|
||||
//
|
||||
// Detect Trend is Switched to Bullish Or not ...
|
||||
bool isSwitchedBullish;
|
||||
|
||||
//
|
||||
// Detect Trend is Bearish or not ...
|
||||
bool isBearish;
|
||||
|
||||
//
|
||||
// Detect Trend is Switched to Bearish Or not ...
|
||||
bool isSwitchedBearish;
|
||||
};
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Helping Indicators Requirements ...
|
||||
class XSCXSSLCHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Buffers ...
|
||||
double upBuffer[];
|
||||
double downBuffer[];
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCXSSLCHelper(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period // Trading Time Frame
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
PrepareTag();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCXSSLCHelper()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// Show Up ...
|
||||
bool ShowUp(
|
||||
bool show // Show or Hide Line
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowUp == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowUp = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show Down ...
|
||||
bool ShowDown(
|
||||
bool show // Show or Hide Line
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowDown == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowDown = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Prepare Tag ...
|
||||
virtual void PrepareTag()
|
||||
{
|
||||
mTag = "XSSLC" + GetTagPrefix();
|
||||
}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
result = mLength;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Indicator Handler ...
|
||||
bool Init()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result =
|
||||
//
|
||||
(mLength >= 2)
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Handler ...
|
||||
mHandler = iCustom(
|
||||
//
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xsslc",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Market ...
|
||||
"",
|
||||
//
|
||||
// Length ...
|
||||
mLength,
|
||||
//
|
||||
// Calculation ...
|
||||
"",
|
||||
//
|
||||
// Method ...
|
||||
mMethod,
|
||||
//
|
||||
// Up Applied To ...
|
||||
mUpAppliedTo,
|
||||
//
|
||||
// Down Applied To ...
|
||||
mDownAppliedTo,
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
//
|
||||
// Show Up ...
|
||||
mShowUp,
|
||||
//
|
||||
// Show Down ...
|
||||
mShowDown
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Current Config ...
|
||||
XSSLCInputs GetConfig()
|
||||
{
|
||||
//
|
||||
XSSLCInputs result;
|
||||
|
||||
//
|
||||
result.length = mLength;
|
||||
result.method = mMethod;
|
||||
result.upAppliedTo = mUpAppliedTo;
|
||||
result.downAppliedTo = mDownAppliedTo;
|
||||
result.showUp = mShowUp;
|
||||
result.showDown = mShowDown;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Config ...
|
||||
bool SetConfig(XSSLCInputs &config)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mLength = config.length;
|
||||
mMethod = config.method;
|
||||
mUpAppliedTo = config.upAppliedTo;
|
||||
mDownAppliedTo = config.downAppliedTo;
|
||||
mShowUp = config.showUp;
|
||||
mShowDown = config.showDown;
|
||||
|
||||
//
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Buffers based on Given Bar Index ...
|
||||
virtual void Calculate(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// UP ...
|
||||
ArraySetAsSeries(upBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XSSLC_UP_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
upBuffer);
|
||||
|
||||
//
|
||||
// DOWN ...
|
||||
ArraySetAsSeries(downBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XSSLC_DOWN_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
downBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Info at Specific Bar Index ...
|
||||
XSSLCInfo GetInfo(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
XSSLCInfo result;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculations ...
|
||||
Calculate(barIndex);
|
||||
|
||||
//
|
||||
// Generate Candle Time ...
|
||||
datetime barTime = GetCandleTime(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
barIndex);
|
||||
|
||||
//
|
||||
// Fill Result ...
|
||||
result.symbol = mSymbol;
|
||||
result.period = mPeriod;
|
||||
result.barTime = barTime;
|
||||
result.barIndex = barIndex;
|
||||
|
||||
//
|
||||
double up = upBuffer[barIndex];
|
||||
double upPrev = upBuffer[barIndex + 1];
|
||||
double down = downBuffer[barIndex];
|
||||
double downPrev = downBuffer[barIndex + 1];
|
||||
|
||||
//
|
||||
Copy(
|
||||
upBuffer,
|
||||
result.ups
|
||||
);
|
||||
Copy(
|
||||
downBuffer,
|
||||
result.downs
|
||||
);
|
||||
|
||||
//
|
||||
result.up = up;
|
||||
result.down = down;
|
||||
|
||||
//
|
||||
result.isBullish = up > down;
|
||||
result.isBearish = up < down;
|
||||
|
||||
//
|
||||
result.isSwitchedBullish =
|
||||
up > down &&
|
||||
upPrev <= downPrev;
|
||||
result.isSwitchedBearish =
|
||||
up < down &&
|
||||
upPrev >= downPrev;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Indicator Properties ...
|
||||
//
|
||||
// Market ...
|
||||
//
|
||||
// Length ...
|
||||
int mLength;
|
||||
//
|
||||
// Calculation ...
|
||||
//
|
||||
// Method ...
|
||||
ENUM_MA_METHOD mMethod;
|
||||
//
|
||||
// Up Applied To ...
|
||||
ENUM_APPLIED_PRICE mUpAppliedTo;
|
||||
//
|
||||
// Down Applied To ...
|
||||
ENUM_APPLIED_PRICE mDownAppliedTo;
|
||||
//
|
||||
// Presentation ...
|
||||
//
|
||||
// Show Up ...
|
||||
bool mShowUp;
|
||||
//
|
||||
// Show Down ...
|
||||
bool mShowDown;
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,473 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXSTRHelper
|
||||
// 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
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
struct XSTRInputs
|
||||
{
|
||||
//
|
||||
// Market ...
|
||||
//
|
||||
// Length ...
|
||||
int atrLength;
|
||||
//
|
||||
// Multiplier ...
|
||||
double atrMultiplier;
|
||||
//
|
||||
// Applied To ...
|
||||
ENUM_APPLIED_PRICE atrAppliedTo;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
//
|
||||
// Show Trends ...
|
||||
bool showTrends;
|
||||
//
|
||||
// Fill Trends ...
|
||||
bool fillTrends;
|
||||
};
|
||||
|
||||
//
|
||||
// Index of Lines ...
|
||||
enum ENUM_XSTR_BUFFERS
|
||||
{
|
||||
//
|
||||
// Main Requirements ...
|
||||
XSTR_LINE = 2,
|
||||
XSTR_TREND_LINE = 5
|
||||
};
|
||||
|
||||
//
|
||||
// Trend State ...
|
||||
enum ENUM_XSTR_TREND
|
||||
{
|
||||
XSTR_BULLISH = 1,
|
||||
XSTR_BEARISH = -1
|
||||
};
|
||||
|
||||
//
|
||||
// Retrieve Info Model ...
|
||||
struct XSTRInfo
|
||||
{
|
||||
//
|
||||
// Symbol ...
|
||||
string symbol;
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
// Bar Time ...
|
||||
datetime barTime;
|
||||
|
||||
//
|
||||
// Bar Index ...
|
||||
int barIndex;
|
||||
|
||||
//
|
||||
// Values ...
|
||||
double main;
|
||||
ENUM_XSTR_TREND trend;
|
||||
|
||||
//
|
||||
double mains[];
|
||||
double trends[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
bool isTrendBullish;
|
||||
bool isTrendBearish;
|
||||
bool isTrendSwitchedToBullish;
|
||||
bool isTrendSwitchedToBearish;
|
||||
};
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Helping Indicators Requirements ...
|
||||
class XSCXSTRHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Buffers ...
|
||||
double mainBuffer[];
|
||||
double trendBuffer[];
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCXSTRHelper(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period // Trading Time Frame
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
PrepareTag();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCXSTRHelper()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Prepare Tag ...
|
||||
virtual void PrepareTag()
|
||||
{
|
||||
mTag = "XSTR" + GetTagPrefix();
|
||||
}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
result = mAtrLength;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Indicator Handler ...
|
||||
bool Init()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result =
|
||||
//
|
||||
(mAtrLength >= 2 &&
|
||||
mAtrMultiplier >= 0)
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Handler ...
|
||||
mHandler = iCustom(
|
||||
//
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xstr",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Makret ...
|
||||
"",
|
||||
//
|
||||
// Length ...
|
||||
mAtrLength,
|
||||
//
|
||||
// Multiplier ...
|
||||
mAtrMultiplier,
|
||||
//
|
||||
// Applied To ...
|
||||
mAtrAppliedTo,
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
//
|
||||
// Show Trends ...
|
||||
mShowTrends,
|
||||
//
|
||||
// Fill Trends ...
|
||||
mFillTrends);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Current Config ...
|
||||
XSTRInputs GetConfig()
|
||||
{
|
||||
//
|
||||
XSTRInputs result;
|
||||
|
||||
//
|
||||
result.atrLength = mAtrLength;
|
||||
result.atrMultiplier = mAtrMultiplier;
|
||||
result.atrAppliedTo = mAtrAppliedTo;
|
||||
result.showTrends = mShowTrends;
|
||||
result.fillTrends = mFillTrends;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Config ...
|
||||
bool SetConfig(XSTRInputs &config)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mAtrLength = config.atrLength;
|
||||
mAtrMultiplier = config.atrMultiplier;
|
||||
mAtrAppliedTo = config.atrAppliedTo;
|
||||
mShowTrends = config.showTrends;
|
||||
mFillTrends = config.fillTrends;
|
||||
|
||||
//
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Show Trends ...
|
||||
bool ShowTrends(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mShowTrends == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mShowTrends = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Fill Trends ...
|
||||
bool FillTrends(
|
||||
bool show // Show or Hide
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (mFillTrends == show)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
mFillTrends = show;
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Buffers based on Given Bar Index ...
|
||||
virtual void Calculate(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// MAIN ...
|
||||
ArraySetAsSeries(mainBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XSTR_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
mainBuffer);
|
||||
|
||||
//
|
||||
// TREND ...
|
||||
ArraySetAsSeries(trendBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XSTR_TREND_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
trendBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Info at Specific Bar Index ...
|
||||
XSTRInfo GetInfo(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
XSTRInfo result;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculations ...
|
||||
Calculate(barIndex);
|
||||
|
||||
//
|
||||
// Generate Candle Time ...
|
||||
datetime barTime = GetCandleTime(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
barIndex);
|
||||
|
||||
//
|
||||
// Fill Result ...
|
||||
result.symbol = mSymbol;
|
||||
result.period = mPeriod;
|
||||
result.barTime = barTime;
|
||||
result.barIndex = barIndex;
|
||||
|
||||
//
|
||||
double main = mainBuffer[barIndex];
|
||||
ENUM_XSTR_TREND trend = (ENUM_XSTR_TREND)trendBuffer[barIndex];
|
||||
ENUM_XSTR_TREND trendPrev = (ENUM_XSTR_TREND)trendBuffer[barIndex + 1];
|
||||
|
||||
//
|
||||
Copy(
|
||||
mainBuffer,
|
||||
result.mains);
|
||||
Copy(
|
||||
trendBuffer,
|
||||
result.trends);
|
||||
|
||||
//
|
||||
result.main = main;
|
||||
result.trend = trend;
|
||||
|
||||
//
|
||||
result.isTrendBullish =
|
||||
trend == XSTR_BULLISH;
|
||||
|
||||
//
|
||||
result.isTrendBearish =
|
||||
trend == XSTR_BEARISH;
|
||||
|
||||
//
|
||||
result.isTrendSwitchedToBullish =
|
||||
trend == XSTR_BULLISH &&
|
||||
trendPrev != XSTR_BULLISH;
|
||||
|
||||
//
|
||||
result.isTrendSwitchedToBearish =
|
||||
trend == XSTR_BEARISH &&
|
||||
trendPrev != XSTR_BEARISH;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Indicator Properties ...
|
||||
//
|
||||
// Market ...
|
||||
//
|
||||
// Length ...
|
||||
int mAtrLength;
|
||||
//
|
||||
// Multiplier ...
|
||||
double mAtrMultiplier;
|
||||
//
|
||||
// Applied To ...
|
||||
ENUM_APPLIED_PRICE mAtrAppliedTo;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
//
|
||||
// Show Trends ...
|
||||
bool mShowTrends;
|
||||
//
|
||||
// Fill Trends ...
|
||||
bool mFillTrends;
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,445 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXTMHelper
|
||||
// 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
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
struct XTMInputs
|
||||
{
|
||||
//
|
||||
// Makret ...
|
||||
int length; // Length
|
||||
int shift; // Shift
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
ENUM_MA_METHOD method; // Method
|
||||
ENUM_APPLIED_PRICE appliedTo; // Applied To
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showLine; // Show Line
|
||||
};
|
||||
|
||||
//
|
||||
// Index of Lines ...
|
||||
enum ENUM_XTM_BUFFERS
|
||||
{
|
||||
//
|
||||
// Main Requirements ...
|
||||
XTM_LINE = 0,
|
||||
XTM_STATE_LINE = 1,
|
||||
};
|
||||
|
||||
//
|
||||
// XTM Indicator States ...
|
||||
enum ENUM_XTM_STATES
|
||||
{
|
||||
X_XTM_BULLISH = 0,
|
||||
X_XTM_BEARISH = 2,
|
||||
X_XTM_NEUTURAL = 1,
|
||||
};
|
||||
|
||||
//
|
||||
// Retrieve Info Model ...
|
||||
struct XTMInfo
|
||||
{
|
||||
//
|
||||
// Symbol ...
|
||||
string symbol;
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
// Bar Time ...
|
||||
datetime barTime;
|
||||
|
||||
//
|
||||
// Bar Index ...
|
||||
int barIndex;
|
||||
|
||||
//
|
||||
// Values ...
|
||||
double value;
|
||||
|
||||
//
|
||||
// State ...
|
||||
ENUM_XTM_STATES state;
|
||||
|
||||
//
|
||||
double values[];
|
||||
double states[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
// Detect Trend is Bullish or not ...
|
||||
bool isBullish;
|
||||
|
||||
//
|
||||
// Detect Trend is Switched to Bullish Or not ...
|
||||
bool isSwitchedBullish;
|
||||
|
||||
//
|
||||
// Detect Trend is Bearish or not ...
|
||||
bool isBearish;
|
||||
|
||||
//
|
||||
// Detect Trend is Switched to Bearish Or not ...
|
||||
bool isSwitchedBearish;
|
||||
|
||||
//
|
||||
// Detect Trend is Neutural or not ...
|
||||
bool isNeutural;
|
||||
|
||||
//
|
||||
// Detect Trend is Switched to Neutural Or not ...
|
||||
bool isSwitchedNeutural;
|
||||
};
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Helping Indicators Requirements ...
|
||||
class XSCXTMHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Buffers ...
|
||||
double valueBuffer[];
|
||||
double stateBuffer[];
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCXTMHelper(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period // Trading Time Frame
|
||||
) : XSCBaseHelper(symbol, period)
|
||||
{
|
||||
PrepareTag();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCXTMHelper()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Prepare Tag ...
|
||||
virtual void PrepareTag()
|
||||
{
|
||||
mTag = "XTM" + GetTagPrefix();
|
||||
}
|
||||
|
||||
//
|
||||
virtual int GetMaxLength()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
result = mLength;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Indicator Handler ...
|
||||
bool Init()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result =
|
||||
//
|
||||
(mLength >= 2)
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Handler ...
|
||||
mHandler = iCustom(
|
||||
//
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xtm",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Makret ...
|
||||
"",
|
||||
//
|
||||
// Length ...
|
||||
mLength,
|
||||
//
|
||||
// Shift ...
|
||||
mShift,
|
||||
//
|
||||
// Calculations ...
|
||||
"",
|
||||
//
|
||||
// Method ...
|
||||
mMethod,
|
||||
//
|
||||
// Applied To ...
|
||||
mAppliedTo,
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
//
|
||||
// Show Line ...
|
||||
mShowLine
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Current Config ...
|
||||
XTMInputs GetConfig()
|
||||
{
|
||||
//
|
||||
XTMInputs result;
|
||||
|
||||
//
|
||||
result.length = mLength;
|
||||
result.shift = mShift;
|
||||
result.method = mMethod;
|
||||
result.appliedTo = mAppliedTo;
|
||||
result.showLine = mShowLine;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Config ...
|
||||
bool SetConfig(XTMInputs &config)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mLength = config.length;
|
||||
mShift = config.shift;
|
||||
mMethod = config.method;
|
||||
mAppliedTo = config.appliedTo;
|
||||
mShowLine = config.showLine;
|
||||
|
||||
//
|
||||
result = Init();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Buffers based on Given Bar Index ...
|
||||
virtual void Calculate(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// VALUE ...
|
||||
ArraySetAsSeries(valueBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XTM_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
valueBuffer);
|
||||
|
||||
//
|
||||
// STATE ...
|
||||
ArraySetAsSeries(stateBuffer, true);
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XTM_STATE_LINE,
|
||||
barIndex,
|
||||
mLoopbackBars,
|
||||
stateBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Info at Specific Bar Index ...
|
||||
XTMInfo GetInfo(
|
||||
int barIndex // Given Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
XTMInfo result;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculations ...
|
||||
Calculate(barIndex);
|
||||
|
||||
//
|
||||
// Generate Candle Time ...
|
||||
datetime barTime = GetCandleTime(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
barIndex);
|
||||
|
||||
//
|
||||
// Fill Result ...
|
||||
result.symbol = mSymbol;
|
||||
result.period = mPeriod;
|
||||
result.barTime = barTime;
|
||||
result.barIndex = barIndex;
|
||||
|
||||
//
|
||||
result.value = valueBuffer[barIndex];
|
||||
|
||||
//
|
||||
ENUM_XTM_STATES state = (ENUM_XTM_STATES)stateBuffer[barIndex];
|
||||
ENUM_XTM_STATES prevState = (ENUM_XTM_STATES)stateBuffer[barIndex + 1];
|
||||
result.state = state;
|
||||
|
||||
//
|
||||
Copy(
|
||||
valueBuffer,
|
||||
result.values);
|
||||
Copy(
|
||||
stateBuffer,
|
||||
result.states);
|
||||
|
||||
//
|
||||
result.isBullish = state == X_XTM_BULLISH;
|
||||
result.isBearish = state == X_XTM_BEARISH;
|
||||
result.isNeutural = state == X_XTM_NEUTURAL;
|
||||
|
||||
//
|
||||
result.isSwitchedBullish =
|
||||
state == X_XTM_BULLISH && prevState != X_XTM_BULLISH;
|
||||
result.isSwitchedBearish =
|
||||
state == X_XTM_BEARISH && prevState != X_XTM_BEARISH;
|
||||
result.isSwitchedNeutural =
|
||||
state == X_XTM_NEUTURAL && prevState != X_XTM_NEUTURAL;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Indicator Properties ...
|
||||
//
|
||||
// Makret ...
|
||||
//
|
||||
// Length ...
|
||||
int mLength;
|
||||
//
|
||||
// Shift ...
|
||||
int mShift;
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Method ...
|
||||
ENUM_MA_METHOD mMethod;
|
||||
//
|
||||
// Applied To ...
|
||||
ENUM_APPLIED_PRICE mAppliedTo;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
//
|
||||
// Show Line ...
|
||||
bool mShowLine;
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,350 @@
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121_XAMA
|
||||
// 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_XAMA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
#define ShortName "X121_XAMA"
|
||||
|
||||
//
|
||||
// XAMA Indicator States ...
|
||||
enum ENUM_X_XAMA_STATES
|
||||
{
|
||||
X_XAMA_BULLISH = 0,
|
||||
X_XAMA_BEARISH = 2,
|
||||
X_XAMA_NEUTURAL = 1,
|
||||
};
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Makret";
|
||||
input int length = 52; // Length
|
||||
input int fastEMA = 2; // Fast EMA Length
|
||||
input int slowEMA = 30; // Slow EMA Length
|
||||
input int maShift = 0; // Shift
|
||||
input ENUM_APPLIED_PRICE appliedTo = PRICE_LOW; // Applied To
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showLine = true; // Show Line
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 1
|
||||
|
||||
//
|
||||
// maBuffer ...
|
||||
#define maBufferIndex 0
|
||||
#define maColorBufferIndex 1
|
||||
|
||||
double maBuffer[];
|
||||
double maColorBuffer[];
|
||||
|
||||
#property indicator_label1 "X121_XAMA"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 clrLime, clrGray, clrRed
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int maHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Initializing MA Handler ...
|
||||
maHandler = iAMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
fastEMA,
|
||||
slowEMA,
|
||||
maShift,
|
||||
appliedTo);
|
||||
if (maHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
string message = "Error Initializing Ma Handler ...";
|
||||
Print(message);
|
||||
|
||||
//
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
IndicatorRelease(maHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// 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;
|
||||
|
||||
//
|
||||
// Check Calculated Bars ...
|
||||
int maCalculatedBars = BarsCalculated(maHandler);
|
||||
if (maCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
int copiedMas = CopyBuffer(maHandler, 0, 0, limit, maBuffer);
|
||||
if (copiedMas <= 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
// Do Buffers Calculation ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (length >= 2)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = length;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
ENUM_DRAW_TYPE drawType = showLine ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Ma Buffer ...
|
||||
ArraySetAsSeries(maBuffer, true);
|
||||
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(maBufferIndex, PLOT_DRAW_TYPE, drawType);
|
||||
PlotIndexSetInteger(maBufferIndex, PLOT_SHOW_DATA, showLine);
|
||||
|
||||
//
|
||||
// Ma Color Buffer ...
|
||||
ArraySetAsSeries(maColorBuffer, true);
|
||||
SetIndexBuffer(maColorBufferIndex, maColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(int bar_index)
|
||||
{
|
||||
//
|
||||
// Requirements ...
|
||||
XOHCL candle = GetCandle(bar_index);
|
||||
|
||||
//
|
||||
double maValue = maBuffer[bar_index];
|
||||
|
||||
//
|
||||
double lineColorIndex =
|
||||
maValue < candle.low ? 0 : maValue > candle.high ? 2
|
||||
: 1;
|
||||
//
|
||||
// Set Ma Buffer Color Index ...
|
||||
maColorBuffer[bar_index] = lineColorIndex;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,454 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Candle Styles
|
||||
// ---------------------------------------------------
|
||||
// Name: X121_CC
|
||||
// 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_CC Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "X121_CC"
|
||||
|
||||
//
|
||||
// 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 color upColor = clrLime; // Up Color
|
||||
input color downColor = clrRed; // Down Color
|
||||
input color lineColor = clrLime; // Line mode and Doji candlestick Color
|
||||
input color bearishColor = clrRed; // Bullish Color
|
||||
input color bullishColor = clrLime; // Bearish Color
|
||||
input color volumesColor = clrGreen; // Volumes Color
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showCandles = true; // Show Candles
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Draw Library ...
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 0
|
||||
#property indicator_plots 0
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
XChartStyle chartStyle;
|
||||
XChartStyle clearStyle;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Apply Chart Style ...
|
||||
ApplyCustomChartStyle();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// 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.upColor = upColor;
|
||||
chartStyle.downColor = downColor;
|
||||
chartStyle.lineColor = lineColor;
|
||||
chartStyle.bearishColor = bearishColor;
|
||||
chartStyle.bullishColor = bullishColor;
|
||||
chartStyle.volumesColor = volumesColor;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Chart Style ...
|
||||
void SetChartStyle(
|
||||
XChartStyle &mChartStyle // Chart Style to Apply
|
||||
)
|
||||
{
|
||||
//
|
||||
ApplyChartStyle(
|
||||
mChartStyle.chartId,
|
||||
mChartStyle.mode,
|
||||
mChartStyle.showBidLine,
|
||||
mChartStyle.showAskLine,
|
||||
mChartStyle.showGrid,
|
||||
mChartStyle.showVolumes,
|
||||
mChartStyle.showTradeLevels,
|
||||
mChartStyle.autoScroll,
|
||||
mChartStyle.quickNavigation,
|
||||
mChartStyle.foreGroundColor,
|
||||
mChartStyle.backGroundColor,
|
||||
mChartStyle.upColor,
|
||||
mChartStyle.downColor,
|
||||
mChartStyle.bullishColor,
|
||||
mChartStyle.bearishColor,
|
||||
mChartStyle.gridColor,
|
||||
mChartStyle.bidLineColor,
|
||||
mChartStyle.askLineColor,
|
||||
mChartStyle.lineColor,
|
||||
mChartStyle.stopColor,
|
||||
mChartStyle.volumesColor);
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,631 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121_XCHE
|
||||
// Description: Chandelier Exit 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_XCHE Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
#define ShortName "X121_XCHE"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Market";
|
||||
input int length = 35; // Length
|
||||
input int loopback = 26; // Loopback
|
||||
input double multiplier1 = 3.0; // 1st Multiplier
|
||||
input double multiplier2 = 3.5; // 2nd Multiplier
|
||||
|
||||
//
|
||||
input group "Calculation";
|
||||
input ENUM_APPLIED_PRICE upAppliedTo = PRICE_HIGH; // Up Zone Applied to
|
||||
input ENUM_APPLIED_PRICE downAppliedTo = PRICE_LOW; // Down Zone Applied to
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showLongExit1Line = true; // Show 1st Long Exit
|
||||
input bool showShortExit1Line = true; // Show 1st Short Exit
|
||||
input bool showLongExit2Line = true; // Show 2st Long Exit
|
||||
input bool showShortExit2Line = true; // Show 2st Short Exit
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 8
|
||||
#property indicator_plots 8
|
||||
|
||||
//
|
||||
// Long Exit 1 ...
|
||||
#define longExit1BufferIndex 0
|
||||
double longExit1Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XCHE LE 1"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrLime
|
||||
#property indicator_style1 STYLE_DOT
|
||||
|
||||
//
|
||||
// Short Exit 1 ...
|
||||
#define shortExit1BufferIndex 1
|
||||
double shortExit1Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121_XCHE SE 1"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_color2 clrRed
|
||||
|
||||
//
|
||||
// Long Exit 2 ...
|
||||
#define longExit2BufferIndex 2
|
||||
double longExit2Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "X121_XCHE LE 2"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_color3 clrAqua
|
||||
|
||||
//
|
||||
// Short Exit 2 ...
|
||||
#define shortExit2BufferIndex 3
|
||||
double shortExit2Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "X121_XCHE SE 2"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_color4 clrMagenta
|
||||
|
||||
//
|
||||
// START Arrows ...
|
||||
|
||||
//
|
||||
// Long Exit 1 Start ...
|
||||
#define longExit1StartBufferIndex 4
|
||||
double longExit1StartBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "X121_XCHE LES 1"
|
||||
#property indicator_type5 DRAW_ARROW
|
||||
#property indicator_color5 clrLime
|
||||
|
||||
//
|
||||
// Short Exit 1 Start ...
|
||||
#define shortExit1StartBufferIndex 5
|
||||
double shortExit1StartBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "X121_XCHE SES 1"
|
||||
#property indicator_type6 DRAW_ARROW
|
||||
#property indicator_color6 clrRed
|
||||
|
||||
//
|
||||
// Long Exit 2 Start ...
|
||||
#define longExit2StartBufferIndex 6
|
||||
double longExit2StartBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "X121_XCHE LES 2"
|
||||
#property indicator_type7 DRAW_ARROW
|
||||
#property indicator_color7 clrAqua
|
||||
|
||||
//
|
||||
// Short Exit 2 Start ...
|
||||
#define shortExit2StartBufferIndex 7
|
||||
double shortExit2StartBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label8 "X121_XCHE SES 2"
|
||||
#property indicator_type8 DRAW_ARROW
|
||||
#property indicator_color8 clrMagenta
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
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
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart mPeriod 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(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
if (Bars(_Symbol, _Period) < rates_total)
|
||||
{
|
||||
return (prev_calculated);
|
||||
}
|
||||
|
||||
//
|
||||
if (ArrayRange(work, 0) != rates_total)
|
||||
{
|
||||
ArrayResize(work, rates_total);
|
||||
}
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
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;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
result =
|
||||
length >= 9 &&
|
||||
loopback >= 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(length, loopback);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
uint arrowCode = 159;
|
||||
|
||||
//
|
||||
// LEVEL 1 ...
|
||||
|
||||
//
|
||||
// Long Exit 1 ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE longExit1DrawType = showLongExit1Line ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE longExit1StartDrawType = showLongExit1Line ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(longExit1BufferIndex, longExit1Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(longExit1BufferIndex, PLOT_SHOW_DATA, showLongExit1Line);
|
||||
PlotIndexSetInteger(longExit1BufferIndex, PLOT_DRAW_TYPE, longExit1DrawType);
|
||||
|
||||
//
|
||||
// Start Buffer ...
|
||||
SetIndexBuffer(longExit1StartBufferIndex, longExit1StartBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(longExit1StartBufferIndex, PLOT_ARROW, arrowCode);
|
||||
PlotIndexSetInteger(longExit1StartBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(longExit1StartBufferIndex, PLOT_DRAW_TYPE, longExit1StartDrawType);
|
||||
|
||||
//
|
||||
// Short Exit 1 ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE shortExit1DrawType = showShortExit1Line ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE shortExit1StartDrawType = showShortExit1Line ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(shortExit1BufferIndex, shortExit1Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(shortExit1BufferIndex, PLOT_SHOW_DATA, showShortExit1Line);
|
||||
PlotIndexSetInteger(shortExit1BufferIndex, PLOT_DRAW_TYPE, shortExit1DrawType);
|
||||
|
||||
//
|
||||
// Start Buffer ...
|
||||
SetIndexBuffer(shortExit1StartBufferIndex, shortExit1StartBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(shortExit1StartBufferIndex, PLOT_ARROW, arrowCode);
|
||||
PlotIndexSetInteger(shortExit1StartBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(shortExit1StartBufferIndex, PLOT_DRAW_TYPE, shortExit1StartDrawType);
|
||||
|
||||
//
|
||||
// LEVEL 2 ...
|
||||
|
||||
//
|
||||
// Long Exit 2 ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE longExit2DrawType = showLongExit2Line ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE longExit2StartDrawType = showLongExit2Line ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(longExit2BufferIndex, longExit2Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(longExit2BufferIndex, PLOT_SHOW_DATA, showLongExit2Line);
|
||||
PlotIndexSetInteger(longExit2BufferIndex, PLOT_DRAW_TYPE, longExit2DrawType);
|
||||
|
||||
//
|
||||
// Start Buffer ...
|
||||
SetIndexBuffer(longExit2StartBufferIndex, longExit2StartBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(longExit2StartBufferIndex, PLOT_ARROW, arrowCode);
|
||||
PlotIndexSetInteger(longExit2StartBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(longExit2StartBufferIndex, PLOT_DRAW_TYPE, longExit2StartDrawType);
|
||||
|
||||
//
|
||||
// Short Exit 2 ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE shortExit2DrawType = showShortExit2Line ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE shortExit2StartDrawType = showShortExit2Line ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(shortExit2BufferIndex, shortExit2Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(shortExit2BufferIndex, PLOT_SHOW_DATA, showShortExit2Line);
|
||||
PlotIndexSetInteger(shortExit2BufferIndex, PLOT_DRAW_TYPE, shortExit2DrawType);
|
||||
|
||||
//
|
||||
// Start Buffer ...
|
||||
SetIndexBuffer(shortExit2StartBufferIndex, shortExit2StartBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(shortExit2StartBufferIndex, PLOT_ARROW, arrowCode);
|
||||
PlotIndexSetInteger(shortExit2StartBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(shortExit2StartBufferIndex, PLOT_DRAW_TYPE, shortExit2StartDrawType);
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
longExit1Buffer[bar_index] = longExit1StartBuffer[bar_index] = shortExit1Buffer[bar_index] = shortExit1StartBuffer[bar_index] = EMPTY_VALUE;
|
||||
longExit2Buffer[bar_index] = longExit2StartBuffer[bar_index] = shortExit2Buffer[bar_index] = shortExit2StartBuffer[bar_index] = EMPTY_VALUE;
|
||||
|
||||
//
|
||||
int start = MathMax(bar_index - loopback, 0);
|
||||
|
||||
//
|
||||
// Calculate ATR Value ...
|
||||
double atrValue = 0;
|
||||
for (int k = 1; k <= length && (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)length;
|
||||
|
||||
//
|
||||
// Retrieve Highest High and Lowest Lows ...
|
||||
double loopbackMax = high[ArrayMaximum(high, start, loopback)];
|
||||
double loopbackMin = low[ArrayMinimum(low, start, loopback)];
|
||||
|
||||
//
|
||||
// Fill Multi Dimesional Working Array ...
|
||||
work[bar_index][hi1Idx] = loopbackMax - multiplier1 * atrValue;
|
||||
work[bar_index][lo1Idx] = loopbackMin + multiplier1 * atrValue;
|
||||
work[bar_index][hi2Idx] = loopbackMax - multiplier2 * atrValue;
|
||||
work[bar_index][lo2Idx] = loopbackMin + multiplier2 * 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 (multiplier1 > 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];
|
||||
}
|
||||
|
||||
//
|
||||
longExit1Buffer[bar_index] = work[bar_index][hi1Idx];
|
||||
|
||||
//
|
||||
if (longExit1Buffer[bar_index - 1] == EMPTY_VALUE)
|
||||
{
|
||||
longExit1StartBuffer[bar_index] = longExit1Buffer[bar_index];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Short ...
|
||||
if (multiplier1 > 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];
|
||||
}
|
||||
|
||||
//
|
||||
shortExit1Buffer[bar_index] = work[bar_index][lo1Idx];
|
||||
|
||||
//
|
||||
if (shortExit1Buffer[bar_index - 1] == EMPTY_VALUE)
|
||||
{
|
||||
shortExit1StartBuffer[bar_index] = shortExit1Buffer[bar_index];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Exit 2 ...
|
||||
|
||||
//
|
||||
// Long ...
|
||||
if (multiplier2 > 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];
|
||||
}
|
||||
|
||||
//
|
||||
longExit2Buffer[bar_index] = work[bar_index][hi2Idx];
|
||||
|
||||
//
|
||||
if (longExit2Buffer[bar_index - 1] == EMPTY_VALUE)
|
||||
{
|
||||
longExit2StartBuffer[bar_index] = longExit2Buffer[bar_index];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Short ...
|
||||
if (multiplier2 > 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];
|
||||
}
|
||||
|
||||
//
|
||||
shortExit2Buffer[bar_index] = work[bar_index][lo2Idx];
|
||||
|
||||
//
|
||||
if (shortExit2Buffer[bar_index - 1] == EMPTY_VALUE)
|
||||
{
|
||||
shortExit2StartBuffer[bar_index] = shortExit2Buffer[bar_index];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,264 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 color clr = clrYellow; // Text Color
|
||||
input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER; // Text Position
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showCandleTime = true; // Show Candle Time
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 0
|
||||
#property indicator_plots 0
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (showCandleTime)
|
||||
{
|
||||
CreateIndicatorObject();
|
||||
}
|
||||
else
|
||||
{
|
||||
ObjectDelete(0, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Delete Object ...
|
||||
ObjectDelete(0, ShortName);
|
||||
|
||||
//
|
||||
Comment("");
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
ArraySetAsSeries(time, true);
|
||||
|
||||
//
|
||||
if (!showCandleTime)
|
||||
{
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
XCandleRemains remainTime;
|
||||
GetCandleRemainsTime(
|
||||
remainTime,
|
||||
_Symbol,
|
||||
_Period,
|
||||
0);
|
||||
|
||||
//
|
||||
string msg = ToString(
|
||||
remainTime,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
":",
|
||||
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;
|
||||
|
||||
//
|
||||
ObjectSetInteger(0, ShortName, OBJPROP_COLOR, clr);
|
||||
ObjectSetString(0, ShortName, OBJPROP_TEXT, objText);
|
||||
ObjectSetInteger(0, ShortName, OBJPROP_FONTSIZE, 10);
|
||||
ObjectSetString(0, ShortName, OBJPROP_FONT, "Courier");
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
void CreateIndicatorObject()
|
||||
{
|
||||
//
|
||||
if (!showCandleTime)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
ObjectCreate(0, ShortName, OBJ_LABEL, 0, 0, 0);
|
||||
ObjectSetInteger(0, ShortName, OBJPROP_CORNER, corner);
|
||||
ObjectSetInteger(0, ShortName, OBJPROP_XDISTANCE, 10);
|
||||
ObjectSetInteger(0, ShortName, OBJPROP_YDISTANCE, 2);
|
||||
|
||||
//
|
||||
ENUM_ANCHOR_POINT Anchor = ANCHOR_LEFT_UPPER;
|
||||
switch (corner)
|
||||
{
|
||||
case CORNER_LEFT_UPPER:
|
||||
Anchor = ANCHOR_LEFT_UPPER;
|
||||
break;
|
||||
case CORNER_RIGHT_UPPER:
|
||||
Anchor = ANCHOR_RIGHT_UPPER;
|
||||
break;
|
||||
case CORNER_LEFT_LOWER:
|
||||
Anchor = ANCHOR_LEFT_LOWER;
|
||||
break;
|
||||
case CORNER_RIGHT_LOWER:
|
||||
Anchor = ANCHOR_RIGHT_LOWER;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
ObjectSetInteger(0, ShortName, OBJPROP_ANCHOR, Anchor);
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,348 @@
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121_XDEMA
|
||||
// Description: Super Trend Indicator ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121_XAMA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
#define ShortName "X121_XDEMA"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int length = 200; // Length
|
||||
input int shift = 0; // Shift
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
input bool showDema = true; // Show Dema
|
||||
input bool showEMA = false; // Show EMA
|
||||
input bool showEMAOfEMA = false; // Show EMA of EMA
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include <MovingAverages.mqh>
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 6
|
||||
#property indicator_plots 6
|
||||
|
||||
//
|
||||
#define demaBufferIndex 0
|
||||
double demaBuffer[];
|
||||
|
||||
//
|
||||
#define demaColorBufferIndex 1
|
||||
double demaColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XDEMA DEMA"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 clrDodgerBlue, CLR_NONE
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
#define emaBufferIndex 2
|
||||
double emaBuffer[];
|
||||
|
||||
//
|
||||
#define emaColorBufferIndex 3
|
||||
double emaColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121_XDEMA EMA"
|
||||
#property indicator_type2 DRAW_COLOR_LINE
|
||||
#property indicator_color2 clrBlue, CLR_NONE
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#define emaOfEMABufferIndex 4
|
||||
double emaOfEMABuffer[];
|
||||
|
||||
//
|
||||
#define emaOfEMAColorBufferIndex 5
|
||||
double emaOfEMAColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "X121_XDEMA EMA of EMA"
|
||||
#property indicator_type3 DRAW_COLOR_LINE
|
||||
#property indicator_color3 clrOrange, CLR_NONE
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculations ...
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const int begin,
|
||||
const double &price[])
|
||||
{
|
||||
//
|
||||
ArraySetAsSeries(price, true);
|
||||
|
||||
//
|
||||
// check for data ...
|
||||
if (rates_total < 2 * length - 2)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
int limit;
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// calculate EMA ...
|
||||
ExponentialMAOnBuffer(rates_total, prev_calculated, 0, length, price, emaBuffer);
|
||||
|
||||
//
|
||||
// calculate EMA on EMA array ...
|
||||
ExponentialMAOnBuffer(rates_total, prev_calculated, length - 1, length, emaBuffer, emaOfEMABuffer);
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
// calculate DEMA ...
|
||||
demaBuffer[i] = 2 * emaBuffer[i] - emaOfEMABuffer[i];
|
||||
|
||||
//
|
||||
double showColorIDX = 0;
|
||||
double hideColorIDX = 1;
|
||||
|
||||
//
|
||||
demaColorBuffer[i] = hideColorIDX;
|
||||
emaColorBuffer[i] = hideColorIDX;
|
||||
emaOfEMAColorBuffer[i] = hideColorIDX;
|
||||
|
||||
//
|
||||
if (showDema)
|
||||
{
|
||||
demaColorBuffer[i] = showColorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
if (showEMA)
|
||||
{
|
||||
emaColorBuffer[i] = showColorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
if (showEMAOfEMA)
|
||||
{
|
||||
emaOfEMAColorBuffer[i] = showColorIDX;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
(length > 2 &&
|
||||
shift >= 0)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Peaks and Vales ...
|
||||
result = length;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// DEMA ...
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
ArraySetAsSeries(demaBuffer, true);
|
||||
SetIndexBuffer(demaBufferIndex, demaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(demaBufferIndex, PLOT_SHOW_DATA, showDema);
|
||||
|
||||
//
|
||||
// Color Buffer ...
|
||||
ArraySetAsSeries(demaColorBuffer, true);
|
||||
SetIndexBuffer(demaColorBufferIndex, demaColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// EMA ...
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
ArraySetAsSeries(emaBuffer, true);
|
||||
SetIndexBuffer(emaBufferIndex, emaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(emaBufferIndex, PLOT_SHOW_DATA, showEMA);
|
||||
|
||||
//
|
||||
// Color Buffer ...
|
||||
ArraySetAsSeries(emaColorBuffer, true);
|
||||
SetIndexBuffer(emaColorBufferIndex, emaColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// EMA of EMA ...
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
ArraySetAsSeries(emaOfEMABuffer, true);
|
||||
SetIndexBuffer(emaOfEMABufferIndex, emaOfEMABuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(emaOfEMABufferIndex, PLOT_SHOW_DATA, showEMAOfEMA);
|
||||
|
||||
//
|
||||
// Color Buffer ...
|
||||
ArraySetAsSeries(emaOfEMAColorBuffer, true);
|
||||
SetIndexBuffer(emaOfEMAColorBufferIndex, emaOfEMAColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,768 @@
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// --------------------------------------
|
||||
// Name: X121_XFBB
|
||||
// Description: Fibonacci Band ...
|
||||
//
|
||||
//
|
||||
// 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_XFBB Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "X121_XFBB"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int length = 200; // Length
|
||||
input double multiplier = 3.0; // Multiplier
|
||||
input ENUM_APPLIED_PRICE appliedTo = PRICE_TYPICAL; // Applied To
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
input bool showBase = true; // Show Base
|
||||
input bool showBand = true; // Show Band
|
||||
input bool showGoldenArea = true; // Show Golden Area
|
||||
input bool showOthers = false; // Show Other Levels
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 28
|
||||
#property indicator_plots 26
|
||||
|
||||
//
|
||||
// PLOTTED Buffers ...
|
||||
|
||||
//
|
||||
#define baseBufferIndex 0
|
||||
#define basePlotBufferIndex 0
|
||||
double baseBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XFBB Base"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 CLR_NONE, clrDarkGray, clrDeepPink, clrMediumSeaGreen
|
||||
#property indicator_style1 STYLE_DOT
|
||||
|
||||
#define baseColorBufferIndex 1
|
||||
double baseColorBuffer[];
|
||||
|
||||
//
|
||||
#define upL1BufferIndex 2
|
||||
#define upL1PlotBufferIndex 1
|
||||
double upL1Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121_XFBB UF 1"
|
||||
#property indicator_type2 DRAW_COLOR_LINE
|
||||
#property indicator_color2 CLR_NONE, clrDarkGray
|
||||
#property indicator_style2 STYLE_DOT
|
||||
|
||||
#define upL1ColorBufferIndex 3
|
||||
double upL1ColorBuffer[];
|
||||
|
||||
//
|
||||
#define upL2BufferIndex 4
|
||||
#define upL2PlotBufferIndex 2
|
||||
double upL2Buffer[];
|
||||
|
||||
#define upL2ColorBufferIndex 5
|
||||
double upL2ColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "X121_XFBB UF 2"
|
||||
#property indicator_type3 DRAW_COLOR_LINE
|
||||
#property indicator_color3 CLR_NONE, clrDarkGray
|
||||
#property indicator_style3 STYLE_DOT
|
||||
|
||||
//
|
||||
#define upL3BufferIndex 6
|
||||
#define upL3PlotBufferIndex 3
|
||||
double upL3Buffer[];
|
||||
|
||||
#define upL3ColorBufferIndex 7
|
||||
double upL3ColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "X121_XFBB UF 3"
|
||||
#property indicator_type4 DRAW_COLOR_LINE
|
||||
#property indicator_color4 CLR_NONE, clrGold
|
||||
#property indicator_style4 STYLE_DOT
|
||||
|
||||
//
|
||||
#define upL4BufferIndex 8
|
||||
#define upL4PlotBufferIndex 4
|
||||
double upL4Buffer[];
|
||||
|
||||
#define upL4ColorBufferIndex 9
|
||||
double upL4ColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "X121_XFBB UF 4"
|
||||
#property indicator_type5 DRAW_COLOR_LINE
|
||||
#property indicator_color5 CLR_NONE, clrGold
|
||||
#property indicator_style5 STYLE_DOT
|
||||
|
||||
//
|
||||
#define upL5BufferIndex 10
|
||||
#define upL5PlotBufferIndex 5
|
||||
double upL5Buffer[];
|
||||
|
||||
#define upL5ColorBufferIndex 11
|
||||
double upL5ColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "X121_XFBB UF 5"
|
||||
#property indicator_type6 DRAW_COLOR_LINE
|
||||
#property indicator_color6 CLR_NONE, clrDarkGray
|
||||
#property indicator_style6 STYLE_DOT
|
||||
|
||||
//
|
||||
#define upL6BufferIndex 12
|
||||
#define upL6PlotBufferIndex 6
|
||||
double upL6Buffer[];
|
||||
|
||||
#define upL6ColorBufferIndex 13
|
||||
double upL6ColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "X121_XFBB UF 6"
|
||||
#property indicator_type7 DRAW_COLOR_LINE
|
||||
#property indicator_color7 CLR_NONE, clrRed
|
||||
#property indicator_style7 STYLE_DOT
|
||||
|
||||
//
|
||||
// DOWN ...
|
||||
|
||||
//
|
||||
#define downL1BufferIndex 14
|
||||
#define downL1PlotBufferIndex 7
|
||||
double downL1Buffer[];
|
||||
|
||||
#define downL1ColorBufferIndex 15
|
||||
double downL1ColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label8 "X121_XFBB UD 1"
|
||||
#property indicator_type8 DRAW_COLOR_LINE
|
||||
#property indicator_color8 CLR_NONE, clrDarkGray
|
||||
#property indicator_style8 STYLE_DOT
|
||||
|
||||
//
|
||||
#define downL2BufferIndex 16
|
||||
#define downL2PlotBufferIndex 8
|
||||
double downL2Buffer[];
|
||||
|
||||
#define downL2ColorBufferIndex 17
|
||||
double downL2ColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label9 "X121_XFBB UD 2"
|
||||
#property indicator_type9 DRAW_COLOR_LINE
|
||||
#property indicator_color9 CLR_NONE, clrDarkGray
|
||||
#property indicator_style9 STYLE_DOT
|
||||
|
||||
//
|
||||
#define downL3BufferIndex 18
|
||||
#define downL3PlotBufferIndex 9
|
||||
double downL3Buffer[];
|
||||
|
||||
#define downL3ColorBufferIndex 19
|
||||
double downL3ColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label10 "X121_XFBB UD 3"
|
||||
#property indicator_type10 DRAW_COLOR_LINE
|
||||
#property indicator_color10 CLR_NONE, clrGold
|
||||
#property indicator_style10 STYLE_DOT
|
||||
|
||||
//
|
||||
#define downL4BufferIndex 20
|
||||
#define downL4PlotBufferIndex 10
|
||||
double downL4Buffer[];
|
||||
|
||||
#define downL4ColorBufferIndex 21
|
||||
double downL4ColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label11 "X121_XFBB UD 4"
|
||||
#property indicator_type11 DRAW_COLOR_LINE
|
||||
#property indicator_color11 CLR_NONE, clrGold
|
||||
#property indicator_style11 STYLE_DOT
|
||||
|
||||
//
|
||||
#define downL5BufferIndex 22
|
||||
#define downL5PlotBufferIndex 11
|
||||
double downL5Buffer[];
|
||||
|
||||
#define downL5ColorBufferIndex 23
|
||||
double downL5ColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label12 "X121_XFBB UD 5"
|
||||
#property indicator_type12 DRAW_COLOR_LINE
|
||||
#property indicator_color12 CLR_NONE, clrDarkGray
|
||||
#property indicator_style12 STYLE_DOT
|
||||
|
||||
//
|
||||
#define downL6BufferIndex 24
|
||||
#define downL6PlotBufferIndex 12
|
||||
double downL6Buffer[];
|
||||
|
||||
#define downL6ColorBufferIndex 25
|
||||
double downL6ColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label13 "X121_XFBB UD 6"
|
||||
#property indicator_type13 DRAW_COLOR_LINE
|
||||
#property indicator_color13 CLR_NONE, clrRed
|
||||
#property indicator_style13 STYLE_DOT
|
||||
|
||||
//
|
||||
// DATA BUffers ...
|
||||
|
||||
//
|
||||
#define stdDevBufferIndex 26
|
||||
double stdDevBuffer[];
|
||||
|
||||
//
|
||||
#define vwmaBufferIndex 27
|
||||
double vwmaBuffer[];
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int mSTDevHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Initialize Handlers ...
|
||||
mSTDevHandler = iStdDev(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
0,
|
||||
MODE_SMA,
|
||||
appliedTo);
|
||||
if (mSTDevHandler == INVALID_HANDLE)
|
||||
{
|
||||
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
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
|
||||
//
|
||||
IndicatorRelease(mSTDevHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
int i = (prev_calculated > 0 ? prev_calculated - 1 : 0);
|
||||
for (i; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
double price = GetAppliedPrice(
|
||||
appliedTo,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
i);
|
||||
|
||||
//
|
||||
double vwma = iVWMA(price, volume[i], length, i, rates_total);
|
||||
vwmaBuffer[i] = vwma;
|
||||
baseBuffer[i] = vwma;
|
||||
|
||||
//
|
||||
double baseColorIDX = (i > 0)
|
||||
? (vwmaBuffer[i] > vwmaBuffer[i - 1])
|
||||
? 3
|
||||
: (vwmaBuffer[i] < vwmaBuffer[i - 1])
|
||||
? 2
|
||||
: baseColorBuffer[i - 1]
|
||||
: 1;
|
||||
|
||||
//
|
||||
if (showBase)
|
||||
{
|
||||
baseColorBuffer[i] = baseColorIDX;
|
||||
}
|
||||
else
|
||||
{
|
||||
baseColorBuffer[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// Check Calculated Bars ...
|
||||
//
|
||||
int stdDevCalculatedBars = BarsCalculated(mSTDevHandler);
|
||||
if (stdDevCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
//
|
||||
int copiedSTDDevs = CopyBuffer(mSTDevHandler, 0, 0, limit, stdDevBuffer);
|
||||
if (copiedSTDDevs <= 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 =
|
||||
//
|
||||
(length >= 2 &&
|
||||
multiplier > 0)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(result, length);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// PLOTTED ...
|
||||
|
||||
//
|
||||
// BASE ...
|
||||
// ArraySetAsSeries(baseBuffer, true);
|
||||
// ArraySetAsSeries(baseColorBuffer, true);
|
||||
SetIndexBuffer(baseBufferIndex, baseBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(basePlotBufferIndex, PLOT_SHOW_DATA, showBase);
|
||||
SetIndexBuffer(baseColorBufferIndex, baseColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// UP 1 ...
|
||||
// ArraySetAsSeries(upL1Buffer, true);
|
||||
// ArraySetAsSeries(upL1ColorBuffer, true);
|
||||
SetIndexBuffer(upL1BufferIndex, upL1Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(upL1PlotBufferIndex, PLOT_SHOW_DATA, showOthers);
|
||||
SetIndexBuffer(upL1ColorBufferIndex, upL1ColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// UP 2 ...
|
||||
// ArraySetAsSeries(upL2Buffer, true);
|
||||
// ArraySetAsSeries(upL2ColorBuffer, true);
|
||||
SetIndexBuffer(upL2BufferIndex, upL2Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(upL2PlotBufferIndex, PLOT_SHOW_DATA, showOthers);
|
||||
SetIndexBuffer(upL2ColorBufferIndex, upL2ColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// UP 3 ...
|
||||
// ArraySetAsSeries(upL3Buffer, true);
|
||||
// ArraySetAsSeries(upL3ColorBuffer, true);
|
||||
SetIndexBuffer(upL3BufferIndex, upL3Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(upL3PlotBufferIndex, PLOT_SHOW_DATA, showGoldenArea);
|
||||
SetIndexBuffer(upL3ColorBufferIndex, upL3ColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// UP 4 ...
|
||||
// ArraySetAsSeries(upL4Buffer, true);
|
||||
// ArraySetAsSeries(upL4ColorBuffer, true);
|
||||
SetIndexBuffer(upL4BufferIndex, upL4Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(upL4PlotBufferIndex, PLOT_SHOW_DATA, showGoldenArea);
|
||||
SetIndexBuffer(upL4ColorBufferIndex, upL4ColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// UP 5 ...
|
||||
// ArraySetAsSeries(upL5Buffer, true);
|
||||
// ArraySetAsSeries(upL5ColorBuffer, true);
|
||||
SetIndexBuffer(upL5BufferIndex, upL5Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(upL5PlotBufferIndex, PLOT_SHOW_DATA, showOthers);
|
||||
SetIndexBuffer(upL5ColorBufferIndex, upL5ColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// UP 6 ...
|
||||
// ArraySetAsSeries(upL6Buffer, true);
|
||||
// ArraySetAsSeries(upL6ColorBuffer, true);
|
||||
SetIndexBuffer(upL6BufferIndex, upL6Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(upL6PlotBufferIndex, PLOT_SHOW_DATA, showBand);
|
||||
SetIndexBuffer(upL6ColorBufferIndex, upL6ColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// DOWN 1 ...
|
||||
// ArraySetAsSeries(downL1Buffer, true);
|
||||
// ArraySetAsSeries(downL1ColorBuffer, true);
|
||||
SetIndexBuffer(downL1BufferIndex, downL1Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(downL1PlotBufferIndex, PLOT_SHOW_DATA, showOthers);
|
||||
SetIndexBuffer(downL1ColorBufferIndex, downL1ColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// DOWN 2 ...
|
||||
// ArraySetAsSeries(downL2Buffer, true);
|
||||
// ArraySetAsSeries(downL2ColorBuffer, true);
|
||||
SetIndexBuffer(downL2BufferIndex, downL2Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(downL2PlotBufferIndex, PLOT_SHOW_DATA, showOthers);
|
||||
SetIndexBuffer(downL2ColorBufferIndex, downL2ColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// DOWN 3 ...
|
||||
// ArraySetAsSeries(downL3Buffer, true);
|
||||
// ArraySetAsSeries(downL3ColorBuffer, true);
|
||||
SetIndexBuffer(downL3BufferIndex, downL3Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(downL3PlotBufferIndex, PLOT_SHOW_DATA, showGoldenArea);
|
||||
SetIndexBuffer(downL3ColorBufferIndex, downL3ColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// DOWN 4 ...
|
||||
// ArraySetAsSeries(downL4Buffer, true);
|
||||
// ArraySetAsSeries(downL4ColorBuffer, true);
|
||||
SetIndexBuffer(downL4BufferIndex, downL4Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(downL4PlotBufferIndex, PLOT_SHOW_DATA, showGoldenArea);
|
||||
SetIndexBuffer(downL4ColorBufferIndex, downL4ColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// DOWN 5 ...
|
||||
// ArraySetAsSeries(downL5Buffer, true);
|
||||
// ArraySetAsSeries(downL5ColorBuffer, true);
|
||||
SetIndexBuffer(downL5BufferIndex, downL5Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(downL5PlotBufferIndex, PLOT_SHOW_DATA, showOthers);
|
||||
SetIndexBuffer(downL5ColorBufferIndex, downL5ColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// DOWN 6 ...
|
||||
// ArraySetAsSeries(downL6Buffer, true);
|
||||
// ArraySetAsSeries(downL6ColorBuffer, true);
|
||||
SetIndexBuffer(downL6BufferIndex, downL6Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(downL6PlotBufferIndex, PLOT_SHOW_DATA, showBand);
|
||||
SetIndexBuffer(downL6ColorBufferIndex, downL6ColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// DATA ...
|
||||
|
||||
//
|
||||
// ArraySetAsSeries(stdDevBuffer, true);
|
||||
SetIndexBuffer(stdDevBufferIndex, stdDevBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// ArraySetAsSeries(vwmaBuffer, true);
|
||||
SetIndexBuffer(vwmaBufferIndex, vwmaBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// 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
|
||||
)
|
||||
{
|
||||
//
|
||||
double stdDev = stdDevBuffer[bar_index];
|
||||
double dev = stdDev * multiplier;
|
||||
|
||||
//
|
||||
double base = baseBuffer[bar_index];
|
||||
|
||||
//
|
||||
double fib1 = 0.236;
|
||||
double fib2 = 0.382;
|
||||
double fib3 = 0.5;
|
||||
double fib4 = 0.618;
|
||||
double fib5 = 0.764;
|
||||
double fib6 = 1;
|
||||
|
||||
//
|
||||
double u1 = base + (fib1 * dev);
|
||||
double u2 = base + (fib2 * dev);
|
||||
double u3 = base + (fib3 * dev);
|
||||
double u4 = base + (fib4 * dev);
|
||||
double u5 = base + (fib5 * dev);
|
||||
double u6 = base + (fib6 * dev);
|
||||
|
||||
//
|
||||
upL1Buffer[bar_index] = u1;
|
||||
upL2Buffer[bar_index] = u2;
|
||||
upL3Buffer[bar_index] = u3;
|
||||
upL4Buffer[bar_index] = u4;
|
||||
upL5Buffer[bar_index] = u5;
|
||||
upL6Buffer[bar_index] = u6;
|
||||
|
||||
//
|
||||
double d1 = base - (fib1 * dev);
|
||||
double d2 = base - (fib2 * dev);
|
||||
double d3 = base - (fib3 * dev);
|
||||
double d4 = base - (fib4 * dev);
|
||||
double d5 = base - (fib5 * dev);
|
||||
double d6 = base - (fib6 * dev);
|
||||
|
||||
//
|
||||
downL1Buffer[bar_index] = d1;
|
||||
downL2Buffer[bar_index] = d2;
|
||||
downL3Buffer[bar_index] = d3;
|
||||
downL4Buffer[bar_index] = d4;
|
||||
downL5Buffer[bar_index] = d5;
|
||||
downL6Buffer[bar_index] = d6;
|
||||
|
||||
//
|
||||
// Setup Color IDX ...
|
||||
|
||||
//
|
||||
double hideColorIDX = 0;
|
||||
double showColorIDX = 1;
|
||||
|
||||
//
|
||||
// SET Default Colors ...
|
||||
|
||||
//
|
||||
upL1ColorBuffer[bar_index] = hideColorIDX;
|
||||
upL2ColorBuffer[bar_index] = hideColorIDX;
|
||||
upL3ColorBuffer[bar_index] = hideColorIDX;
|
||||
upL4ColorBuffer[bar_index] = hideColorIDX;
|
||||
upL5ColorBuffer[bar_index] = hideColorIDX;
|
||||
upL6ColorBuffer[bar_index] = hideColorIDX;
|
||||
|
||||
//
|
||||
downL1ColorBuffer[bar_index] = hideColorIDX;
|
||||
downL2ColorBuffer[bar_index] = hideColorIDX;
|
||||
downL3ColorBuffer[bar_index] = hideColorIDX;
|
||||
downL4ColorBuffer[bar_index] = hideColorIDX;
|
||||
downL5ColorBuffer[bar_index] = hideColorIDX;
|
||||
downL6ColorBuffer[bar_index] = hideColorIDX;
|
||||
|
||||
//
|
||||
if (!showBase)
|
||||
{
|
||||
baseColorBuffer[bar_index] = hideColorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
if (showBand)
|
||||
{
|
||||
//
|
||||
upL6ColorBuffer[bar_index] = showColorIDX;
|
||||
downL6ColorBuffer[bar_index] = showColorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
if (showGoldenArea)
|
||||
{
|
||||
//
|
||||
upL3ColorBuffer[bar_index] = showColorIDX;
|
||||
upL4ColorBuffer[bar_index] = showColorIDX;
|
||||
|
||||
//
|
||||
downL3ColorBuffer[bar_index] = showColorIDX;
|
||||
downL4ColorBuffer[bar_index] = showColorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
if (showOthers)
|
||||
{
|
||||
//
|
||||
upL1ColorBuffer[bar_index] = showColorIDX;
|
||||
upL2ColorBuffer[bar_index] = showColorIDX;
|
||||
upL5ColorBuffer[bar_index] = showColorIDX;
|
||||
|
||||
//
|
||||
downL1ColorBuffer[bar_index] = showColorIDX;
|
||||
downL2ColorBuffer[bar_index] = showColorIDX;
|
||||
downL5ColorBuffer[bar_index] = showColorIDX;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,486 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// --------------------------------------------
|
||||
// Name: X121_HK
|
||||
// Description: Hiken Ashi ...
|
||||
// Market Analysor ...
|
||||
//
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "X121_XHK"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool drawCandles = true; // Draw Hiken Ashi Candle
|
||||
input bool drawCandleLines = false; // Show HikenAshi Lines
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 13
|
||||
#property indicator_plots 5
|
||||
|
||||
//
|
||||
// PLOTTED Buffers ...
|
||||
|
||||
//
|
||||
// Open ...
|
||||
#define openBufferIndex 0
|
||||
double openBuffer[];
|
||||
|
||||
//
|
||||
// High ...
|
||||
#define highBufferIndex 1
|
||||
double highBuffer[];
|
||||
|
||||
//
|
||||
// Low ...
|
||||
#define lowBufferIndex 2
|
||||
double lowBuffer[];
|
||||
|
||||
//
|
||||
// Close ...
|
||||
#define closeBufferIndex 3
|
||||
double closeBuffer[];
|
||||
|
||||
//
|
||||
// Candle Color ...
|
||||
#define candleColorBufferIndex 4
|
||||
double candleColorBuffer[];
|
||||
|
||||
//
|
||||
#define candlesBufferIndex 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 clrAqua, clrMagenta, CLR_NONE
|
||||
|
||||
//
|
||||
#define openHKBufferIndex 5
|
||||
#define openHKColorBufferIndex 6
|
||||
double openHKBuffer[];
|
||||
double openHKColorBuffer[];
|
||||
|
||||
//
|
||||
#define openHKBufferPlotIndex 1
|
||||
#property indicator_label2 "X121_XHK O"
|
||||
#property indicator_type2 DRAW_COLOR_LINE
|
||||
#property indicator_color2 clrAqua, clrMagenta, clrLightGray
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#define highHKBufferIndex 7
|
||||
#define highHKColorBufferIndex 8
|
||||
double highHKBuffer[];
|
||||
double highHKColorBuffer[];
|
||||
|
||||
//
|
||||
#define highHKBufferPlotIndex 2
|
||||
#property indicator_label3 "X121_XHK H"
|
||||
#property indicator_type3 DRAW_COLOR_LINE
|
||||
#property indicator_color3 clrAqua, clrMagenta, clrLightGray
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
#define lowHKBufferIndex 9
|
||||
#define lowHKColorBufferIndex 10
|
||||
double lowHKBuffer[];
|
||||
double lowHKColorBuffer[];
|
||||
|
||||
//
|
||||
#define lowHKBufferPlotIndex 3
|
||||
#property indicator_label4 "X121_XHK L"
|
||||
#property indicator_type4 DRAW_COLOR_LINE
|
||||
#property indicator_color4 clrAqua, clrMagenta, clrLightGray
|
||||
#property indicator_style4 STYLE_DOT
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
#define closeHKBufferIndex 11
|
||||
#define closeHKColorBufferIndex 12
|
||||
double closeHKBuffer[];
|
||||
double closeHKColorBuffer[];
|
||||
|
||||
//
|
||||
#define closeHKBufferPlotIndex 4
|
||||
#property indicator_label5 "X121_XHK C"
|
||||
#property indicator_type5 DRAW_COLOR_LINE
|
||||
#property indicator_color5 clrAqua, clrMagenta, clrLightGray
|
||||
#property indicator_style5 STYLE_DOT
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// 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, prev_calculated, rates_total, open, high, close, low);
|
||||
}
|
||||
|
||||
//
|
||||
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()
|
||||
{
|
||||
//
|
||||
// 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);
|
||||
PlotIndexSetInteger(candleColorBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// Open ...
|
||||
ArraySetAsSeries(openBuffer, true);
|
||||
PlotIndexSetInteger(openBufferIndex, PLOT_SHOW_DATA, false);
|
||||
SetIndexBuffer(openBufferIndex, openBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// High ...
|
||||
ArraySetAsSeries(highBuffer, true);
|
||||
SetIndexBuffer(highBufferIndex, highBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(highBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// Close ...
|
||||
ArraySetAsSeries(closeBuffer, true);
|
||||
SetIndexBuffer(closeBufferIndex, closeBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(closeBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
ArraySetAsSeries(lowBuffer, true);
|
||||
SetIndexBuffer(lowBufferIndex, lowBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(lowBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// Open HK ...
|
||||
ENUM_DRAW_TYPE openDrawType = drawCandleLines ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(openHKBuffer, true);
|
||||
SetIndexBuffer(openHKBufferIndex, openHKBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(openHKBufferPlotIndex, PLOT_SHOW_DATA, drawCandleLines);
|
||||
PlotIndexSetInteger(openHKBufferPlotIndex, PLOT_DRAW_TYPE, openDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(openHKColorBuffer, true);
|
||||
SetIndexBuffer(openHKColorBufferIndex, openHKColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// High HK ...
|
||||
ENUM_DRAW_TYPE highDrawType = drawCandleLines ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(highHKBuffer, true);
|
||||
SetIndexBuffer(highHKBufferIndex, highHKBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(highHKBufferPlotIndex, PLOT_SHOW_DATA, drawCandleLines);
|
||||
PlotIndexSetInteger(highHKBufferPlotIndex, PLOT_DRAW_TYPE, highDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(highHKColorBuffer, true);
|
||||
SetIndexBuffer(highHKColorBufferIndex, highHKColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Low HK ...
|
||||
ENUM_DRAW_TYPE lowDrawType = drawCandleLines ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(lowHKBuffer, true);
|
||||
SetIndexBuffer(lowHKBufferIndex, lowHKBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(lowHKBufferPlotIndex, PLOT_SHOW_DATA, drawCandleLines);
|
||||
PlotIndexSetInteger(lowHKBufferPlotIndex, PLOT_DRAW_TYPE, lowDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(lowHKColorBuffer, true);
|
||||
SetIndexBuffer(lowHKColorBufferIndex, lowHKColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Close HK ...
|
||||
ENUM_DRAW_TYPE closeDrawType = drawCandleLines ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(closeHKBuffer, true);
|
||||
SetIndexBuffer(closeHKBufferIndex, closeHKBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(closeHKBufferPlotIndex, PLOT_SHOW_DATA, drawCandleLines);
|
||||
PlotIndexSetInteger(closeHKBufferPlotIndex, PLOT_DRAW_TYPE, closeDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(closeHKColorBuffer, true);
|
||||
SetIndexBuffer(closeHKColorBufferIndex, closeHKColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
}
|
||||
|
||||
//
|
||||
// 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
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[])
|
||||
{
|
||||
//
|
||||
double mPrevHKOpenValue;
|
||||
double mPrevHKCloseValue;
|
||||
|
||||
//
|
||||
if (ArraySize(open) <= bar_index + 1)
|
||||
{
|
||||
//
|
||||
mPrevHKOpenValue = 0;
|
||||
mPrevHKCloseValue = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
mPrevHKOpenValue = openBuffer[bar_index + 1];
|
||||
mPrevHKCloseValue = closeBuffer[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));
|
||||
|
||||
//
|
||||
openBuffer[bar_index] = mHKOpenValue;
|
||||
highBuffer[bar_index] = mHKHighValue;
|
||||
lowBuffer[bar_index] = mHKLowValue;
|
||||
closeBuffer[bar_index] = mHKCloseValue;
|
||||
|
||||
//
|
||||
double candleColorValue =
|
||||
mHKOpenValue < mHKCloseValue ? 0 : 1;
|
||||
|
||||
//
|
||||
candleColorBuffer[bar_index] = drawCandles ? candleColorValue : 2;
|
||||
|
||||
//
|
||||
openHKBuffer[bar_index] = mHKOpenValue;
|
||||
openHKColorBuffer[bar_index] = candleColorValue;
|
||||
|
||||
//
|
||||
highHKBuffer[bar_index] = mHKHighValue;
|
||||
highHKColorBuffer[bar_index] = candleColorValue;
|
||||
|
||||
//
|
||||
lowHKBuffer[bar_index] = mHKLowValue;
|
||||
lowHKColorBuffer[bar_index] = candleColorValue;
|
||||
|
||||
//
|
||||
closeHKBuffer[bar_index] = mHKCloseValue;
|
||||
closeHKColorBuffer[bar_index] = candleColorValue;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,602 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121_XHULL
|
||||
// Description: Hull Trend Indicator ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121_XHULL Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
#define ShortName "X121_XHULL"
|
||||
|
||||
//
|
||||
struct XHullData
|
||||
{
|
||||
//
|
||||
double value;
|
||||
double value3;
|
||||
|
||||
//
|
||||
double wsum1;
|
||||
double wsum2;
|
||||
double wsum3;
|
||||
|
||||
//
|
||||
double lsum1;
|
||||
double lsum2;
|
||||
double lsum3;
|
||||
};
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XSCHULL Class Definition ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class For Hull Calculations ...
|
||||
class XSCHull
|
||||
{
|
||||
//
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
XSCHull() : mFullPeriod(1), mHalfPeriod(1), mSqrtPeriod(1), mArraySize(-1)
|
||||
{
|
||||
//
|
||||
// These are a way above to assign Private variables at Construct time ...
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCHull()
|
||||
{
|
||||
ArrayFree(mData);
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Hull ...
|
||||
bool Init(
|
||||
int mPeriod,
|
||||
double mDivisor)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mFullPeriod = (int)(mPeriod > 1 ? mPeriod : 1);
|
||||
mHalfPeriod = (int)(mFullPeriod > 1 ? mFullPeriod / (mDivisor > 1 ? mDivisor : 1) : 1);
|
||||
mSqrtPeriod = (int)MathSqrt(mFullPeriod);
|
||||
|
||||
//
|
||||
mArraySize = -1;
|
||||
mWeight1 = mWeight2 = mWeight3 = 1;
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// CalCulate Specific Value ...
|
||||
double Calculate(
|
||||
double value,
|
||||
int i,
|
||||
int bars)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
if (mArraySize < bars)
|
||||
{
|
||||
//
|
||||
mArraySize = ArrayResize(mData, bars + 500);
|
||||
if (mArraySize < bars)
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mData[i].value = value;
|
||||
if (i > mFullPeriod)
|
||||
{
|
||||
//
|
||||
mData[i].wsum1 = mData[i - 1].wsum1 + value * mHalfPeriod - mData[i - 1].lsum1;
|
||||
mData[i].lsum1 = mData[i - 1].lsum1 + value - mData[i - mHalfPeriod].value;
|
||||
mData[i].wsum2 = mData[i - 1].wsum2 + value * mFullPeriod - mData[i - 1].lsum2;
|
||||
mData[i].lsum2 = mData[i - 1].lsum2 + value - mData[i - mFullPeriod].value;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
mData[i].wsum1 = mData[i].wsum2 =
|
||||
mData[i].lsum1 = mData[i].lsum2 = mWeight1 = mWeight2 = 0;
|
||||
for (int k = 0, w1 = mHalfPeriod, w2 = mFullPeriod; w2 > 0 && i >= k; k++, w1--, w2--)
|
||||
{
|
||||
//
|
||||
if (w1 > 0)
|
||||
{
|
||||
//
|
||||
mData[i].wsum1 += mData[i - k].value * w1;
|
||||
mData[i].lsum1 += mData[i - k].value;
|
||||
mWeight1 += w1;
|
||||
}
|
||||
|
||||
//
|
||||
mData[i].wsum2 += mData[i - k].value * w2;
|
||||
mData[i].lsum2 += mData[i - k].value;
|
||||
mWeight2 += w2;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
mData[i].value3 = 2.0 * mData[i].wsum1 / mWeight1 - mData[i].wsum2 / mWeight2;
|
||||
|
||||
//
|
||||
if (i > mSqrtPeriod)
|
||||
{
|
||||
//
|
||||
mData[i].wsum3 = mData[i - 1].wsum3 + mData[i].value3 * mSqrtPeriod - mData[i - 1].lsum3;
|
||||
mData[i].lsum3 = mData[i - 1].lsum3 + mData[i].value3 - mData[i - mSqrtPeriod].value3;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
mData[i].wsum3 =
|
||||
mData[i].lsum3 = mWeight3 = 0;
|
||||
|
||||
//
|
||||
for (int k = 0, w3 = mSqrtPeriod; w3 > 0 && i >= k; k++, w3--)
|
||||
{
|
||||
//
|
||||
mData[i].wsum3 += mData[i - k].value3 * w3;
|
||||
mData[i].lsum3 += mData[i - k].value3;
|
||||
mWeight3 += w3;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = mData[i].wsum3 / mWeight3;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
int mFullPeriod;
|
||||
int mHalfPeriod;
|
||||
int mSqrtPeriod;
|
||||
int mArraySize;
|
||||
double mWeight1;
|
||||
double mWeight2;
|
||||
double mWeight3;
|
||||
|
||||
//
|
||||
XHullData mData[];
|
||||
};
|
||||
|
||||
//
|
||||
// END XSCHULL Class Definition ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Market";
|
||||
input int length = 72; // Length
|
||||
input double divisor = 2.0; // Divisor (Speed)
|
||||
|
||||
//
|
||||
input group "Calculation";
|
||||
input ENUM_APPLIED_PRICE upAppliedTo = PRICE_HIGH; // Up Zone Applied to
|
||||
input ENUM_APPLIED_PRICE downAppliedTo = PRICE_LOW; // Down Zone Applied to
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showUpZone = true; // Show Up Zone
|
||||
input bool showDownZone = true; // Show Down Zone
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 4
|
||||
|
||||
//
|
||||
// UP Zone ...
|
||||
|
||||
//
|
||||
#define upZoneBufferIndex 0
|
||||
#define upZoneColorBufferIndex 1
|
||||
|
||||
//
|
||||
double upZoneBuffer[];
|
||||
double upZoneColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XHULL Up"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 clrLightGray, clrAqua, clrMagenta
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// DOWN Zone ...
|
||||
|
||||
//
|
||||
#define downZoneBufferIndex 2
|
||||
#define downZoneColorBufferIndex 3
|
||||
|
||||
//
|
||||
double downZoneBuffer[];
|
||||
double downZoneColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121_XHULL Down"
|
||||
#property indicator_type2 DRAW_COLOR_LINE
|
||||
#property indicator_color2 clrLightGray, clrAqua, clrMagenta
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
XSCHull *mUpZHull;
|
||||
XSCHull *mDownZHull;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Make an Instance of Hull Class ...
|
||||
|
||||
//
|
||||
mUpZHull = new XSCHull();
|
||||
mUpZHull.Init(
|
||||
length,
|
||||
divisor);
|
||||
|
||||
//
|
||||
mDownZHull = new XSCHull();
|
||||
mDownZHull.Init(
|
||||
length,
|
||||
divisor);
|
||||
|
||||
//
|
||||
// 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 mPeriod 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 mUpZHull;
|
||||
delete mDownZHull;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
limit = prev_calculated - 1;
|
||||
if (limit < 0)
|
||||
{
|
||||
limit = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
double upPrice = getPrice(
|
||||
upAppliedTo,
|
||||
open, high, low, close, i);
|
||||
|
||||
//
|
||||
double downPrice = getPrice(
|
||||
downAppliedTo,
|
||||
open, high, low, close, i);
|
||||
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
rates_total,
|
||||
upPrice,
|
||||
downPrice);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
result =
|
||||
length >= 9 &&
|
||||
divisor >= 0.5;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = length;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// UP Zone ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE upZoneDrawType = showUpZone ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(upZoneBufferIndex, upZoneBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(upZoneBufferIndex, PLOT_SHOW_DATA, showUpZone);
|
||||
PlotIndexSetInteger(upZoneBufferIndex, PLOT_DRAW_TYPE, upZoneDrawType);
|
||||
|
||||
//
|
||||
// Color Buffer ...
|
||||
SetIndexBuffer(upZoneColorBufferIndex, upZoneColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// DOWN Zone ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE downZoneDrawType = showDownZone ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(downZoneBufferIndex, downZoneBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(downZoneBufferIndex - 1, PLOT_SHOW_DATA, showDownZone);
|
||||
PlotIndexSetInteger(downZoneBufferIndex - 1, PLOT_DRAW_TYPE, downZoneDrawType);
|
||||
|
||||
//
|
||||
// Color Buffer ...
|
||||
SetIndexBuffer(downZoneColorBufferIndex, downZoneColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
int ratesTotal, // Total Rates
|
||||
double upPrice, // Up Price ...
|
||||
double downPrice // Down Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
double upValue = mUpZHull.Calculate(
|
||||
upPrice,
|
||||
bar_index,
|
||||
ratesTotal);
|
||||
upZoneBuffer[bar_index] = upValue;
|
||||
double upColorIDX = (bar_index > 0)
|
||||
? (upZoneBuffer[bar_index] > upZoneBuffer[bar_index - 1])
|
||||
? 1
|
||||
: (upZoneBuffer[bar_index] < upZoneBuffer[bar_index - 1])
|
||||
? 2
|
||||
: upZoneColorBuffer[bar_index - 1]
|
||||
: 0;
|
||||
upZoneColorBuffer[bar_index] = upColorIDX;
|
||||
|
||||
//
|
||||
double downValue = mDownZHull.Calculate(
|
||||
downPrice,
|
||||
bar_index,
|
||||
ratesTotal);
|
||||
downZoneBuffer[bar_index] = downValue;
|
||||
double downColorIDX = (bar_index > 0)
|
||||
? (downZoneBuffer[bar_index] > downZoneBuffer[bar_index - 1])
|
||||
? 1
|
||||
: (downZoneBuffer[bar_index] < downZoneBuffer[bar_index - 1])
|
||||
? 2
|
||||
: downZoneColorBuffer[bar_index - 1]
|
||||
: 0;
|
||||
downZoneColorBuffer[bar_index] = downColorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// TEMPLATE Function ...
|
||||
|
||||
template <typename T>
|
||||
double getPrice(ENUM_APPLIED_PRICE tprice, T &open[], T &high[], T &low[], T &close[], int i)
|
||||
{
|
||||
switch (tprice)
|
||||
{
|
||||
case PRICE_CLOSE:
|
||||
return (close[i]);
|
||||
case PRICE_OPEN:
|
||||
return (open[i]);
|
||||
case PRICE_HIGH:
|
||||
return (high[i]);
|
||||
case PRICE_LOW:
|
||||
return (low[i]);
|
||||
case PRICE_MEDIAN:
|
||||
return ((high[i] + low[i]) / 2.0);
|
||||
case PRICE_TYPICAL:
|
||||
return ((high[i] + low[i] + close[i]) / 3.0);
|
||||
case PRICE_WEIGHTED:
|
||||
return ((high[i] + low[i] + close[i] + close[i]) / 4.0);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,836 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121_XICH
|
||||
// Description: Ichimoku Kinko Hyo ...
|
||||
//
|
||||
//
|
||||
// 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_XICH Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "X121_XICH"
|
||||
|
||||
//
|
||||
// Ichimoku Golden Numbers ...
|
||||
enum ENUM_X_ICHIMOKU_GOLDEN_NUMBERS
|
||||
{
|
||||
X_ICH_BASE = 9,
|
||||
X_ICH_GOLDEN = 17,
|
||||
X_ICH_CYCLE = 26,
|
||||
X_ICH_PERIOD = 35,
|
||||
X_ICH_STAR = 45,
|
||||
X_ICH_MED = 52,
|
||||
X_ICH_LONG = 63,
|
||||
X_ICH_FULL = 72
|
||||
};
|
||||
|
||||
//
|
||||
// Ichimoku Lines Calculator Mode ...
|
||||
enum ENUM_X_ICHIMOKU_CALCULATION_MODE
|
||||
{
|
||||
//
|
||||
X_XICH_HH_LL_MODE = 1, // Highest High and Lowest Low
|
||||
X_XICH_HO_LC_MODE = 2, // Highest Open and Lowest Close
|
||||
};
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// ICHIMOKU Kinko Hyo ...
|
||||
|
||||
//
|
||||
// TENKANSEN ...
|
||||
input group "Tenkan Sen";
|
||||
input int tenkanSenLength = 9; // Length
|
||||
input ENUM_X_ICHIMOKU_CALCULATION_MODE tenkanSenMode = X_XICH_HH_LL_MODE; // Calculation Mode
|
||||
|
||||
//
|
||||
// KIJUNSEN ...
|
||||
input group "Kijun Sen";
|
||||
input int kijunSenLength = 26; // Length
|
||||
input ENUM_X_ICHIMOKU_CALCULATION_MODE kijunSenMode = X_XICH_HH_LL_MODE; // Calculation Mode
|
||||
|
||||
//
|
||||
// SENKOUSPANB ...
|
||||
input group "Senkou Span B";
|
||||
input int senkouSpanBLength = 52; // Length
|
||||
input ENUM_X_ICHIMOKU_CALCULATION_MODE senkouSpanBMode = X_XICH_HH_LL_MODE; // Calculation Mode
|
||||
|
||||
//
|
||||
// CHIKOUSPAN ...
|
||||
input group "Chikou Span";
|
||||
input ENUM_APPLIED_PRICE chikuoSpanAppliedTo = PRICE_CLOSE; // Price Type
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showTenkanSen = true; // Show Tenkan Sen
|
||||
input bool showKijunSen = true; // Show Kijun Sen
|
||||
input bool showKijunSenPlus = false; // Show Kijun Sen +
|
||||
input bool showKijunSenNegative = false; // Show Kijun Sen -
|
||||
input bool showChikouSpan = true; // Show Chikou Span
|
||||
input bool showSenkouSpanA = true; // Show Senkou Span A
|
||||
input bool showSenkouSpanB = true; // Show Senkou Span B
|
||||
input bool showKumo = true; // Show Kumo
|
||||
input bool shiftKumo = true; // Shift Kumo to Future
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 15
|
||||
#property indicator_plots 8
|
||||
|
||||
//
|
||||
// PLOTTED Buffers ...
|
||||
|
||||
//
|
||||
// ICHIMOKU ...
|
||||
|
||||
//
|
||||
// TENKANSEN ...
|
||||
|
||||
//
|
||||
#define tenkanSenBufferIndex 0
|
||||
double tenkanSenBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XICH TK"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrBrown
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// KIJUNSEN ...
|
||||
|
||||
//
|
||||
#define kijunSenBufferIndex 1
|
||||
double kijunSenBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121_XICH KJ"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrDodgerBlue
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#define kijunSenPlusBufferIndex 2
|
||||
double kijunSenPlusBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "X121_XICH KJ+"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrMediumTurquoise
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
#define kijunSenNegativeBufferIndex 3
|
||||
double kijunSenNegativeBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "X121_XICH KJ-"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrDarkSeaGreen
|
||||
#property indicator_style4 STYLE_DOT
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// CHIKOUSPAN ...
|
||||
|
||||
//
|
||||
#define chikouSpanBufferIndex 4
|
||||
double chikouSpanBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "X121_XICH CS"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrDarkGreen
|
||||
#property indicator_style5 STYLE_SOLID
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
#define senkouABufferIndex 5
|
||||
double senkouABuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "X121_XICH SSA"
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_color6 clrLightGray
|
||||
#property indicator_style6 STYLE_DASHDOTDOT
|
||||
#property indicator_width6 1
|
||||
|
||||
//
|
||||
#define senkouBBufferIndex 6
|
||||
double senkouBBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "X121_XICH SSB"
|
||||
#property indicator_type7 DRAW_LINE
|
||||
#property indicator_color7 clrLightGray
|
||||
#property indicator_style7 STYLE_DASHDOTDOT
|
||||
#property indicator_width7 1
|
||||
|
||||
//
|
||||
// KUMO ...
|
||||
|
||||
//
|
||||
// SENKOUSPANA ...
|
||||
|
||||
//
|
||||
#define senkouSpanABufferIndex 7
|
||||
double senkouSpanABuffer[];
|
||||
|
||||
//
|
||||
// SENKOUSPANB ...
|
||||
|
||||
//
|
||||
#define senkouSpanBBufferIndex 8
|
||||
double senkouSpanBBuffer[];
|
||||
|
||||
//
|
||||
// KUMOCLOUD ...
|
||||
|
||||
//
|
||||
#define kumoBufferIndex 7
|
||||
|
||||
//
|
||||
#property indicator_label8 "X121_XICH Kumo"
|
||||
#property indicator_type8 DRAW_FILLING
|
||||
#property indicator_color8 clrAqua, clrMagenta
|
||||
#property indicator_style8 STYLE_SOLID
|
||||
#property indicator_width8 1
|
||||
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
#define dTenkanBufferIndex 9
|
||||
double dTenkanBuffer[];
|
||||
|
||||
//
|
||||
#define dKijunBufferIndex 10
|
||||
double dKijunBuffer[];
|
||||
|
||||
//
|
||||
#define dChikouBufferIndex 11
|
||||
double dChikouBuffer[];
|
||||
|
||||
//
|
||||
#define dSSABufferIndex 12
|
||||
double dSSABuffer[];
|
||||
|
||||
//
|
||||
#define dSSBBufferIndex 13
|
||||
double dSSBBuffer[];
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
int mHandler;
|
||||
|
||||
//
|
||||
ENUM_SERIESMODE mTenkanSenTopMode = NULL;
|
||||
ENUM_SERIESMODE mTenkanSenBottomMode = NULL;
|
||||
|
||||
//
|
||||
ENUM_SERIESMODE mKijunSenTopMode = NULL;
|
||||
ENUM_SERIESMODE mKijunSenBottomMode = NULL;
|
||||
|
||||
//
|
||||
ENUM_SERIESMODE mSenkouSpanBTopMode = NULL;
|
||||
ENUM_SERIESMODE mSenkouSpanBBottomMode = NULL;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Init Handler ...
|
||||
mHandler = iIchimoku(
|
||||
_Symbol,
|
||||
_Period,
|
||||
tenkanSenLength,
|
||||
kijunSenLength,
|
||||
senkouSpanBLength);
|
||||
if (mHandler == INVALID_HANDLE)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
IndicatorRelease(mHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// 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;
|
||||
|
||||
//
|
||||
// Check Calculated Bars ...
|
||||
int ichCalculatedBars = BarsCalculated(mHandler);
|
||||
if (ichCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
int copiedTenkans = CopyBuffer(mHandler, TENKANSEN_LINE, 0, limit, dTenkanBuffer);
|
||||
int copiedKijuns = CopyBuffer(mHandler, KIJUNSEN_LINE, 0, limit, dKijunBuffer);
|
||||
int copiedChikous = CopyBuffer(mHandler, CHIKOUSPAN_LINE, 0, limit, dChikouBuffer);
|
||||
int copiedSSAs = CopyBuffer(mHandler, SENKOUSPANA_LINE, 0, limit, dSSABuffer);
|
||||
int copiedSSBs = CopyBuffer(mHandler, SENKOUSPANB_LINE, 0, limit, dSSBBuffer);
|
||||
if (
|
||||
copiedSSAs < 0 ||
|
||||
copiedSSBs < 0 ||
|
||||
copiedKijuns < 0 ||
|
||||
copiedTenkans < 0 ||
|
||||
copiedChikous < 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 =
|
||||
//
|
||||
(tenkanSenLength > 2 &&
|
||||
kijunSenLength > tenkanSenLength &&
|
||||
senkouSpanBLength > kijunSenLength)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Ichimoku ...
|
||||
result = MathMax(result, tenkanSenLength);
|
||||
result = MathMax(result, kijunSenLength);
|
||||
result = MathMax(result, senkouSpanBLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// ICHIMOKU ...
|
||||
|
||||
//
|
||||
// TENKANSEN ...
|
||||
|
||||
//
|
||||
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);
|
||||
|
||||
//
|
||||
// KIJUNSEN ...
|
||||
|
||||
//
|
||||
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);
|
||||
|
||||
//
|
||||
// KIJUNSEN Plus ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE kijunSenPlusDrawType = showKijunSenPlus ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(kijunSenPlusBuffer, true);
|
||||
SetIndexBuffer(kijunSenPlusBufferIndex, kijunSenPlusBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(kijunSenPlusBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(kijunSenPlusBufferIndex, PLOT_SHIFT, kijunSenLength);
|
||||
PlotIndexSetInteger(kijunSenPlusBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(kijunSenPlusBufferIndex, PLOT_DRAW_TYPE, kijunSenPlusDrawType);
|
||||
|
||||
//
|
||||
// KIJUNSEN Negative ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE kijunSenNegativeDrawType = showKijunSenNegative ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(kijunSenNegativeBuffer, true);
|
||||
SetIndexBuffer(kijunSenNegativeBufferIndex, kijunSenNegativeBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(kijunSenNegativeBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(kijunSenNegativeBufferIndex, PLOT_SHIFT, -kijunSenLength);
|
||||
PlotIndexSetInteger(kijunSenNegativeBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(kijunSenNegativeBufferIndex, PLOT_DRAW_TYPE, kijunSenNegativeDrawType);
|
||||
|
||||
//
|
||||
// CHIKOUSPAN ...
|
||||
|
||||
//
|
||||
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);
|
||||
|
||||
//
|
||||
// SENKOUSPAN A and B ...
|
||||
int shiftSize = shiftKumo ? kijunSenLength : 0;
|
||||
|
||||
//
|
||||
// SENKOUSPANA ...
|
||||
ENUM_DRAW_TYPE senkouSpanADrawType = showSenkouSpanA ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(senkouABuffer, true);
|
||||
SetIndexBuffer(senkouABufferIndex, senkouABuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(senkouABufferIndex, PLOT_SHIFT, shiftSize);
|
||||
PlotIndexSetInteger(senkouABufferIndex, PLOT_SHOW_DATA, showSenkouSpanA);
|
||||
PlotIndexSetInteger(senkouABufferIndex, PLOT_DRAW_TYPE, senkouSpanADrawType);
|
||||
|
||||
//
|
||||
// SENKOUSPANB ...
|
||||
ENUM_DRAW_TYPE senkouSpanBDrawType = showSenkouSpanB ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(senkouBBuffer, true);
|
||||
SetIndexBuffer(senkouBBufferIndex, senkouBBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(senkouBBufferIndex, PLOT_SHIFT, shiftSize);
|
||||
PlotIndexSetInteger(senkouBBufferIndex, PLOT_SHOW_DATA, showSenkouSpanB);
|
||||
PlotIndexSetInteger(senkouBBufferIndex, PLOT_DRAW_TYPE, senkouSpanBDrawType);
|
||||
|
||||
//
|
||||
// KUMO ...
|
||||
|
||||
//
|
||||
// SENKOUSPANA ...
|
||||
ArraySetAsSeries(senkouSpanABuffer, true);
|
||||
SetIndexBuffer(senkouSpanABufferIndex, senkouSpanABuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(senkouSpanABufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
// SENKOUSPANB ...
|
||||
ArraySetAsSeries(senkouSpanBBuffer, true);
|
||||
SetIndexBuffer(senkouSpanBBufferIndex, senkouSpanBBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(senkouSpanBBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
// KUMO ...
|
||||
|
||||
//
|
||||
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);
|
||||
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
// D Tenkan ...
|
||||
ArraySetAsSeries(dTenkanBuffer, true);
|
||||
SetIndexBuffer(dTenkanBufferIndex, dTenkanBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// D Kijun ...
|
||||
ArraySetAsSeries(dKijunBuffer, true);
|
||||
SetIndexBuffer(dKijunBufferIndex, dKijunBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// D Chikou ...
|
||||
ArraySetAsSeries(dChikouBuffer, true);
|
||||
SetIndexBuffer(dChikouBufferIndex, dChikouBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// D SSA ...
|
||||
ArraySetAsSeries(dSSABuffer, true);
|
||||
SetIndexBuffer(dSSABufferIndex, dSSABuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// D SSB ...
|
||||
ArraySetAsSeries(dSSBBuffer, true);
|
||||
SetIndexBuffer(dSSBBufferIndex, dSSBBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// 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
|
||||
)
|
||||
{
|
||||
//
|
||||
// ICHIMOKU ...
|
||||
|
||||
//
|
||||
double topValue;
|
||||
double bottomValue;
|
||||
|
||||
//
|
||||
// TENKANSEN ...
|
||||
|
||||
//
|
||||
// Extract Tenkan Sen Top/Bottom Calculation Mode based on User Input ...
|
||||
if (mTenkanSenTopMode == NULL || mTenkanSenBottomMode == NULL)
|
||||
{
|
||||
//
|
||||
switch (tenkanSenMode)
|
||||
{
|
||||
//
|
||||
case X_XICH_HH_LL_MODE:
|
||||
//
|
||||
mTenkanSenTopMode = MODE_HIGH;
|
||||
mTenkanSenBottomMode = MODE_LOW;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_XICH_HO_LC_MODE:
|
||||
//
|
||||
mTenkanSenTopMode = MODE_OPEN;
|
||||
mTenkanSenBottomMode = MODE_CLOSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Top ...
|
||||
topValue = GetHighestHigh(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mTenkanSenTopMode,
|
||||
tenkanSenLength,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
// Calculate Bottom ...
|
||||
bottomValue = GetLowestLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mTenkanSenBottomMode,
|
||||
tenkanSenLength,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
double tenkanSenValue = (topValue + bottomValue) / 2;
|
||||
tenkanSenBuffer[bar_index] = tenkanSenValue;
|
||||
|
||||
//
|
||||
// KIJUNSEN ...
|
||||
|
||||
//
|
||||
// Extract Kijun Sen Top/Bottom Calculation Mode based on User Input ...
|
||||
if (mKijunSenTopMode == NULL || mKijunSenBottomMode == NULL)
|
||||
{
|
||||
//
|
||||
switch (kijunSenMode)
|
||||
{
|
||||
//
|
||||
case X_XICH_HH_LL_MODE:
|
||||
//
|
||||
mKijunSenTopMode = MODE_HIGH;
|
||||
mKijunSenBottomMode = MODE_LOW;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_XICH_HO_LC_MODE:
|
||||
//
|
||||
mKijunSenTopMode = MODE_OPEN;
|
||||
mKijunSenBottomMode = MODE_CLOSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Top ...
|
||||
topValue = GetHighestHigh(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mKijunSenTopMode,
|
||||
kijunSenLength,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
// Calculate Bottom ...
|
||||
bottomValue = GetLowestLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mKijunSenBottomMode,
|
||||
kijunSenLength,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
double kijunSenValue = (topValue + bottomValue) / 2;
|
||||
kijunSenBuffer[bar_index] = kijunSenValue;
|
||||
|
||||
//
|
||||
kijunSenPlusBuffer[bar_index] = kijunSenValue;
|
||||
kijunSenNegativeBuffer[bar_index] = kijunSenValue;
|
||||
|
||||
//
|
||||
// CHIKOUSPAN ...
|
||||
double chikouSpanValue = GetAppliedPrice(
|
||||
bar_index,
|
||||
chikuoSpanAppliedTo);
|
||||
chikouSpanBuffer[bar_index] = chikouSpanValue;
|
||||
|
||||
//
|
||||
// KUMO ...
|
||||
|
||||
//
|
||||
// SENKOUSPANA ...
|
||||
double senkouSpanAValue = (tenkanSenValue + kijunSenValue) / 2;
|
||||
senkouABuffer[bar_index] = senkouSpanAValue;
|
||||
senkouSpanABuffer[bar_index] = senkouSpanAValue;
|
||||
|
||||
//
|
||||
// SENKOUSPANB ...
|
||||
|
||||
//
|
||||
// Extract Senkou Span B Top/Bottom Calculation Mode based on User Input ...
|
||||
if (mSenkouSpanBTopMode == NULL || mSenkouSpanBBottomMode == NULL)
|
||||
{
|
||||
//
|
||||
switch (senkouSpanBMode)
|
||||
{
|
||||
//
|
||||
case X_XICH_HH_LL_MODE:
|
||||
//
|
||||
mSenkouSpanBTopMode = MODE_HIGH;
|
||||
mSenkouSpanBBottomMode = MODE_LOW;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_XICH_HO_LC_MODE:
|
||||
//
|
||||
mSenkouSpanBTopMode = MODE_OPEN;
|
||||
mSenkouSpanBBottomMode = MODE_CLOSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Top ...
|
||||
topValue = GetHighestHigh(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mSenkouSpanBTopMode,
|
||||
senkouSpanBLength,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
// Calculate Bottom ...
|
||||
bottomValue = GetLowestLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mSenkouSpanBBottomMode,
|
||||
senkouSpanBLength,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
double senkouSpanBValue = (topValue + bottomValue) / 2;
|
||||
senkouBBuffer[bar_index] = senkouSpanBValue;
|
||||
senkouSpanBBuffer[bar_index] = senkouSpanBValue;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,786 @@
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// --------------------------------------
|
||||
// Name: X121_XMRB
|
||||
// Description: Moving Average Ribbon
|
||||
//
|
||||
//
|
||||
// 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_XMRB Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "X121_XMRB"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Ribbon 1";
|
||||
input int fast1Length = 3; // Fast
|
||||
input int slow1Length = 5; // Slow
|
||||
|
||||
//
|
||||
input group "Ribbon 2";
|
||||
input int fast2Length = 8; // Fast
|
||||
input int slow2Length = 13; // Slow
|
||||
|
||||
//
|
||||
input group "Ribbon 3";
|
||||
input int fast3Length = 21; // Fast
|
||||
input int slow3Length = 34; // Slow
|
||||
|
||||
//
|
||||
input group "Ribbon 4";
|
||||
input int fast4Length = 55; // Fast
|
||||
input int slow4Length = 89; // Slow
|
||||
|
||||
//
|
||||
input group "Ribbon 5";
|
||||
input int fast5Length = 144; // Fast
|
||||
input int slow5Length = 233; // Slow
|
||||
|
||||
//
|
||||
input group "Calculation";
|
||||
input ENUM_MA_METHOD ribbonMode = MODE_EMA; // Mode
|
||||
input ENUM_APPLIED_PRICE ribbonAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showFastMa = true; // Show Fast
|
||||
input bool showSlowMa = true; // Show Slow
|
||||
input bool showRibbon = false; // Show Ribbon
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 12
|
||||
#property indicator_plots 12
|
||||
|
||||
//
|
||||
// PLOTTED Buffers ...
|
||||
|
||||
//
|
||||
// MA ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
#define fastMaBufferIndex 0
|
||||
double fastMaBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XMRB F"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrLime
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
#define slowMaBufferIndex 1
|
||||
double slowMaBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121_XMRB S"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
|
||||
//
|
||||
#define fast1BufferIndex 2
|
||||
double fast1Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "X121_XMRB 1 F"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrAquamarine
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
#define fast2BufferIndex 3
|
||||
double fast2Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "X121_XMRB 2 F"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrAquamarine
|
||||
#property indicator_style4 STYLE_DOT
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
#define fast3BufferIndex 4
|
||||
double fast3Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "X121_XMRB 3 F"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrAquamarine
|
||||
#property indicator_style5 STYLE_DOT
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
#define fast4BufferIndex 5
|
||||
double fast4Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "X121_XMRB 4 F"
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_color6 clrAquamarine
|
||||
#property indicator_style6 STYLE_DOT
|
||||
#property indicator_width6 1
|
||||
|
||||
//
|
||||
#define fast5BufferIndex 6
|
||||
double fast5Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "X121_XMRB 5 F"
|
||||
#property indicator_type7 DRAW_LINE
|
||||
#property indicator_color7 clrAquamarine
|
||||
#property indicator_style7 STYLE_DOT
|
||||
#property indicator_width7 1
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
|
||||
//
|
||||
#define slow1BufferIndex 7
|
||||
double slow1Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label8 "X121_XMRB 1 S"
|
||||
#property indicator_type8 DRAW_LINE
|
||||
#property indicator_color8 clrPlum
|
||||
#property indicator_style8 STYLE_DOT
|
||||
#property indicator_width8 1
|
||||
|
||||
//
|
||||
#define slow2BufferIndex 8
|
||||
double slow2Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label9 "X121_XMRB 2 S"
|
||||
#property indicator_type9 DRAW_LINE
|
||||
#property indicator_color9 clrPlum
|
||||
#property indicator_style9 STYLE_DOT
|
||||
#property indicator_width9 1
|
||||
|
||||
//
|
||||
#define slow3BufferIndex 9
|
||||
double slow3Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label10 "X121_XMRB 3 S"
|
||||
#property indicator_type10 DRAW_LINE
|
||||
#property indicator_color10 clrPlum
|
||||
#property indicator_style10 STYLE_DOT
|
||||
#property indicator_width10 1
|
||||
|
||||
//
|
||||
#define slow4BufferIndex 10
|
||||
double slow4Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label11 "X121_XMRB 4 S"
|
||||
#property indicator_type11 DRAW_LINE
|
||||
#property indicator_color11 clrPlum
|
||||
#property indicator_style11 STYLE_DOT
|
||||
#property indicator_width11 1
|
||||
|
||||
//
|
||||
#define slow5BufferIndex 11
|
||||
double slow5Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label12 "X121_XMRB 5 S"
|
||||
#property indicator_type12 DRAW_LINE
|
||||
#property indicator_color12 clrPlum
|
||||
#property indicator_style12 STYLE_DOT
|
||||
#property indicator_width12 1
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int fast1MaHandler = INVALID_HANDLE;
|
||||
int fast2MaHandler = INVALID_HANDLE;
|
||||
int fast3MaHandler = INVALID_HANDLE;
|
||||
int fast4MaHandler = INVALID_HANDLE;
|
||||
int fast5MaHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
int slow1MaHandler = INVALID_HANDLE;
|
||||
int slow2MaHandler = INVALID_HANDLE;
|
||||
int slow3MaHandler = INVALID_HANDLE;
|
||||
int slow4MaHandler = INVALID_HANDLE;
|
||||
int slow5MaHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Initialize MAs ...
|
||||
if (!InitializeMas())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
|
||||
//
|
||||
IndicatorRelease(fast1MaHandler);
|
||||
IndicatorRelease(fast2MaHandler);
|
||||
IndicatorRelease(fast3MaHandler);
|
||||
IndicatorRelease(fast4MaHandler);
|
||||
IndicatorRelease(fast5MaHandler);
|
||||
|
||||
//
|
||||
IndicatorRelease(slow1MaHandler);
|
||||
IndicatorRelease(slow2MaHandler);
|
||||
IndicatorRelease(slow3MaHandler);
|
||||
IndicatorRelease(slow4MaHandler);
|
||||
IndicatorRelease(slow5MaHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// 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;
|
||||
|
||||
//
|
||||
// Check Calculated Bars ...
|
||||
//
|
||||
int fast1MaCalculatedBars = BarsCalculated(fast1MaHandler);
|
||||
int fast2MaCalculatedBars = BarsCalculated(fast2MaHandler);
|
||||
int fast3MaCalculatedBars = BarsCalculated(fast3MaHandler);
|
||||
int fast4MaCalculatedBars = BarsCalculated(fast4MaHandler);
|
||||
int fast5MaCalculatedBars = BarsCalculated(fast5MaHandler);
|
||||
//
|
||||
int slow1MaCalculatedBars = BarsCalculated(slow1MaHandler);
|
||||
int slow2MaCalculatedBars = BarsCalculated(slow2MaHandler);
|
||||
int slow3MaCalculatedBars = BarsCalculated(slow3MaHandler);
|
||||
int slow4MaCalculatedBars = BarsCalculated(slow4MaHandler);
|
||||
int slow5MaCalculatedBars = BarsCalculated(slow5MaHandler);
|
||||
if (
|
||||
fast1MaCalculatedBars < maxLength ||
|
||||
fast2MaCalculatedBars < maxLength ||
|
||||
fast3MaCalculatedBars < maxLength ||
|
||||
fast4MaCalculatedBars < maxLength ||
|
||||
fast5MaCalculatedBars < maxLength ||
|
||||
slow1MaCalculatedBars < maxLength ||
|
||||
slow2MaCalculatedBars < maxLength ||
|
||||
slow3MaCalculatedBars < maxLength ||
|
||||
slow4MaCalculatedBars < maxLength ||
|
||||
slow5MaCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
//
|
||||
int copiedFast1Mas = CopyBuffer(fast1MaHandler, 0, 0, limit, fast1Buffer);
|
||||
int copiedFast2Mas = CopyBuffer(fast2MaHandler, 0, 0, limit, fast2Buffer);
|
||||
int copiedFast3Mas = CopyBuffer(fast3MaHandler, 0, 0, limit, fast3Buffer);
|
||||
int copiedFast4Mas = CopyBuffer(fast4MaHandler, 0, 0, limit, fast4Buffer);
|
||||
int copiedFast5Mas = CopyBuffer(fast5MaHandler, 0, 0, limit, fast5Buffer);
|
||||
//
|
||||
int copiedSlow1Mas = CopyBuffer(slow1MaHandler, 0, 0, limit, slow1Buffer);
|
||||
int copiedSlow2Mas = CopyBuffer(slow2MaHandler, 0, 0, limit, slow2Buffer);
|
||||
int copiedSlow3Mas = CopyBuffer(slow3MaHandler, 0, 0, limit, slow3Buffer);
|
||||
int copiedSlow4Mas = CopyBuffer(slow4MaHandler, 0, 0, limit, slow4Buffer);
|
||||
int copiedSlow5Mas = CopyBuffer(slow5MaHandler, 0, 0, limit, slow5Buffer);
|
||||
if (
|
||||
copiedFast1Mas <= 0 ||
|
||||
copiedFast2Mas <= 0 ||
|
||||
copiedFast3Mas <= 0 ||
|
||||
copiedFast4Mas <= 0 ||
|
||||
copiedFast5Mas <= 0 ||
|
||||
copiedSlow1Mas <= 0 ||
|
||||
copiedSlow2Mas <= 0 ||
|
||||
copiedSlow3Mas <= 0 ||
|
||||
copiedSlow4Mas <= 0 ||
|
||||
copiedSlow5Mas <= 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 =
|
||||
//
|
||||
(fast1Length > 2 &&
|
||||
fast2Length > fast1Length &&
|
||||
fast3Length > fast2Length &&
|
||||
fast4Length > fast3Length &&
|
||||
fast5Length > fast4Length &&
|
||||
slow1Length > fast1Length &&
|
||||
slow2Length > fast2Length &&
|
||||
slow3Length > fast3Length &&
|
||||
slow4Length > fast4Length &&
|
||||
slow5Length > fast5Length &&
|
||||
slow2Length > slow1Length &&
|
||||
slow3Length > slow2Length &&
|
||||
slow4Length > slow3Length &&
|
||||
slow5Length > slow4Length
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Ma ...
|
||||
|
||||
//
|
||||
result = MathMax(fast1Length, fast2Length);
|
||||
result = MathMax(result, fast3Length);
|
||||
result = MathMax(result, fast4Length);
|
||||
result = MathMax(result, fast5Length);
|
||||
|
||||
//
|
||||
result = MathMax(result, slow1Length);
|
||||
result = MathMax(result, slow2Length);
|
||||
result = MathMax(result, slow3Length);
|
||||
result = MathMax(result, slow4Length);
|
||||
result = MathMax(result, slow5Length);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Ma Handlers ...
|
||||
bool InitializeMas()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
fast1MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
fast1Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
ribbonAppliedTo);
|
||||
fast2MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
fast2Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
ribbonAppliedTo);
|
||||
fast3MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
fast3Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
ribbonAppliedTo);
|
||||
fast4MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
fast4Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
ribbonAppliedTo);
|
||||
fast5MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
fast5Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
ribbonAppliedTo);
|
||||
|
||||
//
|
||||
slow1MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slow1Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
ribbonAppliedTo);
|
||||
slow2MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slow2Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
ribbonAppliedTo);
|
||||
slow3MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slow3Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
ribbonAppliedTo);
|
||||
slow4MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slow4Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
ribbonAppliedTo);
|
||||
slow5MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slow5Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
ribbonAppliedTo);
|
||||
|
||||
//
|
||||
result =
|
||||
fast1MaHandler != INVALID_HANDLE &&
|
||||
fast2MaHandler != INVALID_HANDLE &&
|
||||
fast3MaHandler != INVALID_HANDLE &&
|
||||
fast4MaHandler != INVALID_HANDLE &&
|
||||
fast5MaHandler != INVALID_HANDLE &&
|
||||
slow1MaHandler != INVALID_HANDLE &&
|
||||
slow2MaHandler != INVALID_HANDLE &&
|
||||
slow3MaHandler != INVALID_HANDLE &&
|
||||
slow4MaHandler != INVALID_HANDLE &&
|
||||
slow5MaHandler != INVALID_HANDLE;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
string message = "Error Initializing Handlers ...";
|
||||
Print(message);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// FAST ...
|
||||
ENUM_DRAW_TYPE fastDrawType = showFastMa ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
ArraySetAsSeries(fastMaBuffer, true);
|
||||
SetIndexBuffer(fastMaBufferIndex, fastMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fastMaBufferIndex, PLOT_SHOW_DATA, showFastMa);
|
||||
PlotIndexSetInteger(fastMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fastMaBufferIndex, PLOT_DRAW_TYPE, fastDrawType);
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
ENUM_DRAW_TYPE slowDrawType = showSlowMa ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
ArraySetAsSeries(slowMaBuffer, true);
|
||||
SetIndexBuffer(slowMaBufferIndex, slowMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(slowMaBufferIndex, PLOT_SHOW_DATA, showSlowMa);
|
||||
PlotIndexSetInteger(slowMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(slowMaBufferIndex, PLOT_DRAW_TYPE, slowDrawType);
|
||||
|
||||
//
|
||||
// DATA ...
|
||||
ENUM_DRAW_TYPE ribbonDrawType = showRibbon ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fast1Buffer, true);
|
||||
SetIndexBuffer(fast1BufferIndex, fast1Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fast1BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(fast1BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fast1BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fast2Buffer, true);
|
||||
SetIndexBuffer(fast2BufferIndex, fast2Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fast2BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(fast2BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fast2BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fast3Buffer, true);
|
||||
SetIndexBuffer(fast3BufferIndex, fast3Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fast3BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(fast3BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fast3BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fast4Buffer, true);
|
||||
SetIndexBuffer(fast4BufferIndex, fast4Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fast4BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(fast4BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fast4BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fast5Buffer, true);
|
||||
SetIndexBuffer(fast5BufferIndex, fast5Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fast5BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(fast5BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fast5BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(slow1Buffer, true);
|
||||
SetIndexBuffer(slow1BufferIndex, slow1Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(slow1BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(slow1BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(slow1BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(slow2Buffer, true);
|
||||
SetIndexBuffer(slow2BufferIndex, slow2Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(slow2BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(slow2BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(slow2BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(slow3Buffer, true);
|
||||
SetIndexBuffer(slow3BufferIndex, slow3Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(slow3BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(slow3BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(slow3BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(slow4Buffer, true);
|
||||
SetIndexBuffer(slow4BufferIndex, slow4Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(slow4BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(slow4BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(slow4BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(slow5Buffer, true);
|
||||
SetIndexBuffer(slow5BufferIndex, slow5Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(slow5BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(slow5BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(slow5BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
}
|
||||
|
||||
//
|
||||
// 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
|
||||
)
|
||||
{
|
||||
//
|
||||
// Retireve Values ...
|
||||
|
||||
//
|
||||
double fast1Value = fast1Buffer[bar_index];
|
||||
double fast2Value = fast2Buffer[bar_index];
|
||||
double fast3Value = fast3Buffer[bar_index];
|
||||
double fast4Value = fast4Buffer[bar_index];
|
||||
double fast5Value = fast5Buffer[bar_index];
|
||||
|
||||
//
|
||||
double slow1Value = slow1Buffer[bar_index];
|
||||
double slow2Value = slow2Buffer[bar_index];
|
||||
double slow3Value = slow3Buffer[bar_index];
|
||||
double slow4Value = slow4Buffer[bar_index];
|
||||
double slow5Value = slow5Buffer[bar_index];
|
||||
|
||||
//
|
||||
double fastValue = (fast1Value + fast2Value + fast3Value + fast4Value + fast5Value) / 5;
|
||||
fastMaBuffer[bar_index] = fastValue;
|
||||
|
||||
//
|
||||
double slowValue = (slow1Value + slow2Value + slow3Value + slow4Value + slow5Value) / 5;
|
||||
slowMaBuffer[bar_index] = slowValue;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,721 @@
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121_XOSC
|
||||
// Description: provides some oscillator values
|
||||
// as empty Indicator ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121_XAMA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
#define ShortName "X121_XOSC"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
input group "ATR";
|
||||
input int atrLength = 14; // Length
|
||||
|
||||
//
|
||||
// RVI ...
|
||||
// The buffer numbers are the following: 0 - MAIN_LINE, 1 - SIGNAL_LINE.
|
||||
input group "RVI";
|
||||
input int rviLength = 10; // Length
|
||||
|
||||
//
|
||||
// BULLPOWER ...
|
||||
input group "Bulls Power";
|
||||
input int bullpLength = 13; // Length
|
||||
|
||||
//
|
||||
// BEARPOWER ...
|
||||
input group "Bears Power";
|
||||
input int bearpLength = 13; // Length
|
||||
|
||||
//
|
||||
// VOLUME ...
|
||||
input group "Volumes";
|
||||
input ENUM_APPLIED_VOLUME volumeAppliedTo = VOLUME_TICK; // Applied To
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
input group "RSI";
|
||||
input int rsiLength = 14; // Length
|
||||
input ENUM_APPLIED_PRICE rsiAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// CCI ...
|
||||
input group "CCI";
|
||||
input int cciLength = 14; // Length
|
||||
input ENUM_APPLIED_PRICE cciAppliedTo = PRICE_TYPICAL; // Applied To
|
||||
|
||||
//
|
||||
// STDDEV ...
|
||||
input group "Standard Deviation";
|
||||
input int stddevLength = 20; // Length
|
||||
input int stddevShift = 0; // Shift
|
||||
input ENUM_MA_METHOD stddevMethod = MODE_SMA; // Mode
|
||||
input ENUM_APPLIED_PRICE stddevAppliedTo = PRICE_CLOSE; // AppliedTo
|
||||
|
||||
//
|
||||
// MOMENTUM ...
|
||||
input group "Momentum";
|
||||
input int momentumLength = 14; // Length
|
||||
input ENUM_APPLIED_PRICE momentumAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
input group "SAR";
|
||||
input double sarStep = 0.02; // Step
|
||||
input double sarMaximum = 0.2; // Maximum
|
||||
|
||||
//
|
||||
// MACD ...
|
||||
// The buffer numbers are the following: 0 - MAIN_LINE, 1 - SIGNAL_LINE.
|
||||
input group "MACD";
|
||||
input int macdFastLength = 12; // Fast Length
|
||||
input int macdSlowLength = 26; // Slow Length
|
||||
input int macdSignaLength = 9; // Signal Length
|
||||
input ENUM_APPLIED_PRICE macdAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// STOCHASTIC ...
|
||||
// The buffer numbers: 0 - MAIN_LINE, 1 - SIGNAL_LINE.
|
||||
input group "Stochastic";
|
||||
input int stochKLength = 5; // K Length
|
||||
input int stochDLength = 3; // D Length
|
||||
input int stochSlowing = 3; // Slowing
|
||||
input ENUM_MA_METHOD stochMaMethod = MODE_SMA; // Ma Method
|
||||
input ENUM_STO_PRICE stochMode = STO_LOWHIGH; // Calculation Mode
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 15
|
||||
#property indicator_plots 0
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
#define atrBufferIndex 0
|
||||
double atrBuffer[];
|
||||
|
||||
//
|
||||
// RVI ...
|
||||
#define rviMainBufferIndex 1
|
||||
#define rviSignalBufferIndex 2
|
||||
double rviMainBuffer[];
|
||||
double rviSignalBuffer[];
|
||||
|
||||
//
|
||||
// BULLPOWER ...
|
||||
#define bullPBufferIndex 3
|
||||
double bullPBuffer[];
|
||||
|
||||
//
|
||||
// BEARPOWER ...
|
||||
#define bearPBufferIndex 4
|
||||
double bearPBuffer[];
|
||||
|
||||
//
|
||||
// VOLUME ...
|
||||
#define volumeBufferIndex 5
|
||||
double volumeBuffer[];
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
#define rsiBufferIndex 6
|
||||
double rsiBuffer[];
|
||||
|
||||
//
|
||||
// CCI ...
|
||||
#define cciBufferIndex 7
|
||||
double cciBuffer[];
|
||||
|
||||
//
|
||||
// MOMENTUM ...
|
||||
#define momentumBufferIndex 8
|
||||
double momentumBuffer[];
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
#define sarBufferIndex 9
|
||||
double sarBuffer[];
|
||||
|
||||
//
|
||||
// MACD ...
|
||||
#define macdMainBufferIndex 10
|
||||
#define macdSignalBufferIndex 11
|
||||
double macdMainBuffer[];
|
||||
double macdSignalBuffer[];
|
||||
|
||||
//
|
||||
// STOCHASTIC ...
|
||||
#define stochMainBufferIndex 12
|
||||
#define stochSignalBufferIndex 13
|
||||
double stochMainBuffer[];
|
||||
double stochSignalBuffer[];
|
||||
|
||||
//
|
||||
// STANDARDDEVIATION ...
|
||||
#define stddevBufferIndex 14
|
||||
double stddevBuffer[];
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int atrHandler = INVALID_HANDLE;
|
||||
int rviHandler = INVALID_HANDLE;
|
||||
int bullPHandler = INVALID_HANDLE;
|
||||
int bearPHandler = INVALID_HANDLE;
|
||||
int volumeHandler = INVALID_HANDLE;
|
||||
int rsiHandler = INVALID_HANDLE;
|
||||
int cciHandler = INVALID_HANDLE;
|
||||
int momentumHandler = INVALID_HANDLE;
|
||||
int sarHandler = INVALID_HANDLE;
|
||||
int macdHandler = INVALID_HANDLE;
|
||||
int stochHandler = INVALID_HANDLE;
|
||||
int stddevHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Initializing Handlers ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
atrHandler = iATR(
|
||||
_Symbol,
|
||||
_Period,
|
||||
atrLength);
|
||||
|
||||
//
|
||||
// RVI ...
|
||||
rviHandler = iRVI(
|
||||
_Symbol,
|
||||
_Period,
|
||||
rviLength);
|
||||
|
||||
//
|
||||
// BULLSPOWER ...
|
||||
bullPHandler = iBullsPower(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bullpLength);
|
||||
|
||||
//
|
||||
// BEARSPOWER ...
|
||||
bearPHandler = iBearsPower(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bullpLength);
|
||||
|
||||
//
|
||||
// VOLUMES ...
|
||||
volumeHandler = iVolumes(
|
||||
_Symbol,
|
||||
_Period,
|
||||
volumeAppliedTo);
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
rsiHandler = iRSI(
|
||||
_Symbol,
|
||||
_Period,
|
||||
rsiLength,
|
||||
rsiAppliedTo);
|
||||
|
||||
//
|
||||
// CCI ...
|
||||
cciHandler = iCCI(
|
||||
_Symbol,
|
||||
_Period,
|
||||
cciLength,
|
||||
cciAppliedTo);
|
||||
|
||||
//
|
||||
// MOMENTUM ...
|
||||
momentumHandler = iMomentum(
|
||||
_Symbol,
|
||||
_Period,
|
||||
momentumLength,
|
||||
momentumAppliedTo);
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
sarHandler = iSAR(
|
||||
_Symbol,
|
||||
_Period,
|
||||
sarStep,
|
||||
sarMaximum);
|
||||
|
||||
//
|
||||
// MACD ...
|
||||
macdHandler = iMACD(
|
||||
_Symbol,
|
||||
_Period,
|
||||
macdFastLength,
|
||||
macdSlowLength,
|
||||
macdSignaLength,
|
||||
macdAppliedTo);
|
||||
|
||||
//
|
||||
// STOCHASTIC ...
|
||||
stochHandler = iStochastic(
|
||||
_Symbol,
|
||||
_Period,
|
||||
stochKLength,
|
||||
stochDLength,
|
||||
stochSlowing,
|
||||
stochMaMethod,
|
||||
stochMode);
|
||||
|
||||
//
|
||||
// STANDARDDEVIATION ...
|
||||
stddevHandler = iStdDev(
|
||||
_Symbol,
|
||||
_Period,
|
||||
stddevLength,
|
||||
stddevShift,
|
||||
stddevMethod,
|
||||
stddevAppliedTo);
|
||||
|
||||
//
|
||||
bool isAllHandlersInit =
|
||||
//
|
||||
atrHandler != INVALID_HANDLE &&
|
||||
rviHandler != INVALID_HANDLE &&
|
||||
bullPHandler != INVALID_HANDLE &&
|
||||
bearPHandler != INVALID_HANDLE &&
|
||||
volumeHandler != INVALID_HANDLE &&
|
||||
rsiHandler != INVALID_HANDLE &&
|
||||
cciHandler != INVALID_HANDLE &&
|
||||
momentumHandler != INVALID_HANDLE &&
|
||||
sarHandler != INVALID_HANDLE &&
|
||||
macdHandler != INVALID_HANDLE &&
|
||||
stochHandler != INVALID_HANDLE &&
|
||||
stddevHandler != INVALID_HANDLE
|
||||
//
|
||||
;
|
||||
if (!isAllHandlersInit)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
IndicatorRelease(atrHandler);
|
||||
IndicatorRelease(rviHandler);
|
||||
IndicatorRelease(bullPHandler);
|
||||
IndicatorRelease(bearPHandler);
|
||||
IndicatorRelease(volumeHandler);
|
||||
IndicatorRelease(rsiHandler);
|
||||
IndicatorRelease(cciHandler);
|
||||
IndicatorRelease(momentumHandler);
|
||||
IndicatorRelease(sarHandler);
|
||||
IndicatorRelease(macdHandler);
|
||||
IndicatorRelease(stochHandler);
|
||||
IndicatorRelease(stddevHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// 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;
|
||||
|
||||
//
|
||||
// Check Calculated Bars ...
|
||||
int atrCalculatedBars = BarsCalculated(atrHandler);
|
||||
int rviCalculatedBars = BarsCalculated(rviHandler);
|
||||
int bullPCalculatedBars = BarsCalculated(bullPHandler);
|
||||
int bearPCalculatedBars = BarsCalculated(bearPHandler);
|
||||
int volumeCalculatedBars = BarsCalculated(volumeHandler);
|
||||
int rsiCalculatedBars = BarsCalculated(rsiHandler);
|
||||
int cciCalculatedBars = BarsCalculated(cciHandler);
|
||||
int momentumCalculatedBars = BarsCalculated(momentumHandler);
|
||||
int sarCalculatedBars = BarsCalculated(sarHandler);
|
||||
int macdCalculatedBars = BarsCalculated(macdHandler);
|
||||
int stochCalculatedBars = BarsCalculated(stochHandler);
|
||||
int stddevCalculatedBars = BarsCalculated(stddevHandler);
|
||||
|
||||
//
|
||||
bool isCalculatedBarsPassed =
|
||||
//
|
||||
atrCalculatedBars >= maxLength &&
|
||||
rviCalculatedBars >= maxLength &&
|
||||
bullPCalculatedBars >= maxLength &&
|
||||
bearPCalculatedBars >= maxLength &&
|
||||
volumeCalculatedBars >= maxLength &&
|
||||
rsiCalculatedBars >= maxLength &&
|
||||
cciCalculatedBars >= maxLength &&
|
||||
momentumCalculatedBars >= maxLength &&
|
||||
sarCalculatedBars >= maxLength &&
|
||||
macdCalculatedBars >= maxLength &&
|
||||
stochCalculatedBars >= maxLength &&
|
||||
stddevCalculatedBars >= maxLength
|
||||
//
|
||||
;
|
||||
if (!isCalculatedBarsPassed)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
int atrCopiedItems = CopyBuffer(atrHandler, 0, 0, limit, atrBuffer);
|
||||
int rviMainCopiedItems = CopyBuffer(rviHandler, MAIN_LINE, 0, limit, rviMainBuffer);
|
||||
int rviSignalCopiedItems = CopyBuffer(rviHandler, SIGNAL_LINE, 0, limit, rviSignalBuffer);
|
||||
int bullPCopiedItems = CopyBuffer(bullPHandler, 0, 0, limit, bullPBuffer);
|
||||
int bearPCopiedItems = CopyBuffer(bearPHandler, 0, 0, limit, bearPBuffer);
|
||||
int volumeCopiedItems = CopyBuffer(volumeHandler, 0, 0, limit, volumeBuffer);
|
||||
int rsiCopiedItems = CopyBuffer(rsiHandler, 0, 0, limit, rsiBuffer);
|
||||
int cciCopiedItems = CopyBuffer(cciHandler, 0, 0, limit, cciBuffer);
|
||||
int momentumCopiedItems = CopyBuffer(momentumHandler, 0, 0, limit, momentumBuffer);
|
||||
int sarCopiedItems = CopyBuffer(sarHandler, 0, 0, limit, sarBuffer);
|
||||
int macdMainCopiedItems = CopyBuffer(macdHandler, MAIN_LINE, 0, limit, macdMainBuffer);
|
||||
int macdSignalCopiedItems = CopyBuffer(macdHandler, SIGNAL_LINE, 0, limit, macdSignalBuffer);
|
||||
int stochMainCopiedItems = CopyBuffer(stochHandler, MAIN_LINE, 0, limit, stochMainBuffer);
|
||||
int stocSignalhCopiedItems = CopyBuffer(stochHandler, SIGNAL_LINE, 0, limit, stochSignalBuffer);
|
||||
int stddevCopiedItems = CopyBuffer(stddevHandler, 0, 0, limit, stddevBuffer);
|
||||
|
||||
//
|
||||
bool isCopiedBarsPassed =
|
||||
//
|
||||
atrCopiedItems > 0 &&
|
||||
rviMainCopiedItems > 0 &&
|
||||
rviSignalCopiedItems > 0 &&
|
||||
bullPCopiedItems > 0 &&
|
||||
bearPCopiedItems > 0 &&
|
||||
volumeCopiedItems > 0 &&
|
||||
rsiCopiedItems > 0 &&
|
||||
cciCopiedItems > 0 &&
|
||||
momentumCopiedItems > 0 &&
|
||||
sarCopiedItems > 0 &&
|
||||
macdMainCopiedItems > 0 &&
|
||||
macdSignalCopiedItems > 0 &&
|
||||
stochMainCopiedItems > 0 &&
|
||||
stocSignalhCopiedItems > 0 &&
|
||||
stddevCopiedItems > 0
|
||||
//
|
||||
;
|
||||
if (!isCopiedBarsPassed)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
// Do Buffers Calculation ...
|
||||
// HERE We Do Not anything ...
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result =
|
||||
//
|
||||
atrLength >= 2 &&
|
||||
rviLength >= 2 &&
|
||||
bullpLength >= 2 &&
|
||||
bearpLength >= 2 &&
|
||||
rsiLength >= 2 &&
|
||||
cciLength >= 2 &&
|
||||
momentumLength >= 2 &&
|
||||
sarStep > 0 &&
|
||||
sarStep < sarMaximum &&
|
||||
macdFastLength >= 2 &&
|
||||
macdSlowLength > macdFastLength &&
|
||||
macdSignaLength >= 2 &&
|
||||
stochKLength >= 2 &&
|
||||
stochDLength >= 2 &&
|
||||
stochSlowing >= 2 &&
|
||||
stddevLength >= 2 &&
|
||||
stddevShift >= 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(atrLength, rviLength);
|
||||
result = MathMax(result, bullpLength);
|
||||
result = MathMax(result, bearpLength);
|
||||
result = MathMax(result, rsiLength);
|
||||
result = MathMax(result, cciLength);
|
||||
result = MathMax(result, momentumLength);
|
||||
result = MathMax(result, macdFastLength);
|
||||
result = MathMax(result, macdSlowLength);
|
||||
result = MathMax(result, macdSignaLength);
|
||||
result = MathMax(result, stochKLength);
|
||||
result = MathMax(result, stochDLength);
|
||||
result = MathMax(result, stochSlowing);
|
||||
result = MathMax(result, stddevLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
ArraySetAsSeries(atrBuffer, true);
|
||||
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// RVI ...
|
||||
|
||||
//
|
||||
// Main ...
|
||||
ArraySetAsSeries(rviMainBuffer, true);
|
||||
SetIndexBuffer(rviMainBufferIndex, rviMainBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Signal ...
|
||||
ArraySetAsSeries(rviSignalBuffer, true);
|
||||
SetIndexBuffer(rviSignalBufferIndex, rviSignalBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// BULLPOWER ...
|
||||
ArraySetAsSeries(bullPBuffer, true);
|
||||
SetIndexBuffer(bullPBufferIndex, bullPBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// BEARPOWER ...
|
||||
ArraySetAsSeries(bearPBuffer, true);
|
||||
SetIndexBuffer(bearPBufferIndex, bearPBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// VOLUME ...
|
||||
ArraySetAsSeries(volumeBuffer, true);
|
||||
SetIndexBuffer(volumeBufferIndex, volumeBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
ArraySetAsSeries(rsiBuffer, true);
|
||||
SetIndexBuffer(rsiBufferIndex, rsiBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// CCI ...
|
||||
ArraySetAsSeries(cciBuffer, true);
|
||||
SetIndexBuffer(cciBufferIndex, cciBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// MOMENTUM ...
|
||||
ArraySetAsSeries(momentumBuffer, true);
|
||||
SetIndexBuffer(momentumBufferIndex, momentumBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
ArraySetAsSeries(sarBuffer, true);
|
||||
SetIndexBuffer(sarBufferIndex, sarBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// STANDARDDEVIATION ...
|
||||
ArraySetAsSeries(stddevBuffer, true);
|
||||
SetIndexBuffer(stddevBufferIndex, stddevBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// MACD ...
|
||||
|
||||
//
|
||||
// Main ...
|
||||
ArraySetAsSeries(macdMainBuffer, true);
|
||||
SetIndexBuffer(macdMainBufferIndex, macdMainBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Signal ...
|
||||
ArraySetAsSeries(macdSignalBuffer, true);
|
||||
SetIndexBuffer(macdSignalBufferIndex, macdSignalBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,992 @@
|
||||
///////////////////////////////////////////////////////
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------
|
||||
// Name: X121_XPV
|
||||
// Description: Market Peaks and Vales
|
||||
//
|
||||
//
|
||||
// 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_XPV Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "X121_XPV"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Makret Cycles";
|
||||
input int shortLength = 9; // Short Length
|
||||
input int mediumLength = 17; // Medium Length
|
||||
input int longLength = 26; // Long Length
|
||||
input int hindLength = 35; // Hind Length
|
||||
input double fiboLevel1 = 0.382; // Fibio 1st Level
|
||||
input double fiboLevel2 = 0.5; // Fibio 2st Level
|
||||
input double fiboLevel3 = 0.618; // Fibio 3rd Level
|
||||
|
||||
//
|
||||
input group "Detection Modes";
|
||||
input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method
|
||||
input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showPeaksAndVales = true; // Show Peaks and Vales
|
||||
input bool showLevels = false; // Show Levels
|
||||
input bool showFibo1Levels = true; // Show Fibo 1st Level
|
||||
input bool showFibo2Levels = true; // Show Fibo 2nd Level
|
||||
input bool showFibo3Levels = true; // Show Fibo 3rd Level
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 26
|
||||
#property indicator_plots 18
|
||||
|
||||
//
|
||||
// PEKSANDVALES ...
|
||||
|
||||
//
|
||||
// PEAKS ...
|
||||
|
||||
//
|
||||
#define peaksBufferIndex 0
|
||||
double peaksBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XPV PEAKS"
|
||||
#property indicator_type1 DRAW_ARROW
|
||||
#property indicator_color1 clrAqua
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// VALES ...
|
||||
|
||||
//
|
||||
#define valesBufferIndex 1
|
||||
double valesBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121_XPV VALES"
|
||||
#property indicator_type2 DRAW_ARROW
|
||||
#property indicator_color2 clrMagenta
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#define rBufferIndex 2
|
||||
double rBuffer[];
|
||||
|
||||
//
|
||||
#define rColorBufferIndex 3
|
||||
double rColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "X121_XPV R"
|
||||
#property indicator_type3 DRAW_COLOR_LINE
|
||||
#property indicator_color3 clrAqua, CLR_NONE
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
#define sBufferIndex 4
|
||||
#define sBufferPlotIndex 3
|
||||
double sBuffer[];
|
||||
|
||||
//
|
||||
#define sColorBufferIndex 5
|
||||
double sColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "X121_XPV S"
|
||||
#property indicator_type4 DRAW_COLOR_LINE
|
||||
#property indicator_color4 clrMagenta, CLR_NONE
|
||||
#property indicator_style4 STYLE_DOT
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// FIBBO Level 1 ...
|
||||
|
||||
//
|
||||
#define fl1BufferIndex 6
|
||||
#define fl1BufferPlotIndex 4
|
||||
double fl1Buffer[];
|
||||
|
||||
//
|
||||
#define fl1ColorBufferIndex 7
|
||||
double fl1ColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "X121_XPV FL1"
|
||||
#property indicator_type5 DRAW_COLOR_LINE
|
||||
#property indicator_color5 CLR_NONE, clrGold
|
||||
#property indicator_style5 STYLE_DASHDOTDOT
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
// FIBBO Level 2 ...
|
||||
|
||||
//
|
||||
#define fl2BufferIndex 8
|
||||
#define fl2BufferPlotIndex 5
|
||||
double fl2Buffer[];
|
||||
|
||||
//
|
||||
#define fl2ColorBufferIndex 9
|
||||
double fl2ColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "X121_XPV FL2"
|
||||
#property indicator_type6 DRAW_COLOR_LINE
|
||||
#property indicator_color6 CLR_NONE, clrGold
|
||||
#property indicator_style6 STYLE_DASHDOTDOT
|
||||
#property indicator_width6 1
|
||||
|
||||
//
|
||||
// FIBBO Level 3 ...
|
||||
|
||||
//
|
||||
#define fl3BufferIndex 10
|
||||
#define fl3BufferPlotIndex 6
|
||||
double fl3Buffer[];
|
||||
|
||||
//
|
||||
#define fl3ColorBufferIndex 11
|
||||
double fl3ColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "X121_XPV FL3"
|
||||
#property indicator_type7 DRAW_COLOR_LINE
|
||||
#property indicator_color7 CLR_NONE, clrGold
|
||||
#property indicator_style7 STYLE_DASHDOTDOT
|
||||
#property indicator_width7 1
|
||||
|
||||
//
|
||||
// LEVELS ...
|
||||
|
||||
//
|
||||
#define sHHBufferIndex 12
|
||||
#define sHHBufferPlotIndex 7
|
||||
double sHHBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label8 "X121_XPV SHH"
|
||||
#property indicator_type8 DRAW_LINE
|
||||
#property indicator_color8 clrLightGray
|
||||
#property indicator_style8 STYLE_DOT
|
||||
#property indicator_width8 1
|
||||
|
||||
#define sLLBufferIndex 13
|
||||
#define sLLBufferPlotIndex 8
|
||||
double sLLBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label9 "X121_XPV SLL"
|
||||
#property indicator_type9 DRAW_LINE
|
||||
#property indicator_color9 clrLightGray
|
||||
#property indicator_style9 STYLE_DOT
|
||||
#property indicator_width9 1
|
||||
|
||||
//
|
||||
#define mHHBufferIndex 14
|
||||
#define mHHBufferPlotIndex 9
|
||||
double mHHBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label10 "X121_XPV MHH"
|
||||
#property indicator_type10 DRAW_LINE
|
||||
#property indicator_color10 clrLightGray
|
||||
#property indicator_style10 STYLE_DOT
|
||||
#property indicator_width10 1
|
||||
|
||||
//
|
||||
#define mLLBufferIndex 15
|
||||
#define mLLBufferPlotIndex 10
|
||||
double mLLBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label11 "X121_XPV MLL"
|
||||
#property indicator_type11 DRAW_LINE
|
||||
#property indicator_color11 clrLightGray
|
||||
#property indicator_style11 STYLE_DOT
|
||||
#property indicator_width11 1
|
||||
|
||||
//
|
||||
#define lHHBufferIndex 16
|
||||
#define lHHBufferPlotIndex 11
|
||||
double lHHBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label12 "X121_XPV LHH"
|
||||
#property indicator_type12 DRAW_LINE
|
||||
#property indicator_color12 clrLightGray
|
||||
#property indicator_style12 STYLE_DOT
|
||||
#property indicator_width12 1
|
||||
|
||||
//
|
||||
#define lLLBufferIndex 17
|
||||
#define lLLBufferPlotIndex 12
|
||||
double lLLBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label13 "X121_XPV LLL"
|
||||
#property indicator_type13 DRAW_LINE
|
||||
#property indicator_color13 clrLightGray
|
||||
#property indicator_style13 STYLE_DOT
|
||||
#property indicator_width13 1
|
||||
|
||||
//
|
||||
#define hHHBufferIndex 18
|
||||
#define hHHBufferPlotIndex 13
|
||||
double hHHBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label14 "X121_XPV HHH"
|
||||
#property indicator_type14 DRAW_LINE
|
||||
#property indicator_color14 clrLightGray
|
||||
#property indicator_style14 STYLE_DOT
|
||||
#property indicator_width14 1
|
||||
|
||||
//
|
||||
#define hLLBufferIndex 19
|
||||
#define hLLBufferPlotIndex 14
|
||||
double hLLBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label15 "X121_XPV HLL"
|
||||
#property indicator_type15 DRAW_LINE
|
||||
#property indicator_color15 clrLightGray
|
||||
#property indicator_style15 STYLE_DOT
|
||||
#property indicator_width15 1
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
double lastPeak;
|
||||
double lastVale;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// 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 =
|
||||
//
|
||||
(shortLength > 2 &&
|
||||
mediumLength > shortLength &&
|
||||
longLength > mediumLength &&
|
||||
hindLength > longLength)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Peaks and Vales ...
|
||||
result = MathMax(shortLength, mediumLength);
|
||||
result = MathMax(result, longLength);
|
||||
result = MathMax(result, hindLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// RANGE ...
|
||||
|
||||
//
|
||||
// PEAKS and VALES ...
|
||||
ENUM_DRAW_TYPE pvDrawType = showPeaksAndVales ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// PEAKS ...
|
||||
ArraySetAsSeries(peaksBuffer, true);
|
||||
SetIndexBuffer(peaksBufferIndex, peaksBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(peaksBufferIndex, PLOT_ARROW, 225);
|
||||
// PlotIndexSetInteger(peaksBufferIndex, PLOT_ARROW_SHIFT, -20);
|
||||
PlotIndexSetDouble(peaksBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(peaksBufferIndex, PLOT_SHOW_DATA, showPeaksAndVales);
|
||||
PlotIndexSetInteger(peaksBufferIndex, PLOT_DRAW_TYPE, pvDrawType);
|
||||
|
||||
//
|
||||
// VALES ...
|
||||
ArraySetAsSeries(valesBuffer, true);
|
||||
SetIndexBuffer(valesBufferIndex, valesBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(valesBufferIndex, PLOT_ARROW, 225);
|
||||
// PlotIndexSetInteger(valesBufferIndex, PLOT_ARROW_SHIFT, 20);
|
||||
PlotIndexSetDouble(valesBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(valesBufferIndex, PLOT_SHOW_DATA, showPeaksAndVales);
|
||||
PlotIndexSetInteger(valesBufferIndex, PLOT_DRAW_TYPE, pvDrawType);
|
||||
|
||||
//
|
||||
// SUPPORT and RESISTANCE ...
|
||||
//
|
||||
|
||||
//
|
||||
// RESISTANCE ...
|
||||
ArraySetAsSeries(rBuffer, true);
|
||||
SetIndexBuffer(rBufferIndex, rBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(rBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(rBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// RESISTANCE Color ...
|
||||
ArraySetAsSeries(rColorBuffer, true);
|
||||
SetIndexBuffer(rColorBufferIndex, rColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// SUPPORT ...
|
||||
ArraySetAsSeries(sBuffer, true);
|
||||
SetIndexBuffer(sBufferIndex, sBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(sBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(sBufferPlotIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// SUPPORT Color ...
|
||||
ArraySetAsSeries(sColorBuffer, true);
|
||||
SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// FIBBO Levels ...
|
||||
|
||||
//
|
||||
// LEVEL 1 ...
|
||||
|
||||
//
|
||||
// BULLISH ...
|
||||
ArraySetAsSeries(fl1Buffer, true);
|
||||
SetIndexBuffer(fl1BufferIndex, fl1Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fl1BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fl1BufferIndex, PLOT_SHOW_DATA, showFibo1Levels);
|
||||
|
||||
//
|
||||
// BULLISH Color ...
|
||||
ArraySetAsSeries(fl1ColorBuffer, true);
|
||||
SetIndexBuffer(fl1ColorBufferIndex, fl1ColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// LEVEL 2 ...
|
||||
|
||||
//
|
||||
// BULLISH ...
|
||||
ArraySetAsSeries(fl2Buffer, true);
|
||||
SetIndexBuffer(fl2BufferIndex, fl2Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fl2BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fl2BufferIndex, PLOT_SHOW_DATA, showFibo2Levels);
|
||||
|
||||
//
|
||||
// BULLISH Color ...
|
||||
ArraySetAsSeries(fl2ColorBuffer, true);
|
||||
SetIndexBuffer(fl2ColorBufferIndex, fl2ColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// LEVEL 3 ...
|
||||
|
||||
//
|
||||
// BULLISH ...
|
||||
ArraySetAsSeries(fl3Buffer, true);
|
||||
SetIndexBuffer(fl3BufferIndex, fl3Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fl3BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fl3BufferIndex, PLOT_SHOW_DATA, showFibo3Levels);
|
||||
|
||||
//
|
||||
// BULLISH Color ...
|
||||
ArraySetAsSeries(fl3ColorBuffer, true);
|
||||
SetIndexBuffer(fl3ColorBufferIndex, fl3ColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE zoneDrawType = showLevels ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
// SHORT Buffers ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
ArraySetAsSeries(sHHBuffer, true);
|
||||
SetIndexBuffer(sHHBufferIndex, sHHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(sHHBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(sHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
||||
PlotIndexSetInteger(sHHBufferPlotIndex, PLOT_DRAW_TYPE, zoneDrawType);
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
ArraySetAsSeries(sLLBuffer, true);
|
||||
SetIndexBuffer(sLLBufferIndex, sLLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(sLLBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(sLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
||||
PlotIndexSetInteger(sLLBufferPlotIndex, PLOT_DRAW_TYPE, zoneDrawType);
|
||||
|
||||
//
|
||||
// MEDIUM Buffer ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
ArraySetAsSeries(mHHBuffer, true);
|
||||
SetIndexBuffer(mHHBufferIndex, mHHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(mHHBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(mHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
||||
PlotIndexSetInteger(mHHBufferPlotIndex, PLOT_DRAW_TYPE, zoneDrawType);
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
ArraySetAsSeries(mLLBuffer, true);
|
||||
SetIndexBuffer(mLLBufferIndex, mLLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(mLLBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(mLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
||||
PlotIndexSetInteger(mLLBufferPlotIndex, PLOT_DRAW_TYPE, zoneDrawType);
|
||||
|
||||
//
|
||||
// LONG Buffer ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
ArraySetAsSeries(lHHBuffer, true);
|
||||
SetIndexBuffer(lHHBufferIndex, lHHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(lHHBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(lHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
||||
PlotIndexSetInteger(lHHBufferPlotIndex, PLOT_DRAW_TYPE, zoneDrawType);
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
ArraySetAsSeries(lLLBuffer, true);
|
||||
SetIndexBuffer(lLLBufferIndex, lLLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(lLLBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(lLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
||||
PlotIndexSetInteger(lLLBufferPlotIndex, PLOT_DRAW_TYPE, zoneDrawType);
|
||||
|
||||
//
|
||||
// HIND Buffer ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
ArraySetAsSeries(hHHBuffer, true);
|
||||
SetIndexBuffer(hHHBufferIndex, hHHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(hHHBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(hHHBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
||||
PlotIndexSetInteger(hHHBufferPlotIndex, PLOT_DRAW_TYPE, zoneDrawType);
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
ArraySetAsSeries(hLLBuffer, true);
|
||||
SetIndexBuffer(hLLBufferIndex, hLLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(hLLBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(hLLBufferPlotIndex, PLOT_SHOW_DATA, showLevels);
|
||||
PlotIndexSetInteger(hLLBufferPlotIndex, PLOT_DRAW_TYPE, zoneDrawType);
|
||||
}
|
||||
|
||||
//
|
||||
// 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
|
||||
)
|
||||
{
|
||||
//
|
||||
// Calculate ...
|
||||
|
||||
//
|
||||
double rColorIDX = 1;
|
||||
double sColorIDX = 1;
|
||||
|
||||
//
|
||||
// SHORT ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
int sHHIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhMode,
|
||||
shortLength,
|
||||
bar_index);
|
||||
double sHHValue = GetAppliedPrice(
|
||||
sHHIndex,
|
||||
hhMode);
|
||||
|
||||
//
|
||||
sHHBuffer[bar_index] = sHHValue;
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
int sLLIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llMode,
|
||||
shortLength,
|
||||
bar_index);
|
||||
double sLLValue = GetAppliedPrice(
|
||||
sLLIndex,
|
||||
llMode);
|
||||
|
||||
//
|
||||
sLLBuffer[bar_index] = sLLValue;
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
int mHHIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhMode,
|
||||
mediumLength,
|
||||
bar_index);
|
||||
double mHHValue = GetAppliedPrice(
|
||||
mHHIndex,
|
||||
hhMode);
|
||||
|
||||
//
|
||||
mHHBuffer[bar_index] = mHHValue;
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
int mLLIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llMode,
|
||||
mediumLength,
|
||||
bar_index);
|
||||
double mLLValue = GetAppliedPrice(
|
||||
mLLIndex,
|
||||
llMode);
|
||||
|
||||
//
|
||||
mLLBuffer[bar_index] = mLLValue;
|
||||
|
||||
//
|
||||
// LONG ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
int lHHIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhMode,
|
||||
longLength,
|
||||
bar_index);
|
||||
double lHHValue = GetAppliedPrice(
|
||||
lHHIndex,
|
||||
hhMode);
|
||||
|
||||
//
|
||||
lHHBuffer[bar_index] = lHHValue;
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
int lLLIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llMode,
|
||||
longLength,
|
||||
bar_index);
|
||||
double lLLValue = GetAppliedPrice(
|
||||
lLLIndex,
|
||||
llMode);
|
||||
|
||||
//
|
||||
lLLBuffer[bar_index] = lLLValue;
|
||||
|
||||
//
|
||||
// HIND ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
int hHHIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhMode,
|
||||
hindLength,
|
||||
bar_index);
|
||||
double hHHValue = GetAppliedPrice(
|
||||
hHHIndex,
|
||||
hhMode);
|
||||
|
||||
//
|
||||
hHHBuffer[bar_index] = hHHValue;
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
int hLLIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llMode,
|
||||
hindLength,
|
||||
bar_index);
|
||||
double hLLValue = GetAppliedPrice(
|
||||
hLLIndex,
|
||||
llMode);
|
||||
|
||||
//
|
||||
hLLBuffer[bar_index] = hLLValue;
|
||||
|
||||
//
|
||||
// RESISTANCE SUPPORT ...
|
||||
|
||||
//
|
||||
// RESISTANCE ...
|
||||
double rValue = (sHHValue + mHHValue + lHHValue + hHHValue) / 4;
|
||||
rBuffer[bar_index] = rValue;
|
||||
|
||||
//
|
||||
// SUPPORT ...
|
||||
double sValue = (sLLValue + mLLValue + lLLValue + hLLValue) / 4;
|
||||
sBuffer[bar_index] = sValue;
|
||||
|
||||
//
|
||||
// PEAKS and VALES ...
|
||||
|
||||
//
|
||||
// PEAKS ...
|
||||
bool isPeak = rValue == hHHValue &&
|
||||
hHHValue == lHHValue &&
|
||||
lHHValue == mHHValue &&
|
||||
mHHValue == sHHValue;
|
||||
//
|
||||
if (isPeak && lastPeak != rValue)
|
||||
{
|
||||
//
|
||||
if (showPeaksAndVales)
|
||||
{
|
||||
rColorIDX = 0;
|
||||
}
|
||||
|
||||
//
|
||||
lastPeak = rValue;
|
||||
peaksBuffer[bar_index] = lastPeak;
|
||||
}
|
||||
else
|
||||
{
|
||||
peaksBuffer[bar_index] = lastPeak;
|
||||
}
|
||||
|
||||
//
|
||||
// VALES ...
|
||||
bool isVale = sValue == hLLValue &&
|
||||
hLLValue == lLLValue &&
|
||||
lLLValue == mLLValue &&
|
||||
mLLValue == sLLValue;
|
||||
|
||||
//
|
||||
if (isVale && lastVale != sValue)
|
||||
{
|
||||
//
|
||||
if (showPeaksAndVales)
|
||||
{
|
||||
sColorIDX = 0;
|
||||
}
|
||||
|
||||
//
|
||||
lastVale = sValue;
|
||||
valesBuffer[bar_index] = lastVale;
|
||||
}
|
||||
else
|
||||
{
|
||||
valesBuffer[bar_index] = lastVale;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Default Colors ...
|
||||
|
||||
//
|
||||
rColorBuffer[bar_index] = rColorIDX;
|
||||
sColorBuffer[bar_index] = sColorIDX;
|
||||
|
||||
//
|
||||
// Calculate Fibonacci ...
|
||||
double upPrice = peaksBuffer[bar_index];
|
||||
double downPrice = valesBuffer[bar_index];
|
||||
|
||||
//
|
||||
// Level 1 ...
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
double fibLevel1BullishValue = GetFibonacciLevel(
|
||||
upPrice,
|
||||
downPrice,
|
||||
fiboLevel1,
|
||||
1);
|
||||
fl1Buffer[bar_index] = fibLevel1BullishValue;
|
||||
double fl1BullColorIdx = showFibo1Levels ? 1 : 0;
|
||||
fl1ColorBuffer[bar_index] = fl1BullColorIdx;
|
||||
|
||||
// //
|
||||
// // Bearish ...
|
||||
// double fibLevel1BearishValue = GetFibonacciLevel(
|
||||
// upPrice,
|
||||
// downPrice,
|
||||
// fiboLevel1,
|
||||
// 0);
|
||||
// fl1BearBuffer[bar_index] = fibLevel1BearishValue;
|
||||
// double fl1BearColorIdx = showFibo1Levels ? 1 : 0;
|
||||
// fl1BearColorBuffer[bar_index] = fl1BearColorIdx;
|
||||
|
||||
//
|
||||
// Level 2 ...
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
double fibLevel2BullishValue = GetFibonacciLevel(
|
||||
upPrice,
|
||||
downPrice,
|
||||
fiboLevel2,
|
||||
1);
|
||||
fl2Buffer[bar_index] = fibLevel2BullishValue;
|
||||
double fl2BullColorIdx = showFibo2Levels ? 1 : 0;
|
||||
fl2ColorBuffer[bar_index] = fl2BullColorIdx;
|
||||
|
||||
// //
|
||||
// // Bearish ...
|
||||
// double fibLevel2BearishValue = GetFibonacciLevel(
|
||||
// upPrice,
|
||||
// downPrice,
|
||||
// fiboLevel2,
|
||||
// 0);
|
||||
// fl2BearBuffer[bar_index] = fibLevel2BearishValue;
|
||||
// double fl2BearColorIdx = showFibo2Levels ? 1 : 0;
|
||||
// fl2BearColorBuffer[bar_index] = fl2BearColorIdx;
|
||||
|
||||
//
|
||||
// Level 3 ...
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
double fibLevel3BullishValue = GetFibonacciLevel(
|
||||
upPrice,
|
||||
downPrice,
|
||||
fiboLevel3,
|
||||
1);
|
||||
fl3Buffer[bar_index] = fibLevel3BullishValue;
|
||||
double fl3BullColorIdx = showFibo3Levels ? 1 : 0;
|
||||
fl3ColorBuffer[bar_index] = fl3BullColorIdx;
|
||||
|
||||
// //
|
||||
// // Bearish ...
|
||||
// double fibLevel3BearishValue = GetFibonacciLevel(
|
||||
// upPrice,
|
||||
// downPrice,
|
||||
// fiboLevel3,
|
||||
// 0);
|
||||
// fl3BearBuffer[bar_index] = fibLevel3BearishValue;
|
||||
// double fl3BearColorIdx = showFibo3Levels ? 1 : 0;
|
||||
// fl3BearColorBuffer[bar_index] = fl3BearColorIdx;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,437 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ----------------------------------------------------
|
||||
// Name: X121_XSSLC
|
||||
// Description: SSL Channel 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_XSSLC Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "X121_XSSLC"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Market";
|
||||
input int length = 36; // Length
|
||||
|
||||
//
|
||||
input group "Calculation";
|
||||
input ENUM_MA_METHOD method = MODE_SMA; // Method
|
||||
input ENUM_APPLIED_PRICE upAppliedTo = PRICE_HIGH; // Up Applied To
|
||||
input ENUM_APPLIED_PRICE downAppliedTo = PRICE_LOW; // Down Applied To
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showUp = true; // Show Up
|
||||
input bool showDown = true; // Show Down
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 5
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
// PLOTTED Buffers ...
|
||||
|
||||
//
|
||||
#define upBufferIndex 0
|
||||
double upBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XSSLC Up"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrLime
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
#define downBufferIndex 1
|
||||
double downBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121_XSSLC Down"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
#define upMaBufferIndex 2
|
||||
double upMaBuffer[];
|
||||
|
||||
//
|
||||
#define downMaBufferIndex 3
|
||||
double downMaBuffer[];
|
||||
|
||||
//
|
||||
#define kpiBufferIndex 4
|
||||
double kpiBuffer[];
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int upHandler = INVALID_HANDLE;
|
||||
int downHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Initialize Requierd Handlers ...
|
||||
upHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
0,
|
||||
method,
|
||||
upAppliedTo);
|
||||
downHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
0,
|
||||
method,
|
||||
downAppliedTo);
|
||||
if (upHandler == INVALID_HANDLE || downHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
string msg = "Error in Initilizing Indicator ...";
|
||||
Print(msg);
|
||||
|
||||
//
|
||||
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
|
||||
|
||||
//
|
||||
// Release Indicators ...
|
||||
IndicatorRelease(upHandler);
|
||||
IndicatorRelease(downHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// 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;
|
||||
|
||||
//
|
||||
// Check Calculated Bars ...
|
||||
int upCalculatedBars = BarsCalculated(upHandler);
|
||||
int downCalculatedBars = BarsCalculated(downHandler);
|
||||
if (upCalculatedBars < maxLength ||
|
||||
downCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
int copiedUps = CopyBuffer(upHandler, 0, 0, limit, upMaBuffer);
|
||||
int copiedDowns = CopyBuffer(downHandler, 0, 0, limit, downMaBuffer);
|
||||
if (copiedUps <= 0 ||
|
||||
copiedDowns <= 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
CalculateBuffers(i, limit, rates_total, prev_calculated, close);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
(length > 2)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(result, length);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// UP ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE upDrawType = showUp ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
|
||||
ArraySetAsSeries(upBuffer, true);
|
||||
SetIndexBuffer(upBufferIndex, upBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(upBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(upBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(upBufferIndex, PLOT_DRAW_TYPE, upDrawType);
|
||||
|
||||
//
|
||||
// DOWN ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE downDrawType = showDown ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
|
||||
ArraySetAsSeries(downBuffer, true);
|
||||
SetIndexBuffer(downBufferIndex, downBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(downBufferIndex, PLOT_SHOW_DATA, showDown);
|
||||
PlotIndexSetInteger(downBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(downBufferIndex, PLOT_DRAW_TYPE, downDrawType);
|
||||
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
// UP MA ...
|
||||
ArraySetAsSeries(upMaBuffer, true);
|
||||
SetIndexBuffer(upMaBufferIndex, upMaBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// DOWN MA ...
|
||||
ArraySetAsSeries(downMaBuffer, true);
|
||||
SetIndexBuffer(downMaBufferIndex, downMaBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// KPI ...
|
||||
ArraySetAsSeries(kpiBuffer, true);
|
||||
SetIndexBuffer(kpiBufferIndex, kpiBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// 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 limit,
|
||||
int ratesTotal,
|
||||
int prevCalculated,
|
||||
const double &close[])
|
||||
{
|
||||
//
|
||||
double upMaValue = upMaBuffer[bar_index];
|
||||
double downMaValue = downMaBuffer[bar_index];
|
||||
|
||||
//
|
||||
double closeValue = close[bar_index];
|
||||
|
||||
//
|
||||
double kpiValue;
|
||||
if (closeValue > upMaValue) {
|
||||
kpiValue = 1;
|
||||
} else if (closeValue < downMaValue) {
|
||||
kpiValue = -1;
|
||||
} else {
|
||||
kpiValue = kpiBuffer[bar_index + 1];
|
||||
}
|
||||
|
||||
//
|
||||
kpiBuffer[bar_index] = kpiValue;
|
||||
|
||||
//
|
||||
double upValue = kpiValue < 0 ? downMaValue : upMaValue;
|
||||
upBuffer[bar_index] = upValue;
|
||||
|
||||
//
|
||||
double downValue = kpiValue < 0 ? upMaValue : downMaValue;
|
||||
downBuffer[bar_index] = downValue;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,580 @@
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121_XSTR
|
||||
// Description: Super Trend Indicator ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121_XAMA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
#define ShortName "X121_XSTR"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "ATR";
|
||||
input int atrLength = 14; // Length
|
||||
input double atrMultiplier = 3.0; // Multiplier
|
||||
input ENUM_APPLIED_PRICE atrAppliedTo = PRICE_MEDIAN; // Applied To
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
input bool showTrends = true; // Show Trends
|
||||
input bool fillTrends = true; // Fill Trends
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 9
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
#define fillUpBufferIndex 0
|
||||
double fillUpBuffer[];
|
||||
|
||||
#define fillDownBufferIndex 1
|
||||
double fillDownBuffer[];
|
||||
|
||||
//
|
||||
#define fillingPlotBufferIndex 0
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XSTR Filling"
|
||||
#property indicator_type1 DRAW_FILLING
|
||||
#property indicator_color1 clrBisque, clrPaleGreen
|
||||
|
||||
//
|
||||
#define mainBufferIndex 2
|
||||
#define mainPlotBufferIndex 1
|
||||
double mainBuffer[];
|
||||
|
||||
//
|
||||
#define mainColorBufferIndex 3
|
||||
double mainColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121_XSTR"
|
||||
#property indicator_type2 DRAW_COLOR_LINE
|
||||
#property indicator_color2 CLR_NONE, clrGreen, clrDarkRed
|
||||
#property indicator_style2 STYLE_DOT
|
||||
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
#define atrBufferIndex 4
|
||||
double atrBuffer[];
|
||||
|
||||
//
|
||||
#define trendBufferIndex 5
|
||||
double trendBuffer[];
|
||||
|
||||
//
|
||||
#define upBufferIndex 6
|
||||
double upBuffer[];
|
||||
|
||||
//
|
||||
#define downBufferIndex 7
|
||||
double downBuffer[];
|
||||
|
||||
//
|
||||
#define priceBufferIndex 8
|
||||
double priceBuffer[];
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int atrHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
int changeOfTrend;
|
||||
int startBearishTrend;
|
||||
int startBullishTrend;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
atrHandler = iATR(
|
||||
_Symbol,
|
||||
_Period,
|
||||
atrLength);
|
||||
if (atrHandler == INVALID_HANDLE)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
IndicatorRelease(atrHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
int numOfRequiredAtrs;
|
||||
if (prev_calculated > rates_total || prev_calculated < 0)
|
||||
{
|
||||
numOfRequiredAtrs = rates_total;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
numOfRequiredAtrs = rates_total - prev_calculated;
|
||||
if (prev_calculated > 0)
|
||||
{
|
||||
numOfRequiredAtrs++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Checking for stop ...
|
||||
if (IsStopped())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Number of items Copy or not ...
|
||||
int copiedATRs = CopyBuffer(atrHandler, 0, 0, numOfRequiredAtrs, atrBuffer);
|
||||
if (copiedATRs <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
int limit;
|
||||
|
||||
//
|
||||
// checking for the limit start of calculation of an indicator ...
|
||||
if (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
{
|
||||
//
|
||||
// starting index for calculation of all bars ...
|
||||
limit = maxLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// starting number for calculation of new bars
|
||||
limit = prev_calculated - 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
// Calculated Price ...
|
||||
double price = getPrice(
|
||||
atrAppliedTo,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
i);
|
||||
// price = (high[i] + low[i]) / 2;
|
||||
priceBuffer[i] = price;
|
||||
|
||||
//
|
||||
double atr = atrBuffer[i];
|
||||
|
||||
//
|
||||
// Up ...
|
||||
upBuffer[i] = price + (atrMultiplier * atr);
|
||||
|
||||
//
|
||||
// Down ...
|
||||
downBuffer[i] = price - (atrMultiplier * atr);
|
||||
|
||||
//
|
||||
if (close[i] > upBuffer[i - 1])
|
||||
{
|
||||
//
|
||||
trendBuffer[i] = 1;
|
||||
if (trendBuffer[i - 1] == -1)
|
||||
{
|
||||
changeOfTrend = 1;
|
||||
}
|
||||
}
|
||||
else if (close[i] < downBuffer[i - 1])
|
||||
{
|
||||
//
|
||||
trendBuffer[i] = -1;
|
||||
if (trendBuffer[i - 1] == 1)
|
||||
{
|
||||
changeOfTrend = 1;
|
||||
}
|
||||
}
|
||||
else if (trendBuffer[i - 1] == 1)
|
||||
{
|
||||
//
|
||||
trendBuffer[i] = 1;
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
else if (trendBuffer[i - 1] == -1)
|
||||
{
|
||||
//
|
||||
trendBuffer[i] = -1;
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Down Trend Starting ...
|
||||
if (trendBuffer[i] < 0 && trendBuffer[i - 1] > 0)
|
||||
{
|
||||
startBearishTrend = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
startBearishTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Up Trend Starting ...
|
||||
if (trendBuffer[i] > 0 && trendBuffer[i - 1] < 0)
|
||||
{
|
||||
startBullishTrend = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
startBullishTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
if (trendBuffer[i] > 0 && downBuffer[i] < downBuffer[i - 1])
|
||||
{
|
||||
downBuffer[i] = downBuffer[i - 1];
|
||||
}
|
||||
|
||||
//
|
||||
if (trendBuffer[i] < 0 && upBuffer[i] > upBuffer[i - 1])
|
||||
{
|
||||
upBuffer[i] = upBuffer[i - 1];
|
||||
}
|
||||
|
||||
//
|
||||
if (startBearishTrend == 1)
|
||||
{
|
||||
upBuffer[i] = priceBuffer[i] + (atrMultiplier * atr);
|
||||
}
|
||||
|
||||
//
|
||||
if (startBullishTrend == 1)
|
||||
{
|
||||
downBuffer[i] = priceBuffer[i] - (atrMultiplier * atr);
|
||||
}
|
||||
|
||||
//
|
||||
// Draw the indicator ...
|
||||
|
||||
//
|
||||
double colorIDX = 0;
|
||||
mainColorBuffer[i] = colorIDX;
|
||||
|
||||
//
|
||||
if (trendBuffer[i] == 1)
|
||||
{
|
||||
//
|
||||
mainBuffer[i] = downBuffer[i];
|
||||
if (changeOfTrend == 1)
|
||||
{
|
||||
mainBuffer[i - 1] = mainBuffer[i - 2];
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
colorIDX = 1;
|
||||
}
|
||||
else if (trendBuffer[i] == -1)
|
||||
{
|
||||
//
|
||||
mainBuffer[i] = upBuffer[i];
|
||||
if (changeOfTrend == 1)
|
||||
{
|
||||
//
|
||||
mainBuffer[i - 1] = mainBuffer[i - 2];
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
colorIDX = 2;
|
||||
}
|
||||
|
||||
//
|
||||
if (showTrends)
|
||||
{
|
||||
mainColorBuffer[i] = colorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
// Filling ...
|
||||
if (fillTrends)
|
||||
{
|
||||
//
|
||||
fillUpBuffer[i] = mainBuffer[i];
|
||||
fillDownBuffer[i] = close[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
fillUpBuffer[i] = EMPTY_VALUE;
|
||||
fillDownBuffer[i] = EMPTY_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result =
|
||||
//
|
||||
atrLength >= 2
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = atrLength;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// PLOT Buffers ...
|
||||
|
||||
//
|
||||
// FILLINGS ...
|
||||
SetIndexBuffer(fillUpBufferIndex, fillUpBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(fillDownBufferIndex, fillDownBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fillingPlotBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// MAIN ...
|
||||
SetIndexBuffer(mainBufferIndex, mainBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(mainPlotBufferIndex, PLOT_SHOW_DATA, showTrends);
|
||||
SetIndexBuffer(mainColorBufferIndex, mainColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// TREND ...
|
||||
SetIndexBuffer(trendBufferIndex, trendBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// UP ...
|
||||
SetIndexBuffer(upBufferIndex, upBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// DOWN ...
|
||||
SetIndexBuffer(downBufferIndex, downBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// PRICE ...
|
||||
SetIndexBuffer(priceBufferIndex, priceBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// TEMPLATE Function ...
|
||||
|
||||
template <typename T>
|
||||
double getPrice(ENUM_APPLIED_PRICE tprice, T &open[], T &high[], T &low[], T &close[], int i)
|
||||
{
|
||||
switch (tprice)
|
||||
{
|
||||
case PRICE_CLOSE:
|
||||
return (close[i]);
|
||||
case PRICE_OPEN:
|
||||
return (open[i]);
|
||||
case PRICE_HIGH:
|
||||
return (high[i]);
|
||||
case PRICE_LOW:
|
||||
return (low[i]);
|
||||
case PRICE_MEDIAN:
|
||||
return ((high[i] + low[i]) / 2.0);
|
||||
case PRICE_TYPICAL:
|
||||
return ((high[i] + low[i] + close[i]) / 3.0);
|
||||
case PRICE_WEIGHTED:
|
||||
return ((high[i] + low[i] + close[i] + close[i]) / 4.0);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,354 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121_XTM
|
||||
// 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_XTM Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
#define ShortName "X121_XTM"
|
||||
|
||||
//
|
||||
// XTM Indicator States ...
|
||||
enum ENUM_X_XTM_STATES
|
||||
{
|
||||
X_XTM_BULLISH = 0,
|
||||
X_XTM_BEARISH = 2,
|
||||
X_XTM_NEUTURAL = 1,
|
||||
};
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Makret";
|
||||
input int length = 35; // Length
|
||||
input int shift = 0; // Shift
|
||||
|
||||
//
|
||||
input group "Calculations";
|
||||
input ENUM_MA_METHOD method = MODE_SMA; // Method
|
||||
input ENUM_APPLIED_PRICE appliedTo = PRICE_LOW; // Applied To
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showLine = true; // Show Line
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
// maBuffer ...
|
||||
#define maBufferIndex 0
|
||||
double maBuffer[];
|
||||
|
||||
#define maColorBufferIndex 1
|
||||
double maColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121_XTM"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 clrLime, clrGray, clrRed
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int maHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Initializing MA Handler ...
|
||||
maHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
shift,
|
||||
method,
|
||||
appliedTo);
|
||||
if (maHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
string message = "Error Initializing Ma Handler ...";
|
||||
Print(message);
|
||||
|
||||
//
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
IndicatorRelease(maHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// 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;
|
||||
|
||||
//
|
||||
// Check Calculated Bars ...
|
||||
int maCalculatedBars = BarsCalculated(maHandler);
|
||||
if (maCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
int copiedMas = CopyBuffer(maHandler, 0, 0, limit, maBuffer);
|
||||
if (copiedMas <= 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
// Do Buffers Calculation ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (length >= 2)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = length;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
ENUM_DRAW_TYPE drawType = showLine ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Ma Buffer ...
|
||||
ArraySetAsSeries(maBuffer, true);
|
||||
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(maBufferIndex, PLOT_DRAW_TYPE, drawType);
|
||||
PlotIndexSetInteger(maBufferIndex, PLOT_SHOW_DATA, showLine);
|
||||
|
||||
//
|
||||
// Ma Color Buffer ...
|
||||
ArraySetAsSeries(maColorBuffer, true);
|
||||
SetIndexBuffer(maColorBufferIndex, maColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(int bar_index)
|
||||
{
|
||||
//
|
||||
// Requirements ...
|
||||
XOHCL candle = GetCandle(bar_index);
|
||||
|
||||
//
|
||||
double maValue = maBuffer[bar_index];
|
||||
|
||||
//
|
||||
double lineColorIndex =
|
||||
maValue < candle.low ? 0 : maValue > candle.high ? 2
|
||||
: 1;
|
||||
|
||||
//
|
||||
// Set Ma Buffer Color Index ...
|
||||
maColorBuffer[bar_index] = lineColorIndex;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,775 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121_XCHNL
|
||||
// Description: XCHL Channel 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_XCHNL Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
#define ShortName "X121_XCHNL"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Includes Draw Library ...
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XSCHULL Class Definition ...
|
||||
//
|
||||
|
||||
//
|
||||
// END XSCHULL Class Definition ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Makret Cycles";
|
||||
input int shortLength = 9; // Short Length
|
||||
input int mediumLength = 17; // Medium Length
|
||||
input int longLength = 26; // Long Length
|
||||
input int hindLength = 35; // Hind Length
|
||||
|
||||
//
|
||||
input group "Trend";
|
||||
input int numOfShoulder = 10; // Number of Shoulders for Swings
|
||||
|
||||
//
|
||||
input group "Detection Modes";
|
||||
input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method
|
||||
input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showTrend = false; // Show Trend
|
||||
input bool showSRs = false; // Show Support and Resistance
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// PEKSANDVALES ...
|
||||
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 8
|
||||
#property indicator_plots 0
|
||||
|
||||
#define sHHBufferIndex 0
|
||||
#define sLLBufferIndex 1
|
||||
#define mHHBufferIndex 2
|
||||
#define mLLBufferIndex 3
|
||||
#define lHHBufferIndex 4
|
||||
#define lLLBufferIndex 5
|
||||
#define hHHBufferIndex 6
|
||||
#define hLLBufferIndex 7
|
||||
|
||||
double sHHBuffer[];
|
||||
double sLLBuffer[];
|
||||
double mHHBuffer[];
|
||||
double mLLBuffer[];
|
||||
double lHHBuffer[];
|
||||
double lLLBuffer[];
|
||||
double hHHBuffer[];
|
||||
double hLLBuffer[];
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// 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();
|
||||
|
||||
//
|
||||
// Make an Instance of Hull Class ...
|
||||
|
||||
//
|
||||
// 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 mPeriod 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
|
||||
|
||||
//
|
||||
RemoveDraws(drawPrefix);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
limit = prev_calculated - 1;
|
||||
if (limit < 0)
|
||||
{
|
||||
limit = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
// Validate Peaks and Vales ...
|
||||
(shortLength > 2 &&
|
||||
mediumLength > shortLength &&
|
||||
longLength > mediumLength &&
|
||||
hindLength > longLength)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Peaks and Vales ...
|
||||
result = MathMax(shortLength, mediumLength);
|
||||
result = MathMax(result, longLength);
|
||||
result = MathMax(result, hindLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
ArraySetAsSeries(sHHBuffer, true);
|
||||
SetIndexBuffer(sHHBufferIndex, sHHBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(sLLBuffer, true);
|
||||
SetIndexBuffer(sLLBufferIndex, sLLBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(mHHBuffer, true);
|
||||
SetIndexBuffer(mHHBufferIndex, mHHBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(mLLBuffer, true);
|
||||
SetIndexBuffer(mLLBufferIndex, mLLBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(lHHBuffer, true);
|
||||
SetIndexBuffer(lHHBufferIndex, lHHBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(lLLBuffer, true);
|
||||
SetIndexBuffer(lLLBufferIndex, lLLBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(hHHBuffer, true);
|
||||
SetIndexBuffer(hHHBufferIndex, hHHBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(hLLBuffer, true);
|
||||
SetIndexBuffer(hLLBufferIndex, hLLBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index // Selected Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// Calculate ...
|
||||
|
||||
//
|
||||
// SHORT ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
int sHHIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhMode,
|
||||
shortLength,
|
||||
bar_index);
|
||||
double sHHValue = GetAppliedPrice(
|
||||
sHHIndex,
|
||||
hhMode);
|
||||
|
||||
//
|
||||
sHHBuffer[bar_index] = sHHValue;
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
int sLLIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llMode,
|
||||
shortLength,
|
||||
bar_index);
|
||||
double sLLValue = GetAppliedPrice(
|
||||
sLLIndex,
|
||||
llMode);
|
||||
|
||||
//
|
||||
sLLBuffer[bar_index] = sLLValue;
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
int mHHIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhMode,
|
||||
mediumLength,
|
||||
bar_index);
|
||||
double mHHValue = GetAppliedPrice(
|
||||
mHHIndex,
|
||||
hhMode);
|
||||
|
||||
//
|
||||
mHHBuffer[bar_index] = mHHValue;
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
int mLLIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llMode,
|
||||
mediumLength,
|
||||
bar_index);
|
||||
double mLLValue = GetAppliedPrice(
|
||||
mLLIndex,
|
||||
llMode);
|
||||
|
||||
//
|
||||
mLLBuffer[bar_index] = mLLValue;
|
||||
|
||||
//
|
||||
// LONG ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
int lHHIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhMode,
|
||||
longLength,
|
||||
bar_index);
|
||||
double lHHValue = GetAppliedPrice(
|
||||
lHHIndex,
|
||||
hhMode);
|
||||
|
||||
//
|
||||
lHHBuffer[bar_index] = lHHValue;
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
int lLLIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llMode,
|
||||
longLength,
|
||||
bar_index);
|
||||
double lLLValue = GetAppliedPrice(
|
||||
lLLIndex,
|
||||
llMode);
|
||||
|
||||
//
|
||||
lLLBuffer[bar_index] = lLLValue;
|
||||
|
||||
//
|
||||
// HIND ...
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
int hHHIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhMode,
|
||||
hindLength,
|
||||
bar_index);
|
||||
double hHHValue = GetAppliedPrice(
|
||||
hHHIndex,
|
||||
hhMode);
|
||||
|
||||
//
|
||||
hHHBuffer[bar_index] = hHHValue;
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
int hLLIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llMode,
|
||||
hindLength,
|
||||
bar_index);
|
||||
double hLLValue = GetAppliedPrice(
|
||||
hLLIndex,
|
||||
llMode);
|
||||
|
||||
//
|
||||
hLLBuffer[bar_index] = hLLValue;
|
||||
|
||||
//
|
||||
// Find Swings ...
|
||||
|
||||
//
|
||||
// High ...
|
||||
int hSwing1 = FindSwing(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_HIGH,
|
||||
numOfShoulder,
|
||||
bar_index + 1);
|
||||
|
||||
int hSwing2 = FindSwing(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_HIGH,
|
||||
numOfShoulder,
|
||||
hSwing1 + 1);
|
||||
|
||||
//
|
||||
// High ...
|
||||
int hSwing3 = FindSwing(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_HIGH,
|
||||
numOfShoulder,
|
||||
hSwing2 + 1);
|
||||
|
||||
// int hSwing4 = FindSwing(
|
||||
// _Symbol,
|
||||
// _Period,
|
||||
// MODE_HIGH,
|
||||
// numOfShoulder,
|
||||
// hSwing3 + 1);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
int lSwing1 = FindSwing(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_LOW,
|
||||
numOfShoulder,
|
||||
bar_index + 1);
|
||||
|
||||
int lSwing2 = FindSwing(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_LOW,
|
||||
numOfShoulder,
|
||||
lSwing1 + 1);
|
||||
|
||||
int lSwing3 = FindSwing(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_LOW,
|
||||
numOfShoulder,
|
||||
lSwing2 + 1);
|
||||
|
||||
// int lSwing4 = FindSwing(
|
||||
// _Symbol,
|
||||
// _Period,
|
||||
// MODE_LOW,
|
||||
// numOfShoulder,
|
||||
// lSwing3 + 1);
|
||||
|
||||
//
|
||||
if (bar_index < 50)
|
||||
{
|
||||
|
||||
//
|
||||
bool isStrongResistance =
|
||||
//
|
||||
hHHBuffer[bar_index + 1] == hHHBuffer[bar_index + 2] &&
|
||||
hHHBuffer[bar_index + 2] == hHHBuffer[bar_index + 3] &&
|
||||
//
|
||||
lHHBuffer[bar_index + 1] == lHHBuffer[bar_index + 2] &&
|
||||
lHHBuffer[bar_index + 2] == lHHBuffer[bar_index + 3] &&
|
||||
//
|
||||
mHHBuffer[bar_index + 1] == mHHBuffer[bar_index + 2] &&
|
||||
mHHBuffer[bar_index + 2] == mHHBuffer[bar_index + 3] &&
|
||||
//
|
||||
sHHBuffer[bar_index + 1] == sHHBuffer[bar_index + 2] &&
|
||||
sHHBuffer[bar_index + 2] == sHHBuffer[bar_index + 3]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isStrongSupport =
|
||||
//
|
||||
hLLBuffer[bar_index + 1] == hLLBuffer[bar_index + 2] &&
|
||||
hLLBuffer[bar_index + 2] == hLLBuffer[bar_index + 3] &&
|
||||
//
|
||||
lLLBuffer[bar_index + 1] == lLLBuffer[bar_index + 2] &&
|
||||
lLLBuffer[bar_index + 2] == lLLBuffer[bar_index + 3] &&
|
||||
//
|
||||
mLLBuffer[bar_index + 1] == mLLBuffer[bar_index + 2] &&
|
||||
mLLBuffer[bar_index + 2] == mLLBuffer[bar_index + 3] &&
|
||||
//
|
||||
sLLBuffer[bar_index + 1] == sLLBuffer[bar_index + 2] &&
|
||||
sLLBuffer[bar_index + 2] == sLLBuffer[bar_index + 3]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (isStrongResistance && showSRs)
|
||||
{
|
||||
//
|
||||
DrawSupportResistance(
|
||||
"R",
|
||||
clrRed,
|
||||
sHHBuffer[bar_index + 3],
|
||||
bar_index + 3);
|
||||
}
|
||||
|
||||
//
|
||||
if (isStrongSupport && showSRs)
|
||||
{
|
||||
//
|
||||
DrawSupportResistance(
|
||||
"S",
|
||||
clrGreen,
|
||||
sLLBuffer[bar_index + 3],
|
||||
bar_index + 3);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (showTrend && bar_index < 20)
|
||||
{
|
||||
//
|
||||
DrawSwing(
|
||||
"High1",
|
||||
MODE_HIGH,
|
||||
clrAqua,
|
||||
hSwing1,
|
||||
hSwing2);
|
||||
|
||||
//
|
||||
DrawSwing(
|
||||
"Low1",
|
||||
MODE_LOW,
|
||||
clrAqua,
|
||||
lSwing1,
|
||||
lSwing2);
|
||||
|
||||
//
|
||||
DrawSwing(
|
||||
"High2",
|
||||
MODE_HIGH,
|
||||
clrMagenta,
|
||||
hSwing2,
|
||||
hSwing3);
|
||||
|
||||
//
|
||||
DrawSwing(
|
||||
"Low2",
|
||||
MODE_LOW,
|
||||
clrMagenta,
|
||||
lSwing2,
|
||||
lSwing3);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
void DrawSwing(
|
||||
string prefix, // Prefix ...
|
||||
ENUM_SERIESMODE mode, // Swing Mode ...
|
||||
color swingColor, // Color ...
|
||||
int index1, // Index 1 ...
|
||||
int index2 // Index 2 ...
|
||||
)
|
||||
{
|
||||
//
|
||||
if (mode != MODE_HIGH && mode != MODE_LOW)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL c1 = GetCandle(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index1);
|
||||
|
||||
//
|
||||
datetime time1 = GetCandleTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index1);
|
||||
|
||||
//
|
||||
XOHCL c2 = GetCandle(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index2);
|
||||
|
||||
//
|
||||
datetime time2 = GetCandleTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index2);
|
||||
|
||||
//
|
||||
double value1 = -1;
|
||||
double value2 = -1;
|
||||
|
||||
//
|
||||
switch (mode)
|
||||
{
|
||||
//
|
||||
case MODE_HIGH:
|
||||
value1 = c1.high;
|
||||
value2 = c2.high;
|
||||
break;
|
||||
|
||||
//
|
||||
case MODE_LOW:
|
||||
value1 = c1.low;
|
||||
value2 = c2.low;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
if (value1 == -1 || value2 == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
long chartId = ChartID();
|
||||
string tlName = prefix + "_" + "TrendLine";
|
||||
|
||||
// //
|
||||
// if (IsDrawExists(tlName)) {
|
||||
// RemoveDraw(tlName);
|
||||
// }
|
||||
|
||||
//
|
||||
DrawTrendLine(
|
||||
chartId,
|
||||
tlName,
|
||||
0,
|
||||
time2,
|
||||
value2,
|
||||
time1,
|
||||
value1,
|
||||
swingColor,
|
||||
STYLE_DOT,
|
||||
3,
|
||||
false,
|
||||
false,
|
||||
true);
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Support and Resistance ...
|
||||
void DrawSupportResistance(
|
||||
string prefix, // Prefix ...
|
||||
color lColor, // Color ...
|
||||
double price, // Support or Resistance price ...
|
||||
int bar_index // Start Bar Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
datetime time1 = GetCandleTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
datetime time2 = GetCandleTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index - 1);
|
||||
|
||||
//
|
||||
long chartId = ChartID();
|
||||
string tlName = prefix + "_" + "TL" + "_" + (string)(NormalizePrice(price, _Symbol));
|
||||
|
||||
//
|
||||
DrawTrendLine(
|
||||
chartId,
|
||||
tlName,
|
||||
0,
|
||||
time1,
|
||||
price,
|
||||
time2,
|
||||
price,
|
||||
lColor,
|
||||
STYLE_DOT,
|
||||
3,
|
||||
false,
|
||||
false,
|
||||
true);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,187 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Alert Library
|
||||
// --------------------------------------
|
||||
// Name: XAlert
|
||||
// Description: provides Alerts abilities ...
|
||||
//
|
||||
//
|
||||
// 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 Inputs ...
|
||||
//
|
||||
input group "Alerts";
|
||||
input bool enableAlerts = true; // Enable Alerts
|
||||
input bool logAlerts = true; // Log Alerts
|
||||
input bool terminalAlerts = false; // Terminal Alerts
|
||||
input bool mailAlerts = false; // Mail Alerts
|
||||
input bool pushAlerts = false; // Push Alerts
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
#include "x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
string alertPrefix = "X-Alert";
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
//
|
||||
// Initial Library if required ...
|
||||
bool OnInInitAlertLibrary()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitial Library if required ...
|
||||
void OnDeinitAlertLibrary()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Attach Alert Prefix to Message ...
|
||||
string PrepareAlertMessage(string message)
|
||||
{
|
||||
//
|
||||
StringReplace(message, "\n", " | ");
|
||||
|
||||
//
|
||||
StringConcatenate(message, alertPrefix, " > ", message);
|
||||
|
||||
//
|
||||
return message;
|
||||
}
|
||||
|
||||
//
|
||||
// Logging an Alert ...
|
||||
void LogAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts || !logAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
LogMessage(alertPrefix, message);
|
||||
}
|
||||
|
||||
//
|
||||
// Terminal Alert ...
|
||||
void TerminalAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts || !terminalAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Message ...
|
||||
message = PrepareAlertMessage(message);
|
||||
|
||||
// Send Terminal Alert ...
|
||||
Alert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Mail Alert ...
|
||||
void MailAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts || !mailAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Send Mail Alert ...
|
||||
SendMail(alertPrefix, message);
|
||||
}
|
||||
|
||||
//
|
||||
// Send Push Notification ...
|
||||
void PushAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts || !pushAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Message ...
|
||||
message = PrepareAlertMessage(message);
|
||||
|
||||
//
|
||||
// Send Push Notification Alert ...
|
||||
SendNotification(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Alert Sending ...
|
||||
void SendAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Log ...
|
||||
if (logAlerts)
|
||||
{
|
||||
LogAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Terminal ...
|
||||
if (terminalAlerts)
|
||||
{
|
||||
TerminalAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Mail ...
|
||||
if (mailAlerts)
|
||||
{
|
||||
MailAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Push ...
|
||||
if (pushAlerts)
|
||||
{
|
||||
PushAlert(message);
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
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
Binary file not shown.
@@ -0,0 +1,177 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Http Library
|
||||
// ------------------------------------------
|
||||
// Name: XHttp
|
||||
// Description: provide http communication
|
||||
// abilities ...
|
||||
//
|
||||
//
|
||||
// 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 Model Definition ...
|
||||
//
|
||||
enum X_HTTP_METHOD
|
||||
{
|
||||
X_HTTP_GET,
|
||||
X_HTTP_POST
|
||||
};
|
||||
//
|
||||
// END Model Definition ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
//
|
||||
// Initial Library if required ...
|
||||
bool OnInInitHttpLibrary()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitial Library if required ...
|
||||
void OnDeinitHttpLibrary()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
|
||||
//
|
||||
result = WebRequest(
|
||||
strMethod,
|
||||
url,
|
||||
headers,
|
||||
timeout,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders
|
||||
);
|
||||
|
||||
//
|
||||
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;
|
||||
}
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user