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

519 lines
10 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXPVHelper
// Description: provides all Indicator
// Helper requirements ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// START Definitions ...
//
//
// Inputs ...
struct XPVInputs
{
//
// Makret Cycles ...
int shortLength; // Short Length
int mediumLength; // Medium Length
int longLength; // Long Length
int hindLength; // Hind Length
//
// Detection Modes ...
ENUM_SERIESMODE hhMode; // Highest High Calculation Method
ENUM_SERIESMODE llMode; // Lowest Low Calculation Method
//
// Presentation ...
bool showPeaksAndVales; // Show Peaks and Vales
bool showLevels; // Show Levels
};
//
// Index of Lines ...
enum ENUM_XPV_BUFFERS
{
//
// Main Requirements ...
XPV_PEAKS_LINE = 0,
XPV_VALES_LINE = 1,
};
//
// Retrieve Info Model ...
struct XPVInfo
{
//
// Symbol ...
string symbol;
//
// Period ...
ENUM_TIMEFRAMES period;
//
// Bar Time ...
datetime barTime;
//
// Bar Index ...
int barIndex;
//
// Values ...
double peak;
double vale;
//
// Conditions ...
//
// Determines New Peaks Happens ...
bool isNewPeak;
//
// Determines New Vales Happens ...
bool isNewVale;
};
//
// END Definitions ...
//
//
// START Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Classes/x-saherelm.xhelper.class.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
//
// a Class for Helping Indicators Requirements ...
class XSCXPVHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Buffers ...
double peaksBuffer[];
double valesBuffer[];
//
// Constructor ...
void XSCXPVHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Time Frame
XPVInputs &config // Indicator Properties ...
) : XSCBaseHelper(symbol, period)
{
//
XSCXPVHelper(symbol,
period,
config.shortLength,
config.mediumLength,
config.longLength,
config.hindLength,
config.hhMode,
config.llMode,
config.showPeaksAndVales,
config.showLevels);
}
void XSCXPVHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Time Frame
//
// Indicator Properties ...
//
// Market ...
//
// Short Length ...
int shortLength = 9,
//
// Medium Length
int mediumLength = 17,
//
// Long Length ...
int longLength = 26,
//
// Hind Length ...
int hindLength = 35,
//
// Detection Mode ...
//
// Highest High Calculation Method ...
ENUM_SERIESMODE hhMode = MODE_HIGH,
//
// Lowest Low Calculation Method ...
ENUM_SERIESMODE llMode = MODE_LOW,
//
// Presentations ...
//
// Show Peaks and Vales ...
bool showPeaksAndVales = false,
//
// Show Levels ...
bool showLevels = false
//
) : XSCBaseHelper(symbol, period)
{
//
// Indicator Properties ...
mHHMode = hhMode;
mLLMode = llMode;
mLongLength = longLength;
mHindLength = hindLength;
mShowLevels = showLevels;
mShortLength = shortLength;
mMediumLength = mediumLength;
mShowPeaksAndVales = showPeaksAndVales;
//
PrepareTag();
}
//
// Deconstructor ...
void ~XSCXPVHelper()
{
}
//
// START Properties ...
//
//
// Show Levels ...
bool ShowLevels(
bool show // Show or Hide Levels
)
{
//
bool result = false;
//
if (mShowLevels == show)
{
return true;
}
//
mShowLevels = show;
result = Init();
//
return result;
}
//
// Show Peaks and Vales ...
bool ShowPeaksAnVales(
bool show // Show or Hide Levels
)
{
//
bool result = false;
//
if (mShowPeaksAndVales == show)
{
return true;
}
//
mShowPeaksAndVales = show;
result = Init();
//
return result;
}
//
// END Properties ...
//
//
// START Provided Functions ...
//
//
// Prepare Tag ...
virtual void PrepareTag()
{
mTag = "XPV" + GetTagPrefix();
}
//
// Initial Indicator Handler ...
bool Init()
{
//
bool result = false;
//
// Validate Args ...
result =
//
(mShortLength > 2 &&
mMediumLength > mShortLength &&
mLongLength > mMediumLength &&
mHindLength > mLongLength)
//
;
if (!result)
{
return false;
}
//
// Initialize Handler ...
mHandler = iCustom(
//
mSymbol,
mPeriod,
"x-saherelm.x121.xpv",
//
// Inputs ...
//
// Market ...
"",
//
// Short Length ...
mShortLength,
//
// Medium Length
mMediumLength,
//
// Long Length ...
mLongLength,
//
// Hind Length ...
mHindLength,
//
// Detection Mode ...
"",
//
// Highest High Calculation Method ...
mHHMode,
//
// Lowest Low Calculation Method ...
mLLMode,
//
// Presentations ...
"",
//
// Show Peaks and Vales ...
mShowPeaksAndVales,
//
// Show Levels ...
mShowLevels
//
);
result = mHandler != INVALID_HANDLE;
//
return result;
}
//
// Retrieve Current Config ...
XPVInputs GetConfig()
{
//
XPVInputs result;
//
result.shortLength = mShortLength;
result.mediumLength = mMediumLength;
result.longLength = mLongLength;
result.hindLength = mHindLength;
result.hhMode = mHHMode;
result.llMode = mLLMode;
result.showPeaksAndVales = mShowPeaksAndVales;
result.showLevels = mShowLevels;
//
return result;
}
//
// Set Config ...
bool SetConfig(XPVInputs &config)
{
//
bool result = false;
//
mShortLength = config.shortLength;
mMediumLength = config.mediumLength;
mLongLength = config.longLength;
mHindLength = config.hindLength;
mHHMode = config.hhMode;
mLLMode = config.llMode;
mShowPeaksAndVales = config.showPeaksAndVales;
mShowLevels = config.showLevels;
//
result = Init();
//
return result;
}
//
// Reading Buffers based on Given Bar Index ...
void Calculate(
int barIndex // Given Bar Index
)
{
//
// PEAKS ...
ArraySetAsSeries(peaksBuffer, true);
CopyBuffer(
mHandler,
XPV_PEAKS_LINE,
barIndex,
mLoopbackBars,
peaksBuffer);
//
// VALES ...
ArraySetAsSeries(valesBuffer, true);
CopyBuffer(
mHandler,
XPV_VALES_LINE,
barIndex,
mLoopbackBars,
valesBuffer);
}
//
// Retrieve Info at Specific Bar Index ...
XPVInfo GetInfo(
int barIndex // Given Bar Index
)
{
//
XPVInfo 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.peak = peaksBuffer[barIndex];
result.vale = valesBuffer[barIndex];
//
result.isNewPeak =
peaksBuffer[barIndex] != peaksBuffer[barIndex + 1];
result.isNewVale =
valesBuffer[barIndex] != valesBuffer[barIndex + 1];
//
return result;
}
//
// END Provided Functions ...
//
//
// Protected ...
protected:
//
// Private ...
private:
//
// Indicator Properties ...
//
// Market ...
//
// Short Length ...
int mShortLength;
//
// Medium Length
int mMediumLength;
//
// Long Length ...
int mLongLength;
//
// Hind Length ...
int mHindLength;
//
// Detection Mode ...
//
// Highest High Calculation Method ...
ENUM_SERIESMODE mHHMode;
//
// Lowest Low Calculation Method ...
ENUM_SERIESMODE mLLMode;
//
// Presentations ...
//
// Show Peaks and Vales ...
bool mShowPeaksAndVales;
//
// Show Levels ...
bool mShowLevels;
};
//
// START Usefull Functions ...
//
//
// END Usefull Functions ...
//