do backup ...
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// --------------------------------------
|
||||
// Name: XBaseClass
|
||||
// Description: provides all based classes for use ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// XBase Class ...
|
||||
class XCBase
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Protected ...
|
||||
|
||||
//
|
||||
// Represent Basic Unique Tag ...
|
||||
virtual string GetTag() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Class Token ...
|
||||
virtual string GetToken() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
};
|
||||
|
||||
//
|
||||
template <typename T>
|
||||
string GenerateSpecifiedCommonSummary(
|
||||
T &mItem,
|
||||
string separator = "\n",
|
||||
bool includeScores = true,
|
||||
bool setLabel = false //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
mItem.GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
(!setLabel
|
||||
? ""
|
||||
: "Commons:" + separator) +
|
||||
"---------------" + separator +
|
||||
"Symbol: " + mItem.symbol + separator +
|
||||
"Period: " + ToString(mItem.period) + separator +
|
||||
"Time: " + ToString(mItem.time) + separator +
|
||||
(includeScores
|
||||
? "---------------" + separator +
|
||||
"Scores:" + separator +
|
||||
"---------------" + separator +
|
||||
"Bullish: " + ToString(bullishScore) + separator +
|
||||
"Bearish: " + ToString(bearishScore) + separator +
|
||||
"---------------" + separator
|
||||
: "") +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,398 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCAccount
|
||||
// Description: provides all Account requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Classes/x-saherelm.base.class.mq5"
|
||||
#include <Trade/AccountInfo.mqh>
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Manage Account ...
|
||||
class XCAccount : public XCBase
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XCAccount()
|
||||
{
|
||||
//
|
||||
mAccountInfo = new CAccountInfo();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XCAccount()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// User Account ...
|
||||
long GetUserAccount()
|
||||
{
|
||||
return mAccountInfo.Login();
|
||||
}
|
||||
|
||||
//
|
||||
// Account Leverage ...
|
||||
long GetLeverage()
|
||||
{
|
||||
return mAccountInfo.Leverage();
|
||||
}
|
||||
|
||||
//
|
||||
// Get Trade Expert State ...
|
||||
bool CanExpertTrade()
|
||||
{
|
||||
return mAccountInfo.TradeExpert();
|
||||
}
|
||||
|
||||
//
|
||||
// User Account Trade Mopde (ENUM_ACCOUNT_TRADE_MODE) ...
|
||||
// --------------------------
|
||||
// ACCOUNT_TRADE_MODE_DEMO
|
||||
// ACCOUNT_TRADE_MODE_CONTEST
|
||||
// ACCOUNT_TRADE_MODE_REAL
|
||||
ENUM_ACCOUNT_TRADE_MODE GetTradeMode()
|
||||
{
|
||||
return mAccountInfo.TradeMode();
|
||||
}
|
||||
|
||||
//
|
||||
// Get Account Balance ...
|
||||
double GetBalance()
|
||||
{
|
||||
return mAccountInfo.Balance();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the amount of give Credit ...
|
||||
double GetCredit()
|
||||
{
|
||||
return mAccountInfo.Credit();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the amount of current Profit on account ...
|
||||
double GetProfit()
|
||||
{
|
||||
return mAccountInfo.Profit();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the amount of current Equity on account ...
|
||||
double GetEquity()
|
||||
{
|
||||
return mAccountInfo.Equity();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the amount of reserved Margin ...
|
||||
double GetMargin()
|
||||
{
|
||||
return mAccountInfo.Margin();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the amount of free Margin ...
|
||||
double GetFreeMargin()
|
||||
{
|
||||
return mAccountInfo.FreeMargin();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Level of Margin ...
|
||||
double GetMarginLevel()
|
||||
{
|
||||
return mAccountInfo.MarginLevel();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Level Of Margin for a Deposit ...
|
||||
double GetMarginCall()
|
||||
{
|
||||
return mAccountInfo.MarginCall();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Level of Margin for Stop out ...
|
||||
double GetMarginStopOut()
|
||||
{
|
||||
return mAccountInfo.MarginStopOut();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Client Name ...
|
||||
string GetName()
|
||||
{
|
||||
return mAccountInfo.Name();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Trade Server Name ...
|
||||
string GetServerName()
|
||||
{
|
||||
return mAccountInfo.Server();
|
||||
}
|
||||
|
||||
//
|
||||
// Get deposit Currency Name ...
|
||||
string GetCurrency()
|
||||
{
|
||||
return mAccountInfo.Currency();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Company Name that serves an Account ...
|
||||
string GetCompany()
|
||||
{
|
||||
return mAccountInfo.Company();
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Profits for the current account based on passed parameters ...
|
||||
double CalculateTradeProfit(
|
||||
const string symbol, // trading symbol
|
||||
ENUM_ORDER_TYPE type, // order type
|
||||
double volume, // volume
|
||||
double entry, // open price
|
||||
double exit // close price
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = mAccountInfo.OrderProfitCheck(
|
||||
symbol,
|
||||
type,
|
||||
volume,
|
||||
entry,
|
||||
exit);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate amount of margin which required for trade operation ...
|
||||
double CalculateMarging(
|
||||
const string symbol, // trading symbol
|
||||
ENUM_ORDER_TYPE type, // order type
|
||||
double volume, // volume
|
||||
double entry // open price
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = mAccountInfo.MarginCheck(
|
||||
symbol,
|
||||
type,
|
||||
volume,
|
||||
entry);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate amount of free margin left after trade operation ...
|
||||
double CalculateFreeMarging(
|
||||
const string symbol, // trading symbol
|
||||
ENUM_ORDER_TYPE type, // order type
|
||||
double volume, // volume
|
||||
double entry // open price
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = mAccountInfo.FreeMarginCheck(
|
||||
symbol,
|
||||
type,
|
||||
volume,
|
||||
entry);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate the Maximum possible volume of trade operation ...
|
||||
double CalculateMaxVolume(
|
||||
const string symbol, // trading symbol
|
||||
ENUM_ORDER_TYPE type, // order type
|
||||
double entry, // open price
|
||||
double percent = 100 // percent of available margin
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = mAccountInfo.MaxLotCheck(
|
||||
symbol,
|
||||
type,
|
||||
entry,
|
||||
percent);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Point Value for Given Symbol based on Account ...
|
||||
double GetPointValue(
|
||||
string symbol // trading symbol
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
double tickSize = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE);
|
||||
double tickValue = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_VALUE);
|
||||
double point = SymbolInfoDouble(symbol, SYMBOL_POINT);
|
||||
|
||||
//
|
||||
double ticksPerPoint = tickSize / point;
|
||||
|
||||
//
|
||||
result = tickValue / ticksPerPoint;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Risk Amount based on account Currency by Providing:
|
||||
// Points and Volume ...
|
||||
double CalculateRiskAmount(
|
||||
string symbol, // trading symbol
|
||||
double points, // amount of Risk Points
|
||||
double volume // position Volume
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
double pointValue = GetPointValue(symbol);
|
||||
|
||||
//
|
||||
result = pointValue * volume * points;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Risk Points based on account Currency by Providing:
|
||||
// Volume and Amount ...
|
||||
double CalculateRiskPoints(
|
||||
string symbol, // trading symbol
|
||||
double volume, // position Volume
|
||||
double amount // amount of Risk based on Account Currency
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
double pointValue = GetPointValue(symbol);
|
||||
|
||||
//
|
||||
result = amount / (pointValue * volume);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Volume based on account Currency by Providing:
|
||||
// Amount and Risk Points ...
|
||||
double CalculateVolume(
|
||||
string symbol, // trading symbol
|
||||
double amount, // amount of Risk based on Account Currency
|
||||
double points // amount of Risk Points
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
points =
|
||||
points <= 0
|
||||
? 10
|
||||
: points;
|
||||
|
||||
//
|
||||
double pointValue = GetPointValue(symbol);
|
||||
|
||||
//
|
||||
result = amount / (pointValue * points);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Account Info ...
|
||||
CAccountInfo mAccountInfo;
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,278 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// --------------------------------------
|
||||
// Name: XCPanel
|
||||
// Description: provides all based classes for use ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
|
||||
//
|
||||
#include <Controls/Dialog.mqh>
|
||||
|
||||
//
|
||||
#include "../Classes/x-saherelm.base.class.mq5"
|
||||
|
||||
//
|
||||
// Extentions ...
|
||||
|
||||
/**
|
||||
* Check a Qery Contains in a Content or not ...
|
||||
*
|
||||
* @param mQuery: String ...
|
||||
* @param mContent: String ...
|
||||
* @param ignoreCase: Boolean ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool XContains(
|
||||
string mQuery, // Search String
|
||||
string mContent, // Search Content
|
||||
bool ignoreCase = true // Ignore Case
|
||||
)
|
||||
{
|
||||
return Contains(
|
||||
mQuery,
|
||||
mContent,
|
||||
ignoreCase //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Implementation ...
|
||||
|
||||
//
|
||||
// a Base App Dialog Class ...
|
||||
class XCAppDialog : public CAppDialog
|
||||
{
|
||||
public:
|
||||
//
|
||||
// Action ...
|
||||
|
||||
//
|
||||
// Virual ...
|
||||
|
||||
/**
|
||||
* Override Close Button Click Action ...
|
||||
*/
|
||||
void OnClickButtonClose()
|
||||
{
|
||||
//
|
||||
bool isClosed = ConfirmDialog("Close EA ?");
|
||||
|
||||
//
|
||||
if (isClosed)
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Configuration Actions ...
|
||||
|
||||
/**
|
||||
* Show or Hide Minimize Button ...
|
||||
*
|
||||
* @param show: boolean
|
||||
*/
|
||||
void MinimizeButton(bool show)
|
||||
{
|
||||
//
|
||||
int controlIDX = ControlFind("MinMax");
|
||||
if (!IsValidIndex(controlIDX))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
if (show)
|
||||
{
|
||||
Control(controlIDX).Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
Control(controlIDX).Hide();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show or Hide Close Button ...
|
||||
*
|
||||
* @param show: boolean
|
||||
*/
|
||||
void CloseButton(bool show)
|
||||
{
|
||||
//
|
||||
int controlIDX = ControlFind("Close");
|
||||
if (!IsValidIndex(controlIDX))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
if (show)
|
||||
{
|
||||
Control(controlIDX).Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
Control(controlIDX).Hide();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Minimize Functionality Implementation ...
|
||||
*/
|
||||
void Minimize()
|
||||
{
|
||||
//
|
||||
m_minimized = true;
|
||||
Rebound(m_min_rect);
|
||||
ClientAreaVisible(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Background Color ...
|
||||
*
|
||||
* @param clr: Color ...
|
||||
*/
|
||||
void BackgroundColor(color clr)
|
||||
{
|
||||
//
|
||||
int controlIDX = ControlFind("Client");
|
||||
if (!IsValidIndex(controlIDX))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
CWnd *obj = Control(controlIDX);
|
||||
CWndClient *wndclient = (CWndClient *)obj;
|
||||
|
||||
//
|
||||
wndclient.ColorBackground(clr);
|
||||
}
|
||||
|
||||
//
|
||||
// Overrides ...
|
||||
|
||||
//
|
||||
protected:
|
||||
//
|
||||
|
||||
/**
|
||||
* Find Specific Control in Dialog ...
|
||||
*
|
||||
* @param name: String to Search
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ControlFind(string name)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
if (!IsValid(name))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int count = ControlsTotal();
|
||||
if (!IsValidSize(count))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
string iName = Control(i).Name();
|
||||
|
||||
//
|
||||
bool isContains = XContains(
|
||||
name,
|
||||
iName,
|
||||
true // Ignore Case ...
|
||||
);
|
||||
if (isContains)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and Run Confirm Dialog ...
|
||||
*
|
||||
* @param message: message for Message Box ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ConfirmDialog(string message = NULL)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (!IsValid(message))
|
||||
{
|
||||
message = "Confirm ?";
|
||||
}
|
||||
|
||||
//
|
||||
int dialogResult = MessageBox(message, NULL, MB_YESNO);
|
||||
|
||||
//
|
||||
// use 'switch' or 'if' as needed
|
||||
switch (dialogResult)
|
||||
{
|
||||
//
|
||||
// Yes ...
|
||||
case IDYES:
|
||||
result = true;
|
||||
break;
|
||||
//
|
||||
// No ...
|
||||
case IDNO:
|
||||
result = false;
|
||||
break;
|
||||
//
|
||||
// Cancel ...
|
||||
case IDCANCEL:
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
private:
|
||||
//
|
||||
|
||||
//
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,967 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// --------------------------------------
|
||||
// Name: XCBaseExpert
|
||||
// Description: provides all based classes for use ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.x-alert.class.mq5"
|
||||
#include "../Classes/x-saherelm.x-trade.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
string XCBaseExpertToken = "XCBaseEA";
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Implementations ...
|
||||
class XCBaseExpert : public XCBaseAlert
|
||||
{
|
||||
//
|
||||
public:
|
||||
//
|
||||
|
||||
//
|
||||
XCTrade *mTrader; // Trader of Expert Adviser ...
|
||||
|
||||
//
|
||||
// Constructur(s) ...
|
||||
void XCBaseExpert()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XCBaseExpert()
|
||||
{
|
||||
//
|
||||
delete mTrader;
|
||||
|
||||
//
|
||||
ZeroMemory(mTrader);
|
||||
}
|
||||
|
||||
//
|
||||
// Getter(s) / Setter(s) ...
|
||||
|
||||
//
|
||||
// Common ...
|
||||
|
||||
/**
|
||||
* Get Magic Number ...
|
||||
*
|
||||
* @return ( long )
|
||||
*/
|
||||
long MagicNumber()
|
||||
{
|
||||
return mMagicNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Magic Number ...
|
||||
*
|
||||
* @param value: Long ...
|
||||
*/
|
||||
void MagicNumber(long value)
|
||||
{
|
||||
//
|
||||
mMagicNumber = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Slippage ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int Slippage()
|
||||
{
|
||||
return mSlippage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Slippage ...
|
||||
*
|
||||
* @param value: Integer ...
|
||||
*/
|
||||
void Slippage(int value)
|
||||
{
|
||||
//
|
||||
mSlippage = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Tag Prefix ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string TagPrefix()
|
||||
{
|
||||
return mTagPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Tag Prefix ...
|
||||
*
|
||||
* @param value: String ...
|
||||
*/
|
||||
void TagPrefix(string value)
|
||||
{
|
||||
//
|
||||
mTagPrefix = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
//
|
||||
// Symbol ...
|
||||
|
||||
/**
|
||||
* Get Period ...
|
||||
*
|
||||
* @return ( ENUM_TIMEFRAMES )
|
||||
*/
|
||||
ENUM_TIMEFRAMES GetPeriod()
|
||||
{
|
||||
return mPeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Period ...
|
||||
*
|
||||
* @param value: ENUM_TIMEFRAMES member ...
|
||||
*/
|
||||
void SetPeriod(ENUM_TIMEFRAMES value)
|
||||
{
|
||||
//
|
||||
mPeriod = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Symbol ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GetSymbol()
|
||||
{
|
||||
return mSymbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Symbol ...
|
||||
*
|
||||
* @param value: String ...
|
||||
*/
|
||||
void SetSymbol(string value)
|
||||
{
|
||||
//
|
||||
mSymbol = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Multi Symbol is Enable or Not ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool MultiSymbol()
|
||||
{
|
||||
return mMultiSymbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Multi Symbol is Enable or Not ...
|
||||
*
|
||||
* @param value: Boolean ...
|
||||
*/
|
||||
void MultiSymbol(bool value)
|
||||
{
|
||||
//
|
||||
mMultiSymbol = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Multi Provided Symbols ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string Symbols()
|
||||
{
|
||||
return mSymbols;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Multi Provided Symbols ...
|
||||
*
|
||||
* @param value: String ...
|
||||
*/
|
||||
void Symbols(string value)
|
||||
{
|
||||
//
|
||||
mSymbols = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
//
|
||||
// Signalling ...
|
||||
|
||||
/**
|
||||
* Get Force Disable Signalling ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool Disabled()
|
||||
{
|
||||
return mDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Force Disable Signalling ...
|
||||
*
|
||||
* @param value: Boolean ...
|
||||
*/
|
||||
void Disabled(bool value)
|
||||
{
|
||||
//
|
||||
mDisabled = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Allow Long Signals ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool AllowLong()
|
||||
{
|
||||
return mAllowLong;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Allow Long Signals ...
|
||||
*
|
||||
* @param value: Boolean ...
|
||||
*/
|
||||
void AllowLong(bool value)
|
||||
{
|
||||
//
|
||||
mAllowLong = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Allow Short Signalling ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool AllowShort()
|
||||
{
|
||||
return mAllowShort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Allow Short Signalling ...
|
||||
*
|
||||
* @param value: Boolean ...
|
||||
*/
|
||||
void AllowShort(bool value)
|
||||
{
|
||||
//
|
||||
mAllowShort = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
//
|
||||
// Reports ...
|
||||
|
||||
/**
|
||||
* Get Report New Month State ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ReportNewMonths()
|
||||
{
|
||||
return mReportNewMonths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Report New Month State ...
|
||||
*
|
||||
* @param value: Boolean ...
|
||||
*/
|
||||
void ReportNewMonths(bool value)
|
||||
{
|
||||
//
|
||||
mReportNewMonths = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Report New Weeks State ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ReportNewWeeks()
|
||||
{
|
||||
return mReportNewWeeks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Report New Weeks State ...
|
||||
*
|
||||
* @param value: Boolean ...
|
||||
*/
|
||||
void ReportNewWeeks(bool value)
|
||||
{
|
||||
//
|
||||
mReportNewWeeks = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Report New Days State ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ReportNewDays()
|
||||
{
|
||||
return mReportNewDays;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Report New Days State ...
|
||||
*
|
||||
* @param value: Boolean ...
|
||||
*/
|
||||
void ReportNewDays(bool value)
|
||||
{
|
||||
//
|
||||
mReportNewDays = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Report New Hours State ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ReportNewHours()
|
||||
{
|
||||
return mReportNewHours;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Report New Hours State ...
|
||||
*
|
||||
* @param value: Boolean ...
|
||||
*/
|
||||
void ReportNewHours(bool value)
|
||||
{
|
||||
//
|
||||
mReportNewHours = value;
|
||||
ReConfigure();
|
||||
}
|
||||
|
||||
//
|
||||
// Actions ...
|
||||
|
||||
/**
|
||||
* Handle Expert OnInit Event ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HandleOnInit()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
string message = "";
|
||||
|
||||
//
|
||||
// Validate Input ...
|
||||
result = ValidateInputs();
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
message = "Invalid Inputs ....";
|
||||
|
||||
//
|
||||
Alert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Initial All Requirements ...
|
||||
result = InitEA();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initial All GUI Requirements ...
|
||||
result = InitGUI();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
message = "Initialized Successfully ...";
|
||||
Alert(message);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Expert OnDeInit Event ...
|
||||
*/
|
||||
void HandleOnDeInit()
|
||||
{
|
||||
//
|
||||
// Destroy all GUI Requirements ...
|
||||
DestroyGUI();
|
||||
|
||||
//
|
||||
// Alert De Initialization Succeeded ...
|
||||
string msg = "De Initialized Successfully ...";
|
||||
Alert(msg);
|
||||
|
||||
//
|
||||
// Destroy all EA Requirements ...
|
||||
DestroyEA();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Expert OnTick Event ...
|
||||
*/
|
||||
void HandleOnTick()
|
||||
{
|
||||
//
|
||||
UpdateGUI();
|
||||
HandleReportTime();
|
||||
HandleStrategiesOnTick();
|
||||
HandleStrategiesGuard();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Expert OnTrade Event ...
|
||||
*/
|
||||
void HandleOnTrade()
|
||||
{
|
||||
mTrader.HandleOnTrade();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Expert OnTimer Event ...
|
||||
*/
|
||||
void HandleOnTimer()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Expert OnChart Event ...
|
||||
*/
|
||||
void HandleOnChartEvent(
|
||||
const int id,
|
||||
const long &lparam,
|
||||
const double &dparam,
|
||||
const string &sparam //
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Virtual Actions ...
|
||||
|
||||
/**
|
||||
* Apply Default Configurations ...
|
||||
*/
|
||||
virtual void DefaultConfigure()
|
||||
{
|
||||
//
|
||||
// Commons ...
|
||||
Slippage(10);
|
||||
TagPrefix("");
|
||||
MagicNumber(1694056);
|
||||
|
||||
//
|
||||
// Symbol ...
|
||||
SetSymbol(_Symbol);
|
||||
SetPeriod(_Period);
|
||||
MultiSymbol(false);
|
||||
Symbols("EURUSDb,GBPUSDb,USDJPYb,USDCHFb,DowJones30,XAUUSDb");
|
||||
|
||||
//
|
||||
// Signalling ...
|
||||
Disabled(false);
|
||||
AllowLong(true);
|
||||
AllowShort(true);
|
||||
|
||||
//
|
||||
string tag = GetTag();
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
SetAlertPrefix(tag);
|
||||
SetAlertLogAlerts(true);
|
||||
SetAlertPushAlerts(true);
|
||||
SetAlertMailAlerts(false);
|
||||
SetAlertEnableAlerts(true);
|
||||
SetAlertTerminalAlerts(false);
|
||||
|
||||
//
|
||||
// Reports ...
|
||||
ReportNewDays(true);
|
||||
ReportNewWeeks(false);
|
||||
ReportNewHours(false);
|
||||
ReportNewMonths(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vaslidate Inputs ...
|
||||
*
|
||||
* @return ( virtual bool )
|
||||
*/
|
||||
virtual bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
string errMessage = "";
|
||||
|
||||
//
|
||||
bool isCommonValid = (
|
||||
//
|
||||
mSlippage > 0 &&
|
||||
mMagicNumber > 0
|
||||
//
|
||||
);
|
||||
if (!isCommonValid)
|
||||
{
|
||||
//
|
||||
errMessage += "common configurations error;" + "\n";
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
// Common ...
|
||||
isCommonValid &&
|
||||
//
|
||||
// Otere ...
|
||||
true
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
// Since here Logger not Initiallized, we Use Raw Print Command ...
|
||||
errMessage = " Errors: \n" + errMessage;
|
||||
Alert(errMessage);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initializers and DeInitializers ...
|
||||
|
||||
/**
|
||||
* Initial EA Requirements ...
|
||||
*
|
||||
* @return ( virtual bool )
|
||||
*/
|
||||
virtual bool InitEA()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator Helpers ...
|
||||
|
||||
//
|
||||
// Create Trader Instance and Configure it ...
|
||||
mTrader = new XCTrade(
|
||||
mSlippage,
|
||||
mMagicNumber //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Initialized Requirements ...
|
||||
*/
|
||||
virtual void DestroyEA()
|
||||
{
|
||||
//
|
||||
delete mTrader;
|
||||
|
||||
//
|
||||
ZeroMemory(mTrader);
|
||||
}
|
||||
|
||||
/**
|
||||
* GUI Initialize if required ...
|
||||
*
|
||||
* @return ( virtual bool )
|
||||
*/
|
||||
virtual bool InitGUI()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update All GUI Contents ...
|
||||
*/
|
||||
virtual void UpdateGUI()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy all Initialized GUi Elements ...
|
||||
*/
|
||||
virtual void DestroyGUI()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Calls When a Position's SL Triggered ...
|
||||
*
|
||||
* @param deal: XDeal instance ...
|
||||
*/
|
||||
virtual void HandleOnStopLossTriggered(const XDeal &deal)
|
||||
{
|
||||
HandleReportBalance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls When a Position's TP Triggered ...
|
||||
*
|
||||
* @param deal: XDeal instance ...
|
||||
*/
|
||||
virtual void HandleOnTakeProfitTriggered(const XDeal &deal)
|
||||
{
|
||||
HandleReportBalance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Force Close a Position ...
|
||||
*
|
||||
* @param ticket: Position Ticket ...
|
||||
* @param position: XPosition ...
|
||||
* @param comment: Closing Comment ...
|
||||
*/
|
||||
virtual void HandleOnPositionForceClosed(
|
||||
const ulong ticket,
|
||||
const XPosition &position,
|
||||
const string comment //
|
||||
)
|
||||
{
|
||||
HandleReportBalance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Position Modified ...
|
||||
*
|
||||
* @param ticket: ULONG ...
|
||||
* @param profit: Double ...
|
||||
* @param comment: String ...
|
||||
*/
|
||||
virtual void HandleOnPositionModified(
|
||||
const ulong ticket,
|
||||
const double profit,
|
||||
const string comment //
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Position Partially Closed ...
|
||||
*
|
||||
* @param ticket: ULONG ...
|
||||
* @param profit: Double ...
|
||||
* @param comment: String ...
|
||||
*/
|
||||
virtual void HandleOnPositionPartialClosed(
|
||||
const ulong ticket,
|
||||
const double profit,
|
||||
const string comment //
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Deals Changed ...
|
||||
*
|
||||
* @param count: Integer, Number of Changes ...
|
||||
*/
|
||||
virtual void HandleOnDealsChanged(int count)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Orders Changed ...
|
||||
*
|
||||
* @param count: Integer, Number of Changes ...
|
||||
*/
|
||||
virtual void HandleOnOrdersChanged(int count)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Positions Changed ...
|
||||
*
|
||||
* @param count: Integer, Number of Changes ...
|
||||
*/
|
||||
virtual void HandleOnPositionsChanged(int count)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Do All Signalling Processing Here ...
|
||||
*/
|
||||
virtual void HandleStrategiesOnTick()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Strategies for Guards and then Apply Them ...
|
||||
*/
|
||||
virtual void HandleStrategiesGuard()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Time Handlers ...
|
||||
|
||||
virtual void HandleOnNewMonth()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void HandleOnNewWeek()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void HandleOnNewDay()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void HandleOnNewHour()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void ReConfigure()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Identifier Tag ...
|
||||
*
|
||||
* @return ( virtual string )
|
||||
*/
|
||||
virtual string GetTag()
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
string tagPrefix = TagPrefix();
|
||||
if (IsValid(tagPrefix))
|
||||
{
|
||||
result = tagPrefix;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = "";
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
XCBaseExpertToken + result;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
protected:
|
||||
//
|
||||
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
XTimeTracker mTimeTracker; // Time Tracker for Providing Reports ...
|
||||
|
||||
//
|
||||
// Actions ...
|
||||
|
||||
/**
|
||||
* Report Account Balance ...
|
||||
*/
|
||||
void HandleReportBalance()
|
||||
{
|
||||
//
|
||||
if (!IsRunningOnTestMode())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
string msg = "Balance: " + ToString(mTrader.mAccount.GetBalance());
|
||||
Log(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Time Reporting based on Inputs ...
|
||||
*/
|
||||
void HandleReportTime()
|
||||
{
|
||||
//
|
||||
// Monthly Report ....
|
||||
if (mTimeTracker.IsNewMonth())
|
||||
{
|
||||
//
|
||||
HandleOnNewMonth();
|
||||
|
||||
//
|
||||
if (mReportNewMonths)
|
||||
{
|
||||
//
|
||||
string msg = "New Month ...";
|
||||
|
||||
//
|
||||
Alert(msg);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Weekly Report ....
|
||||
if (mTimeTracker.IsNewWeek())
|
||||
{
|
||||
//
|
||||
HandleOnNewWeek();
|
||||
|
||||
//
|
||||
if (mReportNewWeeks)
|
||||
{
|
||||
//
|
||||
string msg = "New Week ...";
|
||||
|
||||
//
|
||||
Alert(msg);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Daily Report ....
|
||||
if (mTimeTracker.IsNewDay())
|
||||
{
|
||||
//
|
||||
HandleOnNewDay();
|
||||
|
||||
//
|
||||
if (mReportNewDays)
|
||||
{
|
||||
//
|
||||
string msg = "New Day ...";
|
||||
|
||||
//
|
||||
Alert(msg);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Hourly Report ....
|
||||
if (mTimeTracker.IsNewHour())
|
||||
{
|
||||
//
|
||||
HandleOnNewHour();
|
||||
|
||||
//
|
||||
if (mReportNewHours)
|
||||
{
|
||||
//
|
||||
string msg = "New Hour ...";
|
||||
|
||||
//
|
||||
Alert(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
private:
|
||||
//
|
||||
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Common ...
|
||||
long mMagicNumber; // Magic Number ...
|
||||
int mSlippage; // Slippage ...
|
||||
string mTagPrefix; // Tag Prefix ...
|
||||
|
||||
//
|
||||
// Symbol ...
|
||||
ENUM_TIMEFRAMES mPeriod; // Period ...
|
||||
string mSymbol; // Symbol ...
|
||||
bool mMultiSymbol; // Multi Symbol is Enable or Not ...
|
||||
string mSymbols; // Multi Provided Symbols ...
|
||||
|
||||
//
|
||||
// Signalling ...
|
||||
bool mDisabled; // Force Disable Signalling ...
|
||||
bool mAllowLong; // Allow Long Signals ...
|
||||
bool mAllowShort; // Allow Short Signals ...
|
||||
|
||||
//
|
||||
// Reports ...
|
||||
bool mReportNewMonths; // Report New Month ...
|
||||
bool mReportNewWeeks; // Report New Weeks ...
|
||||
bool mReportNewDays; // Report New Days ...
|
||||
bool mReportNewHours; // Report New Hours ...
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
@@ -0,0 +1,151 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCBaseHelper
|
||||
// Description: provides all Base Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Classes/x-saherelm.base.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// a Class for Handle base requirements ...
|
||||
// for indicators ...
|
||||
class XCBaseHelper : public XCBase
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XCBaseHelper(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period // Trading Time Frame
|
||||
)
|
||||
{
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XCBaseHelper()
|
||||
{
|
||||
//
|
||||
IndicatorRelease(mHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Setter(s) / Getter(s) ...
|
||||
|
||||
//
|
||||
// Symbol ...
|
||||
string GetSymbol()
|
||||
{
|
||||
return mSymbol;
|
||||
}
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES GetPeriod()
|
||||
{
|
||||
return mPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Bars ...
|
||||
int CountBars()
|
||||
{
|
||||
//
|
||||
int result =
|
||||
Bars(
|
||||
mSymbol,
|
||||
mPeriod
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Indicator Calculated Bars ...
|
||||
int CountCalculatedBars()
|
||||
{
|
||||
return BarsCalculated(mHandler);
|
||||
}
|
||||
|
||||
//
|
||||
virtual void Free() {}
|
||||
|
||||
//
|
||||
// Generate Tag ...
|
||||
virtual string GetTag()
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
GetToken() +
|
||||
"[" +
|
||||
GetSymbol() + "|" +
|
||||
ToString(GetPeriod()) +
|
||||
"]"
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Symbol ...
|
||||
string mSymbol;
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES mPeriod;
|
||||
|
||||
//
|
||||
// Indicator Handler ...
|
||||
int mHandler;
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ....
|
||||
@@ -0,0 +1,373 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCHttp
|
||||
// Description: provides all HTTP requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
enum X_HTTP_METHOD
|
||||
{
|
||||
X_HTTP_GET,
|
||||
X_HTTP_POST
|
||||
};
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Classes/x-saherelm.base.class.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// a Class for Manage Account ...
|
||||
class XCHttp : public XCBase
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XCHttp()
|
||||
{
|
||||
XCHttp("", 10000);
|
||||
}
|
||||
void XCHttp(
|
||||
string path, // Base Folder to Store Data
|
||||
int timeout // base timeout for Requests
|
||||
)
|
||||
{
|
||||
//
|
||||
Path(path);
|
||||
Timeout(timeout);
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XCHttp()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Properties Getter(s) / Setter(s) ...
|
||||
|
||||
//
|
||||
// Path ...
|
||||
void Path(string value)
|
||||
{
|
||||
//
|
||||
mPath = value;
|
||||
|
||||
//
|
||||
if (!IsValid(mPath))
|
||||
{
|
||||
mPath = GetTag();
|
||||
}
|
||||
}
|
||||
|
||||
string Path()
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
//
|
||||
// Timeout ...
|
||||
void Timeout(int value)
|
||||
{
|
||||
mTimeout = value;
|
||||
}
|
||||
|
||||
//
|
||||
int Timeout()
|
||||
{
|
||||
return mTimeout;
|
||||
}
|
||||
|
||||
//
|
||||
// Error ...
|
||||
int Error()
|
||||
{
|
||||
return mError;
|
||||
}
|
||||
|
||||
//
|
||||
// Response ...
|
||||
string Response()
|
||||
{
|
||||
return mResponse;
|
||||
}
|
||||
|
||||
//
|
||||
// Overrides ...
|
||||
string GetTag() override
|
||||
{
|
||||
return GetSpecificToken(this);
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Send Global Request ...
|
||||
int SendRequest(
|
||||
X_HTTP_METHOD method, // Httm Request Method
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
string strMethod = ToString(method);
|
||||
if (StringLen(strMethod) == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reset State ...
|
||||
ResetState();
|
||||
|
||||
//
|
||||
result = WebRequest(
|
||||
strMethod,
|
||||
url,
|
||||
headers,
|
||||
timeout,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders);
|
||||
|
||||
//
|
||||
if (result < 0)
|
||||
{
|
||||
mError = GetLastError();
|
||||
}
|
||||
else
|
||||
{
|
||||
mResponse = CharArrayToString(response);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Get Request ...
|
||||
int GetRequest(
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = SendRequest(
|
||||
X_HTTP_GET,
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Post Request ...
|
||||
int PostRequest(
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = SendRequest(
|
||||
X_HTTP_POST,
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Download Specific URL Content to Specific Path and File Name ...
|
||||
bool Download(
|
||||
string url, // the URL address which going to download
|
||||
string fileName // Specify Destination file name to Store Response
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
string filePath = GetFilePath(fileName);
|
||||
string cookie = NULL;
|
||||
string referer = NULL;
|
||||
int timeout = Timeout();
|
||||
|
||||
//
|
||||
char payload[];
|
||||
string headers;
|
||||
char response[];
|
||||
string responseHeaders;
|
||||
|
||||
//
|
||||
// Send Request ...
|
||||
int requestResult = GetRequest(
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout);
|
||||
|
||||
//
|
||||
// Define File Handler ...
|
||||
int mFileHandler = FileOpen(
|
||||
filePath,
|
||||
FILE_WRITE | FILE_BIN);
|
||||
if (mFileHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
mError = GetLastError();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Write Response to File ...
|
||||
uint writed = FileWriteArray(
|
||||
mFileHandler,
|
||||
response,
|
||||
0,
|
||||
ArraySize(response));
|
||||
FileFlush(mFileHandler);
|
||||
FileClose(mFileHandler);
|
||||
|
||||
//
|
||||
result = writed > 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Destintion Folder Path ...
|
||||
string mPath;
|
||||
|
||||
//
|
||||
// WEB Request Timeout Value ...
|
||||
int mTimeout;
|
||||
|
||||
//
|
||||
// WEB Request's Response ...
|
||||
string mResponse;
|
||||
|
||||
//
|
||||
// Error Value ...
|
||||
int mError;
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Reset Errors State ...
|
||||
void ResetState()
|
||||
{
|
||||
//
|
||||
// Reset Errors ...
|
||||
mError = -1;
|
||||
mResponse = "";
|
||||
ResetLastError();
|
||||
}
|
||||
|
||||
//
|
||||
// Generate Full File Path ...
|
||||
string GetFilePath(string fileName)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
Path() + "\\" + fileName
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Convert enum to String ...
|
||||
string ToString(X_HTTP_METHOD method)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
switch (method)
|
||||
{
|
||||
//
|
||||
case X_HTTP_GET:
|
||||
result = "GET";
|
||||
break;
|
||||
|
||||
//
|
||||
case X_HTTP_POST:
|
||||
result = "POST";
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,445 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCMD5
|
||||
// Description: Provides MD5 Hashing Requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
static uchar _md5_PADDING[64] =
|
||||
{
|
||||
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
|
||||
//
|
||||
#define _md5_F(x, y, z) (((x) & (y)) | ((~x) & (z)))
|
||||
#define _md5_G(x, y, z) (((x) & (z)) | ((y) & (~z)))
|
||||
#define _md5_H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
#define _md5_I(x, y, z) ((y) ^ ((x) | (~z)))
|
||||
#define _md5_ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
|
||||
|
||||
//
|
||||
#define _md5_FF(a, b, c, d, x, s, ac) \
|
||||
{ \
|
||||
(a) += _md5_F((b), (c), (d)) + (x) + (uint)(ac); \
|
||||
(a) = _md5_ROTATE_LEFT((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
//
|
||||
#define _md5_GG(a, b, c, d, x, s, ac) \
|
||||
{ \
|
||||
(a) += _md5_G((b), (c), (d)) + (x) + (uint)(ac); \
|
||||
(a) = _md5_ROTATE_LEFT((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
//
|
||||
#define _md5_HH(a, b, c, d, x, s, ac) \
|
||||
{ \
|
||||
(a) += _md5_H((b), (c), (d)) + (x) + (uint)(ac); \
|
||||
(a) = _md5_ROTATE_LEFT((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
//
|
||||
#define _md5_II(a, b, c, d, x, s, ac) \
|
||||
{ \
|
||||
(a) += _md5_I((b), (c), (d)) + (x) + (uint)(ac); \
|
||||
(a) = _md5_ROTATE_LEFT((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
//
|
||||
#define _md5_INIT_STATE_0 0x67452301
|
||||
#define _md5_INIT_STATE_1 0xefcdab89
|
||||
#define _md5_INIT_STATE_2 0x98badcfe
|
||||
#define _md5_INIT_STATE_3 0x10325476
|
||||
|
||||
//
|
||||
#define _md5_S11 7
|
||||
#define _md5_S12 12
|
||||
#define _md5_S13 17
|
||||
#define _md5_S14 22
|
||||
|
||||
//
|
||||
#define _md5_S21 5
|
||||
#define _md5_S22 9
|
||||
#define _md5_S23 14
|
||||
#define _md5_S24 20
|
||||
|
||||
//
|
||||
#define _md5_S31 4
|
||||
#define _md5_S32 11
|
||||
#define _md5_S33 16
|
||||
#define _md5_S34 23
|
||||
|
||||
//
|
||||
#define _md5_S41 6
|
||||
#define _md5_S42 10
|
||||
#define _md5_S43 15
|
||||
#define _md5_S44 21
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// XCMD5 a library for Hashing ...
|
||||
class XCMD5
|
||||
{
|
||||
//
|
||||
// Public Provides ...
|
||||
public:
|
||||
//
|
||||
// Protected Provides ...
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XCMD5(void)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCMD5(void)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Hash Specified Char Array ...
|
||||
string Hash(
|
||||
uchar &mSource[], // Specify Char Array to Hash
|
||||
int mLength = 0 // Specify Length of Char Array which required to hash
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
int sourceCount = ArraySize(mSource);
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
sourceCount <= 0 ||
|
||||
(sourceCount > 0 && mLength > sourceCount))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Normalize Args ...
|
||||
if (mLength == 0)
|
||||
{
|
||||
mLength = sourceCount;
|
||||
}
|
||||
|
||||
//
|
||||
// Init MD5 ...
|
||||
MD5Init();
|
||||
|
||||
//
|
||||
// Update Buffer ...
|
||||
MD5Update(mSource, mLength);
|
||||
|
||||
//
|
||||
// Calculate Result ...
|
||||
result = MD5Final();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Hash Specified String ...
|
||||
string Hash(
|
||||
string mSource // Specified String
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
// Converts String to Char Array ...
|
||||
uchar bytes[];
|
||||
StringToCharArray(
|
||||
mSource,
|
||||
bytes,
|
||||
0,
|
||||
StringLen(mSource));
|
||||
|
||||
//
|
||||
result = Hash(
|
||||
bytes,
|
||||
ArraySize(bytes));
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
protected:
|
||||
//
|
||||
// Private Provides ...
|
||||
private:
|
||||
//
|
||||
uint m_lMD5[4];
|
||||
uint m_nCount[2];
|
||||
uchar m_lpszBuffer[64];
|
||||
|
||||
//
|
||||
// Convert Byte to DWord ...
|
||||
void ByteToDWord(int &out[], uint &in[], uint len)
|
||||
{
|
||||
//
|
||||
uint i = 0;
|
||||
uint j = 0;
|
||||
|
||||
//
|
||||
for (; j < len; i++, j += 4)
|
||||
{
|
||||
out[i] = (int)in[j] | (int)in[j + 1] << 8 | (int)in[j + 2] << 16 | (int)in[j + 3] << 24;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Convert DWord to Byte ...
|
||||
void DWordToByte(uchar &out[], int &in[], uint len)
|
||||
{
|
||||
//
|
||||
uint i = 0;
|
||||
uint j = 0;
|
||||
|
||||
//
|
||||
for (; j < len; i++, j += 4)
|
||||
{
|
||||
//
|
||||
out[j] = (uchar)(in[i] & 0xff);
|
||||
out[j + 1] = (uchar)((in[i] >> 8) & 0xff);
|
||||
out[j + 2] = (uchar)((in[i] >> 16) & 0xff);
|
||||
out[j + 3] = (uchar)((in[i] >> 24) & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Init MD5 Array ...
|
||||
void MD5Init()
|
||||
{
|
||||
//
|
||||
ArrayInitialize(m_lpszBuffer, 64);
|
||||
|
||||
//
|
||||
m_nCount[0] = m_nCount[1] = 0;
|
||||
m_lMD5[0] = _md5_INIT_STATE_0;
|
||||
m_lMD5[1] = _md5_INIT_STATE_1;
|
||||
m_lMD5[2] = _md5_INIT_STATE_2;
|
||||
m_lMD5[3] = _md5_INIT_STATE_3;
|
||||
}
|
||||
|
||||
//
|
||||
// Update MD5 ...
|
||||
void MD5Update(uchar &inBuf[], uint inLen)
|
||||
{
|
||||
//
|
||||
int i, ii;
|
||||
int mdi;
|
||||
|
||||
//
|
||||
uint in[16];
|
||||
int i0 = 0;
|
||||
|
||||
//
|
||||
mdi = (int)((m_nCount[0] >> 3) & 0x3F);
|
||||
|
||||
//
|
||||
if ((m_nCount[0] + ((uint)inLen << 3)) < m_nCount[0])
|
||||
{
|
||||
m_nCount[1]++;
|
||||
}
|
||||
|
||||
//
|
||||
m_nCount[0] += ((uint)inLen << 3);
|
||||
m_nCount[1] += ((uint)inLen >> 29);
|
||||
|
||||
//
|
||||
while ((inLen--) > 0)
|
||||
{
|
||||
//
|
||||
m_lpszBuffer[mdi++] = inBuf[i0++];
|
||||
if (mdi == 0x40)
|
||||
{
|
||||
//
|
||||
for (i = 0, ii = 0; i < 16; i++, ii += 4)
|
||||
{
|
||||
in[i] = (((uint)m_lpszBuffer[ii + 3]) << 24) | (((uint)m_lpszBuffer[ii + 2]) << 16) | (((uint)m_lpszBuffer[ii + 1]) << 8) | ((uint)m_lpszBuffer[ii]);
|
||||
}
|
||||
|
||||
//
|
||||
Transform(m_lMD5, in);
|
||||
|
||||
//
|
||||
mdi = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Finalize an MD5 Expression ...
|
||||
string MD5Final()
|
||||
{
|
||||
//
|
||||
uchar bits[8];
|
||||
int nIndex;
|
||||
uint nPadLen;
|
||||
const int nMD5Size = 16;
|
||||
uchar lpszMD5[16];
|
||||
string temp;
|
||||
string out = "";
|
||||
int i;
|
||||
|
||||
//
|
||||
DWordToByte(bits, m_nCount, 8);
|
||||
nIndex = (int)((m_nCount[0] >> 3) & 0x3f);
|
||||
nPadLen = (nIndex < 56) ? (56 - nIndex) : (120 - nIndex);
|
||||
MD5Update(_md5_PADDING, nPadLen);
|
||||
MD5Update(bits, 8);
|
||||
DWordToByte(lpszMD5, m_lMD5, nMD5Size);
|
||||
|
||||
//
|
||||
for (i = 0; i < nMD5Size; i++)
|
||||
{
|
||||
//
|
||||
if (lpszMD5[i] == 0)
|
||||
{
|
||||
temp = "00";
|
||||
}
|
||||
else if (lpszMD5[i] <= 15)
|
||||
{
|
||||
temp = StringFormat("0%x", lpszMD5[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
temp = StringFormat("%x", lpszMD5[i]);
|
||||
}
|
||||
|
||||
//
|
||||
out += temp;
|
||||
}
|
||||
|
||||
//
|
||||
lpszMD5[0] = '\0';
|
||||
|
||||
//
|
||||
return (out);
|
||||
}
|
||||
|
||||
//
|
||||
// Transform Buffers ...
|
||||
void Transform(uint &buf[], uint &in[])
|
||||
{
|
||||
//
|
||||
uint a = buf[0], b = buf[1], c = buf[2], d = buf[3];
|
||||
|
||||
//
|
||||
_md5_FF(a, b, c, d, in[0], _md5_S11, 0xD76AA478);
|
||||
_md5_FF(d, a, b, c, in[1], _md5_S12, 0xE8C7B756);
|
||||
_md5_FF(c, d, a, b, in[2], _md5_S13, 0x242070DB);
|
||||
_md5_FF(b, c, d, a, in[3], _md5_S14, 0xC1BDCEEE);
|
||||
_md5_FF(a, b, c, d, in[4], _md5_S11, 0xF57C0FAF);
|
||||
_md5_FF(d, a, b, c, in[5], _md5_S12, 0x4787C62A);
|
||||
_md5_FF(c, d, a, b, in[6], _md5_S13, 0xA8304613);
|
||||
_md5_FF(b, c, d, a, in[7], _md5_S14, 0xFD469501);
|
||||
_md5_FF(a, b, c, d, in[8], _md5_S11, 0x698098D8);
|
||||
_md5_FF(d, a, b, c, in[9], _md5_S12, 0x8B44F7AF);
|
||||
_md5_FF(c, d, a, b, in[10], _md5_S13, 0xFFFF5BB1);
|
||||
_md5_FF(b, c, d, a, in[11], _md5_S14, 0x895CD7BE);
|
||||
_md5_FF(a, b, c, d, in[12], _md5_S11, 0x6B901122);
|
||||
_md5_FF(d, a, b, c, in[13], _md5_S12, 0xFD987193);
|
||||
_md5_FF(c, d, a, b, in[14], _md5_S13, 0xA679438E);
|
||||
_md5_FF(b, c, d, a, in[15], _md5_S14, 0x49B40821);
|
||||
|
||||
//
|
||||
_md5_GG(a, b, c, d, in[1], _md5_S21, 0xF61E2562);
|
||||
_md5_GG(d, a, b, c, in[6], _md5_S22, 0xC040B340);
|
||||
_md5_GG(c, d, a, b, in[11], _md5_S23, 0x265E5A51);
|
||||
_md5_GG(b, c, d, a, in[0], _md5_S24, 0xE9B6C7AA);
|
||||
_md5_GG(a, b, c, d, in[5], _md5_S21, 0xD62F105D);
|
||||
_md5_GG(d, a, b, c, in[10], _md5_S22, 0x02441453);
|
||||
_md5_GG(c, d, a, b, in[15], _md5_S23, 0xD8A1E681);
|
||||
_md5_GG(b, c, d, a, in[4], _md5_S24, 0xE7D3FBC8);
|
||||
_md5_GG(a, b, c, d, in[9], _md5_S21, 0x21E1CDE6);
|
||||
_md5_GG(d, a, b, c, in[14], _md5_S22, 0xC33707D6);
|
||||
_md5_GG(c, d, a, b, in[3], _md5_S23, 0xF4D50D87);
|
||||
_md5_GG(b, c, d, a, in[8], _md5_S24, 0x455A14ED);
|
||||
_md5_GG(a, b, c, d, in[13], _md5_S21, 0xA9E3E905);
|
||||
_md5_GG(d, a, b, c, in[2], _md5_S22, 0xFCEFA3F8);
|
||||
_md5_GG(c, d, a, b, in[7], _md5_S23, 0x676F02D9);
|
||||
_md5_GG(b, c, d, a, in[12], _md5_S24, 0x8D2A4C8A);
|
||||
|
||||
//
|
||||
_md5_HH(a, b, c, d, in[5], _md5_S31, 0xFFFA3942);
|
||||
_md5_HH(d, a, b, c, in[8], _md5_S32, 0x8771F681);
|
||||
_md5_HH(c, d, a, b, in[11], _md5_S33, 0x6D9D6122);
|
||||
_md5_HH(b, c, d, a, in[14], _md5_S34, 0xFDE5380C);
|
||||
_md5_HH(a, b, c, d, in[1], _md5_S31, 0xA4BEEA44);
|
||||
_md5_HH(d, a, b, c, in[4], _md5_S32, 0x4BDECFA9);
|
||||
_md5_HH(c, d, a, b, in[7], _md5_S33, 0xF6BB4B60);
|
||||
_md5_HH(b, c, d, a, in[10], _md5_S34, 0xBEBFBC70);
|
||||
_md5_HH(a, b, c, d, in[13], _md5_S31, 0x289B7EC6);
|
||||
_md5_HH(d, a, b, c, in[0], _md5_S32, 0xEAA127FA);
|
||||
_md5_HH(c, d, a, b, in[3], _md5_S33, 0xD4EF3085);
|
||||
_md5_HH(b, c, d, a, in[6], _md5_S34, 0x04881D05);
|
||||
_md5_HH(a, b, c, d, in[9], _md5_S31, 0xD9D4D039);
|
||||
_md5_HH(d, a, b, c, in[12], _md5_S32, 0xE6DB99E5);
|
||||
_md5_HH(c, d, a, b, in[15], _md5_S33, 0x1FA27CF8);
|
||||
_md5_HH(b, c, d, a, in[2], _md5_S34, 0xC4AC5665);
|
||||
|
||||
//
|
||||
_md5_II(a, b, c, d, in[0], _md5_S41, 0xF4292244);
|
||||
_md5_II(d, a, b, c, in[7], _md5_S42, 0x432AFF97);
|
||||
_md5_II(c, d, a, b, in[14], _md5_S43, 0xAB9423A7);
|
||||
_md5_II(b, c, d, a, in[5], _md5_S44, 0xFC93A039);
|
||||
_md5_II(a, b, c, d, in[12], _md5_S41, 0x655B59C3);
|
||||
_md5_II(d, a, b, c, in[3], _md5_S42, 0x8F0CCC92);
|
||||
_md5_II(c, d, a, b, in[10], _md5_S43, 0xFFEFF47D);
|
||||
_md5_II(b, c, d, a, in[1], _md5_S44, 0x85845DD1);
|
||||
_md5_II(a, b, c, d, in[8], _md5_S41, 0x6FA87E4F);
|
||||
_md5_II(d, a, b, c, in[15], _md5_S42, 0xFE2CE6E0);
|
||||
_md5_II(c, d, a, b, in[6], _md5_S43, 0xA3014314);
|
||||
_md5_II(b, c, d, a, in[13], _md5_S44, 0x4E0811A1);
|
||||
_md5_II(a, b, c, d, in[4], _md5_S41, 0xF7537E82);
|
||||
_md5_II(d, a, b, c, in[11], _md5_S42, 0xBD3AF235);
|
||||
_md5_II(c, d, a, b, in[2], _md5_S43, 0x2AD7D2BB);
|
||||
_md5_II(b, c, d, a, in[9], _md5_S44, 0xEB86D391);
|
||||
|
||||
//
|
||||
buf[0] += a;
|
||||
buf[1] += b;
|
||||
buf[2] += c;
|
||||
buf[3] += d;
|
||||
}
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,792 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// --------------------------------------
|
||||
// Name: XCVolume
|
||||
// Description: provides all Requirements for Volume Managing ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Template Variables of Inputs for Using ...
|
||||
// input group "Volume";
|
||||
// input ENUM_X_VOLUME_SELECT_TYPE eaVolumeSelect = X_VOLUME_STATIC; // Volume Applying Type
|
||||
// input double eaStaticVoluem = X_MIN_VOLUME; // Static Volume
|
||||
// input double eaDynamicVolumeStepBalance = 0.0; // Step of Balance for Increase Volume
|
||||
// input double eaDynamicVolumeStepVolume = X_MIN_VOLUME; // Step of Volume Increasing
|
||||
// input double eaConstantRiskBalance = 0.0; // Constant Risk Balance per Trade
|
||||
// input double eaConstantPercent = 0.0; // Constant Percent of Balance Per Trade
|
||||
// input double eaConstantBalance = 0.0; // Constant Balance for Calculations
|
||||
// XCVolume *eaVolume;
|
||||
// eaVolume = new XCVolume();
|
||||
// bool result = eaVolume.Init(
|
||||
// eaVolumeSelect,
|
||||
// eaStaticVoluem,
|
||||
// eaDynamicVolumeStepBalance,
|
||||
// eaDynamicVolumeStepVolume,
|
||||
// eaConstantRiskBalance,
|
||||
// eaConstantPercent,
|
||||
// eaConstantBalance //
|
||||
// );
|
||||
// if (!result) {
|
||||
// return INIT_FAILED;
|
||||
// }
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.x-account.class.mq5"
|
||||
#include "../Libraries/x-saherelm.x-trade.lib.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
#define X_MIN_VOLUME 0.01
|
||||
|
||||
//
|
||||
enum ENUM_X_VOLUME_SELECT_TYPE
|
||||
{
|
||||
X_VOLUME_NONE, // None
|
||||
X_VOLUME_STATIC, // Static Volume
|
||||
X_VOLUME_CURRENT, // Current Balance
|
||||
X_VOLUME_EQUITY, // Current Equity
|
||||
X_VOLUME_CONSTANT // Constant Value
|
||||
};
|
||||
|
||||
//
|
||||
bool IsValid(ENUM_X_VOLUME_SELECT_TYPE value)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = value != X_VOLUME_NONE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string ToString(ENUM_X_VOLUME_SELECT_TYPE value)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
result = EnumToString(value);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Implementation ...
|
||||
class XCVolume : public XCBase
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
XCAccount *account;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XCVolume()
|
||||
{
|
||||
//
|
||||
account = new XCAccount();
|
||||
|
||||
//
|
||||
Default();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCVolume()
|
||||
{
|
||||
//
|
||||
ZeroMemory(account);
|
||||
}
|
||||
|
||||
//
|
||||
bool Init(
|
||||
ENUM_X_VOLUME_SELECT_TYPE _SelectType,
|
||||
double _StaticVolume,
|
||||
double _DynamicVolumeStepBalance,
|
||||
double _DynamicVolumeStepVolume,
|
||||
double _ConstantRiskBalance,
|
||||
double _ConstantPercent,
|
||||
double _ConstantBalance //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mVolumeType = _SelectType;
|
||||
mStaticVolume = _StaticVolume;
|
||||
mConstantPercent = _ConstantPercent;
|
||||
mConstantBalance = _ConstantBalance;
|
||||
mConstantRiskBalance = _ConstantRiskBalance;
|
||||
mDynamicVolumeStepVolume = _DynamicVolumeStepVolume;
|
||||
mDynamicVolumeStepBalance = _DynamicVolumeStepBalance;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
CanUseStaticVolume() ||
|
||||
CanUseDynamicVolume() ||
|
||||
CanUseConstantRiskBalance() ||
|
||||
CanUseConstantBalancePercent()
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Prperties ...
|
||||
|
||||
/**
|
||||
* Get Volume Calculating Method ...
|
||||
*
|
||||
* @return (ENUM_X_VOLUME_SELECT_TYPE)
|
||||
*/
|
||||
ENUM_X_VOLUME_SELECT_TYPE VolumeType()
|
||||
{
|
||||
return mVolumeType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Volume Calculating Method ...
|
||||
*
|
||||
* @param value: ENUM_X_VOLUME_SELECT_TYPE member ...
|
||||
*/
|
||||
void VolumeType(ENUM_X_VOLUME_SELECT_TYPE value)
|
||||
{
|
||||
mVolumeType = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Static Volume ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double StaticVolume()
|
||||
{
|
||||
return mStaticVolume;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Static Volume ...
|
||||
*
|
||||
* @param value: double
|
||||
*/
|
||||
void StaticVolume(double value)
|
||||
{
|
||||
//
|
||||
value = NormalizeDouble(value, 0.01, 1);
|
||||
|
||||
//
|
||||
mStaticVolume = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Dynamic Volume Step Balance ...
|
||||
* used to Calculate Final Lottage ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double DynamicVolumeStepBalance()
|
||||
{
|
||||
return mDynamicVolumeStepBalance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Dynamic Volume Step Balance ...
|
||||
* used to Calculate Final Lottage ...
|
||||
*
|
||||
* @param value: Argument 1
|
||||
*/
|
||||
void DynamicVolumeStepBalance(double value)
|
||||
{
|
||||
//
|
||||
value = NormalizeDouble(value, 0);
|
||||
|
||||
//
|
||||
mDynamicVolumeStepBalance = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Dynamic Volume Step Volume ...
|
||||
* used to Calculate Final Lottage ...
|
||||
* how much increase Final Volume based oBalance Step ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double DynamicVolumeStepVolume()
|
||||
{
|
||||
return mDynamicVolumeStepVolume;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Dynamic Volume Step Volume ...
|
||||
* used to Calculate Final Lottage ...
|
||||
* how much increase Final Volume based oBalance Step ...
|
||||
*
|
||||
* @param value: double
|
||||
*/
|
||||
void DynamicVolumeStepVolume(double value)
|
||||
{
|
||||
//
|
||||
value = NormalizeDouble(value, 0.01, 0.1);
|
||||
|
||||
//
|
||||
mDynamicVolumeStepVolume = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Constant Balance Use for Dyamic Volume Calculation ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double ConstantBalance()
|
||||
{
|
||||
return mConstantBalance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Constant Balance Use for Dyamic Volume Calculation ...
|
||||
*
|
||||
* @param value: Argument 1
|
||||
*/
|
||||
void ConstantBalance(double value)
|
||||
{
|
||||
//
|
||||
value = NormalizeDouble(value, 0);
|
||||
|
||||
//
|
||||
mConstantBalance = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Constant Risk Value Based on Account Currency ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double ConstantRiskBalance()
|
||||
{
|
||||
return mConstantRiskBalance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Constant Risk Value Based on Account Currency ...
|
||||
*
|
||||
* @param value: double
|
||||
*/
|
||||
void ConstantRiskBalance(double value)
|
||||
{
|
||||
//
|
||||
value = NormalizeDouble(value, 0);
|
||||
|
||||
//
|
||||
mConstantRiskBalance = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Constant Percent Based On Selected Balance ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double ConstantPercent()
|
||||
{
|
||||
return mConstantPercent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Constant Percent Based On Selected Balance ...
|
||||
*
|
||||
* @param value: double ...
|
||||
*/
|
||||
void ConstantPercent(double value)
|
||||
{
|
||||
//
|
||||
value = NormalizeDouble(value, 0, 100);
|
||||
|
||||
//
|
||||
mConstantPercent = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Retrieve Balance based on Provided Volume Type ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double GetBalance()
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
if (!IsValid(mVolumeType))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (mConstantBalance > 0 &&
|
||||
mVolumeType == X_VOLUME_CONSTANT)
|
||||
{
|
||||
result = mConstantBalance;
|
||||
}
|
||||
else if (mVolumeType == X_VOLUME_CURRENT)
|
||||
{
|
||||
result = account.GetBalance();
|
||||
}
|
||||
else if (mVolumeType == X_VOLUME_EQUITY)
|
||||
{
|
||||
result = account.GetEquity();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Balance based on Provided Volume Type ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double GetBalance(ENUM_X_VOLUME_SELECT_TYPE type)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
if (!IsValid(type))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (mConstantBalance > 0 &&
|
||||
type == X_VOLUME_CONSTANT)
|
||||
{
|
||||
result = mConstantBalance;
|
||||
}
|
||||
else if (type == X_VOLUME_CURRENT)
|
||||
{
|
||||
result = account.GetBalance();
|
||||
}
|
||||
else if (type == X_VOLUME_EQUITY)
|
||||
{
|
||||
result = account.GetEquity();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Volume Based On Given Configuration ...
|
||||
*
|
||||
* @param symbol: string, Trading Symbol ...
|
||||
* @param entry: double, Entry Price ...
|
||||
* @param sl: double, Stop Loss Price ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double CalculateVolume(
|
||||
string symbol,
|
||||
double entry,
|
||||
double sl //
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = X_MIN_VOLUME;
|
||||
|
||||
//
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
has =
|
||||
sl > 0 &&
|
||||
entry > 0 &&
|
||||
IsValid(symbol);
|
||||
if (!has)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Balance Type ...
|
||||
double balance = GetBalance();
|
||||
double points = GetPoints(symbol);
|
||||
double riskPrice = MathAbs(entry - sl);
|
||||
double riskInPoints = riskPrice / points;
|
||||
|
||||
//
|
||||
has = CanUseStaticVolume();
|
||||
if (has)
|
||||
{
|
||||
result = mStaticVolume;
|
||||
}
|
||||
|
||||
//
|
||||
has = CanUseDynamicVolume();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
double multiplier = balance / mDynamicVolumeStepBalance;
|
||||
if (multiplier < 0)
|
||||
{
|
||||
multiplier = 1;
|
||||
}
|
||||
|
||||
//
|
||||
result = multiplier * mDynamicVolumeStepVolume;
|
||||
}
|
||||
|
||||
//
|
||||
has = CanUseConstantRiskBalance();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
result = account.CalculateVolume(
|
||||
symbol,
|
||||
mConstantRiskBalance,
|
||||
riskInPoints //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
has = CanUseConstantBalancePercent();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
double riskAmountPerBalance = (mConstantPercent * balance) / 100;
|
||||
|
||||
//
|
||||
result = account.CalculateVolume(
|
||||
symbol,
|
||||
riskAmountPerBalance,
|
||||
riskInPoints //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
if (result < X_MIN_VOLUME)
|
||||
{
|
||||
result = X_MIN_VOLUME;
|
||||
}
|
||||
|
||||
//
|
||||
// Normalize Volume ...
|
||||
result = NormalizeVolume(result, symbol);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Volume Based On Given Configuration ...
|
||||
*
|
||||
* @param signal: XSignal instance reference, provided required Data ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double CalculateVolume(XSignal &signal)
|
||||
{
|
||||
//
|
||||
double result = X_MIN_VOLUME;
|
||||
|
||||
//
|
||||
if (!signal.IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = CalculateVolume(
|
||||
signal.symbol,
|
||||
signal.entry,
|
||||
signal.sl //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Specified Percent of Selected Balance for Volume ...
|
||||
*
|
||||
* @param percent: double, percent of Balance Risking ...
|
||||
* @param symbol: string, Trading Symbol ...
|
||||
* @param entry: double, Entry Price ...
|
||||
* @param sl: double Stop Loss Price ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double CalculateVolume(
|
||||
ENUM_X_VOLUME_SELECT_TYPE selectType,
|
||||
double percent,
|
||||
string symbol,
|
||||
double entry,
|
||||
double sl //
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = X_MIN_VOLUME;
|
||||
|
||||
//
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
has =
|
||||
sl > 0 &&
|
||||
entry > 0 &&
|
||||
percent > 0 &&
|
||||
IsValid(symbol) &&
|
||||
IsValid(selectType) &&
|
||||
(selectType == X_VOLUME_EQUITY ||
|
||||
selectType == X_VOLUME_CURRENT);
|
||||
if (!has)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Balance Type ...
|
||||
double points = GetPoints(symbol);
|
||||
double riskPrice = MathAbs(entry - sl);
|
||||
double balance = GetBalance(selectType);
|
||||
double riskInPoints = riskPrice / points;
|
||||
|
||||
//
|
||||
double riskAmountPerBalance = (percent * balance) / 100;
|
||||
|
||||
//
|
||||
result = account.CalculateVolume(
|
||||
symbol,
|
||||
riskAmountPerBalance,
|
||||
riskInPoints //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Set Default Props ...
|
||||
*/
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
VolumeType(X_VOLUME_STATIC);
|
||||
StaticVolume(0.01);
|
||||
|
||||
//
|
||||
ConstantBalance(0);
|
||||
ConstantPercent(0);
|
||||
ConstantRiskBalance(0);
|
||||
|
||||
//
|
||||
DynamicVolumeStepBalance(0);
|
||||
DynamicVolumeStepVolume(0.01);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Configuration is Valid For Static Volume ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool CanUseStaticVolume()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid(mVolumeType);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Static Volume ...
|
||||
result =
|
||||
//
|
||||
mVolumeType == X_VOLUME_STATIC &&
|
||||
mStaticVolume > 0 &&
|
||||
//
|
||||
mDynamicVolumeStepBalance == 0 &&
|
||||
//
|
||||
mConstantBalance == 0 &&
|
||||
mConstantPercent == 0 &&
|
||||
mConstantRiskBalance == 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Configuration is Valid For Dynamic Volume ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool CanUseDynamicVolume()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid(mVolumeType);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
(mVolumeType == X_VOLUME_CURRENT ||
|
||||
mVolumeType == X_VOLUME_EQUITY ||
|
||||
(mVolumeType == X_VOLUME_CONSTANT &&
|
||||
mConstantBalance > 0)) &&
|
||||
//
|
||||
mDynamicVolumeStepBalance > 0 &&
|
||||
mDynamicVolumeStepVolume > 0 &&
|
||||
//
|
||||
mStaticVolume == 0 &&
|
||||
mConstantPercent == 0 &&
|
||||
mConstantRiskBalance == 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Configuration is Valid For Constant Risk Balance ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool CanUseConstantRiskBalance()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid(mVolumeType);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
(mVolumeType == X_VOLUME_CURRENT ||
|
||||
mVolumeType == X_VOLUME_EQUITY ||
|
||||
(mVolumeType == X_VOLUME_CONSTANT &&
|
||||
mConstantBalance > 0)) &&
|
||||
//
|
||||
mConstantRiskBalance > 0 &&
|
||||
//
|
||||
mStaticVolume == 0 &&
|
||||
mConstantPercent == 0 &&
|
||||
mDynamicVolumeStepBalance == 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Configuration is Valid For Constant Risk Percent ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool CanUseConstantBalancePercent()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid(mVolumeType);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
(mVolumeType == X_VOLUME_CURRENT ||
|
||||
mVolumeType == X_VOLUME_EQUITY ||
|
||||
(mVolumeType == X_VOLUME_CONSTANT &&
|
||||
mConstantBalance > 0)) &&
|
||||
//
|
||||
mConstantPercent > 0 &&
|
||||
//
|
||||
mStaticVolume == 0 &&
|
||||
mConstantRiskBalance == 0 &&
|
||||
mDynamicVolumeStepBalance == 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
ENUM_X_VOLUME_SELECT_TYPE mVolumeType; // Balance Type ...
|
||||
|
||||
//
|
||||
// Static Volume ...
|
||||
double mStaticVolume; // Static Volume ...
|
||||
|
||||
//
|
||||
double mDynamicVolumeStepBalance; // Step of Balance ...
|
||||
double mDynamicVolumeStepVolume; // Step of Volume ...
|
||||
|
||||
//
|
||||
double mConstantBalance; // Constant Balance ....
|
||||
double mConstantRiskBalance; // Constant Risk Balance ...
|
||||
double mConstantPercent; // Constant Percent of Balance ...
|
||||
};
|
||||
|
||||
//
|
||||
@@ -0,0 +1,236 @@
|
||||
//
|
||||
// HTF Proves ...
|
||||
|
||||
// //
|
||||
// double scoreMultiplier = 1.5;
|
||||
|
||||
// //
|
||||
// bool isConsolidationScoreBullish =
|
||||
// provider.consolidationBullishScore > (provider.consolidationBearishScore * scoreMultiplier);
|
||||
|
||||
// //
|
||||
// bool isConsolidationScoreBearish =
|
||||
// provider.consolidationBearishScore > (provider.consolidationBullishScore * scoreMultiplier);
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
// //
|
||||
// // Detect Kumo Trend ...
|
||||
// bool isKumoBullish = provider.decisionXConditions.isSenkouSpanAOverB;
|
||||
// bool isKumoBearish = provider.decisionXConditions.isSenkouSpanAUnderB;
|
||||
|
||||
// //
|
||||
// // Detect Nearest Cross ...
|
||||
// XOHCL tkCrossedBar;
|
||||
// ENUM_X_DIRECTION tkCrossDir;
|
||||
// bool hasNearestTenkanSenKijunSenCross =
|
||||
// provider
|
||||
// .decisionCycleHelper
|
||||
// .DetectNearestTenKijCross(
|
||||
// tkCrossedBar,
|
||||
// tkCrossDir,
|
||||
// zIndex //
|
||||
// );
|
||||
|
||||
// //
|
||||
// bool isNearestTenkensSenCrossedOverKijunSen =
|
||||
// hasNearestTenkanSenKijunSenCross &&
|
||||
// IsBullish(tkCrossDir);
|
||||
|
||||
// //
|
||||
// bool isNearestTenkensSenCrossedUnderKijunSen =
|
||||
// hasNearestTenkanSenKijunSenCross &&
|
||||
// IsBearish(tkCrossDir);
|
||||
|
||||
// //
|
||||
// // Detect Nearest Volume ...
|
||||
// XOHCL vSwitchedBar;
|
||||
// ENUM_X_DIRECTION vSwitchedDir;
|
||||
// bool isVolumeSwitched =
|
||||
// provider
|
||||
// .decisionCycleHelper
|
||||
// .DetectNearestVolumeSwitched(
|
||||
// vSwitchedBar,
|
||||
// vSwitchedDir,
|
||||
// zIndex //
|
||||
// );
|
||||
// bool isVolumeBullish =
|
||||
// isVolumeSwitched &&
|
||||
// IsBullish(vSwitchedDir);
|
||||
// bool isVolumeBearish =
|
||||
// isVolumeSwitched &&
|
||||
// IsBearish(vSwitchedDir);
|
||||
|
||||
// //
|
||||
// // Detect Nearest Delta Crossed ...
|
||||
// XOHCL deltaCrossedBar;
|
||||
// ENUM_X_DIRECTION deltaCrossedDir;
|
||||
// bool isDeltaCrossed =
|
||||
// provider
|
||||
// .decisionCycleHelper
|
||||
// .DetectNearestDeltaSwitched(
|
||||
// deltaCrossedBar,
|
||||
// deltaCrossedDir,
|
||||
// zIndex //
|
||||
// );
|
||||
// bool isDeltaBullish =
|
||||
// isDeltaCrossed &&
|
||||
// IsBullish(deltaCrossedDir);
|
||||
// bool isDeltaBearish =
|
||||
// isDeltaCrossed &&
|
||||
// IsBearish(deltaCrossedDir);
|
||||
|
||||
// //
|
||||
// // Detect Nearest Str Switched ...
|
||||
// XOHCL strSwitchedBar;
|
||||
// ENUM_X_DIRECTION strSwitchedDir;
|
||||
// bool isStrSwitched =
|
||||
// provider
|
||||
// .decisionCycleHelper
|
||||
// .DetectNearestStrSwitched(
|
||||
// strSwitchedBar,
|
||||
// strSwitchedDir,
|
||||
// zIndex //
|
||||
// );
|
||||
// bool isStrBullish =
|
||||
// isStrSwitched &&
|
||||
// IsBullish(deltaCrossedDir);
|
||||
// bool isStrBearish =
|
||||
// isStrSwitched &&
|
||||
// IsBearish(deltaCrossedDir);
|
||||
|
||||
// //
|
||||
// // Detect Price in TK Zone ...
|
||||
// bool isBarInsideTKZone =
|
||||
// isNearestTenkensSenCrossedOverKijunSen
|
||||
// ? cBar.low < provider.decisionXConditions.tenkanSenBuffer[cIndex]
|
||||
// : isNearestTenkensSenCrossedUnderKijunSen
|
||||
// ? cBar.high > provider.decisionXConditions.tenkanSenBuffer[cIndex]
|
||||
// : false;
|
||||
|
||||
// //
|
||||
// // Checking Bar Based on Positions State ...
|
||||
// ENUM_X_DIRECTION iBarPosDir;
|
||||
// bool isBarValidForDir = provider.decisionCycleHelper
|
||||
// .mBarAnalyser
|
||||
// .IsValidForPosition(
|
||||
// cBar,
|
||||
// iBarPosDir //
|
||||
// );
|
||||
// bool isBarValidForBullish =
|
||||
// isBarValidForDir &&
|
||||
// IsBullish(iBarPosDir);
|
||||
// bool isBarValidForBearish =
|
||||
// isBarValidForDir &&
|
||||
// IsBearish(iBarPosDir);
|
||||
|
||||
//
|
||||
// Summarize Conditions ...
|
||||
|
||||
//
|
||||
isBullish =
|
||||
//
|
||||
false
|
||||
// isStrBullish &&
|
||||
// isKumoBullish &&
|
||||
// isDeltaBullish &&
|
||||
// isVolumeBullish &&
|
||||
// isBarInsideTKZone &&
|
||||
// isBarValidForBullish &&
|
||||
// isConsolidationScoreBullish &&
|
||||
// isNearestTenkensSenCrossedOverKijunSen
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
//
|
||||
false
|
||||
// isStrBearish &&
|
||||
// isKumoBearish &&
|
||||
// isDeltaBearish &&
|
||||
// isVolumeBearish &&
|
||||
// isBarInsideTKZone &&
|
||||
// isBarValidForBearish &&
|
||||
// isConsolidationScoreBearish &&
|
||||
// isNearestTenkensSenCrossedUnderKijunSen
|
||||
//
|
||||
;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
iBox.to = TimeCurrent();
|
||||
XCBoxObject *iObj;
|
||||
has = helper.poiDrawer.DrawBox(
|
||||
iBox,
|
||||
iObj //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
iObj.BoxWidth(2);
|
||||
|
||||
//
|
||||
color iCLR =
|
||||
iBox.IsBullish()
|
||||
? clrAqua
|
||||
: clrMagenta;
|
||||
iObj.BoxColor(iCLR);
|
||||
iObj.BoxStyle(STYLE_SOLID);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
// COMPLEX ...
|
||||
|
||||
//
|
||||
double iKTIRNDs[] = {
|
||||
cKI,
|
||||
cTKI,
|
||||
cTrend //
|
||||
};
|
||||
|
||||
//
|
||||
double iKTIRNDMax = GetMax(iKTIRNDs);
|
||||
double iKTIRNDMin = GetMin(iKTIRNDs);
|
||||
|
||||
//
|
||||
// Conditions Preparing ...
|
||||
|
||||
//
|
||||
bool isTKITRNDBullish =
|
||||
cKIState > 0 &&
|
||||
cTKIState > 0 &&
|
||||
ctrendState > 0;
|
||||
|
||||
//
|
||||
bool isTKITRNDBullishPrev =
|
||||
pKIState > 0 &&
|
||||
pTKIState > 0 &&
|
||||
ptrendState > 0;
|
||||
|
||||
//
|
||||
bool isTKITRNDBearish =
|
||||
cKIState < 0 &&
|
||||
cTKIState < 0 &&
|
||||
ctrendState < 0;
|
||||
|
||||
//
|
||||
bool isTKITRNDBearishPrev =
|
||||
pKIState < 0 &&
|
||||
pTKIState < 0 &&
|
||||
ptrendState < 0;
|
||||
|
||||
//
|
||||
bool isTKITRNDSwitchedToBullish =
|
||||
isTKITRNDBullish &&
|
||||
!isTKITRNDBullishPrev;
|
||||
|
||||
//
|
||||
bool isTKITRNDSwitchedToBearish =
|
||||
isTKITRNDBearish &&
|
||||
!isTKITRNDBearishPrev;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,36 @@
|
||||
// isLowsUnderValesGolden &&
|
||||
// conditions.isStrSwitchedToBullish
|
||||
//
|
||||
// conditions.isStrBullish &&
|
||||
// conditions.isRejectUpHSM // &&
|
||||
//
|
||||
// isStrBullishVPattern &&
|
||||
// isSwingLowSameAsVale &&
|
||||
// !conditions.isNewPeakUnderLast
|
||||
//
|
||||
// zBar.IsBullish() &&
|
||||
// isSameStrBreakedUp &&
|
||||
// isCBarValidForBullish &&
|
||||
// conditions.isStrBullish &&
|
||||
// conditions.isATROverLast &&
|
||||
// conditions.isVidyaUnderLSM // &&
|
||||
// zBar.close > conditions.strSMHighBuffer[cIDX]
|
||||
//
|
||||
|
||||
|
||||
// isHighsOverPeaksGolden &&
|
||||
// conditions.isStrSwitchedToBearish
|
||||
// conditions.isStrBearish &&
|
||||
// conditions.isRejectDownLSM // &&
|
||||
//
|
||||
// isStrBearishVPattern &&
|
||||
// isSwingHighSameAsPeak &&
|
||||
// !conditions.isNewValeOverLast
|
||||
//
|
||||
// zBar.IsBearish() &&
|
||||
// isSameStrBreakedDown &&
|
||||
// isCBarValidForBearish &&
|
||||
// conditions.isStrBearish &&
|
||||
// conditions.isATRUnderLast &&
|
||||
// conditions.isVidyaOverHSM // &&
|
||||
// zBar.close < conditions.strSMLowBuffer[cIDX]
|
||||
@@ -0,0 +1,959 @@
|
||||
//
|
||||
// Detect Signals Based On XPV Indicator Golden Zones ...
|
||||
//
|
||||
bool HasXPVConditions(
|
||||
ENUM_X_CYCLES cycle,
|
||||
XBoxZone &box,
|
||||
ENUM_X_DIRECTION &dir,
|
||||
X121SMCStrategySignalProviderData &provider,
|
||||
int barIndex = 0 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
box.Clean();
|
||||
dir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
// Fil Selected Data ...
|
||||
XPOIState cState;
|
||||
X121Conditions cXConditions;
|
||||
XPOIStateEvents cStateEvents;
|
||||
XC121SMCCycleHelper *cHelper;
|
||||
X121SMCCycleConditions cConditions;
|
||||
result = provider.SelectCycle(
|
||||
cycle,
|
||||
cState,
|
||||
cStateEvents,
|
||||
cXConditions,
|
||||
cHelper,
|
||||
cConditions //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
cState.Clean();
|
||||
ZeroMemory(cHelper);
|
||||
cConditions.Clean();
|
||||
cXConditions.Clean();
|
||||
cStateEvents.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Normalize Args ...
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
int idx = -1;
|
||||
int count = 0;
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
int zIDX = barIndex;
|
||||
int cIDX = zIDX + 1;
|
||||
int pIDX = cIDX + 1;
|
||||
int ppIDX = pIDX + 1;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
XOHCL cBar;
|
||||
XOHCL pBar;
|
||||
XOHCL pPBar;
|
||||
|
||||
//
|
||||
// Initial Bars ...
|
||||
result = zBar.Init(
|
||||
cState.symbol,
|
||||
cState.period,
|
||||
barIndex //
|
||||
);
|
||||
result =
|
||||
result &&
|
||||
zBar.GetPreviousBar(cBar);
|
||||
result =
|
||||
result &&
|
||||
cBar.GetPreviousBar(pBar);
|
||||
result =
|
||||
result &&
|
||||
pBar.GetPreviousBar(pPBar);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
cState.Clean();
|
||||
ZeroMemory(cHelper);
|
||||
cConditions.Clean();
|
||||
cXConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Checking Conditions ...
|
||||
|
||||
//
|
||||
// Retrieve Some Values ...
|
||||
|
||||
//
|
||||
double peak = cXConditions.peaksBuffer[cIDX];
|
||||
double peakZ = cXConditions.peaksBuffer[zIDX];
|
||||
double peakP = cXConditions.peaksBuffer[pIDX];
|
||||
double peakPP = cXConditions.peaksBuffer[ppIDX];
|
||||
|
||||
//
|
||||
double vale = cXConditions.valesBuffer[cIDX];
|
||||
double valeZ = cXConditions.valesBuffer[zIDX];
|
||||
double valeP = cXConditions.valesBuffer[pIDX];
|
||||
double valePP = cXConditions.valesBuffer[ppIDX];
|
||||
|
||||
//
|
||||
double atrUpperSM = cXConditions.atrUpperSMBuffer[cIDX];
|
||||
double atrLowerSM = cXConditions.atrLowerSMBuffer[cIDX];
|
||||
|
||||
//
|
||||
double atrUpperSMZ = cXConditions.atrUpperSMBuffer[zIDX];
|
||||
double atrLowerSMZ = cXConditions.atrLowerSMBuffer[zIDX];
|
||||
|
||||
//
|
||||
double atrUpperSMP = cXConditions.atrUpperSMBuffer[pIDX];
|
||||
double atrLowerSMP = cXConditions.atrLowerSMBuffer[pIDX];
|
||||
|
||||
//
|
||||
double atrUpperSMPP = cXConditions.atrUpperSMBuffer[ppIDX];
|
||||
double atrLowerSMPP = cXConditions.atrLowerSMBuffer[ppIDX];
|
||||
|
||||
//
|
||||
double rsiChange = cXConditions.rsiChangeBuffer[cIDX];
|
||||
double rsiChangeZ = cXConditions.rsiChangeBuffer[zIDX];
|
||||
double rsiChangeP = cXConditions.rsiChangeBuffer[pIDX];
|
||||
double rsiChangePP = cXConditions.rsiChangeBuffer[ppIDX];
|
||||
|
||||
//
|
||||
double rsiChangeSM = cXConditions.rsiChangeSMBuffer[cIDX];
|
||||
double rsiChangeSMZ = cXConditions.rsiChangeSMBuffer[zIDX];
|
||||
double rsiChangeSMP = cXConditions.rsiChangeSMBuffer[pIDX];
|
||||
double rsiChangeSMPP = cXConditions.rsiChangeSMBuffer[ppIDX];
|
||||
|
||||
//
|
||||
double peaksGolden = cXConditions.peaksGoldenBuffer[cIDX];
|
||||
double peaksGoldenZ = cXConditions.peaksGoldenBuffer[zIDX];
|
||||
double peaksGoldenP = cXConditions.peaksGoldenBuffer[pIDX];
|
||||
double peaksGoldenPP = cXConditions.peaksGoldenBuffer[ppIDX];
|
||||
|
||||
//
|
||||
double valesGolden = cXConditions.valesGoldenBuffer[cIDX];
|
||||
double valesGoldenZ = cXConditions.valesGoldenBuffer[zIDX];
|
||||
double valesGoldenP = cXConditions.valesGoldenBuffer[pIDX];
|
||||
double valesGoldenPP = cXConditions.valesGoldenBuffer[ppIDX];
|
||||
|
||||
//
|
||||
double priceChange = cXConditions.priceChangeBuffer[cIDX];
|
||||
double priceChangeZ = cXConditions.priceChangeBuffer[zIDX];
|
||||
double priceChangeP = cXConditions.priceChangeBuffer[pIDX];
|
||||
double priceChangePP = cXConditions.priceChangeBuffer[ppIDX];
|
||||
|
||||
//
|
||||
double priceChangeSM = cXConditions.priceChangeSMBuffer[cIDX];
|
||||
double priceChangeSMZ = cXConditions.priceChangeSMBuffer[zIDX];
|
||||
double priceChangeSMP = cXConditions.priceChangeSMBuffer[pIDX];
|
||||
double priceChangeSMPP = cXConditions.priceChangeSMBuffer[ppIDX];
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//
|
||||
bool isPSwingLow =
|
||||
//
|
||||
(pBar.low < pPBar.low &&
|
||||
pBar.low < cBar.low &&
|
||||
zBar.open > cBar.low)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isCSwingLow =
|
||||
//
|
||||
(pBar.low < pPBar.low &&
|
||||
cBar.low < pBar.low &&
|
||||
zBar.close > cBar.low)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSwingLow =
|
||||
//
|
||||
isPSwingLow ||
|
||||
isCSwingLow
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isPSwingHigh =
|
||||
//
|
||||
pBar.high >= pPBar.high &&
|
||||
pBar.high > cBar.high &&
|
||||
zBar.open < cBar.high
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isCSwingHigh =
|
||||
//
|
||||
(pBar.high >= pPBar.high &&
|
||||
cBar.high > pBar.high &&
|
||||
zBar.close < cBar.high)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isSwingHigh =
|
||||
//
|
||||
isPSwingHigh &&
|
||||
isCSwingHigh
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isBarsOverPeaksGoldenZone =
|
||||
//
|
||||
cBar.high > peaksGolden &&
|
||||
pBar.high > peaksGoldenP
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isBarsUnderValesGoldenZone =
|
||||
//
|
||||
cBar.low < valesGolden &&
|
||||
pBar.low < valesGoldenP
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isBarsOverAtrUpper =
|
||||
//
|
||||
cBar.high > atrUpperSM &&
|
||||
pBar.high > atrUpperSMP
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isBarsUnderAtrLower =
|
||||
//
|
||||
cBar.low < atrLowerSM &&
|
||||
pBar.low < atrLowerSMP
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isRsiChangeOverAtrUpper =
|
||||
rsiChangeP > atrUpperSMP;
|
||||
|
||||
//
|
||||
bool isRsiChangeUnderAtrLower =
|
||||
rsiChangeP < atrLowerSMP;
|
||||
|
||||
//
|
||||
bool isRsiChangeOverPeaksGoldenZone =
|
||||
rsiChangeP > peaksGoldenP;
|
||||
|
||||
//
|
||||
bool isRsiChangeUnderValesGoldenZone =
|
||||
rsiChangeP < valesGoldenP;
|
||||
|
||||
//
|
||||
bool isPriceChangeOverAtrUpper =
|
||||
priceChangeP > atrUpperSMP;
|
||||
|
||||
//
|
||||
bool isPriceChangeUnderAtrLower =
|
||||
priceChangeP < atrLowerSMP;
|
||||
|
||||
//
|
||||
bool isPriceChangeOverPeaksGoldenZone =
|
||||
priceChangeP > peaksGoldenP;
|
||||
|
||||
//
|
||||
bool isPriceChangeUnderValesGoldenZone =
|
||||
priceChangeP < valesGoldenP;
|
||||
|
||||
//
|
||||
// XPV Peaks or Vales ...
|
||||
|
||||
//
|
||||
bool isCBarEqualsToPeak = cBar.high == peak;
|
||||
bool isCBarEqualsToVale = cBar.low == vale;
|
||||
|
||||
//
|
||||
bool isPBarEqualsToPeak = pBar.high == peakP;
|
||||
bool isPBarEqualsToVale = pBar.low == valeP;
|
||||
|
||||
//
|
||||
bool isPPBarEqualsToPeak = pPBar.high == peakPP;
|
||||
bool isPPBarEqualsToVale = pPBar.low == valePP;
|
||||
|
||||
//
|
||||
bool isBarsEqualsToPeak = isCBarEqualsToPeak ||
|
||||
isPBarEqualsToPeak ||
|
||||
isPPBarEqualsToPeak;
|
||||
bool isBarsEqualsToVale = isCBarEqualsToVale ||
|
||||
isPBarEqualsToVale ||
|
||||
isPPBarEqualsToVale;
|
||||
|
||||
//
|
||||
// Detect VPatterns ...
|
||||
|
||||
//
|
||||
bool isRsiChangeBullishVPattern =
|
||||
//
|
||||
rsiChangeP < rsiChangePP &&
|
||||
rsiChangeP < rsiChange &&
|
||||
rsiChangeP < rsiChangeZ
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isRsiChangeBearishVPattern =
|
||||
//
|
||||
rsiChangeP > rsiChangePP &&
|
||||
rsiChangeP > rsiChange &&
|
||||
rsiChangeP > rsiChangeZ
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isRsiChangeBullish =
|
||||
//
|
||||
(isRsiChangeUnderAtrLower &&
|
||||
isRsiChangeBullishVPattern &&
|
||||
isRsiChangeUnderValesGoldenZone)
|
||||
//
|
||||
;
|
||||
|
||||
bool isRsiChangeBearish =
|
||||
//
|
||||
(isRsiChangeOverAtrUpper &&
|
||||
isRsiChangeBearishVPattern &&
|
||||
isRsiChangeOverPeaksGoldenZone)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isPriceChangeBullishVPattern =
|
||||
//
|
||||
priceChangeP < priceChangePP &&
|
||||
priceChangeP < priceChange &&
|
||||
priceChangeP < priceChangeZ
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isPriceChangeBearishVPattern =
|
||||
//
|
||||
priceChangeP > priceChangePP &&
|
||||
priceChangeP > priceChange &&
|
||||
priceChangeP > priceChangeZ
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isPriceChangeBullish =
|
||||
//
|
||||
(isPriceChangeUnderAtrLower &&
|
||||
isPriceChangeBullishVPattern &&
|
||||
isPriceChangeUnderValesGoldenZone)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isPriceChangeBearish =
|
||||
//
|
||||
(isPriceChangeOverAtrUpper &&
|
||||
isPriceChangeBearishVPattern &&
|
||||
isPriceChangeOverPeaksGoldenZone)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// XVWAP ...
|
||||
|
||||
//
|
||||
bool isVWapIsBullish =
|
||||
//
|
||||
(cXConditions.isVWapBullishOrdered &&
|
||||
cXConditions.isVWapSwitchedToBullishState)
|
||||
//
|
||||
||
|
||||
//
|
||||
(cXConditions.isVWapBullishState &&
|
||||
cXConditions.isVWapSwitchedToBullishOrdered)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isVWapIsBearish =
|
||||
//
|
||||
(cXConditions.isVWapBearishOrdered &&
|
||||
cXConditions.isVWapSwitchedToBearishState)
|
||||
//
|
||||
||
|
||||
//
|
||||
(cXConditions.isVWapBearishState &&
|
||||
cXConditions.isVWapSwitchedToBearishOrdered)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Checking Bar States ...
|
||||
|
||||
//
|
||||
ENUM_X_DIRECTION cBarPosDir;
|
||||
bool isCBarValidForPosition =
|
||||
cHelper
|
||||
.mBarAnalyser
|
||||
.IsValidForPosition(
|
||||
cBar,
|
||||
cBarPosDir //
|
||||
);
|
||||
|
||||
//
|
||||
ENUM_X_DIRECTION pBarPosDir;
|
||||
bool isPBarValidForPosition =
|
||||
cHelper
|
||||
.mBarAnalyser
|
||||
.IsValidForPosition(
|
||||
pBar,
|
||||
pBarPosDir //
|
||||
);
|
||||
|
||||
//
|
||||
bool isBarValidForBullish =
|
||||
//
|
||||
(isCBarValidForPosition &&
|
||||
IsBullish(cBarPosDir))
|
||||
//
|
||||
&&
|
||||
//
|
||||
(isPBarValidForPosition &&
|
||||
IsBullish(pBarPosDir))
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isBarValidForBearish =
|
||||
//
|
||||
(isCBarValidForPosition &&
|
||||
IsBearish(cBarPosDir))
|
||||
//
|
||||
&&
|
||||
//
|
||||
(isPBarValidForPosition &&
|
||||
IsBearish(pBarPosDir))
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Summarize Conditions ...
|
||||
|
||||
//
|
||||
isBullish =
|
||||
//
|
||||
// isVWapIsBullish &&
|
||||
// isBarsEqualsToVale &&
|
||||
// isBarValidForBullish &&
|
||||
isSwingLow &&
|
||||
isBarsUnderAtrLower &&
|
||||
isRsiChangeBullish &&
|
||||
isPriceChangeBullish &&
|
||||
isBarsUnderValesGoldenZone
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
//
|
||||
// isVWapIsBearish &&
|
||||
// isBarsEqualsToPeak &&
|
||||
// isBarValidForBearish &&
|
||||
isSwingHigh &&
|
||||
isBarsOverAtrUpper &&
|
||||
isRsiChangeBearish &&
|
||||
isPriceChangeBearish &&
|
||||
isBarsOverPeaksGoldenZone
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Filling Requirements ...
|
||||
result =
|
||||
isBullish ||
|
||||
isBearish;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
dir =
|
||||
isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
box.dir = dir;
|
||||
box.from = pPBar.time;
|
||||
box.to = TimeCurrent();
|
||||
box.symbol = cBar.symbol;
|
||||
box.period = cBar.period;
|
||||
|
||||
//
|
||||
double points = GetPoints(box.symbol);
|
||||
|
||||
//
|
||||
// Usually is Preffered SL ...
|
||||
double pivot = 0;
|
||||
|
||||
//
|
||||
// Usually is Current Price or Entry Price ...
|
||||
double point = GetEntry(
|
||||
cBar.symbol,
|
||||
dir //
|
||||
);
|
||||
|
||||
//
|
||||
box.upper =
|
||||
isBullish
|
||||
? point
|
||||
: pivot;
|
||||
|
||||
//
|
||||
box.lower =
|
||||
isBullish
|
||||
? pivot
|
||||
: point;
|
||||
|
||||
//
|
||||
XCPOIDrawer *drawer = provider.visionCycleHelper.mPOIDrawer;
|
||||
bool drawBoxes = true;
|
||||
if (drawBoxes)
|
||||
{
|
||||
//
|
||||
if (box.IsValid())
|
||||
{
|
||||
//
|
||||
XCBoxObject *iObj;
|
||||
bool isCreated = drawer.DrawBox(
|
||||
box,
|
||||
iObj //
|
||||
);
|
||||
|
||||
//
|
||||
if (isCreated)
|
||||
{
|
||||
//
|
||||
// TODO: ...
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check All Conditions ...
|
||||
result =
|
||||
box.IsValid() &&
|
||||
HasDirection(dir) &&
|
||||
(isBullish ||
|
||||
isBearish);
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
pPBar.Clean();
|
||||
cState.Clean();
|
||||
cConditions.Clean();
|
||||
cConditions.Clean();
|
||||
ZeroMemory(cHelper);
|
||||
cStateEvents.Clean();
|
||||
cXConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool HasXSTRConditions(
|
||||
ENUM_X_CYCLES cycle,
|
||||
XBoxZone &box,
|
||||
ENUM_X_DIRECTION &dir,
|
||||
X121SMCStrategySignalProviderData &provider,
|
||||
int barIndex = 0 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
box.Clean();
|
||||
dir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
// Fil Selected Data ...
|
||||
XPOIState cState;
|
||||
X121Conditions cXConditions;
|
||||
XPOIStateEvents cStateEvents;
|
||||
XC121SMCCycleHelper *cHelper;
|
||||
X121SMCCycleConditions cConditions;
|
||||
result = provider.SelectCycle(
|
||||
cycle,
|
||||
cState,
|
||||
cStateEvents,
|
||||
cXConditions,
|
||||
cHelper,
|
||||
cConditions //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
cState.Clean();
|
||||
ZeroMemory(cHelper);
|
||||
cConditions.Clean();
|
||||
cXConditions.Clean();
|
||||
cStateEvents.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Normalize Args ...
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
int idx = -1;
|
||||
int count = 0;
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
int zIDX = barIndex;
|
||||
int cIDX = zIDX + 1;
|
||||
int pIDX = cIDX + 1;
|
||||
int ppIDX = pIDX + 1;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
XOHCL cBar;
|
||||
XOHCL pBar;
|
||||
XOHCL pPBar;
|
||||
|
||||
//
|
||||
// Initial Bars ...
|
||||
result = zBar.Init(
|
||||
cState.symbol,
|
||||
cState.period,
|
||||
barIndex //
|
||||
);
|
||||
result =
|
||||
result &&
|
||||
zBar.GetPreviousBar(cBar);
|
||||
result =
|
||||
result &&
|
||||
cBar.GetPreviousBar(pBar);
|
||||
result =
|
||||
result &&
|
||||
pBar.GetPreviousBar(pPBar);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
cState.Clean();
|
||||
ZeroMemory(cHelper);
|
||||
cConditions.Clean();
|
||||
cXConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Checking Conditions ...
|
||||
|
||||
//
|
||||
// XSTR ...
|
||||
bool isStrIsBullish =
|
||||
(cXConditions.isStrBullish ||
|
||||
cXConditions.isStrSwitchedToBullish);
|
||||
bool isStrIsBearish =
|
||||
(cXConditions.isStrBearish ||
|
||||
cXConditions.isStrSwitchedToBearish);
|
||||
|
||||
//
|
||||
// Detecting Str Box ...
|
||||
XBoxZone strBox;
|
||||
bool hasStrBox = false;
|
||||
if (!hasStrBox)
|
||||
{
|
||||
//
|
||||
hasStrBox =
|
||||
cXConditions.isStrBullish ||
|
||||
cXConditions.isStrBearish;
|
||||
if (hasStrBox)
|
||||
{
|
||||
//
|
||||
ENUM_X_DIRECTION strDir =
|
||||
cXConditions.isStrBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
XOHCL lastBar;
|
||||
ENUM_X_DIRECTION lastDir;
|
||||
bool hasLast =
|
||||
cHelper
|
||||
.DetectNearestStrSwitched(
|
||||
lastBar,
|
||||
lastDir,
|
||||
zIDX //
|
||||
);
|
||||
|
||||
//
|
||||
XOHCL prevBar;
|
||||
ENUM_X_DIRECTION prevDir;
|
||||
bool hasPrev =
|
||||
hasLast &&
|
||||
cHelper
|
||||
.DetectNearestStrSwitched(
|
||||
prevBar,
|
||||
prevDir,
|
||||
lastBar.Index() + 1 //
|
||||
);
|
||||
|
||||
//
|
||||
hasStrBox =
|
||||
hasLast &&
|
||||
hasPrev;
|
||||
if (hasStrBox)
|
||||
{
|
||||
//
|
||||
int fromIDX = MathMax(
|
||||
lastBar.Index(),
|
||||
prevBar.Index() //
|
||||
);
|
||||
|
||||
//
|
||||
string symbol = cBar.symbol;
|
||||
ENUM_TIMEFRAMES period = cBar.period;
|
||||
|
||||
//
|
||||
datetime from = GetBarTime(
|
||||
symbol,
|
||||
period,
|
||||
fromIDX //
|
||||
);
|
||||
|
||||
//
|
||||
int length = fromIDX - barIndex;
|
||||
|
||||
//
|
||||
double upper = zBar.FindHighest(
|
||||
length,
|
||||
MODE_HIGH //
|
||||
);
|
||||
|
||||
//
|
||||
double lower = zBar.FindLowest(
|
||||
length,
|
||||
MODE_LOW //
|
||||
);
|
||||
|
||||
//
|
||||
strBox.from = from;
|
||||
strBox.dir = strDir;
|
||||
strBox.lower = lower;
|
||||
strBox.upper = upper;
|
||||
strBox.symbol = symbol;
|
||||
strBox.period = period;
|
||||
strBox.type = "XSTRBox";
|
||||
strBox.to = TimeCurrent();
|
||||
|
||||
//
|
||||
hasStrBox = strBox.IsValid();
|
||||
}
|
||||
|
||||
//
|
||||
lastBar.Clean();
|
||||
prevBar.Clean();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// XFastMa ...
|
||||
|
||||
//
|
||||
bool isFastMaOverStr =
|
||||
(cXConditions.x3maFastBuffer[cIDX] > cXConditions.strBuffer[cIDX]);
|
||||
|
||||
//
|
||||
bool isFastMaUnderStr =
|
||||
(cXConditions.x3maFastBuffer[cIDX] < cXConditions.strBuffer[cIDX]);
|
||||
|
||||
//
|
||||
bool isFastMaBullishReject =
|
||||
cBar.low < pBar.low &&
|
||||
cBar.low > cXConditions.strBuffer[cIDX] &&
|
||||
cBar.low < cXConditions.x3maFastBuffer[cIDX] &&
|
||||
cBar.GetDown() > cXConditions.x3maFastBuffer[cIDX];
|
||||
|
||||
//
|
||||
bool isFastMaBearishReject =
|
||||
cBar.high > pBar.high &&
|
||||
cBar.high < cXConditions.strBuffer[cIDX] &&
|
||||
cBar.high > cXConditions.x3maFastBuffer[cIDX] &&
|
||||
cBar.GetUp() < cXConditions.x3maFastBuffer[cIDX];
|
||||
|
||||
//
|
||||
// Summarize Conditions ...
|
||||
|
||||
//
|
||||
isBullish =
|
||||
//
|
||||
// false
|
||||
hasStrBox &&
|
||||
isStrIsBullish &&
|
||||
isFastMaOverStr &&
|
||||
isFastMaBullishReject
|
||||
//
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
//
|
||||
// false
|
||||
hasStrBox &&
|
||||
isStrIsBearish &&
|
||||
isFastMaUnderStr &&
|
||||
isFastMaBearishReject
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Filling Requirements ...
|
||||
result =
|
||||
isBullish ||
|
||||
isBearish;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
XCPOIDrawer *drawer = provider.visionCycleHelper.mPOIDrawer;
|
||||
XCBoxObject *iObj;
|
||||
bool isCreated = drawer.DrawBox(
|
||||
strBox,
|
||||
iObj //
|
||||
);
|
||||
if (isCreated)
|
||||
{
|
||||
//
|
||||
Print("STRBox");
|
||||
}
|
||||
|
||||
//
|
||||
dir =
|
||||
isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
box.dir = dir;
|
||||
box.from = pPBar.time;
|
||||
box.to = TimeCurrent();
|
||||
box.symbol = cBar.symbol;
|
||||
box.period = cBar.period;
|
||||
|
||||
//
|
||||
double points = GetPoints(box.symbol);
|
||||
|
||||
//
|
||||
double pivot = cXConditions.strBuffer[cIDX];
|
||||
// isBullish
|
||||
// ? cBar.low - (points * 5)
|
||||
// : cBar.high + (points * 5);
|
||||
|
||||
//
|
||||
double point = GetEntry(
|
||||
cBar.symbol,
|
||||
dir //
|
||||
);
|
||||
|
||||
//
|
||||
box.upper =
|
||||
isBullish
|
||||
? point
|
||||
: pivot;
|
||||
|
||||
//
|
||||
box.lower =
|
||||
isBullish
|
||||
? pivot
|
||||
: point;
|
||||
|
||||
//
|
||||
bool drawBoxes = true;
|
||||
if (drawBoxes)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check All Conditions ...
|
||||
result =
|
||||
box.IsValid() &&
|
||||
HasDirection(dir) &&
|
||||
(isBullish ||
|
||||
isBearish);
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
pPBar.Clean();
|
||||
cState.Clean();
|
||||
strBox.Clean();
|
||||
cConditions.Clean();
|
||||
cConditions.Clean();
|
||||
ZeroMemory(cHelper);
|
||||
cStateEvents.Clean();
|
||||
cXConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,128 @@
|
||||
#property copyright "Your Name"
|
||||
#property link "https://www.example.com"
|
||||
#property version "1.00"
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 0
|
||||
#property indicator_plots 0
|
||||
|
||||
// Input parameters
|
||||
input int SwingPeriod = 5; // Lookback period for swing detection
|
||||
|
||||
// Global variables
|
||||
double LastSwingHigh = 0, LastSwingLow = 0;
|
||||
bool IsBullish = false;
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
// Start from the latest bar
|
||||
for(int i = rates_total - prev_calculated - 1; i >= 0; i--)
|
||||
{
|
||||
// Detect swing high and low
|
||||
if(IsSwingHigh(high, low, i, SwingPeriod))
|
||||
{
|
||||
LastSwingHigh = high[i];
|
||||
CheckStructure(i, high[i], low[i], time[i]);
|
||||
}
|
||||
if(IsSwingLow(high, low, i, SwingPeriod))
|
||||
{
|
||||
LastSwingLow = low[i];
|
||||
CheckStructure(i, high[i], low[i], time[i]);
|
||||
}
|
||||
}
|
||||
return(rates_total);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
bool IsSwingHigh(const double &high[], const double &low[], int index, int period)
|
||||
{
|
||||
if(index < period || index >= ArraySize(high) - period) return false;
|
||||
for(int i = 1; i <= period; i++)
|
||||
{
|
||||
if(high[index] <= high[index - i] || high[index] <= high[index + i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
bool IsSwingLow(const double &high[], const double &low[], int index, int period)
|
||||
{
|
||||
if(index < period || index >= ArraySize(low) - period) return false;
|
||||
for(int i = 1; i <= period; i++)
|
||||
{
|
||||
if(low[index] >= low[index - i] || low[index] >= low[index + i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
void CheckStructure(int index, double high, double low, datetime time)
|
||||
{
|
||||
// Determine trend direction
|
||||
if(LastSwingHigh > 0 && LastSwingLow > 0)
|
||||
{
|
||||
IsBullish = (LastSwingHigh > LastSwingLow);
|
||||
|
||||
// Check for BOS
|
||||
if(IsBullish && high > LastSwingHigh)
|
||||
{
|
||||
LastSwingHigh = high;
|
||||
ObjectCreate(0, "BOS_" + TimeToString(time), OBJ_TEXT, 0, time, high);
|
||||
ObjectSetString(0, "BOS_" + TimeToString(time), OBJPROP_TEXT, "BOS");
|
||||
ObjectSetInteger(0, "BOS_" + TimeToString(time), OBJPROP_COLOR, clrGreen);
|
||||
Alert("Break of Structure (BOS) detected at " + DoubleToString(high, 5));
|
||||
}
|
||||
else if(!IsBullish && low < LastSwingLow)
|
||||
{
|
||||
LastSwingLow = low;
|
||||
ObjectCreate(0, "BOS_" + TimeToString(time), OBJ_TEXT, 0, time, low);
|
||||
ObjectSetString(0, "BOS_" + TimeToString(time), OBJPROP_TEXT, "BOS");
|
||||
ObjectSetInteger(0, "BOS_" + TimeToString(time), OBJPROP_COLOR, clrRed);
|
||||
Alert("Break of Structure (BOS) detected at " + DoubleToString(low, 5));
|
||||
}
|
||||
|
||||
// Check for CHoCH
|
||||
if(IsBullish && low < LastSwingLow)
|
||||
{
|
||||
LastSwingLow = low;
|
||||
ObjectCreate(0, "CHoCH_" + TimeToString(time), OBJ_TEXT, 0, time, low);
|
||||
ObjectSetString(0, "CHoCH_" + TimeToString(time), OBJPROP_TEXT, "CHoCH");
|
||||
ObjectSetInteger(0, "CHoCH_" + TimeToString(time), OBJPROP_COLOR, clrRed);
|
||||
Alert("Change of Character (CHoCH) detected at " + DoubleToString(low, 5));
|
||||
IsBullish = false; // Trend may reverse
|
||||
}
|
||||
else if(!IsBullish && high > LastSwingHigh)
|
||||
{
|
||||
LastSwingHigh = high;
|
||||
ObjectCreate(0, "CHoCH_" + TimeToString(time), OBJ_TEXT, 0, time, high);
|
||||
ObjectSetString(0, "CHoCH_" + TimeToString(time), OBJPROP_TEXT, "CHoCH");
|
||||
ObjectSetInteger(0, "CHoCH_" + TimeToString(time), OBJPROP_COLOR, clrGreen);
|
||||
Alert("Change of Character (CHoCH) detected at " + DoubleToString(high, 5));
|
||||
IsBullish = true; // Trend may reverse
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
ObjectsDeleteAll(0, "BOS_");
|
||||
ObjectsDeleteAll(0, "CHoCH_");
|
||||
}
|
||||
@@ -0,0 +1,888 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XSMC
|
||||
// Description: XSMC ...
|
||||
//
|
||||
//
|
||||
// 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 XSMC Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121 XSMC"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int swingLength = 5; // Swing Length
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
input int trendArrowCode = 117; // Trend Arrow
|
||||
input int swingLowsArrowCode = 159; // Swing Lows Arrow
|
||||
input int swingHighsArrowCode = 159; // Swing Highs Arrow
|
||||
input int swingLowBOSArrowCode = 233; // Swing Low BOS Arrow
|
||||
input int swingHighBOSArrowCode = 234; // Swing High BOS Arrow
|
||||
input int swingLowCHOCHArrowCode = 225; // Swing Low CHOCH Arrow
|
||||
input int swingHighCHOCHArrowCode = 226; // Swing High CHOCH Arrow
|
||||
|
||||
//
|
||||
input bool showTrend = true; // Show Trend
|
||||
input bool showSwingLows = true; // Show Swing Lows
|
||||
input bool showSwingHighs = true; // Show Swing Highs
|
||||
input bool showSwingLowBOS = true; // Show Swing Low BOS
|
||||
input bool showSwingHighBOS = true; // Show Swing High BOS
|
||||
input bool showSwingLowCHOCH = true; // Show Swing Low CHOCH
|
||||
input bool showSwingHighCHOCH = true; // Show Swing High CHOCH
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#define emptyValue 0.0
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 9
|
||||
#property indicator_plots 7
|
||||
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// Swing Lows ...
|
||||
|
||||
//
|
||||
#define swingLowsBufferIndex 0
|
||||
double swingLowsBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121 SWL"
|
||||
#property indicator_type1 DRAW_ARROW
|
||||
#property indicator_color1 clrAqua
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// Swng Highs ...
|
||||
|
||||
//
|
||||
#define swingHighsBufferIndex 1
|
||||
double swingHighsBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121 SWH"
|
||||
#property indicator_type2 DRAW_ARROW
|
||||
#property indicator_color2 clrMagenta
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Swing Low BOS ...
|
||||
#define swingLowsBOSBufferIndex 2
|
||||
double swingLowsBOSBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "X121 SWLBOS"
|
||||
#property indicator_type3 DRAW_ARROW
|
||||
#property indicator_color3 clrAqua
|
||||
#property indicator_width3 3
|
||||
|
||||
//
|
||||
// Swing High BOS ...
|
||||
#define swingHighsBOSBufferIndex 3
|
||||
double swingHighsBOSBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "X121 SWHBOS"
|
||||
#property indicator_type4 DRAW_ARROW
|
||||
#property indicator_color4 clrMagenta
|
||||
#property indicator_width4 3
|
||||
|
||||
//
|
||||
// Swing Low CHOCH ...
|
||||
#define swingLowsCHOCHBufferIndex 4
|
||||
double swingLowsCHOCHBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "X121 SWLCHOCH"
|
||||
#property indicator_type5 DRAW_ARROW
|
||||
#property indicator_color5 clrYellow
|
||||
#property indicator_width5 3
|
||||
|
||||
//
|
||||
// Swing High CHOCH ...
|
||||
#define swingHighsCHOCHBufferIndex 5
|
||||
double swingHighsCHOCHBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "X121 SWHCHOCH"
|
||||
#property indicator_type6 DRAW_ARROW
|
||||
#property indicator_color6 clrYellow
|
||||
#property indicator_width6 3
|
||||
|
||||
//
|
||||
// Trend ...
|
||||
#define trendBufferIndex 6
|
||||
double trendBuffer[];
|
||||
|
||||
#define trendColorBufferIndex 7
|
||||
double trendColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "X121 TRND"
|
||||
#property indicator_type7 DRAW_COLOR_ARROW
|
||||
#property indicator_color7 CLR_NONE, clrAqua, clrMagenta, clrGray
|
||||
#property indicator_width7 3
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 7;
|
||||
|
||||
//
|
||||
// Trend State ...
|
||||
#define trendStateBufferIndex mLastBufferIndex + 1
|
||||
double trendStateBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
double lastSwing = 0.0;
|
||||
ENUM_X_DIRECTION lastSwingDir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
swingLength > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = swingLength;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// Swing Lows ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE swingLowsDrawType = showSwingLows ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(swingLowsBuffer, true);
|
||||
SetIndexBuffer(swingLowsBufferIndex, swingLowsBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(swingLowsBufferIndex, PLOT_SHOW_DATA, showSwingLows);
|
||||
PlotIndexSetInteger(swingLowsBufferIndex, PLOT_DRAW_TYPE, swingLowsDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(swingLowsBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(swingLowsBufferIndex, PLOT_ARROW, swingLowsArrowCode);
|
||||
|
||||
//
|
||||
// Swing Highs ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE swingHighsDrawType = showSwingHighs ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(swingHighsBuffer, true);
|
||||
SetIndexBuffer(swingHighsBufferIndex, swingHighsBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(swingHighsBufferIndex, PLOT_SHOW_DATA, showSwingHighs);
|
||||
PlotIndexSetInteger(swingHighsBufferIndex, PLOT_DRAW_TYPE, swingHighsDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(swingHighsBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(swingHighsBufferIndex, PLOT_ARROW, swingHighsArrowCode);
|
||||
|
||||
//
|
||||
// Trends ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE trendDrawType = showTrend ? DRAW_COLOR_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(trendBuffer, true);
|
||||
SetIndexBuffer(trendBufferIndex, trendBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(trendBufferIndex, PLOT_SHOW_DATA, showTrend);
|
||||
PlotIndexSetInteger(trendBufferIndex, PLOT_DRAW_TYPE, trendDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(trendBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(trendBufferIndex, PLOT_ARROW, trendArrowCode);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(trendColorBuffer, true);
|
||||
SetIndexBuffer(trendColorBufferIndex, trendColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// SWLBOS ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE swingLowBOSDrawType = showSwingLowBOS ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(swingLowsBOSBuffer, true);
|
||||
SetIndexBuffer(swingLowsBOSBufferIndex, swingLowsBOSBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(swingLowsBOSBufferIndex, PLOT_SHOW_DATA, showSwingLowBOS);
|
||||
PlotIndexSetInteger(swingLowsBOSBufferIndex, PLOT_DRAW_TYPE, swingLowBOSDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(swingLowsBOSBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(swingLowsBOSBufferIndex, PLOT_ARROW, swingLowBOSArrowCode);
|
||||
|
||||
//
|
||||
// SWHBOS ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE swingHighBOSDrawType = showSwingHighBOS ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(swingHighsBOSBuffer, true);
|
||||
SetIndexBuffer(swingHighsBOSBufferIndex, swingHighsBOSBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(swingHighsBOSBufferIndex, PLOT_SHOW_DATA, showSwingHighBOS);
|
||||
PlotIndexSetInteger(swingHighsBOSBufferIndex, PLOT_DRAW_TYPE, swingHighBOSDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(swingHighsBOSBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(swingHighsBOSBufferIndex, PLOT_ARROW, swingHighBOSArrowCode);
|
||||
|
||||
//
|
||||
// SWLCHOCH ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE swingLowCHOCHDrawType = showSwingLowCHOCH ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(swingLowsCHOCHBuffer, true);
|
||||
SetIndexBuffer(swingLowsCHOCHBufferIndex, swingLowsCHOCHBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(swingLowsCHOCHBufferIndex, PLOT_SHOW_DATA, showSwingLowCHOCH);
|
||||
PlotIndexSetInteger(swingLowsCHOCHBufferIndex, PLOT_DRAW_TYPE, swingLowCHOCHDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(swingLowsCHOCHBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(swingLowsCHOCHBufferIndex, PLOT_ARROW, swingLowCHOCHArrowCode);
|
||||
|
||||
//
|
||||
// SWHCHOCH ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE swingHighCHOCHDrawType = showSwingHighCHOCH ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(swingHighsCHOCHBuffer, true);
|
||||
SetIndexBuffer(swingHighsCHOCHBufferIndex, swingHighsCHOCHBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(swingHighsCHOCHBufferIndex, PLOT_SHOW_DATA, showSwingHighCHOCH);
|
||||
PlotIndexSetInteger(swingHighsCHOCHBufferIndex, PLOT_DRAW_TYPE, swingHighCHOCHDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(swingHighsCHOCHBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(swingHighsCHOCHBufferIndex, PLOT_ARROW, swingHighCHOCHArrowCode);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(trendStateBuffer, true);
|
||||
SetIndexBuffer(trendStateBufferIndex, trendStateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Custom Buffers ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int barsLimit = startCalculationForLastBars > 0
|
||||
? startCalculationForLastBars
|
||||
: 0;
|
||||
//
|
||||
// bool canCalculate = true;
|
||||
bool canCalculate =
|
||||
barsLimit == 0 ||
|
||||
bar_index <= barsLimit;
|
||||
if (canCalculate)
|
||||
{
|
||||
//
|
||||
CalculateValues(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBuffersZero(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Custom ...
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
trendBuffer[barIndex] = emptyValue;
|
||||
swingLowsBuffer[barIndex] = emptyValue;
|
||||
swingHighsBuffer[barIndex] = emptyValue;
|
||||
swingLowsBOSBuffer[barIndex] = emptyValue;
|
||||
swingHighsBOSBuffer[barIndex] = emptyValue;
|
||||
swingLowsCHOCHBuffer[barIndex] = emptyValue;
|
||||
swingHighsCHOCHBuffer[barIndex] = emptyValue;
|
||||
|
||||
//
|
||||
trendColorBuffer[barIndex] = hideColorIDX;
|
||||
trendStateBuffer[barIndex] = (double)((int)X_DIRECTION_NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Values ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
*/
|
||||
void CalculateValues(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int lastBarIndex = bar_index + 1;
|
||||
bool isFirstBar =
|
||||
startCalculationForLastBars > 0
|
||||
? bar_index == startCalculationForLastBars
|
||||
: bar_index == ratesTotal;
|
||||
|
||||
//
|
||||
double iLow = low[bar_index];
|
||||
double iHigh = high[bar_index];
|
||||
|
||||
//
|
||||
// Swing Low ...
|
||||
double lastSwingLow = isFirstBar
|
||||
? emptyValue
|
||||
: swingLowsBuffer[lastBarIndex];
|
||||
bool isSwingLow = IsSwingLow(high, low, bar_index, swingLength);
|
||||
double iSwingLow =
|
||||
!isSwingLow
|
||||
? lastSwingLow
|
||||
: iLow;
|
||||
swingLowsBuffer[bar_index] = iSwingLow;
|
||||
|
||||
//
|
||||
// Swing High ...
|
||||
double lastSwingHigh = isFirstBar
|
||||
? emptyValue
|
||||
: swingHighsBuffer[lastBarIndex];
|
||||
bool isSwingHigh = IsSwingHigh(high, low, bar_index, swingLength);
|
||||
double iSwingHigh =
|
||||
!isSwingHigh
|
||||
? lastSwingHigh
|
||||
: iHigh;
|
||||
swingHighsBuffer[bar_index] = iSwingHigh;
|
||||
|
||||
//
|
||||
// Detect Last Swing/Last Swing Direction ...
|
||||
bool isSwing = isSwingLow ||
|
||||
isSwingHigh;
|
||||
if (isSwing)
|
||||
{
|
||||
//
|
||||
if (isSwingLow)
|
||||
{
|
||||
//
|
||||
lastSwing = iSwingLow;
|
||||
lastSwingDir = X_DIRECTION_BULLISH;
|
||||
}
|
||||
else if (isSwingHigh)
|
||||
{
|
||||
//
|
||||
lastSwing = iSwingHigh;
|
||||
lastSwingDir = X_DIRECTION_BEARISH;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Trend ...
|
||||
|
||||
//
|
||||
// Detecting Trend Direction ...
|
||||
ENUM_X_DIRECTION lastTendDir =
|
||||
isFirstBar
|
||||
? X_DIRECTION_NONE
|
||||
: (ENUM_X_DIRECTION)((int)trendStateBuffer[lastBarIndex]);
|
||||
ENUM_X_DIRECTION iTrendDir =
|
||||
isSwingLow &&
|
||||
iSwingLow > lastSwingLow
|
||||
? X_DIRECTION_BULLISH
|
||||
: isSwingHigh &&
|
||||
iSwingHigh < lastSwingHigh
|
||||
? X_DIRECTION_BEARISH
|
||||
: lastTendDir;
|
||||
bool isTrendChanged =
|
||||
HasDirection(lastTendDir) &&
|
||||
HasDirection(iTrendDir) &&
|
||||
lastTendDir != iTrendDir;
|
||||
|
||||
//
|
||||
// Detecting Trend State ...
|
||||
double iTrendState = (int)iTrendDir;
|
||||
trendStateBuffer[bar_index] = iTrendState;
|
||||
|
||||
//
|
||||
// Detecting Trend Value ...
|
||||
double lastTrendValue =
|
||||
isFirstBar
|
||||
? emptyValue
|
||||
: trendBuffer[lastBarIndex];
|
||||
double iTrendValue =
|
||||
IsBullish(iTrendDir)
|
||||
? isTrendChanged
|
||||
? iLow
|
||||
: lastTrendValue
|
||||
: IsBearish(iTrendDir)
|
||||
? isTrendChanged
|
||||
? iHigh
|
||||
: lastTrendValue
|
||||
: lastTrendValue;
|
||||
trendBuffer[bar_index] = iTrendValue;
|
||||
|
||||
//
|
||||
// Detecting Trend Color ...
|
||||
double iTrendColorValue =
|
||||
IsBullish(iTrendDir)
|
||||
? bullishColorIDX
|
||||
: IsBearish(iTrendDir)
|
||||
? bearishColorIDX
|
||||
: hideColorIDX;
|
||||
bool isTrendBreaked = false;
|
||||
if (IsBullish(iTrendDir))
|
||||
{
|
||||
//
|
||||
isTrendBreaked = iHigh < lastTrendValue;
|
||||
if (isTrendBreaked)
|
||||
{
|
||||
iTrendColorValue = bearishColorIDX;
|
||||
}
|
||||
}
|
||||
else if (IsBearish(iTrendDir))
|
||||
{
|
||||
//
|
||||
isTrendBreaked = iLow > lastTrendValue;
|
||||
if (isTrendBreaked)
|
||||
{
|
||||
iTrendColorValue = bullishColorIDX;
|
||||
}
|
||||
}
|
||||
trendColorBuffer[bar_index] = iTrendColorValue;
|
||||
|
||||
//
|
||||
bool isTrendBullish = iTrendColorValue == bullishColorIDX;
|
||||
bool isTrendBearish = iTrendColorValue == bearishColorIDX;
|
||||
|
||||
//
|
||||
// Detecting BOS ...
|
||||
|
||||
//
|
||||
// Swing Low BOS ...
|
||||
double lastSwingLowBOSValue =
|
||||
isFirstBar
|
||||
? emptyValue
|
||||
: swingLowsBOSBuffer[lastBarIndex];
|
||||
double iSwingLowBOSValue =
|
||||
isTrendBullish &&
|
||||
iHigh > lastSwing
|
||||
? iLow
|
||||
: emptyValue;
|
||||
bool isSwingLowBOSBreaked =
|
||||
iSwingLowBOSValue != emptyValue &&
|
||||
iLow < iSwingLowBOSValue;
|
||||
if (isSwingLowBOSBreaked)
|
||||
{
|
||||
iSwingLowBOSValue = emptyValue;
|
||||
}
|
||||
swingLowsBOSBuffer[bar_index] = iSwingLowBOSValue;
|
||||
|
||||
//
|
||||
// Swing High BOS ...
|
||||
double lastSwingHighBOSValue =
|
||||
isFirstBar
|
||||
? emptyValue
|
||||
: swingHighsBOSBuffer[lastBarIndex];
|
||||
double iSwingHighBOSValue =
|
||||
isTrendBearish &&
|
||||
iLow < lastSwing
|
||||
? iHigh
|
||||
: emptyValue;
|
||||
bool isSwingHighBOSBreaked =
|
||||
iSwingHighBOSValue != emptyValue &&
|
||||
iHigh > iSwingHighBOSValue;
|
||||
if (isSwingHighBOSBreaked)
|
||||
{
|
||||
iSwingHighBOSValue = emptyValue;
|
||||
}
|
||||
swingHighsBOSBuffer[bar_index] = iSwingHighBOSValue;
|
||||
|
||||
//
|
||||
// Detecting CHOCHs ...
|
||||
|
||||
//
|
||||
// Swing Low CHOCH ...
|
||||
double lastSwingLowCHOCHValue =
|
||||
isFirstBar
|
||||
? emptyValue
|
||||
: swingLowsCHOCHBuffer[lastBarIndex];
|
||||
double iSwingLowCHOCHValue =
|
||||
isTrendBullish &&
|
||||
iLow < lastSwing
|
||||
? iLow
|
||||
: emptyValue;
|
||||
swingLowsCHOCHBuffer[bar_index] = iSwingLowCHOCHValue;
|
||||
|
||||
//
|
||||
// Swing High CHOCH ...
|
||||
double lastSwingHighCHOCHValue =
|
||||
isFirstBar
|
||||
? emptyValue
|
||||
: swingHighsCHOCHBuffer[lastBarIndex];
|
||||
double iSwingHighCHOCHValue =
|
||||
isTrendBearish &&
|
||||
iHigh > lastSwing
|
||||
? iHigh
|
||||
: emptyValue;
|
||||
swingHighsCHOCHBuffer[bar_index] = iSwingHighCHOCHValue;
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
bool IsSwingLow(
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
int index,
|
||||
int length //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = index - length > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 1; i <= length; i++)
|
||||
{
|
||||
//
|
||||
result = low[index] < low[index - 1] &&
|
||||
low[index] < low[index + i];
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool IsSwingHigh(
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
int index,
|
||||
int length //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = index - length > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 1; i <= length; i++)
|
||||
{
|
||||
//
|
||||
result = high[index] > high[index - 1] &&
|
||||
high[index] > high[index + i];
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,637 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XSTR
|
||||
// Description: XSTR ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121 XSTR Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121 XSTR"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int strLength = 14; // Length
|
||||
input double strMultiplier = 3; // Multiplier
|
||||
input ENUM_APPLIED_PRICE strAppliedTo = PRICE_MEDIAN; // Applied To
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input bool showStr = true; // Show Str
|
||||
input bool showStrUpper = true; // Show Str Upper
|
||||
input bool showStrLower = true; // Show Str Lower
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 7
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
// STR ...
|
||||
#define strBufferIndex 0
|
||||
double strBuffer[];
|
||||
|
||||
#define strColorBufferIndex 1
|
||||
double strColorBuffer[];
|
||||
|
||||
//
|
||||
#define strPlotBufferIndex 0
|
||||
#property indicator_label1 "X121 STR"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 CLR_NONE, clrLime, clrRed, clrGray
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 2
|
||||
|
||||
//
|
||||
// Up ...
|
||||
#define strUpBufferIndex 2
|
||||
double strUpBuffer[];
|
||||
|
||||
//
|
||||
#define strUpPlotBufferIndex 1
|
||||
#property indicator_label2 "X121 STR U"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 C'255,106,0'
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Down ...
|
||||
#define strDownBufferIndex 3
|
||||
double strDownBuffer[];
|
||||
|
||||
//
|
||||
#define strDownPlotBufferIndex 2
|
||||
#property indicator_label3 "X121 STR D"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 C'255,106,0'
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 3;
|
||||
|
||||
//
|
||||
// STR ...
|
||||
|
||||
//
|
||||
// Atr ...
|
||||
#define atrBufferIndex mLastBufferIndex + 1
|
||||
double atrBuffer[];
|
||||
|
||||
//
|
||||
// Price ...
|
||||
#define strPriceBufferIndex mLastBufferIndex + 2
|
||||
double strPriceBuffer[];
|
||||
|
||||
//
|
||||
// Trend ...
|
||||
#define strStateBufferIndex mLastBufferIndex + 3
|
||||
double strStateBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// ATR Handler ...
|
||||
int atrHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
bool isStrTrendChanged;
|
||||
bool isStrStartBearishTrend;
|
||||
bool isStrStartBullishTrend;
|
||||
|
||||
//
|
||||
int changeOfTrend;
|
||||
int startBearishTrend;
|
||||
int startBullishTrend;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
atrHandler = iATR(
|
||||
_Symbol,
|
||||
_Period,
|
||||
strLength //
|
||||
);
|
||||
bool isInited = atrHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
IndicatorRelease(atrHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
|
||||
//
|
||||
// Validate Calculated Bars ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
int atrCalculatedBars = BarsCalculated(atrHandler);
|
||||
|
||||
//
|
||||
bool isPassedRequiredCalculatedBars =
|
||||
//
|
||||
// ATR ...
|
||||
atrCalculatedBars >= 0
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCalculatedBars)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// checking for the limit start of calculation of an indicator ...
|
||||
limit =
|
||||
(prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? maxLength
|
||||
: prev_calculated - 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
int copiedAtrs = CopyBuffer(atrHandler, 0, 0, rates_total, atrBuffer);
|
||||
|
||||
//
|
||||
// Validate Copied Items ...
|
||||
bool isPassedRequiredCopiedItems =
|
||||
//
|
||||
// ATR ...
|
||||
copiedAtrs >= 0
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCopiedItems)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
// STR ...
|
||||
strLength > 0 &&
|
||||
strMultiplier > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(1, strLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// STR ...
|
||||
SetIndexBuffer(strBufferIndex, strBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(strColorBufferIndex, strColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE strUpDrawType = showStrUpper ? DRAW_LINE : DRAW_NONE;
|
||||
SetIndexBuffer(strUpBufferIndex, strUpBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(strUpPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(strUpPlotBufferIndex, PLOT_SHOW_DATA, showStrUpper);
|
||||
PlotIndexSetInteger(strUpPlotBufferIndex, PLOT_DRAW_TYPE, strUpDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE strDownDrawType = showStrLower ? DRAW_LINE : DRAW_NONE;
|
||||
SetIndexBuffer(strDownBufferIndex, strDownBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(strDownPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(strDownPlotBufferIndex, PLOT_SHOW_DATA, showStrLower);
|
||||
PlotIndexSetInteger(strDownPlotBufferIndex, PLOT_DRAW_TYPE, strDownDrawType);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
// STR ...
|
||||
|
||||
//
|
||||
SetIndexBuffer(strPriceBufferIndex, strPriceBuffer, INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(strStateBufferIndex, strStateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Custom Buffers ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
CalculateStr(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Custom ...
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
// STR ...
|
||||
strBuffer[barIndex] = 0;
|
||||
strUpBuffer[barIndex] = 0;
|
||||
strDownBuffer[barIndex] = 0;
|
||||
strPriceBuffer[barIndex] = 0;
|
||||
strColorBuffer[barIndex] = hideColorIDX;
|
||||
strStateBuffer[barIndex] = hideColorIDX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate STR ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
*/
|
||||
void CalculateStr(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Calculated Price ...
|
||||
ENUM_X_PRICE mPTYpe = ToXPrice(strAppliedTo);
|
||||
double price = GetAppliedPrice(
|
||||
mPTYpe,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
strPriceBuffer[bar_index] = price;
|
||||
|
||||
//
|
||||
double atr = atrBuffer[bar_index];
|
||||
|
||||
//
|
||||
// Up ...
|
||||
strUpBuffer[bar_index] = price + (strMultiplier * atr);
|
||||
|
||||
//
|
||||
// Down ...
|
||||
strDownBuffer[bar_index] = price - (strMultiplier * atr);
|
||||
|
||||
//
|
||||
if (close[bar_index] > strUpBuffer[bar_index - 1])
|
||||
{
|
||||
//
|
||||
strStateBuffer[bar_index] = 1;
|
||||
if (strStateBuffer[bar_index - 1] == -1)
|
||||
{
|
||||
changeOfTrend = 1;
|
||||
}
|
||||
}
|
||||
else if (close[bar_index] < strDownBuffer[bar_index - 1])
|
||||
{
|
||||
//
|
||||
strStateBuffer[bar_index] = -1;
|
||||
if (strStateBuffer[bar_index - 1] == 1)
|
||||
{
|
||||
changeOfTrend = 1;
|
||||
}
|
||||
}
|
||||
else if (strStateBuffer[bar_index - 1] == 1)
|
||||
{
|
||||
//
|
||||
strStateBuffer[bar_index] = 1;
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
else if (strStateBuffer[bar_index - 1] == -1)
|
||||
{
|
||||
//
|
||||
strStateBuffer[bar_index] = -1;
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Down Trend Starting ...
|
||||
if (strStateBuffer[bar_index] < 0 && strStateBuffer[bar_index - 1] > 0)
|
||||
{
|
||||
startBearishTrend = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
startBearishTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Up Trend Starting ...
|
||||
if (strStateBuffer[bar_index] > 0 && strStateBuffer[bar_index - 1] < 0)
|
||||
{
|
||||
startBullishTrend = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
startBullishTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
if (strStateBuffer[bar_index] > 0 && strDownBuffer[bar_index] < strDownBuffer[bar_index - 1])
|
||||
{
|
||||
strDownBuffer[bar_index] = strDownBuffer[bar_index - 1];
|
||||
}
|
||||
|
||||
//
|
||||
if (strStateBuffer[bar_index] < 0 && strUpBuffer[bar_index] > strUpBuffer[bar_index - 1])
|
||||
{
|
||||
strUpBuffer[bar_index] = strUpBuffer[bar_index - 1];
|
||||
}
|
||||
|
||||
//
|
||||
if (startBearishTrend == 1)
|
||||
{
|
||||
strUpBuffer[bar_index] = strPriceBuffer[bar_index] + (strMultiplier * atr);
|
||||
}
|
||||
|
||||
//
|
||||
if (startBullishTrend == 1)
|
||||
{
|
||||
strDownBuffer[bar_index] = strPriceBuffer[bar_index] - (strMultiplier * atr);
|
||||
}
|
||||
|
||||
//
|
||||
// Draw the indicator ...
|
||||
|
||||
//
|
||||
double colorIDX = hideColorIDX;
|
||||
strColorBuffer[bar_index] = colorIDX;
|
||||
|
||||
//
|
||||
if (strStateBuffer[bar_index] == 1)
|
||||
{
|
||||
//
|
||||
strBuffer[bar_index] = strDownBuffer[bar_index];
|
||||
if (changeOfTrend == 1)
|
||||
{
|
||||
strBuffer[bar_index - 1] = strBuffer[bar_index - 2];
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
colorIDX = bullishColorIDX;
|
||||
}
|
||||
else if (strStateBuffer[bar_index] == -1)
|
||||
{
|
||||
//
|
||||
strBuffer[bar_index] = strUpBuffer[bar_index];
|
||||
if (changeOfTrend == 1)
|
||||
{
|
||||
//
|
||||
strBuffer[bar_index - 1] = strBuffer[bar_index - 2];
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
colorIDX = bearishColorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
if (showStr)
|
||||
{
|
||||
strColorBuffer[bar_index] = colorIDX;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,793 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XSTR
|
||||
// Description: XSTR ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121 XSTR Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121 XSTR"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int strLength = 14; // Length
|
||||
input double strMultiplier = 3; // Multiplier
|
||||
input ENUM_MA_METHOD strBoundaryMode = MODE_SMA; // Boundary Mode
|
||||
input ENUM_APPLIED_PRICE strAppliedTo = PRICE_MEDIAN; // Applied To
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showStr = true; // Show Str
|
||||
input bool showStrMid = true; // Show Str Mid
|
||||
input bool showStrUpper = true; // Show Str Upper
|
||||
input bool showStrLower = true; // Show Str Lower
|
||||
input bool showStrLowMa = true; // Show Low Smoothed Buffer
|
||||
input bool showStrHighMa = true; // Show High Smoothed Buffer
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#define emptyValue 0.0
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 11
|
||||
#property indicator_plots 6
|
||||
|
||||
//
|
||||
// STR ...
|
||||
#define strBufferIndex 0
|
||||
double strBuffer[];
|
||||
|
||||
#define strColorBufferIndex 1
|
||||
double strColorBuffer[];
|
||||
|
||||
//
|
||||
#define strPlotBufferIndex 0
|
||||
#property indicator_label1 "X121 STR"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 CLR_NONE, clrLime, clrRed, clrGray
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 2
|
||||
|
||||
//
|
||||
// Up ...
|
||||
#define strUpBufferIndex 2
|
||||
double strUpBuffer[];
|
||||
|
||||
//
|
||||
#define strUpPlotBufferIndex 1
|
||||
#property indicator_label2 "X121 STR U"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrBlueViolet
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Down ...
|
||||
#define strDownBufferIndex 3
|
||||
double strDownBuffer[];
|
||||
|
||||
//
|
||||
#define strDownPlotBufferIndex 2
|
||||
#property indicator_label3 "X121 STR D"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrBlueViolet
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// High MA ...
|
||||
#define strHighMaBufferIndex 4
|
||||
double strHighMaBuffer[];
|
||||
|
||||
//
|
||||
#define strHighMaPlotBufferIndex 3
|
||||
#property indicator_label4 "X121 STR HSM"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrAqua
|
||||
#property indicator_style4 STYLE_SOLID
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// Low Ma ...
|
||||
#define strLowMaBufferIndex 5
|
||||
double strLowMaBuffer[];
|
||||
|
||||
//
|
||||
#define strLowMaPlotBufferIndex 4
|
||||
#property indicator_label5 "X121 STR LSM"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrMagenta
|
||||
#property indicator_style5 STYLE_SOLID
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
// STR Mmid ...
|
||||
#define strMidBufferIndex 6
|
||||
double strMidBuffer[];
|
||||
|
||||
#define strMidColorBufferIndex 7
|
||||
double strMidColorBuffer[];
|
||||
|
||||
//
|
||||
#define strMidPlotBufferIndex 5
|
||||
#property indicator_label6 "X121 STR Mid"
|
||||
#property indicator_type6 DRAW_COLOR_LINE
|
||||
#property indicator_color6 CLR_NONE, clrLime, clrRed, clrGray
|
||||
#property indicator_style6 STYLE_SOLID
|
||||
#property indicator_width6 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 7;
|
||||
|
||||
//
|
||||
// STR ...
|
||||
|
||||
//
|
||||
// Atr ...
|
||||
#define atrBufferIndex mLastBufferIndex + 1
|
||||
double atrBuffer[];
|
||||
|
||||
//
|
||||
// Price ...
|
||||
#define strPriceBufferIndex mLastBufferIndex + 2
|
||||
double strPriceBuffer[];
|
||||
|
||||
//
|
||||
// Trend ...
|
||||
#define strStateBufferIndex mLastBufferIndex + 3
|
||||
double strStateBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// ATR Handler ...
|
||||
int atrHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// MA Handler ...
|
||||
int lowMaHandler = INVALID_HANDLE;
|
||||
int highMaHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
bool isStrTrendChanged;
|
||||
bool isStrStartBearishTrend;
|
||||
bool isStrStartBullishTrend;
|
||||
|
||||
//
|
||||
int changeOfTrend;
|
||||
int startBearishTrend;
|
||||
int startBullishTrend;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
atrHandler = iATR(
|
||||
_Symbol,
|
||||
_Period,
|
||||
strLength //
|
||||
);
|
||||
bool isInited = atrHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Low Ma ...
|
||||
lowMaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
strLength,
|
||||
0,
|
||||
strBoundaryMode,
|
||||
PRICE_LOW //
|
||||
);
|
||||
isInited = lowMaHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// High Ma ...
|
||||
highMaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
strLength,
|
||||
0,
|
||||
strBoundaryMode,
|
||||
PRICE_HIGH //
|
||||
);
|
||||
isInited = highMaHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
IndicatorRelease(atrHandler);
|
||||
IndicatorRelease(lowMaHandler);
|
||||
IndicatorRelease(highMaHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
|
||||
//
|
||||
// Validate Calculated Bars ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
int atrCalculatedBars = BarsCalculated(atrHandler);
|
||||
|
||||
//
|
||||
// Low Ma ...
|
||||
int lowMaCalculatedBars = BarsCalculated(lowMaHandler);
|
||||
|
||||
//
|
||||
// High Ma ...
|
||||
int highMaCalculatedBars = BarsCalculated(highMaHandler);
|
||||
|
||||
//
|
||||
bool isPassedRequiredCalculatedBars =
|
||||
//
|
||||
// ATR ...
|
||||
atrCalculatedBars >= 0 &&
|
||||
//
|
||||
// Low Ma ...
|
||||
lowMaCalculatedBars >= 0 &&
|
||||
//
|
||||
// High Ma ...
|
||||
highMaCalculatedBars >= 0
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCalculatedBars)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// checking for the limit start of calculation of an indicator ...
|
||||
limit =
|
||||
(prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? maxLength
|
||||
: prev_calculated - 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
int copiedAtrs = CopyBuffer(atrHandler, 0, 0, rates_total, atrBuffer);
|
||||
|
||||
//
|
||||
// Low Ma ...
|
||||
int copiedLowMas = CopyBuffer(lowMaHandler, 0, 0, rates_total, strLowMaBuffer);
|
||||
|
||||
//
|
||||
// High Ma ...
|
||||
int copiedHighMas = CopyBuffer(highMaHandler, 0, 0, rates_total, strHighMaBuffer);
|
||||
|
||||
//
|
||||
// Validate Copied Items ...
|
||||
bool isPassedRequiredCopiedItems =
|
||||
//
|
||||
// ATR ...
|
||||
copiedAtrs >= 0 &&
|
||||
//
|
||||
// Low Ma ...
|
||||
copiedLowMas >= 0 &&
|
||||
//
|
||||
// Hig Ma ...
|
||||
copiedHighMas >= 0
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCopiedItems)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
// STR ...
|
||||
strLength > 0 &&
|
||||
strMultiplier > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(1, strLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// STR ...
|
||||
SetIndexBuffer(strBufferIndex, strBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(strColorBufferIndex, strColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE strUpDrawType = showStrUpper ? DRAW_LINE : DRAW_NONE;
|
||||
SetIndexBuffer(strUpBufferIndex, strUpBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(strUpPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(strUpPlotBufferIndex, PLOT_SHOW_DATA, showStrUpper);
|
||||
PlotIndexSetInteger(strUpPlotBufferIndex, PLOT_DRAW_TYPE, strUpDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE strDownDrawType = showStrLower ? DRAW_LINE : DRAW_NONE;
|
||||
SetIndexBuffer(strDownBufferIndex, strDownBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(strDownPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(strDownPlotBufferIndex, PLOT_SHOW_DATA, showStrLower);
|
||||
PlotIndexSetInteger(strDownPlotBufferIndex, PLOT_DRAW_TYPE, strDownDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE strLowMaDrawType = showStrLowMa ? DRAW_LINE : DRAW_NONE;
|
||||
SetIndexBuffer(strLowMaBufferIndex, strLowMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(strLowMaPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(strLowMaPlotBufferIndex, PLOT_SHOW_DATA, showStrLowMa);
|
||||
PlotIndexSetInteger(strLowMaPlotBufferIndex, PLOT_DRAW_TYPE, strLowMaDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE strHighMaDrawType = showStrHighMa ? DRAW_LINE : DRAW_NONE;
|
||||
SetIndexBuffer(strHighMaBufferIndex, strHighMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(strHighMaPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(strHighMaPlotBufferIndex, PLOT_SHOW_DATA, showStrHighMa);
|
||||
PlotIndexSetInteger(strHighMaPlotBufferIndex, PLOT_DRAW_TYPE, strHighMaDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE strMidDrawType = showStrMid ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
SetIndexBuffer(strMidBufferIndex, strMidBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(strMidColorBufferIndex, strMidColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
PlotIndexSetDouble(strMidPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(strMidPlotBufferIndex, PLOT_SHOW_DATA, showStrMid);
|
||||
PlotIndexSetInteger(strMidPlotBufferIndex, PLOT_DRAW_TYPE, strMidDrawType);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
SetIndexBuffer(strPriceBufferIndex, strPriceBuffer, INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(strStateBufferIndex, strStateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Custom Buffers ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
CalculateStr(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Custom ...
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
// STR ...
|
||||
strBuffer[barIndex] = emptyValue;
|
||||
strUpBuffer[barIndex] = emptyValue;
|
||||
strMidBuffer[barIndex] = emptyValue;
|
||||
strMidBuffer[barIndex] = emptyValue;
|
||||
strDownBuffer[barIndex] = emptyValue;
|
||||
strPriceBuffer[barIndex] = emptyValue;
|
||||
strLowMaBuffer[barIndex] = emptyValue;
|
||||
strHighMaBuffer[barIndex] = emptyValue;
|
||||
|
||||
//
|
||||
strColorBuffer[barIndex] = hideColorIDX;
|
||||
strStateBuffer[barIndex] = hideColorIDX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate STR ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
*/
|
||||
void CalculateStr(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Calculated Price ...
|
||||
ENUM_X_PRICE mPType = ToXPrice(strAppliedTo);
|
||||
double price = GetAppliedPrice(
|
||||
mPType,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
strPriceBuffer[bar_index] = price;
|
||||
|
||||
//
|
||||
double atr = atrBuffer[bar_index];
|
||||
|
||||
//
|
||||
// Up ...
|
||||
strUpBuffer[bar_index] = price + (strMultiplier * atr);
|
||||
|
||||
//
|
||||
// Down ...
|
||||
strDownBuffer[bar_index] = price - (strMultiplier * atr);
|
||||
|
||||
//
|
||||
if (close[bar_index] > strUpBuffer[bar_index - 1])
|
||||
{
|
||||
//
|
||||
strStateBuffer[bar_index] = 1;
|
||||
if (strStateBuffer[bar_index - 1] == -1)
|
||||
{
|
||||
changeOfTrend = 1;
|
||||
}
|
||||
}
|
||||
else if (close[bar_index] < strDownBuffer[bar_index - 1])
|
||||
{
|
||||
//
|
||||
strStateBuffer[bar_index] = -1;
|
||||
if (strStateBuffer[bar_index - 1] == 1)
|
||||
{
|
||||
changeOfTrend = 1;
|
||||
}
|
||||
}
|
||||
else if (strStateBuffer[bar_index - 1] == 1)
|
||||
{
|
||||
//
|
||||
strStateBuffer[bar_index] = 1;
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
else if (strStateBuffer[bar_index - 1] == -1)
|
||||
{
|
||||
//
|
||||
strStateBuffer[bar_index] = -1;
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Down Trend Starting ...
|
||||
if (strStateBuffer[bar_index] < 0 && strStateBuffer[bar_index - 1] > 0)
|
||||
{
|
||||
startBearishTrend = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
startBearishTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Up Trend Starting ...
|
||||
if (strStateBuffer[bar_index] > 0 && strStateBuffer[bar_index - 1] < 0)
|
||||
{
|
||||
startBullishTrend = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
startBullishTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
if (strStateBuffer[bar_index] > 0 && strDownBuffer[bar_index] < strDownBuffer[bar_index - 1])
|
||||
{
|
||||
strDownBuffer[bar_index] = strDownBuffer[bar_index - 1];
|
||||
}
|
||||
|
||||
//
|
||||
if (strStateBuffer[bar_index] < 0 && strUpBuffer[bar_index] > strUpBuffer[bar_index - 1])
|
||||
{
|
||||
strUpBuffer[bar_index] = strUpBuffer[bar_index - 1];
|
||||
}
|
||||
|
||||
//
|
||||
if (startBearishTrend == 1)
|
||||
{
|
||||
strUpBuffer[bar_index] = strPriceBuffer[bar_index] + (strMultiplier * atr);
|
||||
}
|
||||
|
||||
//
|
||||
if (startBullishTrend == 1)
|
||||
{
|
||||
strDownBuffer[bar_index] = strPriceBuffer[bar_index] - (strMultiplier * atr);
|
||||
}
|
||||
|
||||
//
|
||||
// Draw the indicator ...
|
||||
|
||||
//
|
||||
double colorIDX = hideColorIDX;
|
||||
strColorBuffer[bar_index] = colorIDX;
|
||||
|
||||
//
|
||||
if (strStateBuffer[bar_index] == 1)
|
||||
{
|
||||
//
|
||||
strBuffer[bar_index] = strDownBuffer[bar_index];
|
||||
if (changeOfTrend == 1)
|
||||
{
|
||||
strBuffer[bar_index - 1] = strBuffer[bar_index - 2];
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
colorIDX = bullishColorIDX;
|
||||
}
|
||||
else if (strStateBuffer[bar_index] == -1)
|
||||
{
|
||||
//
|
||||
strBuffer[bar_index] = strUpBuffer[bar_index];
|
||||
if (changeOfTrend == 1)
|
||||
{
|
||||
//
|
||||
strBuffer[bar_index - 1] = strBuffer[bar_index - 2];
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
colorIDX = bearishColorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
if (showStr)
|
||||
{
|
||||
strColorBuffer[bar_index] = colorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
// Str Mid ...
|
||||
|
||||
//
|
||||
double iStrMid = strDownBuffer[bar_index] + ((strUpBuffer[bar_index] - strDownBuffer[bar_index]) / 2);
|
||||
strMidBuffer[bar_index] = iStrMid;
|
||||
|
||||
//
|
||||
double iStrColor = close[bar_index] > strMidBuffer[bar_index]
|
||||
? bullishColorIDX
|
||||
: close[bar_index] < strMidBuffer[bar_index]
|
||||
? bearishColorIDX
|
||||
: neuturalColorIDX;
|
||||
strMidColorBuffer[bar_index] = iStrColor;
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,27 @@
|
||||
|
||||
//
|
||||
// XCC ...
|
||||
|
||||
//
|
||||
// XPV ...
|
||||
|
||||
//
|
||||
// XHK ...
|
||||
|
||||
//
|
||||
// XMAS ...
|
||||
|
||||
//
|
||||
// XATR ...
|
||||
|
||||
//
|
||||
// XSTR ...
|
||||
|
||||
//
|
||||
// XCHE ...
|
||||
|
||||
//
|
||||
// X3MA ...
|
||||
|
||||
//
|
||||
// XVWAP ...
|
||||
@@ -0,0 +1,82 @@
|
||||
|
||||
//
|
||||
// XCC ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
// XPV ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
// XHK ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
// XMAS ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
// XATR ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
// XSTR ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
// XCHE ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
// X3MA ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
// XVWAP ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
@@ -0,0 +1,359 @@
|
||||
|
||||
//
|
||||
// XCC ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
// XPV ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
double sarBuffer[];
|
||||
double cHHBuffer[];
|
||||
double cLLBuffer[];
|
||||
double sHHBuffer[];
|
||||
double sLLBuffer[];
|
||||
double mHHBuffer[];
|
||||
double mLLBuffer[];
|
||||
double lHHBuffer[];
|
||||
double lLLBuffer[];
|
||||
double hHHBuffer[];
|
||||
double hLLBuffer[];
|
||||
double peaksBuffer[];
|
||||
double valesBuffer[];
|
||||
double supportsBuffer[];
|
||||
double peaksGoldenBuffer[];
|
||||
double valesGoldenBuffer[];
|
||||
double resistancesBuffer[];
|
||||
double fractalsUpperBuffer[];
|
||||
double fractalsLowerBuffer[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isSarBullish;
|
||||
bool isSarBearish;
|
||||
|
||||
//
|
||||
bool isSarSwitchedToBullish;
|
||||
bool isSarSwitchedToBearish;
|
||||
|
||||
//
|
||||
bool isNewPeak;
|
||||
bool isNewPeakOverLast;
|
||||
bool isNewPeakUnderLast;
|
||||
|
||||
//
|
||||
bool isNewVale;
|
||||
bool isNewValeOverLast;
|
||||
bool isNewValeUnderLast;
|
||||
|
||||
//
|
||||
// XHK ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
double xhkSMLowBuffer[];
|
||||
double xhkRawLowBuffer[];
|
||||
double xhkSMOpenBuffer[];
|
||||
double xhkSMHighBuffer[];
|
||||
double xhkRawOpenBuffer[];
|
||||
double xhkRawHighBuffer[];
|
||||
double xhkSMCloseBuffer[];
|
||||
double xhkRawCloseBuffer[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isSMHKBullish;
|
||||
bool isRawHKBullish;
|
||||
bool isSMHKSwitchedToBullish;
|
||||
bool isRawHKSwitchedToBullish;
|
||||
|
||||
//
|
||||
bool isSMHKBearish;
|
||||
bool isRawHKBearish;
|
||||
bool isSMHKSwitchedToBearish;
|
||||
bool isRawHKSwitchedToBearish;
|
||||
|
||||
//
|
||||
bool isClosedOverSMHK;
|
||||
bool isClosedUnderSMHK;
|
||||
bool isClosedOverRawHK;
|
||||
bool isClosedUnderRawHK;
|
||||
|
||||
//
|
||||
bool isRawHKClosedOverSMHK;
|
||||
bool isRawHKClosedUnderSMHK;
|
||||
|
||||
//
|
||||
// XMAS ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
double midBuffer[];
|
||||
double upperBuffer[];
|
||||
double lowerBuffer[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
// XATR ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
double rsiBuffer[];
|
||||
double atrBuffer[];
|
||||
double atrUpperBuffer[];
|
||||
double atrLowerBuffer[];
|
||||
double atrUpperSMBuffer[];
|
||||
double atrLowerSMBuffer[];
|
||||
double rsiChangeBuffer[];
|
||||
double rsiChangeSMBuffer[];
|
||||
double priceChangeBuffer[];
|
||||
double priceChangeSMBuffer[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isRsiInRange;
|
||||
bool isRsiOverSold;
|
||||
bool isRsiOverBought;
|
||||
bool isRsiCrossedOverOverSold;
|
||||
bool isRsiCrossedUnderOverSold;
|
||||
bool isRsiCrossedOverOverBought;
|
||||
bool isRsiCrossedUnderOverBought;
|
||||
|
||||
//
|
||||
bool isRsiSMOverPriceChange;
|
||||
bool isRsiSMUnderPriceChange;
|
||||
|
||||
//
|
||||
bool isRsiSMCrossedOverPriceChange;
|
||||
bool isRsiSMCrossedUnderPriceChange;
|
||||
|
||||
//
|
||||
bool isPriceChangeSMOverRsi;
|
||||
bool isPriceChangeSMUnderRsi;
|
||||
|
||||
//
|
||||
bool isPriceChangeSMCrossedOverRsi;
|
||||
bool isPriceChangeSMCrossedUnderRsi;
|
||||
|
||||
//
|
||||
bool isRsiOverRsiSM;
|
||||
bool isRsiUnderRsiSM;
|
||||
|
||||
//
|
||||
bool isRsiCrossedOverRsiSM;
|
||||
bool isRsiCrossedUnderRsiSM;
|
||||
|
||||
//
|
||||
bool isPriceChangeOverPriceChangeSM;
|
||||
bool isPriceChangeUnderPriceChangeSM;
|
||||
|
||||
//
|
||||
bool isPriceChangeCrossedOverPriceChangeSM;
|
||||
bool isPriceChangeCrossedUnderPriceChangeSM;
|
||||
|
||||
//
|
||||
// XSTR ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
double strBuffer[];
|
||||
double strUpBuffer[];
|
||||
double strDownBuffer[];
|
||||
double strPriceBuffer[];
|
||||
double strStateBuffer[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isStrBullish;
|
||||
bool isStrBearish;
|
||||
|
||||
//
|
||||
bool isStrSwitchedToBullish;
|
||||
bool isStrSwitchedToBearish;
|
||||
|
||||
//
|
||||
// XCHE ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
double le1Buffer[];
|
||||
double se1Buffer[];
|
||||
double le2Buffer[];
|
||||
double se2Buffer[];
|
||||
double le1StartBuffer[];
|
||||
double se1StartBuffer[];
|
||||
double le2StartBuffer[];
|
||||
double se2StartBuffer[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isChe1Bullish;
|
||||
bool isChe1Bearish;
|
||||
|
||||
//
|
||||
bool isChe1SwitchedToBullish;
|
||||
bool isChe1SwitchedToBearish;
|
||||
|
||||
//
|
||||
bool isChe2Bullish;
|
||||
bool isChe2Bearish;
|
||||
|
||||
//
|
||||
bool isChe2SwitchedToBullish;
|
||||
bool isChe2SwitchedToBearish;
|
||||
|
||||
//
|
||||
bool isCheBullish;
|
||||
bool isCheBearish;
|
||||
|
||||
//
|
||||
bool isCheSwitchedToBullish;
|
||||
bool isCheSwitchedToBearish;
|
||||
|
||||
//
|
||||
// X3MA ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
double x3maMidBuffer[];
|
||||
double x3maFastBuffer[];
|
||||
double x3maSlowBuffer[];
|
||||
double x3maMidStateBuffer[];
|
||||
double x3maFastStateBuffer[];
|
||||
double x3maSlowStateBuffer[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isX3MaFastBullish;
|
||||
bool isX3MaFastBearish;
|
||||
bool isX3MaFastNeutural;
|
||||
|
||||
//
|
||||
bool isX3MaMidBullish;
|
||||
bool isX3MaMidBearish;
|
||||
bool isX3MaMidNeutural;
|
||||
|
||||
//
|
||||
bool isX3MaSlowBullish;
|
||||
bool isX3MaSlowBearish;
|
||||
bool isX3MaSlowNeutural;
|
||||
|
||||
//
|
||||
bool isX3MaFastOverMid;
|
||||
bool isX3MaMidOverSlow;
|
||||
|
||||
//
|
||||
bool isX3MaFastUnderMid;
|
||||
bool isX3MaMidUnderSlow;
|
||||
|
||||
//
|
||||
bool isX3MaBullishState;
|
||||
bool isX3MaBearishState;
|
||||
bool isX3MaNeuturalState;
|
||||
|
||||
//
|
||||
bool isX3MaBullishOrdered;
|
||||
bool isX3MaBearishOrdered;
|
||||
|
||||
//
|
||||
bool isX3MaSwitchedToBullishOrdered;
|
||||
bool isX3MaSwitchedToBearishOrdered;
|
||||
|
||||
//
|
||||
bool isX3MaSwitchedToBullishState;
|
||||
bool isX3MaSwitchedToBearishState;
|
||||
bool isX3MaSwitchedToNeuturalState;
|
||||
|
||||
//
|
||||
// XVWAP ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
double vwapMidBuffer[];
|
||||
double vwapFastBuffer[];
|
||||
double vwapSlowBuffer[];
|
||||
double vwapPriceBuffer[];
|
||||
double vwapVolumeBuffer[];
|
||||
double vwapMidStateBuffer[];
|
||||
double vwapFastStateBuffer[];
|
||||
double vwapSlowStateBuffer[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isVWapFastBullish;
|
||||
bool isVWapFastBearish;
|
||||
bool isVWapFastNeutural;
|
||||
|
||||
//
|
||||
bool isVWapMidBullish;
|
||||
bool isVWapMidBearish;
|
||||
bool isVWapMidNeutural;
|
||||
|
||||
//
|
||||
bool isVWapSlowBullish;
|
||||
bool isVWapSlowBearish;
|
||||
bool isVWapSlowNeutural;
|
||||
|
||||
//
|
||||
bool isVWapFastOverMid;
|
||||
bool isVWapMidOverSlow;
|
||||
|
||||
//
|
||||
bool isVWapFastUnderMid;
|
||||
bool isVWapMidUnderSlow;
|
||||
|
||||
//
|
||||
bool isVWapBullishState;
|
||||
bool isVWapBearishState;
|
||||
bool isVWapNeuturalState;
|
||||
|
||||
//
|
||||
bool isVWapBullishOrdered;
|
||||
bool isVWapBearishOrdered;
|
||||
|
||||
//
|
||||
bool isVWapSwitchedToBullishOrdered;
|
||||
bool isVWapSwitchedToBearishOrdered;
|
||||
|
||||
//
|
||||
bool isVWapSwitchedToBullishState;
|
||||
bool isVWapSwitchedToBearishState;
|
||||
bool isVWapSwitchedToNeuturalState;
|
||||
@@ -0,0 +1,408 @@
|
||||
//
|
||||
// XPV ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
|
||||
//
|
||||
Clean(sarBuffer);
|
||||
Clean(cHHBuffer);
|
||||
Clean(cLLBuffer);
|
||||
Clean(sHHBuffer);
|
||||
Clean(sLLBuffer);
|
||||
Clean(mHHBuffer);
|
||||
Clean(mLLBuffer);
|
||||
Clean(lHHBuffer);
|
||||
Clean(lLLBuffer);
|
||||
Clean(hHHBuffer);
|
||||
Clean(hLLBuffer);
|
||||
Clean(peaksBuffer);
|
||||
Clean(valesBuffer);
|
||||
Clean(supportsBuffer);
|
||||
Clean(peaksGoldenBuffer);
|
||||
Clean(valesGoldenBuffer);
|
||||
Clean(resistancesBuffer);
|
||||
Clean(fractalsUpperBuffer);
|
||||
Clean(fractalsLowerBuffer);
|
||||
|
||||
//
|
||||
// Set As Series ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(sarBuffer, true);
|
||||
ArraySetAsSeries(cHHBuffer, true);
|
||||
ArraySetAsSeries(cLLBuffer, true);
|
||||
ArraySetAsSeries(sHHBuffer, true);
|
||||
ArraySetAsSeries(sLLBuffer, true);
|
||||
ArraySetAsSeries(mHHBuffer, true);
|
||||
ArraySetAsSeries(mLLBuffer, true);
|
||||
ArraySetAsSeries(lHHBuffer, true);
|
||||
ArraySetAsSeries(lLLBuffer, true);
|
||||
ArraySetAsSeries(hHHBuffer, true);
|
||||
ArraySetAsSeries(hLLBuffer, true);
|
||||
ArraySetAsSeries(peaksBuffer, true);
|
||||
ArraySetAsSeries(valesBuffer, true);
|
||||
ArraySetAsSeries(supportsBuffer, true);
|
||||
ArraySetAsSeries(peaksGoldenBuffer, true);
|
||||
ArraySetAsSeries(valesGoldenBuffer, true);
|
||||
ArraySetAsSeries(resistancesBuffer, true);
|
||||
ArraySetAsSeries(fractalsUpperBuffer, true);
|
||||
ArraySetAsSeries(fractalsLowerBuffer, true);
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
isNewPeak = false;
|
||||
isNewVale = false;
|
||||
isSarBullish = false;
|
||||
isSarBearish = false;
|
||||
isNewPeakOverLast = false;
|
||||
isNewValeOverLast = false;
|
||||
isNewPeakUnderLast = false;
|
||||
isNewValeUnderLast = false;
|
||||
isSarSwitchedToBullish = false;
|
||||
isSarSwitchedToBearish = false;
|
||||
|
||||
//
|
||||
// XHK ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
|
||||
//
|
||||
Clean(xhkSMLowBuffer);
|
||||
Clean(xhkRawLowBuffer);
|
||||
Clean(xhkSMOpenBuffer);
|
||||
Clean(xhkSMHighBuffer);
|
||||
Clean(xhkRawOpenBuffer);
|
||||
Clean(xhkRawHighBuffer);
|
||||
Clean(xhkSMCloseBuffer);
|
||||
Clean(xhkRawCloseBuffer);
|
||||
|
||||
//
|
||||
// Set As Series ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(xhkSMLowBuffer, true);
|
||||
ArraySetAsSeries(xhkRawLowBuffer, true);
|
||||
ArraySetAsSeries(xhkSMOpenBuffer, true);
|
||||
ArraySetAsSeries(xhkSMHighBuffer, true);
|
||||
ArraySetAsSeries(xhkRawOpenBuffer, true);
|
||||
ArraySetAsSeries(xhkRawHighBuffer, true);
|
||||
ArraySetAsSeries(xhkSMCloseBuffer, true);
|
||||
ArraySetAsSeries(xhkRawCloseBuffer, true);
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
isSMHKBullish = false;
|
||||
isSMHKBearish = false;
|
||||
isRawHKBullish = false;
|
||||
isRawHKBearish = false;
|
||||
isClosedOverSMHK = false;
|
||||
isClosedUnderSMHK = false;
|
||||
isClosedOverRawHK = false;
|
||||
isClosedUnderRawHK = false;
|
||||
isRawHKClosedOverSMHK = false;
|
||||
isRawHKClosedUnderSMHK = false;
|
||||
isSMHKSwitchedToBearish = false;
|
||||
isSMHKSwitchedToBullish = false;
|
||||
isRawHKSwitchedToBullish = false;
|
||||
isRawHKSwitchedToBearish = false;
|
||||
|
||||
//
|
||||
// XMAS ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
|
||||
//
|
||||
Clean(midBuffer);
|
||||
Clean(upperBuffer);
|
||||
Clean(lowerBuffer);
|
||||
|
||||
//
|
||||
// Set As Series ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(midBuffer, true);
|
||||
ArraySetAsSeries(upperBuffer, true);
|
||||
ArraySetAsSeries(lowerBuffer, true);
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
// XATR ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
|
||||
//
|
||||
Clean(rsiBuffer);
|
||||
Clean(atrBuffer);
|
||||
Clean(atrUpperBuffer);
|
||||
Clean(atrLowerBuffer);
|
||||
Clean(rsiChangeBuffer);
|
||||
Clean(atrUpperSMBuffer);
|
||||
Clean(atrLowerSMBuffer);
|
||||
Clean(rsiChangeSMBuffer);
|
||||
Clean(priceChangeBuffer);
|
||||
Clean(priceChangeSMBuffer);
|
||||
|
||||
//
|
||||
// Set As Series ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(rsiBuffer, true);
|
||||
ArraySetAsSeries(atrBuffer, true);
|
||||
ArraySetAsSeries(atrUpperBuffer, true);
|
||||
ArraySetAsSeries(atrLowerBuffer, true);
|
||||
ArraySetAsSeries(rsiChangeBuffer, true);
|
||||
ArraySetAsSeries(atrUpperSMBuffer, true);
|
||||
ArraySetAsSeries(atrLowerSMBuffer, true);
|
||||
ArraySetAsSeries(rsiChangeSMBuffer, true);
|
||||
ArraySetAsSeries(priceChangeBuffer, true);
|
||||
ArraySetAsSeries(priceChangeSMBuffer, true);
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
isRsiInRange = false;
|
||||
isRsiOverSold = false;
|
||||
isRsiOverRsiSM = false;
|
||||
isRsiUnderRsiSM = false;
|
||||
isRsiOverBought = false;
|
||||
isRsiCrossedOverRsiSM = false;
|
||||
isRsiCrossedUnderRsiSM = false;
|
||||
isPriceChangeSMOverRsi = false;
|
||||
isRsiSMOverPriceChange = false;
|
||||
isRsiSMUnderPriceChange = false;
|
||||
isPriceChangeSMUnderRsi = false;
|
||||
isRsiCrossedOverOverSold = false;
|
||||
isRsiCrossedUnderOverSold = false;
|
||||
isRsiCrossedOverOverBought = false;
|
||||
isRsiCrossedUnderOverBought = false;
|
||||
isRsiSMCrossedOverPriceChange = false;
|
||||
isPriceChangeSMCrossedOverRsi = false;
|
||||
isRsiSMCrossedUnderPriceChange = false;
|
||||
isPriceChangeSMCrossedUnderRsi = false;
|
||||
isPriceChangeOverPriceChangeSM = false;
|
||||
isPriceChangeUnderPriceChangeSM = false;
|
||||
isPriceChangeCrossedOverPriceChangeSM = false;
|
||||
isPriceChangeCrossedUnderPriceChangeSM = false;
|
||||
|
||||
//
|
||||
// XSTR ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
|
||||
//
|
||||
Clean(strBuffer);
|
||||
Clean(strUpBuffer);
|
||||
Clean(strDownBuffer);
|
||||
Clean(strPriceBuffer);
|
||||
Clean(strStateBuffer);
|
||||
|
||||
//
|
||||
// Set As Series ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(strBuffer, true);
|
||||
ArraySetAsSeries(strUpBuffer, true);
|
||||
ArraySetAsSeries(strDownBuffer, true);
|
||||
ArraySetAsSeries(strPriceBuffer, true);
|
||||
ArraySetAsSeries(strStateBuffer, true);
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
isStrBullish = false;
|
||||
isStrBearish = false;
|
||||
isStrSwitchedToBullish = false;
|
||||
isStrSwitchedToBearish = false;
|
||||
|
||||
//
|
||||
// XCHE ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
|
||||
//
|
||||
Clean(le1Buffer);
|
||||
Clean(se1Buffer);
|
||||
Clean(le2Buffer);
|
||||
Clean(se2Buffer);
|
||||
Clean(le1StartBuffer);
|
||||
Clean(se1StartBuffer);
|
||||
Clean(le2StartBuffer);
|
||||
Clean(se2StartBuffer);
|
||||
|
||||
//
|
||||
// Set As Series ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(le1Buffer, true);
|
||||
ArraySetAsSeries(se1Buffer, true);
|
||||
ArraySetAsSeries(le2Buffer, true);
|
||||
ArraySetAsSeries(se2Buffer, true);
|
||||
ArraySetAsSeries(le1StartBuffer, true);
|
||||
ArraySetAsSeries(se1StartBuffer, true);
|
||||
ArraySetAsSeries(le2StartBuffer, true);
|
||||
ArraySetAsSeries(se2StartBuffer, true);
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
isCheBullish = false;
|
||||
isCheBearish = false;
|
||||
isChe1Bullish = false;
|
||||
isChe1Bearish = false;
|
||||
isChe2Bullish = false;
|
||||
isChe2Bearish = false;
|
||||
isCheSwitchedToBullish = false;
|
||||
isCheSwitchedToBearish = false;
|
||||
isChe1SwitchedToBullish = false;
|
||||
isChe1SwitchedToBearish = false;
|
||||
isChe2SwitchedToBullish = false;
|
||||
isChe2SwitchedToBearish = false;
|
||||
|
||||
//
|
||||
// X3MA ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
|
||||
//
|
||||
Clean(x3maMidBuffer);
|
||||
Clean(x3maFastBuffer);
|
||||
Clean(x3maSlowBuffer);
|
||||
Clean(x3maMidStateBuffer);
|
||||
Clean(x3maFastStateBuffer);
|
||||
Clean(x3maSlowStateBuffer);
|
||||
|
||||
//
|
||||
// Set As Series ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(x3maMidBuffer, true);
|
||||
ArraySetAsSeries(x3maFastBuffer, true);
|
||||
ArraySetAsSeries(x3maSlowBuffer, true);
|
||||
ArraySetAsSeries(x3maMidStateBuffer, true);
|
||||
ArraySetAsSeries(x3maFastStateBuffer, true);
|
||||
ArraySetAsSeries(x3maSlowStateBuffer, true);
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
isX3MaMidBullish = false;
|
||||
isX3MaMidBearish = false;
|
||||
isX3MaFastBullish = false;
|
||||
isX3MaFastBearish = false;
|
||||
isX3MaMidNeutural = false;
|
||||
isX3MaSlowBullish = false;
|
||||
isX3MaSlowBearish = false;
|
||||
isX3MaFastOverMid = false;
|
||||
isX3MaMidOverSlow = false;
|
||||
isX3MaFastNeutural = false;
|
||||
isX3MaSlowNeutural = false;
|
||||
isX3MaFastUnderMid = false;
|
||||
isX3MaMidUnderSlow = false;
|
||||
isX3MaBullishState = false;
|
||||
isX3MaBearishState = false;
|
||||
isX3MaNeuturalState = false;
|
||||
isX3MaBullishOrdered = false;
|
||||
isX3MaBearishOrdered = false;
|
||||
isX3MaSwitchedToBullishState = false;
|
||||
isX3MaSwitchedToBearishState = false;
|
||||
isX3MaSwitchedToNeuturalState = false;
|
||||
isX3MaSwitchedToBullishOrdered = false;
|
||||
isX3MaSwitchedToBearishOrdered = false;
|
||||
|
||||
//
|
||||
// XVWAP ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
|
||||
//
|
||||
Clean(vwapMidBuffer);
|
||||
Clean(vwapFastBuffer);
|
||||
Clean(vwapSlowBuffer);
|
||||
Clean(vwapPriceBuffer);
|
||||
Clean(vwapVolumeBuffer);
|
||||
Clean(vwapMidStateBuffer);
|
||||
Clean(vwapFastStateBuffer);
|
||||
Clean(vwapSlowStateBuffer);
|
||||
|
||||
//
|
||||
// Set As Series ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(vwapMidBuffer, true);
|
||||
ArraySetAsSeries(vwapFastBuffer, true);
|
||||
ArraySetAsSeries(vwapSlowBuffer, true);
|
||||
ArraySetAsSeries(vwapPriceBuffer, true);
|
||||
ArraySetAsSeries(vwapVolumeBuffer, true);
|
||||
ArraySetAsSeries(vwapMidStateBuffer, true);
|
||||
ArraySetAsSeries(vwapFastStateBuffer, true);
|
||||
ArraySetAsSeries(vwapSlowStateBuffer, true);
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
isVWapMidBullish = false;
|
||||
isVWapMidBearish = false;
|
||||
isVWapMidNeutural = false;
|
||||
isVWapFastBullish = false;
|
||||
isVWapFastBearish = false;
|
||||
isVWapSlowBullish = false;
|
||||
isVWapSlowBearish = false;
|
||||
isVWapFastOverMid = false;
|
||||
isVWapMidOverSlow = false;
|
||||
isVWapFastNeutural = false;
|
||||
isVWapSlowNeutural = false;
|
||||
isVWapFastUnderMid = false;
|
||||
isVWapMidUnderSlow = false;
|
||||
isVWapBullishState = false;
|
||||
isVWapBearishState = false;
|
||||
isVWapNeuturalState = false;
|
||||
isVWapBullishOrdered = false;
|
||||
isVWapBearishOrdered = false;
|
||||
isVWapSwitchedToBullishState = false;
|
||||
isVWapSwitchedToBearishState = false;
|
||||
isVWapSwitchedToNeuturalState = false;
|
||||
isVWapSwitchedToBullishOrdered = false;
|
||||
isVWapSwitchedToBearishOrdered = false;
|
||||
@@ -0,0 +1,96 @@
|
||||
|
||||
//
|
||||
// XDON ...
|
||||
x121Inputs.xdonInputs.showOpen = showAll || false;
|
||||
x121Inputs.xdonInputs.showClose = showAll || false;
|
||||
x121Inputs.xdonInputs.showLow = showAll || false;
|
||||
x121Inputs.xdonInputs.showHigh = showAll || false;
|
||||
|
||||
//
|
||||
// XICH ...
|
||||
x121Inputs.xichInputs.showTenkanSen = showAll || false;
|
||||
x121Inputs.xichInputs.showKijunSen = showAll || false;
|
||||
x121Inputs.xichInputs.showChikouSpan = showAll || false;
|
||||
x121Inputs.xichInputs.showSenkouSpanA = showAll || false;
|
||||
x121Inputs.xichInputs.showSenkouSpanB = showAll || false;
|
||||
x121Inputs.xichInputs.showKumo = showAll || false;
|
||||
|
||||
//
|
||||
// XCC ...
|
||||
x121Inputs.xccInputs.showCandles = showAll || true;
|
||||
|
||||
//
|
||||
// XPV ...
|
||||
|
||||
//
|
||||
x121Inputs.xpvInputs.showSar = showAll || false;
|
||||
x121Inputs.xpvInputs.showPeaks = showAll || true;
|
||||
x121Inputs.xpvInputs.showVales = showAll || true;
|
||||
x121Inputs.xpvInputs.showSupports = showAll || false;
|
||||
x121Inputs.xpvInputs.showResistances = showAll || false;
|
||||
x121Inputs.xpvInputs.showGoldenZones = showAll || true;
|
||||
|
||||
//
|
||||
// XHK ...
|
||||
|
||||
//
|
||||
x121Inputs.xhkInputs.drawRawXHKCandles = showAll || false;
|
||||
x121Inputs.xhkInputs.drawSmoothedXHKCandles = showAll || false;
|
||||
|
||||
//
|
||||
// XMAS ...
|
||||
|
||||
//
|
||||
x121Inputs.xmasInputs.showUpper = showAll || false;
|
||||
x121Inputs.xmasInputs.showMid = showAll || false;
|
||||
x121Inputs.xmasInputs.showLower = showAll || false;
|
||||
|
||||
//
|
||||
// XATR ...
|
||||
x121Inputs.xatrInputs.showATRUpper = showAll || false;
|
||||
x121Inputs.xatrInputs.showATRLower = showAll || false;
|
||||
|
||||
//
|
||||
// XSTR ...
|
||||
x121Inputs.xstrInputs.showStr = showAll || true;
|
||||
x121Inputs.xstrInputs.showStrUpper = showAll || false;
|
||||
x121Inputs.xstrInputs.showStrLower = showAll || false;
|
||||
|
||||
//
|
||||
// XCHE ...
|
||||
x121Inputs.xcheInputs.showLE1 = showAll || false;
|
||||
x121Inputs.xcheInputs.showLE2 = showAll || false;
|
||||
x121Inputs.xcheInputs.showSE1 = showAll || false;
|
||||
x121Inputs.xcheInputs.showSE2 = showAll || false;
|
||||
|
||||
//
|
||||
// XVWAP ...
|
||||
x121Inputs.xvwapInputs.showVWapFast = showAll || false;
|
||||
x121Inputs.xvwapInputs.showVWapMedium = showAll || false;
|
||||
x121Inputs.xvwapInputs.showVWapSlow = showAll || false;
|
||||
|
||||
//
|
||||
// X3MA ...
|
||||
x121Inputs.x3maInputs.showX3MaFast = showAll || true;
|
||||
x121Inputs.x3maInputs.showX3MaMid = showAll || false;
|
||||
x121Inputs.x3maInputs.showX3MaSlow = showAll || false;
|
||||
|
||||
//
|
||||
|
||||
//
|
||||
// x121Inputs.xcheInputs.cheLength = 14;
|
||||
// x121Inputs.xcheInputs.cheLoopback = 7;
|
||||
// x121Inputs.xcheInputs.cheMultiplier1 = 1.5;
|
||||
// x121Inputs.xcheInputs.cheMultiplier2 = 2;
|
||||
|
||||
//
|
||||
// x121Inputs.xstrInputs.strLength = 14;
|
||||
// x121Inputs.xstrInputs.strMultiplier = 1.5;
|
||||
|
||||
//
|
||||
// x121Inputs.xccInputs.upColor = clrLime;
|
||||
// x121Inputs.xccInputs.downColor = clrRed;
|
||||
// x121Inputs.xccInputs.lineColor = CLR_NONE;
|
||||
// x121Inputs.xccInputs.bearishColor = clrRed;
|
||||
// x121Inputs.xccInputs.bullishColor = clrLime;
|
||||
// x121Inputs.xccInputs.volumesColor = clrGreen;
|
||||
@@ -0,0 +1,411 @@
|
||||
// This indicator is created under TechnoBlooms - Innovating Trading Indicators and Strategies.
|
||||
// All rights reserved. Unauthorized copying or distribution is prohibited.
|
||||
// © TechnoBlooms
|
||||
|
||||
//@version=6
|
||||
indicator("AutoFibGauge (TechnoBlooms) ", overlay=true)
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Initialize with a default value that's not NaN
|
||||
//----------------------------------------------------------------------------
|
||||
var float highestHigh = 0.0
|
||||
var float lowestLow = 0.0
|
||||
var float level0 = na
|
||||
var float level100 = na
|
||||
var float level236 = na
|
||||
var float level382 = na
|
||||
var float level500 = na
|
||||
var float level618 = na
|
||||
var float level786 = na
|
||||
|
||||
// Variables for labels
|
||||
var label label0 = na
|
||||
var label label100 = na
|
||||
var label label236 = na
|
||||
var label label382 = na
|
||||
var label label500 = na
|
||||
var label label618 = na
|
||||
var label label786 = na
|
||||
|
||||
var int positionState = 0 // 0 = neutral, 1 = buy, -1 = sell
|
||||
Thermometer_position = input.string("Middle right", title="Position", options=["Middle left", "Middle right"], group='Thermometer Settings')
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
//input how many candles to consider for drawing fibonacci
|
||||
//-------------------------------------------------------------------------------
|
||||
num_of_cand = input(25,"No of Candles to find fib")
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
// Calculate the highest high and lowest low of the last n candles
|
||||
//-------------------------------------------------------------------------------
|
||||
highestHigh := ta.highest(high, num_of_cand)
|
||||
lowestLow := ta.lowest(low, num_of_cand)
|
||||
|
||||
hhBar = ta.highestbars(high, num_of_cand)
|
||||
llBar = ta.lowestbars(low, num_of_cand)
|
||||
|
||||
// Calculate actual bar indices (negative offsets need to be converted)
|
||||
currentBar = bar_index
|
||||
highBarIndex = currentBar + hhBar
|
||||
lowBarIndex = currentBar + llBar
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
// Calculate Simple Moving Average (SMA)
|
||||
//-------------------------------------------------------------------------------
|
||||
SLength = input(20,"Short Length")
|
||||
LLength = input(55,"Long Length") // You can adjust this to change the SMA period
|
||||
Strend = ta.sma(close,SLength)
|
||||
LTrend = ta.sma(close, LLength)
|
||||
|
||||
//-------------------------------------------------------------------------------------------
|
||||
// Determine if we're in an uptrend or downtrend based on the current close relative to SMA
|
||||
//-------------------------------------------------------------------------------------------
|
||||
isUptrend = Strend > LTrend
|
||||
barColor = isUptrend ?#26a6c6 : #9c1f98
|
||||
barcolor(barColor, title="Trend-Based Bar Color")
|
||||
|
||||
|
||||
|
||||
//----------------------------------------
|
||||
//Choose Visibility of MA lines
|
||||
//----------------------------------------
|
||||
showSMAShort = input.bool(false,"Short SMA")
|
||||
showSMALong = input.bool(false,"Long SMA")
|
||||
|
||||
//---------------------------------------------------
|
||||
//Choose which all fib lines to display
|
||||
//---------------------------------------------------
|
||||
showFib0 = input.bool(true, "Fib 0",group = "Show Fib Lines")
|
||||
showFib236 = input.bool(true,"Fib 23.6",group = "Show Fib Lines")
|
||||
showFib382 = input.bool(true,"Fib 38.2",group = "Show Fib Lines")
|
||||
showFib500 = input.bool(true,"Fib 50",group = "Show Fib Lines")
|
||||
showFib618 = input.bool(true,"Fib 61.8",group = "Show Fib Lines")
|
||||
showFib786 = input.bool(true,"Fib 78.6",group = "Show Fib Lines")
|
||||
showFib100 = input.bool(true,"Fib 100",group = "Show Fib Lines")
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Choose background color of thermometer
|
||||
//----------------------------------------------------------------
|
||||
color0 = color.from_gradient(0, 0, 7, color.aqua, color.purple)
|
||||
color1 = color.from_gradient(1, 0, 7, color.aqua, color.purple)
|
||||
color2 = color.from_gradient(2, 0, 7, color.aqua, color.purple)
|
||||
color3 = color.from_gradient(3, 0, 7, color.aqua, color.purple)
|
||||
color4 = color.from_gradient(4, 0, 7, color.aqua, color.purple)
|
||||
color5 = color.from_gradient(5, 0, 7, color.aqua, color.purple)
|
||||
color6 = color.from_gradient(6, 0, 7, color.aqua, color.purple)
|
||||
color7 = color.from_gradient(7, 7, 14, color.purple, color.red)
|
||||
color8 = color.from_gradient(8, 7, 14, color.purple, color.red)
|
||||
color9 = color.from_gradient(9, 7, 14, color.purple, color.red)
|
||||
color10 = color.from_gradient(10, 7, 14, color.purple, color.red)
|
||||
color11 = color.from_gradient(11, 7, 14, color.purple, color.red)
|
||||
color12 = color.from_gradient(12, 7, 14, color.purple, color.red)
|
||||
color13 = color.from_gradient(13, 7, 14,color.purple, color.red)
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Calculate Fibonacci levels based on trend
|
||||
//---------------------------------------------------------------------
|
||||
if not na(highestHigh) and not na(lowestLow) and highestHigh != lowestLow
|
||||
float diff = highestHigh - lowestLow
|
||||
|
||||
if isUptrend
|
||||
level0 := highestHigh
|
||||
level100 := lowestLow
|
||||
level236 := highestHigh - (diff * 0.236)
|
||||
level382 := highestHigh - (diff * 0.382)
|
||||
level500 := highestHigh - (diff * 0.500)
|
||||
level618 := highestHigh - (diff * 0.618)
|
||||
level786 := highestHigh - (diff * 0.786)
|
||||
else
|
||||
level0 := lowestLow
|
||||
level100 := highestHigh
|
||||
level236 := lowestLow + (diff * 0.236)
|
||||
level382 := lowestLow + (diff * 0.382)
|
||||
level500 := lowestLow + (diff * 0.500)
|
||||
level618 := lowestLow + (diff * 0.618)
|
||||
level786 := lowestLow + (diff * 0.786)
|
||||
|
||||
//-------------------------------------------------
|
||||
// Delete old labels
|
||||
//-------------------------------------------------
|
||||
label.delete(label0)
|
||||
label.delete(label100)
|
||||
label.delete(label236)
|
||||
label.delete(label382)
|
||||
label.delete(label500)
|
||||
label.delete(label618)
|
||||
label.delete(label786)
|
||||
|
||||
//----------------------------------------------------
|
||||
// Draw new labels, considering trend
|
||||
//----------------------------------------------------
|
||||
if showFib0
|
||||
label0 := label.new(bar_index+5, level0, text="0.0%", color=color0, textcolor=color.white, style=label.style_label_left)
|
||||
if showFib100
|
||||
label100 := label.new(bar_index+5, level100, text="100.0%", color=color12, textcolor=color.white, style=label.style_label_left)
|
||||
if showFib236
|
||||
label236 := label.new(bar_index+5, level236, text="23.6%", color=color2, textcolor=color.white, style=label.style_label_left)
|
||||
if showFib382
|
||||
label382 := label.new(bar_index+5, level382, text="38.2%", color=color4, textcolor=color.white, style=label.style_label_left)
|
||||
if showFib500
|
||||
label500 := label.new(bar_index+5, level500, text="50.0%", color=color6, textcolor=color.white, style=label.style_label_left)
|
||||
if showFib618
|
||||
label618 := label.new(bar_index+5, level618, text="61.8%", color=color8, textcolor=color.white, style=label.style_label_left)
|
||||
if showFib786
|
||||
label786 := label.new(bar_index+5, level786, text="78.6%", color=color10, textcolor=color.white, style=label.style_label_left)
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Draw straight lines to 20 candles back
|
||||
//---------------------------------------------------------------
|
||||
var line line0 = na
|
||||
var line line100 = na
|
||||
var line line236 = na
|
||||
var line line382 = na
|
||||
var line line500 = na
|
||||
var line line618 = na
|
||||
var line line786 = na
|
||||
|
||||
line.delete(line0)
|
||||
line.delete(line100)
|
||||
line.delete(line236)
|
||||
line.delete(line382)
|
||||
line.delete(line500)
|
||||
line.delete(line618)
|
||||
line.delete(line786)
|
||||
|
||||
if showFib0
|
||||
line0 := line.new(bar_index[num_of_cand], level0, bar_index+5, level0, color=color0, width=1)
|
||||
if showFib100
|
||||
line100 := line.new(bar_index[num_of_cand], level100, bar_index+5, level100, color=color12, width=1)
|
||||
if showFib236
|
||||
line236 := line.new(bar_index[num_of_cand], level236, bar_index+5, level236, color=color2, width=1)
|
||||
if showFib382
|
||||
line382 := line.new(bar_index[num_of_cand], level382, bar_index+5, level382, color=color4, width=1)
|
||||
if showFib500
|
||||
line500 := line.new(bar_index[num_of_cand], level500, bar_index+5, level500, color=color6,width = 1)
|
||||
if showFib618
|
||||
line618 := line.new(bar_index[num_of_cand], level618, bar_index+5, level618, color=color8,width = 1)
|
||||
if showFib786
|
||||
line786 := line.new(bar_index[num_of_cand], level786, bar_index+5, level786, color=color10,width = 1)
|
||||
|
||||
// Draw dashed line for showing Fib range
|
||||
var line fibline = na
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//Highlight Golden Ration region
|
||||
//-------------------------------------------------------------------------
|
||||
var box box1 = na
|
||||
var box box2 = na
|
||||
var box box3 = na
|
||||
var box box2_lower = na
|
||||
var box box2_upper = na
|
||||
var box box3_lower = na
|
||||
var box box3_upper = na
|
||||
// Draw gradient shading with darker areas above and below 61.8%, fading toward 38.2% and 78.6%
|
||||
// Delete previous boxes
|
||||
if not na(box1)
|
||||
box.delete(box1)
|
||||
if not na(box2_lower)
|
||||
box.delete(box2_lower)
|
||||
if not na(box2_upper)
|
||||
box.delete(box2_upper)
|
||||
if not na(box3_lower)
|
||||
box.delete(box3_lower)
|
||||
if not na(box3_upper)
|
||||
box.delete(box3_upper)
|
||||
|
||||
// Base layer: Full range (38.2% to 78.6%) - lightest shade
|
||||
// box1 := box.new(left=bar_index[num_of_cand], top=level786, right=bar_index+5, bottom=level382, bgcolor=color.new(color.yellow, 100), border_width=0)
|
||||
|
||||
// Middle layers: Split around 61.8%, fading outward
|
||||
box2_lower := box.new(left=bar_index[num_of_cand], top=(level618 + level382)/2, right=bar_index+5, bottom=level382, bgcolor=color.new(color.yellow, 100), border_width=0)
|
||||
box2_upper := box.new(left=bar_index[num_of_cand], top=level786, right=bar_index+5, bottom=(level786 + level618)/2, bgcolor=color.new(color.yellow, 100), border_width=0)
|
||||
|
||||
// Core layers: Closest to 61.8%, darkest shade
|
||||
box3_lower := box.new(left=bar_index[num_of_cand], top=level618, right=bar_index+5, bottom=(level618 + level382)/2, bgcolor=color.new(color.yellow, 85), border_width=0)
|
||||
box3_upper := box.new(left=bar_index[num_of_cand], top=(level786 + level618)/2, right=bar_index+5, bottom=level618, bgcolor=color.new(color.yellow, 85), border_width=0)
|
||||
if isUptrend
|
||||
line.delete(fibline)
|
||||
fibline := line.new(lowBarIndex, lowestLow, highBarIndex, highestHigh, color=color.gray, style=line.style_dashed)
|
||||
else
|
||||
line.delete(fibline)
|
||||
fibline := line.new(highBarIndex, highestHigh, lowBarIndex, lowestLow, color=color.gray, style=line.style_dashed)
|
||||
|
||||
//-------------------------
|
||||
// Plot SMA
|
||||
//-------------------------
|
||||
plot(showSMAShort? Strend:na, title="SMA", color=color.blue, linewidth=1)
|
||||
plot(showSMALong? LTrend:na, title="Strend", color=#f321b4, linewidth=1)
|
||||
|
||||
//-----------------------------------------------------------
|
||||
//create labels in Thermometer when trend = 1 (uptrend)
|
||||
//-----------------------------------------------------------
|
||||
var table_position = Thermometer_position == 'Top right' ? position.top_right :
|
||||
Thermometer_position == 'Top left' ? position.top_left :
|
||||
Thermometer_position == 'Top center' ? position.top_center :
|
||||
Thermometer_position == 'Bottom right' ? position.bottom_right :
|
||||
Thermometer_position == 'Bottom left' ? position.bottom_left :
|
||||
Thermometer_position == 'Bottom center' ? position.bottom_center :
|
||||
Thermometer_position == 'Middle right' ? position.middle_right : position.middle_right
|
||||
|
||||
|
||||
tbl = table.new(position=table_position, columns = 100, rows=100)
|
||||
closenum=math.round(close,0)
|
||||
|
||||
if level0 < level100
|
||||
|
||||
table.cell(tbl,0,0,text = label100.get_text() , text_color = #f83f8c)
|
||||
table.cell(tbl,0,11,text = label236.get_text() ,text_color = #f83f8c)
|
||||
table.cell(tbl,0,8,text = label382.get_text() ,text_color = #f83f8c)
|
||||
table.cell(tbl,0,5,text = label618.get_text() , text_color =#f83f8c)
|
||||
table.cell(tbl,0,2,text = label786.get_text(),text_color = #f83f8c)
|
||||
table.cell(tbl,0,13,text = label0.get_text(), text_color = #f83f8c)
|
||||
|
||||
|
||||
table.cell(tbl,2,13,text = str.tostring(level0," #,###"), text_color = #f83f8c)
|
||||
table.cell(tbl,2,11,text = str.tostring(level236, " #,###"),text_color = #f83f8c)
|
||||
table.cell(tbl,2,8,text = str.tostring(level382, " #,###"),text_color = #f83f8c)
|
||||
table.cell(tbl,2,5,text = str.tostring(level618, " #,###"), text_color =#f83f8c)
|
||||
table.cell(tbl,2,2,text = str.tostring(level786, " #,###"),text_color = #f83f8c)
|
||||
table.cell(tbl,2,0,text = str.tostring(level100," #,###"), text_color = #f83f8c)
|
||||
|
||||
for i = 0 to 13 by 1
|
||||
table.cell(tbl, 1, i, "", bgcolor = i < 8 ? color.from_gradient(i, 0, 7, color.aqua, color.purple) : color.from_gradient(i, 7, 14, color.purple, color.red))
|
||||
|
||||
var reg = 0
|
||||
bkcolor = color.aqua
|
||||
|
||||
if closenum > level0 and closenum < level236
|
||||
reg := 12
|
||||
if closenum > level236 and closenum < level382
|
||||
reg := 9
|
||||
if closenum > level382 and closenum < level618
|
||||
reg := 6
|
||||
if closenum > level618 and closenum < level786
|
||||
reg := 3
|
||||
if closenum > level786 and closenum < level100
|
||||
reg := 1
|
||||
if closenum == level0
|
||||
reg := 0
|
||||
if closenum == level236
|
||||
reg := 11
|
||||
if closenum == level382
|
||||
reg := 8
|
||||
if closenum == level618
|
||||
reg := 5
|
||||
if closenum == level786
|
||||
reg := 2
|
||||
|
||||
|
||||
if reg == 12
|
||||
bkcolor := color12
|
||||
if reg == 9
|
||||
bkcolor := color9
|
||||
if reg == 6
|
||||
bkcolor := color6
|
||||
if reg == 3
|
||||
bkcolor := color3
|
||||
if reg == 1
|
||||
bkcolor := color1
|
||||
if reg == 2
|
||||
bkcolor := color2
|
||||
|
||||
if reg == 4
|
||||
bkcolor := color4
|
||||
if reg == 5
|
||||
bkcolor := color5
|
||||
if reg == 7
|
||||
bkcolor := color7
|
||||
if reg == 8
|
||||
bkcolor := color8
|
||||
if reg == 10
|
||||
bkcolor := color10
|
||||
if reg == 11
|
||||
bkcolor := color11
|
||||
if reg == 13
|
||||
bkcolor := color13
|
||||
|
||||
|
||||
table.cell(tbl,1,reg,"🌕", text_size = size.small,bgcolor = bkcolor)
|
||||
//-----------------------------------------------------------
|
||||
//create labels in Thermometer
|
||||
//-----------------------------------------------------------
|
||||
else
|
||||
table.cell(tbl,0,13,text = label100.get_text() , text_color = #f83f8c)
|
||||
table.cell(tbl,0,2,text = label236.get_text() ,text_color = #f83f8c)
|
||||
table.cell(tbl,0,5,text = label382.get_text() ,text_color = #f83f8c)
|
||||
table.cell(tbl,0,8,text = label618.get_text() , text_color =#f83f8c)
|
||||
table.cell(tbl,0,11,text = label786.get_text(),text_color = #f83f8c)
|
||||
table.cell(tbl,0,0,text = label0.get_text(), text_color = #f83f8c)
|
||||
|
||||
|
||||
table.cell(tbl,2,0,text = str.tostring(level0," #,###"), text_color = #f83f8c)
|
||||
table.cell(tbl,2,2,text = str.tostring(level236, " #,###"),text_color = #f83f8c)
|
||||
table.cell(tbl,2,5,text = str.tostring(level382, " #,###"),text_color = #f83f8c)
|
||||
table.cell(tbl,2,8,text = str.tostring(level618, " #,###"), text_color =#f83f8c)
|
||||
table.cell(tbl,2,11,text = str.tostring(level786, " #,###"),text_color = #f83f8c)
|
||||
table.cell(tbl,2,13,text = str.tostring(level100," #,###"), text_color = #f83f8c)
|
||||
|
||||
for i = 0 to 13 by 1
|
||||
table.cell(tbl, 1, i, "", bgcolor = i < 8 ? color.from_gradient(i, 0, 7, color.aqua, color.purple) : color.from_gradient(i, 7, 14, color.purple, color.red))
|
||||
|
||||
var reg = 0
|
||||
bkcolor = color.aqua
|
||||
|
||||
if closenum > level100 and closenum < level786
|
||||
reg := 12
|
||||
if closenum > level786 and closenum < level618
|
||||
reg := 9
|
||||
if closenum > level618 and closenum < level382
|
||||
reg := 6
|
||||
if closenum > level382 and closenum < level236
|
||||
reg := 3
|
||||
if closenum > level236 and closenum < level0
|
||||
reg := 1
|
||||
if closenum == level0
|
||||
reg := 0
|
||||
if closenum == level236
|
||||
reg := 11
|
||||
if closenum == level382
|
||||
reg := 8
|
||||
if closenum == level618
|
||||
reg := 5
|
||||
if closenum == level786
|
||||
reg := 2
|
||||
|
||||
|
||||
if reg == 12
|
||||
bkcolor := color12
|
||||
if reg == 9
|
||||
bkcolor := color9
|
||||
if reg == 6
|
||||
bkcolor := color6
|
||||
if reg == 3
|
||||
bkcolor := color3
|
||||
if reg == 1
|
||||
bkcolor := color1
|
||||
if reg == 2
|
||||
bkcolor := color2
|
||||
|
||||
if reg == 4
|
||||
bkcolor := color4
|
||||
if reg == 5
|
||||
bkcolor := color5
|
||||
if reg == 7
|
||||
bkcolor := color7
|
||||
if reg == 8
|
||||
bkcolor := color8
|
||||
if reg == 10
|
||||
bkcolor := color10
|
||||
if reg == 11
|
||||
bkcolor := color11
|
||||
if reg == 13
|
||||
bkcolor := color13
|
||||
|
||||
|
||||
table.cell(tbl,1,reg,"🌕", text_size = size.small,bgcolor = bkcolor)
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
|
||||
// © LonesomeTheBlue
|
||||
|
||||
//@version=4
|
||||
study("Cumulative Delta Volume", "CDV")
|
||||
linestyle = input(defval = 'Candle', title = "Style", options = ['Candle', 'Line'])
|
||||
hacandle = input(defval = true, title = "Heikin Ashi Candles?")
|
||||
showma1 = input(defval = false, title = "SMA 1", inline = "ma1")
|
||||
ma1len = input(defval = 50, title = "", minval = 1, inline = "ma1")
|
||||
ma1col = input(defval = color.lime, title = "", inline = "ma1")
|
||||
showma2 = input(defval = false, title = "SMA 2", inline = "ma2")
|
||||
ma2len = input(defval = 200, title = "", minval = 1, inline = "ma2")
|
||||
ma2col = input(defval = color.red, title = "", inline = "ma2")
|
||||
showema1 = input(defval = false, title = "EMA 1", inline = "ema1")
|
||||
ema1len = input(defval = 50, title = "", minval = 1, inline = "ema1")
|
||||
ema1col = input(defval = color.lime, title = "", inline = "ema1")
|
||||
showema2 = input(defval = false, title = "EMA 2", inline = "ema2")
|
||||
ema2len = input(defval = 200, title = "", minval = 1, inline = "ema2")
|
||||
ema2col = input(defval = color.red, title = "", inline = "ema2")
|
||||
colorup = input(defval = color.lime, title = "Body", inline = "bcol")
|
||||
colordown = input(defval = color.red, title = "", inline = "bcol")
|
||||
bcolup = input(defval = #74e05e, title = "Border", inline = "bocol")
|
||||
bcoldown = input(defval = #ffad7d, title = "", inline = "bocol")
|
||||
wcolup = input(defval = #b5b5b8, title = "Wicks", inline = "wcol")
|
||||
wcoldown = input(defval = #b5b5b8, title = "", inline = "wcol")
|
||||
|
||||
tw = high - max(open, close)
|
||||
bw = min(open, close) - low
|
||||
body = abs(close - open)
|
||||
|
||||
_rate(cond) =>
|
||||
ret = 0.5 * (tw + bw + (cond ? 2 * body : 0)) / (tw + bw + body)
|
||||
ret := nz(ret) == 0 ? 0.5 : ret
|
||||
ret
|
||||
|
||||
deltaup = volume * _rate(open <= close)
|
||||
deltadown = volume * _rate(open > close)
|
||||
delta = close >= open ? deltaup : -deltadown
|
||||
cumdelta = cum(delta)
|
||||
float ctl = na
|
||||
float o = na
|
||||
float h = na
|
||||
float l = na
|
||||
float c = na
|
||||
if linestyle == 'Candle'
|
||||
o := cumdelta[1]
|
||||
h := max(cumdelta, cumdelta[1])
|
||||
l := min(cumdelta, cumdelta[1])
|
||||
c := cumdelta
|
||||
ctl
|
||||
else
|
||||
ctl := cumdelta
|
||||
|
||||
plot(ctl, title = "CDV Line", color = color.blue, linewidth = 2)
|
||||
|
||||
float haclose = na
|
||||
float haopen = na
|
||||
float hahigh = na
|
||||
float halow = na
|
||||
haclose := (o + h + l + c) / 4
|
||||
haopen := na(haopen[1]) ? (o + c) / 2 : (haopen[1] + haclose[1]) / 2
|
||||
hahigh := max(h, max(haopen, haclose))
|
||||
halow := min(l, min(haopen, haclose))
|
||||
|
||||
c_ = hacandle ? haclose : c
|
||||
o_ = hacandle ? haopen : o
|
||||
h_ = hacandle ? hahigh : h
|
||||
l_ = hacandle ? halow : l
|
||||
|
||||
plotcandle(o_, h_, l_, c_, title='CDV Candles', color = o_ <= c_ ? colorup : colordown, bordercolor = o_ <= c_ ? bcolup : bcoldown, wickcolor = o_ <= c_ ? bcolup : bcoldown)
|
||||
|
||||
plot(showma1 and linestyle == "Candle" ? sma(c_, ma1len) : na, title = "SMA 1", color = ma1col)
|
||||
plot(showma2 and linestyle == "Candle" ? sma(c_, ma2len) : na, title = "SMA 2", color = ma2col)
|
||||
plot(showema1 and linestyle == "Candle" ? ema(c_, ema1len) : na, title = "EMA 1", color = ema1col)
|
||||
plot(showema2 and linestyle == "Candle" ? ema(c_, ema2len) : na, title = "EMA 2", color = ema2col)
|
||||
@@ -0,0 +1,37 @@
|
||||
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
|
||||
// © Ankit_1618
|
||||
|
||||
//@version=4
|
||||
study("Cumulative Volume Delta")
|
||||
|
||||
upper_wick = close>open ? high-close : high-open
|
||||
lower_wick = close>open ? open-low : close-low
|
||||
spread = high-low
|
||||
body_length = spread - (upper_wick + lower_wick)
|
||||
|
||||
percent_upper_wick = upper_wick/spread
|
||||
percent_lower_wick = lower_wick/spread
|
||||
percent_body_length = body_length/spread
|
||||
|
||||
|
||||
buying_volume = close>open ? (percent_body_length + (percent_upper_wick + percent_lower_wick)/2)*volume : ((percent_upper_wick + percent_lower_wick)/2) * volume
|
||||
selling_volume = close<open ? (percent_body_length + (percent_upper_wick + percent_lower_wick)/2)*volume : ((percent_upper_wick + percent_lower_wick)/2) * volume
|
||||
|
||||
cumulation_length = input(14)
|
||||
cumulative_buying_volume = ema(buying_volume,cumulation_length)
|
||||
cumulative_selling_volume = ema(selling_volume,cumulation_length)
|
||||
|
||||
fill_color = cumulative_buying_volume > cumulative_selling_volume ? color.green : cumulative_buying_volume < cumulative_selling_volume ? color.red : color.yellow
|
||||
|
||||
pb = plot(cumulative_buying_volume, color=color.green , transp=70)
|
||||
ps = plot(cumulative_selling_volume, color=color.red , transp=70)
|
||||
|
||||
fill(pb, ps, color = fill_color)
|
||||
|
||||
volume_strength_wave = cumulative_buying_volume > cumulative_selling_volume ? cumulative_buying_volume : cumulative_selling_volume
|
||||
ema_volume_strength_wave = ema(volume_strength_wave , cumulation_length)
|
||||
plot(ema_volume_strength_wave, color=color.gray, transp=80)
|
||||
|
||||
cumulative_volume_delta = cumulative_buying_volume - cumulative_selling_volume
|
||||
plot(cumulative_volume_delta, color= cumulative_volume_delta>0 ? color.green : color.red, style=plot.style_columns, transp=61)
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| CumulativeDelta.mq5 |
|
||||
//| Copyright © 2023, YourName |
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "YourName"
|
||||
#property link "https://www.yourwebsite.com"
|
||||
#property version "1.00"
|
||||
|
||||
//
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
//--- Plot settings for Line
|
||||
#property indicator_label1 "Cumulative Delta"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrYellow
|
||||
|
||||
//
|
||||
//--- Plot settings for Histogram
|
||||
#property indicator_label2 "Delta"
|
||||
#property indicator_type2 DRAW_HISTOGRAM
|
||||
#property indicator_color2 clrGray
|
||||
|
||||
//
|
||||
//--- Plot settings for Moving Average line
|
||||
#property indicator_label3 "Signal"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrOrchid
|
||||
|
||||
//
|
||||
//--- Input parameters
|
||||
input int MAPeriod = 14; // Period for the moving average
|
||||
|
||||
//
|
||||
//--- Indicator buffers
|
||||
double MABuffer[];
|
||||
double DeltaBuffer[];
|
||||
double CumulativeDeltaBuffer[];
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Attach buffer to the indicator
|
||||
SetIndexBuffer(2, MABuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(1, DeltaBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(0, CumulativeDeltaBuffer, INDICATOR_DATA);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, "Cumulative Delta");
|
||||
|
||||
//
|
||||
return (INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Start from the first uncalculated bar
|
||||
int start = MathMax(prev_calculated - 1, 0);
|
||||
|
||||
//
|
||||
// Loop through bars
|
||||
for (int i = start; i < rates_total; i++)
|
||||
{
|
||||
//
|
||||
// Calculate Delta based on bar-level data
|
||||
double delta = 0.0;
|
||||
if (close[i] > open[i])
|
||||
{
|
||||
delta = (double)tick_volume[i]; // Buying pressure (bullish bar)
|
||||
}
|
||||
else if (close[i] < open[i])
|
||||
{
|
||||
delta = -(double)tick_volume[i]; // Selling pressure (bearish bar)
|
||||
}
|
||||
|
||||
//
|
||||
// Accumulate cumulative delta
|
||||
if (i == 0)
|
||||
{
|
||||
//
|
||||
DeltaBuffer[i] = delta;
|
||||
CumulativeDeltaBuffer[i] = delta; // First bar starts with delta
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
DeltaBuffer[i] = DeltaBuffer[i - 1] + delta;
|
||||
CumulativeDeltaBuffer[i] = CumulativeDeltaBuffer[i - 1] + delta;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Moving Average of Cumulative Delta
|
||||
if (i >= MAPeriod - 1)
|
||||
{
|
||||
//
|
||||
double sum = 0.0;
|
||||
for (int j = 0; j < MAPeriod; j++)
|
||||
{
|
||||
sum += CumulativeDeltaBuffer[i - j];
|
||||
}
|
||||
|
||||
//
|
||||
MABuffer[i] = sum / MAPeriod; // Simple Moving Average
|
||||
}
|
||||
else
|
||||
{
|
||||
MABuffer[i] = EMPTY_VALUE; // Not enough data for MA
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return (rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,347 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| ForexSessionHighLowIndicator.mq5 |
|
||||
//| Copyright 2023, MetaQuotes Software Corp. |
|
||||
//| https://www.metaquotes.net/ |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2023, MetaQuotes Software Corp."
|
||||
#property link "https://www.metaquotes.net/"
|
||||
#property version "1.00"
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 8
|
||||
#property indicator_plots 4
|
||||
|
||||
// Session times (in broker time)
|
||||
input string SydneyStart = "22:00"; // Sydney session start (GMT+10 when DST)
|
||||
input string SydneyEnd = "07:00"; // Sydney session end
|
||||
input string TokyoStart = "00:00"; // Tokyo session start (GMT+9)
|
||||
input string TokyoEnd = "09:00"; // Tokyo session end
|
||||
input string LondonStart = "08:00"; // London session start (GMT+0)
|
||||
input string LondonEnd = "17:00"; // London session end
|
||||
input string NewYorkStart = "13:00"; // New York session start (GMT-4/5)
|
||||
input string NewYorkEnd = "22:00"; // New York session end
|
||||
|
||||
input color SydneyColor = clrDodgerBlue; // Sydney session color
|
||||
input color TokyoColor = clrMediumSeaGreen; // Tokyo session color
|
||||
input color LondonColor = clrGold; // London session color
|
||||
input color NewYorkColor = clrTomato; // New York session color
|
||||
input int LineWidth = 1; // Line width
|
||||
input bool ShowLabels = true; // Show session labels
|
||||
input bool ShowHighLow = true; // Show high/low prices
|
||||
|
||||
// Buffers for session high/low
|
||||
double SydneyHighBuffer[];
|
||||
double SydneyLowBuffer[];
|
||||
double TokyoHighBuffer[];
|
||||
double TokyoLowBuffer[];
|
||||
double LondonHighBuffer[];
|
||||
double LondonLowBuffer[];
|
||||
double NewYorkHighBuffer[];
|
||||
double NewYorkLowBuffer[];
|
||||
|
||||
// Global variables
|
||||
int SydneyStartHour, SydneyStartMin;
|
||||
int SydneyEndHour, SydneyEndMin;
|
||||
int TokyoStartHour, TokyoStartMin;
|
||||
int TokyoEndHour, TokyoEndMin;
|
||||
int LondonStartHour, LondonStartMin;
|
||||
int LondonEndHour, LondonEndMin;
|
||||
int NewYorkStartHour, NewYorkStartMin;
|
||||
int NewYorkEndHour, NewYorkEndMin;
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
// Parse session times
|
||||
ParseTime(SydneyStart, SydneyStartHour, SydneyStartMin);
|
||||
ParseTime(SydneyEnd, SydneyEndHour, SydneyEndMin);
|
||||
ParseTime(TokyoStart, TokyoStartHour, TokyoStartMin);
|
||||
ParseTime(TokyoEnd, TokyoEndHour, TokyoEndMin);
|
||||
ParseTime(LondonStart, LondonStartHour, LondonStartMin);
|
||||
ParseTime(LondonEnd, LondonEndHour, LondonEndMin);
|
||||
ParseTime(NewYorkStart, NewYorkStartHour, NewYorkStartMin);
|
||||
ParseTime(NewYorkEnd, NewYorkEndHour, NewYorkEndMin);
|
||||
|
||||
// Set indicator properties
|
||||
SetIndexBuffer(0, SydneyHighBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(1, SydneyLowBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(2, TokyoHighBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(3, TokyoLowBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(4, LondonHighBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(5, LondonLowBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(6, NewYorkHighBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(7, NewYorkLowBuffer, INDICATOR_DATA);
|
||||
|
||||
// Set drawing styles
|
||||
PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_LINE);
|
||||
PlotIndexSetInteger(0, PLOT_LINE_COLOR, SydneyColor);
|
||||
PlotIndexSetInteger(0, PLOT_LINE_WIDTH, LineWidth);
|
||||
PlotIndexSetString(0, PLOT_LABEL, "Sydney High");
|
||||
|
||||
PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_LINE);
|
||||
PlotIndexSetInteger(1, PLOT_LINE_COLOR, SydneyColor);
|
||||
PlotIndexSetInteger(1, PLOT_LINE_STYLE, STYLE_DOT);
|
||||
PlotIndexSetInteger(1, PLOT_LINE_WIDTH, LineWidth);
|
||||
PlotIndexSetString(1, PLOT_LABEL, "Sydney Low");
|
||||
|
||||
PlotIndexSetInteger(2, PLOT_DRAW_TYPE, DRAW_LINE);
|
||||
PlotIndexSetInteger(2, PLOT_LINE_COLOR, TokyoColor);
|
||||
PlotIndexSetInteger(2, PLOT_LINE_WIDTH, LineWidth);
|
||||
PlotIndexSetString(2, PLOT_LABEL, "Tokyo High");
|
||||
|
||||
PlotIndexSetInteger(3, PLOT_DRAW_TYPE, DRAW_LINE);
|
||||
PlotIndexSetInteger(3, PLOT_LINE_COLOR, TokyoColor);
|
||||
PlotIndexSetInteger(3, PLOT_LINE_STYLE, STYLE_DOT);
|
||||
PlotIndexSetInteger(3, PLOT_LINE_WIDTH, LineWidth);
|
||||
PlotIndexSetString(3, PLOT_LABEL, "Tokyo Low");
|
||||
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
// Check if we have enough data
|
||||
if(rates_total < 2) return(0);
|
||||
|
||||
// Set all buffers to EMPTY_VALUE initially
|
||||
ArrayInitialize(SydneyHighBuffer, EMPTY_VALUE);
|
||||
ArrayInitialize(SydneyLowBuffer, EMPTY_VALUE);
|
||||
ArrayInitialize(TokyoHighBuffer, EMPTY_VALUE);
|
||||
ArrayInitialize(TokyoLowBuffer, EMPTY_VALUE);
|
||||
ArrayInitialize(LondonHighBuffer, EMPTY_VALUE);
|
||||
ArrayInitialize(LondonLowBuffer, EMPTY_VALUE);
|
||||
ArrayInitialize(NewYorkHighBuffer, EMPTY_VALUE);
|
||||
ArrayInitialize(NewYorkLowBuffer, EMPTY_VALUE);
|
||||
|
||||
// Calculate start position
|
||||
int start = (prev_calculated == 0) ? 0 : prev_calculated - 1;
|
||||
|
||||
// Main calculation loop
|
||||
for(int i = start; i < rates_total; i++)
|
||||
{
|
||||
MqlDateTime dt;
|
||||
TimeToStruct(time[i], dt);
|
||||
|
||||
// Check if current time is within any session
|
||||
bool inSydney = IsInSession(dt.hour, dt.min, SydneyStartHour, SydneyStartMin, SydneyEndHour, SydneyEndMin);
|
||||
bool inTokyo = IsInSession(dt.hour, dt.min, TokyoStartHour, TokyoStartMin, TokyoEndHour, TokyoEndMin);
|
||||
bool inLondon = IsInSession(dt.hour, dt.min, LondonStartHour, LondonStartMin, LondonEndHour, LondonEndMin);
|
||||
bool inNewYork = IsInSession(dt.hour, dt.min, NewYorkStartHour, NewYorkStartMin, NewYorkEndHour, NewYorkEndMin);
|
||||
|
||||
// Find session boundaries and calculate high/low
|
||||
if(inSydney)
|
||||
{
|
||||
CalculateSessionHighLow(i, rates_total, time, high, low, SydneyHighBuffer, SydneyLowBuffer, SydneyStartHour, SydneyStartMin, SydneyEndHour, SydneyEndMin);
|
||||
}
|
||||
|
||||
if(inTokyo)
|
||||
{
|
||||
CalculateSessionHighLow(i, rates_total, time, high, low, TokyoHighBuffer, TokyoLowBuffer, TokyoStartHour, TokyoStartMin, TokyoEndHour, TokyoEndMin);
|
||||
}
|
||||
|
||||
if(inLondon)
|
||||
{
|
||||
CalculateSessionHighLow(i, rates_total, time, high, low, LondonHighBuffer, LondonLowBuffer, LondonStartHour, LondonStartMin, LondonEndHour, LondonEndMin);
|
||||
}
|
||||
|
||||
if(inNewYork)
|
||||
{
|
||||
CalculateSessionHighLow(i, rates_total, time, high, low, NewYorkHighBuffer, NewYorkLowBuffer, NewYorkStartHour, NewYorkStartMin, NewYorkEndHour, NewYorkEndMin);
|
||||
}
|
||||
|
||||
// Add labels if enabled
|
||||
if(ShowLabels && i == rates_total - 1)
|
||||
{
|
||||
AddSessionLabels(time[rates_total-1], high[rates_total-1], low[rates_total-1]);
|
||||
}
|
||||
}
|
||||
|
||||
return(rates_total);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Parse time string into hours and minutes |
|
||||
//+------------------------------------------------------------------+
|
||||
void ParseTime(string timeStr, int &hour, int &min)
|
||||
{
|
||||
string parts[];
|
||||
StringSplit(timeStr, ':', parts);
|
||||
hour = (int)StringToInteger(parts[0]);
|
||||
min = (ArraySize(parts) > 1) ? (int)StringToInteger(parts[1]) : 0;
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Check if current time is within a session |
|
||||
//+------------------------------------------------------------------+
|
||||
bool IsInSession(int currentHour, int currentMin, int startHour, int startMin, int endHour, int endMin)
|
||||
{
|
||||
int currentTime = currentHour * 100 + currentMin;
|
||||
int sessionStart = startHour * 100 + startMin;
|
||||
int sessionEnd = endHour * 100 + endMin;
|
||||
|
||||
// Handle sessions that cross midnight
|
||||
if(sessionStart > sessionEnd)
|
||||
{
|
||||
return(currentTime >= sessionStart || currentTime < sessionEnd);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(currentTime >= sessionStart && currentTime < sessionEnd);
|
||||
}
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Calculate session high and low |
|
||||
//+------------------------------------------------------------------+
|
||||
void CalculateSessionHighLow(int index, int rates_total, const datetime &time[], const double &high[], const double &low[],
|
||||
double &highBuffer[], double &lowBuffer[], int startHour, int startMin, int endHour, int endMin)
|
||||
{
|
||||
// Find the start of the current session
|
||||
MqlDateTime currentDt, sessionStartDt;
|
||||
TimeToStruct(time[index], currentDt);
|
||||
TimeToStruct(time[index], sessionStartDt);
|
||||
|
||||
sessionStartDt.hour = startHour;
|
||||
sessionStartDt.min = startMin;
|
||||
sessionStartDt.sec = 0;
|
||||
|
||||
datetime sessionStartTime = StructToTime(sessionStartDt);
|
||||
|
||||
// If session crosses midnight, adjust the start time
|
||||
int sessionStart = startHour * 100 + startMin;
|
||||
int sessionEnd = endHour * 100 + endMin;
|
||||
|
||||
if(sessionStart > sessionEnd)
|
||||
{
|
||||
// Session crosses midnight, check if we need to use previous day
|
||||
int currentTime = currentDt.hour * 100 + currentDt.min;
|
||||
if(currentTime < sessionEnd)
|
||||
{
|
||||
sessionStartTime -= 86400; // Subtract one day
|
||||
}
|
||||
}
|
||||
|
||||
// Find the bar index for the session start
|
||||
int sessionStartIndex = iBarShift(NULL, 0, sessionStartTime);
|
||||
if(sessionStartIndex < 0) sessionStartIndex = 0;
|
||||
|
||||
// Calculate high and low for the session
|
||||
double sessionHigh = high[sessionStartIndex];
|
||||
double sessionLow = low[sessionStartIndex];
|
||||
|
||||
for(int j = sessionStartIndex; j <= index; j++)
|
||||
{
|
||||
if(j >= rates_total) continue;
|
||||
|
||||
if(high[j] > sessionHigh) sessionHigh = high[j];
|
||||
if(low[j] < sessionLow) sessionLow = low[j];
|
||||
}
|
||||
|
||||
// Store the values in buffers
|
||||
highBuffer[index] = sessionHigh;
|
||||
lowBuffer[index] = sessionLow;
|
||||
|
||||
// If ShowHighLow is enabled, draw the levels
|
||||
if(ShowHighLow && index == rates_total - 1)
|
||||
{
|
||||
string sessionName = "";
|
||||
color sessionClr = clrNONE;
|
||||
|
||||
if(startHour == SydneyStartHour && startMin == SydneyStartMin)
|
||||
{
|
||||
sessionName = "Sydney";
|
||||
sessionClr = SydneyColor;
|
||||
}
|
||||
else if(startHour == TokyoStartHour && startMin == TokyoStartMin)
|
||||
{
|
||||
sessionName = "Tokyo";
|
||||
sessionClr = TokyoColor;
|
||||
}
|
||||
else if(startHour == LondonStartHour && startMin == LondonStartMin)
|
||||
{
|
||||
sessionName = "London";
|
||||
sessionClr = LondonColor;
|
||||
}
|
||||
else if(startHour == NewYorkStartHour && startMin == NewYorkStartMin)
|
||||
{
|
||||
sessionName = "NewYork";
|
||||
sessionClr = NewYorkColor;
|
||||
}
|
||||
|
||||
if(sessionName != "")
|
||||
{
|
||||
string highLabel = sessionName + " High: " + DoubleToString(sessionHigh, _Digits);
|
||||
string lowLabel = sessionName + " Low: " + DoubleToString(sessionLow, _Digits);
|
||||
|
||||
ObjectCreate(0, highLabel, OBJ_HLINE, 0, 0, sessionHigh);
|
||||
ObjectSetInteger(0, highLabel, OBJPROP_COLOR, sessionClr);
|
||||
ObjectSetInteger(0, highLabel, OBJPROP_WIDTH, LineWidth);
|
||||
ObjectSetInteger(0, highLabel, OBJPROP_BACK, true);
|
||||
|
||||
ObjectCreate(0, lowLabel, OBJ_HLINE, 0, 0, sessionLow);
|
||||
ObjectSetInteger(0, lowLabel, OBJPROP_COLOR, sessionClr);
|
||||
ObjectSetInteger(0, lowLabel, OBJPROP_WIDTH, LineWidth);
|
||||
ObjectSetInteger(0, lowLabel, OBJPROP_STYLE, STYLE_DOT);
|
||||
ObjectSetInteger(0, lowLabel, OBJPROP_BACK, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Add session labels to the chart |
|
||||
//+------------------------------------------------------------------+
|
||||
void AddSessionLabels(datetime currentTime, double currentHigh, double currentLow)
|
||||
{
|
||||
MqlDateTime dt;
|
||||
TimeToStruct(currentTime, dt);
|
||||
|
||||
// Remove previous labels
|
||||
ObjectsDeleteAll(0, "SessionLabel_");
|
||||
|
||||
if(IsInSession(dt.hour, dt.min, SydneyStartHour, SydneyStartMin, SydneyEndHour, SydneyEndMin))
|
||||
{
|
||||
ObjectCreate(0, "SessionLabel_Sydney", OBJ_TEXT, 0, currentTime, currentHigh + 10 * _Point);
|
||||
ObjectSetString(0, "SessionLabel_Sydney", OBJPROP_TEXT, "Sydney Session");
|
||||
ObjectSetInteger(0, "SessionLabel_Sydney", OBJPROP_COLOR, SydneyColor);
|
||||
ObjectSetInteger(0, "SessionLabel_Sydney", OBJPROP_ANCHOR, ANCHOR_LEFT_UPPER);
|
||||
}
|
||||
|
||||
if(IsInSession(dt.hour, dt.min, TokyoStartHour, TokyoStartMin, TokyoEndHour, TokyoEndMin))
|
||||
{
|
||||
ObjectCreate(0, "SessionLabel_Tokyo", OBJ_TEXT, 0, currentTime, currentHigh + 20 * _Point);
|
||||
ObjectSetString(0, "SessionLabel_Tokyo", OBJPROP_TEXT, "Tokyo Session");
|
||||
ObjectSetInteger(0, "SessionLabel_Tokyo", OBJPROP_COLOR, TokyoColor);
|
||||
ObjectSetInteger(0, "SessionLabel_Tokyo", OBJPROP_ANCHOR, ANCHOR_LEFT_UPPER);
|
||||
}
|
||||
|
||||
if(IsInSession(dt.hour, dt.min, LondonStartHour, LondonStartMin, LondonEndHour, LondonEndMin))
|
||||
{
|
||||
ObjectCreate(0, "SessionLabel_London", OBJ_TEXT, 0, currentTime, currentHigh + 30 * _Point);
|
||||
ObjectSetString(0, "SessionLabel_London", OBJPROP_TEXT, "London Session");
|
||||
ObjectSetInteger(0, "SessionLabel_London", OBJPROP_COLOR, LondonColor);
|
||||
ObjectSetInteger(0, "SessionLabel_London", OBJPROP_ANCHOR, ANCHOR_LEFT_UPPER);
|
||||
}
|
||||
|
||||
if(IsInSession(dt.hour, dt.min, NewYorkStartHour, NewYorkStartMin, NewYorkEndHour, NewYorkEndMin))
|
||||
{
|
||||
ObjectCreate(0, "SessionLabel_NewYork", OBJ_TEXT, 0, currentTime, currentHigh + 40 * _Point);
|
||||
ObjectSetString(0, "SessionLabel_NewYork", OBJPROP_TEXT, "New York Session");
|
||||
ObjectSetInteger(0, "SessionLabel_NewYork", OBJPROP_COLOR, NewYorkColor);
|
||||
ObjectSetInteger(0, "SessionLabel_NewYork", OBJPROP_ANCHOR, ANCHOR_LEFT_UPPER);
|
||||
}
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,35 @@
|
||||
//
|
||||
XCPOIDrawer *drawer = cHelper.mPOIDrawer;
|
||||
|
||||
//
|
||||
if (cStateEvents.hasNewFairValueGap)
|
||||
{
|
||||
//
|
||||
int idx = GetYoungest(cState.fairValueGaps);
|
||||
has = IsValidIndex(idx);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
XBoxZone box;
|
||||
has = ToBox(
|
||||
box,
|
||||
cState.fairValueGaps[idx] //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
XCBoxObject *iObj;
|
||||
has = drawer.DrawBox(
|
||||
box,
|
||||
iObj //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
Print("Box Drawn ...");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
ZeroMemory(drawer);
|
||||
@@ -0,0 +1,66 @@
|
||||
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
|
||||
// © Mattes00
|
||||
|
||||
//@version=6
|
||||
indicator("25-75 Percentile SuperTrend | Mattes", shorttitle = "25-75 ST | Mattes", overlay = true)
|
||||
|
||||
subject = input.int (14,"Supertrend length", minval = 2 , group="25-75 Percentile SuperTrend")
|
||||
mult = input.float (1, "Multiplier", step=0.05,group="25-75 Percentile SuperTrend")
|
||||
slen = input.int (27, "Percentile length", group="25-75 Percentile SuperTrend")
|
||||
src_2575 = input.source(high, "Median smoothing source", group="25-75 Percentile SuperTrend")
|
||||
|
||||
smooth_lower = ta.percentile_nearest_rank(src_2575, slen, 25)
|
||||
smooth_upper = ta.percentile_nearest_rank(src_2575, slen, 75)
|
||||
|
||||
|
||||
Percentile_SuperTrend_func(mult, atrPeriod) =>
|
||||
src_long = smooth_upper
|
||||
src_short = smooth_lower
|
||||
|
||||
atr = ta.atr(atrPeriod)
|
||||
upper = src_long + mult * atr
|
||||
lower = src_short - mult * atr
|
||||
pl = nz(lower[1])
|
||||
pu = nz(upper[1])
|
||||
|
||||
lower := lower > pl or close[1] < pl ? lower : pl
|
||||
upper := upper < pu or close[1] > pu ? upper : pu
|
||||
|
||||
int dist = na
|
||||
float st = na
|
||||
pt = st[1]
|
||||
if na(atr[1])
|
||||
dist := 1
|
||||
else if pt == pu
|
||||
dist := close > upper ? -1 : 1
|
||||
else
|
||||
dist := close < lower ? 1 : -1
|
||||
st := dist == -1 ? lower : upper
|
||||
[st, dist]
|
||||
|
||||
|
||||
[x, dist] = Percentile_SuperTrend_func(mult, subject)
|
||||
|
||||
ST_L = ta.crossunder(dist, 0)
|
||||
ST_S = ta.crossover(dist, 0)
|
||||
|
||||
Long = ST_L
|
||||
Short = ST_S
|
||||
|
||||
var Mattes = 0
|
||||
if (Long and not Short)
|
||||
Mattes := 1
|
||||
if Short
|
||||
Mattes := -1
|
||||
|
||||
syscol = Mattes == 1 ? color.rgb(45, 162, 252) : Mattes == -1 ? color.rgb(113, 59, 249) : color.gray
|
||||
BlueTransParent = color.new(color.rgb(45, 162, 252), 50)
|
||||
PurpleTransParent = color.new(color.rgb(113, 59, 249), 50)
|
||||
|
||||
plotcandle(open, high, low, close, 'BarColor', color = syscol, bordercolor = syscol, wickcolor = syscol,force_overlay = true)
|
||||
upTrend = plot(dist < 0 ? x : na, "Up Trend", color = color.rgb(45, 162, 252), style = plot.style_linebr, linewidth = 2)
|
||||
downTrend = plot(dist < 0 ? na : x, "Down Trend", color = color.rgb(113, 59, 249), style = plot.style_linebr, linewidth = 2)
|
||||
s = plot((smooth_lower + smooth_upper) / 2, color = syscol)
|
||||
fill(s, upTrend, BlueTransParent, fillgaps = false)
|
||||
fill(s, downTrend, PurpleTransParent, fillgaps = false)
|
||||
|
||||
@@ -0,0 +1,318 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Forex Sessions and Day Range Indicator |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Your Name"
|
||||
#property link "https://www.example.com"
|
||||
#property version "1.00"
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 8 // 4 sessions * (High + Low)
|
||||
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include <Arrays/ArrayObj.mqh>
|
||||
|
||||
// Define an enumeration for DST rules
|
||||
enum DST_RULE
|
||||
{
|
||||
DST_SYDNEY,
|
||||
DST_TOKYO,
|
||||
DST_LONDON,
|
||||
DST_NEW_YORK
|
||||
};
|
||||
|
||||
struct SessionInfo
|
||||
{
|
||||
string name;
|
||||
int startHour; // Standard start hour (GMT)
|
||||
int startMinute;
|
||||
int endHour; // Standard end hour (GMT)
|
||||
int endMinute;
|
||||
DST_RULE dstRule; // DST rule for the session
|
||||
int dstAdjustment; // Hours to add during DST
|
||||
};
|
||||
|
||||
SessionInfo sessions[] = {
|
||||
{"Sydney", 21, 0, 5, 0, DST_SYDNEY, 1},
|
||||
{"Tokyo", 23, 0, 8, 0, DST_TOKYO, 0},
|
||||
{"London", 7, 0, 15, 0, DST_LONDON, 1},
|
||||
{"New York", 12, 0, 17, 0, DST_NEW_YORK, 1}};
|
||||
|
||||
double sessionHighBuffers[]; // Buffer for session highs
|
||||
double sessionLowBuffers[]; // Buffer for session lows
|
||||
|
||||
bool sessionActive[];
|
||||
double sessionHigh[];
|
||||
double sessionLow[];
|
||||
datetime sessionStartTime[];
|
||||
datetime sessionEndTime[];
|
||||
|
||||
double dayHigh = 0;
|
||||
double dayLow = 0;
|
||||
datetime dayStartTime;
|
||||
|
||||
// Function to extract the year from a datetime value
|
||||
int GetYear(datetime time)
|
||||
{
|
||||
return (int)StringSubstr(TimeToString(time, TIME_DATE), 0, 4);
|
||||
}
|
||||
|
||||
// Function to extract the day of the month from a datetime value
|
||||
int GetDay(datetime time)
|
||||
{
|
||||
MqlDateTime dt;
|
||||
TimeToStruct(time, dt);
|
||||
return dt.day;
|
||||
}
|
||||
|
||||
// Function to extract the day of the week from a datetime value (0=Sunday, 6=Saturday)
|
||||
int GetDayOfWeek(datetime time)
|
||||
{
|
||||
MqlDateTime dt;
|
||||
TimeToStruct(time, dt);
|
||||
return dt.day_of_week;
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
ArrayResize(sessionActive, ArraySize(sessions));
|
||||
ArrayResize(sessionHigh, ArraySize(sessions));
|
||||
ArrayResize(sessionLow, ArraySize(sessions));
|
||||
ArrayResize(sessionStartTime, ArraySize(sessions));
|
||||
ArrayResize(sessionEndTime, ArraySize(sessions));
|
||||
|
||||
for (int i = 0; i < ArraySize(sessions); i++)
|
||||
{
|
||||
sessionActive[i] = false;
|
||||
sessionHigh[i] = 0;
|
||||
sessionLow[i] = 0;
|
||||
sessionStartTime[i] = 0;
|
||||
sessionEndTime[i] = 0;
|
||||
}
|
||||
|
||||
dayHigh = 0;
|
||||
dayLow = 0;
|
||||
dayStartTime = 0;
|
||||
|
||||
// Initialize buffers for session highs and lows
|
||||
int totalSessions = ArraySize(sessions);
|
||||
int totalBars = iBars(NULL, 0); // Get the number of bars on the chart
|
||||
|
||||
ArrayResize(sessionHighBuffers, totalBars); // Resize to match the number of bars
|
||||
ArrayResize(sessionLowBuffers, totalBars); // Resize to match the number of bars
|
||||
|
||||
for (int i = 0; i < totalSessions; i++)
|
||||
{
|
||||
SetIndexBuffer(i * 2, sessionHighBuffers, INDICATOR_DATA);
|
||||
SetIndexBuffer(i * 2 + 1, sessionLowBuffers, INDICATOR_DATA);
|
||||
|
||||
// Optional: Set colors for high and low buffers
|
||||
PlotIndexSetInteger(i * 2, PLOT_LINE_COLOR, clrGreen);
|
||||
PlotIndexSetInteger(i * 2 + 1, PLOT_LINE_COLOR, clrRed);
|
||||
|
||||
IndicatorSetInteger(INDICATOR_LEVELS, 0); // No predefined levels
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, "Forex Sessions");
|
||||
}
|
||||
|
||||
return (INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
// Ensure buffers are resized to match the number of bars
|
||||
if (ArraySize(sessionHighBuffers) < rates_total)
|
||||
{
|
||||
ArrayResize(sessionHighBuffers, rates_total);
|
||||
ArrayResize(sessionLowBuffers, rates_total);
|
||||
}
|
||||
|
||||
datetime currentTime = TimeCurrent();
|
||||
|
||||
// Retrieve Ask and Bid prices dynamically
|
||||
double askPrice = SymbolInfoDouble(Symbol(), SYMBOL_ASK);
|
||||
double bidPrice = SymbolInfoDouble(Symbol(), SYMBOL_BID);
|
||||
|
||||
// Check each session
|
||||
for (int i = 0; i < ArraySize(sessions); i++)
|
||||
{
|
||||
SessionInfo session = sessions[i];
|
||||
|
||||
// Determine if DST is active using the session's DST rule
|
||||
bool dstActive = IsDSTActive(session.dstRule, currentTime);
|
||||
int adjStartHour = session.startHour + (dstActive ? session.dstAdjustment : 0);
|
||||
int adjEndHour = session.endHour + (dstActive ? session.dstAdjustment : 0);
|
||||
|
||||
datetime todayStart = StringToTime(TimeToString(currentTime, TIME_DATE) + " " +
|
||||
IntegerToString(adjStartHour) + ":" +
|
||||
IntegerToString(session.startMinute));
|
||||
datetime todayEnd = StringToTime(TimeToString(currentTime, TIME_DATE) + " " +
|
||||
IntegerToString(adjEndHour) + ":" +
|
||||
IntegerToString(session.endMinute));
|
||||
|
||||
// Handle sessions spanning midnight
|
||||
if (adjEndHour < adjStartHour)
|
||||
{
|
||||
todayEnd += 24 * 3600;
|
||||
}
|
||||
|
||||
if (currentTime >= todayStart && currentTime < todayEnd)
|
||||
{
|
||||
if (!sessionActive[i])
|
||||
{
|
||||
sessionActive[i] = true;
|
||||
sessionStartTime[i] = todayStart;
|
||||
sessionEndTime[i] = todayEnd;
|
||||
sessionHigh[i] = askPrice;
|
||||
sessionLow[i] = bidPrice;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (askPrice > sessionHigh[i])
|
||||
sessionHigh[i] = askPrice;
|
||||
if (bidPrice < sessionLow[i])
|
||||
sessionLow[i] = bidPrice;
|
||||
}
|
||||
|
||||
// Update buffers for the current bar
|
||||
sessionHighBuffers[rates_total - 1] = sessionHigh[i];
|
||||
sessionLowBuffers[rates_total - 1] = sessionLow[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
sessionActive[i] = false;
|
||||
sessionHighBuffers[rates_total - 1] = EMPTY_VALUE; // Clear buffer when session is inactive
|
||||
sessionLowBuffers[rates_total - 1] = EMPTY_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
// Check day range
|
||||
bool dstActiveNY = IsDSTActive(DST_NEW_YORK, currentTime);
|
||||
int dayStartHour = dstActiveNY ? 21 : 22;
|
||||
datetime todayDayStart = StringToTime(TimeToString(currentTime, TIME_DATE) + " " +
|
||||
IntegerToString(dayStartHour) + ":00");
|
||||
|
||||
if (currentTime < todayDayStart)
|
||||
{
|
||||
todayDayStart -= 24 * 3600;
|
||||
}
|
||||
|
||||
if (dayStartTime != todayDayStart)
|
||||
{
|
||||
dayStartTime = todayDayStart;
|
||||
dayHigh = askPrice;
|
||||
dayLow = bidPrice;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (askPrice > dayHigh)
|
||||
dayHigh = askPrice;
|
||||
if (bidPrice < dayLow)
|
||||
dayLow = bidPrice;
|
||||
}
|
||||
|
||||
// Display information on chart
|
||||
string comment = "Active Forex Sessions:\n";
|
||||
for (int i = 0; i < ArraySize(sessions); i++)
|
||||
{
|
||||
if (sessionActive[i])
|
||||
{
|
||||
comment += sessions[i].name + " Session\n" +
|
||||
"High: " + DoubleToString(sessionHigh[i], _Digits) + "\n" +
|
||||
"Low: " + DoubleToString(sessionLow[i], _Digits) + "\n";
|
||||
}
|
||||
}
|
||||
comment += "\nDay Range:\n" +
|
||||
"High: " + DoubleToString(dayHigh, _Digits) + "\n" +
|
||||
"Low: " + DoubleToString(dayLow, _Digits);
|
||||
Comment(comment);
|
||||
|
||||
return (rates_total);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Check if DST is active for a given session |
|
||||
//+------------------------------------------------------------------+
|
||||
bool IsDSTActive(DST_RULE dstRule, datetime time)
|
||||
{
|
||||
switch (dstRule)
|
||||
{
|
||||
case DST_SYDNEY:
|
||||
return IsSydneyDST(time);
|
||||
case DST_TOKYO:
|
||||
return IsTokyoDST(time);
|
||||
case DST_LONDON:
|
||||
return IsLondonDST(time);
|
||||
case DST_NEW_YORK:
|
||||
return IsNewYorkDST(time);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| DST Check Functions |
|
||||
//+------------------------------------------------------------------+
|
||||
bool IsLondonDST(datetime time)
|
||||
{
|
||||
int year = GetYear(time);
|
||||
datetime march31 = StringToTime(ToString(year) + ".03.31 00:00");
|
||||
int lastSundayMarch = GetDay(march31) - (GetDayOfWeek(march31) % 7);
|
||||
datetime dstStart = StringToTime(ToString(year) + ".03." + IntegerToString(lastSundayMarch) + " 01:00");
|
||||
|
||||
datetime oct31 = StringToTime(ToString(year) + ".10.31 00:00");
|
||||
int lastSundayOct = GetDay(oct31) - (GetDayOfWeek(oct31) % 7);
|
||||
datetime dstEnd = StringToTime(ToString(year) + ".10." + IntegerToString(lastSundayOct) + " 01:00");
|
||||
|
||||
return time >= dstStart && time < dstEnd;
|
||||
}
|
||||
|
||||
bool IsNewYorkDST(datetime time)
|
||||
{
|
||||
int year = GetYear(time);
|
||||
datetime march1 = StringToTime(ToString(year) + ".03.01 00:00");
|
||||
int dayOfWeekMarch1 = GetDayOfWeek(march1);
|
||||
int secondSundayMarch = 1 + (7 - dayOfWeekMarch1) % 7 + 7;
|
||||
datetime dstStart = StringToTime(ToString(year) + ".03." + IntegerToString(secondSundayMarch) + " 07:00");
|
||||
|
||||
datetime nov1 = StringToTime(ToString(year) + ".11.01 00:00");
|
||||
int dayOfWeekNov1 = GetDayOfWeek(nov1);
|
||||
int firstSundayNov = 1 + (7 - dayOfWeekNov1) % 7;
|
||||
datetime dstEnd = StringToTime(ToString(year) + ".11." + IntegerToString(firstSundayNov) + " 06:00");
|
||||
|
||||
return time >= dstStart && time < dstEnd;
|
||||
}
|
||||
|
||||
bool IsSydneyDST(datetime time)
|
||||
{
|
||||
int year = GetYear(time);
|
||||
datetime oct1 = StringToTime(ToString(year) + ".10.01 00:00");
|
||||
int dayOfWeekOct1 = GetDayOfWeek(oct1);
|
||||
int firstSundayOct = 1 + (7 - dayOfWeekOct1) % 7;
|
||||
datetime dstStart = StringToTime(ToString(year) + ".10." + IntegerToString(firstSundayOct) + " 13:00");
|
||||
|
||||
datetime apr1 = StringToTime(ToString(year) + ".04.01 00:00");
|
||||
int dayOfWeekApr1 = GetDayOfWeek(apr1);
|
||||
int firstSundayApr = 1 + (7 - dayOfWeekApr1) % 7;
|
||||
datetime dstEnd = StringToTime(ToString(year) + ".04." + IntegerToString(firstSundayApr) + " 15:00");
|
||||
|
||||
return time >= dstStart && time < dstEnd;
|
||||
}
|
||||
|
||||
bool IsTokyoDST(datetime time)
|
||||
{
|
||||
// Tokyo does not observe Daylight Saving Time (DST)
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,798 @@
|
||||
|
||||
//
|
||||
// Checking Bar Based on Positions State ...
|
||||
ENUM_X_DIRECTION iBarPosDir;
|
||||
bool isBarValidForDir = cHelper
|
||||
.mBarAnalyser
|
||||
.IsValidForPosition(
|
||||
cBar,
|
||||
iBarPosDir //
|
||||
);
|
||||
bool isBarValidForBullish =
|
||||
isBarValidForDir &&
|
||||
IsBullish(iBarPosDir);
|
||||
bool isBarValidForBearish =
|
||||
isBarValidForDir &&
|
||||
IsBearish(iBarPosDir);
|
||||
|
||||
//
|
||||
// Check Bar Place Based on Golden Zones ...
|
||||
|
||||
//
|
||||
bool isBarInPeaksGoldenZone =
|
||||
cBar.high <= cXConditions.peaksBuffer[cIDX] &&
|
||||
cBar.low >= cXConditions.peaksGoldenBuffer[cIDX];
|
||||
|
||||
//
|
||||
bool isBarInValesGoldenZone =
|
||||
cBar.high >= cXConditions.valesBuffer[cIDX] &&
|
||||
cBar.low <= cXConditions.valesGoldenBuffer[cIDX];
|
||||
|
||||
//
|
||||
XCPOIDrawer *drawer = provider.visionCycleHelper.mPOIDrawer;
|
||||
|
||||
//
|
||||
// X3MA ...
|
||||
|
||||
//
|
||||
bool isX3MaFastMidOverPeaksGoldeZone =
|
||||
isX3MaFastOverPeaksGoldenZone &&
|
||||
isX3MaMidOverPeaksGoldenZone;
|
||||
|
||||
//
|
||||
bool isX3MaFastMidUnderValesGoldeZone =
|
||||
isX3MaFastUnderValesGoldenZone &&
|
||||
isX3MaMidUnderValesGoldenZone;
|
||||
|
||||
//
|
||||
// XVWAP ...
|
||||
|
||||
//
|
||||
bool isVWapFastMidOverPeaksGoldeZone =
|
||||
isVWapFastOverPeaksGoldenZone &&
|
||||
isVWapMidOverPeaksGoldenZone;
|
||||
|
||||
//
|
||||
bool isVWapFastMidUnderValesGoldeZone =
|
||||
isVWapFastUnderValesGoldenZone &&
|
||||
isVWapMidUnderValesGoldenZone;
|
||||
|
||||
//
|
||||
//
|
||||
|
||||
//
|
||||
bool isX3MaVWapFastUnderValuesGoldenZone =
|
||||
isX3MaFastUnderValesGoldenZone &&
|
||||
isVWapFastUnderValesGoldenZone;
|
||||
|
||||
//
|
||||
bool isX3MaVWapFastOverPeaksGoldenZone =
|
||||
isX3MaFastOverPeaksGoldenZone &&
|
||||
isVWapFastOverPeaksGoldenZone;
|
||||
|
||||
//
|
||||
//
|
||||
|
||||
//
|
||||
double x3MaFastMidMax = MathMax(
|
||||
cXConditions.x3maFastBuffer[cIDX],
|
||||
cXConditions.x3maMidBuffer[cIDX] //
|
||||
);
|
||||
|
||||
//
|
||||
double x3MaFastMidMin = MathMin(
|
||||
cXConditions.x3maFastBuffer[cIDX],
|
||||
cXConditions.x3maMidBuffer[cIDX] //
|
||||
);
|
||||
|
||||
//
|
||||
double vwapFastMidMax = MathMax(
|
||||
cXConditions.vwapFastBuffer[cIDX],
|
||||
cXConditions.vwapMidBuffer[cIDX] //
|
||||
);
|
||||
|
||||
//
|
||||
double vwapFastMidMin = MathMin(
|
||||
cXConditions.vwapFastBuffer[cIDX],
|
||||
cXConditions.vwapMidBuffer[cIDX] //
|
||||
);
|
||||
|
||||
//
|
||||
//
|
||||
|
||||
//
|
||||
double x3maVWapFastMidMax = MathMax(x3MaFastMidMax, vwapFastMidMax);
|
||||
double x3maVWapFastMidMin = MathMin(x3MaFastMidMin, vwapFastMidMin);
|
||||
|
||||
//
|
||||
double x3maVWapMax = MathMax(cXConditions.x3maMax, cXConditions.vwapMax);
|
||||
double x3maVWapMin = MathMin(cXConditions.x3maMin, cXConditions.vwapMin);
|
||||
|
||||
//
|
||||
double x3maVWapDiff = x3maVWapMax - x3maVWapMin;
|
||||
|
||||
//
|
||||
double atr = cXConditions.atrBuffer[cIDX];
|
||||
|
||||
//
|
||||
bool isConsolidate = x3maVWapDiff <= (3 * atr);
|
||||
|
||||
//
|
||||
bool isX3MaVWapSwitchedToBullish =
|
||||
//
|
||||
// VWap ...
|
||||
(
|
||||
//
|
||||
(cXConditions.isVWapBullishOrdered &&
|
||||
cXConditions.isVWapSwitchedToBullishState) ||
|
||||
(cXConditions.isVWapBullishState &&
|
||||
cXConditions.isVWapSwitchedToBullishOrdered)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
// X3Ma ...
|
||||
(
|
||||
//
|
||||
(cXConditions.isX3MaBullishOrdered &&
|
||||
cXConditions.isX3MaSwitchedToBullishState) ||
|
||||
(cXConditions.isX3MaBullishState &&
|
||||
cXConditions.isX3MaSwitchedToBullishOrdered)
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isX3MaVWapSwitchedToBearish =
|
||||
//
|
||||
// VWap ...
|
||||
(
|
||||
//
|
||||
(cXConditions.isVWapBearishOrdered &&
|
||||
cXConditions.isVWapSwitchedToBearishState) ||
|
||||
(cXConditions.isVWapBearishState &&
|
||||
cXConditions.isVWapSwitchedToBearishOrdered)
|
||||
//
|
||||
)
|
||||
//
|
||||
||
|
||||
//
|
||||
// X3Ma ...
|
||||
(
|
||||
//
|
||||
(cXConditions.isX3MaBearishOrdered &&
|
||||
cXConditions.isX3MaSwitchedToBearishState) ||
|
||||
(cXConditions.isX3MaBearishState &&
|
||||
cXConditions.isX3MaSwitchedToBearishOrdered)
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Bullish Conditions ...
|
||||
isBullish =
|
||||
//
|
||||
// Base Condition ...
|
||||
(
|
||||
//
|
||||
false
|
||||
//
|
||||
// isConsolidate &&
|
||||
// isBarValidForBullish &&
|
||||
// cXConditions.isSarBullish &&
|
||||
// isX3MaVWapSwitchedToBullish &&
|
||||
// cXConditions.isNewPeakOverLast // &&
|
||||
// isVWapFastMidUnderValesGoldeZone // &&
|
||||
// cXConditions.isAtrLowerSlopeBullish
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Bearish Conditions ...
|
||||
isBearish =
|
||||
//
|
||||
// Base Condition ...
|
||||
(
|
||||
//
|
||||
false
|
||||
//
|
||||
// isConsolidate &&
|
||||
// isBarValidForBearish &&
|
||||
// cXConditions.isSarBearish &&
|
||||
// isX3MaVWapSwitchedToBearish &&
|
||||
// cXConditions.isNewValeUnderLast // &&
|
||||
// isVWapFastMidOverPeaksGoldeZone // &&
|
||||
// cXConditions.isAtrUpperSlopeBearish
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
// XWPVZ ...
|
||||
bool HasXWPVZConditions(
|
||||
ENUM_X_CYCLES cycle,
|
||||
XSignalBox &box,
|
||||
ENUM_X_DIRECTION &dir,
|
||||
X121SMCStrategySignalProviderData &provider,
|
||||
int barIndex = 0 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
box.Clean();
|
||||
dir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
// Fil Selected Data ...
|
||||
XPOIState cState;
|
||||
X121Conditions cXConditions;
|
||||
XPOIStateEvents cStateEvents;
|
||||
XC121SMCCycleHelper *cHelper;
|
||||
X121SMCCycleConditions cConditions;
|
||||
result = provider.SelectCycle(
|
||||
cycle,
|
||||
cState,
|
||||
cStateEvents,
|
||||
cXConditions,
|
||||
cHelper,
|
||||
cConditions //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
cState.Clean();
|
||||
ZeroMemory(cHelper);
|
||||
cConditions.Clean();
|
||||
cXConditions.Clean();
|
||||
cStateEvents.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
Parse(cXConditions);
|
||||
|
||||
//
|
||||
// Normalize Args ...
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
int idx = -1;
|
||||
int count = 0;
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
int zIDX = barIndex;
|
||||
int cIDX = zIDX + 1;
|
||||
int pIDX = cIDX + 1;
|
||||
int ppIDX = pIDX + 1;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
XOHCL cBar;
|
||||
XOHCL pBar;
|
||||
|
||||
//
|
||||
// Initial Bars ...
|
||||
result = zBar.Init(
|
||||
cState.symbol,
|
||||
cState.period,
|
||||
barIndex //
|
||||
);
|
||||
result =
|
||||
result &&
|
||||
zBar.GetPreviousBar(cBar);
|
||||
result =
|
||||
result &&
|
||||
cBar.GetPreviousBar(pBar);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
cState.Clean();
|
||||
ZeroMemory(cHelper);
|
||||
cConditions.Clean();
|
||||
cXConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XCPOIDrawer *drawer = provider.visionCycleHelper.mPOIDrawer;
|
||||
|
||||
//
|
||||
// Checking Other Conditions ...
|
||||
|
||||
//
|
||||
// Checking Bar Based on Positions State ...
|
||||
ENUM_X_DIRECTION iBarPosDir;
|
||||
bool isBarValidForDir = cHelper
|
||||
.mBarAnalyser
|
||||
.IsValidForPosition(
|
||||
cBar,
|
||||
iBarPosDir //
|
||||
);
|
||||
bool isBarValidForBullish =
|
||||
isBarValidForDir &&
|
||||
IsBullish(iBarPosDir);
|
||||
bool isBarValidForBearish =
|
||||
isBarValidForDir &&
|
||||
IsBearish(iBarPosDir);
|
||||
|
||||
// //
|
||||
// // Continuation Bullish ...
|
||||
// bool isContinuationBullish =
|
||||
// //
|
||||
// isBarValidForBullish &&
|
||||
// cXConditions.isSarBullish &&
|
||||
// cXConditions.isStrBullish &&
|
||||
// cXConditions.isNewPeakOverLast
|
||||
// //
|
||||
// ;
|
||||
|
||||
// //
|
||||
// // Continuation Bearish ...
|
||||
// bool isContinuationBearish =
|
||||
// //
|
||||
// isBarValidForBearish &&
|
||||
// cXConditions.isSarBearish &&
|
||||
// cXConditions.isStrBearish &&
|
||||
// cXConditions.isNewValeUnderLast
|
||||
// //
|
||||
// ;
|
||||
|
||||
//
|
||||
XBoxZone obBox;
|
||||
XBoxZone fvgBox;
|
||||
XBoxZone supResBox;
|
||||
XBoxZone tmpBoxes[];
|
||||
bool isBullishFVGRejected = false;
|
||||
bool isBearishFVGRejected = false;
|
||||
bool isFVGLowerBullishRejected = false;
|
||||
bool isFVGUpperBullishRejected = false;
|
||||
bool isFVGLowerBearishRejected = false;
|
||||
bool isFVGUpperBearishRejected = false;
|
||||
has = cState.HasFairValueGaps();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Converts FairValueGaps to Box ...
|
||||
ToBox(
|
||||
cState.fairValueGaps,
|
||||
tmpBoxes //
|
||||
);
|
||||
|
||||
//
|
||||
// Select FVG ...
|
||||
while (HasChild(tmpBoxes))
|
||||
{
|
||||
//
|
||||
idx = GetYoungest(tmpBoxes);
|
||||
has = IsValidIndex(idx);
|
||||
if (!has)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
XBoxZone iBox = tmpBoxes[idx];
|
||||
ArrayRemove(
|
||||
tmpBoxes,
|
||||
idx,
|
||||
1 //
|
||||
);
|
||||
|
||||
//
|
||||
isFVGLowerBullishRejected =
|
||||
//
|
||||
cBar.low < iBox.lower &&
|
||||
cBar.GetDown() > iBox.lower
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
isFVGUpperBullishRejected =
|
||||
//
|
||||
cBar.low < iBox.upper &&
|
||||
cBar.GetDown() > iBox.upper
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
isFVGLowerBearishRejected =
|
||||
//
|
||||
cBar.high > iBox.lower &&
|
||||
cBar.GetUp() < iBox.lower
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
isFVGUpperBearishRejected =
|
||||
//
|
||||
cBar.high > iBox.upper &&
|
||||
cBar.GetUp() < iBox.upper
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
//
|
||||
|
||||
//
|
||||
isBullishFVGRejected =
|
||||
//
|
||||
iBox.IsBullish() &&
|
||||
cBar.IsBullish() &&
|
||||
(isFVGLowerBullishRejected
|
||||
// || isFVGUpperBullishRejected
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
isBearishFVGRejected =
|
||||
//
|
||||
iBox.IsBearish() &&
|
||||
cBar.IsBearish() &&
|
||||
( // isFVGLowerBearishRejected ||
|
||||
isFVGUpperBearishRejected)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
has = isBullishFVGRejected ||
|
||||
isBearishFVGRejected;
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
iBox.to = TimeCurrent();
|
||||
fvgBox = iBox;
|
||||
iBox.Clean();
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
iBox.Clean();
|
||||
}
|
||||
Clean(tmpBoxes);
|
||||
|
||||
//
|
||||
// Select Order Block which FVG is Inside it ...
|
||||
has = fvgBox.IsValid();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Converts Order Blocks to Box ...
|
||||
ToBox(
|
||||
cState.orderBlocks,
|
||||
tmpBoxes //
|
||||
);
|
||||
|
||||
//
|
||||
// Select Order Blocks ...
|
||||
has = HasChild(tmpBoxes);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
while (HasChild(tmpBoxes))
|
||||
{
|
||||
//
|
||||
idx = GetYoungest(tmpBoxes);
|
||||
has = IsValidIndex(idx);
|
||||
if (!has)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
XBoxZone iBox = tmpBoxes[idx];
|
||||
ArrayRemove(
|
||||
tmpBoxes,
|
||||
idx,
|
||||
1 //
|
||||
);
|
||||
|
||||
//
|
||||
// Validate Order Blocks ...
|
||||
bool isSameDir = iBox.dir == fvgBox.dir;
|
||||
bool isFVGInsideOB = IsBoxInsideOr(
|
||||
fvgBox,
|
||||
iBox //
|
||||
);
|
||||
|
||||
//
|
||||
has =
|
||||
isSameDir &&
|
||||
isFVGInsideOB;
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
iBox.to = TimeCurrent();
|
||||
obBox = iBox;
|
||||
iBox.Clean();
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
iBox.Clean();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
has = obBox.IsValid();
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
obBox.Clean();
|
||||
fvgBox.Clean();
|
||||
|
||||
//
|
||||
isBullishFVGRejected = false;
|
||||
isBearishFVGRejected = false;
|
||||
isFVGLowerBullishRejected = false;
|
||||
isFVGUpperBullishRejected = false;
|
||||
isFVGLowerBearishRejected = false;
|
||||
isFVGUpperBearishRejected = false;
|
||||
}
|
||||
Clean(tmpBoxes);
|
||||
|
||||
//
|
||||
// Checking Support nad Resistance ...
|
||||
bool isDirBullish =
|
||||
obBox.IsBullish() &&
|
||||
fvgBox.IsBullish();
|
||||
has =
|
||||
obBox.IsValid() &&
|
||||
fvgBox.IsValid();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Converts Support or Resistance to Boxes ...
|
||||
if (isDirBullish)
|
||||
{
|
||||
//
|
||||
ToBox(
|
||||
cState.supportZones,
|
||||
tmpBoxes //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
ToBox(
|
||||
cState.resistanceZones,
|
||||
tmpBoxes //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Selecting Support nad Resistance ...
|
||||
has = HasChild(tmpBoxes);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
while (HasChild(tmpBoxes))
|
||||
{
|
||||
//
|
||||
idx = GetYoungest(tmpBoxes);
|
||||
has = IsValidIndex(idx);
|
||||
if (!has)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
XBoxZone iBox = tmpBoxes[idx];
|
||||
ArrayRemove(
|
||||
tmpBoxes,
|
||||
idx,
|
||||
1 //
|
||||
);
|
||||
|
||||
//
|
||||
// Validate Support and Resistane ...
|
||||
bool isDirPassed = iBox.dir == obBox.dir;
|
||||
bool isPlacePassed =
|
||||
IsBoxAbove(
|
||||
iBox,
|
||||
fvgBox //
|
||||
) ||
|
||||
IsBoxAbove(
|
||||
fvgBox,
|
||||
iBox //
|
||||
) ||
|
||||
IsBoxInside(
|
||||
iBox,
|
||||
fvgBox //
|
||||
) ||
|
||||
IsBoxInside(
|
||||
fvgBox,
|
||||
iBox //
|
||||
);
|
||||
|
||||
has =
|
||||
isDirPassed &&
|
||||
isPlacePassed;
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
iBox.to = TimeCurrent();
|
||||
supResBox = iBox;
|
||||
iBox.Clean();
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
iBox.Clean();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
has = obBox.IsValid() &&
|
||||
fvgBox.IsValid() &&
|
||||
supResBox.IsValid();
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
obBox.Clean();
|
||||
fvgBox.Clean();
|
||||
supResBox.Clean();
|
||||
|
||||
//
|
||||
isBullishFVGRejected = false;
|
||||
isBearishFVGRejected = false;
|
||||
isFVGLowerBullishRejected = false;
|
||||
isFVGUpperBullishRejected = false;
|
||||
isFVGLowerBearishRejected = false;
|
||||
isFVGUpperBearishRejected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Clean(tmpBoxes);
|
||||
|
||||
//
|
||||
// Checking OB and FVG Validation ...
|
||||
has = obBox.IsValid() &&
|
||||
fvgBox.IsValid() &&
|
||||
supResBox.IsValid();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Draw OB ...
|
||||
if (obBox.IsValid())
|
||||
{
|
||||
//
|
||||
XCBoxObject *iObj;
|
||||
has = drawer.DrawBox(
|
||||
obBox,
|
||||
iObj //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
iObj.BoxStyle(STYLE_DASH);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Draw FVG ...
|
||||
if (fvgBox.IsValid())
|
||||
{
|
||||
//
|
||||
XCBoxObject *iObj;
|
||||
has = drawer.DrawBox(
|
||||
fvgBox,
|
||||
iObj //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
iObj.BoxStyle(STYLE_SOLID);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Sup/Res Box ...
|
||||
if (supResBox.IsValid())
|
||||
{
|
||||
//
|
||||
XCBoxObject *iObj;
|
||||
has = drawer.DrawBox(
|
||||
supResBox,
|
||||
iObj //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
iObj.BoxStyle(STYLE_DOT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Bullish Conditions ...
|
||||
isBullish =
|
||||
//
|
||||
// Base Condition ...
|
||||
(
|
||||
//
|
||||
// false
|
||||
isBullishFVGRejected
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Bearish Conditions ...
|
||||
isBearish =
|
||||
//
|
||||
// Base Condition ...
|
||||
(
|
||||
//
|
||||
// false
|
||||
isBearishFVGRejected
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Filling Requirements ...
|
||||
result =
|
||||
isBullish ||
|
||||
isBearish;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
dir =
|
||||
isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
box.ob = obBox;
|
||||
box.fvg = fvgBox;
|
||||
box.sharp = supResBox;
|
||||
}
|
||||
|
||||
//
|
||||
// Check All Conditions ...
|
||||
result =
|
||||
box.IsValid() &&
|
||||
HasDirection(dir) &&
|
||||
(isBullish ||
|
||||
isBearish);
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
cState.Clean();
|
||||
ZeroMemory(cHelper);
|
||||
cConditions.Clean();
|
||||
cStateEvents.Clean();
|
||||
cXConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,210 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| BuySellVolumes.mq5 |
|
||||
//| Copyright © 2023, YourName |
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "YourName"
|
||||
#property link "https://www.yourwebsite.com"
|
||||
#property version "1.00"
|
||||
|
||||
//
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 4
|
||||
|
||||
//--- Plot settings for Buy Volume
|
||||
#property indicator_label1 "Buy Volume"
|
||||
#property indicator_type1 DRAW_HISTOGRAM
|
||||
#property indicator_color1 clrLime
|
||||
|
||||
//--- Plot settings for Sell Volume
|
||||
#property indicator_label2 "Sell Volume"
|
||||
#property indicator_type2 DRAW_HISTOGRAM
|
||||
#property indicator_color2 clrRed
|
||||
|
||||
//--- Plot settings for Buy Volume MA
|
||||
#property indicator_label3 "Buy Volume MA"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrGreen
|
||||
|
||||
//--- Plot settings for Sell Volume MA
|
||||
#property indicator_label4 "Sell Volume MA"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrRed
|
||||
|
||||
//--- Input parameters
|
||||
input int MAPeriod = 14; // Period for the moving average
|
||||
|
||||
//--- Indicator buffers
|
||||
double BuyVolumeBuffer[]; // Buffer for Buy Volume
|
||||
double SellVolumeBuffer[]; // Buffer for Sell Volume
|
||||
double BuyVolumeMABuffer[]; // Buffer for Buy Volume Moving Average
|
||||
double SellVolumeMABuffer[]; // Buffer for Sell Volume Moving Average
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Attach buffers to the indicator
|
||||
SetIndexBuffer(0, BuyVolumeBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(1, SellVolumeBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(2, BuyVolumeMABuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(3, SellVolumeMABuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// Set short name for the indicator
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, "Buy and Sell Volumes");
|
||||
|
||||
//
|
||||
return (INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Start from the first uncalculated bar
|
||||
int start = MathMax(prev_calculated - 1, 0);
|
||||
|
||||
//
|
||||
// Loop through bars
|
||||
for (int i = start; i < rates_total; i++)
|
||||
{
|
||||
//
|
||||
// Calculate Buy and Sell Volumes based on bar-level data
|
||||
double buyVolume = 0.0;
|
||||
double sellVolume = 0.0;
|
||||
|
||||
//
|
||||
if (close[i] > open[i])
|
||||
{
|
||||
//
|
||||
buyVolume = (double)tick_volume[i]; // Buying pressure (bullish bar)
|
||||
sellVolume = 0.0;
|
||||
}
|
||||
else if (close[i] < open[i])
|
||||
{
|
||||
//
|
||||
sellVolume = (double)tick_volume[i]; // Selling pressure (bearish bar)
|
||||
buyVolume = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Neutral bar: split volume equally between buy and sell
|
||||
buyVolume = tick_volume[i] / 2.0;
|
||||
sellVolume = tick_volume[i] / 2.0;
|
||||
}
|
||||
|
||||
//
|
||||
// Store Buy and Sell Volumes in their respective buffers
|
||||
BuyVolumeBuffer[i] = buyVolume;
|
||||
SellVolumeBuffer[i] = sellVolume;
|
||||
|
||||
//
|
||||
// Calculate Moving Averages for Buy and Sell Volumes
|
||||
if (i >= MAPeriod - 1)
|
||||
{
|
||||
//
|
||||
// Calculate Simple Moving Average for Buy Volume
|
||||
double buySum = 0.0;
|
||||
for (int j = 0; j < MAPeriod; j++)
|
||||
buySum += BuyVolumeBuffer[i - j];
|
||||
BuyVolumeMABuffer[i] = buySum / MAPeriod;
|
||||
|
||||
//
|
||||
// Calculate Simple Moving Average for Sell Volume
|
||||
double sellSum = 0.0;
|
||||
for (int j = 0; j < MAPeriod; j++)
|
||||
sellSum += SellVolumeBuffer[i - j];
|
||||
SellVolumeMABuffer[i] = sellSum / MAPeriod;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Not enough data for MA
|
||||
BuyVolumeMABuffer[i] = EMPTY_VALUE;
|
||||
SellVolumeMABuffer[i] = EMPTY_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Normalize all values between 0 and 100
|
||||
// NormalizeValues(rates_total);
|
||||
|
||||
//
|
||||
return (rates_total);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Normalize all values between 0 and 100 |
|
||||
//+------------------------------------------------------------------+
|
||||
void NormalizeValues(int rates_total)
|
||||
{
|
||||
//
|
||||
// Find the maximum and minimum values across all buffers
|
||||
double maxValue = 0.0;
|
||||
double minValue = DBL_MAX;
|
||||
|
||||
//
|
||||
for (int i = 0; i < rates_total; i++)
|
||||
{
|
||||
//
|
||||
if (BuyVolumeBuffer[i] != EMPTY_VALUE && BuyVolumeBuffer[i] > maxValue)
|
||||
maxValue = BuyVolumeBuffer[i];
|
||||
if (SellVolumeBuffer[i] != EMPTY_VALUE && SellVolumeBuffer[i] > maxValue)
|
||||
maxValue = SellVolumeBuffer[i];
|
||||
if (BuyVolumeMABuffer[i] != EMPTY_VALUE && BuyVolumeMABuffer[i] > maxValue)
|
||||
maxValue = BuyVolumeMABuffer[i];
|
||||
if (SellVolumeMABuffer[i] != EMPTY_VALUE && SellVolumeMABuffer[i] > maxValue)
|
||||
maxValue = SellVolumeMABuffer[i];
|
||||
|
||||
//
|
||||
if (BuyVolumeBuffer[i] != EMPTY_VALUE && BuyVolumeBuffer[i] < minValue)
|
||||
minValue = BuyVolumeBuffer[i];
|
||||
if (SellVolumeBuffer[i] != EMPTY_VALUE && SellVolumeBuffer[i] < minValue)
|
||||
minValue = SellVolumeBuffer[i];
|
||||
if (BuyVolumeMABuffer[i] != EMPTY_VALUE && BuyVolumeMABuffer[i] < minValue)
|
||||
minValue = BuyVolumeMABuffer[i];
|
||||
if (SellVolumeMABuffer[i] != EMPTY_VALUE && SellVolumeMABuffer[i] < minValue)
|
||||
minValue = SellVolumeMABuffer[i];
|
||||
}
|
||||
|
||||
//
|
||||
// Avoid division by zero
|
||||
if (maxValue == minValue)
|
||||
return;
|
||||
|
||||
//
|
||||
// Normalize all values
|
||||
for (int i = 0; i < rates_total; i++)
|
||||
{
|
||||
//
|
||||
if (BuyVolumeBuffer[i] != EMPTY_VALUE)
|
||||
BuyVolumeBuffer[i] = ((BuyVolumeBuffer[i] - minValue) / (maxValue - minValue)) * 100.0;
|
||||
|
||||
if (SellVolumeBuffer[i] != EMPTY_VALUE)
|
||||
SellVolumeBuffer[i] = ((SellVolumeBuffer[i] - minValue) / (maxValue - minValue)) * 100.0;
|
||||
|
||||
if (BuyVolumeMABuffer[i] != EMPTY_VALUE)
|
||||
BuyVolumeMABuffer[i] = ((BuyVolumeMABuffer[i] - minValue) / (maxValue - minValue)) * 100.0;
|
||||
|
||||
if (SellVolumeMABuffer[i] != EMPTY_VALUE)
|
||||
SellVolumeMABuffer[i] = ((SellVolumeMABuffer[i] - minValue) / (maxValue - minValue)) * 100.0;
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,580 @@
|
||||
|
||||
//
|
||||
bool DetectNearestTenKijCross(
|
||||
XOHCL &bar,
|
||||
ENUM_X_DIRECTION &dir,
|
||||
int barIndex = 0,
|
||||
int maxAllowedBars = 20 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bar.Clean();
|
||||
dir = X_DIRECTION_NONE;
|
||||
barIndex = NormalizeInt(barIndex, 0);
|
||||
maxAllowedBars = NormalizeInt(maxAllowedBars, 20);
|
||||
|
||||
//
|
||||
// Looping Through LoopBack Period ...
|
||||
// for Detecting Result ...
|
||||
for (int i = barIndex; i < barIndex + maxAllowedBars; i++)
|
||||
{
|
||||
//
|
||||
XOHCL iBar;
|
||||
result = iBar.Init(
|
||||
GetSymbol(),
|
||||
GetPeriod(),
|
||||
i //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
iBar.Clean();
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
double iTSen = mX121Helper.xichHelper.GetTenkanSen(i);
|
||||
double iTSenP = mX121Helper.xichHelper.GetTenkanSen(i + 1);
|
||||
|
||||
//
|
||||
double iKSen = mX121Helper.xichHelper.GetKijunSen(i);
|
||||
double iKSenP = mX121Helper.xichHelper.GetKijunSen(i + 1);
|
||||
|
||||
//
|
||||
bool isTSenOverKSen = iTSen > iKSen;
|
||||
bool isTSenOverKSenP = iTSenP > iKSenP;
|
||||
|
||||
//
|
||||
bool isTSenUnderKSen = iTSen < iKSen;
|
||||
bool isTSenUnderKSenP = iTSenP < iKSenP;
|
||||
|
||||
//
|
||||
|
||||
//
|
||||
bool isTSenCrossedOverKSen = isTSenOverKSen &&
|
||||
!isTSenOverKSenP;
|
||||
|
||||
//
|
||||
bool isTSenCrossedUnderKSen = isTSenUnderKSen &&
|
||||
!isTSenUnderKSenP;
|
||||
|
||||
//
|
||||
result = isTSenCrossedOverKSen ||
|
||||
isTSenCrossedUnderKSen;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
bar = iBar;
|
||||
|
||||
//
|
||||
dir = isTSenCrossedOverKSen
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool DetectNearestVolumeSwitched(
|
||||
XOHCL &bar,
|
||||
ENUM_X_DIRECTION &dir,
|
||||
int barIndex = 0,
|
||||
int maxAllowedBars = 20 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bar.Clean();
|
||||
dir = X_DIRECTION_NONE;
|
||||
barIndex = NormalizeInt(barIndex, 0);
|
||||
maxAllowedBars = NormalizeInt(maxAllowedBars, 20);
|
||||
|
||||
//
|
||||
// Looping Through LoopBack Period ...
|
||||
// for Detecting Result ...
|
||||
for (int i = barIndex; i < barIndex + maxAllowedBars; i++)
|
||||
{
|
||||
//
|
||||
XOHCL iBar;
|
||||
result = iBar.Init(
|
||||
GetSymbol(),
|
||||
GetPeriod(),
|
||||
i //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
iBar.Clean();
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
double iBullVMa = mX121Helper.xvolumeHelper.GetBullishVolumeMa(i);
|
||||
double iBullVMaP = mX121Helper.xvolumeHelper.GetBullishVolumeMa(i + 1);
|
||||
|
||||
//
|
||||
double iBearVMa = mX121Helper.xvolumeHelper.GetBearishVolumeMa(i);
|
||||
double iBearVMaP = mX121Helper.xvolumeHelper.GetBearishVolumeMa(i + 1);
|
||||
|
||||
//
|
||||
bool isBullVMaOverBearVMa = iBullVMa > iBearVMa;
|
||||
bool isBullVMaOverBearVMaP = iBullVMaP > iBearVMaP;
|
||||
bool isCrossOver = isBullVMaOverBearVMa &&
|
||||
!isBullVMaOverBearVMaP;
|
||||
|
||||
//
|
||||
bool isBullVMaUnderBearVMa = iBullVMa < iBearVMa;
|
||||
bool isBullVMaUnderBearVMaP = iBullVMaP < iBearVMaP;
|
||||
bool isCrossUnder = isBullVMaUnderBearVMa &&
|
||||
!isBullVMaUnderBearVMaP;
|
||||
|
||||
//
|
||||
result = isCrossOver ||
|
||||
isCrossUnder;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
bar = iBar;
|
||||
|
||||
//
|
||||
dir = isCrossOver
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool DetectNearestDeltaSwitched(
|
||||
XOHCL &bar,
|
||||
ENUM_X_DIRECTION &dir,
|
||||
int barIndex = 0,
|
||||
int maxAllowedBars = 20 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bar.Clean();
|
||||
dir = X_DIRECTION_NONE;
|
||||
barIndex = NormalizeInt(barIndex, 0);
|
||||
maxAllowedBars = NormalizeInt(maxAllowedBars, 20);
|
||||
|
||||
//
|
||||
// Looping Through LoopBack Period ...
|
||||
// for Detecting Result ...
|
||||
for (int i = barIndex; i < barIndex + maxAllowedBars; i++)
|
||||
{
|
||||
//
|
||||
XOHCL iBar;
|
||||
result = iBar.Init(
|
||||
GetSymbol(),
|
||||
GetPeriod(),
|
||||
i //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
iBar.Clean();
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
double iDelta = mX121Helper.xdeltaHelper.GetDelta(i);
|
||||
double iDeltaP = mX121Helper.xdeltaHelper.GetDelta(i + 1);
|
||||
|
||||
//
|
||||
double iDeltaMa = mX121Helper.xdeltaHelper.GetDeltaMa(i);
|
||||
double iDeltaMaP = mX121Helper.xdeltaHelper.GetDeltaMa(i + 1);
|
||||
|
||||
//
|
||||
bool isDeltaOverMa = iDelta > iDeltaMa;
|
||||
bool isDeltaOverMaP = iDeltaP > iDeltaMaP;
|
||||
|
||||
//
|
||||
bool isDeltaUnderMa = iDelta < iDeltaMa;
|
||||
bool isDeltaUnderMaP = iDeltaP < iDeltaMaP;
|
||||
|
||||
//
|
||||
bool isCrossOver = isDeltaOverMa &&
|
||||
!isDeltaOverMaP;
|
||||
|
||||
//
|
||||
bool isCrossUnder = isDeltaUnderMa &&
|
||||
!isDeltaUnderMaP;
|
||||
|
||||
//
|
||||
result = isCrossOver ||
|
||||
isCrossUnder;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
bar = iBar;
|
||||
|
||||
//
|
||||
dir = isCrossOver
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Activated Boxes ...
|
||||
bool HasActivatedBoxConditions(
|
||||
ENUM_X_CYCLES cycle,
|
||||
XSignalBox &box,
|
||||
ENUM_X_DIRECTION &dir,
|
||||
XSignalBox &waitingBoxes[],
|
||||
X121SMCStrategySignalProviderData &provider,
|
||||
int barIndex = 0 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
box.Clean();
|
||||
dir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
// Checking Waiting Baoxes Exists ...
|
||||
result = HasChild(waitingBoxes);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Fil Selected Data ...
|
||||
XPOIState cState;
|
||||
X121Conditions cXConditions;
|
||||
XPOIStateEvents cStateEvents;
|
||||
XC121SMCCycleHelper *cHelper;
|
||||
X121SMCCycleConditions cConditions;
|
||||
result = provider.SelectCycle(
|
||||
cycle,
|
||||
cState,
|
||||
cStateEvents,
|
||||
cXConditions,
|
||||
cHelper,
|
||||
cConditions //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
cState.Clean();
|
||||
ZeroMemory(cHelper);
|
||||
cConditions.Clean();
|
||||
cXConditions.Clean();
|
||||
cStateEvents.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
Parse(cXConditions);
|
||||
|
||||
//
|
||||
// Normalize Args ...
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
int idx = -1;
|
||||
int count = 0;
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
int zIDX = barIndex;
|
||||
int cIDX = zIDX + 1;
|
||||
int pIDX = cIDX + 1;
|
||||
int ppIDX = pIDX + 1;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
XOHCL cBar;
|
||||
XOHCL pBar;
|
||||
|
||||
//
|
||||
// Initial Bars ...
|
||||
result = zBar.Init(
|
||||
cState.symbol,
|
||||
cState.period,
|
||||
barIndex //
|
||||
);
|
||||
result =
|
||||
result &&
|
||||
zBar.GetPreviousBar(cBar);
|
||||
result =
|
||||
result &&
|
||||
cBar.GetPreviousBar(pBar);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
cState.Clean();
|
||||
ZeroMemory(cHelper);
|
||||
cConditions.Clean();
|
||||
cXConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Checking Bar Based on Positions State ...
|
||||
ENUM_X_DIRECTION iBarPosDir;
|
||||
bool isBarValidForDir = cHelper
|
||||
.mBarAnalyser
|
||||
.IsValidForPosition(
|
||||
cBar,
|
||||
iBarPosDir //
|
||||
);
|
||||
bool isBarValidForBullish =
|
||||
isBarValidForDir &&
|
||||
IsBullish(iBarPosDir);
|
||||
bool isBarValidForBearish =
|
||||
isBarValidForDir &&
|
||||
IsBearish(iBarPosDir);
|
||||
|
||||
//
|
||||
// Extract Selected Boxes ...
|
||||
XBoxZone selectedBox;
|
||||
XSignalBox iSignalBox;
|
||||
count = ArraySize(waitingBoxes);
|
||||
has = IsValidSize(count);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XSignalBox iBox = waitingBoxes[i];
|
||||
|
||||
//
|
||||
bool isBullish = iBox.ob.IsBullish();
|
||||
|
||||
//
|
||||
has = cBar.low < iBox.sharp.upper &&
|
||||
cBar.low > iBox.sharp.lower &&
|
||||
cBar.high > iBox.sharp.lower &&
|
||||
cBar.high < iBox.sharp.upper;
|
||||
|
||||
//
|
||||
// Force Using OB ...
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
iSignalBox = iBox;
|
||||
if (!selectedBox.IsValid())
|
||||
{
|
||||
selectedBox = iBox.ob;
|
||||
}
|
||||
iBox.Clean();
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
iBox.Clean();
|
||||
}
|
||||
}
|
||||
result =
|
||||
iSignalBox.IsValid() &&
|
||||
selectedBox.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
cState.Clean();
|
||||
iSignalBox.Clean();
|
||||
selectedBox.Clean();
|
||||
ZeroMemory(cHelper);
|
||||
cConditions.Clean();
|
||||
cXConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool hasSignalBox = iSignalBox.IsValid();
|
||||
bool isSignalBoxBullish = IsBullish(iSignalBox.ob.dir);
|
||||
|
||||
//
|
||||
// Checking Other Conditions ...
|
||||
|
||||
//
|
||||
// XVWAP ...
|
||||
|
||||
//
|
||||
bool isVWapSlopeBullish =
|
||||
cXConditions.isVwapFastSlopeBullish &&
|
||||
cXConditions.isVwapMidSlopeBullish &&
|
||||
cXConditions.isVwapSlowSlopeBullish;
|
||||
|
||||
//
|
||||
bool isVWapSlopeBearish =
|
||||
cXConditions.isVwapFastSlopeBearish &&
|
||||
cXConditions.isVwapMidSlopeBearish &&
|
||||
cXConditions.isVwapSlowSlopeBearish;
|
||||
|
||||
//
|
||||
bool isVWapBullishCondition =
|
||||
(cXConditions.isVWapBullishOrdered &&
|
||||
cXConditions.isVWapSwitchedToBullishState) ||
|
||||
(cXConditions.isVWapBullishState &&
|
||||
cXConditions.isVWapSwitchedToBullishOrdered);
|
||||
|
||||
//
|
||||
bool isVWapBearishCondition =
|
||||
(cXConditions.isVWapBearishOrdered &&
|
||||
cXConditions.isVWapSwitchedToBearishState) ||
|
||||
(cXConditions.isVWapBearishState &&
|
||||
cXConditions.isVWapSwitchedToBearishOrdered);
|
||||
|
||||
//
|
||||
// Bullish Conditions ...
|
||||
isBullish =
|
||||
//
|
||||
// Base Condition ...
|
||||
(
|
||||
//
|
||||
hasSignalBox &&
|
||||
isSignalBoxBullish &&
|
||||
isVWapSlopeBullish &&
|
||||
isBarValidForBullish &&
|
||||
isVWapBullishCondition
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Bearish Conditions ...
|
||||
isBearish =
|
||||
//
|
||||
// Base Condition ...
|
||||
(
|
||||
//
|
||||
hasSignalBox &&
|
||||
isVWapSlopeBearish &&
|
||||
!isSignalBoxBullish &&
|
||||
isBarValidForBearish &&
|
||||
isVWapBearishCondition
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Filling Requirements ...
|
||||
result =
|
||||
isBullish ||
|
||||
isBearish;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
dir =
|
||||
isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
box = iSignalBox;
|
||||
box.UpdateTo(TimeCurrent());
|
||||
|
||||
//
|
||||
// Provide TP/SL ...
|
||||
|
||||
//
|
||||
box.sl = isBullish
|
||||
? cXConditions.vwapMin
|
||||
: cXConditions.vwapMax;
|
||||
|
||||
//
|
||||
box.tp = isBullish
|
||||
? box.sharp.upper
|
||||
: box.sharp.lower;
|
||||
}
|
||||
|
||||
//
|
||||
// Check All Conditions ...
|
||||
result =
|
||||
box.IsValid() &&
|
||||
HasDirection(dir) &&
|
||||
(isBullish ||
|
||||
isBearish);
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
cState.Clean();
|
||||
iSignalBox.Clean();
|
||||
selectedBox.Clean();
|
||||
ZeroMemory(cHelper);
|
||||
cConditions.Clean();
|
||||
cStateEvents.Clean();
|
||||
cXConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@@ -0,0 +1,232 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| SaherElm IT Center MQL5 Expert Advisor |
|
||||
//| |
|
||||
//| Name: X121 XPV EA |
|
||||
//| Description: Multi-Timeframe Peak & Vale Breakout Strategy |
|
||||
//| Maintainer: Hadi Khazaee Asl |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#include "../Helpers/x-saherelm.x121.xpv.helper.mq5"
|
||||
|
||||
// Input Parameters
|
||||
input double RiskPercent = 1.0; // Risk per trade in percentage
|
||||
input int StopLossPips = 50; // Stop Loss in pips
|
||||
input int TakeProfitPips = 100; // Take Profit in pips
|
||||
input bool UseTrailingStop = true; // Enable trailing stop
|
||||
input int TrailingStopPips = 30; // Trailing stop distance in pips
|
||||
input int MagicNumber = 123456; // Unique identifier for trades
|
||||
input bool DebugMode = true; // Enable debug messages
|
||||
|
||||
//
|
||||
// Global Variables ...
|
||||
X121XPVInputs mXPVInputs;
|
||||
XCX121XPVHelper *mXPVHelper;
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert Initialization Function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Attach the X121 XPV indicator ...
|
||||
mXPVInputs.Default();
|
||||
mXPVHelper = new XCX121XPVHelper();
|
||||
bool isInited = mXPVHelper.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mXPVInputs //
|
||||
);
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
Print("X121 XPV EA Initialized.");
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert Deinitialization Function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
mXPVInputs.Clean();
|
||||
ZeroMemory(mXPVHelper);
|
||||
Print("X121 XPV EA Deinitialized.");
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert Tick Function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
// Check if there are open positions for this symbol
|
||||
if (PositionSelect(_Symbol))
|
||||
{
|
||||
ManageOpenPosition();
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
X121XPVConditions pvConditions;
|
||||
bool isRetrieved = mXPVHelper.GetConditions(
|
||||
pvConditions,
|
||||
1 //
|
||||
);
|
||||
if (!isRetrieved)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Get indicator values
|
||||
double peak = pvConditions.peaksBuffer[0];
|
||||
double vale = pvConditions.valesBuffer[0];
|
||||
double peakGoldenZone = pvConditions.peaksGoldenBuffer[0];
|
||||
double valeGoldenZone = pvConditions.valesGoldenBuffer[0];
|
||||
|
||||
//
|
||||
// Validate indicator values
|
||||
if (peak == EMPTY_VALUE || vale == EMPTY_VALUE || peakGoldenZone == EMPTY_VALUE || valeGoldenZone == EMPTY_VALUE)
|
||||
{
|
||||
//
|
||||
if (DebugMode)
|
||||
Print("Invalid indicator values. Skipping...");
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Entry Conditions
|
||||
double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
|
||||
double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
|
||||
|
||||
//
|
||||
// Long Entry
|
||||
if (bid > peak && bid > peakGoldenZone)
|
||||
{
|
||||
OpenTrade(ORDER_TYPE_BUY, peak, valeGoldenZone);
|
||||
}
|
||||
|
||||
//
|
||||
// Short Entry
|
||||
if (ask < vale && ask < valeGoldenZone)
|
||||
{
|
||||
OpenTrade(ORDER_TYPE_SELL, vale, peakGoldenZone);
|
||||
}
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Open a Trade |
|
||||
//+------------------------------------------------------------------+
|
||||
void OpenTrade(int orderType, double entryLevel, double targetLevel)
|
||||
{
|
||||
//
|
||||
double lotSize = CalculateLotSize(entryLevel, targetLevel);
|
||||
double sl = (orderType == ORDER_TYPE_BUY) ? entryLevel - StopLossPips * Point() : entryLevel + StopLossPips * Point();
|
||||
double tp = (orderType == ORDER_TYPE_BUY) ? entryLevel + TakeProfitPips * Point() : entryLevel - TakeProfitPips * Point();
|
||||
|
||||
//
|
||||
// Prepare trade request
|
||||
MqlTradeRequest request = {};
|
||||
MqlTradeResult result = {};
|
||||
|
||||
//
|
||||
request.action = TRADE_ACTION_DEAL;
|
||||
request.symbol = _Symbol;
|
||||
request.volume = lotSize;
|
||||
request.type = (ENUM_ORDER_TYPE)orderType;
|
||||
request.price = (orderType == ORDER_TYPE_BUY) ? SymbolInfoDouble(_Symbol, SYMBOL_ASK) : SymbolInfoDouble(_Symbol, SYMBOL_BID);
|
||||
request.sl = sl;
|
||||
request.tp = tp;
|
||||
request.deviation = 10;
|
||||
request.magic = MagicNumber;
|
||||
|
||||
//
|
||||
// Send trade request
|
||||
if (!OrderSend(request, result))
|
||||
{
|
||||
Print("Trade failed: ", result.retcode);
|
||||
}
|
||||
else
|
||||
{
|
||||
Print("Trade opened successfully.");
|
||||
}
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Manage Open Position |
|
||||
//+------------------------------------------------------------------+
|
||||
void ManageOpenPosition()
|
||||
{
|
||||
ulong ticket = PositionGetInteger(POSITION_TICKET);
|
||||
double currentPrice = (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) ? SymbolInfoDouble(_Symbol, SYMBOL_BID) : SymbolInfoDouble(_Symbol, SYMBOL_ASK);
|
||||
double openPrice = PositionGetDouble(POSITION_PRICE_OPEN);
|
||||
double sl = PositionGetDouble(POSITION_SL);
|
||||
double tp = PositionGetDouble(POSITION_TP);
|
||||
|
||||
// Trailing Stop Logic
|
||||
if (UseTrailingStop)
|
||||
{
|
||||
double newSL = (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
|
||||
? currentPrice - TrailingStopPips * Point()
|
||||
: currentPrice + TrailingStopPips * Point();
|
||||
|
||||
if ((PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY && newSL > sl) ||
|
||||
(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL && newSL < sl))
|
||||
{
|
||||
ModifyPosition(ticket, newSL, tp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Modify Position |
|
||||
//+------------------------------------------------------------------+
|
||||
void ModifyPosition(ulong ticket, double newSL, double newTP)
|
||||
{
|
||||
MqlTradeRequest request = {};
|
||||
MqlTradeResult result = {};
|
||||
|
||||
request.action = TRADE_ACTION_SLTP;
|
||||
request.position = ticket;
|
||||
request.sl = newSL;
|
||||
request.tp = newTP;
|
||||
|
||||
if (!OrderSend(request, result))
|
||||
{
|
||||
Print("Failed to modify position: ", result.retcode);
|
||||
}
|
||||
else
|
||||
{
|
||||
Print("Position modified successfully.");
|
||||
}
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Calculate Lot Size |
|
||||
//+------------------------------------------------------------------+
|
||||
double CalculateLotSize(double entryLevel, double targetLevel)
|
||||
{
|
||||
double riskAmount = AccountInfoDouble(ACCOUNT_BALANCE) * RiskPercent / 100;
|
||||
double stopLossDistance = MathAbs(entryLevel - targetLevel) / Point();
|
||||
double tickValue = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE);
|
||||
double lotSize = riskAmount / (stopLossDistance * tickValue);
|
||||
|
||||
// Normalize lot size
|
||||
double minLot = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
|
||||
double maxLot = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX);
|
||||
double stepLot = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);
|
||||
|
||||
lotSize = MathFloor(lotSize / stepLot) * stepLot;
|
||||
lotSize = MathMax(minLot, MathMin(maxLot, lotSize));
|
||||
|
||||
return lotSize;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,573 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Ocillator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XCDV
|
||||
// Description: Detect Comulative Delta Volume ...
|
||||
//
|
||||
//
|
||||
// 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 XCDV Ocillator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121_XCDV"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Makret ...
|
||||
input group "Market";
|
||||
input int maLength = 14; // Moving Averge Length
|
||||
input ENUM_X_PRICE maAppliedTo = X_PRICE_CLOSE; // Moving Averge Applied To
|
||||
input ENUM_X_MA_METHOD maMethod = X_MA_MODE_EMA; // Moving Averge Method
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
input bool showCDV = true; // Show Delta Line
|
||||
input bool showMA = true; // Show Delta Histogram
|
||||
|
||||
//
|
||||
// Buffers Props ...
|
||||
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 10
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define openBufferIndex 0
|
||||
double openBuffer[];
|
||||
|
||||
//
|
||||
#define highBufferIndex 1
|
||||
double highBuffer[];
|
||||
|
||||
//
|
||||
#define lowBufferIndex 2
|
||||
double lowBuffer[];
|
||||
|
||||
//
|
||||
#define closeBufferIndex 3
|
||||
double closeBuffer[];
|
||||
|
||||
//
|
||||
#define colorBufferIndex 4
|
||||
double colorBuffer[];
|
||||
|
||||
//
|
||||
#define barBufferIndex 0
|
||||
#property indicator_label1 "X121 XCDV Open;X121 XCDV High;X121 XCDV Low;X121 XCDV Close"
|
||||
#property indicator_type1 DRAW_COLOR_CANDLES
|
||||
#property indicator_color1 CLR_NONE, clrLime, clrRed
|
||||
|
||||
//
|
||||
#define maBufferIndex 5
|
||||
double maBuffer[];
|
||||
|
||||
#property indicator_label2 "MA"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrYellow
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
#define mLastBufferIndex 5
|
||||
|
||||
#define priceBufferIndex mLastBufferIndex + 1
|
||||
double priceBuffer[];
|
||||
|
||||
#define deltaBufferIndex mLastBufferIndex + 2
|
||||
double deltaBuffer[];
|
||||
|
||||
#define cumulativeDeltaBufferIndex mLastBufferIndex + 3
|
||||
double cumulativeDeltaBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
double lastCDV = 0.0;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
//
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = maLength > 0 &&
|
||||
IsValid(maMethod) &&
|
||||
IsValid(maAppliedTo);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(0, maLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// CDV ...
|
||||
|
||||
//
|
||||
// Raw Candles Color ...
|
||||
ArraySetAsSeries(colorBuffer, true);
|
||||
SetIndexBuffer(colorBufferIndex, colorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE barDrawType = showCDV ? DRAW_COLOR_CANDLES : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Set EMPTY_VALUE on Candles Buffer ...
|
||||
PlotIndexSetDouble(barBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(barBufferIndex, PLOT_SHOW_DATA, showCDV);
|
||||
PlotIndexSetInteger(barBufferIndex, PLOT_DRAW_TYPE, barDrawType);
|
||||
|
||||
//
|
||||
// Open ...
|
||||
ArraySetAsSeries(openBuffer, true);
|
||||
SetIndexBuffer(openBufferIndex, openBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// High ...
|
||||
ArraySetAsSeries(highBuffer, true);
|
||||
SetIndexBuffer(highBufferIndex, highBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// Close ...
|
||||
ArraySetAsSeries(closeBuffer, true);
|
||||
SetIndexBuffer(closeBufferIndex, closeBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
ArraySetAsSeries(lowBuffer, true);
|
||||
SetIndexBuffer(lowBufferIndex, lowBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// Ma ...
|
||||
ENUM_DRAW_TYPE maDrawType = showMA ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(maBuffer, true);
|
||||
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(maBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(maBufferIndex, PLOT_SHOW_DATA, showMA);
|
||||
PlotIndexSetInteger(maBufferIndex, PLOT_DRAW_TYPE, maDrawType);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(priceBuffer, true);
|
||||
SetIndexBuffer(priceBufferIndex, priceBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(deltaBuffer, true);
|
||||
SetIndexBuffer(deltaBufferIndex, deltaBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(cumulativeDeltaBuffer, true);
|
||||
SetIndexBuffer(cumulativeDeltaBufferIndex, cumulativeDeltaBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Custom Buffers ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int barsLimit = startCalculationForLastBars > 0
|
||||
? startCalculationForLastBars
|
||||
: 0;
|
||||
//
|
||||
// bool canCalculate = true;
|
||||
bool canCalculate =
|
||||
barsLimit == 0 ||
|
||||
bar_index <= barsLimit;
|
||||
if (canCalculate)
|
||||
{
|
||||
//
|
||||
CalculateValues(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBuffersZero(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
openBuffer[barIndex] = 0.0;
|
||||
highBuffer[barIndex] = 0.0;
|
||||
closeBuffer[barIndex] = 0.0;
|
||||
lowBuffer[barIndex] = 0.0;
|
||||
colorBuffer[barIndex] = hideColorIDX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Vales ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateValues(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
XOHCL bar;
|
||||
bool has = bar.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index //
|
||||
);
|
||||
if (!has)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double lowShadow = bar.GetLowShadow();
|
||||
double highShadow = bar.GetHighShadow();
|
||||
double body = bar.GetBody();
|
||||
bool isBullish = bar.IsBullish();
|
||||
bool hasDir = HasDirection(bar.GetDirection());
|
||||
|
||||
//
|
||||
double iRate = 0.5 * (highShadow + lowShadow + (hasDir ? 2 * body : 0)) / (highShadow + lowShadow + body);
|
||||
iRate = iRate <= 0
|
||||
? 0.5
|
||||
: iRate;
|
||||
|
||||
//
|
||||
double iVRate = tickVolume[bar_index] * iRate;
|
||||
double iDelta = isBullish
|
||||
? iVRate
|
||||
: -1 * iVRate;
|
||||
deltaBuffer[bar_index] = iDelta;
|
||||
|
||||
//
|
||||
double iCumulate = lastCDV + iDelta;
|
||||
cumulativeDeltaBuffer[bar_index] = iCumulate;
|
||||
lastCDV = iCumulate;
|
||||
|
||||
//
|
||||
bool isFirstBar =
|
||||
startCalculationForLastBars > 0
|
||||
? bar_index == startCalculationForLastBars
|
||||
: bar_index == ratesTotal;
|
||||
|
||||
//
|
||||
double iO = 0;
|
||||
double iH = 0;
|
||||
double iL = 0;
|
||||
double iC = 0;
|
||||
if (!isFirstBar)
|
||||
{
|
||||
//
|
||||
iO = cumulativeDeltaBuffer[bar_index + 1];
|
||||
iH = MathMax(cumulativeDeltaBuffer[bar_index], cumulativeDeltaBuffer[bar_index + 1]);
|
||||
iL = MathMin(cumulativeDeltaBuffer[bar_index], cumulativeDeltaBuffer[bar_index + 1]);
|
||||
iC = iCumulate;
|
||||
}
|
||||
|
||||
//
|
||||
double iClose = (iO + iH + iL + iC) / 4;
|
||||
double iOpen = isFirstBar
|
||||
? (iO + iC) / 2
|
||||
: (openBuffer[bar_index + 1] + closeBuffer[bar_index + 1]) / 2;
|
||||
double iLow = MathMin(iL, MathMin(iOpen, iClose));
|
||||
double iHigh = MathMax(iH, MathMax(iOpen, iClose));
|
||||
|
||||
//
|
||||
lowBuffer[bar_index] = iLow;
|
||||
openBuffer[bar_index] = iOpen;
|
||||
highBuffer[bar_index] = iHigh;
|
||||
closeBuffer[bar_index] = iClose;
|
||||
|
||||
//
|
||||
bool isCBullish = iOpen <= iClose;
|
||||
double iColor = isCBullish
|
||||
? bullishColorIDX
|
||||
: bearishColorIDX;
|
||||
colorBuffer[bar_index] = iColor;
|
||||
|
||||
//
|
||||
double iPrice = GetAppliedPrice(
|
||||
maAppliedTo,
|
||||
openBuffer,
|
||||
highBuffer,
|
||||
lowBuffer,
|
||||
closeBuffer,
|
||||
bar_index //
|
||||
);
|
||||
priceBuffer[bar_index] = iPrice;
|
||||
|
||||
//
|
||||
// Calculate Moving Averages ...
|
||||
int deltaMAsCount = iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
maLength,
|
||||
priceBuffer,
|
||||
maBuffer,
|
||||
maMethod //
|
||||
);
|
||||
|
||||
//
|
||||
bar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,846 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: 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 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 "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 "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 "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 "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 "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 "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 "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 "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;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL bar;
|
||||
bar.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Top ...
|
||||
topValue = bar
|
||||
.FindHighest(
|
||||
tenkanSenLength,
|
||||
mTenkanSenTopMode
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Bottom ...
|
||||
bottomValue = bar
|
||||
.FindLowest(
|
||||
tenkanSenLength,
|
||||
mTenkanSenBottomMode
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
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 = bar
|
||||
.FindHighest(
|
||||
kijunSenLength,
|
||||
mKijunSenTopMode
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Bottom ...
|
||||
bottomValue = bar
|
||||
.FindLowest(
|
||||
kijunSenLength,
|
||||
mKijunSenBottomMode
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
double kijunSenValue = (topValue + bottomValue) / 2;
|
||||
kijunSenBuffer[bar_index] = kijunSenValue;
|
||||
|
||||
//
|
||||
kijunSenPlusBuffer[bar_index] = kijunSenValue;
|
||||
kijunSenNegativeBuffer[bar_index] = kijunSenValue;
|
||||
|
||||
//
|
||||
// CHIKOUSPAN ...
|
||||
double chikouSpanValue = bar
|
||||
.GetPrice(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 = bar
|
||||
.FindHighest(
|
||||
senkouSpanBLength,
|
||||
mSenkouSpanBTopMode
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Bottom ...
|
||||
bottomValue = bar
|
||||
.FindLowest(
|
||||
senkouSpanBLength,
|
||||
mSenkouSpanBBottomMode
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
double senkouSpanBValue = (topValue + bottomValue) / 2;
|
||||
senkouBBuffer[bar_index] = senkouSpanBValue;
|
||||
senkouSpanBBuffer[bar_index] = senkouSpanBValue;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,393 @@
|
||||
|
||||
// //
|
||||
// // XICH ...
|
||||
// X121XICHConditions xichConditions;
|
||||
// result = GetICHConditions(
|
||||
// xichConditions,
|
||||
// barIndex,
|
||||
// loopback //
|
||||
// );
|
||||
// if (!result)
|
||||
// {
|
||||
// //
|
||||
// xpvConditions.Clean();
|
||||
// xhkConditions.Clean();
|
||||
// xichConditions.Clean();
|
||||
|
||||
// //
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// //
|
||||
// // XDON ...
|
||||
// X121XDONConditions xdonConditions;
|
||||
// result = GetDONConditions(
|
||||
// xdonConditions,
|
||||
// barIndex,
|
||||
// loopback //
|
||||
// );
|
||||
// if (!result)
|
||||
// {
|
||||
// //
|
||||
// xpvConditions.Clean();
|
||||
// xhkConditions.Clean();
|
||||
// xichConditions.Clean();
|
||||
// xmasConditions.Clean();
|
||||
// xatrConditions.Clean();
|
||||
// xstrConditions.Clean();
|
||||
// xcheConditions.Clean();
|
||||
// xdonConditions.Clean();
|
||||
|
||||
// //
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// //
|
||||
// // XDELTA ...
|
||||
// X121XDELTAConditions xdeltaConditions;
|
||||
// result = GetDELTAConditions(
|
||||
// xdeltaConditions,
|
||||
// barIndex,
|
||||
// loopback //
|
||||
// );
|
||||
// if (!result)
|
||||
// {
|
||||
// //
|
||||
// xpvConditions.Clean();
|
||||
// xhkConditions.Clean();
|
||||
// xichConditions.Clean();
|
||||
// xmasConditions.Clean();
|
||||
// xatrConditions.Clean();
|
||||
// xstrConditions.Clean();
|
||||
// xcheConditions.Clean();
|
||||
// xdonConditions.Clean();
|
||||
// x3maConditions.Clean();
|
||||
// xvwapConditions.Clean();
|
||||
// xdeltaConditions.Clean();
|
||||
|
||||
// //
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// //
|
||||
// // XVOLUME ...
|
||||
// X121XVOLUMEConditions xvolumeConditions;
|
||||
// result = GetVOLUMEConditions(
|
||||
// xvolumeConditions,
|
||||
// barIndex,
|
||||
// loopback //
|
||||
// );
|
||||
// if (!result)
|
||||
// {
|
||||
// //
|
||||
// xpvConditions.Clean();
|
||||
// xhkConditions.Clean();
|
||||
// xichConditions.Clean();
|
||||
// xmasConditions.Clean();
|
||||
// xatrConditions.Clean();
|
||||
// xstrConditions.Clean();
|
||||
// xcheConditions.Clean();
|
||||
// xdonConditions.Clean();
|
||||
// x3maConditions.Clean();
|
||||
// xvwapConditions.Clean();
|
||||
// xdeltaConditions.Clean();
|
||||
// xvolumeConditions.Clean();
|
||||
|
||||
// //
|
||||
// return result;
|
||||
// }
|
||||
|
||||
//
|
||||
// xichConditions.Clean();
|
||||
// xdonConditions.Clean();
|
||||
// xdeltaConditions.Clean();
|
||||
// xvolumeConditions.Clean();
|
||||
|
||||
|
||||
// //
|
||||
// // XICH ...
|
||||
// bool GetICHConditions(
|
||||
// X121XICHConditions &conditions, //
|
||||
// int barIndex = 0, //
|
||||
// int loopback = 5 //
|
||||
// )
|
||||
// {
|
||||
// //
|
||||
// bool result = false;
|
||||
|
||||
// //
|
||||
// result = xichHelper.GetConditions(
|
||||
// conditions,
|
||||
// barIndex,
|
||||
// loopback //
|
||||
// );
|
||||
|
||||
// //
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// //
|
||||
// // XDON ...
|
||||
// bool GetDONConditions(
|
||||
// X121XDONConditions &conditions, //
|
||||
// int barIndex = 0, //
|
||||
// int loopback = 5 //
|
||||
// )
|
||||
// {
|
||||
// //
|
||||
// bool result = false;
|
||||
|
||||
// //
|
||||
// result = xdonHelper.GetConditions(
|
||||
// conditions,
|
||||
// barIndex,
|
||||
// loopback //
|
||||
// );
|
||||
|
||||
// //
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// //
|
||||
// // XDELTA ...
|
||||
// bool GetDELTAConditions(
|
||||
// X121XDELTAConditions &conditions, //
|
||||
// int barIndex = 0, //
|
||||
// int loopback = 5 //
|
||||
// )
|
||||
// {
|
||||
// //
|
||||
// bool result = false;
|
||||
|
||||
// //
|
||||
// result = xdeltaHelper.GetConditions(
|
||||
// conditions,
|
||||
// barIndex,
|
||||
// loopback //
|
||||
// );
|
||||
|
||||
// //
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// //
|
||||
// // XVOLUME ...
|
||||
// bool GetVOLUMEConditions(
|
||||
// X121XVOLUMEConditions &conditions, //
|
||||
// int barIndex = 0, //
|
||||
// int loopback = 5 //
|
||||
// )
|
||||
// {
|
||||
// //
|
||||
// bool result = false;
|
||||
|
||||
// //
|
||||
// result = xvolumeHelper.GetConditions(
|
||||
// conditions,
|
||||
// barIndex,
|
||||
// loopback //
|
||||
// );
|
||||
|
||||
// //
|
||||
// return result;
|
||||
// }
|
||||
|
||||
|
||||
//
|
||||
// xichInputs = inputs.xichInputs;
|
||||
// xdonInputs = inputs.xdonInputs;
|
||||
// xdeltaInputs = inputs.xdeltaInputs;
|
||||
// xvolumeInputs = inputs.xvolumeInputs;
|
||||
|
||||
|
||||
|
||||
// //
|
||||
// // XICH ...
|
||||
// xichHelper = new XCX121XICHHelper();
|
||||
// result = xichHelper.Init(
|
||||
// symbol,
|
||||
// period,
|
||||
// xichInputs //
|
||||
// );
|
||||
// if (!result)
|
||||
// {
|
||||
// //
|
||||
// ZeroMemory(xccHelper);
|
||||
// ZeroMemory(xpvHelper);
|
||||
// ZeroMemory(xhkHelper);
|
||||
// ZeroMemory(xmasHelper);
|
||||
// ZeroMemory(xatrHelper);
|
||||
// ZeroMemory(xstrHelper);
|
||||
// ZeroMemory(xcheHelper);
|
||||
// ZeroMemory(x3maHelper);
|
||||
// ZeroMemory(xvwapHelper);
|
||||
|
||||
// //
|
||||
// // ZeroMemory(xichHelper);
|
||||
// // ZeroMemory(xdonHelper);
|
||||
// // ZeroMemory(xdeltaHelper);
|
||||
// // ZeroMemory(xvolumeHelper);
|
||||
|
||||
// //
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// //
|
||||
// // XDON ...
|
||||
// xdonHelper = new XCX121XDONHelper();
|
||||
// result = xdonHelper.Init(
|
||||
// symbol,
|
||||
// period,
|
||||
// xdonInputs //
|
||||
// );
|
||||
// if (!result)
|
||||
// {
|
||||
// //
|
||||
// ZeroMemory(xccHelper);
|
||||
// ZeroMemory(xpvHelper);
|
||||
// ZeroMemory(xhkHelper);
|
||||
// ZeroMemory(xmasHelper);
|
||||
// ZeroMemory(xatrHelper);
|
||||
// ZeroMemory(xstrHelper);
|
||||
// ZeroMemory(xcheHelper);
|
||||
// ZeroMemory(x3maHelper);
|
||||
// ZeroMemory(xvwapHelper);
|
||||
|
||||
// //
|
||||
// // ZeroMemory(xichHelper);
|
||||
// // ZeroMemory(xdonHelper);
|
||||
// // ZeroMemory(xdeltaHelper);
|
||||
// // ZeroMemory(xvolumeHelper);
|
||||
|
||||
// //
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// //
|
||||
// // XDELTA ...
|
||||
// xdeltaHelper = new XCX121XDELTAHelper();
|
||||
// result = xdeltaHelper.Init(
|
||||
// symbol,
|
||||
// period,
|
||||
// xdeltaInputs //
|
||||
// );
|
||||
// if (!result)
|
||||
// {
|
||||
// //
|
||||
// ZeroMemory(xccHelper);
|
||||
// ZeroMemory(xpvHelper);
|
||||
// ZeroMemory(xhkHelper);
|
||||
// ZeroMemory(xmasHelper);
|
||||
// ZeroMemory(xatrHelper);
|
||||
// ZeroMemory(xstrHelper);
|
||||
// ZeroMemory(xcheHelper);
|
||||
// ZeroMemory(x3maHelper);
|
||||
// ZeroMemory(xvwapHelper);
|
||||
|
||||
// //
|
||||
// // ZeroMemory(xichHelper);
|
||||
// // ZeroMemory(xdonHelper);
|
||||
// // ZeroMemory(xdeltaHelper);
|
||||
// // ZeroMemory(xvolumeHelper);
|
||||
|
||||
// //
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// //
|
||||
// // XVOLUME ...
|
||||
// xvolumeHelper = new XCX121XVOLUMEHelper();
|
||||
// result = xvolumeHelper.Init(
|
||||
// symbol,
|
||||
// period,
|
||||
// xvolumeInputs //
|
||||
// );
|
||||
// if (!result)
|
||||
// {
|
||||
// //
|
||||
// ZeroMemory(xccHelper);
|
||||
// ZeroMemory(xpvHelper);
|
||||
// ZeroMemory(xhkHelper);
|
||||
// ZeroMemory(xmasHelper);
|
||||
// ZeroMemory(xatrHelper);
|
||||
// ZeroMemory(xstrHelper);
|
||||
// ZeroMemory(xcheHelper);
|
||||
// ZeroMemory(x3maHelper);
|
||||
// ZeroMemory(xvwapHelper);
|
||||
|
||||
// //
|
||||
// // ZeroMemory(xichHelper);
|
||||
// // ZeroMemory(xdonHelper);
|
||||
// // ZeroMemory(xdeltaHelper);
|
||||
// // ZeroMemory(xvolumeHelper);
|
||||
|
||||
// //
|
||||
// return result;
|
||||
// }
|
||||
|
||||
|
||||
//
|
||||
// ZeroMemory(xichHelper);
|
||||
// ZeroMemory(xdonHelper);
|
||||
// ZeroMemory(xdeltaHelper);
|
||||
// ZeroMemory(xvolumeHelper);
|
||||
|
||||
|
||||
//
|
||||
// XCX121XICHHelper *xichHelper;
|
||||
// XCX121XDONHelper *xdonHelper;
|
||||
// XCX121XDELTAHelper *xdeltaHelper;
|
||||
// XCX121XVOLUMEHelper *xvolumeHelper;
|
||||
|
||||
|
||||
//
|
||||
// int xdonMax = xdonInputs.Max();
|
||||
// int xichMax = xichInputs.Max();
|
||||
// int xdeltaMax = xdeltaInputs.Max();
|
||||
// int xvolumeMax = xvolumeInputs.Max();
|
||||
|
||||
|
||||
//
|
||||
// result = MathMax(result, xdonMax);
|
||||
// result = MathMax(result, xichMax);
|
||||
// result = MathMax(result, xdeltaMax);
|
||||
// result = MathMax(result, xvolumeMax);
|
||||
|
||||
// &&
|
||||
// xichInputs.IsValid() &&
|
||||
// xdonInputs.IsValid() &&
|
||||
// xdeltaInputs.IsValid() &&
|
||||
// xvolumeInputs.IsValid()
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// xichInputs.Default();
|
||||
// xdonInputs.Default();
|
||||
// xdeltaInputs.Default();
|
||||
// xvolumeInputs.Default();
|
||||
|
||||
|
||||
//
|
||||
// xichInputs.Clean();
|
||||
// xdonInputs.Clean();
|
||||
// xdeltaInputs.Clean();
|
||||
// xvolumeInputs.Clean();
|
||||
|
||||
//
|
||||
// xichInputs.Clean();
|
||||
// xdonInputs.Clean();
|
||||
// xdeltaInputs.Clean();
|
||||
// xvolumeInputs.Clean();
|
||||
|
||||
//
|
||||
// delete xichHelper;
|
||||
// delete xdonHelper;
|
||||
// delete xdeltaHelper;
|
||||
// delete xvolumeHelper;
|
||||
|
||||
//
|
||||
// ZeroMemory(xichHelper);
|
||||
// ZeroMemory(xdonHelper);
|
||||
// ZeroMemory(xdeltaHelper);
|
||||
// ZeroMemory(xvolumeHelper);
|
||||
@@ -0,0 +1,431 @@
|
||||
//
|
||||
bool isPeakPivot = conditions.isPeakIsPivot;
|
||||
bool isValePivot = conditions.isValeIsPivot;
|
||||
|
||||
//
|
||||
bool isPivotBullish = isValePivot &&
|
||||
isCBarValidForBullish;
|
||||
|
||||
//
|
||||
bool isPivotBearish = isPeakPivot &&
|
||||
isCBarValidForBearish;
|
||||
|
||||
//
|
||||
bool isPivotBullishReversal =
|
||||
//
|
||||
isPivotBullish &&
|
||||
conditions.isKIBearish &&
|
||||
conditions.isSarBearish &&
|
||||
conditions.isTrendBearish &&
|
||||
conditions.isLastSupportRejected
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isPivotBearishReversal =
|
||||
//
|
||||
isPivotBearish &&
|
||||
conditions.isKIBullish &&
|
||||
conditions.isSarBullish &&
|
||||
conditions.isTrendBullish &&
|
||||
conditions.isLastResistanceRejected
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isPivot = isPivotBullishReversal ||
|
||||
isPivotBearishReversal;
|
||||
|
||||
if (isPivot)
|
||||
{
|
||||
Print("Pivot: ");
|
||||
|
||||
//
|
||||
if (isPivotBullish)
|
||||
{
|
||||
Print("Bullish: ", isPivotBullish);
|
||||
}
|
||||
|
||||
//
|
||||
if (isPivotBearish)
|
||||
{
|
||||
Print("Bearish: ", isPivotBearish);
|
||||
}
|
||||
|
||||
//
|
||||
Print("Bullish Score: ", bullishScore);
|
||||
Print("Bearish Score: ", bearishScore);
|
||||
}
|
||||
|
||||
//
|
||||
bool isOverFib2 = pBar.low > conditions.fiboLevel2Buffer[cIDX];
|
||||
bool isUnderFib2 = pBar.high < conditions.fiboLevel2Buffer[cIDX];
|
||||
|
||||
//
|
||||
bool isTrendBasedBullish =
|
||||
isUnderFib2 &&
|
||||
isCBarValidForBullish &&
|
||||
conditions.isTrendRejectUp;
|
||||
|
||||
//
|
||||
bool isTrendBasedBearish =
|
||||
isOverFib2 &&
|
||||
isCBarValidForBearish &&
|
||||
conditions.isTrendRejectDown;
|
||||
|
||||
//
|
||||
bool isTrend =
|
||||
isTrendBasedBullish ||
|
||||
isTrendBasedBearish;
|
||||
|
||||
//
|
||||
if (isTrend)
|
||||
{
|
||||
Print("Trend Based ...");
|
||||
}
|
||||
|
||||
//
|
||||
bool isBarBreakedKITrendBullish =
|
||||
cBar.IsBullish() &&
|
||||
isCBarBullishMomentum &&
|
||||
cBar.open < conditions.kiBuffer[cIDX] &&
|
||||
cBar.close > conditions.kiBuffer[cIDX] &&
|
||||
cBar.open < conditions.trendBuffer[cIDX] &&
|
||||
cBar.close > conditions.trendBuffer[cIDX];
|
||||
|
||||
//
|
||||
bool isBarBreakedKITrendBearish =
|
||||
cBar.IsBearish() &&
|
||||
isCBarBearishMomentum &&
|
||||
cBar.open > conditions.kiBuffer[cIDX] &&
|
||||
cBar.close < conditions.kiBuffer[cIDX] &&
|
||||
cBar.open > conditions.trendBuffer[cIDX] &&
|
||||
cBar.close > conditions.trendBuffer[cIDX];
|
||||
|
||||
//
|
||||
bool isKITrendBreaked =
|
||||
isBarBreakedKITrendBullish ||
|
||||
isBarBreakedKITrendBearish;
|
||||
|
||||
//
|
||||
if (isKITrendBreaked)
|
||||
{
|
||||
Print("KI Trend Breaked ...");
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// while (index <= end)
|
||||
// {
|
||||
// //
|
||||
// XCAEAConditions iConditions;
|
||||
// bool has = helper.GetConditions(
|
||||
// iConditions,
|
||||
// index,
|
||||
// 5 //
|
||||
// );
|
||||
// if (!has)
|
||||
// {
|
||||
// //
|
||||
// iConditions.Clean();
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// //
|
||||
// zIDX = 0;
|
||||
// cIDX = zIDX + 1;
|
||||
// pIDX = cIDX + 1;
|
||||
// p2IDX = pIDX + 1;
|
||||
|
||||
// //
|
||||
// XOHCL cBar;
|
||||
// has = cBar.Init(
|
||||
// iConditions.symbol,
|
||||
// iConditions.period,
|
||||
// index + 1 //
|
||||
// );
|
||||
// if (!has)
|
||||
// {
|
||||
// //
|
||||
// cBar.Clean();
|
||||
// iConditions.Clean();
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Read Reuired Data ...
|
||||
|
||||
// //
|
||||
// // KI ...
|
||||
|
||||
// //
|
||||
// double cKI = iConditions.kiBuffer[cIDX];
|
||||
// double pKI = iConditions.kiBuffer[pIDX];
|
||||
// double p2KI = iConditions.kiBuffer[p2IDX];
|
||||
|
||||
// //
|
||||
// double cKIState = iConditions.kiStateBuffer[cIDX];
|
||||
// double pKIState = iConditions.kiStateBuffer[pIDX];
|
||||
// double p2KIState = iConditions.kiStateBuffer[p2IDX];
|
||||
|
||||
// //
|
||||
// // TKI ...
|
||||
|
||||
// //
|
||||
// double cTKI = iConditions.tkiBuffer[cIDX];
|
||||
// double pTKI = iConditions.tkiBuffer[pIDX];
|
||||
// double p2TKI = iConditions.tkiBuffer[p2IDX];
|
||||
|
||||
// //
|
||||
// double cTKIState = iConditions.tkiStateBuffer[cIDX];
|
||||
// double pTKIState = iConditions.tkiStateBuffer[pIDX];
|
||||
// double p2TKIState = iConditions.tkiStateBuffer[p2IDX];
|
||||
|
||||
// //
|
||||
// // TREND ...
|
||||
|
||||
// //
|
||||
// double cTrend = iConditions.trendBuffer[cIDX];
|
||||
// double pTrend = iConditions.trendBuffer[pIDX];
|
||||
// double p2Trend = iConditions.trendBuffer[p2IDX];
|
||||
|
||||
// //
|
||||
// double ctrendState = iConditions.trendStateBuffer[cIDX];
|
||||
// double ptrendState = iConditions.trendStateBuffer[pIDX];
|
||||
// double p2trendState = iConditions.trendStateBuffer[p2IDX];
|
||||
|
||||
// //
|
||||
// // SWING Low ...
|
||||
|
||||
// //
|
||||
// double cSWL = iConditions.swingLowBuffer[cIDX];
|
||||
// double pSWL = iConditions.swingLowBuffer[pIDX];
|
||||
// double p2SWL = iConditions.swingLowBuffer[p2IDX];
|
||||
|
||||
// //
|
||||
// // SWING High ...
|
||||
|
||||
// //
|
||||
// double cSWH = iConditions.swingHighBuffer[cIDX];
|
||||
// double pSWH = iConditions.swingHighBuffer[pIDX];
|
||||
// double p2SWH = iConditions.swingHighBuffer[p2IDX];
|
||||
|
||||
// //
|
||||
// // PEAK ...
|
||||
|
||||
// //
|
||||
// double cPeak = iConditions.peakBuffer[cIDX];
|
||||
// double pPeak = iConditions.peakBuffer[pIDX];
|
||||
// double p2Peak = iConditions.peakBuffer[p2IDX];
|
||||
|
||||
// //
|
||||
// // VALE ...
|
||||
|
||||
// //
|
||||
// double cVale = iConditions.valeBuffer[cIDX];
|
||||
// double pVale = iConditions.valeBuffer[pIDX];
|
||||
// double p2Vale = iConditions.valeBuffer[p2IDX];
|
||||
|
||||
// //
|
||||
// // Required Condirions ...
|
||||
|
||||
// //
|
||||
// bool isTKITRNDBullish =
|
||||
// iConditions.isKIBullish &&
|
||||
// iConditions.isTKIBullish &&
|
||||
// iConditions.isTrendBullish;
|
||||
|
||||
// //
|
||||
// bool isTKITRNDBearish =
|
||||
// iConditions.isKIBearish &&
|
||||
// iConditions.isTKIBearish &&
|
||||
// iConditions.isTrendBearish;
|
||||
|
||||
// //
|
||||
// XBoxZone iBox;
|
||||
|
||||
// //
|
||||
// // Check FVG ...
|
||||
// bool isFVG = barAnalyser.IsFVG(
|
||||
// cBar,
|
||||
// iBox,
|
||||
// false // Force Same Bars ...
|
||||
// );
|
||||
// if (isFVG)
|
||||
// {
|
||||
// //
|
||||
// // Validate FVG ...
|
||||
// bool isFVGBullish = iBox.IsBullish();
|
||||
|
||||
// // //
|
||||
// // isFVG =
|
||||
// // isFVGBullish
|
||||
// // ? isTKITRNDBullish
|
||||
// // : isTKITRNDBearish;
|
||||
|
||||
// //
|
||||
// if (isFVG)
|
||||
// {
|
||||
// //
|
||||
// XCBoxObject *iObj;
|
||||
// has = drawer.DrawBox(
|
||||
// iBox,
|
||||
// iObj //
|
||||
// );
|
||||
// if (has)
|
||||
// {
|
||||
// iObj.BoxWidth(2);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// //
|
||||
// index++;
|
||||
// cBar.Clean();
|
||||
// iConditions.Clean();
|
||||
// }
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
XBoxZone tmpFVGBoxes[];
|
||||
|
||||
//
|
||||
int index = barIndex;
|
||||
int end = index + loopback;
|
||||
while (index <= end)
|
||||
{
|
||||
//
|
||||
XOHCL cBar;
|
||||
bool has = cBar.Init(
|
||||
helper.GetSymbol(),
|
||||
helper.GetPeriod(),
|
||||
index + 1 //
|
||||
);
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
cBar.Clean();
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Check FVG ...
|
||||
XBoxZone iBox;
|
||||
bool isFVG = barAnalyser.IsFVG(
|
||||
cBar,
|
||||
iBox,
|
||||
false // Force Same Bars ...
|
||||
);
|
||||
if (isFVG)
|
||||
{
|
||||
//
|
||||
AddBox(
|
||||
iBox,
|
||||
tmpFVGBoxes //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
index++;
|
||||
cBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
int idx = -1;
|
||||
bool has = false;
|
||||
if (HasChild(tmpFVGBoxes))
|
||||
{
|
||||
//
|
||||
while (HasChild(tmpFVGBoxes))
|
||||
{
|
||||
//
|
||||
idx = GetYoungest(tmpFVGBoxes);
|
||||
has = IsValidIndex(idx);
|
||||
if (!has)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
XBoxZone iBox = tmpFVGBoxes[idx];
|
||||
ArrayRemove(
|
||||
tmpFVGBoxes,
|
||||
idx,
|
||||
1 //
|
||||
);
|
||||
|
||||
//
|
||||
// Here We Have to Validate FVG ...
|
||||
|
||||
//
|
||||
XCBoxObject *iObj;
|
||||
has = drawer.DrawBox(
|
||||
iBox,
|
||||
iObj //
|
||||
);
|
||||
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
has = HasPeakPivots();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
count = CountPeakPivots();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XCAPivot iPivot = peakPivots[i];
|
||||
|
||||
//
|
||||
int toIDX = iPivot.ToIndex();
|
||||
int fromIDX = iPivot.FromIndex();
|
||||
has = IsValidIndex(toIDX) &&
|
||||
IsValidIndex(fromIDX);
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
iPivot.Clean();
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
for (int j = toIDX; j <= fromIDX; j++) {
|
||||
//
|
||||
XCAEAConditions jConditions;
|
||||
has = helper.GetConditions(
|
||||
jConditions,
|
||||
j,
|
||||
5 //
|
||||
);
|
||||
if (!has) {
|
||||
//
|
||||
jConditions.Clean();
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
datetime jTime = GetBarTime(
|
||||
jConditions.symbol,
|
||||
jConditions.period,
|
||||
j //
|
||||
);
|
||||
|
||||
//
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
iPivot.Clean();
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
|
||||
//
|
||||
// PEAKS ...
|
||||
|
||||
//
|
||||
// VALES ...
|
||||
|
||||
//
|
||||
// PEAK SWH RES ...
|
||||
|
||||
//
|
||||
// VALE SWL SUP ...
|
||||
|
||||
//
|
||||
// SWING HIGH ...
|
||||
|
||||
//
|
||||
// SWING LOW ...
|
||||
|
||||
//
|
||||
// KI ...
|
||||
|
||||
//
|
||||
// TKI ...
|
||||
|
||||
//
|
||||
// FVG ...
|
||||
|
||||
//
|
||||
// TREND ...
|
||||
|
||||
//
|
||||
// TKITRND ...
|
||||
|
||||
//
|
||||
// SAME CYCLES HH / LL ...
|
||||
|
||||
//
|
||||
// OSCS ...
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
|
||||
//
|
||||
// CCI ...
|
||||
@@ -0,0 +1,816 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
bool DetectXCAEAConditions(
|
||||
XBoxZone &boxes[],
|
||||
XCAEAConditions &conditions,
|
||||
XBoxZone &pivotBox,
|
||||
XBoxZone &box,
|
||||
ENUM_X_DIRECTION &dir,
|
||||
XCXCAEAHelper *helper,
|
||||
int barIndex = 0,
|
||||
int loopback = 10 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
int idx = -1;
|
||||
int count = 0;
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
box.Clean();
|
||||
conditions.Clean();
|
||||
dir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
loopback = NormalizeInt(loopback, 5);
|
||||
|
||||
//
|
||||
string symbol = helper.GetSymbol();
|
||||
ENUM_TIMEFRAMES period = helper.GetPeriod();
|
||||
|
||||
//
|
||||
result = helper.GetConditions(
|
||||
conditions,
|
||||
barIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
conditions.Clean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int zIDX = barIndex;
|
||||
int cIDX = zIDX + 1;
|
||||
int pIDX = cIDX + 1;
|
||||
int p2IDX = pIDX + 1;
|
||||
int p3IDX = p2IDX + 1;
|
||||
int p4IDX = p3IDX + 1;
|
||||
|
||||
//
|
||||
// Reading Parameters ...
|
||||
|
||||
//
|
||||
// KI ...
|
||||
|
||||
//
|
||||
double cKI = conditions.kiBuffer[cIDX];
|
||||
double pKI = conditions.kiBuffer[pIDX];
|
||||
double p2KI = conditions.kiBuffer[p2IDX];
|
||||
|
||||
//
|
||||
double cKIState = conditions.kiStateBuffer[cIDX];
|
||||
double pKIState = conditions.kiStateBuffer[pIDX];
|
||||
double p2KIState = conditions.kiStateBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// TKI ...
|
||||
|
||||
//
|
||||
double cTKI = conditions.tkiBuffer[cIDX];
|
||||
double pTKI = conditions.tkiBuffer[pIDX];
|
||||
double p2TKI = conditions.tkiBuffer[p2IDX];
|
||||
|
||||
//
|
||||
double cTKIState = conditions.tkiStateBuffer[cIDX];
|
||||
double pTKIState = conditions.tkiStateBuffer[pIDX];
|
||||
double p2TKIState = conditions.tkiStateBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// TREND ...
|
||||
|
||||
//
|
||||
double cTrend = conditions.trendBuffer[cIDX];
|
||||
double pTrend = conditions.trendBuffer[pIDX];
|
||||
double p2Trend = conditions.trendBuffer[p2IDX];
|
||||
|
||||
//
|
||||
double ctrendState = conditions.trendStateBuffer[cIDX];
|
||||
double ptrendState = conditions.trendStateBuffer[pIDX];
|
||||
double p2trendState = conditions.trendStateBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// SWING Low ...
|
||||
double cSWL = conditions.swingLowBuffer[cIDX];
|
||||
double pSWL = conditions.swingLowBuffer[pIDX];
|
||||
double p2SWL = conditions.swingLowBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// SWING High ...
|
||||
double cSWH = conditions.swingHighBuffer[cIDX];
|
||||
double pSWH = conditions.swingHighBuffer[pIDX];
|
||||
double p2SWH = conditions.swingHighBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// PEAK ...
|
||||
double zPeak = conditions.peakBuffer[zIDX];
|
||||
double cPeak = conditions.peakBuffer[cIDX];
|
||||
double pPeak = conditions.peakBuffer[pIDX];
|
||||
double p2Peak = conditions.peakBuffer[p2IDX];
|
||||
double p3Peak = conditions.peakBuffer[p3IDX];
|
||||
|
||||
//
|
||||
// VALE ...
|
||||
double zVale = conditions.valeBuffer[zIDX];
|
||||
double cVale = conditions.valeBuffer[cIDX];
|
||||
double pVale = conditions.valeBuffer[pIDX];
|
||||
double p2Vale = conditions.valeBuffer[p2IDX];
|
||||
double p3Vale = conditions.valeBuffer[p3IDX];
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
double zRSI = conditions.rsiBuffer[zIDX];
|
||||
double cRSI = conditions.rsiBuffer[cIDX];
|
||||
double pRSI = conditions.rsiBuffer[pIDX];
|
||||
double p2RSI = conditions.rsiBuffer[p2IDX];
|
||||
double p3RSI = conditions.rsiBuffer[p3IDX];
|
||||
|
||||
//
|
||||
// CCI ...
|
||||
double zCCI = conditions.cciBuffer[zIDX];
|
||||
double cCCI = conditions.cciBuffer[cIDX];
|
||||
double pCCI = conditions.cciBuffer[pIDX];
|
||||
double p2CCI = conditions.cciBuffer[p2IDX];
|
||||
double p3CCI = conditions.cciBuffer[p3IDX];
|
||||
|
||||
//
|
||||
// RVI ...
|
||||
|
||||
//
|
||||
double zRVI = conditions.rviBuffer[zIDX];
|
||||
double cRVI = conditions.rviBuffer[cIDX];
|
||||
double pRVI = conditions.rviBuffer[pIDX];
|
||||
double p2RVI = conditions.rviBuffer[p2IDX];
|
||||
double p3RVI = conditions.rviBuffer[p3IDX];
|
||||
|
||||
//
|
||||
double zRVISignal = conditions.rviSignalBuffer[zIDX];
|
||||
double cRVISignal = conditions.rviSignalBuffer[cIDX];
|
||||
double pRVISignal = conditions.rviSignalBuffer[pIDX];
|
||||
double p2RVISignal = conditions.rviSignalBuffer[p2IDX];
|
||||
double p3RVISignal = conditions.rviSignalBuffer[p3IDX];
|
||||
|
||||
//
|
||||
// Reading Bars ...
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
XOHCL cBar;
|
||||
XOHCL pBar;
|
||||
XOHCL p2Bar;
|
||||
XOHCL p3Bar;
|
||||
XOHCL p4Bar;
|
||||
result = zBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
zIDX //
|
||||
);
|
||||
result =
|
||||
result &&
|
||||
zBar.GetPreviousBar(cBar);
|
||||
result =
|
||||
result &&
|
||||
cBar.GetPreviousBar(pBar);
|
||||
result =
|
||||
result &&
|
||||
pBar.GetPreviousBar(p2Bar);
|
||||
result =
|
||||
result &&
|
||||
p2Bar.GetPreviousBar(p3Bar);
|
||||
result =
|
||||
result &&
|
||||
p3Bar.GetPreviousBar(p4Bar);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
p2Bar.Clean();
|
||||
p3Bar.Clean();
|
||||
p4Bar.Clean();
|
||||
|
||||
//
|
||||
box.Clean();
|
||||
conditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Bars Conditions ...
|
||||
|
||||
//
|
||||
ENUM_X_DIRECTION cBarDir;
|
||||
|
||||
//
|
||||
// Hammer ...
|
||||
bool isCBarHammer = helper
|
||||
.barAnalyser
|
||||
.IsHammer(
|
||||
cBar,
|
||||
cBarDir //
|
||||
);
|
||||
bool isCBarBullishHammer =
|
||||
isCBarHammer &&
|
||||
IsBullish(cBarDir);
|
||||
bool isCBarBearishHammer =
|
||||
isCBarHammer &&
|
||||
IsBearish(cBarDir);
|
||||
|
||||
//
|
||||
// Rejected ...
|
||||
bool isCBarRejected = helper
|
||||
.barAnalyser
|
||||
.IsRejected(
|
||||
cBar,
|
||||
cBarDir,
|
||||
false, // Force Type ...
|
||||
true // Force Fibo Pressure ...
|
||||
);
|
||||
bool isCBarBullishRejected =
|
||||
isCBarRejected &&
|
||||
IsBullish(cBarDir);
|
||||
bool isCBarBearishRejected =
|
||||
isCBarRejected &&
|
||||
IsBearish(cBarDir);
|
||||
|
||||
//
|
||||
// Engulfed ...
|
||||
bool isCBarEngulfed = helper
|
||||
.barAnalyser
|
||||
.IsEngulfed(
|
||||
cBar,
|
||||
cBarDir //
|
||||
);
|
||||
bool isCBarBullishEngulfed =
|
||||
isCBarEngulfed &&
|
||||
IsBullish(cBarDir);
|
||||
bool isCBarBearishEngulfed =
|
||||
isCBarEngulfed &&
|
||||
IsBearish(cBarDir);
|
||||
|
||||
//
|
||||
// Momentum ...
|
||||
bool isCBarMomentum = helper
|
||||
.barAnalyser
|
||||
.IsMomentum(
|
||||
cBar,
|
||||
cBarDir,
|
||||
1 //
|
||||
);
|
||||
bool isCBarBullishMomentum =
|
||||
isCBarMomentum &&
|
||||
IsBullish(cBarDir);
|
||||
bool isCBarBearishMomentum =
|
||||
isCBarMomentum &&
|
||||
IsBearish(cBarDir);
|
||||
|
||||
//
|
||||
// Bar Sumarise ...
|
||||
|
||||
//
|
||||
bool isCBarValidForBullish =
|
||||
(isCBarBullishHammer ||
|
||||
isCBarBullishRejected ||
|
||||
isCBarBullishMomentum ||
|
||||
isCBarBullishEngulfed);
|
||||
|
||||
//
|
||||
bool isCBarValidForBearish =
|
||||
(isCBarBearishHammer ||
|
||||
isCBarBearishRejected ||
|
||||
isCBarBearishMomentum ||
|
||||
isCBarBearishEngulfed);
|
||||
|
||||
//
|
||||
double pBarLowShadow = pBar.GetLowShadow();
|
||||
double pBarHighShadow = pBar.GetHighShadow();
|
||||
|
||||
//
|
||||
bool isPBarSwingLow =
|
||||
pBarLowShadow > 0 &&
|
||||
pBar.low < p2Bar.low &&
|
||||
pBar.low < cBar.low &&
|
||||
p2Bar.GetUp() >= pBar.low &&
|
||||
p2Bar.GetDown() <= pBar.high &&
|
||||
cBar.GetUp() >= pBar.low &&
|
||||
cBar.GetDown() <= pBar.high;
|
||||
|
||||
//
|
||||
bool isPBarSwingHigh =
|
||||
pBarHighShadow > 0 &&
|
||||
pBar.high > p2Bar.high &&
|
||||
pBar.high > cBar.high &&
|
||||
p2Bar.GetUp() >= pBar.low &&
|
||||
p2Bar.GetDown() <= pBar.high &&
|
||||
cBar.GetUp() >= pBar.low &&
|
||||
cBar.GetDown() <= pBar.high;
|
||||
|
||||
//
|
||||
// Score ...
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
conditions.GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
bool isScoreBullish =
|
||||
bullishScore > bearishScore;
|
||||
|
||||
//
|
||||
bool isScoreBearish =
|
||||
bearishScore > bullishScore;
|
||||
|
||||
//
|
||||
string summary =
|
||||
conditions
|
||||
.GenerateSummary();
|
||||
|
||||
//
|
||||
// Detect Selected Box ...
|
||||
double providedSL = 0;
|
||||
bool isBoxRejected = false;
|
||||
bool isBoxActivated = false;
|
||||
bool hasBoxes = HasChild(boxes);
|
||||
if (hasBoxes)
|
||||
{
|
||||
//
|
||||
// Detect Selected Boxes ...
|
||||
XBoxZone tmp[];
|
||||
Copy(
|
||||
boxes,
|
||||
tmp //
|
||||
);
|
||||
while (HasChild(tmp))
|
||||
{
|
||||
//
|
||||
idx = GetYoungest(tmp);
|
||||
has = IsValidIndex(idx);
|
||||
if (!has)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
XBoxZone iBox;
|
||||
iBox = tmp[idx];
|
||||
ArrayRemove(
|
||||
tmp,
|
||||
idx,
|
||||
1 //
|
||||
);
|
||||
|
||||
//
|
||||
// Check Selected Box not RSI or CCI ...
|
||||
has = iBox.type == ToString(XCA_PEAKSWHRES) ||
|
||||
iBox.type == ToString(XCA_VALESWLSUP);
|
||||
if (!has)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
bool isBullish = iBox.IsBullish();
|
||||
bool isBearish = iBox.IsBearish();
|
||||
|
||||
//
|
||||
double rejectedCheckPrice =
|
||||
isBullish
|
||||
? iBox.upper
|
||||
: iBox.lower;
|
||||
|
||||
//
|
||||
// Check Box Selecting Senarios ...
|
||||
|
||||
//
|
||||
// Selecting Rejected Boxes ...
|
||||
isBoxRejected = cBar.IsRejected(
|
||||
rejectedCheckPrice,
|
||||
iBox.dir,
|
||||
false,
|
||||
false //
|
||||
);
|
||||
|
||||
//
|
||||
// Selecting Activation Boxes ...
|
||||
|
||||
//
|
||||
bool isBullishActivated =
|
||||
isBullish &&
|
||||
isPBarSwingLow &&
|
||||
cBar.IsBullish() &&
|
||||
cBar.GetUp() > rejectedCheckPrice &&
|
||||
cBar.GetDown() < rejectedCheckPrice;
|
||||
|
||||
//
|
||||
bool isBearishActivated =
|
||||
isBearish &&
|
||||
isPBarSwingHigh &&
|
||||
cBar.IsBearish() &&
|
||||
cBar.GetUp() > rejectedCheckPrice &&
|
||||
cBar.GetDown() < rejectedCheckPrice;
|
||||
|
||||
//
|
||||
isBoxActivated = isBullishActivated ||
|
||||
isBearishActivated;
|
||||
|
||||
//
|
||||
// Detect Box is Selected or not ...
|
||||
has =
|
||||
isBoxRejected ||
|
||||
isBoxActivated;
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
pivotBox = iBox;
|
||||
|
||||
//
|
||||
iBox.Clean();
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
iBox.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
Clean(tmp);
|
||||
}
|
||||
|
||||
//
|
||||
// Force Conditions to Have Selected Box ...
|
||||
result = hasBoxes &&
|
||||
pivotBox.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
p2Bar.Clean();
|
||||
p3Bar.Clean();
|
||||
p4Bar.Clean();
|
||||
|
||||
//
|
||||
box.Clean();
|
||||
pivotBox.Clean();
|
||||
conditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isRSIBullish =
|
||||
zRSI >= cRSI &&
|
||||
cRSI > pRSI;
|
||||
bool isRSIBearish =
|
||||
zRSI <= cRSI &&
|
||||
cRSI < pRSI;
|
||||
|
||||
//
|
||||
bool isCCIBullish =
|
||||
zCCI >= cCCI &&
|
||||
cCCI > pCCI &&
|
||||
(zCCI > conditions.cciOSLevel ||
|
||||
cCCI > conditions.cciOSLevel);
|
||||
bool isCCIBearish =
|
||||
zCCI >= cCCI &&
|
||||
cCCI > pCCI &&
|
||||
(zCCI < conditions.cciOBLevel ||
|
||||
cCCI < conditions.cciOBLevel);
|
||||
|
||||
//
|
||||
// Signaller Summarization ...
|
||||
|
||||
//
|
||||
// Cond1 Act Using Box Activation ...
|
||||
|
||||
//
|
||||
bool isCond1Bullish =
|
||||
//
|
||||
false &&
|
||||
isCCIBullish &&
|
||||
isBoxActivated &&
|
||||
pivotBox.IsValid() &&
|
||||
pivotBox.IsBullish()
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isCond1Bearish =
|
||||
//
|
||||
false &&
|
||||
isCCIBearish &&
|
||||
isBoxActivated &&
|
||||
pivotBox.IsValid() &&
|
||||
pivotBox.IsBearish()
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isCond1 = isCond1Bullish ||
|
||||
isCond1Bearish;
|
||||
if (isCond1)
|
||||
{
|
||||
//
|
||||
providedSL =
|
||||
isCond1Bullish
|
||||
? MathMin(pBar.low, pivotBox.lower)
|
||||
: MathMax(pBar.high, pivotBox.upper);
|
||||
|
||||
//
|
||||
Print("Cond1");
|
||||
}
|
||||
|
||||
//
|
||||
// Cond2 Act Using Box Rejection ...
|
||||
|
||||
//
|
||||
bool isCond2Bullish =
|
||||
//
|
||||
false &&
|
||||
isBoxRejected &&
|
||||
pivotBox.IsValid() &&
|
||||
pivotBox.IsBullish()
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isCond2Bearish =
|
||||
//
|
||||
false &&
|
||||
isBoxRejected &&
|
||||
pivotBox.IsValid() &&
|
||||
pivotBox.IsBearish()
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isCond2 = isCond2Bullish ||
|
||||
isCond2Bearish;
|
||||
if (isCond2)
|
||||
{
|
||||
//
|
||||
providedSL =
|
||||
isCond1Bullish
|
||||
? MathMin(pBar.low, pivotBox.lower)
|
||||
: MathMax(pBar.high, pivotBox.upper);
|
||||
|
||||
//
|
||||
Print("Cond2");
|
||||
}
|
||||
|
||||
//
|
||||
// Cond3 Act Using CCi Peaks and Vales ...
|
||||
|
||||
//
|
||||
bool isCond3Bullish = false;
|
||||
|
||||
//
|
||||
bool isCond3Bearish = false;
|
||||
|
||||
//
|
||||
bool isCond3 = isCond3Bullish ||
|
||||
isCond3Bearish;
|
||||
if (isCond3)
|
||||
{
|
||||
//
|
||||
|
||||
//
|
||||
Print("Cond3");
|
||||
}
|
||||
|
||||
//
|
||||
// Summarise Conditions ...
|
||||
|
||||
//
|
||||
bool isBullish =
|
||||
//
|
||||
isCond1Bullish ||
|
||||
isCond2Bullish;
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isBearish =
|
||||
//
|
||||
isCond1Bearish ||
|
||||
isCond2Bearish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
dir =
|
||||
isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
double entry = GetEntry(
|
||||
conditions.symbol,
|
||||
dir //
|
||||
);
|
||||
|
||||
//
|
||||
double sl =
|
||||
providedSL > 0
|
||||
? providedSL
|
||||
: isBullish
|
||||
? pivotBox.lower
|
||||
: pivotBox.upper;
|
||||
|
||||
//
|
||||
box.dir = dir;
|
||||
box.symbol = conditions.symbol;
|
||||
box.period = conditions.period;
|
||||
|
||||
//
|
||||
box.upper =
|
||||
isBullish
|
||||
? entry
|
||||
: sl;
|
||||
|
||||
//
|
||||
box.lower =
|
||||
isBullish
|
||||
? sl
|
||||
: entry;
|
||||
|
||||
//
|
||||
box.to = zBar.time;
|
||||
box.from = p4Bar.time;
|
||||
|
||||
//
|
||||
box.type = "XCASignal";
|
||||
}
|
||||
|
||||
//
|
||||
result = box.IsValid() &&
|
||||
HasDirection(dir);
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
box.Clean();
|
||||
pivotBox.Clean();
|
||||
conditions.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
p2Bar.Clean();
|
||||
p3Bar.Clean();
|
||||
p4Bar.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Detect Trend Lines ...
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
bool canLookupValeTrendLine =
|
||||
detector.HasRSIValePivots() &&
|
||||
detector.CountRSIValePivots() >= 2;
|
||||
if (canLookupValeTrendLine)
|
||||
{
|
||||
//
|
||||
XBoxZone rsiVale;
|
||||
XBoxZone rsiValePrev;
|
||||
count = detector.CountRSIValePivots();
|
||||
has = detector.rsiValePivots[count - 1].AsBox(rsiValePrev);
|
||||
has = has &&
|
||||
detector.rsiValePivots[count - 2].AsBox(rsiVale);
|
||||
bool hasTrend = has &&
|
||||
rsiVale.lower > rsiValePrev.lower;
|
||||
|
||||
//
|
||||
if (hasTrend)
|
||||
{
|
||||
//
|
||||
string valeTrendLineName = "RSIValeTrendLine";
|
||||
CChartObjectTrend *iVTLine;
|
||||
iVTLine = new CChartObjectTrend();
|
||||
has = iVTLine.Create(
|
||||
0,
|
||||
valeTrendLineName,
|
||||
0,
|
||||
rsiValePrev.from,
|
||||
rsiValePrev.lower,
|
||||
rsiVale.to,
|
||||
rsiVale.lower //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
iVTLine.RayRight(true);
|
||||
iVTLine.Width(2);
|
||||
iVTLine.Color(clrAqua);
|
||||
iVTLine.Style(STYLE_SOLID);
|
||||
|
||||
//
|
||||
mObjects.Add(iVTLine);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
rsiVale.Clean();
|
||||
rsiValePrev.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// CCI ...
|
||||
// canLookupValeTrendLine =
|
||||
// detector.HasCCIValePivots() &&
|
||||
// detector.CountCCIValePivots() >= 2;
|
||||
// if (canLookupValeTrendLine)
|
||||
// {
|
||||
// //
|
||||
// XBoxZone cciVale;
|
||||
// XBoxZone cciValePrev;
|
||||
// count = detector.CountCCIValePivots();
|
||||
// has = detector.cciValePivots[count - 1].AsBox(cciValePrev);
|
||||
// has = has &&
|
||||
// detector.cciValePivots[count - 2].AsBox(cciVale);
|
||||
// bool hasTrend = has &&
|
||||
// cciVale.lower > cciValePrev.lower;
|
||||
|
||||
// //
|
||||
// if (hasTrend)
|
||||
// {
|
||||
// //
|
||||
// string valeTrendLineName = "CCIValeTrendLine";
|
||||
// CChartObjectTrend *iVTLine;
|
||||
// iVTLine = new CChartObjectTrend();
|
||||
// has = iVTLine.Create(
|
||||
// 0,
|
||||
// valeTrendLineName,
|
||||
// 0,
|
||||
// cciValePrev.from,
|
||||
// cciValePrev.lower,
|
||||
// cciVale.to,
|
||||
// cciVale.lower //
|
||||
// );
|
||||
// if (has)
|
||||
// {
|
||||
// //
|
||||
// iVTLine.RayRight(true);
|
||||
// iVTLine.Width(2);
|
||||
// iVTLine.Color(clrAqua);
|
||||
// iVTLine.Style(STYLE_SOLID);
|
||||
|
||||
// //
|
||||
// mObjects.Add(iVTLine);
|
||||
// }
|
||||
// }
|
||||
|
||||
// //
|
||||
// cciVale.Clean();
|
||||
// cciValePrev.Clean();
|
||||
// }
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -0,0 +1,481 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: XCXCAEAPOIDetector ...
|
||||
// Description: Class for XCAEA POI Detector ...
|
||||
//
|
||||
//
|
||||
// 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 Class for XCAEA POI Detector"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../../Classes/x-saherelm.x-bar.analyser.class.mq5"
|
||||
#include "../Helpers/xcaea.helper.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
// enum ENUM_X_PIVOT_KINDS
|
||||
// {
|
||||
// X_PIVOT_SWL, // SWL
|
||||
// X_PIVOT_SWH, // SWH
|
||||
// };
|
||||
|
||||
// string ToString(ENUM_X_PIVOT_KINDS value)
|
||||
// {
|
||||
// //
|
||||
// string result = NULL;
|
||||
|
||||
// //
|
||||
// result = EnumToString(value);
|
||||
|
||||
// //
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// struct XSamePivot
|
||||
// {
|
||||
// //
|
||||
// // Props ...
|
||||
// datetime to;
|
||||
// string type;
|
||||
// double value;
|
||||
// datetime from;
|
||||
// string symbol;
|
||||
// ENUM_X_DIRECTION dir;
|
||||
// ENUM_TIMEFRAMES period;
|
||||
|
||||
// //
|
||||
// // Constructor ...
|
||||
// XSamePivot()
|
||||
// {
|
||||
// Clean();
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Tools ...
|
||||
|
||||
// /**
|
||||
// * Cleanup Model ...
|
||||
// */
|
||||
// void Clean()
|
||||
// {
|
||||
// //
|
||||
// to = NULL;
|
||||
// value = 0;
|
||||
// from = NULL;
|
||||
// type = NULL;
|
||||
// symbol = NULL;
|
||||
// period = NULL;
|
||||
// dir = X_DIRECTION_NONE;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Validate Model ...
|
||||
// *
|
||||
// * @return ( bool )
|
||||
// */
|
||||
// bool IsValid()
|
||||
// {
|
||||
// //
|
||||
// bool result = false;
|
||||
|
||||
// //
|
||||
// result =
|
||||
// //
|
||||
// from < to &&
|
||||
// value != 0 &&
|
||||
// IsValid(to) &&
|
||||
// IsValid(from) &&
|
||||
// IsValid(symbol) &&
|
||||
// IsValid(period) &&
|
||||
// HasDirection(dir)
|
||||
// //
|
||||
// ;
|
||||
|
||||
// //
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Check a Model is Same As Other ...
|
||||
// *
|
||||
// * @return ( bool )
|
||||
// */
|
||||
// bool IsSameAs(XSamePivot &item)
|
||||
// {
|
||||
// //
|
||||
// bool result = false;
|
||||
|
||||
// //
|
||||
// result = IsValid() &&
|
||||
// item.IsValid();
|
||||
// if (!result)
|
||||
// {
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// //
|
||||
// result =
|
||||
// //
|
||||
// to == item.to &&
|
||||
// dir == item.dir &&
|
||||
// from == item.from &&
|
||||
// type == item.type &&
|
||||
// value == item.value &&
|
||||
// symbol == item.symbol &&
|
||||
// period == item.period
|
||||
// //
|
||||
// ;
|
||||
|
||||
// //
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// //
|
||||
// };
|
||||
|
||||
//
|
||||
// Implementations ...
|
||||
class XCXCAEAPOIDetector : public XCBase
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XCXCAEAPOIDetector(
|
||||
XCXCAEAHelper *_helper //
|
||||
)
|
||||
{
|
||||
//
|
||||
helper = _helper;
|
||||
barAnalyser = new XCBarAnalyser();
|
||||
|
||||
//
|
||||
Default();
|
||||
}
|
||||
|
||||
//
|
||||
// De Constructors ...
|
||||
~XCXCAEAPOIDetector()
|
||||
{
|
||||
//
|
||||
Clean(tkitrndPivots);
|
||||
|
||||
//
|
||||
ZeroMemory(helper);
|
||||
ZeroMemory(barAnalyser);
|
||||
}
|
||||
|
||||
//
|
||||
// Properties ...
|
||||
|
||||
int TITrndPivotVerification()
|
||||
{
|
||||
return tkitrndPivotVerification;
|
||||
}
|
||||
|
||||
void TKITrndPivotVerification(int value)
|
||||
{
|
||||
//
|
||||
value = NormalizeInt(value, 0);
|
||||
|
||||
//
|
||||
tkitrndPivotVerification = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
virtual void Default()
|
||||
{
|
||||
//
|
||||
TKITrndPivotVerification(10);
|
||||
}
|
||||
|
||||
//
|
||||
void Update(
|
||||
int barIndex = 0,
|
||||
int loopback = 100 //
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
loopback = NormalizeInt(loopback, 100);
|
||||
|
||||
//
|
||||
int index = barIndex;
|
||||
int end = index + loopback;
|
||||
while (index <= end)
|
||||
{
|
||||
//
|
||||
XCAEAConditions iConditions;
|
||||
bool has = helper.GetConditions(
|
||||
iConditions,
|
||||
index,
|
||||
loopback //
|
||||
);
|
||||
|
||||
//
|
||||
// Detecting Same Pivots ...
|
||||
// HandleTKITRNDPivotDetection(iConditions, index);
|
||||
|
||||
//
|
||||
index++;
|
||||
iConditions.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
// POI Handlers ...
|
||||
|
||||
// bool HasTKITRNDPivots()
|
||||
// {
|
||||
// return HasChild(tkitrndPivots);
|
||||
// }
|
||||
|
||||
// int CountTKITRNDPivots()
|
||||
// {
|
||||
// return ArraySize(tkitrndPivots);
|
||||
// }
|
||||
|
||||
// int FillTKITRNDPivots(XSamePivot &pivots[])
|
||||
// {
|
||||
// //
|
||||
// int result = 0;
|
||||
|
||||
// //
|
||||
// if (!HasTKITRNDPivots())
|
||||
// {
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// //
|
||||
// Copy(
|
||||
// tkitrndPivots,
|
||||
// pivots //
|
||||
// );
|
||||
|
||||
// //
|
||||
// result = ArraySize(pivots);
|
||||
|
||||
// //
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// bool IsTKITRNDPivotExists(
|
||||
// int &index,
|
||||
// XSamePivot &pivot //
|
||||
// )
|
||||
// {
|
||||
// //
|
||||
// bool result = false;
|
||||
|
||||
// //
|
||||
// index = -1;
|
||||
|
||||
// //
|
||||
// result = pivot.IsValid() &&
|
||||
// HasTKITRNDPivots();
|
||||
// if (!result)
|
||||
// {
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// //
|
||||
// int count = CountTKITRNDPivots();
|
||||
// for (int i = 0; i < count; i++)
|
||||
// {
|
||||
// //
|
||||
// XSamePivot iPivot = tkitrndPivots[i];
|
||||
|
||||
// //
|
||||
// bool isSame =
|
||||
// pivot.IsSameAs(iPivot);
|
||||
// if (isSame)
|
||||
// {
|
||||
// //
|
||||
// index = i;
|
||||
// iPivot.Clean();
|
||||
|
||||
// //
|
||||
// break;
|
||||
// }
|
||||
|
||||
// //
|
||||
// iPivot.Clean();
|
||||
// }
|
||||
|
||||
// //
|
||||
// result = IsValidIndex(index);
|
||||
|
||||
// //
|
||||
// return result;
|
||||
// }
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
// //
|
||||
// void HandleTKITRNDPivotDetection(
|
||||
// XCAEAConditions &conditions,
|
||||
// int barIndex = 0 //
|
||||
// )
|
||||
// {
|
||||
// //
|
||||
// if (barIndex < 0)
|
||||
// {
|
||||
// barIndex = 0;
|
||||
// }
|
||||
|
||||
// //
|
||||
// if (tkitrndPivotVerification <= 0)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// //
|
||||
// datetime barTime = GetBarTime(
|
||||
// conditions.symbol,
|
||||
// conditions.period,
|
||||
// barIndex + 1 //
|
||||
// );
|
||||
|
||||
// //
|
||||
// int index = 2;
|
||||
// datetime cTime = barTime;
|
||||
// int end = ArraySize(conditions.swingLowBuffer);
|
||||
|
||||
// //
|
||||
// int swingLowVerified = 0;
|
||||
// datetime swingLowFinishAt = NULL;
|
||||
// datetime swingLowStartAt = barTime;
|
||||
// double swingLow = conditions.swingLowBuffer[1];
|
||||
// bool canLookupSwingLow = true;
|
||||
|
||||
// //
|
||||
// bool isVerified = false;
|
||||
// bool canContinue = true;
|
||||
// while (index < end && canContinue)
|
||||
// {
|
||||
// //
|
||||
// cTime += PeriodSeconds(conditions.period);
|
||||
|
||||
// //
|
||||
// // Swing Low ...
|
||||
// double iSWL = conditions.swingLowBuffer[index];
|
||||
// if (iSWL == swingLow)
|
||||
// {
|
||||
// swingLowVerified++;
|
||||
// }
|
||||
// else if (iSWL != swingLow)
|
||||
// {
|
||||
// //
|
||||
// isVerified = swingLowVerified >= tkitrndPivotVerification;
|
||||
// if (isVerified)
|
||||
// {
|
||||
// //
|
||||
// swingLowFinishAt = cTime;
|
||||
|
||||
// //
|
||||
// XSamePivot iPivot;
|
||||
|
||||
// //
|
||||
// iPivot.value = swingLow;
|
||||
// iPivot.to = swingLowFinishAt;
|
||||
// iPivot.from = swingLowStartAt;
|
||||
// iPivot.dir = X_DIRECTION_BULLISH;
|
||||
// iPivot.symbol = conditions.symbol;
|
||||
// iPivot.period = conditions.period;
|
||||
// iPivot.type = ToString(X_PIVOT_SWL);
|
||||
|
||||
// //
|
||||
// if (iPivot.IsValid())
|
||||
// {
|
||||
// AddOrUpdateTKITRNDPivot(iPivot);
|
||||
// }
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Reset ...
|
||||
// swingLow = iSWL;
|
||||
// swingLowVerified = 0;
|
||||
// swingLowFinishAt = NULL;
|
||||
// swingLowStartAt = cTime;
|
||||
// canLookupSwingLow = true;
|
||||
// }
|
||||
|
||||
// //
|
||||
// index++;
|
||||
|
||||
// //
|
||||
// canContinue = canLookupSwingLow;
|
||||
// }
|
||||
// }
|
||||
|
||||
// //
|
||||
// void AddOrUpdateTKITRNDPivot(XSamePivot &pivot)
|
||||
// {
|
||||
// //
|
||||
// int idx = -1;
|
||||
// bool isExists = IsTKITRNDPivotExists(
|
||||
// idx,
|
||||
// pivot //
|
||||
// );
|
||||
// if (isExists)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// //
|
||||
// AddRef(
|
||||
// pivot,
|
||||
// tkitrndPivots //
|
||||
// );
|
||||
// }
|
||||
|
||||
//
|
||||
// Prrivate ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
int tkitrndPivotVerification; // KI/TKI/Trend Verification ...
|
||||
|
||||
//
|
||||
XCXCAEAHelper *helper;
|
||||
XCBarAnalyser *barAnalyser;
|
||||
|
||||
//
|
||||
// Same Pivots ...
|
||||
// XSamePivot tkitrndPivots[]; // TKITrend is Bullish/Bearish and Swing Low/High Under / Over Min / Max ...
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
@@ -0,0 +1,279 @@
|
||||
<mxfile host="65bd71144e">
|
||||
<diagram id="QReEEfusIJtThQdlE9lK" name="Page-1">
|
||||
<mxGraphModel dx="1382" dy="987" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0"/>
|
||||
<mxCell id="1" parent="0"/>
|
||||
<mxCell id="15" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="2" target="3">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="420" y="100"/>
|
||||
<mxPoint x="100" y="100"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="16" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="2" target="6">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="420" y="100"/>
|
||||
<mxPoint x="780" y="100"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="2" value="Position" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="360" y="40" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="17" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="3" target="4">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="100" y="340"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="18" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="3" target="5">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="100" y="620"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="3" value="States" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="40" y="120" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="27" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="4" target="25">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="180" y="420"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="28" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="4" target="26">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="180" y="500"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="4" value="InDrawdown" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="120" y="320" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="29" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="5" target="23">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="180" y="700"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="30" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="5" target="24">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="180" y="780"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="5" value="InProfit" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="120" y="600" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="19" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="6" target="8">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="780" y="220"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="20" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="6" target="9">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="780" y="300"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="21" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="6" target="11">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="780" y="380"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="22" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="6" target="10">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="780" y="460"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="6" value="Events" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="720" y="120" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="31" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="8" target="25">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="260" y="220"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="38" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="8" target="26">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="520" y="220"/>
|
||||
<mxPoint x="520" y="560"/>
|
||||
<mxPoint x="260" y="560"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="39" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="8" target="23">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="560" y="220"/>
|
||||
<mxPoint x="560" y="640"/>
|
||||
<mxPoint x="260" y="640"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="43" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="8" target="24">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="560" y="220"/>
|
||||
<mxPoint x="560" y="840"/>
|
||||
<mxPoint x="260" y="840"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="8" value="Bullish Sign" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="640" y="200" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="32" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="9" target="25">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="260" y="300"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="37" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="9" target="26">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="520" y="300"/>
|
||||
<mxPoint x="520" y="560"/>
|
||||
<mxPoint x="260" y="560"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="40" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="9" target="23">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="560" y="300"/>
|
||||
<mxPoint x="560" y="640"/>
|
||||
<mxPoint x="260" y="640"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="44" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="9" target="24">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="560" y="300"/>
|
||||
<mxPoint x="560" y="840"/>
|
||||
<mxPoint x="260" y="840"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="9" value="Bearish Sign" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="640" y="280" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="34" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;" edge="1" parent="1" source="10">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="260" y="400" as="targetPoint"/>
|
||||
<Array as="points">
|
||||
<mxPoint x="520" y="460"/>
|
||||
<mxPoint x="520" y="360"/>
|
||||
<mxPoint x="260" y="360"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="35" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="10" target="26">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="520" y="460"/>
|
||||
<mxPoint x="520" y="560"/>
|
||||
<mxPoint x="260" y="560"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="42" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;" edge="1" parent="1" source="10">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="260" y="680" as="targetPoint"/>
|
||||
<Array as="points">
|
||||
<mxPoint x="560" y="460"/>
|
||||
<mxPoint x="560" y="640"/>
|
||||
<mxPoint x="260" y="640"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="46" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="10" target="24">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="260" y="810" as="targetPoint"/>
|
||||
<Array as="points">
|
||||
<mxPoint x="560" y="460"/>
|
||||
<mxPoint x="560" y="840"/>
|
||||
<mxPoint x="260" y="840"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="10" value="Bearish Pushed Tick" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="640" y="440" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="33" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="11" target="25">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="520" y="380"/>
|
||||
<mxPoint x="520" y="360"/>
|
||||
<mxPoint x="260" y="360"/>
|
||||
<mxPoint x="260" y="380"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="36" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="11" target="26">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="520" y="380"/>
|
||||
<mxPoint x="520" y="560"/>
|
||||
<mxPoint x="260" y="560"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="41" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="11" target="23">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="560" y="380"/>
|
||||
<mxPoint x="560" y="640"/>
|
||||
<mxPoint x="260" y="640"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="45" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="11" target="24">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="560" y="380"/>
|
||||
<mxPoint x="560" y="840"/>
|
||||
<mxPoint x="260" y="840"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="11" value="Bullish Pushed Tick" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="640" y="360" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="23" value="Long" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="200" y="680" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="24" value="Short" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="200" y="760" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="25" value="Long" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="200" y="400" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="26" value="Short" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="200" y="480" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
||||
@@ -0,0 +1,506 @@
|
||||
/**
|
||||
* XColor Tools Module ...
|
||||
* a module for handle colorify text contents in node js ...
|
||||
*
|
||||
* Maintainer
|
||||
*
|
||||
* Hadi Khazaee Asl <https://saherelm.ir> (hadi_khazaee_asl@yahoo.com)
|
||||
*/
|
||||
|
||||
//
|
||||
//#region Module Imports ...
|
||||
const XValueTools = require("./x-value.tools");
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Constants ...
|
||||
/**
|
||||
* these are available style which can applied to an string ...
|
||||
*/
|
||||
const AVAILABLE_STYLES = {
|
||||
//
|
||||
Bold: "\x1b[1m",
|
||||
Dim: "\x1b[2m",
|
||||
Underlined: "\x1b[4m",
|
||||
Blink: "\x1b[5m",
|
||||
ReverseFandB: "\x1b[7m",
|
||||
Hidden: "\x1b[8m",
|
||||
//
|
||||
// Commonly used for reset all Styles ...
|
||||
Reset: "\x1b[0m"
|
||||
};
|
||||
|
||||
/**
|
||||
* these are available foreground colors which can applied to an string ...
|
||||
*/
|
||||
const AVAILABLE_FOREGROUND_COLORS = {
|
||||
Default: "\x1b[39m",
|
||||
Black: "\x1b[30m",
|
||||
Red: "\x1b[31m",
|
||||
Green: "\x1b[32m",
|
||||
Yellow: "\x1b[33m",
|
||||
Blue: "\x1b[34m",
|
||||
Magenta: "\x1b[35m",
|
||||
Cyan: "\x1b[36m",
|
||||
LightGray: "\x1b[37m",
|
||||
DarkGray: "\x1b[90m",
|
||||
LightRed: "\x1b[91m",
|
||||
LightGreen: "\x1b[92m",
|
||||
LightYellow: "\x1b[93m",
|
||||
LightBlue: "\x1b[94m",
|
||||
LightMagenta: "\x1b[95m",
|
||||
LightCyan: "\x1b[96m",
|
||||
White: "\x1b[97m",
|
||||
};
|
||||
|
||||
/**
|
||||
* these are available background colors which can applied to an string ...
|
||||
*/
|
||||
const AVAILABLE_BACKGROUND_COLORS = {
|
||||
Default: "\x1b[49m",
|
||||
Black: "\x1b[40m",
|
||||
Red: "\x1b[41m",
|
||||
Green: "\x1b[42m",
|
||||
Yellow: "\x1b[43m",
|
||||
Blue: "\x1b[44m",
|
||||
Magenta: "\x1b[45m",
|
||||
Cyan: "\x1b[46m",
|
||||
LightGray: "\x1b[47m",
|
||||
DarkGray: "\x1b[100m",
|
||||
LightRed: "\x1b[101m",
|
||||
LightGreen: "\x1b[102m",
|
||||
LightYellow: "\x1b[103m",
|
||||
LightBlue: "\x1b[104m",
|
||||
LightMagenta: "\x1b[105m",
|
||||
LightCyan: "\x1b[106m",
|
||||
White: "\x1b[107m",
|
||||
};
|
||||
|
||||
/**
|
||||
* these are available style names, which exports from module and
|
||||
* users can use them ...
|
||||
*/
|
||||
const STYLE_NAMES = {
|
||||
Bold: "Bold",
|
||||
Dim: "Dim",
|
||||
Underlined: "Underlined",
|
||||
Blink: "Blink",
|
||||
ReverseFandB: "ReverseFandB",
|
||||
Hidden: "Hidden",
|
||||
Reset: "Reset",
|
||||
};
|
||||
|
||||
/**
|
||||
* these are available color names, which exports from module and
|
||||
* users can use them ...
|
||||
*/
|
||||
const COLOR_NAMES = {
|
||||
Default: "Default",
|
||||
Black: "Black",
|
||||
Red: "Red",
|
||||
Green: "Green",
|
||||
Yellow: "Yellow",
|
||||
Blue: "Blue",
|
||||
Magenta: "Magenta",
|
||||
Cyan: "Cyan",
|
||||
LightGray: "LightGray",
|
||||
DarkGray: "DarkGray",
|
||||
LightRed: "LightRed",
|
||||
LightGreen: "LightGreen",
|
||||
LightYellow: "LightYellow",
|
||||
LightBlue: "LightBlue",
|
||||
LightMagenta: "LightMagenta",
|
||||
LightCyan: "LightCyan",
|
||||
White: "White",
|
||||
};
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Actions ...
|
||||
/**
|
||||
* apply specified style and color on a content ...
|
||||
*
|
||||
* @param {string} content specified content for styling ...
|
||||
* @param {string} color specific color name for using to styling ...
|
||||
* @param {string} style soecufic style name to use ...
|
||||
* @param {boolean} toForeground apply specified color as foreground ...
|
||||
* @param {boolean} toBackground apply specified color as background ...
|
||||
* @returns {string} styled content ...
|
||||
*/
|
||||
function apply(
|
||||
content,
|
||||
color,
|
||||
style,
|
||||
toForeground = true,
|
||||
toBackground = false
|
||||
) {
|
||||
//
|
||||
let result = content;
|
||||
|
||||
//
|
||||
// Validate Arg ...
|
||||
if (!XValueTools.isValidArg(content)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect and Validate Style and Apply it ...
|
||||
let eStyle = AVAILABLE_STYLES[style];
|
||||
if (XValueTools.isValidArg(eStyle)) {
|
||||
result = `${eStyle}${result}${AVAILABLE_STYLES.Reset}`;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect and Validate Foreground Color and Apply it ...
|
||||
let eFColor = AVAILABLE_FOREGROUND_COLORS[color];
|
||||
if (
|
||||
!!toForeground
|
||||
&& XValueTools.isValidArg(eFColor)
|
||||
) {
|
||||
result = `${eFColor}${result}${AVAILABLE_STYLES.Reset}`;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect and Validate Background Color and Apply it ...
|
||||
let eBColor = AVAILABLE_BACKGROUND_COLORS[color];
|
||||
if (
|
||||
!!toBackground
|
||||
&& XValueTools.isValidArg(eBColor)
|
||||
) {
|
||||
result = `${eBColor}${result}${AVAILABLE_STYLES.Reset}`;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* apply specific style on a content ...
|
||||
*
|
||||
* @param {string} content specific content which going to styled ...
|
||||
* @param {string} style a member of STYLE_NAMES which specified that which style going to applied to content ...
|
||||
* @returns {string} styled content ...
|
||||
*/
|
||||
function applyStyle(content, style) {
|
||||
//
|
||||
// Validate Arg ...
|
||||
if (!XValueTools.isValidArg(content)) {
|
||||
return content;
|
||||
}
|
||||
|
||||
//
|
||||
let eStyle = AVAILABLE_STYLES[style];
|
||||
if (eStyle === undefined) {
|
||||
return content;
|
||||
}
|
||||
|
||||
//
|
||||
return `${eStyle}${content}${AVAILABLE_STYLES.Reset}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* apply specific foreground color on a content ...
|
||||
*
|
||||
* @param {string} content specific content which going to colorified ...
|
||||
* @param {string} color a member of COLOR_NAMES which specified that which color going to applied to content ...
|
||||
* @returns {string} colorified content ...
|
||||
*/
|
||||
function applyForegroundColor(content, color) {
|
||||
//
|
||||
// Validate Arg ...
|
||||
if (!XValueTools.isValidArg(content)) {
|
||||
return content;
|
||||
}
|
||||
|
||||
//
|
||||
let eColor = AVAILABLE_FOREGROUND_COLORS[color];
|
||||
if (eColor === undefined) {
|
||||
return content;
|
||||
}
|
||||
|
||||
//
|
||||
return `${eColor}${content}${AVAILABLE_STYLES.Reset}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* apply specific background color on a content ...
|
||||
*
|
||||
* @param {string} content specific content which going to colorified ...
|
||||
* @param {string} color a member of COLOR_NAMES which specified that which color going to applied to content ...
|
||||
* @returns {string} colorified content ...
|
||||
*/
|
||||
function applyBackgroundColor(content, color) {
|
||||
//
|
||||
// Validate Arg ...
|
||||
if (!XValueTools.isValidArg(content)) {
|
||||
return content;
|
||||
}
|
||||
|
||||
//
|
||||
let eColor = AVAILABLE_BACKGROUND_COLORS[color];
|
||||
if (eColor === undefined) {
|
||||
return content;
|
||||
}
|
||||
|
||||
//
|
||||
return `${eColor}${content}${AVAILABLE_STYLES.Reset}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate style and color applier expression ...
|
||||
*
|
||||
* @param {string} color specific color name for using to styling ...
|
||||
* @param {string} style soecufic style name to use ...
|
||||
* @param {boolean} reset close applier string by reset styles ...
|
||||
* @param {boolean} toForeground apply specified color as foreground ...
|
||||
* @param {boolean} toBackground apply specified color as background ...
|
||||
* @returns {string} style and color applier string ...
|
||||
*/
|
||||
function getApplier(
|
||||
style = "",
|
||||
color = "",
|
||||
reset = false,
|
||||
toForeground = true,
|
||||
toBackground = false
|
||||
) {
|
||||
//
|
||||
let result = "";
|
||||
|
||||
//
|
||||
// Detect and Validate Style and Apply it ...
|
||||
let eStyle = AVAILABLE_STYLES[style];
|
||||
if (XValueTools.isValidArg(eStyle)) {
|
||||
result = `${eStyle}`;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect and Validate Foreground Color and Apply it ...
|
||||
let eFColor = AVAILABLE_FOREGROUND_COLORS[color];
|
||||
if (
|
||||
!!toForeground
|
||||
&& XValueTools.isValidArg(eFColor)
|
||||
) {
|
||||
result = `${eFColor}`;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect and Validate Background Color and Apply it ...
|
||||
let eBColor = AVAILABLE_BACKGROUND_COLORS[color];
|
||||
if (
|
||||
!!toBackground
|
||||
&& XValueTools.isValidArg(eBColor)
|
||||
) {
|
||||
result = `${eBColor}`;
|
||||
}
|
||||
|
||||
//
|
||||
if (
|
||||
!!reset &&
|
||||
result.length > 0
|
||||
) {
|
||||
result = `${result}${AVAILABLE_STYLES.Reset}`;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate style applier expression ...
|
||||
*
|
||||
* @param {string} style soecufic style name to use ...
|
||||
* @param {boolean} reset close applier string by reset styles ...
|
||||
* @returns {string} style applier string ...
|
||||
*/
|
||||
function getStyleApplier(
|
||||
style = "",
|
||||
reset = false
|
||||
) {
|
||||
//
|
||||
let result = "";
|
||||
|
||||
//
|
||||
// Detect and Validate Style and Apply it ...
|
||||
let eStyle = AVAILABLE_STYLES[style];
|
||||
if (XValueTools.isValidArg(eStyle)) {
|
||||
result = `${eStyle}`;
|
||||
}
|
||||
|
||||
//
|
||||
if (
|
||||
!!reset &&
|
||||
result.length > 0
|
||||
) {
|
||||
result = `${result}${AVAILABLE_STYLES.Reset}`;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate color applier expression ...
|
||||
*
|
||||
* @param {string} color specific color name for using to styling ...
|
||||
* @param {boolean} reset close applier string by reset styles ...
|
||||
* @param {boolean} toForeground apply specified color as foreground ...
|
||||
* @param {boolean} toBackground apply specified color as background ...
|
||||
* @returns {string} color applier string ...
|
||||
*/
|
||||
function getColorApplier(
|
||||
color = "",
|
||||
reset = false,
|
||||
toForeground = true,
|
||||
toBackground = false
|
||||
) {
|
||||
//
|
||||
let result = "";
|
||||
|
||||
//
|
||||
// Detect and Validate Foreground Color and Apply it ...
|
||||
let eFColor = AVAILABLE_FOREGROUND_COLORS[color];
|
||||
if (
|
||||
!!toForeground
|
||||
&& XValueTools.isValidArg(eFColor)
|
||||
) {
|
||||
result = `${eFColor}`;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect and Validate Background Color and Apply it ...
|
||||
let eBColor = AVAILABLE_BACKGROUND_COLORS[color];
|
||||
if (
|
||||
!!toBackground
|
||||
&& XValueTools.isValidArg(eBColor)
|
||||
) {
|
||||
result = `${eBColor}`;
|
||||
}
|
||||
|
||||
//
|
||||
if (
|
||||
!!reset &&
|
||||
result.length > 0
|
||||
) {
|
||||
result = `${result}${AVAILABLE_STYLES.Reset}`;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* colorified specific content ...
|
||||
*
|
||||
* @param {string} content specified content for styling ...
|
||||
* @param {string} color specific color name for using to styling ...
|
||||
* @param {boolean} toForeground apply specified color as foreground ...
|
||||
* @param {boolean} toBackground apply specified color as background ...
|
||||
* @returns {string}
|
||||
*/
|
||||
function colorifyContent(
|
||||
content = "",
|
||||
color = "",
|
||||
toForeground = true,
|
||||
toBackground = false
|
||||
) {
|
||||
//
|
||||
let result = content;
|
||||
|
||||
//
|
||||
if (!XValueTools.isValidArg(content)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Finde Colors ...
|
||||
|
||||
//
|
||||
// Detect and Validate Foreground Color and Apply it ...
|
||||
let eFColor = AVAILABLE_FOREGROUND_COLORS[color];
|
||||
if (
|
||||
!!toForeground
|
||||
&& XValueTools.isValidArg(eFColor)
|
||||
) {
|
||||
result = `${eFColor}${result}`;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect and Validate Background Color and Apply it ...
|
||||
let eBColor = AVAILABLE_BACKGROUND_COLORS[color];
|
||||
if (
|
||||
!!toBackground
|
||||
&& XValueTools.isValidArg(eBColor)
|
||||
) {
|
||||
result = `${eBColor}${result}`;
|
||||
}
|
||||
|
||||
//
|
||||
if (
|
||||
result.length > 0
|
||||
&& (
|
||||
XValueTools.isValidArg(eFColor) ||
|
||||
XValueTools.isValidArg(eBColor)
|
||||
)
|
||||
) {
|
||||
result = `${result}${AVAILABLE_STYLES.Reset}`;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* apply style on specific content ...
|
||||
*
|
||||
* @param {string} content specified content for styling ...
|
||||
* @param {string} style soecufic style name to use ...
|
||||
* @returns {string}
|
||||
*/
|
||||
function stylifiyContent(
|
||||
content = "",
|
||||
style = "",
|
||||
) {
|
||||
//
|
||||
let result = content;
|
||||
|
||||
//
|
||||
if (!XValueTools.isValidArg(content)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect and Validate Style and Apply it ...
|
||||
let eStyle = AVAILABLE_STYLES[style];
|
||||
if (XValueTools.isValidArg(eStyle)) {
|
||||
result = `${eStyle}${result}`;
|
||||
}
|
||||
|
||||
//
|
||||
if (
|
||||
result.length > 0
|
||||
&& XValueTools.isValidArg(eStyle)
|
||||
) {
|
||||
result = `${result}${AVAILABLE_STYLES.Reset}`;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Module Exports ...
|
||||
module.exports = {
|
||||
//
|
||||
STYLE_NAMES,
|
||||
COLOR_NAMES,
|
||||
//
|
||||
apply,
|
||||
applyStyle,
|
||||
getApplier,
|
||||
getColorApplier,
|
||||
getStyleApplier,
|
||||
colorifyContent,
|
||||
stylifiyContent,
|
||||
applyForegroundColor,
|
||||
applyBackgroundColor,
|
||||
}
|
||||
//#endregion
|
||||
@@ -0,0 +1,887 @@
|
||||
/**
|
||||
* XFile Tools Module ...
|
||||
* a module for handle all file/folder manipulating task in node js ...
|
||||
*
|
||||
* Maintainer
|
||||
*
|
||||
* Hadi Khazaee Asl <https://saherelm.ir> (hadi_khazaee_asl@yahoo.com)
|
||||
*/
|
||||
|
||||
//
|
||||
//#region Module Imports ...
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const Path = require('path');
|
||||
const http = require('http');
|
||||
const https = require('https');
|
||||
const XValueTools = require('./x-value.tools');
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Constants ...
|
||||
/**
|
||||
* current os path separators ...
|
||||
*/
|
||||
const PathSeparator = Path.sep;
|
||||
|
||||
/**
|
||||
* current directory ...
|
||||
*/
|
||||
const CurrentDir = __dirname;
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Actions ...
|
||||
//
|
||||
//#region Global ...
|
||||
/**
|
||||
* retrieve a path status ...
|
||||
*
|
||||
* @param {string} path a path value to check ...
|
||||
* @returns an stat object ...
|
||||
*/
|
||||
function getStatus(path = '') {
|
||||
//
|
||||
if (!XValueTools.isValidArg(path)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
//
|
||||
return fs.statSync(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve user's Home path ...
|
||||
*
|
||||
* @returns {string} a path ...
|
||||
*/
|
||||
function getHomePath() {
|
||||
return os.homedir();
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Path ...
|
||||
/**
|
||||
* retrieve the base name of specific address path ...
|
||||
*
|
||||
* @param {string} path address of file or folder ...
|
||||
* @returns string ...
|
||||
*/
|
||||
function basename(path = '') {
|
||||
//
|
||||
if (!XValueTools.isValidArg(path)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
//
|
||||
const result = Path.basename(path);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* join several path segments together ...
|
||||
*
|
||||
* @param {...string} path path params ...
|
||||
* @returns a joined paths ...
|
||||
*/
|
||||
function joinPath(...path) {
|
||||
return Path.join(...path);
|
||||
}
|
||||
|
||||
/**
|
||||
* resolve a relative path to absolute ...
|
||||
*
|
||||
* @param {string[]} path a path value to check ...
|
||||
* @returns {string}
|
||||
*/
|
||||
function resolvePath(...path) {
|
||||
return Path.resolve(...path);
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region File ...
|
||||
/**
|
||||
* determines a path destination is a file or not ...
|
||||
*
|
||||
* @param {string} path a path value to check ...
|
||||
* @returns a boolean value ...
|
||||
*/
|
||||
function isFileExists(path = '') {
|
||||
//
|
||||
if (!XValueTools.isValidArg(path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
try {
|
||||
const stat = getStatus(path);
|
||||
if (!stat) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
return stat.isFile();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* remove a file ...
|
||||
*
|
||||
* @param {string} path a file path ...
|
||||
* @returns {Promise<boolean>} action done or not ...
|
||||
*/
|
||||
function removeFile(path = '') {
|
||||
return new Promise((resolve) => {
|
||||
//
|
||||
if (!isFileExists(path)) {
|
||||
resolve(false);
|
||||
}
|
||||
|
||||
//
|
||||
fs.unlink(path, (err) => {
|
||||
//
|
||||
if (err) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* copy a file to destination path ...
|
||||
*
|
||||
* @param {string} source source file path ...
|
||||
* @param {string} dest dest folder path ...
|
||||
* @returns {Promise<boolean>} action done or not ...
|
||||
*/
|
||||
function copyFile(
|
||||
source = '',
|
||||
dest = ''
|
||||
) {
|
||||
return new Promise((resolve) => {
|
||||
//
|
||||
if (
|
||||
!isFileExists(source) ||
|
||||
!isDirectoryExists(dest)
|
||||
) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
const destFilePath = Path.join(dest, Path.basename(source));
|
||||
fs.copyFile(source, destFilePath, (err) => {
|
||||
//
|
||||
if (err) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* reading specified file content ...
|
||||
*
|
||||
* @param {string} path a file path ...
|
||||
* @returns {Promise<string>} file content ...
|
||||
*/
|
||||
function readFile(path = '') {
|
||||
return new Promise((resolve) => {
|
||||
//
|
||||
if (!isFileExists(path)) {
|
||||
resolve('');
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
fs.readFile(path, 'utf8', (err, content) => {
|
||||
//
|
||||
if (err) {
|
||||
resolve(undefined);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
resolve(content);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* write content to a file ...
|
||||
*
|
||||
* @param {string} path a file path ...
|
||||
* @param {string} content the content which going to write to the file ...
|
||||
* @param {bool} overwrite determines file overwrite if exists ...
|
||||
* @returns {Promise<boolean>} action done or not ...
|
||||
*/
|
||||
function writeFile(
|
||||
path = '',
|
||||
content = '',
|
||||
overwrite = true
|
||||
) {
|
||||
return new Promise((resolve) => {
|
||||
//
|
||||
if (isFileExists(path) && !overwrite) {
|
||||
//
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Normalize Content ...
|
||||
content = XValueTools.isValidArg(content) ?
|
||||
content :
|
||||
'';
|
||||
|
||||
//
|
||||
fs.writeFile(path, content, (err) => {
|
||||
//
|
||||
if (err) {
|
||||
//
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* create a file ...
|
||||
*
|
||||
* @param {string} path file path ...
|
||||
* @param {string} fileName file name ...
|
||||
* @returns {Promise<boolean>} action done or not ...
|
||||
*/
|
||||
function createFile(
|
||||
path = '',
|
||||
fileName = ''
|
||||
) {
|
||||
return new Promise((resolve) => {
|
||||
//
|
||||
const filePath = Path.join(path, fileName);
|
||||
if (
|
||||
isFileExists(filePath) ||
|
||||
!XValueTools.isValidArg(path) ||
|
||||
!XValueTools.isValidArg(fileName)
|
||||
) {
|
||||
//
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
fs.writeFile(filePath, '', (err) => {
|
||||
//
|
||||
if (err) {
|
||||
//
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* remove a file name extension ...
|
||||
*
|
||||
* @param {string} name
|
||||
* @returns {string} name without extension ...
|
||||
*/
|
||||
function removeFileExtension(name = '') {
|
||||
return name.substring(0, name.lastIndexOf('.')) || name;
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve a file extension ...
|
||||
*
|
||||
* @param {string} path a path which locate a file ...
|
||||
* @returns {string}
|
||||
*/
|
||||
function getFileExtension(path = '') {
|
||||
//
|
||||
let result = "";
|
||||
|
||||
//
|
||||
// Validate Arg ...
|
||||
if (
|
||||
!XValueTools.isValidArg(path)
|
||||
|| !isFileExists(path)
|
||||
) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve just file name ...
|
||||
const fileName = basename(path);
|
||||
result = fileName.replace(
|
||||
removeFileExtension(fileName),
|
||||
""
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve all files list recursively from specific path ...
|
||||
*
|
||||
* @param {string} path a source folder path ...
|
||||
* @param {string[]} extensions which file extensions need to be listed, live empty for all files ...
|
||||
* @returns {Promise<string[]>}
|
||||
*/
|
||||
async function getRecursiveFilesList(
|
||||
path = "",
|
||||
extensions = []
|
||||
) {
|
||||
//
|
||||
let result = [];
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
!XValueTools.isValidArg(path)
|
||||
|| !isDirectoryExists(path)
|
||||
) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
const contents = await getDirectoryContents(path);
|
||||
for (const item of contents) {
|
||||
//
|
||||
const itemPath = joinPath(
|
||||
path,
|
||||
item
|
||||
);
|
||||
|
||||
//
|
||||
const isItemFile = isFileExists(itemPath);
|
||||
if (isItemFile) {
|
||||
//
|
||||
const itemFileExtension = getFileExtension(itemPath);
|
||||
const isFileInSupportedExtensions =
|
||||
extensions === undefined || extensions.length === 0
|
||||
? true
|
||||
: extensions.includes(itemFileExtension)
|
||||
;
|
||||
if (isFileInSupportedExtensions) {
|
||||
result.push(itemPath);
|
||||
}
|
||||
} else if (isDirectoryExists(itemPath)) {
|
||||
//
|
||||
const itemPathFiles = await getRecursiveFilesList(itemPath, extensions);
|
||||
result.push(...itemPathFiles);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Specific files from a folder and it's content ...
|
||||
*
|
||||
* @param {string} path Folder Path ...
|
||||
* @returns
|
||||
*/
|
||||
async function extractFiles(path = "", ext = [], excludeWorkspaceFolders = []) {
|
||||
//
|
||||
const result = [];
|
||||
|
||||
//
|
||||
if (!ext || ext.length == 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
const pathContent = await getDirectoryContents(path);
|
||||
if (!pathContent || pathContent.length == 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop through Content ...
|
||||
for (const c of pathContent) {
|
||||
//
|
||||
// Prepare full path ...
|
||||
const cPath = joinPath(path, c);
|
||||
|
||||
//
|
||||
// check content path is file or not ...
|
||||
const isCFile = isFileExists(cPath);
|
||||
const isCDirectory = isDirectoryExists(cPath);
|
||||
if (isCFile) {
|
||||
//
|
||||
// Check it is MQL file or not ...
|
||||
const cExt = getFileExtension(cPath);
|
||||
if (ext.includes(cExt)) {
|
||||
result.push(cPath);
|
||||
}
|
||||
} else if (isCDirectory) {
|
||||
//
|
||||
const destFolderName = basename(cPath);
|
||||
const isExcluded = excludeWorkspaceFolders.includes(destFolderName);
|
||||
if (isExcluded) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
const cFiles = await extractFiles(cPath, ext);
|
||||
if (cFiles && cFiles.length > 0) {
|
||||
result.push(...cFiles);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Directory ...
|
||||
/**
|
||||
* create a directory ...
|
||||
*
|
||||
* @param {string} path destination path including dir name ...
|
||||
* @param {boolean} recursive create directories recursively ...
|
||||
* @returns action done or not ...
|
||||
*/
|
||||
function createDirectory(
|
||||
path = '',
|
||||
recursive = true
|
||||
) {
|
||||
//
|
||||
let result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
isDirectoryExists(path) ||
|
||||
!XValueTools.isValidArg(path)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
try {
|
||||
//
|
||||
fs.mkdirSync(path, { recursive: recursive });
|
||||
result = true;
|
||||
return result;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* remove a directory ...
|
||||
*
|
||||
* @param {string} path destination path including dir name ...
|
||||
* @param {boolean} recursive removes directories recursively ...
|
||||
* @returns {Promise<boolean>} action done or not ...
|
||||
*/
|
||||
function removeDirectory(
|
||||
path = '',
|
||||
recursive = false
|
||||
) {
|
||||
return new Promise((resolve) => {
|
||||
//
|
||||
if (!isDirectoryExists(path)) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
fs.rm(path, {
|
||||
recursive
|
||||
}, (err) => {
|
||||
//
|
||||
if (err) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* determines a path destination is a directory or not ...
|
||||
*
|
||||
* @param {string} path a folder path ...
|
||||
* @returns represent destnation path is Directory or not ...
|
||||
*/
|
||||
function isDirectoryExists(path = '') {
|
||||
//
|
||||
if (!XValueTools.isValidArg(path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
try {
|
||||
//
|
||||
const isExists = fs.existsSync(path);
|
||||
if (!isExists) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
const stat = getStatus(path);
|
||||
if (!stat) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
const result = stat.isDirectory();
|
||||
return result;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve a directory content ...
|
||||
*
|
||||
* @param {string} path a folder path ...
|
||||
* @returns {Promise<string[]>} a collection of folder files ...
|
||||
*/
|
||||
function getDirectoryContents(path = '') {
|
||||
return new Promise((resolve) => {
|
||||
//
|
||||
if (!isDirectoryExists(path)) {
|
||||
resolve([]);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
fs.readdir(path, (err, content) => {
|
||||
//
|
||||
if (err) {
|
||||
resolve([]);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
resolve(content);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve a directory files ...
|
||||
*
|
||||
* @param {string} path a folder path ...
|
||||
* @returns {Promise<string[]>} a collection of folder files ...
|
||||
*/
|
||||
function getDirectoryFiles(
|
||||
path = '',
|
||||
containsHiddenFiles = false
|
||||
) {
|
||||
return new Promise((resolve) => {
|
||||
//
|
||||
if (!isDirectoryExists(path)) {
|
||||
resolve([]);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
fs.readdir(path, (err, content) => {
|
||||
//
|
||||
if (err) {
|
||||
resolve([]);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
if (!containsHiddenFiles) {
|
||||
content = content.filter(c => !c.startsWith('.'));
|
||||
}
|
||||
|
||||
//
|
||||
const result = [];
|
||||
content
|
||||
.forEach(c => {
|
||||
//
|
||||
const cPath = Path.join(path, c);
|
||||
if (isFileExists(cPath)) {
|
||||
result.push(c);
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve a directory folders ...
|
||||
*
|
||||
* @param {string} path a folder path ...
|
||||
* @returns {Promise<string[]>} a collection of folder names ...
|
||||
*/
|
||||
function getDirectoryFolders(path = '') {
|
||||
return new Promise((resolve) => {
|
||||
//
|
||||
if (!isDirectoryExists(path)) {
|
||||
resolve([]);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
fs.readdir(path, (err, content) => {
|
||||
//
|
||||
if (err) {
|
||||
resolve([]);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
const result = [];
|
||||
content.forEach(c => {
|
||||
//
|
||||
const cPath = Path.join(path, c);
|
||||
if (isDirectoryExists(cPath)) {
|
||||
result.push(c);
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* copy a folder with all of it's content to dest ...
|
||||
*
|
||||
* @param {string} source source folder path ...
|
||||
* @param {string} dest dest folder path ...
|
||||
* @returns {Promise<boolean>} action done or not ...
|
||||
*/
|
||||
async function copyFolder(
|
||||
source = '',
|
||||
dest = ''
|
||||
) {
|
||||
//
|
||||
if (
|
||||
!isDirectoryExists(source) ||
|
||||
!XValueTools.isValidArg(dest) ||
|
||||
!XValueTools.isValidArg(source)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
const folderName = Path.basename(source);
|
||||
const destPath = Path.join(dest, folderName);
|
||||
|
||||
//
|
||||
// Create Dest Path folder if not exists ...
|
||||
if (!isDirectoryExists(destPath)) {
|
||||
//
|
||||
let result = createDirectory(destPath, true);
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Files ...
|
||||
const files = await getDirectoryFiles(source);
|
||||
if (files && files.constructor === Array && files.length > 0) {
|
||||
//
|
||||
const filesPromises = files.map(file => copyFile(Path.join(source, file), destPath));
|
||||
const filesResult = (await Promise.all(filesPromises)).every(r => !!r);
|
||||
if (!filesResult) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Folders ...
|
||||
const folders = await getDirectoryFolders(source);
|
||||
if (folders && folders.constructor === Array && folders.length > 0) {
|
||||
//
|
||||
const folderPromises = folders.map(folder => copyFolder(Path.join(source, folder), destPath));
|
||||
const filesResult = (await Promise.all(folderPromises)).every(r => !!r);
|
||||
if (!filesResult) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return true;
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Downloader ...
|
||||
/**
|
||||
* download a file from specific url and store it ...
|
||||
*
|
||||
* @param {string} filepath the file name and path which required to put download file on it ...
|
||||
* @param {string} url the web url for downloading ...
|
||||
*/
|
||||
function download(filepath, url) {
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
!XValueTools.isValidArg(url)
|
||||
|| !XValueTools.isValidURL(url)
|
||||
|| !XValueTools.isValidArg(filepath)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
var file = fs.createWriteStream(filepath);
|
||||
|
||||
//
|
||||
if (url.startsWith('https:')) {
|
||||
https.get(url, function (response) {
|
||||
response.pipe(file);
|
||||
});
|
||||
} else if (url.startsWith('http:')) {
|
||||
http.get(url, function (response) {
|
||||
response.pipe(file);
|
||||
});
|
||||
}
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region JSON ...
|
||||
/**
|
||||
* read and parse a JSON content from a file ...
|
||||
*
|
||||
* @param {string} path source file path ...
|
||||
* @returns {any}
|
||||
*/
|
||||
function readJSON(path = "") {
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!isFileExists(path)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
//
|
||||
let result = undefined;
|
||||
try {
|
||||
result = require(path);
|
||||
} catch {
|
||||
result = undefined;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* write a JSON Object content into a file ...
|
||||
*
|
||||
* @param {string} path dest file path ...
|
||||
* @param {any} content an object which required to write to file ...
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
async function writeJSON(
|
||||
path = "",
|
||||
content = undefined
|
||||
) {
|
||||
//
|
||||
let result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!XValueTools.isValidArg(path)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Normallize Content ...
|
||||
if (content === undefined) {
|
||||
content = {};
|
||||
}
|
||||
|
||||
//
|
||||
const contentString = XValueTools.beautifyJSON(content);
|
||||
|
||||
//
|
||||
result = await writeFile(
|
||||
path,
|
||||
contentString,
|
||||
true
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//#endregion
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Module Exports ...
|
||||
module.exports = {
|
||||
//
|
||||
CurrentDir,
|
||||
PathSeparator,
|
||||
|
||||
//
|
||||
getStatus,
|
||||
getHomePath,
|
||||
|
||||
//
|
||||
basename,
|
||||
joinPath,
|
||||
resolvePath,
|
||||
|
||||
//
|
||||
download,
|
||||
|
||||
//
|
||||
readJSON,
|
||||
writeJSON,
|
||||
|
||||
//
|
||||
copyFile,
|
||||
readFile,
|
||||
writeFile,
|
||||
createFile,
|
||||
removeFile,
|
||||
isFileExists,
|
||||
getFileExtension,
|
||||
removeFileExtension,
|
||||
getRecursiveFilesList,
|
||||
extractFiles,
|
||||
|
||||
//
|
||||
copyFolder,
|
||||
createDirectory,
|
||||
removeDirectory,
|
||||
isDirectoryExists,
|
||||
getDirectoryFiles,
|
||||
getDirectoryFolders,
|
||||
getDirectoryContents,
|
||||
};
|
||||
//#endregion
|
||||
@@ -0,0 +1,219 @@
|
||||
/**
|
||||
* XShell Tools Module ...
|
||||
* a module for handling shell actions and retrieve OS Info in node js ...
|
||||
*
|
||||
* Maintainer
|
||||
*
|
||||
* Hadi Khazaee Asl <https://saherelm.ir> (hadi_khazaee_asl@yahoo.com)
|
||||
*/
|
||||
|
||||
//
|
||||
//#region Imports ...
|
||||
const os = require('os');
|
||||
const process = require('process');
|
||||
const { exec } = require("child_process");
|
||||
const XFileTools = require('./x-file.tools');
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Constants ...
|
||||
//
|
||||
const OS = {
|
||||
Aix: 'aix',
|
||||
Darwin: 'darwin',
|
||||
FreeBSD: 'freebsd',
|
||||
Linux: 'linux',
|
||||
OpenBSD: 'openbsd',
|
||||
SnOS: 'sunos',
|
||||
Windows: 'win32'
|
||||
};
|
||||
|
||||
//
|
||||
const isWindows = process.platform === OS.Windows;
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Actions ...
|
||||
//
|
||||
//#region Pure shell commands ...
|
||||
/**
|
||||
* execute a command using NodeJS on shell ...
|
||||
*
|
||||
* @param {string} cmd command to execute ...
|
||||
* @param {string} cwd working directory ...
|
||||
*
|
||||
* @returns Promise<any, errr> instance ...
|
||||
*/
|
||||
function execute(cmd, cwd) {
|
||||
return new Promise((resolve, reject) => {
|
||||
//
|
||||
if (!cmd || cmd.toString().length === 0 || (cwd && !XFileTools.isDirectoryExists(cwd))) {
|
||||
reject('invalid args ...');
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
exec(cmd, { cwd }, (err, result, stdError) => {
|
||||
//
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
if (stdError) {
|
||||
//
|
||||
// reject(stdError);
|
||||
// return;
|
||||
}
|
||||
|
||||
//
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* determines a command exists on host or not ...
|
||||
*
|
||||
* @param {string} name specific command name ...
|
||||
*
|
||||
* @returns boolean Promise ...
|
||||
*/
|
||||
function checkCommandExists(name) {
|
||||
return new Promise(resolve => {
|
||||
//
|
||||
if (!name) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
const cmd = isWindows ? `${name} >nul 2>&1` : `type ${name} >/dev/null 2>&1`;
|
||||
execute(cmd).then(result => {
|
||||
resolve(true);
|
||||
})
|
||||
.catch(err => {
|
||||
resolve(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region required commands state ...
|
||||
/**
|
||||
* check al required commands exists or not ...
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
async function isRequiredCommandsExists() {
|
||||
//
|
||||
let result = false;
|
||||
|
||||
//
|
||||
// const isTarExists = await isTarCommandExists();
|
||||
// const isCatExists = await isCatCommandExists();
|
||||
// const isGrepExists = await isGrepCommandExists();
|
||||
// const isSedExists = await isSedCommandExists();
|
||||
const isNpmExists = await isNpmCommandExists();
|
||||
const isNgExists = await isNgCommandExists();
|
||||
const isIonicExists = await isIonicCommandExists();
|
||||
const isCordovaExists = await isCordovaCommandExists();
|
||||
|
||||
//
|
||||
result = isNpmExists
|
||||
&& isNgExists
|
||||
&& isIonicExists
|
||||
&& isCordovaExists
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve required commands state object ...
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
async function getRequiredCommandsStates() {
|
||||
//
|
||||
const result = {};
|
||||
|
||||
//
|
||||
// const isTarExists = await isTarCommandExists();
|
||||
// const isCatExists = await isCatCommandExists();
|
||||
// const isGrepExists = await isGrepCommandExists();
|
||||
// const isSedExists = await isSedCommandExists();
|
||||
const isNpmExists = await isNpmCommandExists();
|
||||
const isNgExists = await isNgCommandExists();
|
||||
const isIonicExists = await isIonicCommandExists();
|
||||
const isCordovaExists = await isCordovaCommandExists();
|
||||
|
||||
//
|
||||
result['npm'] = isNpmExists;
|
||||
result['ng'] = isNgExists;
|
||||
result['ionic'] = isIonicExists;
|
||||
result['cordova'] = isCordovaExists;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Commonly used Command Checkers ...
|
||||
/**
|
||||
* determines npm command exists or not ...
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
function isNpmCommandExists() {
|
||||
return checkCommandExists('npm');
|
||||
}
|
||||
|
||||
/**
|
||||
* determines ng command exists or not ...
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
function isNgCommandExists() {
|
||||
return checkCommandExists('ng');
|
||||
}
|
||||
|
||||
/**
|
||||
* determines ionic command exists or not ...
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
function isIonicCommandExists() {
|
||||
return checkCommandExists('ionic');
|
||||
}
|
||||
|
||||
/**
|
||||
* determines cordova command exists or not ...
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
function isCordovaCommandExists() {
|
||||
return checkCommandExists('cordova');
|
||||
}
|
||||
//#endregion
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Module Exports ...
|
||||
module.exports = {
|
||||
//
|
||||
execute,
|
||||
checkCommandExists,
|
||||
isRequiredCommandsExists,
|
||||
getRequiredCommandsStates,
|
||||
|
||||
//
|
||||
isNgCommandExists,
|
||||
isIonicCommandExists,
|
||||
isCordovaCommandExists,
|
||||
}
|
||||
//#endregion
|
||||
@@ -0,0 +1,268 @@
|
||||
/**
|
||||
* DataType Tools Module ...
|
||||
* a module for manipulate and detect supported data types in node js ...
|
||||
*
|
||||
* Maintainer
|
||||
*
|
||||
* Hadi Khazaee Asl <https://saherelm.ir> (hadi_khazaee_asl@yahoo.com)
|
||||
*/
|
||||
|
||||
//
|
||||
//#region Constants ...
|
||||
/**
|
||||
* all supported data types ...
|
||||
*/
|
||||
const DataTypes = {
|
||||
Null: 'null',
|
||||
Date: 'date',
|
||||
Array: 'array',
|
||||
Object: 'object',
|
||||
String: 'string',
|
||||
Number: 'number',
|
||||
Unknown: 'unknown',
|
||||
Boolean: 'boolean',
|
||||
Function: 'function',
|
||||
Undefined: 'undefined',
|
||||
};
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Actions ...
|
||||
/**
|
||||
* detect type of a content ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function getType(value) {
|
||||
//
|
||||
const type = typeof value;
|
||||
|
||||
//
|
||||
let result = DataTypes.Unknown;
|
||||
let dateIdentifier = '[object Date]';
|
||||
let constructor = value && value.constructor ?
|
||||
value.constructor.toString() :
|
||||
'';
|
||||
|
||||
//
|
||||
switch (type) {
|
||||
//
|
||||
case 'undefined':
|
||||
result = DataTypes.Undefined;
|
||||
break;
|
||||
|
||||
//
|
||||
case 'boolean':
|
||||
result = DataTypes.Boolean;
|
||||
break;
|
||||
|
||||
//
|
||||
case 'string':
|
||||
result = DataTypes.String;
|
||||
break;
|
||||
|
||||
//
|
||||
case 'number':
|
||||
result = DataTypes.Number;
|
||||
break;
|
||||
|
||||
//
|
||||
case 'function':
|
||||
result = DataTypes.Function;
|
||||
break;
|
||||
|
||||
//
|
||||
case 'object':
|
||||
//
|
||||
// Null ...
|
||||
if (value === null) {
|
||||
result = DataTypes.Null;
|
||||
} else
|
||||
//
|
||||
// Array ...
|
||||
if (Array.isArray(value)) {
|
||||
result = DataTypes.Array;
|
||||
} else
|
||||
//
|
||||
// Data ...
|
||||
if (
|
||||
value instanceof Date ||
|
||||
isFunction(value.getMonth) ||
|
||||
constructor.includes(dateIdentifier) ||
|
||||
Object.prototype.toString.call(value) === dateIdentifier
|
||||
) {
|
||||
result = DataTypes.Date;
|
||||
} else
|
||||
//
|
||||
// Object ...
|
||||
{
|
||||
result = DataTypes.Object;
|
||||
}
|
||||
break;
|
||||
|
||||
//
|
||||
default:
|
||||
result = DataTypes.Unknown;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve an object constructor ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function getConstructor(value) {
|
||||
//
|
||||
const result = value && value.constructor ?
|
||||
value.constructor.toString() :
|
||||
'';
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve an object prototype ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function getPrototype(value) {
|
||||
//
|
||||
const result = value ?
|
||||
Object.prototype.toString.call(value) :
|
||||
'';
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* check an object is null or not ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function isNull(value) {
|
||||
return getType(value) === DataTypes.Null;
|
||||
}
|
||||
|
||||
/**
|
||||
* check an object is undefined or not ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function isUndefined(value) {
|
||||
return getType(value) === DataTypes.Undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* check an object is null or undefined or not ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function isNullOrUndefined(value) {
|
||||
return isNull(value) || isUndefined(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* check an object is a date or not ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function isDate(value) {
|
||||
return getType(value) === DataTypes.Date;
|
||||
}
|
||||
|
||||
/**
|
||||
* check an object is number or not ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function isNumber(value) {
|
||||
return getType(value) === DataTypes.Number;
|
||||
}
|
||||
|
||||
/**
|
||||
* check an object is string or not ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function isString(value) {
|
||||
return getType(value) === DataTypes.String;
|
||||
}
|
||||
|
||||
/**
|
||||
* check an object is boolean or not ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function isBoolean(value) {
|
||||
return getType(value) === DataTypes.Boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* check an object is an Array or not ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function isArray(value) {
|
||||
return getType(value) === DataTypes.Array;
|
||||
}
|
||||
|
||||
/**
|
||||
* check an object is and Object or not ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function isObject(value) {
|
||||
return getType(value) === DataTypes.Object;
|
||||
}
|
||||
|
||||
/**
|
||||
* check an object is a Function or not ...
|
||||
*
|
||||
* @param {any} value the content which going to check ...
|
||||
* @returns
|
||||
*/
|
||||
function isFunction(value) {
|
||||
return getType(value) === DataTypes.Function;
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//
|
||||
//#region Module Exports ...
|
||||
module.exports = {
|
||||
//
|
||||
DataTypes,
|
||||
|
||||
//
|
||||
getType,
|
||||
getConstructor,
|
||||
getPrototype,
|
||||
isNull,
|
||||
isUndefined,
|
||||
isNullOrUndefined,
|
||||
isDate,
|
||||
isNumber,
|
||||
isString,
|
||||
isBoolean,
|
||||
isArray,
|
||||
isObject,
|
||||
isFunction,
|
||||
}
|
||||
//#endregion
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,221 @@
|
||||
|
||||
//
|
||||
// Detect Signals Based On XPV Indicator Golden Zones ...
|
||||
//
|
||||
bool HasTMPConditions(
|
||||
ENUM_X_CYCLES cycle,
|
||||
XBoxZone &box,
|
||||
ENUM_X_DIRECTION &dir,
|
||||
X121SMCStrategySignalProviderData &provider,
|
||||
int barIndex = 0 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
box.Clean();
|
||||
dir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
// Fil Selected Data ...
|
||||
XPOIState cState;
|
||||
X121Conditions cXConditions;
|
||||
XPOIStateEvents cStateEvents;
|
||||
XC121SMCCycleHelper *cHelper;
|
||||
X121SMCCycleConditions cConditions;
|
||||
result = provider.SelectCycle(
|
||||
cycle,
|
||||
cState,
|
||||
cStateEvents,
|
||||
cXConditions,
|
||||
cHelper,
|
||||
cConditions //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
cState.Clean();
|
||||
ZeroMemory(cHelper);
|
||||
cConditions.Clean();
|
||||
cXConditions.Clean();
|
||||
cStateEvents.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Normalize Args ...
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
int idx = -1;
|
||||
int count = 0;
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
int zIDX = barIndex;
|
||||
int cIDX = zIDX + 1;
|
||||
int pIDX = cIDX + 1;
|
||||
int ppIDX = pIDX + 1;
|
||||
|
||||
//
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
XOHCL cBar;
|
||||
XOHCL pBar;
|
||||
XOHCL pPBar;
|
||||
|
||||
//
|
||||
// Initial Bars ...
|
||||
result = zBar.Init(
|
||||
cState.symbol,
|
||||
cState.period,
|
||||
barIndex //
|
||||
);
|
||||
result =
|
||||
result &&
|
||||
zBar.GetPreviousBar(cBar);
|
||||
result =
|
||||
result &&
|
||||
cBar.GetPreviousBar(pBar);
|
||||
result =
|
||||
result &&
|
||||
pBar.GetPreviousBar(pPBar);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
cState.Clean();
|
||||
ZeroMemory(cHelper);
|
||||
cConditions.Clean();
|
||||
cXConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Checking Conditions ...
|
||||
|
||||
//
|
||||
// Summarize Conditions ...
|
||||
|
||||
//
|
||||
isBullish =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
isBearish =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Filling Requirements ...
|
||||
result =
|
||||
isBullish ||
|
||||
isBearish;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
dir =
|
||||
isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
box.dir = dir;
|
||||
box.from = pPBar.time;
|
||||
box.to = TimeCurrent();
|
||||
box.symbol = cBar.symbol;
|
||||
box.period = cBar.period;
|
||||
|
||||
//
|
||||
double points = GetPoints(box.symbol);
|
||||
|
||||
//
|
||||
// Usually is Preffered SL ...
|
||||
double pivot = 0;
|
||||
|
||||
//
|
||||
// Usually is Current Price or Entry Price ...
|
||||
double point = GetEntry(
|
||||
cBar.symbol,
|
||||
dir //
|
||||
);
|
||||
|
||||
//
|
||||
box.upper =
|
||||
isBullish
|
||||
? point
|
||||
: pivot;
|
||||
|
||||
//
|
||||
box.lower =
|
||||
isBullish
|
||||
? pivot
|
||||
: point;
|
||||
|
||||
//
|
||||
XCPOIDrawer *drawer = provider.visionCycleHelper.mPOIDrawer;
|
||||
bool drawBoxes = true;
|
||||
if (drawBoxes)
|
||||
{
|
||||
//
|
||||
if (box.IsValid()) {
|
||||
//
|
||||
XCBoxObject *iObj;
|
||||
bool isCreated = drawer.DrawBox(
|
||||
box,
|
||||
iObj //
|
||||
);
|
||||
|
||||
//
|
||||
if (isCreated) {
|
||||
//
|
||||
// TODO: ...
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check All Conditions ...
|
||||
result =
|
||||
box.IsValid() &&
|
||||
HasDirection(dir) &&
|
||||
(isBullish ||
|
||||
isBearish);
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
pPBar.Clean();
|
||||
cState.Clean();
|
||||
cConditions.Clean();
|
||||
cConditions.Clean();
|
||||
ZeroMemory(cHelper);
|
||||
cStateEvents.Clean();
|
||||
cXConditions.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,542 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XTest MQL5 Expert Advisor
|
||||
// -------------------------------------------------
|
||||
// Name: XEATemplate
|
||||
// Description: a Template For Exper Advisors
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////x
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XEATemplate"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "XEATemplate"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.xalert.class.mq5"
|
||||
#include "../Classes/x-saherelm.xtrade.class.mq5"
|
||||
#include "../Helpers/x-saherelm.xcc.helper.mq5"
|
||||
#include "../Helpers/x-saherelm.xct.helper.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Common ...
|
||||
input group "Common";
|
||||
input long eaMagicNumber = 78692110; // Magic Number
|
||||
input int eaSlippage = 10; // Slippgae
|
||||
input string eaLogSuffix = ""; // Log Suffix
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
// Here we Provider All Requirements for
|
||||
// Configuring Alert Provider ...
|
||||
input group "Alert";
|
||||
input bool eAEnableAlerts = true; // Enable Alerts
|
||||
input bool eALogAlerts = true; // Log Alerts
|
||||
input bool eAMailAlerts = false; // Mail Alerts
|
||||
input bool eAPushAlerts = false; // Push Alerts
|
||||
input bool eATerminalAlerts = false; // Terminal Alerts
|
||||
|
||||
//
|
||||
// Time Report ...
|
||||
input group "Reports";
|
||||
input bool eaReportNewMonths = false; // Report New Month
|
||||
input bool eaReportNewWeeks = false; // Report New Weeks
|
||||
input bool eaReportNewDays = false; // Report New Days
|
||||
input bool eaReportNewHours = false; // Report New Hours
|
||||
|
||||
//
|
||||
// Define Local Variables ...
|
||||
|
||||
//
|
||||
string eaLogTag; // EA Log Prefix ...
|
||||
XSCAlert *eaAlert; // Alert Provider for Expert Adviser ...
|
||||
XSCTrade *eaTrader; // Trader of Expert Adviser ...
|
||||
XTimeTracker eaTimeTracker; // Time Tracker for Providing Reports ...
|
||||
XSCXCTHelper *eaCHelper; // Bar Timer Indicator Helper class ...
|
||||
XSCXCCHelper *eaCCHelper; // Chart Styler Indicator Helper Class ...
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs and Required Parameters
|
||||
// for EA to Works fine ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Timer ...
|
||||
if (!InitTimer()) {
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize all Requirements ...
|
||||
if (!InitEA())
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize all GUI Objects and Classes ...
|
||||
if (!InitGUI())
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Alert Initialization ...
|
||||
string msg = "Initialized Successfully ...";
|
||||
eaAlert.Alert(msg);
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Destroy Timer ...
|
||||
DestroyTimer();
|
||||
|
||||
//
|
||||
// Destroy all GUI Requirements ...
|
||||
DestroyGUI();
|
||||
|
||||
//
|
||||
// Alert De Initialization Succeeded ...
|
||||
string msg = "De Initialized Successfully ...";
|
||||
eaAlert.Alert(msg);
|
||||
|
||||
//
|
||||
// Destroy all EA Requirements ...
|
||||
DestroyEA();
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
UpdateGUI();
|
||||
HandleReportTime();
|
||||
UpdatePositionsState();
|
||||
|
||||
//
|
||||
// TODO: Implemetn Tick Processors Algorithm ...
|
||||
}
|
||||
|
||||
//
|
||||
// Handle On Trade Event ...
|
||||
void OnTrade()
|
||||
{
|
||||
eaTrader.HandleOnTrade();
|
||||
}
|
||||
|
||||
//
|
||||
// On Timer ...
|
||||
void OnTimer()
|
||||
{
|
||||
//
|
||||
// TODO: Implement Time Based Functionalities ...
|
||||
}
|
||||
|
||||
//
|
||||
// Chart Event Handler ...
|
||||
void OnChartEvent(
|
||||
const int id,
|
||||
const long &lparam,
|
||||
const double &dparam,
|
||||
const string &sparam //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Handle OnClick Event ...
|
||||
if (id == CHARTEVENT_OBJECT_CLICK)
|
||||
{
|
||||
HandleOnClickEvent(sparam);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Event Handlers ...
|
||||
|
||||
/**
|
||||
* Handle StopLoss Triggered Positions ...
|
||||
*
|
||||
* @param deal: XDeal ...
|
||||
*/
|
||||
void OnStopLossTriggered(const XDeal &deal)
|
||||
{
|
||||
//
|
||||
HandleReportBalance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Take Profit Triggered Positions ...
|
||||
*
|
||||
* @param deal: XDeal ...
|
||||
*/
|
||||
void OnTakeProfitTriggered(const XDeal &deal)
|
||||
{
|
||||
//
|
||||
HandleReportBalance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Force Close a Position ...
|
||||
*
|
||||
* @param ticket: Position Ticket ...
|
||||
* @param position: XPosition ...
|
||||
* @param comment: Closing Comment ...
|
||||
*/
|
||||
void OnPositionForceClosed(
|
||||
const ulong ticket,
|
||||
const XPosition &position,
|
||||
const string comment //
|
||||
)
|
||||
{
|
||||
//
|
||||
HandleReportBalance();
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
/**
|
||||
* Validate all Inputs of Expert Adviser ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
string errMessage = "";
|
||||
|
||||
//
|
||||
bool isCommonValid = (
|
||||
//
|
||||
eaSlippage > 0 &&
|
||||
eaMagicNumber > 0
|
||||
//
|
||||
);
|
||||
if (!isCommonValid)
|
||||
{
|
||||
//
|
||||
errMessage += "common configurations error;" + "\n";
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
// Common ...
|
||||
isCommonValid &&
|
||||
//
|
||||
// Otere ...
|
||||
true
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
// Since here Logger not Initiallized, we Use Raw Print Command ...
|
||||
Print(ShortName + " Errors: \n", errMessage);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize Timer ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitTimer() {
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// TODO: Initialize Timer if necessary ...
|
||||
// result = EventSetTimer(1);
|
||||
// result = EventSetMillisecondTimer(100);
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Timer ...
|
||||
*/
|
||||
void DestroyTimer() {
|
||||
//
|
||||
// TODO: Use This ...
|
||||
// EventKillTimer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all Requirements for Working Fine ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitEA()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Locally Apply Changes on Prefix ...
|
||||
eaLogTag = ShortName + ">" + eaLogSuffix;
|
||||
|
||||
//
|
||||
// Bar Timer ...
|
||||
XCTInputs ctInputs;
|
||||
ctInputs.Default(); // Default Configurations ...
|
||||
eaCHelper = new XSCXCTHelper();
|
||||
result = eaCHelper.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
ctInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Bar Styles ...
|
||||
XCCInputs ccInputs;
|
||||
ccInputs.Default(); // Default Configurations ...
|
||||
eaCCHelper = new XSCXCCHelper();
|
||||
result = eaCCHelper.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
ccInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Create Instance of Alert Class and Configure it ...
|
||||
eaAlert = new XSCAlert();
|
||||
eaAlert.SetPrefix(eaLogTag);
|
||||
eaAlert.SetLogAlerts(eALogAlerts);
|
||||
eaAlert.SetMailAlerts(eAMailAlerts);
|
||||
eaAlert.SetPushAlerts(eAPushAlerts);
|
||||
eaAlert.SetEnableAlerts(eAEnableAlerts);
|
||||
eaAlert.SetTerminalAlerts(eATerminalAlerts);
|
||||
|
||||
//
|
||||
// Create Trader Instance and Configure it ...
|
||||
eaTrader = new XSCTrade(
|
||||
eaSlippage,
|
||||
eaMagicNumber //
|
||||
);
|
||||
eaTrader.AddOnStopLossEventHandler(OnStopLossTriggered);
|
||||
eaTrader.AddOnTakeProfitEventHandler(OnTakeProfitTriggered);
|
||||
eaTrader.AddOnForceClosePositionEventHandler(OnPositionForceClosed);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy all Initialized EA Requirements ...
|
||||
*/
|
||||
void DestroyEA()
|
||||
{
|
||||
//
|
||||
delete eaCHelper;
|
||||
delete eaCCHelper;
|
||||
|
||||
//
|
||||
delete eaAlert;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all GUI Requirements for EA ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitGUI()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// TODO: Fix This ...
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update GUI based on Each Ticks ...
|
||||
*/
|
||||
void UpdateGUI()
|
||||
{
|
||||
//
|
||||
// TODO: Implement this ...
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy all Initialized GUi Requirements ...
|
||||
*/
|
||||
void DestroyGUI()
|
||||
{
|
||||
//
|
||||
// TODO: Complete this ...
|
||||
}
|
||||
|
||||
//
|
||||
// Others ...
|
||||
|
||||
/**
|
||||
* Update Positions States ...
|
||||
*/
|
||||
void UpdatePositionsState()
|
||||
{
|
||||
//
|
||||
// TODO: Implement this ...
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle On Click Event for GUI Components ...
|
||||
*
|
||||
* @param name: Object Name ...
|
||||
*/
|
||||
void HandleOnClickEvent(string name)
|
||||
{
|
||||
//
|
||||
if (!IsValid(name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
bool isClicked = false;
|
||||
|
||||
//
|
||||
// TODO: Implement Chart Objects On Click ...
|
||||
|
||||
//
|
||||
if (isClicked)
|
||||
{
|
||||
UpdateGUI();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Report Account Balance ...
|
||||
*/
|
||||
void HandleReportBalance()
|
||||
{
|
||||
//
|
||||
if (!IsRunningOnTestMode())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
string msg = "Balance: " + ToString(eaTrader.mAccount.GetBalance());
|
||||
eaAlert.Log(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Time Reporting based on Inputs ...
|
||||
*/
|
||||
void HandleReportTime()
|
||||
{
|
||||
//
|
||||
// Monthly Report ....
|
||||
if (eaReportNewMonths &&
|
||||
eaTimeTracker.IsNewMonth())
|
||||
{
|
||||
//
|
||||
string msg = "New Month ...";
|
||||
|
||||
//
|
||||
eaAlert.Alert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Weekly Report ....
|
||||
if (eaReportNewWeeks &&
|
||||
eaTimeTracker.IsNewWeek())
|
||||
{
|
||||
//
|
||||
string msg = "New Week ...";
|
||||
|
||||
//
|
||||
eaAlert.Alert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Daily Report ....
|
||||
if (eaReportNewDays &&
|
||||
eaTimeTracker.IsNewDay())
|
||||
{
|
||||
//
|
||||
string msg = "New Day ...";
|
||||
|
||||
//
|
||||
eaAlert.Alert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Hourly Report ....
|
||||
if (eaReportNewHours &&
|
||||
eaTimeTracker.IsNewHour())
|
||||
{
|
||||
//
|
||||
string msg = "New Hour ...";
|
||||
|
||||
//
|
||||
eaAlert.Alert(msg);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,575 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XTest MQL5 Expert Advisor
|
||||
// -------------------------------------------------
|
||||
// Name: XPanelEA
|
||||
// Description: an Exper Advisor which used Panels
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////x
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XPanelEA"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "XPANELEA"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.x-app-dialog.class.mq5"
|
||||
#include "../Classes/x-saherelm.xalert.class.mq5"
|
||||
#include "../Classes/x-saherelm.xtrade.class.mq5"
|
||||
#include "../Helpers/x-saherelm.xcc.helper.mq5"
|
||||
#include "../Helpers/x-saherelm.xct.helper.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Common ...
|
||||
input group "Common";
|
||||
input long eaMagicNumber = 78692110; // Magic Number
|
||||
input int eaSlippage = 10; // Slippgae
|
||||
input string eaLogSuffix = ""; // Log Suffix
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
// Here we Provider All Requirements for
|
||||
// Configuring Alert Provider ...
|
||||
input group "Alert";
|
||||
input bool eAEnableAlerts = true; // Enable Alerts
|
||||
input bool eALogAlerts = true; // Log Alerts
|
||||
input bool eAMailAlerts = false; // Mail Alerts
|
||||
input bool eAPushAlerts = false; // Push Alerts
|
||||
input bool eATerminalAlerts = false; // Terminal Alerts
|
||||
|
||||
//
|
||||
// Time Report ...
|
||||
input group "Reports";
|
||||
input bool eaReportNewMonths = false; // Report New Month
|
||||
input bool eaReportNewWeeks = false; // Report New Weeks
|
||||
input bool eaReportNewDays = false; // Report New Days
|
||||
input bool eaReportNewHours = false; // Report New Hours
|
||||
|
||||
//
|
||||
// Define Local Variables ...
|
||||
|
||||
//
|
||||
string eaLogTag; // EA Log Prefix ...
|
||||
XSCAlert *eaAlert; // Alert Provider for Expert Adviser ...
|
||||
XSCTrade *eaTrader; // Trader of Expert Adviser ...
|
||||
XTimeTracker eaTimeTracker; // Time Tracker for Providing Reports ...
|
||||
XSCXCTHelper *eaCTHelper; // Bar Timer Indicator Helper class ...
|
||||
XSCXCCHelper *eaCCHelper; // Chart Styler Indicator Helper Class ...
|
||||
|
||||
//
|
||||
XCAppDialog eaMainWindow; // EA Main Dialog ...
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs and Required Parameters
|
||||
// for EA to Works fine ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Timer ...
|
||||
if (!InitTimer())
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize all Requirements ...
|
||||
if (!InitEA())
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize all GUI Objects and Classes ...
|
||||
if (!InitGUI())
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Alert Initialization ...
|
||||
string msg = "Initialized Successfully ...";
|
||||
eaAlert.Alert(msg);
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Destroy Timer ...
|
||||
DestroyTimer();
|
||||
|
||||
//
|
||||
// Destroy all GUI Requirements ...
|
||||
DestroyGUI();
|
||||
|
||||
//
|
||||
// Alert De Initialization Succeeded ...
|
||||
string msg = "De Initialized Successfully ...";
|
||||
eaAlert.Alert(msg);
|
||||
|
||||
//
|
||||
// Destroy all EA Requirements ...
|
||||
DestroyEA();
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
UpdateGUI();
|
||||
HandleReportTime();
|
||||
UpdatePositionsState();
|
||||
|
||||
//
|
||||
// TODO: Implemetn Tick Processors Algorithm ...
|
||||
}
|
||||
|
||||
//
|
||||
// Handle On Trade Event ...
|
||||
void OnTrade()
|
||||
{
|
||||
eaTrader.HandleOnTrade();
|
||||
}
|
||||
|
||||
//
|
||||
// On Timer ...
|
||||
void OnTimer()
|
||||
{
|
||||
//
|
||||
// TODO: Implement Time Based Functionalities ...
|
||||
}
|
||||
|
||||
//
|
||||
// Chart Event Handler ...
|
||||
void OnChartEvent(
|
||||
const int id,
|
||||
const long &lparam,
|
||||
const double &dparam,
|
||||
const string &sparam //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Apply Chart Event on Main Window ...
|
||||
eaMainWindow.ChartEvent(id, lparam, dparam, sparam);
|
||||
|
||||
//
|
||||
// Handle OnClick Event ...
|
||||
if (id == CHARTEVENT_OBJECT_CLICK)
|
||||
{
|
||||
HandleOnClickEvent(sparam);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Event Handlers ...
|
||||
|
||||
/**
|
||||
* Handle StopLoss Triggered Positions ...
|
||||
*
|
||||
* @param deal: XDeal ...
|
||||
*/
|
||||
void OnStopLossTriggered(const XDeal &deal)
|
||||
{
|
||||
//
|
||||
HandleReportBalance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Take Profit Triggered Positions ...
|
||||
*
|
||||
* @param deal: XDeal ...
|
||||
*/
|
||||
void OnTakeProfitTriggered(const XDeal &deal)
|
||||
{
|
||||
//
|
||||
HandleReportBalance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Force Close a Position ...
|
||||
*
|
||||
* @param ticket: Position Ticket ...
|
||||
* @param position: XPosition ...
|
||||
* @param comment: Closing Comment ...
|
||||
*/
|
||||
void OnPositionForceClosed(
|
||||
const ulong ticket,
|
||||
const XPosition &position,
|
||||
const string comment //
|
||||
)
|
||||
{
|
||||
//
|
||||
HandleReportBalance();
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
/**
|
||||
* Validate all Inputs of Expert Adviser ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
string errMessage = "";
|
||||
|
||||
//
|
||||
bool isCommonValid = (
|
||||
//
|
||||
eaSlippage > 0 &&
|
||||
eaMagicNumber > 0
|
||||
//
|
||||
);
|
||||
if (!isCommonValid)
|
||||
{
|
||||
//
|
||||
errMessage += "common configurations error;" + "\n";
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
// Common ...
|
||||
isCommonValid &&
|
||||
//
|
||||
// Otere ...
|
||||
true
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
// Since here Logger not Initiallized, we Use Raw Print Command ...
|
||||
Print(ShortName + " Errors: \n", errMessage);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize Timer ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitTimer()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// TODO: Initialize Timer if necessary ...
|
||||
// result = EventSetTimer(1);
|
||||
// result = EventSetMillisecondTimer(100);
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Timer ...
|
||||
*/
|
||||
void DestroyTimer()
|
||||
{
|
||||
//
|
||||
// TODO: Use This ...
|
||||
// EventKillTimer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all Requirements for Working Fine ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitEA()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Locally Apply Changes on Prefix ...
|
||||
eaLogTag = ShortName + ">" + eaLogSuffix;
|
||||
|
||||
//
|
||||
// Bar Timer ...
|
||||
XCTInputs ctInputs;
|
||||
ctInputs.Default(); // Default Configurations ...
|
||||
eaCTHelper = new XSCXCTHelper();
|
||||
result = eaCTHelper.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
ctInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Bar Styles ...
|
||||
XCCInputs ccInputs;
|
||||
ccInputs.Default(); // Default Configurations ...
|
||||
eaCCHelper = new XSCXCCHelper();
|
||||
result = eaCCHelper.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
ccInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Create Instance of Alert Class and Configure it ...
|
||||
eaAlert = new XSCAlert();
|
||||
eaAlert.SetPrefix(eaLogTag);
|
||||
eaAlert.SetLogAlerts(eALogAlerts);
|
||||
eaAlert.SetMailAlerts(eAMailAlerts);
|
||||
eaAlert.SetPushAlerts(eAPushAlerts);
|
||||
eaAlert.SetEnableAlerts(eAEnableAlerts);
|
||||
eaAlert.SetTerminalAlerts(eATerminalAlerts);
|
||||
|
||||
//
|
||||
// Create Trader Instance and Configure it ...
|
||||
eaTrader = new XSCTrade(
|
||||
eaSlippage,
|
||||
eaMagicNumber //
|
||||
);
|
||||
eaTrader.AddOnStopLossEventHandler(OnStopLossTriggered);
|
||||
eaTrader.AddOnTakeProfitEventHandler(OnTakeProfitTriggered);
|
||||
eaTrader.AddOnForceClosePositionEventHandler(OnPositionForceClosed);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy all Initialized EA Requirements ...
|
||||
*/
|
||||
void DestroyEA()
|
||||
{
|
||||
//
|
||||
delete eaCTHelper;
|
||||
delete eaCCHelper;
|
||||
|
||||
//
|
||||
delete eaAlert;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all GUI Requirements for EA ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitGUI()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Application Main Window ...
|
||||
result = eaMainWindow.Create(
|
||||
ChartID(),
|
||||
ShortName, // Dialog Name ...
|
||||
0, // SubWindow ...
|
||||
10, // X1 ...
|
||||
35, // Y1 ...
|
||||
300, // X2 ...
|
||||
200 // Y2 ...
|
||||
);
|
||||
|
||||
//
|
||||
// Configuring Dialog ...
|
||||
// eaMainWindow.MinimizeButton(false); // Hide Minimize Button ...
|
||||
// eaMainWindow.CloseButton(false); // Hide Close Button ...
|
||||
eaMainWindow.BackgroundColor(clrBlack);
|
||||
// result = true;
|
||||
|
||||
//
|
||||
// Try To Run Main Window ...
|
||||
if (result)
|
||||
{
|
||||
eaMainWindow.Run();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update GUI based on Each Ticks ...
|
||||
*/
|
||||
void UpdateGUI()
|
||||
{
|
||||
//
|
||||
// TODO: Implement this ...
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy all Initialized GUi Requirements ...
|
||||
*/
|
||||
void DestroyGUI()
|
||||
{
|
||||
//
|
||||
eaMainWindow.Destroy();
|
||||
}
|
||||
|
||||
//
|
||||
// Others ...
|
||||
|
||||
/**
|
||||
* Update Positions States ...
|
||||
*/
|
||||
void UpdatePositionsState()
|
||||
{
|
||||
//
|
||||
// TODO: Implement this ...
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle On Click Event for GUI Components ...
|
||||
*
|
||||
* @param name: Object Name ...
|
||||
*/
|
||||
void HandleOnClickEvent(string name)
|
||||
{
|
||||
//
|
||||
if (!IsValid(name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
bool isClicked = false;
|
||||
|
||||
//
|
||||
// TODO: Implement Chart Objects On Click ...
|
||||
|
||||
//
|
||||
if (isClicked)
|
||||
{
|
||||
UpdateGUI();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Report Account Balance ...
|
||||
*/
|
||||
void HandleReportBalance()
|
||||
{
|
||||
//
|
||||
if (!IsRunningOnTestMode())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
string msg = "Balance: " + ToString(eaTrader.mAccount.GetBalance());
|
||||
eaAlert.Log(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Time Reporting based on Inputs ...
|
||||
*/
|
||||
void HandleReportTime()
|
||||
{
|
||||
//
|
||||
// Monthly Report ....
|
||||
if (eaReportNewMonths &&
|
||||
eaTimeTracker.IsNewMonth())
|
||||
{
|
||||
//
|
||||
string msg = "New Month ...";
|
||||
|
||||
//
|
||||
eaAlert.Alert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Weekly Report ....
|
||||
if (eaReportNewWeeks &&
|
||||
eaTimeTracker.IsNewWeek())
|
||||
{
|
||||
//
|
||||
string msg = "New Week ...";
|
||||
|
||||
//
|
||||
eaAlert.Alert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Daily Report ....
|
||||
if (eaReportNewDays &&
|
||||
eaTimeTracker.IsNewDay())
|
||||
{
|
||||
//
|
||||
string msg = "New Day ...";
|
||||
|
||||
//
|
||||
eaAlert.Alert(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Hourly Report ....
|
||||
if (eaReportNewHours &&
|
||||
eaTimeTracker.IsNewHour())
|
||||
{
|
||||
//
|
||||
string msg = "New Hour ...";
|
||||
|
||||
//
|
||||
eaAlert.Alert(msg);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,187 @@
|
||||
|
||||
//
|
||||
// Senario 3:
|
||||
// ----------
|
||||
bool useSenario3 = false;
|
||||
bool isSenario3Happend = false;
|
||||
bool isSenario3Bullish = false;
|
||||
bool isSenario3Bearish = false;
|
||||
if (useSenario3)
|
||||
{
|
||||
//
|
||||
// Senario 3 Bullish Conditions ...
|
||||
isSenario3Bullish = false;
|
||||
|
||||
//
|
||||
// Senario 3 Bearish Conditions ...
|
||||
isSenario3Bearish = false;
|
||||
|
||||
//
|
||||
// Filling Requirements using Senario 3 ...
|
||||
isSenario3Happend =
|
||||
isSenario3Bullish ||
|
||||
isSenario3Bearish;
|
||||
if (isSenario3Happend)
|
||||
{
|
||||
//
|
||||
dir =
|
||||
isSenario3Bullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
box.dir = dir;
|
||||
box.to = TimeCurrent();
|
||||
box.symbol = provider
|
||||
.decisionXConditions
|
||||
.symbol;
|
||||
box.period = provider
|
||||
.decisionXConditions
|
||||
.period;
|
||||
|
||||
//
|
||||
int fromIDX = -1;
|
||||
if (isSenario3Bullish)
|
||||
{
|
||||
//
|
||||
double vale = provider
|
||||
.decisionXConditions
|
||||
.valesBuffer[cIDX];
|
||||
|
||||
//
|
||||
box.lower = vale;
|
||||
|
||||
//
|
||||
box.upper = provider
|
||||
.decisionXConditions
|
||||
.valesGoldenBuffer[cIDX];
|
||||
|
||||
//
|
||||
int lowerValeIDX = -1;
|
||||
double lowerVale = provider
|
||||
.decisionCycleHelper
|
||||
.mX121Helper
|
||||
.xpvHelper
|
||||
.GetLowerVale(
|
||||
lowerValeIDX,
|
||||
vale,
|
||||
cBar.Index() //
|
||||
);
|
||||
|
||||
//
|
||||
int higherValeIDX = -1;
|
||||
double higherVale = provider
|
||||
.decisionCycleHelper
|
||||
.mX121Helper
|
||||
.xpvHelper
|
||||
.GetHigherVale(
|
||||
higherValeIDX,
|
||||
vale,
|
||||
cBar.Index() //
|
||||
);
|
||||
|
||||
//
|
||||
if (IsValidIndex(lowerValeIDX) &&
|
||||
IsValidIndex(higherValeIDX))
|
||||
{
|
||||
//
|
||||
fromIDX =
|
||||
lowerValeIDX < higherValeIDX
|
||||
? lowerValeIDX
|
||||
: higherValeIDX;
|
||||
}
|
||||
else if (IsValidIndex(lowerValeIDX) &&
|
||||
!IsValidIndex(higherValeIDX))
|
||||
{
|
||||
//
|
||||
fromIDX = lowerValeIDX;
|
||||
}
|
||||
else if (!IsValidIndex(lowerValeIDX) &&
|
||||
IsValidIndex(higherValeIDX))
|
||||
{
|
||||
//
|
||||
fromIDX = higherValeIDX;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
double peak = provider
|
||||
.decisionXConditions
|
||||
.peaksBuffer[cIDX];
|
||||
|
||||
//
|
||||
box.upper = peak;
|
||||
|
||||
//
|
||||
box.lower = provider
|
||||
.decisionXConditions
|
||||
.peaksGoldenBuffer[cIDX];
|
||||
|
||||
//
|
||||
int lowerPeakIDX = -1;
|
||||
double lowerPeak = provider
|
||||
.decisionCycleHelper
|
||||
.mX121Helper
|
||||
.xpvHelper
|
||||
.GetLowerPeak(
|
||||
lowerPeakIDX,
|
||||
peak,
|
||||
cBar.Index() //
|
||||
);
|
||||
|
||||
//
|
||||
int higherPeakIDX = -1;
|
||||
double higherPeak = provider
|
||||
.decisionCycleHelper
|
||||
.mX121Helper
|
||||
.xpvHelper
|
||||
.GetHigherPeak(
|
||||
higherPeakIDX,
|
||||
peak,
|
||||
cBar.Index() //
|
||||
);
|
||||
|
||||
//
|
||||
if (IsValidIndex(lowerPeakIDX) &&
|
||||
IsValidIndex(higherPeakIDX))
|
||||
{
|
||||
//
|
||||
fromIDX =
|
||||
lowerPeakIDX < higherPeakIDX
|
||||
? lowerPeakIDX
|
||||
: higherPeakIDX;
|
||||
}
|
||||
else if (IsValidIndex(lowerPeakIDX) &&
|
||||
!IsValidIndex(higherPeakIDX))
|
||||
{
|
||||
//
|
||||
fromIDX = lowerPeakIDX;
|
||||
}
|
||||
else if (!IsValidIndex(lowerPeakIDX) &&
|
||||
IsValidIndex(higherPeakIDX))
|
||||
{
|
||||
//
|
||||
fromIDX = higherPeakIDX;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (IsValidIndex(fromIDX))
|
||||
{
|
||||
//
|
||||
box.from = iTime(
|
||||
zBar.symbol,
|
||||
zBar.period,
|
||||
fromIDX //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
box.from = pBar.time;
|
||||
}
|
||||
|
||||
//
|
||||
signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_BOX;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,431 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XTest MQL5 Expert Advisor
|
||||
// -------------------------------------------------
|
||||
// Name: XRRToolsEA
|
||||
// Description: a Template For Exper Advisors
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////x
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XRRToolsEA"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "XRRTools"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.x-alert.class.mq5"
|
||||
#include "../Classes/x-saherelm.x-rm.panel.class.mq5"
|
||||
#include "../Classes/x-saherelm.x-trade.class.mq5"
|
||||
#include "../Helpers/x-saherelm.x121.xcc.helper.mq5"
|
||||
#include "../Helpers/x-saherelm.x121.xct.helper.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Common ...
|
||||
input group "Common";
|
||||
input long eaMagicNumber = 78692110; // Magic Number
|
||||
input int eaSlippage = 10; // Slippgae
|
||||
input string eaLogSuffix = ""; // Log Suffix
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
// Here we Provider All Requirements for
|
||||
// Configuring Alert Provider ...
|
||||
input group "Alert";
|
||||
input bool eAEnableAlerts = true; // Enable Alerts
|
||||
input bool eALogAlerts = true; // Log Alerts
|
||||
input bool eAMailAlerts = false; // Mail Alerts
|
||||
input bool eAPushAlerts = false; // Push Alerts
|
||||
input bool eATerminalAlerts = false; // Terminal Alerts
|
||||
|
||||
//
|
||||
// Define Local Variables ...
|
||||
|
||||
//
|
||||
string eaLogTag; // EA Log Prefix ...
|
||||
XCAlert *eaAlert; // Alert Provider for Expert Adviser ...
|
||||
XCTrade *eaTrader; // Trader of Expert Adviser ...
|
||||
XCRMPanel eaMainWindow; // Main Window ...
|
||||
XCX121XCTHelper *eaCTHelper; // Bar Timer Indicator Helper class ...
|
||||
XCX121XCCHelper *eaCCHelper; // Chart Styler Indicator Helper Class ...
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs and Required Parameters
|
||||
// for EA to Works fine ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Timer ...
|
||||
if (!InitTimer())
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize all Requirements ...
|
||||
if (!InitEA())
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize all GUI Objects and Classes ...
|
||||
if (!InitGUI())
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Alert Initialization ...
|
||||
string msg = "Initialized Successfully ...";
|
||||
eaAlert.Alert(msg);
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Destroy Timer ...
|
||||
DestroyTimer();
|
||||
|
||||
//
|
||||
// Destroy all GUI Requirements ...
|
||||
DestroyGUI();
|
||||
|
||||
//
|
||||
// Alert De Initialization Succeeded ...
|
||||
string msg = "De Initialized Successfully ...";
|
||||
eaAlert.Alert(msg);
|
||||
|
||||
//
|
||||
// Destroy all EA Requirements ...
|
||||
DestroyEA();
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
UpdateGUI();
|
||||
}
|
||||
|
||||
//
|
||||
// Handle On Trade Event ...
|
||||
void OnTrade()
|
||||
{
|
||||
eaTrader.HandleOnTrade();
|
||||
}
|
||||
|
||||
//
|
||||
// On Timer ...
|
||||
void OnTimer()
|
||||
{
|
||||
//
|
||||
// TODO: Implement Time Based Functionalities ...
|
||||
}
|
||||
|
||||
//
|
||||
// Chart Event Handler ...
|
||||
void OnChartEvent(
|
||||
const int id,
|
||||
const long &lparam,
|
||||
const double &dparam,
|
||||
const string &sparam //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Apply Chart Event on Main Window ...
|
||||
eaMainWindow.ChartEvent(id, lparam, dparam, sparam);
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Event Handlers ...
|
||||
|
||||
/**
|
||||
* Handle StopLoss Triggered Positions ...
|
||||
*
|
||||
* @param deal: XDeal ...
|
||||
*/
|
||||
void OnStopLossTriggered(const XDeal &deal)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Take Profit Triggered Positions ...
|
||||
*
|
||||
* @param deal: XDeal ...
|
||||
*/
|
||||
void OnTakeProfitTriggered(const XDeal &deal)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Force Close a Position ...
|
||||
*
|
||||
* @param ticket: Position Ticket ...
|
||||
* @param position: XPosition ...
|
||||
* @param comment: Closing Comment ...
|
||||
*/
|
||||
void OnPositionForceClosed(
|
||||
const ulong ticket,
|
||||
const XPosition &position,
|
||||
const string comment //
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
/**
|
||||
* Validate all Inputs of Expert Adviser ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
string errMessage = "";
|
||||
|
||||
//
|
||||
bool isCommonValid = (
|
||||
//
|
||||
eaSlippage > 0 &&
|
||||
eaMagicNumber > 0
|
||||
//
|
||||
);
|
||||
if (!isCommonValid)
|
||||
{
|
||||
//
|
||||
errMessage += "common configurations error;" + "\n";
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
// Common ...
|
||||
isCommonValid &&
|
||||
//
|
||||
// Otere ...
|
||||
true
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
// Since here Logger not Initiallized, we Use Raw Print Command ...
|
||||
Print(ShortName + " Errors: \n", errMessage);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize Timer ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitTimer()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// TODO: Initialize Timer if necessary ...
|
||||
// result = EventSetTimer(1);
|
||||
// result = EventSetMillisecondTimer(100);
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Timer ...
|
||||
*/
|
||||
void DestroyTimer()
|
||||
{
|
||||
//
|
||||
// TODO: Use This ...
|
||||
// EventKillTimer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all Requirements for Working Fine ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitEA()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Locally Apply Changes on Prefix ...
|
||||
eaLogTag = ShortName + ">" + eaLogSuffix;
|
||||
|
||||
//
|
||||
// Bar Timer ...
|
||||
X121XCTInputs ctInputs;
|
||||
ctInputs.Default(); // Default Configurations ...
|
||||
eaCTHelper = new XCX121XCTHelper();
|
||||
result = eaCTHelper.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
ctInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Bar Styles ...
|
||||
X121XCCInputs ccInputs;
|
||||
ccInputs.Default(); // Default Configurations ...
|
||||
eaCCHelper = new XCX121XCCHelper();
|
||||
result = eaCCHelper.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
ccInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Create Instance of Alert Class and Configure it ...
|
||||
eaAlert = new XCAlert();
|
||||
eaAlert.SetPrefix(eaLogTag);
|
||||
eaAlert.SetLogAlerts(eALogAlerts);
|
||||
eaAlert.SetMailAlerts(eAMailAlerts);
|
||||
eaAlert.SetPushAlerts(eAPushAlerts);
|
||||
eaAlert.SetEnableAlerts(eAEnableAlerts);
|
||||
eaAlert.SetTerminalAlerts(eATerminalAlerts);
|
||||
|
||||
//
|
||||
// Create Trader Instance and Configure it ...
|
||||
eaTrader = new XCTrade(
|
||||
eaSlippage,
|
||||
eaMagicNumber //
|
||||
);
|
||||
eaTrader.AddOnStopLossEventHandler(OnStopLossTriggered);
|
||||
eaTrader.AddOnTakeProfitEventHandler(OnTakeProfitTriggered);
|
||||
eaTrader.AddOnForceClosePositionEventHandler(OnPositionForceClosed);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy all Initialized EA Requirements ...
|
||||
*/
|
||||
void DestroyEA()
|
||||
{
|
||||
//
|
||||
delete eaCTHelper;
|
||||
delete eaCCHelper;
|
||||
|
||||
//
|
||||
delete eaAlert;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all GUI Requirements for EA ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitGUI()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Application Main Window ...
|
||||
result = eaMainWindow.Create(
|
||||
ChartID(),
|
||||
ShortName, // Dialog Name ...
|
||||
0, // SubWindow ...
|
||||
10, // X1 ...
|
||||
35, // Y1 ...
|
||||
300, // X2 ...
|
||||
200 // Y2 ...
|
||||
);
|
||||
|
||||
//
|
||||
// Try To Run Main Window ...
|
||||
if (result)
|
||||
{
|
||||
eaMainWindow.Run();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update GUI based on Each Ticks ...
|
||||
*/
|
||||
void UpdateGUI()
|
||||
{
|
||||
//
|
||||
eaMainWindow.UpdateState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy all Initialized GUi Requirements ...
|
||||
*/
|
||||
void DestroyGUI()
|
||||
{
|
||||
//
|
||||
eaMainWindow.Destroy();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,462 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XTest MQL5 Expert Advisor
|
||||
// -------------------------------------------------
|
||||
// Name: X121SMCEA
|
||||
// Description: an Exper Advisor which used Panels
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121SMCEA"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "X121SMCEA"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../X121SMCEA/Experts/x-121.smc.expert.class.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Common ...
|
||||
input group "Common";
|
||||
input long eaMagicNumber = 78692110; // Magic Number
|
||||
input int eaSlippage = 10; // Slippgae
|
||||
input string eaLogSuffix = ""; // Log Suffix
|
||||
|
||||
//
|
||||
// Symbols ...
|
||||
input group "Symbols";
|
||||
input bool eaMultiSymbol = false; // Use Multi Symbol
|
||||
input string eaSymbols = "EURUSDb,GBPUSDb,USDCHFb,USDJPYb"; // Trading Symbols
|
||||
|
||||
//
|
||||
// Signalling ...
|
||||
input group "Signalling";
|
||||
input bool eaAllowLong = true; // Allow Long Signals
|
||||
input bool eaAllowShort = true; // Allow Short Signals
|
||||
input int eaMaxAllowedLongs = 5; // Max Allowed Long Signals
|
||||
input int eaMaxAllowedShorts = 5; // Max Allowed Short Signals
|
||||
input bool eaUseMaxAllowedSignalsPerSymbol = true; // Use Max Allowed Signal Types Per Symbol
|
||||
input double eaLastPositionProfitForAcceptNextInPoint = 0; // Last Position Profit In Points for Accept new Signal
|
||||
input int eaDelaysBetweenTwoSignalsInBar = 0; // Delay between two Signals in Bars
|
||||
input double eaMaxAllowedSpread = 0; // Max Allowed Spread for Signalling
|
||||
|
||||
//
|
||||
// Trade ...
|
||||
input group "Trade";
|
||||
input bool eaAllowTrade = true; // Allow Open Trade On Signals
|
||||
input string eaStartTradeAt = ""; // Enable Trade on Signals on Time
|
||||
input string eaStopTradeAt = ""; // Enable Trade on Signals on Time
|
||||
input string eaCloseAllTradesAt = ""; // Enable Close All Trades on Signals on Time
|
||||
|
||||
//
|
||||
// Risk Management ...
|
||||
input group "Risk Management";
|
||||
input double eaR2R = 6; // Signallers Risk to Reward Ratio
|
||||
input double eaVolume = 0; // Static Volume
|
||||
input double eaStaticBalance = 1000; // Static Balance
|
||||
input double eaBalancePerTrade = 5; // Balance Used in Each Trade
|
||||
input double eaRiskPercentPerBalance = 0; // Risk Percent Per Balance in Each Trade
|
||||
input bool eaDynamicRiskManagement = false; // Dynamic Risk Management
|
||||
input bool eaUseDynamicVolume = false; // Use Dynamic Volume
|
||||
input double eaDynamicVolumeStep = 0.01; // Increase Volume Step
|
||||
input double eaDynamicVolumeBalanceFactor = 200; // Balance Factor for Generate Dynamic Volume
|
||||
input double eaMaxAllowedDrawdownToOpenTrades = 3; // Max Allowed Drawdown for Open Trades
|
||||
input int eaMaxAllowedSLToPauseSignallingPerSymbol = 0; // Max Allowed SL for Pause Signalling Per Symbol
|
||||
input int eaPauseSignallingAfterReachesMaxAllowedSLInSecconds = 0; // Pause Signalling Per Symbol afte Max Allowed SL Reached In Seconds
|
||||
|
||||
//
|
||||
// Protection ...
|
||||
input group "Protection";
|
||||
input bool eaAllowHedging = false; // Allow Hedge Positions
|
||||
input int eaMinOpenTradesFroHedging = 4; // Minimum Open Positions for Hedging
|
||||
input double eaHedgingMinVolumeStep = 0.01; // Minimum Volume Step for Hedging
|
||||
input double eaHedgeingMinRequiredProfitPerVolumeStep = 1.0; // Minimum Required Profit Per Volume Step for Hedging
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
// Here we Provider All Requirements for
|
||||
// Configuring Alert Provider ...
|
||||
input group "Alert";
|
||||
input bool eaEnableAlerts = true; // Enable Alerts
|
||||
input bool eaLogAlerts = true; // Log Alerts
|
||||
input bool eaMailAlerts = false; // Mail Alerts
|
||||
input bool eaPushAlerts = false; // Push Alerts
|
||||
input bool eaTerminalAlerts = false; // Terminal Alerts
|
||||
|
||||
//
|
||||
// Time Report ...
|
||||
input group "Reports";
|
||||
input bool eaReportNewMonths = false; // Report New Month
|
||||
input bool eaReportNewWeeks = false; // Report New Weeks
|
||||
input bool eaReportNewDays = true; // Report New Days
|
||||
input bool eaReportNewHours = false; // Report New Hours
|
||||
|
||||
//
|
||||
// Define Local Variables ...
|
||||
|
||||
XC121SMCExpert *eaExpert;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs and Required Parameters
|
||||
// for EA to Works fine ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Timer ...
|
||||
if (!InitTimer())
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Configure EA Expert Class ...
|
||||
eaExpert = new XC121SMCExpert();
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
eaExpert.OnSignalEventListener = OnSignalRecieved;
|
||||
eaExpert.OnDealsChangedEventListener = OnDealsChanged;
|
||||
eaExpert.OnOrdersChangedEventListener = OnOrdersChanged;
|
||||
eaExpert.OnPositionSLEventListener = OnStopLossTriggered;
|
||||
eaExpert.OnPositionTPEventListener = OnTakeProfitTriggered;
|
||||
eaExpert.OnPositionsChangedEventListener = OnPositionsChanged;
|
||||
eaExpert.OnPositionForceCloseEventListener = OnPositionForceClosed;
|
||||
|
||||
//
|
||||
// Common ...
|
||||
eaExpert.MagicNumber(eaMagicNumber);
|
||||
eaExpert.Slippage(eaSlippage);
|
||||
eaExpert.TagPrefix(eaLogSuffix);
|
||||
|
||||
//
|
||||
// Symbol ...
|
||||
eaExpert.SetSymbol(_Symbol);
|
||||
eaExpert.SetPeriod(_Period);
|
||||
eaExpert.Symbols(eaSymbols);
|
||||
eaExpert.MultiSymbol(eaMultiSymbol);
|
||||
|
||||
//
|
||||
// Signalling ...
|
||||
eaExpert.AllowLong(eaAllowLong);
|
||||
eaExpert.AllowShort(eaAllowShort);
|
||||
eaExpert.MaxAllowedLongs(eaMaxAllowedLongs);
|
||||
eaExpert.MaxAllowedShorts(eaMaxAllowedShorts);
|
||||
eaExpert.UseMaxAllowedSignalsPerSymbol(eaUseMaxAllowedSignalsPerSymbol);
|
||||
eaExpert.LastPositionProfitForAcceptNextInPoint(eaLastPositionProfitForAcceptNextInPoint);
|
||||
eaExpert.DelaysBetweenTwoSignalsInBar(eaDelaysBetweenTwoSignalsInBar);
|
||||
eaExpert.MaxAllowedSpread(eaMaxAllowedSpread);
|
||||
|
||||
//
|
||||
// Trade ...
|
||||
eaExpert.AllowTrade(eaAllowTrade);
|
||||
eaExpert.StartTradeAt(eaStartTradeAt);
|
||||
eaExpert.StopTradeAt(eaStopTradeAt);
|
||||
eaExpert.CloseAllTradesAt(eaCloseAllTradesAt);
|
||||
|
||||
//
|
||||
// Risk Management ...
|
||||
eaExpert.R2R(eaR2R);
|
||||
eaExpert.Volume(eaVolume);
|
||||
eaExpert.StaticBalance(eaStaticBalance);
|
||||
eaExpert.BalancePerTrade(eaBalancePerTrade);
|
||||
eaExpert.RiskPercentPerBalance(eaRiskPercentPerBalance);
|
||||
eaExpert.DynamicRiskManagement(eaDynamicRiskManagement);
|
||||
eaExpert.UseDynamicVolume(eaUseDynamicVolume);
|
||||
eaExpert.DynamicVolumeStep(eaDynamicVolumeStep);
|
||||
eaExpert.DynamicVolumeBalanceFactor(eaDynamicVolumeBalanceFactor);
|
||||
eaExpert.MaxAllowedDrawdownToOpenTrades(eaMaxAllowedDrawdownToOpenTrades);
|
||||
eaExpert.MaxAllowedSLToPauseSignallingPerSymbol(eaMaxAllowedSLToPauseSignallingPerSymbol);
|
||||
eaExpert.PauseSignallingAfterReachesMaxAllowedSLInSecconds(eaPauseSignallingAfterReachesMaxAllowedSLInSecconds);
|
||||
|
||||
//
|
||||
// Protection ...
|
||||
eaExpert.AllowHedging(eaAllowHedging);
|
||||
eaExpert.MinOpenTradesFroHedging(eaMinOpenTradesFroHedging);
|
||||
eaExpert.HedgingMinVolumeStep(eaHedgingMinVolumeStep);
|
||||
eaExpert.HedgeingMinRequiredProfitPerVolumeStep(eaHedgeingMinRequiredProfitPerVolumeStep);
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
eaExpert.SetAlertEnableAlerts(eaEnableAlerts);
|
||||
eaExpert.SetAlertLogAlerts(eaLogAlerts);
|
||||
eaExpert.SetAlertMailAlerts(eaMailAlerts);
|
||||
eaExpert.SetAlertPushAlerts(eaPushAlerts);
|
||||
eaExpert.SetAlertTerminalAlerts(eaTerminalAlerts);
|
||||
|
||||
//
|
||||
// Reports ...
|
||||
eaExpert.ReportNewMonths(eaReportNewMonths);
|
||||
eaExpert.ReportNewWeeks(eaReportNewWeeks);
|
||||
eaExpert.ReportNewDays(eaReportNewDays);
|
||||
eaExpert.ReportNewHours(eaReportNewHours);
|
||||
|
||||
//
|
||||
bool isInited = eaExpert.HandleOnInit();
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Destroy Timer ...
|
||||
eaExpert.HandleOnDeInit();
|
||||
|
||||
//
|
||||
delete eaExpert;
|
||||
|
||||
//
|
||||
ZeroMemory(eaExpert);
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
eaExpert.HandleOnTick();
|
||||
}
|
||||
|
||||
//
|
||||
// Handle On Trade Event ...
|
||||
void OnTrade()
|
||||
{
|
||||
eaExpert.HandleOnTrade();
|
||||
}
|
||||
|
||||
//
|
||||
// On Timer ...
|
||||
void OnTimer()
|
||||
{
|
||||
eaExpert.HandleOnTimer();
|
||||
}
|
||||
|
||||
//
|
||||
// Chart Event Handler ...
|
||||
void OnChartEvent(
|
||||
const int id,
|
||||
const long &lparam,
|
||||
const double &dparam,
|
||||
const string &sparam //
|
||||
)
|
||||
{
|
||||
eaExpert.HandleOnChartEvent(id, lparam, dparam, sparam);
|
||||
}
|
||||
|
||||
//
|
||||
// Event Listeners ...
|
||||
|
||||
/**
|
||||
* Do What we Want by Specific Signal ...
|
||||
*
|
||||
* @param signal: XSignal instance ...
|
||||
* @param conditions: XStrategyConditions instance ...
|
||||
*/
|
||||
void OnSignalRecieved(
|
||||
XSignal &signal,
|
||||
X121SMCStrategyConditions &conditions //
|
||||
)
|
||||
{
|
||||
//
|
||||
eaExpert.HandleOnSignalRecieved(
|
||||
signal,
|
||||
conditions //
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle StopLoss Triggered Positions ...
|
||||
*
|
||||
* @param deal: XDeal instance ...
|
||||
*/
|
||||
void OnStopLossTriggered(const XDeal &deal)
|
||||
{
|
||||
eaExpert.HandleOnStopLossTriggered(deal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Take Profit Triggered Positions ...
|
||||
*
|
||||
* @param deal: XDeal instance ...
|
||||
*/
|
||||
void OnTakeProfitTriggered(const XDeal &deal)
|
||||
{
|
||||
eaExpert.HandleOnTakeProfitTriggered(deal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Force Close a Position ...
|
||||
*
|
||||
* @param ticket: ULONG ...
|
||||
* @param position: XPosition instance ...
|
||||
* @param comment: String ...
|
||||
*/
|
||||
void OnPositionForceClosed(
|
||||
const ulong ticket,
|
||||
const XPosition &position,
|
||||
const string comment //
|
||||
)
|
||||
{
|
||||
//
|
||||
eaExpert.HandleOnPositionForceClosed(
|
||||
ticket,
|
||||
position,
|
||||
comment //
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Deals Changes ...
|
||||
*
|
||||
* @param count: Integer, Number of Changes ...
|
||||
*/
|
||||
void OnDealsChanged(int count)
|
||||
{
|
||||
eaExpert.HandleOnDealsChanged(count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Orders Changes ...
|
||||
*
|
||||
* @param count: Integer, Number of Changes ...
|
||||
*/
|
||||
void OnOrdersChanged(int count)
|
||||
{
|
||||
eaExpert.HandleOnOrdersChanged(count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Positions Changes ...
|
||||
*
|
||||
* @param count: Integer, Number of Changes ...
|
||||
*/
|
||||
void OnPositionsChanged(int count)
|
||||
{
|
||||
eaExpert.HandleOnPositionsChanged(count);
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
/**
|
||||
* Validate all Inputs of Expert Adviser ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
string errMessage = "";
|
||||
|
||||
//
|
||||
bool isCommonValid = (
|
||||
//
|
||||
eaSlippage > 0 &&
|
||||
eaMagicNumber > 0
|
||||
//
|
||||
);
|
||||
if (!isCommonValid)
|
||||
{
|
||||
//
|
||||
errMessage += "common configurations error;" + "\n";
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
// Common ...
|
||||
isCommonValid &&
|
||||
//
|
||||
// Otere ...
|
||||
true
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
// Since here Logger not Initiallized, we Use Raw Print Command ...
|
||||
Print(ShortName + " Errors: \n", errMessage);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize Timer ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitTimer()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// TODO: Initialize Timer if necessary ...
|
||||
// result = EventSetTimer(1);
|
||||
// result = EventSetMillisecondTimer(100);
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Timer ...
|
||||
*/
|
||||
void DestroyTimer()
|
||||
{
|
||||
//
|
||||
// TODO: Use This ...
|
||||
// EventKillTimer();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,624 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XTest MQL5 Expert Advisor
|
||||
// -------------------------------------------------
|
||||
// Name: XCAEA
|
||||
// Description: an Exper Advisor which used Panels
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XCAEA EA"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.x-alert.class.mq5"
|
||||
#include "../Classes/x-saherelm.x-trade.class.mq5"
|
||||
#include "../Classes/x-saherelm.x-volume.class.mq5"
|
||||
#include "../XCAEA/Classes/xcaea.x-trade.manager.class.mq5"
|
||||
#include "../XCAEA/Signals/xcaea.signaller.class.mq5"
|
||||
|
||||
//
|
||||
#define ShortName "XCAEAEA"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Common ...
|
||||
input group "Common";
|
||||
input long eaMagicNumber = 78692110; // Magic Number
|
||||
input int eaSlippage = 10; // Slippgae
|
||||
input string eaLogSuffix = ""; // Log Suffix
|
||||
|
||||
//
|
||||
// Volume ...
|
||||
input group "Volume";
|
||||
input ENUM_X_VOLUME_SELECT_TYPE eaVolumeSelect = X_VOLUME_EQUITY; // Volume Applying Type
|
||||
input double eaStaticVoluem = 0.0; // Static Volume
|
||||
input double eaDynamicVolumeStepBalance = 0.0; // Step of Balance for Increase Volume
|
||||
input double eaDynamicVolumeStepVolume = X_MIN_VOLUME; // Step of Volume Increasing
|
||||
input double eaConstantRiskBalance = 0.0; // Constant Risk Balance per Trade
|
||||
input double eaConstantPercent = 0.5; // Constant Percent of Balance Per Trade
|
||||
input double eaConstantBalance = 0.0; // Constant Balance for Calculations
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
// Here we Provider All Requirements for
|
||||
// Configuring Alert Provider ...
|
||||
input group "Alert";
|
||||
input bool eaEnableAlerts = true; // Enable Alerts
|
||||
input bool eaLogAlerts = true; // Log Alerts
|
||||
input bool eaMailAlerts = false; // Mail Alerts
|
||||
input bool eaPushAlerts = false; // Push Alerts
|
||||
input bool eaTerminalAlerts = false; // Terminal Alerts
|
||||
|
||||
//
|
||||
// Time Report ...
|
||||
input group "Reports";
|
||||
input bool eaReportNewMonths = false; // Report New Month
|
||||
input bool eaReportNewWeeks = false; // Report New Weeks
|
||||
input bool eaReportNewDays = true; // Report New Days
|
||||
input bool eaReportNewHours = false; // Report New Hours
|
||||
|
||||
//
|
||||
// Variables, Instances ...
|
||||
XCAlert *eaAlert;
|
||||
XCTrade *eaTrade;
|
||||
XSignal eaSignal;
|
||||
XCVolume *eaVolume;
|
||||
XCXCAEASignaller *eaSignaller;
|
||||
XCXCAEATradeManager *eaTradeManager;
|
||||
XCAEAStrategyConditions eaConditions;
|
||||
|
||||
//
|
||||
int eaMaxAllowedPositions = 5;
|
||||
double eaMaxAllowedSpread = 25;
|
||||
double eaMaxAllowedDrawdownFactor = 0.3;
|
||||
|
||||
//
|
||||
string eaTag = "";
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs and Required Parameters
|
||||
// for EA to Works fine ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Timer ...
|
||||
if (!InitTimer())
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Requirements ...
|
||||
InitRequirements();
|
||||
|
||||
//
|
||||
// Initialize Volume Manger ...
|
||||
if (!InitVolume())
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
ZeroMemory(eaAlert);
|
||||
ZeroMemory(eaTrade);
|
||||
ZeroMemory(eaVolume);
|
||||
ZeroMemory(eaSignaller);
|
||||
|
||||
//
|
||||
eaSignal.Clean();
|
||||
eaConditions.Clean();
|
||||
|
||||
//
|
||||
DestroyTimer();
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
int idx = -1;
|
||||
int count = 0;
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
// Handle Position Management / Protections ...
|
||||
eaTradeManager.Manage();
|
||||
|
||||
//
|
||||
eaSignal.Clean();
|
||||
eaConditions.Clean();
|
||||
|
||||
//
|
||||
double r2r = 5;
|
||||
string provider = "XCAEA";
|
||||
ENUM_POSITION_TYPE type = POSITION_TYPE_BUY;
|
||||
ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET;
|
||||
|
||||
//
|
||||
bool hasLong = false;
|
||||
bool hasShort = false;
|
||||
|
||||
//
|
||||
// Start Calculations ...
|
||||
|
||||
//
|
||||
// Retrieve Common Data ...
|
||||
string symbol = eaSignaller.GetSymbol();
|
||||
ENUM_TIMEFRAMES period = eaSignaller.GetPeriod();
|
||||
|
||||
//
|
||||
datetime cTime = TimeCurrent();
|
||||
|
||||
//
|
||||
// Required Value For SL/TP Calculations ...
|
||||
double points = GetPoints(symbol);
|
||||
double pip = GetPipPrice(symbol);
|
||||
double pip2 = 2 * pip;
|
||||
|
||||
//
|
||||
has = eaSignaller.DetectSignalSetup(
|
||||
r2r,
|
||||
300 // Max Allowed SL Distance ...
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
count = eaSignaller
|
||||
.AddConditionsIfNotExists();
|
||||
|
||||
//
|
||||
eaSignaller.mConditions.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Check Setuped Conditions Exists ...
|
||||
count = ArraySize(eaSignaller.mConditionsCollection);
|
||||
has = IsValidSize(count);
|
||||
if (!has)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
has = eaSignaller
|
||||
.DetectSignalTrigger(eaSignaller
|
||||
.mConditionsCollection[i]);
|
||||
|
||||
//
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
idx = i;
|
||||
eaConditions = eaSignaller.mConditionsCollection[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
has = IsValidIndex(idx);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
ArrayRemove(
|
||||
eaSignaller.mConditionsCollection,
|
||||
idx,
|
||||
1 //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Check EA Conditions is Valid or not ...
|
||||
has = eaConditions.IsSetuped() &&
|
||||
eaConditions.CanTrigger();
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
eaConditions.Clean();
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Setting Time to Conditions ...
|
||||
eaConditions.time = cTime;
|
||||
has = ToPositionType(
|
||||
type,
|
||||
eaConditions.type //
|
||||
);
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
eaSignal.Clean();
|
||||
eaConditions.Clean();
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Checking Trigger Direction ...
|
||||
hasLong = eaConditions.HasBullishSignal();
|
||||
hasShort = eaConditions.HasBearishSignal();
|
||||
has = hasLong ||
|
||||
hasShort;
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
eaSignal.Clean();
|
||||
eaConditions.Clean();
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Preparing Signal ...
|
||||
//
|
||||
eaSignal.mode = mode;
|
||||
eaSignal.type = type;
|
||||
eaSignal.entry = GetEntry(
|
||||
eaConditions.symbol,
|
||||
eaConditions.dir //
|
||||
);
|
||||
eaSignal.provider = provider;
|
||||
eaSignal.sl = eaConditions.sl;
|
||||
eaSignal.tp = eaConditions.tp;
|
||||
eaSignal.volume = X_MIN_VOLUME;
|
||||
eaSignal.time = eaConditions.time;
|
||||
eaSignal.symbol = eaConditions.symbol;
|
||||
eaSignal.period = eaConditions.period;
|
||||
|
||||
//
|
||||
Copy(
|
||||
eaConditions.targets,
|
||||
eaSignal.targets //
|
||||
);
|
||||
|
||||
//
|
||||
has = eaSignal.IsValid();
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
eaSignal.Clean();
|
||||
eaConditions.Clean();
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Volume Management ...
|
||||
double iVolume = eaVolume.CalculateVolume(eaSignal);
|
||||
if (iVolume > X_MIN_VOLUME &&
|
||||
iVolume != eaSignal.volume)
|
||||
{
|
||||
eaSignal.volume = iVolume;
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Signal ...
|
||||
|
||||
//
|
||||
// Execute Signal ...
|
||||
|
||||
//
|
||||
has = eaTradeManager.Execute(
|
||||
eaSignal,
|
||||
eaConditions //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Do What we Want on Successfully Execution Signal ...
|
||||
Print("Signal Executed ...");
|
||||
}
|
||||
|
||||
//
|
||||
eaSignal.Clean();
|
||||
eaConditions.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Handle On Trade Event ...
|
||||
void OnTrade()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// On Timer ...
|
||||
void OnTimer()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Chart Event Handler ...
|
||||
void OnChartEvent(
|
||||
const int id,
|
||||
const long &lparam,
|
||||
const double &dparam,
|
||||
const string &sparam //
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Event Listeners ...
|
||||
|
||||
/**
|
||||
* Handle StopLoss Triggered Positions ...
|
||||
*
|
||||
* @param deal: XDeal instance ...
|
||||
*/
|
||||
void OnStopLossTriggered(const XDeal &deal)
|
||||
{
|
||||
eaTradeManager.HandleSL(deal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Take Profit Triggered Positions ...
|
||||
*
|
||||
* @param deal: XDeal instance ...
|
||||
*/
|
||||
void OnTakeProfitTriggered(const XDeal &deal)
|
||||
{
|
||||
eaTradeManager.HandleTP(deal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Force Close a Position ...
|
||||
*
|
||||
* @param ticket: ULONG ...
|
||||
* @param position: XPosition instance ...
|
||||
* @param comment: String ...
|
||||
*/
|
||||
void OnPositionForceClosed(
|
||||
const ulong ticket,
|
||||
const XPosition &position,
|
||||
const string comment //
|
||||
)
|
||||
{
|
||||
eaTradeManager.HandleForceClose(position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Deals Changes ...
|
||||
*
|
||||
* @param count: Integer, Number of Changes ...
|
||||
*/
|
||||
void OnDealsChanged(int count)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Orders Changes ...
|
||||
*
|
||||
* @param count: Integer, Number of Changes ...
|
||||
*/
|
||||
void OnOrdersChanged(int count)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Positions Changes ...
|
||||
*
|
||||
* @param count: Integer, Number of Changes ...
|
||||
*/
|
||||
void OnPositionsChanged(int count)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
/**
|
||||
* Validate all Inputs of Expert Adviser ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
string errMessage = "";
|
||||
|
||||
//
|
||||
bool isCommonValid = (
|
||||
//
|
||||
eaSlippage > 0 &&
|
||||
eaMagicNumber > 0
|
||||
//
|
||||
);
|
||||
if (!isCommonValid)
|
||||
{
|
||||
//
|
||||
errMessage += "common configurations error;" + "\n";
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
// Common ...
|
||||
isCommonValid &&
|
||||
//
|
||||
// Otere ...
|
||||
true
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
// Since here Logger not Initiallized, we Use Raw Print Command ...
|
||||
Print(ShortName + " Errors: \n", errMessage);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize Timer ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitTimer()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// TODO: Initialize Timer if necessary ...
|
||||
// result = EventSetTimer(1);
|
||||
// result = EventSetMillisecondTimer(100);
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Timer ...
|
||||
*/
|
||||
void DestroyTimer()
|
||||
{
|
||||
//
|
||||
// TODO: Use This ...
|
||||
// EventKillTimer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initial Volume Manager Class Based on Given Configuration ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitVolume()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
eaVolume = new XCVolume();
|
||||
|
||||
//
|
||||
result = eaVolume.Init(
|
||||
eaVolumeSelect,
|
||||
eaStaticVoluem,
|
||||
eaDynamicVolumeStepBalance,
|
||||
eaDynamicVolumeStepVolume,
|
||||
eaConstantRiskBalance,
|
||||
eaConstantPercent,
|
||||
eaConstantBalance //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initial Requirements of EA ...
|
||||
*
|
||||
*/
|
||||
void InitRequirements()
|
||||
{
|
||||
//
|
||||
// Preparing Tags ...
|
||||
eaTag =
|
||||
(IsValid(eaLogSuffix)
|
||||
? eaLogSuffix + "_"
|
||||
: "") +
|
||||
ShortName;
|
||||
|
||||
//
|
||||
// EA Alert ...
|
||||
eaAlert = new XCAlert(
|
||||
eaTag,
|
||||
eaEnableAlerts,
|
||||
eaLogAlerts,
|
||||
eaTerminalAlerts,
|
||||
eaMailAlerts,
|
||||
eaPushAlerts //
|
||||
);
|
||||
|
||||
//
|
||||
// EA Trade ...
|
||||
eaTrade = new XCTrade(
|
||||
eaSlippage,
|
||||
eaMagicNumber,
|
||||
eaMaxAllowedSpread,
|
||||
eaMaxAllowedPositions,
|
||||
eaMaxAllowedDrawdownFactor //
|
||||
);
|
||||
eaTrade.AddOnStopLossEventHandler(OnStopLossTriggered);
|
||||
eaTrade.AddOnTakeProfitEventHandler(OnTakeProfitTriggered);
|
||||
eaTrade.AddOnForceClosePositionEventHandler(OnPositionForceClosed);
|
||||
|
||||
//
|
||||
// EA Trae Manager ...
|
||||
eaTradeManager = new XCXCAEATradeManager(
|
||||
eaTrade //
|
||||
);
|
||||
eaTradeManager.SetAlertEnableAlerts(eaEnableAlerts);
|
||||
eaTradeManager.SetAlertPrefix(eaTag);
|
||||
eaTradeManager.SetAlertLogAlerts(eaLogAlerts);
|
||||
eaTradeManager.SetAlertMailAlerts(eaMailAlerts);
|
||||
eaTradeManager.SetAlertPushAlerts(eaPushAlerts);
|
||||
eaTradeManager.SetAlertTerminalAlerts(eaTerminalAlerts);
|
||||
|
||||
//
|
||||
// EA Signaller ...
|
||||
eaSignaller = new XCXCAEASignaller(
|
||||
_Symbol,
|
||||
_Period //
|
||||
);
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,252 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCX121XCCHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.x-helper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct X121XCCInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Chart Style ...
|
||||
ENUM_CHART_MODE mode; // Mode
|
||||
color upColor; // Up Color
|
||||
color downColor; // Down Color
|
||||
color lineColor; // Line mode and Doji candlestick Color
|
||||
color bearishColor; // Bullish Color
|
||||
color bullishColor; // Bearish Color
|
||||
color volumesColor; // Volumes Color
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showCandles; // Show Candles
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
X121XCCInputs()
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
mode = CHART_CANDLES;
|
||||
|
||||
//
|
||||
upColor = CLR_NONE;
|
||||
downColor = CLR_NONE;
|
||||
lineColor = CLR_NONE;
|
||||
bearishColor = CLR_NONE;
|
||||
bullishColor = CLR_NONE;
|
||||
volumesColor = CLR_NONE;
|
||||
|
||||
//
|
||||
showCandles = false;
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
mode = CHART_CANDLES;
|
||||
|
||||
//
|
||||
upColor = clrLime;
|
||||
downColor = clrRed;
|
||||
lineColor = clrLime;
|
||||
bearishColor = clrRed;
|
||||
bullishColor = clrLime;
|
||||
volumesColor = clrGreen;
|
||||
//
|
||||
showCandles = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
true
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(0, 0);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XCX121XCCHelper : public XCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XCX121XCCHelper()
|
||||
: XCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCX121XCCHelper()
|
||||
{
|
||||
mInputs.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
X121XCCInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xcc",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Chart Style ...
|
||||
"",
|
||||
mInputs.mode, // Mode
|
||||
mInputs.upColor, // Up Color
|
||||
mInputs.downColor, // Down Color
|
||||
mInputs.lineColor, // Line mode and Doji candlestick Color
|
||||
mInputs.bullishColor, // Bearish Color
|
||||
mInputs.bearishColor, // Bullish Color
|
||||
mInputs.volumesColor, // Volumes Color
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
mInputs.showCandles // Show Candles
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
X121XCCInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
X121XCCInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
X121XCCInputs mInputs; // Inputs ...
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,234 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCX121XCTHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.x-helper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct X121XCTInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
string font; // Font
|
||||
int fontSize; // Font Size;
|
||||
color clr; // Text Color
|
||||
ENUM_BASE_CORNER corner; // Text Position
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showCandleTime; // Show Candle Time
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
X121XCTInputs()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
font = NULL;
|
||||
fontSize = 15;
|
||||
clr = CLR_NONE;
|
||||
corner = CORNER_RIGHT_LOWER;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
showCandleTime = false;
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
font = "Arial";
|
||||
fontSize = 15;
|
||||
clr = clrYellow;
|
||||
corner = CORNER_RIGHT_LOWER;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
showCandleTime = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
true
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(0, 0);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XCX121XCTHelper : public XCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XCX121XCTHelper()
|
||||
: XCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCX121XCTHelper()
|
||||
{
|
||||
mInputs.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
X121XCTInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xct",
|
||||
//
|
||||
// Inputs ...
|
||||
mInputs.fontSize, // Font Size ...
|
||||
mInputs.font, // Font ...
|
||||
mInputs.clr, // Text Color ...
|
||||
mInputs.corner, // Text Position ...
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
mInputs.showCandleTime // Show Candle Time
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
X121XCTInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
X121XCTInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
X121XCTInputs mInputs; // Inputs ...
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
@@ -0,0 +1,856 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XCX121XDELTASHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.x-helper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
enum ENUM_X121_XDELTA_BUFFERS
|
||||
{
|
||||
//
|
||||
X121_XDELTA_VOLUME_LINE = 0,
|
||||
X121_XDELTA_HISTOGRAM_LINE = 1,
|
||||
X121_XDELTA_MA_LINE = 3,
|
||||
X121_XDELTA_STATE_LINE = 5,
|
||||
};
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct X121XDELTAInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Makret ...
|
||||
int maLength; // Moving Averge Length
|
||||
ENUM_X_MA_METHOD maMethod; // Moving Averge Method
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
int startCalculationForLastBars; // Calculate Last n Bars
|
||||
bool showDeltaLine; // Show Delta Line
|
||||
bool showDeltaHistogram; // Show Delta Histogram
|
||||
bool showDeltaMa; // Show Delta Moving Average
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
X121XDELTAInputs()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleanup Model ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
// Makret ...
|
||||
maLength = 0; // Moving Averge Length
|
||||
maMethod = X_MA_MODE_NONE; // Moving Averge Method
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
startCalculationForLastBars = 0; // Calculate Last n Bars
|
||||
showDeltaLine = false; // Show Delta Line
|
||||
showDeltaHistogram = false; // Show Delta Histogram
|
||||
showDeltaMa = false; // Show Delta Moving Average
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default Inputs ...
|
||||
*/
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
// Makret ...
|
||||
maLength = 14; // Moving Averge Length
|
||||
maMethod = X_MA_MODE_EMA; // Moving Averge Method
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
showDeltaLine = true; // Show Delta Line
|
||||
showDeltaHistogram = true; // Show Delta Histogram
|
||||
showDeltaMa = true; // Show Delta Moving Average
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Model ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
maLength > 0 &&
|
||||
IsValid(maMethod)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Max Input Length ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(result, maLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
struct X121XDELTAConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double deltaBuffer[];
|
||||
double deltaMaBuffer[];
|
||||
double deltaStateBuffer[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isDeltaBullish;
|
||||
bool isDeltaBearish;
|
||||
bool isDeltaSwitchedToBullish;
|
||||
bool isDeltaSwitchedToBearish;
|
||||
|
||||
//
|
||||
bool isDeltaOverMa;
|
||||
bool isDeltaUnderMa;
|
||||
bool isDeltaCrossedOverMa;
|
||||
bool isDeltaCrossedUnderMa;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
X121XDELTAConditions()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleaning Up ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
// Commons ...
|
||||
time = NULL;
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
Clean(deltaBuffer);
|
||||
Clean(deltaMaBuffer);
|
||||
Clean(deltaStateBuffer);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(deltaBuffer, true);
|
||||
ArraySetAsSeries(deltaMaBuffer, true);
|
||||
ArraySetAsSeries(deltaStateBuffer, true);
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
isDeltaBullish = false;
|
||||
isDeltaBearish = false;
|
||||
isDeltaSwitchedToBullish = false;
|
||||
isDeltaSwitchedToBearish = false;
|
||||
|
||||
//
|
||||
isDeltaOverMa = false;
|
||||
isDeltaUnderMa = false;
|
||||
isDeltaCrossedOverMa = false;
|
||||
isDeltaCrossedUnderMa = false;
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Conditions Scores ...
|
||||
*
|
||||
* @param bullishScore: Double, Directional Scores Reference ...
|
||||
* @param bearishScore: Double, Directional Scores Reference ...
|
||||
*/
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
double score = 1;
|
||||
double minScore = 0.5;
|
||||
double highScore = 1.5;
|
||||
|
||||
//
|
||||
if (isDeltaOverMa)
|
||||
{
|
||||
bullishScore += minScore;
|
||||
}
|
||||
if (isDeltaBullish)
|
||||
{
|
||||
bullishScore += minScore;
|
||||
}
|
||||
if (isDeltaCrossedOverMa)
|
||||
{
|
||||
bullishScore += score;
|
||||
}
|
||||
if (isDeltaSwitchedToBullish)
|
||||
{
|
||||
bullishScore += score;
|
||||
}
|
||||
|
||||
if (isDeltaBearish)
|
||||
{
|
||||
bearishScore += minScore;
|
||||
}
|
||||
if (isDeltaUnderMa)
|
||||
{
|
||||
bearishScore += minScore;
|
||||
}
|
||||
if (isDeltaCrossedUnderMa)
|
||||
{
|
||||
bearishScore += score;
|
||||
}
|
||||
if (isDeltaSwitchedToBearish)
|
||||
{
|
||||
bearishScore += score;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Summary String for Represent Conditions State ...
|
||||
*
|
||||
* @param onlyCommons: Boolean, Just Generate Only Commons Conditions ...
|
||||
* @param onlyConditions: Boolean, Just Generate Only Conditions ...
|
||||
* @param includeScores: Boolean, Attach Scores Representations on Result ...
|
||||
* @param ignoreFalseConditions: Boolean, Ignore False Conditions on Result ...
|
||||
* @param separator: String, Separate Lines ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GenerateSummary(
|
||||
bool onlyCommons = false,
|
||||
bool onlyConditions = false,
|
||||
bool includeScores = true,
|
||||
bool ignoreFalseConditions = true,
|
||||
string separator = "\n" //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
string scoresStr =
|
||||
//
|
||||
"Scores: " + separator +
|
||||
"---------------" + separator +
|
||||
"Bullish: " + ToString(bullishScore) + separator +
|
||||
"Bearish: " + ToString(bearishScore) + separator +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
string commonStr = GenerateSpecifiedCommonSummary(
|
||||
this,
|
||||
separator,
|
||||
includeScores //
|
||||
);
|
||||
|
||||
//
|
||||
string conditionsStr =
|
||||
//
|
||||
"-----------------------" + separator +
|
||||
"XDELTA: " + separator +
|
||||
"-----------------------" + separator +
|
||||
ToString("isDeltaBullish", isDeltaBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isDeltaBearish", isDeltaBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isDeltaSwitchedToBullish", isDeltaSwitchedToBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isDeltaSwitchedToBearish", isDeltaSwitchedToBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isDeltaOverMa", isDeltaOverMa, ignoreFalseConditions, separator) +
|
||||
ToString("isDeltaUnderMa", isDeltaUnderMa, ignoreFalseConditions, separator) +
|
||||
ToString("isDeltaCrossedOverMa", isDeltaCrossedOverMa, ignoreFalseConditions, separator) +
|
||||
ToString("isDeltaCrossedUnderMa", isDeltaCrossedUnderMa, ignoreFalseConditions, separator) +
|
||||
//
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve nique Tag Identifier ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GetTag()
|
||||
{
|
||||
return GetTypeName(this);
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XCX121XDELTAHelper : public XCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XCX121XDELTAHelper()
|
||||
: XCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCX121XDELTAHelper()
|
||||
{
|
||||
//
|
||||
mInputs.Clean();
|
||||
|
||||
//
|
||||
Clean(deltaBuffer);
|
||||
Clean(deltaMaBuffer);
|
||||
Clean(deltaStateBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
X121XDELTAInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
ArraySetAsSeries(deltaBuffer, true);
|
||||
ArraySetAsSeries(deltaMaBuffer, true);
|
||||
ArraySetAsSeries(deltaStateBuffer, true);
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xdelta",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Market ...
|
||||
"",
|
||||
mInputs.maLength,
|
||||
mInputs.maMethod,
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
//
|
||||
mInputs.startCalculationForLastBars,
|
||||
mInputs.showDeltaLine,
|
||||
mInputs.showDeltaHistogram,
|
||||
mInputs.showDeltaMa
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
X121XDELTAInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
X121XDELTAInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Readers ...
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
|
||||
//
|
||||
double GetDelta(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate(barIndex);
|
||||
|
||||
//
|
||||
int count = ArraySize(deltaBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return deltaBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
int CopyDelta(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate(start);
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
0,
|
||||
count,
|
||||
deltaBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
double GetDeltaState(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate(barIndex);
|
||||
|
||||
//
|
||||
int count = ArraySize(deltaStateBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return deltaStateBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
int CopyDeltaState(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate(start);
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
0,
|
||||
count,
|
||||
deltaStateBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
double GetDeltaMa(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate(barIndex);
|
||||
|
||||
//
|
||||
int count = ArraySize(deltaMaBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return deltaMaBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
int CopyDeltaMa(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate(start);
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
0,
|
||||
count,
|
||||
deltaMaBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
void Free() override
|
||||
{
|
||||
Cleanup(10);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
X121XDELTAConditions &conditions, //
|
||||
int barIndex = 0, //
|
||||
int loopback = 5 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
if (loopback < 5)
|
||||
{
|
||||
loopback = 5;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.Clean();
|
||||
|
||||
//
|
||||
conditions.symbol = mSymbol;
|
||||
conditions.period = mPeriod;
|
||||
conditions.time = TimeCurrent();
|
||||
|
||||
//
|
||||
int zIndex = barIndex;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
CopyDelta(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.deltaBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
CopyDeltaState(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.deltaStateBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
CopyDeltaMa(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.deltaMaBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
int cIDX = 1;
|
||||
int pIDX = cIDX + 1;
|
||||
int pPIDX = pIDX + 1;
|
||||
|
||||
//
|
||||
bool isDeltaBullish = conditions.deltaBuffer[cIDX] > conditions.deltaBuffer[pIDX];
|
||||
bool isDeltaBullishP = conditions.deltaBuffer[pIDX] > conditions.deltaBuffer[pPIDX];
|
||||
bool isDeltaSwitchedToBullish = isDeltaBullish &&
|
||||
!isDeltaBullishP;
|
||||
|
||||
//
|
||||
bool isDeltaBearish = conditions.deltaBuffer[cIDX] < conditions.deltaBuffer[pIDX];
|
||||
bool isDeltaBearishP = conditions.deltaBuffer[pIDX] < conditions.deltaBuffer[pPIDX];
|
||||
bool isDeltaSwitchedToBearish = isDeltaBearish &&
|
||||
!isDeltaBearishP;
|
||||
|
||||
//
|
||||
bool isDeltaOverMa = conditions.deltaBuffer[cIDX] > conditions.deltaMaBuffer[cIDX];
|
||||
bool isDeltaOverMaP = conditions.deltaBuffer[pIDX] > conditions.deltaMaBuffer[pIDX];
|
||||
bool isDeltaCrossedOverMa = isDeltaOverMa &&
|
||||
!isDeltaOverMaP;
|
||||
|
||||
//
|
||||
bool isDeltaUnderMa = conditions.deltaBuffer[cIDX] < conditions.deltaMaBuffer[cIDX];
|
||||
bool isDeltaUnderMaP = conditions.deltaBuffer[pIDX] < conditions.deltaMaBuffer[pIDX];
|
||||
bool isDeltaCrossedUnderMa = isDeltaUnderMa &&
|
||||
!isDeltaUnderMaP;
|
||||
|
||||
//
|
||||
conditions.isDeltaBullish = isDeltaBullish;
|
||||
conditions.isDeltaBearish = isDeltaBearish;
|
||||
conditions.isDeltaSwitchedToBullish = isDeltaSwitchedToBullish;
|
||||
conditions.isDeltaSwitchedToBearish = isDeltaSwitchedToBearish;
|
||||
|
||||
//
|
||||
conditions.isDeltaOverMa = isDeltaOverMa;
|
||||
conditions.isDeltaUnderMa = isDeltaUnderMa;
|
||||
conditions.isDeltaCrossedOverMa = isDeltaCrossedOverMa;
|
||||
conditions.isDeltaCrossedUnderMa = isDeltaCrossedUnderMa;
|
||||
|
||||
//
|
||||
Cleanup();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
X121XDELTAInputs mInputs; // Inputs ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double deltaBuffer[];
|
||||
double deltaMaBuffer[];
|
||||
double deltaStateBuffer[];
|
||||
|
||||
//
|
||||
void Calculate(
|
||||
int barIndex = 0,
|
||||
int maxRequiredBars = 100 //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Buffers ...
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
X121_XDELTA_VOLUME_LINE,
|
||||
barIndex,
|
||||
maxRequiredBars,
|
||||
deltaBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
X121_XDELTA_MA_LINE,
|
||||
barIndex,
|
||||
maxRequiredBars,
|
||||
deltaMaBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
X121_XDELTA_STATE_LINE,
|
||||
barIndex,
|
||||
maxRequiredBars,
|
||||
deltaStateBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
void Cleanup(
|
||||
int maxAllowed = 100 //
|
||||
)
|
||||
{
|
||||
//
|
||||
CleanupArray(
|
||||
deltaBuffer,
|
||||
maxAllowed //
|
||||
);
|
||||
|
||||
//
|
||||
CleanupArray(
|
||||
deltaMaBuffer,
|
||||
maxAllowed //
|
||||
);
|
||||
|
||||
//
|
||||
CleanupArray(
|
||||
deltaStateBuffer,
|
||||
maxAllowed //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,797 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XCX121XMASHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.x-helper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
enum ENUM_X121_XMAS_BUFFERS
|
||||
{
|
||||
//
|
||||
X121_XMAS_UPPER_LINE = 0,
|
||||
X121_XMAS_MID_LINE = 1,
|
||||
X121_XMAS_LOWER_LINE = 2,
|
||||
};
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct X121XMASInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
int length; // MA Length
|
||||
ENUM_MA_METHOD method; // MA Method
|
||||
ENUM_APPLIED_PRICE upperAppliedTo; // Upper Applied To
|
||||
ENUM_APPLIED_PRICE midAppliedTo; // Mid Applied To
|
||||
ENUM_APPLIED_PRICE lowerAppliedTo; // Lower Applied To
|
||||
|
||||
//
|
||||
int startCalculationForLastBars; // Calculate Last n Bars
|
||||
bool showUpper; // Show Upper
|
||||
bool showMid; // Show Mid
|
||||
bool showLower; // Show Lower
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
X121XMASInputs()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
length = 0; // MA Length
|
||||
method = MODE_EMA; // MA Method
|
||||
upperAppliedTo = PRICE_HIGH; // Upper Applied To
|
||||
midAppliedTo = PRICE_MEDIAN; // Mid Applied To
|
||||
lowerAppliedTo = PRICE_LOW; // Lower Applied To
|
||||
|
||||
//
|
||||
startCalculationForLastBars = 0; // Calculate Last n Bars
|
||||
showUpper = false; // Show Upper
|
||||
showMid = false; // Show Mid
|
||||
showLower = false; // Show Lower
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
length = 14; // MA Length
|
||||
method = MODE_EMA; // MA Method
|
||||
upperAppliedTo = PRICE_HIGH; // Upper Applied To
|
||||
midAppliedTo = PRICE_MEDIAN; // Mid Applied To
|
||||
lowerAppliedTo = PRICE_LOW; // Lower Applied To
|
||||
|
||||
//
|
||||
startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
showUpper = true; // Show Upper
|
||||
showMid = true; // Show Mid
|
||||
showLower = true; // Show Lower
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
length > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(result, length);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
struct X121XMASConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double upperBuffer[];
|
||||
double midBuffer[];
|
||||
double lowerBuffer[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
X121XMASConditions()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleaning Up ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
// Commons ...
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
time = NULL;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
Clean(upperBuffer);
|
||||
Clean(midBuffer);
|
||||
Clean(lowerBuffer);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(upperBuffer, true);
|
||||
ArraySetAsSeries(midBuffer, true);
|
||||
ArraySetAsSeries(lowerBuffer, true);
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Conditions Scores ...
|
||||
*
|
||||
* @param bullishScore: Double, Directional Scores Reference ...
|
||||
* @param bearishScore: Double, Directional Scores Reference ...
|
||||
*/
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
// TODO: Implement if Required ...
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Summary String for Represent Conditions State ...
|
||||
*
|
||||
* @param onlyCommons: Boolean, Just Generate Only Commons Conditions ...
|
||||
* @param onlyConditions: Boolean, Just Generate Only Conditions ...
|
||||
* @param includeScores: Boolean, Attach Scores Representations on Result ...
|
||||
* @param ignoreFalseConditions: Boolean, Ignore False Conditions on Result ...
|
||||
* @param separator: String, Separate Lines ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GenerateSummary(
|
||||
bool onlyCommons = false,
|
||||
bool onlyConditions = false,
|
||||
bool includeScores = true,
|
||||
bool ignoreFalseConditions = true,
|
||||
string separator = "\n" //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
string scoresStr =
|
||||
//
|
||||
"Scores: " + separator +
|
||||
"---------------" + separator +
|
||||
"Bullish: " + ToString(bullishScore) + separator +
|
||||
"Bearish: " + ToString(bearishScore) + separator +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
string commonStr = GenerateSpecifiedCommonSummary(
|
||||
this,
|
||||
separator,
|
||||
includeScores //
|
||||
);
|
||||
|
||||
//
|
||||
string conditionsStr =
|
||||
//
|
||||
//
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve nique Tag Identifier ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GetTag()
|
||||
{
|
||||
return GetTypeName(this);
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XCX121XMASHelper : public XCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XCX121XMASHelper()
|
||||
: XCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XCX121XMASHelper()
|
||||
{
|
||||
//
|
||||
mInputs.Clean();
|
||||
|
||||
//
|
||||
Clean(upperBuffer);
|
||||
Clean(midBuffer);
|
||||
Clean(lowerBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
X121XMASInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
ArraySetAsSeries(upperBuffer, true);
|
||||
ArraySetAsSeries(midBuffer, true);
|
||||
ArraySetAsSeries(lowerBuffer, true);
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x121.xmas",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Market ...
|
||||
"",
|
||||
mInputs.length,
|
||||
mInputs.method,
|
||||
mInputs.upperAppliedTo,
|
||||
mInputs.midAppliedTo,
|
||||
mInputs.lowerAppliedTo,
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
//
|
||||
mInputs.startCalculationForLastBars,
|
||||
//
|
||||
mInputs.showUpper,
|
||||
mInputs.showMid,
|
||||
mInputs.showLower
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
X121XMASInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
X121XMASInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Readers ...
|
||||
|
||||
//
|
||||
// Upper ...
|
||||
|
||||
//
|
||||
double GetUpper(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate(barIndex);
|
||||
|
||||
//
|
||||
int count = ArraySize(upperBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return upperBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
int CopyUpper(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate(start);
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
0,
|
||||
count,
|
||||
upperBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
|
||||
//
|
||||
double GetUMid(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate(barIndex);
|
||||
|
||||
//
|
||||
int count = ArraySize(midBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return midBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
int CopyMid(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate(start);
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
0,
|
||||
count,
|
||||
midBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Lower ...
|
||||
|
||||
//
|
||||
double GetULower(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate(barIndex);
|
||||
|
||||
//
|
||||
int count = ArraySize(lowerBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return lowerBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
int CopyLower(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate(start);
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
0,
|
||||
count,
|
||||
lowerBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
void Free() override
|
||||
{
|
||||
Cleanup(10);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
X121XMASConditions &conditions, //
|
||||
int barIndex = 0, //
|
||||
int loopback = 5 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
if (loopback < 5)
|
||||
{
|
||||
loopback = 5;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.Clean();
|
||||
|
||||
//
|
||||
conditions.symbol = mSymbol;
|
||||
conditions.period = mPeriod;
|
||||
conditions.time = TimeCurrent();
|
||||
|
||||
//
|
||||
int zIndex = barIndex;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
result = zBar.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
zIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL cBar;
|
||||
result = cBar.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
cIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL pBar;
|
||||
result = pBar.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
pIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
CopyUpper(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.upperBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
CopyMid(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.midBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
CopyLower(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.lowerBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
int cIDX = 1;
|
||||
int pIDX = cIDX + 1;
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
|
||||
//
|
||||
Cleanup();
|
||||
|
||||
//
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
X121XMASInputs mInputs; // Inputs ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double upperBuffer[];
|
||||
double midBuffer[];
|
||||
double lowerBuffer[];
|
||||
|
||||
//
|
||||
void Calculate(
|
||||
int barIndex = 0,
|
||||
int maxRequiredBars = 100 //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Buffers ...
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
X121_XMAS_UPPER_LINE,
|
||||
barIndex,
|
||||
maxRequiredBars,
|
||||
upperBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// FAST STATE ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
X121_XMAS_MID_LINE,
|
||||
barIndex,
|
||||
maxRequiredBars,
|
||||
midBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// MID ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
X121_XMAS_LOWER_LINE,
|
||||
barIndex,
|
||||
maxRequiredBars,
|
||||
lowerBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
void Cleanup(
|
||||
int maxAllowed = 100 //
|
||||
)
|
||||
{
|
||||
//
|
||||
CleanupArray(
|
||||
upperBuffer,
|
||||
maxAllowed //
|
||||
);
|
||||
|
||||
//
|
||||
CleanupArray(
|
||||
midBuffer,
|
||||
maxAllowed //
|
||||
);
|
||||
|
||||
//
|
||||
CleanupArray(
|
||||
lowerBuffer,
|
||||
maxAllowed //
|
||||
);
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,659 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XWZ
|
||||
// Description: XWZ ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121 XWZ Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121_X3MA"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int fastMALength = 20; // Fast MA Length
|
||||
input int midMALength = 50; // Mid MA Length
|
||||
input int slowMALength = 200; // Slow MA Length
|
||||
input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method
|
||||
input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
input bool showMaFast = true; // Show Fast MA
|
||||
input bool showMaMid = true; // Show Mid MA
|
||||
input bool showMaSlow = true; // Show Slow MA
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 9
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
#define maFastBufferIndex 0
|
||||
double maFastBuffer[];
|
||||
|
||||
#define maFastColorBufferIndex 1
|
||||
double maFastColorBuffer[];
|
||||
|
||||
//
|
||||
#define maFastPlotBufferIndex 0
|
||||
#property indicator_label1 "X121 MAF"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 CLR_NONE, clrAqua, clrMagenta, clrGray
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 2
|
||||
|
||||
//
|
||||
// MID ...
|
||||
#define maMidBufferIndex 2
|
||||
double maMidBuffer[];
|
||||
|
||||
#define maMidColorBufferIndex 3
|
||||
double maMidColorBuffer[];
|
||||
|
||||
//
|
||||
#define maMidPlotBufferIndex 1
|
||||
#property indicator_label2 "X121 MAM"
|
||||
#property indicator_type2 DRAW_COLOR_LINE
|
||||
#property indicator_color2 CLR_NONE, clrGreen, clrRed, clrGray
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 2
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
#define maSlowBufferIndex 4
|
||||
double maSlowBuffer[];
|
||||
|
||||
#define maSlowColorBufferIndex 5
|
||||
double maSlowColorBuffer[];
|
||||
|
||||
//
|
||||
#define maSlowPlotBufferIndex 2
|
||||
#property indicator_label3 "X121 MAS"
|
||||
#property indicator_type3 DRAW_COLOR_LINE
|
||||
#property indicator_color3 CLR_NONE, clrSteelBlue, clrDarkRed, clrGray
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 2
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 5;
|
||||
|
||||
//
|
||||
// Fast State ...
|
||||
#define maFastStateBufferIndex mLastBufferIndex + 1
|
||||
double maFastStateBuffer[];
|
||||
|
||||
//
|
||||
// Mid State ...
|
||||
#define maMidStateBufferIndex mLastBufferIndex + 2
|
||||
double maMidStateBuffer[];
|
||||
|
||||
//
|
||||
// Slow State ...
|
||||
#define maSlowStateBufferIndex mLastBufferIndex + 3
|
||||
double maSlowStateBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int maFastHandler = INVALID_HANDLE;
|
||||
int maMidHandler = INVALID_HANDLE;
|
||||
int maSlowHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// Fast MA ...
|
||||
maFastHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
fastMALength,
|
||||
0,
|
||||
maMethod,
|
||||
maAppliedTo //
|
||||
);
|
||||
bool isInited = maFastHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Mid MA ...
|
||||
maMidHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
midMALength,
|
||||
0,
|
||||
maMethod,
|
||||
maAppliedTo //
|
||||
);
|
||||
isInited = maMidHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Slow MA ...
|
||||
maSlowHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slowMALength,
|
||||
0,
|
||||
maMethod,
|
||||
maAppliedTo //
|
||||
);
|
||||
isInited = maSlowHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
IndicatorRelease(maFastHandler);
|
||||
IndicatorRelease(maMidHandler);
|
||||
IndicatorRelease(maSlowHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// Validate Calculated Bars ...
|
||||
|
||||
//
|
||||
// Fast MA ...
|
||||
int maFastCalculatedBars = BarsCalculated(maFastHandler);
|
||||
|
||||
//
|
||||
// Mid MA ...
|
||||
int maMidCalculatedBars = BarsCalculated(maMidHandler);
|
||||
|
||||
//
|
||||
// Slow MA ...
|
||||
int maSlowCalculatedBars = BarsCalculated(maSlowHandler);
|
||||
|
||||
//
|
||||
bool isPassedRequiredCalculatedBars =
|
||||
//
|
||||
// Fast MA ...
|
||||
maFastCalculatedBars >= maxLength &&
|
||||
//
|
||||
// Slow MA ...
|
||||
maMidCalculatedBars >= maxLength &&
|
||||
//
|
||||
// Slow MA ...
|
||||
maSlowCalculatedBars >= maxLength
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCalculatedBars)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
|
||||
//
|
||||
// Fast MA ...
|
||||
int copiedFastMas = CopyBuffer(maFastHandler, 0, 0, limit, maFastBuffer);
|
||||
|
||||
//
|
||||
// Mid MA ...
|
||||
int copiedMidMas = CopyBuffer(maMidHandler, 0, 0, limit, maMidBuffer);
|
||||
|
||||
//
|
||||
// Slow MA ...
|
||||
int copiedSlowMas = CopyBuffer(maSlowHandler, 0, 0, limit, maSlowBuffer);
|
||||
|
||||
//
|
||||
// Validate Copied Items ...
|
||||
bool isPassedRequiredCopiedItems =
|
||||
//
|
||||
// Fast MA ...
|
||||
copiedFastMas > 0 &&
|
||||
//
|
||||
// Mid MA ...
|
||||
copiedMidMas > 0 &&
|
||||
//
|
||||
// Slow MA ...
|
||||
copiedSlowMas > 0
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCopiedItems)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
//
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = fastMALength > 0 &&
|
||||
midMALength > 0 &&
|
||||
slowMALength > 0 &&
|
||||
midMALength > fastMALength &&
|
||||
slowMALength > midMALength;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(fastMALength, midMALength);
|
||||
result = MathMax(result, slowMALength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// Fast ...
|
||||
ArraySetAsSeries(maFastBuffer, true);
|
||||
ArraySetAsSeries(maFastColorBuffer, true);
|
||||
SetIndexBuffer(maFastBufferIndex, maFastBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(maFastColorBufferIndex, maFastColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
ArraySetAsSeries(maMidBuffer, true);
|
||||
ArraySetAsSeries(maMidColorBuffer, true);
|
||||
SetIndexBuffer(maMidBufferIndex, maMidBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(maMidColorBufferIndex, maMidColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Slow ...
|
||||
ArraySetAsSeries(maSlowBuffer, true);
|
||||
ArraySetAsSeries(maSlowColorBuffer, true);
|
||||
SetIndexBuffer(maSlowBufferIndex, maSlowBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(maSlowColorBufferIndex, maSlowColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
// Fast State ...
|
||||
ArraySetAsSeries(maFastStateBuffer, true);
|
||||
SetIndexBuffer(maFastStateBufferIndex, maFastStateBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Mid State ...
|
||||
ArraySetAsSeries(maMidStateBuffer, true);
|
||||
SetIndexBuffer(maMidStateBufferIndex, maMidStateBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Slow State ...
|
||||
ArraySetAsSeries(maSlowStateBuffer, true);
|
||||
SetIndexBuffer(maSlowStateBufferIndex, maSlowStateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Custom Buffers ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int barsLimit = startCalculationForLastBars > 0
|
||||
? startCalculationForLastBars
|
||||
: 0;
|
||||
//
|
||||
// bool canCalculate = true;
|
||||
bool canCalculate =
|
||||
barsLimit == 0 ||
|
||||
bar_index <= barsLimit;
|
||||
if (canCalculate)
|
||||
{
|
||||
//
|
||||
CalculateValues(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBuffersZero(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
maMidBuffer[barIndex] = 0;
|
||||
maFastBuffer[barIndex] = 0;
|
||||
maSlowBuffer[barIndex] = 0;
|
||||
|
||||
//
|
||||
maFastColorBuffer[barIndex] = hideColorIDX;
|
||||
maMidColorBuffer[barIndex] = hideColorIDX;
|
||||
maSlowColorBuffer[barIndex] = hideColorIDX;
|
||||
maFastStateBuffer[barIndex] = hideColorIDX;
|
||||
maMidStateBuffer[barIndex] = hideColorIDX;
|
||||
maSlowStateBuffer[barIndex] = hideColorIDX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Vales ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateValues(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Implement Colorify Mechanism ...
|
||||
|
||||
//
|
||||
// Calculate Applied Price ...
|
||||
ENUM_X_PRICE mPType = ToXPrice(maAppliedTo);
|
||||
double iPrice = GetAppliedPrice(
|
||||
mPType,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
|
||||
//
|
||||
double iFast = maFastBuffer[bar_index];
|
||||
double iMid = maMidBuffer[bar_index];
|
||||
double iSlow = maSlowBuffer[bar_index];
|
||||
|
||||
//
|
||||
double iFastState = iPrice > iFast
|
||||
? bullishColorIDX
|
||||
: iPrice < iFast
|
||||
? bearishColorIDX
|
||||
: neuturalColorIDX;
|
||||
double iMidState = iPrice > iMid
|
||||
? bullishColorIDX
|
||||
: iPrice < iMid
|
||||
? bearishColorIDX
|
||||
: neuturalColorIDX;
|
||||
double iSlowState = iPrice > iSlow
|
||||
? bullishColorIDX
|
||||
: iPrice < iSlow
|
||||
? bearishColorIDX
|
||||
: neuturalColorIDX;
|
||||
|
||||
//
|
||||
maFastColorBuffer[bar_index] =
|
||||
showMaFast
|
||||
? iFastState
|
||||
: hideColorIDX;
|
||||
maFastStateBuffer[bar_index] = iFastState;
|
||||
|
||||
//
|
||||
maMidColorBuffer[bar_index] =
|
||||
showMaMid
|
||||
? iMidState
|
||||
: hideColorIDX;
|
||||
maMidStateBuffer[bar_index] = iMidState;
|
||||
|
||||
//
|
||||
maSlowColorBuffer[bar_index] =
|
||||
showMaSlow
|
||||
? iSlowState
|
||||
: hideColorIDX;
|
||||
maSlowStateBuffer[bar_index] = iSlowState;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,882 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XATR
|
||||
// Description: XATR ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121 XATR Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121 XATR"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
|
||||
//
|
||||
input group "RSI Detection";
|
||||
input int rsiLength = 14; // Length
|
||||
input ENUM_X_PRICE rsiPriceType = X_PRICE_CLOSE; // Applied To
|
||||
input ENUM_X_MA_METHOD rsiSmoothingMethod = X_MA_MODE_SMA; // Smoothing Method;
|
||||
|
||||
//
|
||||
input group "ATR Detection";
|
||||
input int atrLength = 14; // Length
|
||||
input double atrMultiplier = 1; // Multiplier
|
||||
input ENUM_X_PRICE atrUpperPriceType = X_PRICE_HIGH; // Upper Zone Applied To
|
||||
input ENUM_X_PRICE atrLowerPriceType = X_PRICE_LOW; // Lower Zone Applied To
|
||||
input ENUM_X_MA_METHOD atrSmoothingMethod = X_MA_MODE_SMA; // Smoothing Method
|
||||
|
||||
//
|
||||
input group "Price Change";
|
||||
input int priceChangeSmoothingLength = 14; // Length
|
||||
input ENUM_X_PRICE priceChangeType = X_PRICE_CLOSE; // Price Type
|
||||
input ENUM_X_MA_METHOD priceChangeSmoothingMethod = X_MA_MODE_SMA; // Moving Average Moethod
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
|
||||
//
|
||||
input bool showAtrUpper = true; // Show Upper Zone
|
||||
input bool showAtrLower = true; // Show Lower Zone
|
||||
input bool showSmoothedAtrUpper = true; // Show Smoothed Upper Zone
|
||||
input bool showSmoothedAtrLower = true; // Show Smoothed Lower Zone
|
||||
input bool showRSIChange = true; // Show RSI Change
|
||||
input bool showSmoothedRSIChange = true; // ShowSmoothed RSI Change
|
||||
input bool showPriceChange = true; // Show Price Change
|
||||
input bool showSmoothedPriceChange = true; // ShowSmoothed Price Change
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 10
|
||||
#property indicator_plots 8
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
|
||||
//
|
||||
// Upper ...
|
||||
|
||||
//
|
||||
#define atrUpperBufferIndex 0
|
||||
double atrUpperBuffer[];
|
||||
|
||||
#property indicator_label1 "X121 ATRU"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrYellow
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// Lower ...
|
||||
|
||||
//
|
||||
#define atrLowerBufferIndex 1
|
||||
double atrLowerBuffer[];
|
||||
|
||||
#property indicator_label2 "X121 ATRL"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrYellow
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// ATR Smoothed ...
|
||||
|
||||
//
|
||||
// Upper ...
|
||||
|
||||
//
|
||||
#define atrSmoothedUpperBufferIndex 2
|
||||
double atrSmoothedUpperBuffer[];
|
||||
|
||||
#property indicator_label3 "X121 ATRUSM"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrYellow
|
||||
#property indicator_style3 STYLE_DASH
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Lower ...
|
||||
|
||||
//
|
||||
#define atrSmoothedLowerBufferIndex 3
|
||||
double atrSmoothedLowerBuffer[];
|
||||
|
||||
#property indicator_label4 "X121 ATRLSM"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrYellow
|
||||
#property indicator_style4 STYLE_DASH
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// Price Change ...
|
||||
|
||||
//
|
||||
#define priceChangeBufferIndex 4
|
||||
double priceChangeBuffer[];
|
||||
|
||||
#property indicator_label5 "X121 PCH"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrOrchid
|
||||
#property indicator_style5 STYLE_SOLID
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
// Price Change Smoothed ...
|
||||
|
||||
//
|
||||
#define priceChangeSmoothedBufferIndex 5
|
||||
double priceChangeSmoothedBuffer[];
|
||||
|
||||
#property indicator_label6 "X121 PCHSM"
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_color6 clrOrchid
|
||||
#property indicator_style6 STYLE_SOLID
|
||||
#property indicator_width6 1
|
||||
|
||||
//
|
||||
// RSI Change ...
|
||||
|
||||
//
|
||||
#define rsiChangeBufferIndex 6
|
||||
double rsiChangeBuffer[];
|
||||
|
||||
#property indicator_label7 "X121 RSICH"
|
||||
#property indicator_type7 DRAW_LINE
|
||||
#property indicator_color7 clrCornflowerBlue
|
||||
#property indicator_style7 STYLE_SOLID
|
||||
#property indicator_width7 1
|
||||
|
||||
//
|
||||
// RSI Change Smoothed ...
|
||||
|
||||
//
|
||||
#define rsiChangeSmoothedBufferIndex 7
|
||||
double rsiChangeSmoothedBuffer[];
|
||||
|
||||
#property indicator_label8 "X121 RSICHSM"
|
||||
#property indicator_type8 DRAW_LINE
|
||||
#property indicator_color8 clrCornflowerBlue
|
||||
#property indicator_style8 STYLE_SOLID
|
||||
#property indicator_width8 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 7;
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
|
||||
#define atrBufferIndex mLastBufferIndex + 1
|
||||
double atrBuffer[];
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
#define rsiBufferIndex mLastBufferIndex + 2
|
||||
double rsiBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// RSI Handler ...
|
||||
int rsiHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// ATR Handler ...
|
||||
int atrHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
ENUM_APPLIED_PRICE rsiAppliedTo = ToAppliedPrice(rsiPriceType);
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
rsiHandler = iRSI(
|
||||
_Symbol,
|
||||
_Period,
|
||||
rsiLength,
|
||||
rsiAppliedTo //
|
||||
);
|
||||
bool isInited = rsiHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
atrHandler = iATR(
|
||||
_Symbol,
|
||||
_Period,
|
||||
atrLength //
|
||||
);
|
||||
isInited = atrHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
IndicatorRelease(rsiHandler);
|
||||
IndicatorRelease(atrHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// Fill All Buffers by Zero ...
|
||||
if (prev_calculated == 0)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Calculated Bars ...
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
int rsiCalculatedBars = BarsCalculated(rsiHandler);
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
int atrCalculatedBars = BarsCalculated(atrHandler);
|
||||
|
||||
//
|
||||
bool isPassedRequiredCalculatedBars =
|
||||
//
|
||||
// RSI ...
|
||||
rsiCalculatedBars >= maxLength &&
|
||||
//
|
||||
// ATR ...
|
||||
atrCalculatedBars >= maxLength
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCalculatedBars)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
int copiedRsis = CopyBuffer(rsiHandler, 0, 0, limit, rsiBuffer);
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
int copiedAtrs = CopyBuffer(atrHandler, 0, 0, limit, atrBuffer);
|
||||
|
||||
//
|
||||
// Validate Copied Items ...
|
||||
bool isPassedRequiredCopiedItems =
|
||||
//
|
||||
//
|
||||
// RSI ...
|
||||
copiedRsis > 0 &&
|
||||
//
|
||||
// ATR ...
|
||||
copiedAtrs > 0
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCopiedItems)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
// RSI ...
|
||||
rsiLength > 0 &&
|
||||
//
|
||||
// ATR ...
|
||||
atrLength > 0 &&
|
||||
atrMultiplier > 0 &&
|
||||
//
|
||||
priceChangeSmoothingLength > 0 &&
|
||||
//
|
||||
IsValid(rsiPriceType) &&
|
||||
IsValid(priceChangeType) &&
|
||||
IsValid(atrUpperPriceType) &&
|
||||
IsValid(atrLowerPriceType)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(rsiLength, atrLength);
|
||||
result = MathMax(result, priceChangeSmoothingLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// ATR ...
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
ENUM_DRAW_TYPE atrUpperDrawType = showAtrUpper ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(atrUpperBuffer, true);
|
||||
SetIndexBuffer(atrUpperBufferIndex, atrUpperBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(atrUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(atrUpperBufferIndex, PLOT_SHOW_DATA, showAtrUpper);
|
||||
PlotIndexSetInteger(atrUpperBufferIndex, PLOT_DRAW_TYPE, atrUpperDrawType);
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
ENUM_DRAW_TYPE atrLowerDrawType = showAtrLower ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(atrLowerBuffer, true);
|
||||
SetIndexBuffer(atrLowerBufferIndex, atrLowerBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(atrLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(atrLowerBufferIndex, PLOT_SHOW_DATA, showAtrLower);
|
||||
PlotIndexSetInteger(atrLowerBufferIndex, PLOT_DRAW_TYPE, atrLowerDrawType);
|
||||
|
||||
//
|
||||
// ATR Smoothed ...
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
ENUM_DRAW_TYPE atrSmoothedUpperDrawType = showSmoothedAtrUpper ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(atrSmoothedUpperBuffer, true);
|
||||
SetIndexBuffer(atrSmoothedUpperBufferIndex, atrSmoothedUpperBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(atrSmoothedUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(atrSmoothedUpperBufferIndex, PLOT_SHOW_DATA, showSmoothedAtrUpper);
|
||||
PlotIndexSetInteger(atrSmoothedUpperBufferIndex, PLOT_DRAW_TYPE, atrSmoothedUpperDrawType);
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
ENUM_DRAW_TYPE atrSmoothedLowerDrawType = showSmoothedAtrLower ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(atrSmoothedLowerBuffer, true);
|
||||
SetIndexBuffer(atrSmoothedLowerBufferIndex, atrSmoothedLowerBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(atrSmoothedLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(atrSmoothedLowerBufferIndex, PLOT_SHOW_DATA, showSmoothedAtrLower);
|
||||
PlotIndexSetInteger(atrSmoothedLowerBufferIndex, PLOT_DRAW_TYPE, atrSmoothedLowerDrawType);
|
||||
|
||||
//
|
||||
// PriceChange ...
|
||||
ENUM_DRAW_TYPE priceChangeDrawType = showPriceChange ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(priceChangeBuffer, true);
|
||||
SetIndexBuffer(priceChangeBufferIndex, priceChangeBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(priceChangeBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(priceChangeBufferIndex, PLOT_SHOW_DATA, showPriceChange);
|
||||
PlotIndexSetInteger(priceChangeBufferIndex, PLOT_DRAW_TYPE, priceChangeDrawType);
|
||||
|
||||
//
|
||||
// PriceChange Smoothed ...
|
||||
ENUM_DRAW_TYPE priceChangeSmoothedaDrawType = showSmoothedPriceChange ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(priceChangeSmoothedBuffer, true);
|
||||
SetIndexBuffer(priceChangeSmoothedBufferIndex, priceChangeSmoothedBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(priceChangeSmoothedBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(priceChangeSmoothedBufferIndex, PLOT_SHOW_DATA, showSmoothedPriceChange);
|
||||
PlotIndexSetInteger(priceChangeSmoothedBufferIndex, PLOT_DRAW_TYPE, priceChangeSmoothedaDrawType);
|
||||
|
||||
//
|
||||
// RSIChange ...
|
||||
ENUM_DRAW_TYPE rsiChangeDrawType = showRSIChange ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(rsiChangeBuffer, true);
|
||||
SetIndexBuffer(rsiChangeBufferIndex, rsiChangeBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(rsiChangeBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(rsiChangeBufferIndex, PLOT_SHOW_DATA, showRSIChange);
|
||||
PlotIndexSetInteger(rsiChangeBufferIndex, PLOT_DRAW_TYPE, rsiChangeDrawType);
|
||||
|
||||
//
|
||||
// RSIChangeMa ...
|
||||
ENUM_DRAW_TYPE rsiChangeMaDrawType = showSmoothedRSIChange ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(rsiChangeSmoothedBuffer, true);
|
||||
SetIndexBuffer(rsiChangeSmoothedBufferIndex, rsiChangeSmoothedBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(rsiChangeSmoothedBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(rsiChangeSmoothedBufferIndex, PLOT_SHOW_DATA, showSmoothedRSIChange);
|
||||
PlotIndexSetInteger(rsiChangeSmoothedBufferIndex, PLOT_DRAW_TYPE, rsiChangeMaDrawType);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
ArraySetAsSeries(atrBuffer, true);
|
||||
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
ArraySetAsSeries(rsiBuffer, true);
|
||||
SetIndexBuffer(rsiBufferIndex, rsiBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Custom Buffers ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int barsLimit = startCalculationForLastBars > 0
|
||||
? startCalculationForLastBars
|
||||
: 0;
|
||||
//
|
||||
// bool canCalculate = true;
|
||||
bool canCalculate =
|
||||
barsLimit == 0 ||
|
||||
bar_index <= barsLimit;
|
||||
if (canCalculate)
|
||||
{
|
||||
//
|
||||
CalculateAtrZones(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBuffersZero(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Custom ...
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
rsiBuffer[barIndex] = 0;
|
||||
atrBuffer[barIndex] = 0;
|
||||
atrUpperBuffer[barIndex] = 0;
|
||||
atrLowerBuffer[barIndex] = 0;
|
||||
rsiChangeBuffer[barIndex] = 0;
|
||||
priceChangeBuffer[barIndex] = 0;
|
||||
atrSmoothedUpperBuffer[barIndex] = 0;
|
||||
atrSmoothedLowerBuffer[barIndex] = 0;
|
||||
rsiChangeSmoothedBuffer[barIndex] = 0;
|
||||
priceChangeSmoothedBuffer[barIndex] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate ATR Zones ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
*/
|
||||
void CalculateAtrZones(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
double points = GetPoints(_Symbol);
|
||||
|
||||
//
|
||||
// ATR Calculations ...
|
||||
double iAtr = atrBuffer[bar_index];
|
||||
double iMultiPliedAtr = iAtr * atrMultiplier;
|
||||
|
||||
//
|
||||
// Select Upper Price ...
|
||||
double iUpperPrice = GetAppliedPrice(
|
||||
atrUpperPriceType,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
|
||||
//
|
||||
// Select Lower Price ...
|
||||
double iLowerPrice = GetAppliedPrice(
|
||||
atrLowerPriceType,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Atrs ...
|
||||
|
||||
//
|
||||
double iAtrUpper = iUpperPrice + iMultiPliedAtr;
|
||||
double iAtrLower = iLowerPrice - iMultiPliedAtr;
|
||||
|
||||
//
|
||||
atrUpperBuffer[bar_index] = iAtrUpper;
|
||||
atrLowerBuffer[bar_index] = iAtrLower;
|
||||
|
||||
//
|
||||
bool canSmoothAtr = atrSmoothingMethod != X_MA_MODE_NONE;
|
||||
if (canSmoothAtr)
|
||||
{
|
||||
//
|
||||
// Upper ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
atrLength,
|
||||
atrUpperBuffer,
|
||||
atrSmoothedUpperBuffer,
|
||||
atrSmoothingMethod //
|
||||
);
|
||||
|
||||
//
|
||||
// Lower ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
atrLength,
|
||||
atrLowerBuffer,
|
||||
atrSmoothedLowerBuffer,
|
||||
atrSmoothingMethod //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
atrSmoothedUpperBuffer[bar_index] = iAtrUpper;
|
||||
atrSmoothedLowerBuffer[bar_index] = iAtrLower;
|
||||
}
|
||||
|
||||
//
|
||||
// RSI Change Calculations ...
|
||||
|
||||
//
|
||||
double iRsi = rsiBuffer[bar_index];
|
||||
double iRsiP = rsiBuffer[bar_index + 1];
|
||||
double iRsiPrice = GetAppliedPrice(
|
||||
rsiPriceType,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
|
||||
//
|
||||
double iRsiChanged = iRsi - iRsiP;
|
||||
double iRsiPointsChanged = iRsiChanged / points;
|
||||
|
||||
//
|
||||
double iRChange = iRsiPrice + (iRsiChanged * points);
|
||||
rsiChangeBuffer[bar_index] = iRChange;
|
||||
|
||||
//
|
||||
bool canSmoothRsi = rsiSmoothingMethod != X_MA_MODE_NONE;
|
||||
if (canSmoothRsi)
|
||||
{
|
||||
//
|
||||
// Upper ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
atrLength,
|
||||
rsiChangeBuffer,
|
||||
rsiChangeSmoothedBuffer,
|
||||
rsiSmoothingMethod //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
rsiChangeSmoothedBuffer[bar_index] = iRChange;
|
||||
}
|
||||
|
||||
//
|
||||
// PRICE Change Calculation ...
|
||||
|
||||
//
|
||||
double iPChangePrice = GetAppliedPrice(
|
||||
priceChangeType,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
double iPPChangePrice = GetAppliedPrice(
|
||||
priceChangeType,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index + 1 //
|
||||
);
|
||||
|
||||
//
|
||||
double iPriceChange = iPChangePrice - iPPChangePrice;
|
||||
double iPricePointsChanged = iPriceChange / points;
|
||||
double iVolatilityChange = iPriceChange / iAtr;
|
||||
|
||||
//
|
||||
double iPChange = iPChangePrice + (iPricePointsChanged * points);
|
||||
priceChangeBuffer[bar_index] = iPChange;
|
||||
|
||||
//
|
||||
bool canSmoothPriceChange = priceChangeSmoothingMethod != X_MA_MODE_NONE;
|
||||
if (canSmoothPriceChange)
|
||||
{
|
||||
//
|
||||
// Upper ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
atrLength,
|
||||
priceChangeBuffer,
|
||||
priceChangeSmoothedBuffer,
|
||||
priceChangeSmoothingMethod //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
priceChangeSmoothedBuffer[bar_index] = iPChange;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,437 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Candle Styles
|
||||
// ---------------------------------------------------
|
||||
// Name: X121 XCC
|
||||
// Description: Candle Styles ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121 XCC Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "X121 XCC"
|
||||
|
||||
//
|
||||
// Holds an SnapShot of Charts Configuration ...
|
||||
struct XChartStyle
|
||||
{
|
||||
//
|
||||
// chart's ID ...
|
||||
long chartId;
|
||||
//
|
||||
// chart's mode ...
|
||||
ENUM_CHART_MODE mode;
|
||||
//
|
||||
// show bid line ...
|
||||
bool showBidLine;
|
||||
//
|
||||
// show ask line ...
|
||||
bool showAskLine;
|
||||
//
|
||||
// show grids on chart ...
|
||||
bool showGrid;
|
||||
//
|
||||
// show volumes ...
|
||||
bool showVolumes;
|
||||
//
|
||||
// Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders) ...
|
||||
bool showTradeLevels;
|
||||
//
|
||||
// chart autoscroll ...
|
||||
bool autoScroll;
|
||||
//
|
||||
// chart quick navigation state ...
|
||||
bool quickNavigation;
|
||||
//
|
||||
// chart's foreground color ...
|
||||
color foreGroundColor;
|
||||
//
|
||||
// chart's background color ...
|
||||
color backGroundColor;
|
||||
//
|
||||
// Up Color ...
|
||||
color upColor;
|
||||
//
|
||||
// Down Color ...
|
||||
color downColor;
|
||||
//
|
||||
// Bullish color ...
|
||||
color bullishColor;
|
||||
//
|
||||
// Bearish color ...
|
||||
color bearishColor;
|
||||
//
|
||||
// grid color ...
|
||||
color gridColor;
|
||||
//
|
||||
// bid line color ...
|
||||
color bidLineColor;
|
||||
//
|
||||
// ask line color ...
|
||||
color askLineColor;
|
||||
//
|
||||
// line mode and doji candlestick color ...
|
||||
color lineColor;
|
||||
//
|
||||
// Color of stop order levels (Stop Loss and Take Profit) ...
|
||||
color stopColor;
|
||||
//
|
||||
// volumes color ...
|
||||
color volumesColor;
|
||||
};
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Chart Style";
|
||||
input ENUM_CHART_MODE mode = CHART_CANDLES; // Mode
|
||||
input color upColor = clrGreen; // Up Color
|
||||
input color downColor = clrRed; // Down Color
|
||||
input color lineColor = clrGreen; // Line mode and Doji candlestick Color
|
||||
input color bullishColor = clrGreen; // Bullish Color
|
||||
input color bearishColor = clrRed; // Bearish Color
|
||||
input color volumesColor = clrGreen; // Volumes Color
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showCandles = true; // Show Candles
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Draw Library ...
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 0
|
||||
#property indicator_plots 0
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
XChartStyle chartStyle;
|
||||
XChartStyle clearStyle;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Apply Chart Style ...
|
||||
ApplyCustomChartStyle();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index // Selected Bar Index
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Apply Custom Chart Style ...
|
||||
void ApplyCustomChartStyle()
|
||||
{
|
||||
//
|
||||
// Read Current Chart Config and Store it ...
|
||||
ReadChartStyle();
|
||||
|
||||
//
|
||||
// After Reading Current Chart Style ...
|
||||
// we have to Save Configs and Change Styles ...
|
||||
clearStyle = chartStyle;
|
||||
|
||||
//
|
||||
clearStyle.upColor = CLR_NONE;
|
||||
clearStyle.downColor = CLR_NONE;
|
||||
clearStyle.lineColor = CLR_NONE;
|
||||
clearStyle.bullishColor = CLR_NONE;
|
||||
clearStyle.bearishColor = CLR_NONE;
|
||||
|
||||
//
|
||||
// Decide to Show or not Candles based on User Input ...
|
||||
if (showCandles)
|
||||
{
|
||||
SetChartStyle(chartStyle);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetChartStyle(clearStyle);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Read Previous Chart Style ...
|
||||
void ReadChartStyle()
|
||||
{
|
||||
//
|
||||
// Retrieve Current Chart ID ...
|
||||
long chartId = ChartID();
|
||||
chartStyle.chartId = chartId;
|
||||
|
||||
//
|
||||
// Retrieve Chart Mode ...
|
||||
chartStyle.mode = (ENUM_CHART_MODE)ChartGetInteger(chartId, CHART_MODE);
|
||||
|
||||
//
|
||||
chartStyle.showBidLine = (bool)ChartGetInteger(chartId, CHART_SHOW_BID_LINE);
|
||||
chartStyle.showAskLine = (bool)ChartGetInteger(chartId, CHART_SHOW_ASK_LINE);
|
||||
chartStyle.showGrid = (bool)ChartGetInteger(chartId, CHART_SHOW_GRID);
|
||||
chartStyle.showVolumes = (bool)ChartGetInteger(chartId, CHART_SHOW_VOLUMES);
|
||||
chartStyle.showTradeLevels = (bool)ChartGetInteger(chartId, CHART_SHOW_TRADE_LEVELS);
|
||||
chartStyle.autoScroll = (bool)ChartGetInteger(chartId, CHART_AUTOSCROLL);
|
||||
chartStyle.quickNavigation = (bool)ChartGetInteger(chartId, CHART_QUICK_NAVIGATION);
|
||||
|
||||
//
|
||||
chartStyle.foreGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_FOREGROUND);
|
||||
chartStyle.backGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_BACKGROUND);
|
||||
chartStyle.upColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_UP);
|
||||
chartStyle.downColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_DOWN);
|
||||
chartStyle.bullishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BULL);
|
||||
chartStyle.bearishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BEAR);
|
||||
chartStyle.gridColor = (color)ChartGetInteger(chartId, CHART_COLOR_GRID);
|
||||
chartStyle.bidLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_BID);
|
||||
chartStyle.askLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_ASK);
|
||||
chartStyle.stopColor = (color)ChartGetInteger(chartId, CHART_COLOR_STOP_LEVEL);
|
||||
chartStyle.lineColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_LINE);
|
||||
chartStyle.volumesColor = (color)ChartGetInteger(chartId, CHART_COLOR_VOLUME);
|
||||
|
||||
//
|
||||
chartStyle.mode = mode;
|
||||
chartStyle.upColor = upColor;
|
||||
chartStyle.downColor = downColor;
|
||||
chartStyle.lineColor = lineColor;
|
||||
chartStyle.bearishColor = bearishColor;
|
||||
chartStyle.bullishColor = bullishColor;
|
||||
chartStyle.volumesColor = volumesColor;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Chart Style ...
|
||||
void SetChartStyle(
|
||||
XChartStyle &mChartStyle // Chart Style to Apply
|
||||
)
|
||||
{
|
||||
//
|
||||
ApplyChartStyle(
|
||||
mChartStyle.chartId,
|
||||
mChartStyle.mode,
|
||||
mChartStyle.showBidLine,
|
||||
mChartStyle.showAskLine,
|
||||
mChartStyle.showGrid,
|
||||
mChartStyle.showVolumes,
|
||||
mChartStyle.showTradeLevels,
|
||||
mChartStyle.autoScroll,
|
||||
mChartStyle.quickNavigation,
|
||||
mChartStyle.foreGroundColor,
|
||||
mChartStyle.backGroundColor,
|
||||
mChartStyle.upColor,
|
||||
mChartStyle.downColor,
|
||||
mChartStyle.bullishColor,
|
||||
mChartStyle.bearishColor,
|
||||
mChartStyle.gridColor,
|
||||
mChartStyle.bidLineColor,
|
||||
mChartStyle.askLineColor,
|
||||
mChartStyle.lineColor,
|
||||
mChartStyle.stopColor,
|
||||
mChartStyle.volumesColor);
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,624 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XCHE
|
||||
// Description: XCHE ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121 XCHE Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121 XCHE"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int cheLength = 35; // Length
|
||||
input int cheLoopback = 26; // Loopback
|
||||
input double cheMultiplier1 = 3.0; // 1st Multiplier
|
||||
input double cheMultiplier2 = 3.5; // 2nd Multiplier
|
||||
input ENUM_APPLIED_PRICE cheUpperAppliedTo = PRICE_HIGH; // Upper Zone Applied to
|
||||
input ENUM_APPLIED_PRICE cheLowerAppliedTo = PRICE_LOW; // Lower Zone Applied to
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input int cheArrowCode = 159; // CHE Arrow Code
|
||||
|
||||
//
|
||||
input bool showLE1 = true; // Show 1st Long Exit
|
||||
input bool showSE1 = true; // Show 1st Short Exit
|
||||
input bool showLE2 = true; // Show 2st Long Exit
|
||||
input bool showSE2 = true; // Show 2st Short Exit
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 8
|
||||
#property indicator_plots 8
|
||||
|
||||
//
|
||||
// Exit 1 ...
|
||||
|
||||
//
|
||||
// LONG ...
|
||||
|
||||
//
|
||||
#define le1BufferIndex 0
|
||||
double le1Buffer[];
|
||||
|
||||
#property indicator_label1 "X121 LE1"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrAqua
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// SHORT ...
|
||||
|
||||
//
|
||||
#define se1BufferIndex 1
|
||||
double se1Buffer[];
|
||||
|
||||
#property indicator_label2 "X121 SE1"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrMagenta
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Exit 2 ...
|
||||
|
||||
//
|
||||
// LONG ...
|
||||
|
||||
//
|
||||
#define le2BufferIndex 2
|
||||
double le2Buffer[];
|
||||
|
||||
#property indicator_label3 "X121 LE2"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrAqua
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// SHORT ...
|
||||
|
||||
//
|
||||
#define se2BufferIndex 3
|
||||
double se2Buffer[];
|
||||
|
||||
#property indicator_label4 "X121 SE2"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrMagenta
|
||||
#property indicator_style4 STYLE_SOLID
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// Start Buffers ...
|
||||
|
||||
//
|
||||
#define le1StartBufferIndex 4
|
||||
double le1StartBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "X121 LE1 S"
|
||||
#property indicator_type5 DRAW_ARROW
|
||||
#property indicator_color5 clrLime
|
||||
|
||||
//
|
||||
#define se1StartBufferIndex 5
|
||||
double se1StartBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "X121 SE1 S"
|
||||
#property indicator_type6 DRAW_ARROW
|
||||
#property indicator_color6 clrRed
|
||||
|
||||
//
|
||||
#define le2StartBufferIndex 6
|
||||
double le2StartBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "X121 LE2 S"
|
||||
#property indicator_type7 DRAW_ARROW
|
||||
#property indicator_color7 clrLime
|
||||
|
||||
//
|
||||
#define se2StartBufferIndex 7
|
||||
double se2StartBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label8 "X121 SE2 S"
|
||||
#property indicator_type8 DRAW_ARROW
|
||||
#property indicator_color8 clrRed
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// Working Array ...
|
||||
double work[][6];
|
||||
#define hi1Idx 0
|
||||
#define lo1Idx 1
|
||||
#define hi2Idx 2
|
||||
#define lo2Idx 3
|
||||
#define trend1Idx 4
|
||||
#define trend2Idx 5
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input cheLength, here we get max Input cheLength
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
if (Bars(_Symbol, _Period) < rates_total)
|
||||
{
|
||||
return (prev_calculated);
|
||||
}
|
||||
|
||||
//
|
||||
if (ArrayRange(work, 0) != rates_total)
|
||||
{
|
||||
ArrayResize(work, rates_total);
|
||||
}
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
|
||||
//
|
||||
limit = prev_calculated - 1;
|
||||
if (limit < 0)
|
||||
{
|
||||
limit = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
result =
|
||||
cheLength >= 9 &&
|
||||
cheLoopback >= 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(cheLength, cheLoopback);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// LEVEL 1 ...
|
||||
|
||||
//
|
||||
// Long Exit 1 ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE le1DrawType = showLE1 ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE le1StartDrawType = showLE1 ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(le1BufferIndex, le1Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(le1BufferIndex, PLOT_SHOW_DATA, showLE1);
|
||||
PlotIndexSetInteger(le1BufferIndex, PLOT_DRAW_TYPE, le1DrawType);
|
||||
|
||||
//
|
||||
// Start Buffer ...
|
||||
SetIndexBuffer(le1StartBufferIndex, le1StartBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(le1StartBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(le1StartBufferIndex, PLOT_DRAW_TYPE, le1StartDrawType);
|
||||
PlotIndexSetInteger(le1StartBufferIndex, PLOT_ARROW, cheArrowCode);
|
||||
|
||||
//
|
||||
// Short Exit 1 ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE se1DrawType = showSE1 ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE se1StartDrawType = showSE1 ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(se1BufferIndex, se1Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(se1BufferIndex, PLOT_SHOW_DATA, showSE1);
|
||||
PlotIndexSetInteger(se1BufferIndex, PLOT_DRAW_TYPE, se1DrawType);
|
||||
|
||||
//
|
||||
// Start Buffer ...
|
||||
SetIndexBuffer(se1StartBufferIndex, se1StartBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(se1StartBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(se1StartBufferIndex, PLOT_DRAW_TYPE, se1StartDrawType);
|
||||
PlotIndexSetInteger(se1StartBufferIndex, PLOT_ARROW, cheArrowCode);
|
||||
|
||||
//
|
||||
// LEVEL 2 ...
|
||||
|
||||
//
|
||||
// Long Exit 2 ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE le2DrawType = showLE2 ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE le2StartDrawType = showLE2 ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(le2BufferIndex, le2Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(le2BufferIndex, PLOT_SHOW_DATA, showLE2);
|
||||
PlotIndexSetInteger(le2BufferIndex, PLOT_DRAW_TYPE, le2DrawType);
|
||||
|
||||
//
|
||||
// Start Buffer ...
|
||||
SetIndexBuffer(le2StartBufferIndex, le2StartBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(le2StartBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(le2StartBufferIndex, PLOT_DRAW_TYPE, le2StartDrawType);
|
||||
PlotIndexSetInteger(le2StartBufferIndex, PLOT_ARROW, cheArrowCode);
|
||||
|
||||
//
|
||||
// Short Exit 2 ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE se2DrawType = showSE2 ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE se2StartDrawType = showSE2 ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(se2BufferIndex, se2Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(se2BufferIndex, PLOT_SHOW_DATA, showSE2);
|
||||
PlotIndexSetInteger(se2BufferIndex, PLOT_DRAW_TYPE, se2DrawType);
|
||||
|
||||
//
|
||||
// Start Buffer ...
|
||||
SetIndexBuffer(se2StartBufferIndex, se2StartBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(se2StartBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(se2StartBufferIndex, PLOT_DRAW_TYPE, se2StartDrawType);
|
||||
PlotIndexSetInteger(se2StartBufferIndex, PLOT_ARROW, cheArrowCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Buffers ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
int prevCalculated, // Previous Calculated
|
||||
int ratesTotal, // Total Rates
|
||||
const double &open[], // Rates Open ...
|
||||
const double &high[], // Rates High ...
|
||||
const double &low[], // Rates Low ...
|
||||
const double &close[] // Rates Close ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// Cleanup Buffers ...
|
||||
le1Buffer[bar_index] = le1StartBuffer[bar_index] = se1Buffer[bar_index] = se1StartBuffer[bar_index] = EMPTY_VALUE;
|
||||
le2Buffer[bar_index] = le2StartBuffer[bar_index] = se2Buffer[bar_index] = se2StartBuffer[bar_index] = EMPTY_VALUE;
|
||||
|
||||
//
|
||||
int start = MathMax(bar_index - cheLoopback, 0);
|
||||
|
||||
//
|
||||
// Calculate ATR Value ...
|
||||
double atrValue = 0;
|
||||
for (int k = 1; k <= cheLength && (bar_index - k - 1) >= 0; k++)
|
||||
{
|
||||
//
|
||||
atrValue += MathMax(high[bar_index - k], close[MathMax(bar_index - k - 1, 0)]) -
|
||||
MathMin(low[bar_index - k], close[MathMax(bar_index - k - 1, 0)]);
|
||||
}
|
||||
atrValue /= (double)cheLength;
|
||||
|
||||
//
|
||||
// Retrieve Highest High and Lowest Lows ...
|
||||
double cheLoopbackMax = high[ArrayMaximum(high, start, cheLoopback)];
|
||||
double cheLoopbackMin = low[ArrayMinimum(low, start, cheLoopback)];
|
||||
|
||||
//
|
||||
// Fill Multi Dimesional Working Array ...
|
||||
work[bar_index][hi1Idx] = cheLoopbackMax - cheMultiplier1 * atrValue;
|
||||
work[bar_index][lo1Idx] = cheLoopbackMin + cheMultiplier1 * atrValue;
|
||||
work[bar_index][hi2Idx] = cheLoopbackMax - cheMultiplier2 * atrValue;
|
||||
work[bar_index][lo2Idx] = cheLoopbackMin + cheMultiplier2 * atrValue;
|
||||
work[bar_index][trend1Idx] = (bar_index > 0) ? work[bar_index - 1][trend1Idx] : 0;
|
||||
work[bar_index][trend2Idx] = (bar_index > 0) ? work[bar_index - 1][trend2Idx] : 0;
|
||||
|
||||
//
|
||||
if (bar_index > 0)
|
||||
{
|
||||
//
|
||||
// Calculate Trends ...
|
||||
if (close[bar_index] > work[bar_index - 1][lo1Idx])
|
||||
{
|
||||
work[bar_index][trend1Idx] = 1;
|
||||
}
|
||||
|
||||
//
|
||||
if (close[bar_index] < work[bar_index - 1][hi1Idx])
|
||||
{
|
||||
work[bar_index][trend1Idx] = -1;
|
||||
}
|
||||
|
||||
//
|
||||
if (close[bar_index] > work[bar_index - 1][lo2Idx])
|
||||
{
|
||||
work[bar_index][trend2Idx] = 1;
|
||||
}
|
||||
|
||||
//
|
||||
if (close[bar_index] < work[bar_index - 1][hi2Idx])
|
||||
{
|
||||
work[bar_index][trend2Idx] = -1;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Exit Values ...
|
||||
|
||||
//
|
||||
// Exit 1 ...
|
||||
|
||||
//
|
||||
// Long ...
|
||||
if (cheMultiplier1 > 0 && work[bar_index][trend1Idx] == 1)
|
||||
{
|
||||
//
|
||||
if (work[bar_index][hi1Idx] < work[bar_index - 1][hi1Idx])
|
||||
{
|
||||
work[bar_index][hi1Idx] = work[bar_index - 1][hi1Idx];
|
||||
}
|
||||
|
||||
//
|
||||
le1Buffer[bar_index] = work[bar_index][hi1Idx];
|
||||
|
||||
//
|
||||
if (le1Buffer[bar_index - 1] == EMPTY_VALUE)
|
||||
{
|
||||
le1StartBuffer[bar_index] = le1Buffer[bar_index];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Short ...
|
||||
if (cheMultiplier1 > 0 && work[bar_index][trend1Idx] == -1)
|
||||
{
|
||||
//
|
||||
if (work[bar_index][lo1Idx] > work[bar_index - 1][lo1Idx])
|
||||
{
|
||||
work[bar_index][lo1Idx] = work[bar_index - 1][lo1Idx];
|
||||
}
|
||||
|
||||
//
|
||||
se1Buffer[bar_index] = work[bar_index][lo1Idx];
|
||||
|
||||
//
|
||||
if (se1Buffer[bar_index - 1] == EMPTY_VALUE)
|
||||
{
|
||||
se1StartBuffer[bar_index] = se1Buffer[bar_index];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Exit 2 ...
|
||||
|
||||
//
|
||||
// Long ...
|
||||
if (cheMultiplier2 > 0 && work[bar_index][trend2Idx] == 1)
|
||||
{
|
||||
if (work[bar_index][hi2Idx] < work[bar_index - 1][hi2Idx])
|
||||
{
|
||||
work[bar_index][hi2Idx] = work[bar_index - 1][hi2Idx];
|
||||
}
|
||||
|
||||
//
|
||||
le2Buffer[bar_index] = work[bar_index][hi2Idx];
|
||||
|
||||
//
|
||||
if (le2Buffer[bar_index - 1] == EMPTY_VALUE)
|
||||
{
|
||||
le2StartBuffer[bar_index] = le2Buffer[bar_index];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Short ...
|
||||
if (cheMultiplier2 > 0 && work[bar_index][trend2Idx] == -1)
|
||||
{
|
||||
//
|
||||
if (work[bar_index][lo2Idx] > work[bar_index - 1][lo2Idx])
|
||||
{
|
||||
work[bar_index][lo2Idx] = work[bar_index - 1][lo2Idx];
|
||||
}
|
||||
|
||||
//
|
||||
se2Buffer[bar_index] = work[bar_index][lo2Idx];
|
||||
|
||||
//
|
||||
if (se2Buffer[bar_index - 1] == EMPTY_VALUE)
|
||||
{
|
||||
se2StartBuffer[bar_index] = se2Buffer[bar_index];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,262 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: X121 XCT
|
||||
// Description: Trend Magic Indicator ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121 XCT Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
#define ShortName "X121 XCT"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input int fontSize = 15; // Font Size
|
||||
input string font = "Arial"; // Font
|
||||
input color clr = clrYellow; // Text Color
|
||||
input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER; // Text Position
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showTimer = true; // Show Candle Time
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 0
|
||||
#property indicator_plots 0
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
bool isCreatedObject;
|
||||
string tag;
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
|
||||
//
|
||||
tag = ShortName + _Symbol + ToString(_Period);
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Delete Object ...
|
||||
ObjectDelete(0, tag);
|
||||
|
||||
//
|
||||
Comment("");
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
if (!showTimer)
|
||||
{
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
XBarRemainsTime barRemains;
|
||||
barRemains.Init(
|
||||
_Symbol,
|
||||
_Period
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
string msg = barRemains
|
||||
.ToString(
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
":",
|
||||
true
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
long mSpread = SymbolInfoInteger(Symbol(), SYMBOL_SPREAD);
|
||||
|
||||
//
|
||||
string _sp = "";
|
||||
if (mSpread < 10)
|
||||
_sp = "..";
|
||||
else if (mSpread < 100)
|
||||
_sp = ".";
|
||||
|
||||
//
|
||||
string objText = "Spread: " + IntegerToString(mSpread) + _sp + ", Next Bar in: " + msg;
|
||||
|
||||
//
|
||||
if (IsValid(tag) && !isCreatedObject)
|
||||
{
|
||||
CreateIndicatorObject();
|
||||
}
|
||||
|
||||
//
|
||||
if (isCreatedObject)
|
||||
{
|
||||
ObjectSetString(0, tag, OBJPROP_TEXT, objText);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
void CreateIndicatorObject()
|
||||
{
|
||||
//
|
||||
if (!showTimer ||
|
||||
!IsValid(tag))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
isCreatedObject = ObjectCreate(0, tag, OBJ_LABEL, 0, 0, 0);
|
||||
ObjectSetInteger(0, tag, OBJPROP_CORNER, corner);
|
||||
ObjectSetInteger(0, tag, OBJPROP_XDISTANCE, 10);
|
||||
ObjectSetInteger(0, tag, OBJPROP_YDISTANCE, 2);
|
||||
|
||||
//
|
||||
ENUM_ANCHOR_POINT Anchor = ANCHOR_LEFT_UPPER;
|
||||
switch (corner)
|
||||
{
|
||||
case CORNER_LEFT_UPPER:
|
||||
Anchor = ANCHOR_LEFT_UPPER;
|
||||
break;
|
||||
case CORNER_RIGHT_UPPER:
|
||||
Anchor = ANCHOR_RIGHT_UPPER;
|
||||
break;
|
||||
case CORNER_LEFT_LOWER:
|
||||
Anchor = ANCHOR_LEFT_LOWER;
|
||||
break;
|
||||
case CORNER_RIGHT_LOWER:
|
||||
Anchor = ANCHOR_RIGHT_LOWER;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
int mFontSize = fontSize > 0
|
||||
? fontSize
|
||||
: 10;
|
||||
|
||||
//
|
||||
string mFont = IsValid(font)
|
||||
? font
|
||||
: "Arial";
|
||||
|
||||
//
|
||||
ObjectSetString(0, tag, OBJPROP_FONT, mFont);
|
||||
ObjectSetInteger(0, tag, OBJPROP_COLOR, clr);
|
||||
ObjectSetInteger(0, tag, OBJPROP_ANCHOR, Anchor);
|
||||
ObjectSetInteger(0, tag, OBJPROP_FONTSIZE, mFontSize);
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,532 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Ocillator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XDelta
|
||||
// Description: Detect Comulative Volumes Delta ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121 XDelta Ocillator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121_XDELTA"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Makret ...
|
||||
input group "Market";
|
||||
input int maLength = 14; // Moving Averge Length
|
||||
input ENUM_X_MA_METHOD maMethod = X_MA_MODE_EMA; // Moving Averge Method
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
input bool showDeltaLine = true; // Show Delta Line
|
||||
input bool showDeltaHistogram = true; // Show Delta Histogram
|
||||
input bool showDeltaMa = true; // Show Delta Moving Average
|
||||
|
||||
//
|
||||
// Buffers Props ...
|
||||
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 6
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define deltaLineBufferIndex 0
|
||||
double deltaLineBuffer[];
|
||||
|
||||
#property indicator_label1 "Delta Line"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrYellow
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
#define deltaHistogramBufferIndex 1
|
||||
double deltaHistogramBuffer[];
|
||||
|
||||
//
|
||||
#define deltaHistogramColorBufferIndex 2
|
||||
double deltaHistogramColorBuffer[];
|
||||
|
||||
#property indicator_label2 "Delta Histogram"
|
||||
#property indicator_type2 DRAW_COLOR_HISTOGRAM
|
||||
#property indicator_color2 CLR_NONE, clrGreen, clrDarkRed
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#define deltaMaBufferIndex 3
|
||||
double deltaMaBuffer[];
|
||||
|
||||
#property indicator_label3 "Delta MA"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrOrchid
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
#define mLastBufferIndex 3
|
||||
|
||||
//
|
||||
#define rawDeltaBufferIndex mLastBufferIndex + 1
|
||||
double rawDeltaBuffer[];
|
||||
|
||||
//
|
||||
#define deltaStateBufferIndex mLastBufferIndex + 2
|
||||
double deltaStateBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
//
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = maLength > 0 &&
|
||||
IsValid(maMethod);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(0, maLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// Delta Line ...
|
||||
ENUM_DRAW_TYPE deltaLineDrawType = showDeltaLine ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(deltaLineBuffer, true);
|
||||
SetIndexBuffer(deltaLineBufferIndex, deltaLineBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(deltaLineBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(deltaLineBufferIndex, PLOT_SHOW_DATA, showDeltaLine);
|
||||
PlotIndexSetInteger(deltaLineBufferIndex, PLOT_DRAW_TYPE, deltaLineDrawType);
|
||||
|
||||
//
|
||||
// Delta Histogram ...
|
||||
ENUM_DRAW_TYPE deltaHistogramDrawType = showDeltaHistogram ? DRAW_COLOR_HISTOGRAM : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(deltaHistogramBuffer, true);
|
||||
SetIndexBuffer(deltaHistogramBufferIndex, deltaHistogramBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(deltaHistogramBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(deltaHistogramBufferIndex, PLOT_SHOW_DATA, showDeltaHistogram);
|
||||
PlotIndexSetInteger(deltaHistogramBufferIndex, PLOT_DRAW_TYPE, deltaHistogramDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(deltaHistogramColorBuffer, true);
|
||||
SetIndexBuffer(deltaHistogramColorBufferIndex, deltaHistogramColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Delta Ma ...
|
||||
ENUM_DRAW_TYPE deltaMaDrawType = showDeltaMa ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(deltaMaBuffer, true);
|
||||
SetIndexBuffer(deltaMaBufferIndex, deltaMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(deltaMaBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(deltaMaBufferIndex, PLOT_SHOW_DATA, showDeltaMa);
|
||||
PlotIndexSetInteger(deltaMaBufferIndex, PLOT_DRAW_TYPE, deltaMaDrawType);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(rawDeltaBuffer, true);
|
||||
SetIndexBuffer(rawDeltaBufferIndex, rawDeltaBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(deltaStateBuffer, true);
|
||||
SetIndexBuffer(deltaStateBufferIndex, deltaStateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Custom Buffers ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int barsLimit = startCalculationForLastBars > 0
|
||||
? startCalculationForLastBars
|
||||
: 0;
|
||||
//
|
||||
// bool canCalculate = true;
|
||||
bool canCalculate =
|
||||
barsLimit == 0 ||
|
||||
bar_index <= barsLimit;
|
||||
if (canCalculate)
|
||||
{
|
||||
//
|
||||
CalculateValues(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBuffersZero(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
rawDeltaBuffer[barIndex] = 0.0;
|
||||
deltaLineBuffer[barIndex] = 0.0;
|
||||
deltaStateBuffer[barIndex] = 0.0;
|
||||
deltaHistogramBuffer[barIndex] = 0.0;
|
||||
deltaMaBuffer[barIndex] = 0.0;
|
||||
deltaHistogramColorBuffer[barIndex] = hideColorIDX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Vales ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateValues(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
XOHCL bar;
|
||||
bool has = bar.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index //
|
||||
);
|
||||
if (!has)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double iDelta = 0.0;
|
||||
|
||||
//
|
||||
// Detecting Delta Volume ...
|
||||
if (bar.IsBullish())
|
||||
{
|
||||
iDelta = (double)bar.volume;
|
||||
}
|
||||
else if (bar.IsBearish())
|
||||
{
|
||||
iDelta = -(double)bar.volume;
|
||||
}
|
||||
|
||||
//
|
||||
// Checking First Bar Conditions ...
|
||||
bool isFirstBar =
|
||||
startCalculationForLastBars > 0
|
||||
? bar_index == startCalculationForLastBars
|
||||
: bar_index == ratesTotal;
|
||||
if (isFirstBar)
|
||||
{
|
||||
//
|
||||
rawDeltaBuffer[bar_index] = iDelta;
|
||||
deltaLineBuffer[bar_index] = iDelta;
|
||||
deltaHistogramBuffer[bar_index] = iDelta;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
iDelta += deltaLineBuffer[bar_index + 1];
|
||||
|
||||
//
|
||||
rawDeltaBuffer[bar_index] = iDelta;
|
||||
deltaLineBuffer[bar_index] = iDelta;
|
||||
deltaHistogramBuffer[bar_index] = iDelta;
|
||||
}
|
||||
|
||||
//
|
||||
// Setting iDelta State ...
|
||||
double iState = iDelta > 0
|
||||
? bullishColorIDX
|
||||
: iDelta < 0
|
||||
? bearishColorIDX
|
||||
: hideColorIDX;
|
||||
//
|
||||
// Setting iDelta Color ...
|
||||
double iDeltaColor = iDelta > 0
|
||||
? bullishColorIDX
|
||||
: iDelta < 0
|
||||
? bearishColorIDX
|
||||
: hideColorIDX;
|
||||
|
||||
//
|
||||
deltaStateBuffer[bar_index] = iState;
|
||||
deltaHistogramColorBuffer[bar_index] = iDeltaColor;
|
||||
|
||||
//
|
||||
// Calculate Moving Averages ...
|
||||
int deltaMAsCount = iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
maLength,
|
||||
rawDeltaBuffer,
|
||||
deltaMaBuffer,
|
||||
maMethod //
|
||||
);
|
||||
|
||||
//
|
||||
bar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,692 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XDON
|
||||
// Description: XDON ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121 XDON Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121 XDON"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int donchainLength = 40; // Donchain Length
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
|
||||
//
|
||||
input bool showUpper = true; // Show Upper Band
|
||||
input bool showLower = true; // Show Lower Band
|
||||
|
||||
//
|
||||
input bool showOpen = true; // Show Open
|
||||
input bool showHigh = true; // Show High
|
||||
input bool showClose = true; // Show Close
|
||||
input bool showLow = true; // Show Low
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 8
|
||||
#property indicator_plots 8
|
||||
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// Open ...
|
||||
|
||||
//
|
||||
#define donOpenUpperBufferIndex 0
|
||||
double donOpenUpperBuffer[];
|
||||
|
||||
//
|
||||
#define donOpenUpperPlotBufferIndex 0
|
||||
#property indicator_label1 "X121 O U"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrCornflowerBlue
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
#define donOpenLowerBufferIndex 1
|
||||
double donOpenLowerBuffer[];
|
||||
|
||||
//
|
||||
#define donOpenLowerPlotBufferIndex 1
|
||||
#property indicator_label2 "X121 O L"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrCornflowerBlue
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// High ...
|
||||
|
||||
//
|
||||
#define donHighUpperBufferIndex 2
|
||||
double donHighUpperBuffer[];
|
||||
|
||||
//
|
||||
#define donHighUpperPlotBufferIndex 2
|
||||
#property indicator_label3 "X121 H U"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrAquamarine
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
#define donHighLowerBufferIndex 3
|
||||
double donHighLowerBuffer[];
|
||||
|
||||
//
|
||||
#define donHighLowerPlotBufferIndex 3
|
||||
#property indicator_label4 "X121 H L"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrAquamarine
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// Low ...
|
||||
|
||||
//
|
||||
#define donLowUpperBufferIndex 4
|
||||
double donLowUpperBuffer[];
|
||||
|
||||
//
|
||||
#define donLowUpperPlotBufferIndex 4
|
||||
#property indicator_label5 "X121 L U"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrDarkOrchid
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
#define donLowLowerBufferIndex 5
|
||||
double donLowLowerBuffer[];
|
||||
|
||||
//
|
||||
#define donLowLowerPlotBufferIndex 5
|
||||
#property indicator_label6 "X121 L L"
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_color6 clrDarkOrchid
|
||||
#property indicator_width6 1
|
||||
|
||||
//
|
||||
// Close ...
|
||||
|
||||
//
|
||||
#define donCloseUpperBufferIndex 6
|
||||
double donCloseUpperBuffer[];
|
||||
|
||||
//
|
||||
#define donCloseUpperPlotBufferIndex 6
|
||||
#property indicator_label7 "X121 C U"
|
||||
#property indicator_type7 DRAW_LINE
|
||||
#property indicator_color7 clrCoral
|
||||
#property indicator_width7 1
|
||||
|
||||
//
|
||||
#define donCloseLowerBufferIndex 7
|
||||
double donCloseLowerBuffer[];
|
||||
|
||||
//
|
||||
#define donCloseLowerPlotBufferIndex 7
|
||||
#property indicator_label8 "X121 C L"
|
||||
#property indicator_type8 DRAW_LINE
|
||||
#property indicator_color8 clrCoral
|
||||
#property indicator_width8 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 7;
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// Validate Calculated Bars ...
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
donchainLength > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Plot Buffers ...
|
||||
//
|
||||
// Open ...
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
bool canShowCOpenUpper = showUpper && showOpen;
|
||||
ENUM_DRAW_TYPE donOpenUpperDrawType = canShowCOpenUpper ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(donOpenUpperBuffer, true);
|
||||
SetIndexBuffer(donOpenUpperBufferIndex, donOpenUpperBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(donOpenUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(donOpenUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCOpenUpper);
|
||||
PlotIndexSetInteger(donOpenUpperPlotBufferIndex, PLOT_DRAW_TYPE, donOpenUpperDrawType);
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
bool canShowCOpenLower = showLower && showOpen;
|
||||
ENUM_DRAW_TYPE donOpenLowerDrawType = canShowCOpenLower ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(donOpenLowerBuffer, true);
|
||||
SetIndexBuffer(donOpenLowerBufferIndex, donOpenLowerBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(donOpenLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(donOpenLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCOpenLower);
|
||||
PlotIndexSetInteger(donOpenLowerPlotBufferIndex, PLOT_DRAW_TYPE, donOpenLowerDrawType);
|
||||
|
||||
//
|
||||
// Close ...
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
bool canShowCCloseUpper = showUpper && showClose;
|
||||
ENUM_DRAW_TYPE donCloseUpperDrawType = canShowCCloseUpper ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(donCloseUpperBuffer, true);
|
||||
SetIndexBuffer(donCloseUpperBufferIndex, donCloseUpperBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(donCloseUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(donCloseUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCCloseUpper);
|
||||
PlotIndexSetInteger(donCloseUpperPlotBufferIndex, PLOT_DRAW_TYPE, donCloseUpperDrawType);
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
bool canShowCCloseLower = showLower && showClose;
|
||||
ENUM_DRAW_TYPE donCloseLowerDrawType = canShowCCloseLower ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(donCloseLowerBuffer, true);
|
||||
SetIndexBuffer(donCloseLowerBufferIndex, donCloseLowerBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(donCloseLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(donCloseLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCCloseLower);
|
||||
PlotIndexSetInteger(donCloseLowerPlotBufferIndex, PLOT_DRAW_TYPE, donCloseLowerDrawType);
|
||||
|
||||
//
|
||||
// High ...
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
bool canShowCHighUpper = showUpper && showHigh;
|
||||
ENUM_DRAW_TYPE donHighUpperDrawType = canShowCHighUpper ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(donHighUpperBuffer, true);
|
||||
SetIndexBuffer(donHighUpperBufferIndex, donHighUpperBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(donHighUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(donHighUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCHighUpper);
|
||||
PlotIndexSetInteger(donHighUpperPlotBufferIndex, PLOT_DRAW_TYPE, donHighUpperDrawType);
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
bool canShowCHighLower = showLower && showHigh;
|
||||
ENUM_DRAW_TYPE donHighLowerDrawType = canShowCHighLower ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(donHighLowerBuffer, true);
|
||||
SetIndexBuffer(donHighLowerBufferIndex, donHighLowerBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(donHighLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(donHighLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCHighLower);
|
||||
PlotIndexSetInteger(donHighLowerPlotBufferIndex, PLOT_DRAW_TYPE, donHighLowerDrawType);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
bool canShowCLowUpper = showUpper && showLow;
|
||||
ENUM_DRAW_TYPE donLowUpperDrawType = canShowCLowUpper ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(donLowUpperBuffer, true);
|
||||
SetIndexBuffer(donLowUpperBufferIndex, donLowUpperBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(donLowUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(donLowUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCLowUpper);
|
||||
PlotIndexSetInteger(donLowUpperPlotBufferIndex, PLOT_DRAW_TYPE, donLowUpperDrawType);
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
bool canShowCLowLower = showLower && showLow;
|
||||
ENUM_DRAW_TYPE donLowLowerDrawType = canShowCLowLower ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(donLowLowerBuffer, true);
|
||||
SetIndexBuffer(donLowLowerBufferIndex, donLowLowerBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(donLowLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(donLowLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCLowLower);
|
||||
PlotIndexSetInteger(donLowLowerPlotBufferIndex, PLOT_DRAW_TYPE, donLowLowerDrawType);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Custom Buffers ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int barsLimit = startCalculationForLastBars > 0
|
||||
? startCalculationForLastBars
|
||||
: 0;
|
||||
//
|
||||
// bool canCalculate = true;
|
||||
bool canCalculate =
|
||||
barsLimit == 0 ||
|
||||
bar_index <= barsLimit;
|
||||
if (canCalculate)
|
||||
{
|
||||
//
|
||||
CalculateDonchains(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBuffersZero(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Custom ...
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
donOpenUpperBuffer[barIndex] = EMPTY_VALUE;
|
||||
donOpenLowerBuffer[barIndex] = EMPTY_VALUE;
|
||||
donCloseUpperBuffer[barIndex] = EMPTY_VALUE;
|
||||
donCloseLowerBuffer[barIndex] = EMPTY_VALUE;
|
||||
donHighUpperBuffer[barIndex] = EMPTY_VALUE;
|
||||
donHighLowerBuffer[barIndex] = EMPTY_VALUE;
|
||||
donLowUpperBuffer[barIndex] = EMPTY_VALUE;
|
||||
donLowLowerBuffer[barIndex] = EMPTY_VALUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Donchain ...
|
||||
*
|
||||
* @param bar_index: Integer, Bar Index ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
* @param _length: Integer, Donchain Length ...
|
||||
* @param _ouBuffer: Double Array Reference ...
|
||||
* @param _olBuffer: Double Array Reference ...
|
||||
* @param _huBuffer: Double Array Reference ...
|
||||
* @param _hlBuffer: Double Array Reference ...
|
||||
* @param _luBuffer: Double Array Reference ...
|
||||
* @param _llBuffer: Double Array Reference ...
|
||||
* @param _cuBuffer: Double Array Reference ...
|
||||
* @param _clBuffer: Double Array Reference ...
|
||||
*/
|
||||
void CalculateDonchain(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
//
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[],
|
||||
//
|
||||
int _length,
|
||||
//
|
||||
double &_ouBuffer[],
|
||||
double &_olBuffer[],
|
||||
double &_huBuffer[],
|
||||
double &_hlBuffer[],
|
||||
double &_luBuffer[],
|
||||
double &_llBuffer[],
|
||||
double &_cuBuffer[],
|
||||
double &_clBuffer[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
double iUpper = 0;
|
||||
double iLower = 0;
|
||||
|
||||
//
|
||||
// OPEN ...
|
||||
|
||||
//
|
||||
int from = bar_index;
|
||||
|
||||
//
|
||||
iUpper = open[ArrayMaximum(open, from, _length)];
|
||||
iLower = open[ArrayMinimum(open, from, _length)];
|
||||
|
||||
//
|
||||
_ouBuffer[bar_index] = iUpper;
|
||||
_olBuffer[bar_index] = iLower;
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
|
||||
//
|
||||
iUpper = high[ArrayMaximum(high, from, _length)];
|
||||
iLower = high[ArrayMinimum(high, from, _length)];
|
||||
|
||||
//
|
||||
_huBuffer[bar_index] = iUpper;
|
||||
_hlBuffer[bar_index] = iLower;
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
|
||||
//
|
||||
iUpper = low[ArrayMaximum(low, from, _length)];
|
||||
iLower = low[ArrayMinimum(low, from, _length)];
|
||||
|
||||
//
|
||||
_luBuffer[bar_index] = iUpper;
|
||||
_llBuffer[bar_index] = iLower;
|
||||
|
||||
//
|
||||
// CLOSE ...
|
||||
|
||||
//
|
||||
iUpper = close[ArrayMaximum(close, from, _length)];
|
||||
iLower = close[ArrayMinimum(close, from, _length)];
|
||||
|
||||
//
|
||||
_cuBuffer[bar_index] = iUpper;
|
||||
_clBuffer[bar_index] = iLower;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Different VWaps ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateDonchains(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
CalculateDonchain(
|
||||
//
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
donchainLength,
|
||||
//
|
||||
donOpenUpperBuffer,
|
||||
donOpenLowerBuffer,
|
||||
donHighUpperBuffer,
|
||||
donHighLowerBuffer,
|
||||
donLowUpperBuffer,
|
||||
donLowLowerBuffer,
|
||||
donCloseUpperBuffer,
|
||||
donCloseLowerBuffer //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,616 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XHK
|
||||
// Description: XHK ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121 XHK Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121 XHK"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int xhkSmoothingLength = 14; // Length
|
||||
input ENUM_X_MA_METHOD xhkSmoothingMode = X_MA_MODE_EMA; // Smoothing Method
|
||||
input bool xhkIgnoreSmoothingShadows = false; // Ignore Smoothed Bar Shadows
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
|
||||
//
|
||||
input bool drawRawXHKCandles = true; // Draw Raw Candle
|
||||
input bool drawSmoothedXHKCandles = true; // Draw Smoothed Candle
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 10
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
// PLOTTED Buffers ...
|
||||
|
||||
//
|
||||
#define openHKBufferIndex 0
|
||||
double openHKBuffer[];
|
||||
|
||||
//
|
||||
#define highHKBufferIndex 1
|
||||
double highHKBuffer[];
|
||||
|
||||
//
|
||||
#define lowHKBufferIndex 2
|
||||
double lowHKBuffer[];
|
||||
|
||||
//
|
||||
#define closeHKBufferIndex 3
|
||||
double closeHKBuffer[];
|
||||
|
||||
//
|
||||
#define rawHKColorBufferIndex 4
|
||||
double rawHKColorBuffer[];
|
||||
|
||||
//
|
||||
#define rawHKBufferIndex 0
|
||||
#property indicator_label1 "X121 XHK Open;X121 XHK High;X121 XHK Low;X121 XHK Close"
|
||||
#property indicator_type1 DRAW_COLOR_CANDLES
|
||||
#property indicator_color1 CLR_NONE, clrDodgerBlue, clrDarkGoldenrod
|
||||
|
||||
//
|
||||
// Open ...
|
||||
#define openBufferIndex 5
|
||||
double openBuffer[];
|
||||
|
||||
//
|
||||
// High ...
|
||||
#define highBufferIndex 6
|
||||
double highBuffer[];
|
||||
|
||||
//
|
||||
// Low ...
|
||||
#define lowBufferIndex 7
|
||||
double lowBuffer[];
|
||||
|
||||
//
|
||||
// Close ...
|
||||
#define closeBufferIndex 8
|
||||
double closeBuffer[];
|
||||
|
||||
//
|
||||
// Candle Color ...
|
||||
#define candleColorBufferIndex 9
|
||||
double candleColorBuffer[];
|
||||
|
||||
//
|
||||
#define candlesBufferIndex 1
|
||||
#property indicator_label2 "X121 XHKSM Open;X121 XHKSM High;X121 XHKSM Low;X121 XHKSM Close"
|
||||
#property indicator_type2 DRAW_COLOR_CANDLES
|
||||
#property indicator_color2 CLR_NONE, clrAqua, clrMagenta
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// Fill All Buffers by Zero ...
|
||||
if (prev_calculated == 0)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
true
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(0, xhkSmoothingLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
|
||||
//
|
||||
// RAW ...
|
||||
|
||||
//
|
||||
// Raw Candles Color ...
|
||||
ArraySetAsSeries(rawHKColorBuffer, true);
|
||||
SetIndexBuffer(rawHKColorBufferIndex, rawHKColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Set EMPTY_VALUE on Candles Buffer ...
|
||||
PlotIndexSetDouble(rawHKBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(rawHKBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// Open ...
|
||||
ArraySetAsSeries(openHKBuffer, true);
|
||||
SetIndexBuffer(openHKBufferIndex, openHKBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// High ...
|
||||
ArraySetAsSeries(highHKBuffer, true);
|
||||
SetIndexBuffer(highHKBufferIndex, highHKBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// Close ...
|
||||
ArraySetAsSeries(closeHKBuffer, true);
|
||||
SetIndexBuffer(closeHKBufferIndex, closeHKBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
ArraySetAsSeries(lowHKBuffer, true);
|
||||
SetIndexBuffer(lowHKBufferIndex, lowHKBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// SMOOTHED ...
|
||||
|
||||
//
|
||||
// Candles Color ...
|
||||
ArraySetAsSeries(candleColorBuffer, true);
|
||||
SetIndexBuffer(candleColorBufferIndex, candleColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Set EMPTY_VALUE on Candles Buffer ...
|
||||
PlotIndexSetDouble(candlesBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
PlotIndexSetInteger(candlesBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// Open ...
|
||||
ArraySetAsSeries(openBuffer, true);
|
||||
SetIndexBuffer(openBufferIndex, openBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// High ...
|
||||
ArraySetAsSeries(highBuffer, true);
|
||||
SetIndexBuffer(highBufferIndex, highBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// Close ...
|
||||
ArraySetAsSeries(closeBuffer, true);
|
||||
SetIndexBuffer(closeBufferIndex, closeBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
ArraySetAsSeries(lowBuffer, true);
|
||||
SetIndexBuffer(lowBufferIndex, lowBuffer, INDICATOR_DATA);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Custom Buffers ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int barsLimit = startCalculationForLastBars > 0
|
||||
? startCalculationForLastBars
|
||||
: 0;
|
||||
//
|
||||
bool canCalculate =
|
||||
barsLimit == 0 ||
|
||||
bar_index <= barsLimit;
|
||||
if (canCalculate)
|
||||
{
|
||||
//
|
||||
CalculateXHK(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBuffersZero(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Custom ...
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
lowHKBuffer[barIndex] = 0.0;
|
||||
openHKBuffer[barIndex] = 0.0;
|
||||
highHKBuffer[barIndex] = 0.0;
|
||||
closeHKBuffer[barIndex] = 0.0;
|
||||
rawHKColorBuffer[barIndex] = hideColorIDX;
|
||||
|
||||
//
|
||||
lowBuffer[barIndex] = 0.0;
|
||||
openBuffer[barIndex] = 0.0;
|
||||
highBuffer[barIndex] = 0.0;
|
||||
closeBuffer[barIndex] = 0.0;
|
||||
candleColorBuffer[barIndex] = hideColorIDX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate ATR Zones ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
*/
|
||||
void CalculateXHK(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
double mPrevHKOpenValue;
|
||||
double mPrevHKCloseValue;
|
||||
|
||||
//
|
||||
if (ArraySize(open) <= bar_index + 1)
|
||||
{
|
||||
//
|
||||
mPrevHKOpenValue = 0;
|
||||
mPrevHKCloseValue = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
mPrevHKOpenValue = openHKBuffer[bar_index + 1];
|
||||
mPrevHKCloseValue = closeHKBuffer[bar_index + 1];
|
||||
}
|
||||
|
||||
//
|
||||
double mHKOpenValue = (mPrevHKOpenValue + mPrevHKCloseValue) / 2;
|
||||
double mHKCloseValue = (open[bar_index] + high[bar_index] + close[bar_index] + low[bar_index]) / 4;
|
||||
double mHKHighValue = MathMax(high[bar_index], MathMax(mHKOpenValue, mHKCloseValue));
|
||||
double mHKLowValue = MathMin(low[bar_index], MathMin(mHKOpenValue, mHKCloseValue));
|
||||
|
||||
//
|
||||
double candleColorValue =
|
||||
mHKOpenValue < mHKCloseValue ? bullishColorIDX : bearishColorIDX;
|
||||
|
||||
//
|
||||
// Raw HK Buffers ...
|
||||
openHKBuffer[bar_index] = mHKOpenValue;
|
||||
highHKBuffer[bar_index] = mHKHighValue;
|
||||
lowHKBuffer[bar_index] = mHKLowValue;
|
||||
closeHKBuffer[bar_index] = mHKCloseValue;
|
||||
rawHKColorBuffer[bar_index] = drawRawXHKCandles ? candleColorValue : hideColorIDX;
|
||||
|
||||
//
|
||||
// Apply Smoothing ...
|
||||
bool canSmooth = xhkSmoothingLength > 0 &&
|
||||
xhkSmoothingMode != X_MA_MODE_NONE;
|
||||
if (!canSmooth)
|
||||
{
|
||||
//
|
||||
double min = MathMin(mHKOpenValue, mHKCloseValue);
|
||||
double max = MathMax(mHKOpenValue, mHKCloseValue);
|
||||
|
||||
//
|
||||
openBuffer[bar_index] = mHKOpenValue;
|
||||
highBuffer[bar_index] = xhkIgnoreSmoothingShadows ? max : mHKHighValue;
|
||||
lowBuffer[bar_index] = xhkIgnoreSmoothingShadows ? min : mHKLowValue;
|
||||
closeBuffer[bar_index] = mHKCloseValue;
|
||||
candleColorBuffer[bar_index] = drawSmoothedXHKCandles ? candleColorValue : hideColorIDX;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Open ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
xhkSmoothingLength,
|
||||
openHKBuffer,
|
||||
openBuffer,
|
||||
xhkSmoothingMode //
|
||||
);
|
||||
|
||||
//
|
||||
// Close ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
xhkSmoothingLength,
|
||||
closeHKBuffer,
|
||||
closeBuffer,
|
||||
xhkSmoothingMode //
|
||||
);
|
||||
|
||||
//
|
||||
// Ignoring Shadows ...
|
||||
if (!xhkIgnoreSmoothingShadows)
|
||||
{
|
||||
//
|
||||
// High ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
xhkSmoothingLength,
|
||||
highHKBuffer,
|
||||
highBuffer,
|
||||
xhkSmoothingMode //
|
||||
);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
xhkSmoothingLength,
|
||||
lowHKBuffer,
|
||||
lowBuffer,
|
||||
xhkSmoothingMode //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
double min = MathMin(closeBuffer[bar_index], openBuffer[bar_index]);
|
||||
double max = MathMin(closeBuffer[bar_index], openBuffer[bar_index]);
|
||||
|
||||
//
|
||||
lowBuffer[bar_index] = min;
|
||||
highBuffer[bar_index] = max;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Smoothed Color ...
|
||||
candleColorValue =
|
||||
openBuffer[bar_index] < closeBuffer[bar_index] ? bullishColorIDX : bearishColorIDX;
|
||||
candleColorBuffer[bar_index] = drawSmoothedXHKCandles ? candleColorValue : hideColorIDX;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,625 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XWZ
|
||||
// Description: XWZ ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121 XWZ Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121_XICH"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input ENUM_X_PRICE chikouSpanMode = X_PRICE_CLOSE; // ChikouSpan Mode
|
||||
input int tenkanSenLength = 9; // TenkanSen Length
|
||||
input ENUM_X_BOUNDARY_PRICE tenkanSenMode = X_BOUNDARY_PRICE_HIGH_LOW; // TencanSen Mode
|
||||
input int kijunSenLength = 26; // KijunSen Length
|
||||
input ENUM_X_BOUNDARY_PRICE kijunSenMode = X_BOUNDARY_PRICE_HIGH_LOW; // KijunSen Mode
|
||||
input int senkouSpanBLength = 52; // SenkouSpan B Length
|
||||
input ENUM_X_BOUNDARY_PRICE senkouSpanBMode = X_BOUNDARY_PRICE_HIGH_LOW; // SenkouSpan B Mode
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
input bool shiftKumo = true; // Shift Kumo
|
||||
input bool showTenkanSen = true; // Show TenkanSen
|
||||
input bool showKijunSen = true; // Show KijunSen
|
||||
input bool showChikouSpan = true; // Show ChikouSpan
|
||||
input bool showSenkouSpanA = true; // Show Senkou Span A
|
||||
input bool showSenkouSpanB = true; // Show Senkou Span B
|
||||
input bool showKumo = true; // Show Kumo
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 8
|
||||
#property indicator_plots 6
|
||||
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
#define tenkanSenBufferIndex 0
|
||||
double tenkanSenBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XICH TK"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrBrown
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 2
|
||||
|
||||
//
|
||||
#define kijunSenBufferIndex 1
|
||||
double kijunSenBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "XICH KJ"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrDodgerBlue
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 2
|
||||
|
||||
//
|
||||
#define chikouSpanBufferIndex 2
|
||||
double chikouSpanBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "XICH CS"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrDarkGreen
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 2
|
||||
|
||||
//
|
||||
#define senkouSpanABufferIndex 3
|
||||
double senkouSpanABuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "XICH SSA"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrLightGray
|
||||
#property indicator_style4 STYLE_DASHDOTDOT
|
||||
#property indicator_width4 2
|
||||
|
||||
//
|
||||
#define senkouSpanBBufferIndex 4
|
||||
double senkouSpanBBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "XICH SSB"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrLightGray
|
||||
#property indicator_style5 STYLE_DASHDOTDOT
|
||||
#property indicator_width5 2
|
||||
|
||||
//
|
||||
#define senkouABufferIndex 5
|
||||
double senkouABuffer[];
|
||||
|
||||
//
|
||||
#define senkouBBufferIndex 6
|
||||
double senkouBBuffer[];
|
||||
|
||||
//
|
||||
#define kumoBufferIndex 5
|
||||
|
||||
//
|
||||
#property indicator_label6 "XICH Kumo"
|
||||
#property indicator_type6 DRAW_FILLING
|
||||
#property indicator_color6 clrAqua, clrMagenta
|
||||
#property indicator_style6 STYLE_SOLID
|
||||
#property indicator_width6 2
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 6;
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
//
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
kijunSenLength > 0 &&
|
||||
tenkanSenLength > 0 &&
|
||||
senkouSpanBLength > 0 &&
|
||||
IsValid(kijunSenMode) &&
|
||||
IsValid(tenkanSenMode) &&
|
||||
IsValid(chikouSpanMode) &&
|
||||
IsValid(senkouSpanBMode)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(kijunSenLength, tenkanSenLength);
|
||||
result = MathMax(result, senkouSpanBLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
ENUM_DRAW_TYPE tenkanSenDrawType = showTenkanSen ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(tenkanSenBuffer, true);
|
||||
SetIndexBuffer(tenkanSenBufferIndex, tenkanSenBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(tenkanSenBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(tenkanSenBufferIndex, PLOT_SHOW_DATA, showTenkanSen);
|
||||
PlotIndexSetInteger(tenkanSenBufferIndex, PLOT_DRAW_TYPE, tenkanSenDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE kijunSenDrawType = showKijunSen ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(kijunSenBuffer, true);
|
||||
SetIndexBuffer(kijunSenBufferIndex, kijunSenBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(kijunSenBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(kijunSenBufferIndex, PLOT_SHOW_DATA, showKijunSen);
|
||||
PlotIndexSetInteger(kijunSenBufferIndex, PLOT_DRAW_TYPE, kijunSenDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE chikouSpanDrawType = showChikouSpan ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(chikouSpanBuffer, true);
|
||||
SetIndexBuffer(chikouSpanBufferIndex, chikouSpanBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_SHIFT, -kijunSenLength);
|
||||
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_SHOW_DATA, showChikouSpan);
|
||||
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_DRAW_TYPE, chikouSpanDrawType);
|
||||
|
||||
//
|
||||
int shiftSize = shiftKumo ? kijunSenLength : 0;
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE senkouSpanADrawType = showSenkouSpanA ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(senkouSpanABuffer, true);
|
||||
SetIndexBuffer(senkouSpanABufferIndex, senkouSpanABuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(senkouSpanABufferIndex, PLOT_SHIFT, shiftSize);
|
||||
PlotIndexSetInteger(senkouSpanABufferIndex, PLOT_SHOW_DATA, showSenkouSpanA);
|
||||
PlotIndexSetInteger(senkouSpanABufferIndex, PLOT_DRAW_TYPE, senkouSpanADrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE senkouSpanBDrawType = showSenkouSpanB ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(senkouSpanBBuffer, true);
|
||||
SetIndexBuffer(senkouSpanBBufferIndex, senkouSpanBBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(senkouSpanBBufferIndex, PLOT_SHIFT, shiftSize);
|
||||
PlotIndexSetInteger(senkouSpanBBufferIndex, PLOT_SHOW_DATA, showSenkouSpanB);
|
||||
PlotIndexSetInteger(senkouSpanBBufferIndex, PLOT_DRAW_TYPE, senkouSpanBDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(senkouABuffer, true);
|
||||
SetIndexBuffer(senkouABufferIndex, senkouABuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(senkouABufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(senkouBBuffer, true);
|
||||
SetIndexBuffer(senkouBBufferIndex, senkouBBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(senkouBBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE kumoDrawType = showKumo ? DRAW_FILLING : DRAW_NONE;
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(kumoBufferIndex, PLOT_SHIFT, shiftSize);
|
||||
PlotIndexSetInteger(kumoBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(kumoBufferIndex, PLOT_DRAW_TYPE, kumoDrawType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Custom Buffers ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int barsLimit = startCalculationForLastBars > 0
|
||||
? startCalculationForLastBars
|
||||
: 0;
|
||||
//
|
||||
// bool canCalculate = true;
|
||||
bool canCalculate =
|
||||
barsLimit == 0 ||
|
||||
bar_index <= barsLimit;
|
||||
if (canCalculate)
|
||||
{
|
||||
//
|
||||
CalculateValues(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBuffersZero(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
senkouABuffer[barIndex] = 0;
|
||||
senkouBBuffer[barIndex] = 0;
|
||||
kijunSenBuffer[barIndex] = 0;
|
||||
tenkanSenBuffer[barIndex] = 0;
|
||||
chikouSpanBuffer[barIndex] = 0;
|
||||
senkouSpanABuffer[barIndex] = 0;
|
||||
senkouSpanBBuffer[barIndex] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Vales ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateValues(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
double uppers[];
|
||||
double lowers[];
|
||||
|
||||
//
|
||||
double uppersMax = 0;
|
||||
double uppersMin = 0;
|
||||
|
||||
//
|
||||
double lowersMax = 0;
|
||||
double lowersMin = 0;
|
||||
|
||||
//
|
||||
// Calculate ChikouSpan ...
|
||||
double iChikouSpan = GetAppliedPrice(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index,
|
||||
chikouSpanMode //
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate TenkanSen ...
|
||||
GetPriceBoundary(
|
||||
uppers,
|
||||
lowers,
|
||||
_Symbol,
|
||||
_Period,
|
||||
tenkanSenMode,
|
||||
tenkanSenLength,
|
||||
bar_index //
|
||||
);
|
||||
|
||||
//
|
||||
uppersMax = uppers[ArrayMaximum(uppers)];
|
||||
uppersMin = uppers[ArrayMinimum(uppers)];
|
||||
|
||||
//
|
||||
lowersMax = lowers[ArrayMaximum(lowers)];
|
||||
lowersMin = lowers[ArrayMinimum(lowers)];
|
||||
|
||||
//
|
||||
double iTenkanSen = (uppersMax + lowersMin) / 2;
|
||||
|
||||
//
|
||||
// Calculate KijunSen ...
|
||||
GetPriceBoundary(
|
||||
uppers,
|
||||
lowers,
|
||||
_Symbol,
|
||||
_Period,
|
||||
kijunSenMode,
|
||||
kijunSenLength,
|
||||
bar_index //
|
||||
);
|
||||
|
||||
//
|
||||
uppersMax = uppers[ArrayMaximum(uppers)];
|
||||
uppersMin = uppers[ArrayMinimum(uppers)];
|
||||
|
||||
//
|
||||
lowersMax = lowers[ArrayMaximum(lowers)];
|
||||
lowersMin = lowers[ArrayMinimum(lowers)];
|
||||
|
||||
//
|
||||
double iKijunSen = (uppersMax + lowersMin) / 2;
|
||||
|
||||
//
|
||||
// Calculate SenkouSpanB ...
|
||||
GetPriceBoundary(
|
||||
uppers,
|
||||
lowers,
|
||||
_Symbol,
|
||||
_Period,
|
||||
senkouSpanBMode,
|
||||
senkouSpanBLength,
|
||||
bar_index //
|
||||
);
|
||||
|
||||
//
|
||||
uppersMax = uppers[ArrayMaximum(uppers)];
|
||||
uppersMin = uppers[ArrayMinimum(uppers)];
|
||||
|
||||
//
|
||||
lowersMax = lowers[ArrayMaximum(lowers)];
|
||||
lowersMin = lowers[ArrayMinimum(lowers)];
|
||||
|
||||
//
|
||||
double iSenkouSpanB = (uppersMax + lowersMin) / 2;
|
||||
|
||||
//
|
||||
// Calculate SenkouSpanA ...
|
||||
double iSenkouSpanA = (iTenkanSen + iKijunSen) / 2;
|
||||
|
||||
//
|
||||
// Setting Buffers ...
|
||||
kijunSenBuffer[bar_index] = iKijunSen;
|
||||
senkouABuffer[bar_index] = iSenkouSpanA;
|
||||
senkouBBuffer[bar_index] = iSenkouSpanB;
|
||||
tenkanSenBuffer[bar_index] = iTenkanSen;
|
||||
chikouSpanBuffer[bar_index] = iChikouSpan;
|
||||
senkouSpanABuffer[bar_index] = iSenkouSpanA;
|
||||
senkouSpanBBuffer[bar_index] = iSenkouSpanB;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,574 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XMAS
|
||||
// Description: XMAS ...
|
||||
//
|
||||
//
|
||||
// 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 XMAS Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121_XMAS"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int length = 14; // MA Length
|
||||
input ENUM_MA_METHOD method = MODE_EMA; // MA Method
|
||||
input ENUM_APPLIED_PRICE upperAppliedTo = PRICE_HIGH; // Upper Applied To
|
||||
input ENUM_APPLIED_PRICE midAppliedTo = PRICE_MEDIAN; // Mid Applied To
|
||||
input ENUM_APPLIED_PRICE lowerAppliedTo = PRICE_LOW; // Lower Applied To
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
input bool showUpper = true; // Show Upper
|
||||
input bool showMid = true; // Show Mid
|
||||
input bool showLower = true; // Show Lower
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
#define upperBufferIndex 0
|
||||
double upperBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121 MASU"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrAqua
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// MID ...
|
||||
#define midBufferIndex 1
|
||||
double midBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121 MASM"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrLightBlue
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
#define lowerBufferIndex 2
|
||||
double lowerBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "X121 MASL"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrMagenta
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 2;
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int upperHandler = INVALID_HANDLE;
|
||||
int midHandler = INVALID_HANDLE;
|
||||
int lowerHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// Upper ...
|
||||
upperHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
0,
|
||||
method,
|
||||
upperAppliedTo //
|
||||
);
|
||||
bool isInited = upperHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
midHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
0,
|
||||
method,
|
||||
midAppliedTo //
|
||||
);
|
||||
isInited = midHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Lower ...
|
||||
lowerHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
0,
|
||||
method,
|
||||
lowerAppliedTo //
|
||||
);
|
||||
isInited = lowerHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
IndicatorRelease(upperHandler);
|
||||
IndicatorRelease(midHandler);
|
||||
IndicatorRelease(lowerHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// Validate Calculated Bars ...
|
||||
|
||||
//
|
||||
// Upper ...
|
||||
int upperCalculatedBars = BarsCalculated(upperHandler);
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
int midCalculatedBars = BarsCalculated(midHandler);
|
||||
|
||||
//
|
||||
// Lower ...
|
||||
int lowerCalculatedBars = BarsCalculated(lowerHandler);
|
||||
|
||||
//
|
||||
bool isPassedRequiredCalculatedBars =
|
||||
//
|
||||
// Upper ...
|
||||
upperCalculatedBars >= maxLength &&
|
||||
//
|
||||
// Mid ...
|
||||
midCalculatedBars >= maxLength &&
|
||||
//
|
||||
// Lower ...
|
||||
lowerCalculatedBars >= maxLength
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCalculatedBars)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
|
||||
//
|
||||
// Upper ...
|
||||
int copiedUppers = CopyBuffer(upperHandler, 0, 0, limit, upperBuffer);
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
int copiedMids = CopyBuffer(midHandler, 0, 0, limit, midBuffer);
|
||||
|
||||
//
|
||||
// Lower ...
|
||||
int copiedLowers = CopyBuffer(lowerHandler, 0, 0, limit, lowerBuffer);
|
||||
|
||||
//
|
||||
// Validate Copied Items ...
|
||||
bool isPassedRequiredCopiedItems =
|
||||
//
|
||||
// Upper ...
|
||||
copiedUppers > 0 &&
|
||||
//
|
||||
// Mid ...
|
||||
copiedMids > 0 &&
|
||||
//
|
||||
// Lower ...
|
||||
copiedLowers > 0
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCopiedItems)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
//
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = length > 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(result, length);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// Upper ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE upperDrawType = showUpper ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(upperBuffer, true);
|
||||
SetIndexBuffer(upperBufferIndex, upperBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(upperBufferIndex, PLOT_SHOW_DATA, showUpper);
|
||||
PlotIndexSetInteger(upperBufferIndex, PLOT_DRAW_TYPE, upperDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(upperBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE midDrawType = showMid ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
ArraySetAsSeries(midBuffer, true);
|
||||
SetIndexBuffer(midBufferIndex, midBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(midBufferIndex, PLOT_SHOW_DATA, showMid);
|
||||
PlotIndexSetInteger(midBufferIndex, PLOT_DRAW_TYPE, midDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(midBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
// Lower ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE lowerDrawType = showLower ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
ArraySetAsSeries(lowerBuffer, true);
|
||||
SetIndexBuffer(lowerBufferIndex, lowerBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(lowerBufferIndex, PLOT_SHOW_DATA, showLower);
|
||||
PlotIndexSetInteger(lowerBufferIndex, PLOT_DRAW_TYPE, lowerDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(lowerBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Custom Buffers ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int barsLimit = startCalculationForLastBars > 0
|
||||
? startCalculationForLastBars
|
||||
: 0;
|
||||
//
|
||||
// bool canCalculate = true;
|
||||
bool canCalculate =
|
||||
barsLimit == 0 ||
|
||||
bar_index <= barsLimit;
|
||||
if (canCalculate)
|
||||
{
|
||||
//
|
||||
CalculateValues(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBuffersZero(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
upperBuffer[barIndex] = 0;
|
||||
midBuffer[barIndex] = 0;
|
||||
lowerBuffer[barIndex] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Vales ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateValues(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Implement Colorify Mechanism ...
|
||||
}
|
||||
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,812 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XSTR
|
||||
// Description: XSTR ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121 XSTR Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121 XSTR"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int strLength = 14; // Length
|
||||
input double strMultiplier = 3; // Multiplier
|
||||
input int vidyaLength = 14; // Smothing Length
|
||||
input ENUM_MA_METHOD strBoundaryMode = MODE_SMA; // Boundary Mode
|
||||
input ENUM_APPLIED_PRICE strAppliedTo = PRICE_MEDIAN; // Applied To
|
||||
input ENUM_APPLIED_PRICE vidyaAppliedTo = PRICE_CLOSE; // Smoothing Applied To
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showStr = true; // Show Str
|
||||
input bool showVidya = true; // Show Vidya
|
||||
input bool showStrUpper = true; // Show Str Upper
|
||||
input bool showStrLower = true; // Show Str Lower
|
||||
input bool showStrLowMa = true; // Show Low Smoothed Buffer
|
||||
input bool showStrHighMa = true; // Show High Smoothed Buffer
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#define emptyValue 0.0
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 10
|
||||
#property indicator_plots 6
|
||||
|
||||
//
|
||||
// STR ...
|
||||
#define strBufferIndex 0
|
||||
double strBuffer[];
|
||||
|
||||
#define strColorBufferIndex 1
|
||||
double strColorBuffer[];
|
||||
|
||||
//
|
||||
#define strPlotBufferIndex 0
|
||||
#property indicator_label1 "X121 STR"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 CLR_NONE, clrLime, clrRed, clrGray
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 2
|
||||
|
||||
//
|
||||
// Up ...
|
||||
#define strUpBufferIndex 2
|
||||
double strUpBuffer[];
|
||||
|
||||
//
|
||||
#define strUpPlotBufferIndex 1
|
||||
#property indicator_label2 "X121 STR U"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrBlueViolet
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Down ...
|
||||
#define strDownBufferIndex 3
|
||||
double strDownBuffer[];
|
||||
|
||||
//
|
||||
#define strDownPlotBufferIndex 2
|
||||
#property indicator_label3 "X121 STR D"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrBlueViolet
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// High MA ...
|
||||
#define strHighMaBufferIndex 4
|
||||
double strHighMaBuffer[];
|
||||
|
||||
//
|
||||
#define strHighMaPlotBufferIndex 3
|
||||
#property indicator_label4 "X121 STR HSM"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrAqua
|
||||
#property indicator_style4 STYLE_SOLID
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// Low Ma ...
|
||||
#define strLowMaBufferIndex 5
|
||||
double strLowMaBuffer[];
|
||||
|
||||
//
|
||||
#define strLowMaPlotBufferIndex 4
|
||||
#property indicator_label5 "X121 STR LSM"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrMagenta
|
||||
#property indicator_style5 STYLE_SOLID
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
// VIDYA ...
|
||||
#define vidyaBufferIndex 6
|
||||
double vidyaBuffer[];
|
||||
|
||||
//
|
||||
#define vidyaPlotBufferIndex 5
|
||||
#property indicator_label6 "X121 VIDYA"
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_color6 clrYellow
|
||||
#property indicator_style6 STYLE_SOLID
|
||||
#property indicator_width6 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 6;
|
||||
|
||||
//
|
||||
// STR ...
|
||||
|
||||
//
|
||||
// Atr ...
|
||||
#define atrBufferIndex mLastBufferIndex + 1
|
||||
double atrBuffer[];
|
||||
|
||||
//
|
||||
// Price ...
|
||||
#define strPriceBufferIndex mLastBufferIndex + 2
|
||||
double strPriceBuffer[];
|
||||
|
||||
//
|
||||
// Trend ...
|
||||
#define strStateBufferIndex mLastBufferIndex + 3
|
||||
double strStateBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// ATR Handler ...
|
||||
int atrHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// MA Handler ...
|
||||
int lowMaHandler = INVALID_HANDLE;
|
||||
int highMaHandler = INVALID_HANDLE;
|
||||
int vidyaHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
bool isStrTrendChanged;
|
||||
bool isStrStartBearishTrend;
|
||||
bool isStrStartBullishTrend;
|
||||
|
||||
//
|
||||
int changeOfTrend;
|
||||
int startBearishTrend;
|
||||
int startBullishTrend;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
atrHandler = iATR(
|
||||
_Symbol,
|
||||
_Period,
|
||||
strLength //
|
||||
);
|
||||
bool isInited = atrHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Low Ma ...
|
||||
lowMaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
strLength,
|
||||
0,
|
||||
strBoundaryMode,
|
||||
PRICE_LOW //
|
||||
);
|
||||
isInited = lowMaHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// High Ma ...
|
||||
highMaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
strLength,
|
||||
0,
|
||||
strBoundaryMode,
|
||||
PRICE_HIGH //
|
||||
);
|
||||
isInited = highMaHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Vidya ...
|
||||
vidyaHandler = iVIDyA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
strLength,
|
||||
vidyaLength,
|
||||
0, // Shift ...
|
||||
vidyaAppliedTo //
|
||||
);
|
||||
isInited = vidyaHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
IndicatorRelease(atrHandler);
|
||||
IndicatorRelease(vidyaHandler);
|
||||
IndicatorRelease(lowMaHandler);
|
||||
IndicatorRelease(highMaHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
|
||||
//
|
||||
// Validate Calculated Bars ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
int atrCalculatedBars = BarsCalculated(atrHandler);
|
||||
|
||||
//
|
||||
// VIDYA ...
|
||||
int vidyaCalculatedBars = BarsCalculated(vidyaHandler);
|
||||
|
||||
//
|
||||
// Low Ma ...
|
||||
int lowMaCalculatedBars = BarsCalculated(lowMaHandler);
|
||||
|
||||
//
|
||||
// High Ma ...
|
||||
int highMaCalculatedBars = BarsCalculated(highMaHandler);
|
||||
|
||||
//
|
||||
bool isPassedRequiredCalculatedBars =
|
||||
//
|
||||
// ATR ...
|
||||
atrCalculatedBars >= 0 &&
|
||||
//
|
||||
// VIDYA ...
|
||||
vidyaCalculatedBars >= 0 &&
|
||||
//
|
||||
// Low Ma ...
|
||||
lowMaCalculatedBars >= 0 &&
|
||||
//
|
||||
// High Ma ...
|
||||
highMaCalculatedBars >= 0
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCalculatedBars)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// checking for the limit start of calculation of an indicator ...
|
||||
limit =
|
||||
(prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? maxLength
|
||||
: prev_calculated - 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
int copiedAtrs = CopyBuffer(atrHandler, 0, 0, rates_total, atrBuffer);
|
||||
|
||||
//
|
||||
// VYDIA ...
|
||||
int copiedVidyas = CopyBuffer(vidyaHandler, 0, 0, rates_total, vidyaBuffer);
|
||||
|
||||
//
|
||||
// Low Ma ...
|
||||
int copiedLowMas = CopyBuffer(lowMaHandler, 0, 0, rates_total, strLowMaBuffer);
|
||||
|
||||
//
|
||||
// High Ma ...
|
||||
int copiedHighMas = CopyBuffer(highMaHandler, 0, 0, rates_total, strHighMaBuffer);
|
||||
|
||||
//
|
||||
// Validate Copied Items ...
|
||||
bool isPassedRequiredCopiedItems =
|
||||
//
|
||||
// ATR ...
|
||||
copiedAtrs >= 0 &&
|
||||
//
|
||||
// VIDYA ...
|
||||
copiedVidyas >= 0 &&
|
||||
//
|
||||
// Low Ma ...
|
||||
copiedLowMas >= 0 &&
|
||||
//
|
||||
// Hig Ma ...
|
||||
copiedHighMas >= 0
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCopiedItems)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
// STR ...
|
||||
strLength > 0 &&
|
||||
strMultiplier > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(1, strLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// STR ...
|
||||
SetIndexBuffer(strBufferIndex, strBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(strColorBufferIndex, strColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE strUpDrawType = showStrUpper ? DRAW_LINE : DRAW_NONE;
|
||||
SetIndexBuffer(strUpBufferIndex, strUpBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(strUpPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(strUpPlotBufferIndex, PLOT_SHOW_DATA, showStrUpper);
|
||||
PlotIndexSetInteger(strUpPlotBufferIndex, PLOT_DRAW_TYPE, strUpDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE strDownDrawType = showStrLower ? DRAW_LINE : DRAW_NONE;
|
||||
SetIndexBuffer(strDownBufferIndex, strDownBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(strDownPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(strDownPlotBufferIndex, PLOT_SHOW_DATA, showStrLower);
|
||||
PlotIndexSetInteger(strDownPlotBufferIndex, PLOT_DRAW_TYPE, strDownDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE strLowMaDrawType = showStrLowMa ? DRAW_LINE : DRAW_NONE;
|
||||
SetIndexBuffer(strLowMaBufferIndex, strLowMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(strLowMaPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(strLowMaPlotBufferIndex, PLOT_SHOW_DATA, showStrLowMa);
|
||||
PlotIndexSetInteger(strLowMaPlotBufferIndex, PLOT_DRAW_TYPE, strLowMaDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE strHighMaDrawType = showStrHighMa ? DRAW_LINE : DRAW_NONE;
|
||||
SetIndexBuffer(strHighMaBufferIndex, strHighMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(strHighMaPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(strHighMaPlotBufferIndex, PLOT_SHOW_DATA, showStrHighMa);
|
||||
PlotIndexSetInteger(strHighMaPlotBufferIndex, PLOT_DRAW_TYPE, strHighMaDrawType);
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE vidyaDrawType = showVidya ? DRAW_LINE : DRAW_NONE;
|
||||
SetIndexBuffer(vidyaBufferIndex, vidyaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(vidyaPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(vidyaPlotBufferIndex, PLOT_SHOW_DATA, showVidya);
|
||||
PlotIndexSetInteger(vidyaPlotBufferIndex, PLOT_DRAW_TYPE, vidyaDrawType);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
SetIndexBuffer(strPriceBufferIndex, strPriceBuffer, INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(strStateBufferIndex, strStateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Custom Buffers ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
CalculateStr(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Custom ...
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
// STR ...
|
||||
strBuffer[barIndex] = emptyValue;
|
||||
strUpBuffer[barIndex] = emptyValue;
|
||||
strDownBuffer[barIndex] = emptyValue;
|
||||
strPriceBuffer[barIndex] = emptyValue;
|
||||
strLowMaBuffer[barIndex] = emptyValue;
|
||||
strHighMaBuffer[barIndex] = emptyValue;
|
||||
|
||||
//
|
||||
strColorBuffer[barIndex] = hideColorIDX;
|
||||
strStateBuffer[barIndex] = hideColorIDX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate STR ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
*/
|
||||
void CalculateStr(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Calculated Price ...
|
||||
ENUM_X_PRICE mPType = ToXPrice(strAppliedTo);
|
||||
double price = GetAppliedPrice(
|
||||
mPType,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
strPriceBuffer[bar_index] = price;
|
||||
|
||||
//
|
||||
double atr = atrBuffer[bar_index];
|
||||
|
||||
//
|
||||
// Up ...
|
||||
strUpBuffer[bar_index] = price + (strMultiplier * atr);
|
||||
|
||||
//
|
||||
// Down ...
|
||||
strDownBuffer[bar_index] = price - (strMultiplier * atr);
|
||||
|
||||
//
|
||||
if (close[bar_index] > strUpBuffer[bar_index - 1])
|
||||
{
|
||||
//
|
||||
strStateBuffer[bar_index] = 1;
|
||||
if (strStateBuffer[bar_index - 1] == -1)
|
||||
{
|
||||
changeOfTrend = 1;
|
||||
}
|
||||
}
|
||||
else if (close[bar_index] < strDownBuffer[bar_index - 1])
|
||||
{
|
||||
//
|
||||
strStateBuffer[bar_index] = -1;
|
||||
if (strStateBuffer[bar_index - 1] == 1)
|
||||
{
|
||||
changeOfTrend = 1;
|
||||
}
|
||||
}
|
||||
else if (strStateBuffer[bar_index - 1] == 1)
|
||||
{
|
||||
//
|
||||
strStateBuffer[bar_index] = 1;
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
else if (strStateBuffer[bar_index - 1] == -1)
|
||||
{
|
||||
//
|
||||
strStateBuffer[bar_index] = -1;
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Down Trend Starting ...
|
||||
if (strStateBuffer[bar_index] < 0 && strStateBuffer[bar_index - 1] > 0)
|
||||
{
|
||||
startBearishTrend = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
startBearishTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Up Trend Starting ...
|
||||
if (strStateBuffer[bar_index] > 0 && strStateBuffer[bar_index - 1] < 0)
|
||||
{
|
||||
startBullishTrend = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
startBullishTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
if (strStateBuffer[bar_index] > 0 && strDownBuffer[bar_index] < strDownBuffer[bar_index - 1])
|
||||
{
|
||||
strDownBuffer[bar_index] = strDownBuffer[bar_index - 1];
|
||||
}
|
||||
|
||||
//
|
||||
if (strStateBuffer[bar_index] < 0 && strUpBuffer[bar_index] > strUpBuffer[bar_index - 1])
|
||||
{
|
||||
strUpBuffer[bar_index] = strUpBuffer[bar_index - 1];
|
||||
}
|
||||
|
||||
//
|
||||
if (startBearishTrend == 1)
|
||||
{
|
||||
strUpBuffer[bar_index] = strPriceBuffer[bar_index] + (strMultiplier * atr);
|
||||
}
|
||||
|
||||
//
|
||||
if (startBullishTrend == 1)
|
||||
{
|
||||
strDownBuffer[bar_index] = strPriceBuffer[bar_index] - (strMultiplier * atr);
|
||||
}
|
||||
|
||||
//
|
||||
// Draw the indicator ...
|
||||
|
||||
//
|
||||
double colorIDX = hideColorIDX;
|
||||
strColorBuffer[bar_index] = colorIDX;
|
||||
|
||||
//
|
||||
if (strStateBuffer[bar_index] == 1)
|
||||
{
|
||||
//
|
||||
strBuffer[bar_index] = strDownBuffer[bar_index];
|
||||
if (changeOfTrend == 1)
|
||||
{
|
||||
strBuffer[bar_index - 1] = strBuffer[bar_index - 2];
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
colorIDX = bullishColorIDX;
|
||||
}
|
||||
else if (strStateBuffer[bar_index] == -1)
|
||||
{
|
||||
//
|
||||
strBuffer[bar_index] = strUpBuffer[bar_index];
|
||||
if (changeOfTrend == 1)
|
||||
{
|
||||
//
|
||||
strBuffer[bar_index - 1] = strBuffer[bar_index - 2];
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
colorIDX = bearishColorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
if (showStr)
|
||||
{
|
||||
strColorBuffer[bar_index] = colorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
// Str Mid ...
|
||||
|
||||
//
|
||||
double iStrMid = strDownBuffer[bar_index] + ((strUpBuffer[bar_index] - strDownBuffer[bar_index]) / 2);
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,701 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: X121 XTREND
|
||||
// Description: XTREND ...
|
||||
//
|
||||
//
|
||||
// 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 XTREND Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "X121 XTREND"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
|
||||
input ENUM_APPLIED_PRICE trendPriceType = PRICE_CLOSE; // Detect Trend Price Type
|
||||
|
||||
input group "MA Detection";
|
||||
input int maLength = 50; // MA Length
|
||||
input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method
|
||||
input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // MA Applied To
|
||||
|
||||
input group "ADX Detection";
|
||||
input int adxLength = 14; // ADX Length
|
||||
input double adxThreshold = 25; // ADX Threshold for Strong Trends
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
input int upTrendArrowCode = 233; // Up Trend Arrow Code
|
||||
input int downTrendArrowCode = 234; // Down Trend Arrow Code
|
||||
|
||||
//
|
||||
input bool showOnlyTrendStart = true; // Show Only Trend Start
|
||||
input bool showUpTrend = true; // Show Up Trend
|
||||
input bool showDownTrend = true; // Show Down Trend
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 8
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
#define upTrendBufferIndex 0
|
||||
double upTrendBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X121 XTREND Up"
|
||||
#property indicator_type1 DRAW_ARROW
|
||||
#property indicator_color1 clrAqua
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
#define downTrendBufferIndex 1
|
||||
double downTrendBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X121 XTREND Down"
|
||||
#property indicator_type2 DRAW_ARROW
|
||||
#property indicator_color2 clrMagenta
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 1;
|
||||
|
||||
//
|
||||
#define maBufferIndex mLastBufferIndex + 1
|
||||
double maBuffer[];
|
||||
|
||||
//
|
||||
#define adxBufferIndex mLastBufferIndex + 2
|
||||
double adxBuffer[];
|
||||
|
||||
//
|
||||
#define adxPBufferIndex mLastBufferIndex + 3
|
||||
double adxPBuffer[];
|
||||
|
||||
//
|
||||
#define adxMBufferIndex mLastBufferIndex + 4
|
||||
double adxMBuffer[];
|
||||
|
||||
//
|
||||
#define upTBufferIndex mLastBufferIndex + 5
|
||||
double upTBuffer[];
|
||||
|
||||
//
|
||||
#define downTBufferIndex mLastBufferIndex + 6
|
||||
double downTBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
double lastValue = 0;
|
||||
ENUM_X_DIRECTION lastTrendDir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
// MA Handler ...
|
||||
int maHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// ADX Handler ...
|
||||
int adxHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Indicator Handlers ...
|
||||
|
||||
//
|
||||
// MA ...
|
||||
maHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
maLength,
|
||||
0,
|
||||
maMethod,
|
||||
maAppliedTo //
|
||||
);
|
||||
bool isInited = maHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// ADx ...
|
||||
adxHandler = iADX(
|
||||
_Symbol,
|
||||
_Period,
|
||||
adxLength //
|
||||
);
|
||||
isInited = maHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
IndicatorRelease(maHandler);
|
||||
IndicatorRelease(adxHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// Validate Calculated Bars ...
|
||||
|
||||
//
|
||||
// MA ...
|
||||
int maCalculatedBars = BarsCalculated(maHandler);
|
||||
|
||||
//
|
||||
// ADX ...
|
||||
int adxCalculatedBars = BarsCalculated(adxHandler);
|
||||
|
||||
//
|
||||
bool isPassedRequiredCalculatedBars =
|
||||
//
|
||||
// MA ...
|
||||
maCalculatedBars >= maxLength &&
|
||||
//
|
||||
// ADX ...
|
||||
adxCalculatedBars >= maxLength
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCalculatedBars)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
|
||||
//
|
||||
// MA ...
|
||||
int copiedMas = CopyBuffer(maHandler, 0, 0, limit, maBuffer);
|
||||
|
||||
//
|
||||
// ADX ...
|
||||
int copiedAdxs = CopyBuffer(adxHandler, MAIN_LINE, 0, limit, adxBuffer);
|
||||
int copiedAdxPs = CopyBuffer(adxHandler, PLUSDI_LINE, 0, limit, adxPBuffer);
|
||||
int copiedAdxMs = CopyBuffer(adxHandler, MINUSDI_LINE, 0, limit, adxMBuffer);
|
||||
|
||||
//
|
||||
// Validate Copied Items ...
|
||||
bool isPassedRequiredCopiedItems =
|
||||
//
|
||||
// MA ...
|
||||
copiedMas > 0 &&
|
||||
//
|
||||
// ADX ...
|
||||
copiedAdxs > 0 &&
|
||||
copiedAdxPs > 0 &&
|
||||
copiedAdxMs > 0
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCopiedItems)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
// MA ...
|
||||
maLength > 0 &&
|
||||
//
|
||||
// ADX ...
|
||||
adxLength > 0 &&
|
||||
adxThreshold > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(maLength, adxLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// UP Trend ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE upTrendDrawType = showUpTrend ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(upTrendBuffer, true);
|
||||
SetIndexBuffer(upTrendBufferIndex, upTrendBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(upTrendBufferIndex, PLOT_SHOW_DATA, showUpTrend);
|
||||
PlotIndexSetInteger(upTrendBufferIndex, PLOT_DRAW_TYPE, upTrendDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(upTrendBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(upTrendBufferIndex, PLOT_ARROW, upTrendArrowCode);
|
||||
|
||||
//
|
||||
// DOWN Trend ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE downTrendDrawType = showDownTrend ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(downTrendBuffer, true);
|
||||
SetIndexBuffer(downTrendBufferIndex, downTrendBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(downTrendBufferIndex, PLOT_SHOW_DATA, showDownTrend);
|
||||
PlotIndexSetInteger(downTrendBufferIndex, PLOT_DRAW_TYPE, downTrendDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(downTrendBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(downTrendBufferIndex, PLOT_ARROW, downTrendArrowCode);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(maBuffer, true);
|
||||
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(adxBuffer, true);
|
||||
SetIndexBuffer(adxBufferIndex, adxBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(adxPBuffer, true);
|
||||
SetIndexBuffer(adxPBufferIndex, adxPBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(adxMBuffer, true);
|
||||
SetIndexBuffer(adxMBufferIndex, adxMBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(upTBuffer, true);
|
||||
SetIndexBuffer(upTBufferIndex, upTBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(downTBuffer, true);
|
||||
SetIndexBuffer(downTBufferIndex, downTBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Custom Buffers ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int barsLimit = startCalculationForLastBars > 0
|
||||
? startCalculationForLastBars
|
||||
: 0;
|
||||
//
|
||||
// bool canCalculate = true;
|
||||
bool canCalculate =
|
||||
barsLimit == 0 ||
|
||||
bar_index <= barsLimit;
|
||||
if (canCalculate)
|
||||
{
|
||||
//
|
||||
CalculateTrend(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBuffersZero(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
upTrendBuffer[barIndex] = 0;
|
||||
downTrendBuffer[barIndex] = 0;
|
||||
|
||||
//
|
||||
maBuffer[barIndex] = 0;
|
||||
adxBuffer[barIndex] = 0;
|
||||
adxPBuffer[barIndex] = 0;
|
||||
adxMBuffer[barIndex] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Trends ...
|
||||
*
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateTrend(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
ENUM_X_PRICE mPType = ToXPrice(trendPriceType);
|
||||
double iPrice = GetAppliedPrice(
|
||||
mPType,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
|
||||
//
|
||||
double iMa = maBuffer[bar_index];
|
||||
double iAdx = adxBuffer[bar_index];
|
||||
double points = GetPoints(_Symbol);
|
||||
double points10 = 10 * points;
|
||||
|
||||
//
|
||||
bool isUpTrend =
|
||||
iPrice > iMa &&
|
||||
iAdx > adxThreshold;
|
||||
bool isDownTrend =
|
||||
iPrice < iMa &&
|
||||
iAdx > adxThreshold;
|
||||
|
||||
//
|
||||
if (isUpTrend)
|
||||
{
|
||||
//
|
||||
// double iLastValue =
|
||||
// prevCalculated <= 0
|
||||
// ? 0
|
||||
// : upTrendBuffer[bar_index + 1];
|
||||
// if (iLastValue > 0 &&
|
||||
// iValue > iLastValue)
|
||||
// {
|
||||
// iValue = iLastValue;
|
||||
// }
|
||||
|
||||
//
|
||||
double selectedValue = low[bar_index] - points10;
|
||||
|
||||
//
|
||||
double iValue =
|
||||
!IsBullish(lastTrendDir) ? selectedValue
|
||||
: !showOnlyTrendStart
|
||||
? lastValue
|
||||
: 0;
|
||||
|
||||
//
|
||||
upTrendBuffer[bar_index] = iValue;
|
||||
upTBuffer[bar_index] = selectedValue;
|
||||
|
||||
//
|
||||
downTrendBuffer[bar_index] = 0;
|
||||
|
||||
//
|
||||
lastValue = iValue;
|
||||
lastTrendDir = X_DIRECTION_BULLISH;
|
||||
}
|
||||
else if (isDownTrend)
|
||||
{
|
||||
//
|
||||
// double iLastValue =
|
||||
// prevCalculated <= 0
|
||||
// ? 0
|
||||
// : downTrendBuffer[bar_index + 1];
|
||||
// if (iLastValue > 0 &&
|
||||
// iValue < iLastValue)
|
||||
// {
|
||||
// iValue = iLastValue;
|
||||
// }
|
||||
|
||||
//
|
||||
double selectedValue = high[bar_index] + points10;
|
||||
|
||||
//
|
||||
double iValue =
|
||||
!IsBearish(lastTrendDir) ? selectedValue
|
||||
: !showOnlyTrendStart
|
||||
? lastValue
|
||||
: 0;
|
||||
|
||||
//
|
||||
upTrendBuffer[bar_index] = 0;
|
||||
downTrendBuffer[bar_index] = iValue;
|
||||
downTBuffer[bar_index] = selectedValue;
|
||||
|
||||
//
|
||||
lastValue = iValue;
|
||||
lastTrendDir = X_DIRECTION_BEARISH;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
double iValue =
|
||||
IsBullish(lastTrendDir)
|
||||
? showOnlyTrendStart
|
||||
? 0
|
||||
: lastValue
|
||||
: IsBearish(lastTrendDir)
|
||||
? showOnlyTrendStart
|
||||
? 0
|
||||
: lastValue
|
||||
: 0;
|
||||
|
||||
//
|
||||
upTrendBuffer[bar_index] = 0;
|
||||
downTrendBuffer[bar_index] = 0;
|
||||
|
||||
//
|
||||
upTBuffer[bar_index] = 0;
|
||||
downTBuffer[bar_index] = 0;
|
||||
|
||||
//
|
||||
lastValue = 0;
|
||||
lastTrendDir = X_DIRECTION_NONE;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user