Files
xMQL5/MQLTestWorkspace/BKPS/BKP/Constructor Issues/Helpers/x-saherelm.x121.xama.helper.class.mq5
T

471 lines
8.8 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXAMAHelper
// Description: provides all Indicator
// Helper requirements ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// START Definitions ...
//
//
// Inputs ...
struct XAMAInputs
{
//
// Makret ...
int length; // Length
int fastEMA; // Fast EMA Length
int slowEMA; // Slow EMA Length
int maShift; // Shift
ENUM_APPLIED_PRICE appliedTo; // Applied To
//
// Presentation ...
bool showLine; // Show Line
};
//
// Index of Lines ...
enum ENUM_XAMA_BUFFERS
{
//
// Main Requirements ...
XAMA_LINE = 0,
XAMA_STATE_LINE = 1,
};
//
// XAMA Indicator States ...
enum ENUM_XAMA_STATES
{
X_XAMA_BULLISH = 0,
X_XAMA_BEARISH = 2,
X_XAMA_NEUTURAL = 1,
};
//
// Retrieve Info Model ...
struct XAMAInfo
{
//
// Symbol ...
string symbol;
//
// Period ...
ENUM_TIMEFRAMES period;
//
// Bar Time ...
datetime barTime;
//
// Bar Index ...
int barIndex;
//
// Values ...
double value;
//
// State ...
ENUM_XAMA_STATES state;
//
// Conditions ...
//
// Detect Trend is Bullish or not ...
bool isBullish;
//
// Detect Trend is Switched to Bullish Or not ...
bool isSwitchedBullish;
//
// Detect Trend is Bearish or not ...
bool isBearish;
//
// Detect Trend is Switched to Bearish Or not ...
bool isSwitchedBearish;
//
// Detect Trend is Neutural or not ...
bool isNeutural;
//
// Detect Trend is Switched to Neutural Or not ...
bool isSwitchedNeutural;
};
//
// END Definitions ...
//
//
// START Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Classes/x-saherelm.xhelper.class.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
//
// a Class for Helping Indicators Requirements ...
class XSCXAMAHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Buffers ...
double valueBuffer[];
double stateBuffer[];
//
// Constructor ...
void XSCXAMAHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Time Frame
XAMAInputs &config // Indicator Properties ...
) : XSCBaseHelper(symbol, period)
{
//
XSCXAMAHelper(symbol,
period,
config.length,
config.fastEMA,
config.slowEMA,
config.maShift,
config.appliedTo,
config.showLine);
}
void XSCXAMAHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Time Frame
//
// Indicator Properties ...
//
// Market ...
//
// Length ...
int length = 52,
//
// Fast EMA Length ...
int fastEMA = 2,
//
// Slow EMA Length ...
int slowEMA = 30,
//
// Shift ...
int maShift = 0,
//
// Applied To ...
ENUM_APPLIED_PRICE appliedTo = PRICE_LOW,
//
// Presentation ...
//
// Show Line ...
bool showLine = true
//
) : XSCBaseHelper(symbol, period)
{
//
// Indicator Properties ...
mLength = length;
mFastEMA = fastEMA;
mSlowEMA = slowEMA;
mMaShift = maShift;
mShowLine = showLine;
mAppliedTo = appliedTo;
//
PrepareTag();
}
//
// Deconstructor ...
void ~XSCXAMAHelper()
{
}
//
// START Properties ...
//
//
// END Properties ...
//
//
// START Provided Functions ...
//
//
// Prepare Tag ...
virtual void PrepareTag()
{
mTag = "XAMA" + GetTagPrefix();
}
//
// Initial Indicator Handler ...
bool Init()
{
//
bool result = false;
//
// Validate Args ...
result =
//
(mLength >= 2)
//
;
if (!result)
{
return false;
}
//
// Initialize Handler ...
mHandler = iCustom(
//
mSymbol,
mPeriod,
"x-saherelm.x121.xama",
//
// Inputs ...
//
// Makret ...
"",
//
// Length ...
mLength,
//
// Fast EMA Length ...
mFastEMA,
//
// Slow EMA Length ...
mSlowEMA,
//
// Shift ...
mMaShift,
//
// Applied To ...
mAppliedTo,
//
// Presentation ...
"",
//
// Show Line ...
mShowLine
//
);
result = mHandler != INVALID_HANDLE;
//
return result;
}
//
// Retrieve Current Config ...
XAMAInputs GetConfig()
{
//
XAMAInputs result;
//
result.length = mLength;
result.fastEMA = mFastEMA;
result.slowEMA = mSlowEMA;
result.maShift = mMaShift;
result.appliedTo = mAppliedTo;
result.showLine = mShowLine;
//
return result;
}
//
// Set Config ...
bool SetConfig(XAMAInputs &config)
{
//
bool result = false;
//
mLength = config.length;
mFastEMA = config.fastEMA;
mSlowEMA = config.slowEMA;
mMaShift = config.maShift;
mAppliedTo = config.appliedTo;
mShowLine = config.showLine;
//
result = Init();
//
return result;
}
//
// Reading Buffers based on Given Bar Index ...
void Calculate(
int barIndex // Given Bar Index
)
{
//
// VALUE ...
ArraySetAsSeries(valueBuffer, true);
CopyBuffer(
mHandler,
XAMA_LINE,
barIndex,
mLoopbackBars,
valueBuffer);
//
// STATE ...
ArraySetAsSeries(stateBuffer, true);
CopyBuffer(
mHandler,
XAMA_STATE_LINE,
barIndex,
mLoopbackBars,
stateBuffer);
}
//
// Retrieve Info at Specific Bar Index ...
XAMAInfo GetInfo(
int barIndex // Given Bar Index
)
{
//
XAMAInfo result;
//
if (barIndex < 0)
{
return result;
}
//
// 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_XAMA_STATES state = (ENUM_XAMA_STATES)stateBuffer[barIndex];
ENUM_XAMA_STATES prevState = (ENUM_XAMA_STATES)stateBuffer[barIndex + 1];
result.state = state;
//
result.isBullish = state == X_XAMA_BULLISH;
result.isBearish = state == X_XAMA_BEARISH;
result.isNeutural = state == X_XAMA_NEUTURAL;
//
result.isSwitchedBullish =
state == X_XAMA_BULLISH && prevState != X_XAMA_BULLISH;
result.isSwitchedBearish =
state == X_XAMA_BEARISH && prevState != X_XAMA_BEARISH;
result.isSwitchedNeutural =
state == X_XAMA_NEUTURAL && prevState != X_XAMA_NEUTURAL;
//
return result;
}
//
// END Provided Functions ...
//
//
// Protected ...
protected:
//
// Private ...
private:
//
// Indicator Properties ...
//
// Market ...
//
// Length ...
int mLength;
//
// Fast EMA Length ...
int mFastEMA;
//
// Slow EMA Length ...
int mSlowEMA;
//
// Shift ...
int mMaShift;
//
// Applied To ...
ENUM_APPLIED_PRICE mAppliedTo;
//
// Presentation ...
//
// Show Line ...
bool mShowLine;
};
//
// START Usefull Functions ...
//
//
// END Usefull Functions ...
//