436 lines
7.9 KiB
Plaintext
436 lines
7.9 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 ...
|
|
//
|
|
|
|
//
|
|
// 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;
|
|
|
|
//
|
|
// Peak Value ...
|
|
double peak;
|
|
|
|
//
|
|
// Vales Value ...
|
|
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
|
|
//
|
|
// 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;
|
|
|
|
//
|
|
Init();
|
|
}
|
|
|
|
//
|
|
// 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 ...
|
|
void PrepareTag()
|
|
{
|
|
mTag = "" + 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;
|
|
}
|
|
|
|
//
|
|
// Reading Buffers based on Given Bar Index ...
|
|
void Calculate(
|
|
int barIndex // Given Bar Index
|
|
)
|
|
{
|
|
//
|
|
// PEAKS ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
XPV_PEAKS_LINE,
|
|
barIndex,
|
|
mLoopbackBars,
|
|
peaksBuffer);
|
|
|
|
//
|
|
// VALES ...
|
|
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 ...
|
|
//
|