Files
xMQL5/MQLTestWorkspace/X121/Old/Helpers/x-saherelm.x121.xdema.helper.class.mq5
T
2024-05-01 14:46:50 +03:30

471 lines
7.8 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXDEMAHelper
// Description: provides all Indicator
// Helper requirements ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// START Definitions ...
//
//
// Inputs ...
struct XDEMAInputs
{
//
// Makret ...
int length; // Length
int shift; // Shift
//
// Presentation ...
bool showDema; // Show Dema
bool showEMA; // Show EMA
bool showEMAOfEMA; // Show EMA of EMA
};
//
// Index of Lines ...
enum ENUM_XDEMA_BUFFERS
{
//
// Main Requirements ...
XDEMA_LINE = 0,
XDEMA_EMA_LINE = 2,
XDEMA_EMA_OF_EMA_LINE = 4,
};
//
// Retrieve Info Model ...
struct XDEMAInfo
{
//
// Symbol ...
string symbol;
//
// Period ...
ENUM_TIMEFRAMES period;
//
// Bar Time ...
datetime barTime;
//
// Bar Index ...
int barIndex;
//
// Values ...
double dema;
double ema;
double emaOfEma;
//
double demas[];
double emas[];
double emaOfEMAs[];
//
// Conditions ...
};
//
// END Definitions ...
//
//
// START Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Classes/x-saherelm.xhelper.class.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
//
// a Class for Helping Indicators Requirements ...
class XSCXDEMAHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Buffers ...
double demaBuffer[];
double emaBuffer[];
double emaOfEMABuffer[];
//
// Constructor ...
void XSCXDEMAHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period // Trading Time Frame
) : XSCBaseHelper(symbol, period)
{
PrepareTag();
}
//
// Deconstructor ...
void ~XSCXDEMAHelper()
{
}
//
// START Properties ...
//
//
// END Properties ...
//
//
// START Provided Functions ...
//
//
// Prepare Tag ...
virtual void PrepareTag()
{
mTag = "XDEMA" + GetTagPrefix();
}
//
virtual int GetMaxLength()
{
//
int result = -1;
//
result = mLength;
//
return result;
}
//
// Initial Indicator Handler ...
bool Init()
{
//
bool result = false;
//
// Validate Args ...
result =
//
(mLength >= 2 &&
mShift >= 0)
//
;
if (!result)
{
return false;
}
//
// Initialize Handler ...
mHandler = iCustom(
//
mSymbol,
mPeriod,
"x-saherelm.x121.xdema",
//
// Inputs ...
//
// Makret ...
"",
//
// Length ...
mLength,
//
// Shift ...
mShift,
//
// Presentation ...
"",
//
// Show Dema ...
mShowDema,
//
// Show EMA ...
mShowEMA,
//
// Show EMA of EMA ...
mShowEMAOfEMA
//
);
result = mHandler != INVALID_HANDLE;
//
return result;
}
//
// Retrieve Current Config ...
XDEMAInputs GetConfig()
{
//
XDEMAInputs result;
//
result.length = mLength;
result.shift = mShift;
result.showDema = mShowDema;
result.showEMA = mShowEMA;
result.showEMAOfEMA = mShowEMAOfEMA;
//
return result;
}
//
// Set Config ...
bool SetConfig(XDEMAInputs &config)
{
//
bool result = false;
//
mLength = config.length;
mShift = config.shift;
mShowDema = config.showDema;
mShowEMA = config.showEMA;
mShowEMAOfEMA = config.showEMAOfEMA;
//
result = Init();
//
return result;
}
//
// Show Dema ...
bool ShowDema(
bool show // Show or Hide
)
{
//
bool result = false;
//
if (mShowDema == show)
{
return true;
}
//
mShowDema = show;
result = Init();
//
return result;
}
//
// Show EMA ...
bool ShowEMA(
bool show // Show or Hide
)
{
//
bool result = false;
//
if (mShowEMA == show)
{
return true;
}
//
mShowEMA = show;
result = Init();
//
return result;
}
//
// Show EMA of EMA ...
bool ShowEMAOfEMA(
bool show // Show or Hide
)
{
//
bool result = false;
//
if (mShowEMAOfEMA == show)
{
return true;
}
//
mShowEMAOfEMA = show;
result = Init();
//
return result;
}
//
// Reading Buffers based on Given Bar Index ...
virtual void Calculate(
int barIndex // Given Bar Index
)
{
//
// DEMA ...
ArraySetAsSeries(demaBuffer, true);
CopyBuffer(
mHandler,
XDEMA_LINE,
barIndex,
mLoopbackBars,
demaBuffer);
//
// EMA ...
ArraySetAsSeries(emaBuffer, true);
CopyBuffer(
mHandler,
XDEMA_EMA_LINE,
barIndex,
mLoopbackBars,
emaBuffer);
//
// EMAOFEMA ...
ArraySetAsSeries(emaOfEMABuffer, true);
CopyBuffer(
mHandler,
XDEMA_EMA_OF_EMA_LINE,
barIndex,
mLoopbackBars,
emaOfEMABuffer);
}
//
// Retrieve Info at Specific Bar Index ...
XDEMAInfo GetInfo(
int barIndex // Given Bar Index
)
{
//
XDEMAInfo result;
//
if (barIndex < 0)
{
barIndex = 0;
}
//
// Do Calculations ...
Calculate(barIndex);
//
// Generate Candle Time ...
datetime barTime = GetCandleTime(
mSymbol,
mPeriod,
barIndex);
//
// Fill Result ...
result.symbol = mSymbol;
result.period = mPeriod;
result.barTime = barTime;
result.barIndex = barIndex;
//
result.ema = emaBuffer[barIndex];
result.dema = demaBuffer[barIndex];
result.emaOfEma = emaOfEMABuffer[barIndex];
//
Copy(
emaBuffer,
result.demas);
Copy(
demaBuffer,
result.emas);
Copy(
emaOfEMABuffer,
result.emaOfEMAs);
//
return result;
}
//
// END Provided Functions ...
//
//
// Protected ...
protected:
//
// Private ...
private:
//
// Indicator Properties ...
//
// Market ...
//
// Length ...
int mLength;
//
// Shift ...
int mShift;
//
// Presentation ...
//
// Show Dema ...
bool mShowDema;
//
// Show EMA ...
bool mShowEMA;
//
// Show EMA of EMA ...
bool mShowEMAOfEMA;
};
//
// START Usefull Functions ...
//
//
// END Usefull Functions ...
//