Files
xMQL5/MQLTestWorkspace/Helpers/x-saherelm.x121.xtm.helper.class.mq5
T

440 lines
7.6 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXTMHelper
// Description: provides all Indicator
// Helper requirements ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// START Definitions ...
//
//
// Inputs ...
struct XTMInputs
{
//
// Makret ...
int length; // Length
int shift; // Shift
//
// Calculations ...
ENUM_MA_METHOD method; // Method
ENUM_APPLIED_PRICE appliedTo; // Applied To
//
// Presentation ...
bool showLine; // Show Line
};
//
// Index of Lines ...
enum ENUM_XTM_BUFFERS
{
//
// Main Requirements ...
XTM_LINE = 0,
XTM_STATE_LINE = 1,
};
//
// XTM Indicator States ...
enum ENUM_XTM_STATES
{
X_XTM_BULLISH = 0,
X_XTM_BEARISH = 2,
X_XTM_NEUTURAL = 1,
};
//
// Retrieve Info Model ...
struct XTMInfo
{
//
// Symbol ...
string symbol;
//
// Period ...
ENUM_TIMEFRAMES period;
//
// Bar Time ...
datetime barTime;
//
// Bar Index ...
int barIndex;
//
// Values ...
double value;
//
// State ...
ENUM_XTM_STATES state;
//
// Conditions ...
//
// Detect Trend is Bullish or not ...
bool isBullish;
//
// Detect Trend is Switched to Bullish Or not ...
bool isSwitchedBullish;
//
// Detect Trend is Bearish or not ...
bool isBearish;
//
// Detect Trend is Switched to Bearish Or not ...
bool isSwitchedBearish;
//
// Detect Trend is Neutural or not ...
bool isNeutural;
//
// Detect Trend is Switched to Neutural Or not ...
bool isSwitchedNeutural;
};
//
// END Definitions ...
//
//
// START Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Classes/x-saherelm.xhelper.class.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
//
// a Class for Helping Indicators Requirements ...
class XSCXTMHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Buffers ...
double valueBuffer[];
double stateBuffer[];
//
// Constructor ...
void XSCXTMHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period // Trading Time Frame
) : XSCBaseHelper(symbol, period)
{
PrepareTag();
}
//
// Deconstructor ...
void ~XSCXTMHelper()
{
}
//
// START Properties ...
//
//
// END Properties ...
//
//
// START Provided Functions ...
//
//
// Prepare Tag ...
virtual void PrepareTag()
{
mTag = "XTM" + GetTagPrefix();
}
//
virtual int GetMaxLength()
{
//
int result = -1;
//
result = mLength;
//
return result;
}
//
// Initial Indicator Handler ...
bool Init()
{
//
bool result = false;
//
// Validate Args ...
result =
//
(mLength >= 2)
//
;
if (!result)
{
return false;
}
//
// Initialize Handler ...
mHandler = iCustom(
//
mSymbol,
mPeriod,
"x-saherelm.x121.xtm",
//
// Inputs ...
//
// Makret ...
"",
//
// Length ...
mLength,
//
// Shift ...
mShift,
//
// Calculations ...
"",
//
// Method ...
mMethod,
//
// Applied To ...
mAppliedTo,
//
// Presentation ...
"",
//
// Show Line ...
mShowLine
//
);
result = mHandler != INVALID_HANDLE;
//
return result;
}
//
// Retrieve Current Config ...
XTMInputs GetConfig()
{
//
XTMInputs result;
//
result.length = mLength;
result.shift = mShift;
result.method = mMethod;
result.appliedTo = mAppliedTo;
result.showLine = mShowLine;
//
return result;
}
//
// Set Config ...
bool SetConfig(XTMInputs &config)
{
//
bool result = false;
//
mLength = config.length;
mShift = config.shift;
mMethod = config.method;
mAppliedTo = config.appliedTo;
mShowLine = config.showLine;
//
result = Init();
//
return result;
}
//
// Reading Buffers based on Given Bar Index ...
virtual void Calculate(
int barIndex // Given Bar Index
)
{
//
// VALUE ...
ArraySetAsSeries(valueBuffer, true);
CopyBuffer(
mHandler,
XTM_LINE,
barIndex,
mLoopbackBars,
valueBuffer);
//
// STATE ...
ArraySetAsSeries(stateBuffer, true);
CopyBuffer(
mHandler,
XTM_STATE_LINE,
barIndex,
mLoopbackBars,
stateBuffer);
}
//
// Retrieve Info at Specific Bar Index ...
XTMInfo GetInfo(
int barIndex // Given Bar Index
)
{
//
XTMInfo result;
//
if (barIndex < 0)
{
return result;
}
//
barIndex--;
if (barIndex < 0) {
barIndex = 0;
}
//
// Do Calculations ...
Calculate(barIndex);
//
// Generate Candle Time ...
datetime barTime = GetCandleTime(
mSymbol,
mPeriod,
barIndex);
//
// Fill Result ...
result.symbol = mSymbol;
result.period = mPeriod;
result.barTime = barTime;
result.barIndex = barIndex;
//
result.value = valueBuffer[barIndex];
//
ENUM_XTM_STATES state = (ENUM_XTM_STATES)stateBuffer[barIndex];
ENUM_XTM_STATES prevState = (ENUM_XTM_STATES)stateBuffer[barIndex + 1];
result.state = state;
//
result.isBullish = state == X_XTM_BULLISH;
result.isBearish = state == X_XTM_BEARISH;
result.isNeutural = state == X_XTM_NEUTURAL;
//
result.isSwitchedBullish =
state == X_XTM_BULLISH && prevState != X_XTM_BULLISH;
result.isSwitchedBearish =
state == X_XTM_BEARISH && prevState != X_XTM_BEARISH;
result.isSwitchedNeutural =
state == X_XTM_NEUTURAL && prevState != X_XTM_NEUTURAL;
//
return result;
}
//
// END Provided Functions ...
//
//
// Protected ...
protected:
//
// Private ...
private:
//
// Indicator Properties ...
//
// Makret ...
//
// Length ...
int mLength;
//
// Shift ...
int mShift;
//
// Calculations ...
//
// Method ...
ENUM_MA_METHOD mMethod;
//
// Applied To ...
ENUM_APPLIED_PRICE mAppliedTo;
//
// Presentation ...
//
// Show Line ...
bool mShowLine;
};
//
// START Usefull Functions ...
//
//
// END Usefull Functions ...
//