645 lines
12 KiB
Plaintext
645 lines
12 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
|
|
double fiboLevel1; // Fibio 1st Level
|
|
double fiboLevel2; // Fibio 2st Level
|
|
double fiboLevel3; // Fibio 3rd Level
|
|
|
|
//
|
|
// 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
|
|
bool showFibo1Levels; // Show Fibo 1st Level
|
|
bool showFibo2Levels; // Show Fibo 2nd Level
|
|
bool showFibo3Levels; // Show Fibo 3rd Level
|
|
};
|
|
|
|
//
|
|
// Index of Lines ...
|
|
enum ENUM_XPV_BUFFERS
|
|
{
|
|
//
|
|
// Main Requirements ...
|
|
XPV_PEAKS_LINE = 0,
|
|
XPV_VALES_LINE = 1,
|
|
XPV_FL1_LINE = 6,
|
|
XPV_FL2_LINE = 8,
|
|
XPV_FL3_LINE = 10,
|
|
};
|
|
|
|
//
|
|
// 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;
|
|
double fl1;
|
|
double fl2;
|
|
double fl3;
|
|
|
|
//
|
|
// 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[];
|
|
double fl1Buffer[];
|
|
double fl2Buffer[];
|
|
double fl3Buffer[];
|
|
|
|
//
|
|
// Constructor ...
|
|
void XSCXPVHelper(
|
|
string symbol, // Trading Symbol
|
|
ENUM_TIMEFRAMES period // Trading Time Frame
|
|
) : XSCBaseHelper(symbol, period)
|
|
{
|
|
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;
|
|
}
|
|
|
|
//
|
|
// Show Fibo 1st Level ...
|
|
bool ShowFibo1Levels(
|
|
bool show // Show or Hide Levels
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (mShowFibo1Levels == show)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
//
|
|
mShowFibo1Levels = show;
|
|
result = Init();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Show Fibo 2nd Level ...
|
|
bool ShowFibo2Levels(
|
|
bool show // Show or Hide Levels
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (mShowFibo2Levels == show)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
//
|
|
mShowFibo2Levels = show;
|
|
result = Init();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Show Fibo 3rd Level ...
|
|
bool ShowFibo3Levels(
|
|
bool show // Show or Hide Levels
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (mShowFibo3Levels == show)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
//
|
|
mShowFibo3Levels = show;
|
|
result = Init();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// END Properties ...
|
|
//
|
|
|
|
//
|
|
// START Provided Functions ...
|
|
//
|
|
|
|
//
|
|
// Prepare Tag ...
|
|
virtual void PrepareTag()
|
|
{
|
|
mTag = "XPV" + GetTagPrefix();
|
|
}
|
|
|
|
//
|
|
virtual int GetMaxLength()
|
|
{
|
|
//
|
|
int result = -1;
|
|
|
|
//
|
|
result = MathMax(mShortLength, mMediumLength);
|
|
result = MathMax(result, mLongLength);
|
|
result = MathMax(result, mHindLength);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// 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,
|
|
//
|
|
// Fibio 1st Level ...
|
|
mFiboLevel1,
|
|
//
|
|
// Fibio 2st Level ...
|
|
mFiboLevel2,
|
|
//
|
|
// Fibio 3rd Level ...
|
|
mFiboLevel3,
|
|
//
|
|
// Detection Mode ...
|
|
"",
|
|
//
|
|
// Highest High Calculation Method ...
|
|
mHHMode,
|
|
//
|
|
// Lowest Low Calculation Method ...
|
|
mLLMode,
|
|
//
|
|
// Presentations ...
|
|
"",
|
|
//
|
|
// Show Peaks and Vales ...
|
|
mShowPeaksAndVales,
|
|
//
|
|
// Show Levels ...
|
|
mShowLevels,
|
|
//
|
|
// Show Fibo 1st Level ...
|
|
mShowFibo1Levels,
|
|
//
|
|
// Show Fibo 2nd Level ...
|
|
mShowFibo2Levels,
|
|
//
|
|
// Show Fibo 3rd Level ...
|
|
mShowFibo3Levels
|
|
//
|
|
);
|
|
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.fiboLevel1 = mFiboLevel1;
|
|
result.fiboLevel2 = mFiboLevel2;
|
|
result.fiboLevel3 = mFiboLevel3;
|
|
result.hhMode = mHHMode;
|
|
result.llMode = mLLMode;
|
|
result.showPeaksAndVales = mShowPeaksAndVales;
|
|
result.showLevels = mShowLevels;
|
|
result.showFibo1Levels = mShowFibo1Levels;
|
|
result.showFibo2Levels = mShowFibo2Levels;
|
|
result.showFibo3Levels = mShowFibo3Levels;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Set Config ...
|
|
bool SetConfig(XPVInputs &config)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
mShortLength = config.shortLength;
|
|
mMediumLength = config.mediumLength;
|
|
mLongLength = config.longLength;
|
|
mHindLength = config.hindLength;
|
|
mFiboLevel1 = config.fiboLevel1;
|
|
mFiboLevel2 = config.fiboLevel2;
|
|
mFiboLevel3 = config.fiboLevel3;
|
|
mHHMode = config.hhMode;
|
|
mLLMode = config.llMode;
|
|
mShowPeaksAndVales = config.showPeaksAndVales;
|
|
mShowLevels = config.showLevels;
|
|
mShowFibo1Levels = config.showFibo1Levels;
|
|
mShowFibo2Levels = config.showFibo2Levels;
|
|
mShowFibo3Levels = config.showFibo3Levels;
|
|
|
|
//
|
|
result = Init();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Reading Buffers based on Given Bar Index ...
|
|
virtual 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);
|
|
|
|
//
|
|
// FIBBO LEVELS ...
|
|
|
|
//
|
|
// LEVEL 1 ...
|
|
ArraySetAsSeries(fl1Buffer, true);
|
|
CopyBuffer(
|
|
mHandler,
|
|
XPV_FL1_LINE,
|
|
barIndex,
|
|
mLoopbackBars,
|
|
fl1Buffer);
|
|
|
|
//
|
|
// LEVEL 2 ...
|
|
ArraySetAsSeries(fl2Buffer, true);
|
|
CopyBuffer(
|
|
mHandler,
|
|
XPV_FL2_LINE,
|
|
barIndex,
|
|
mLoopbackBars,
|
|
fl2Buffer);
|
|
|
|
//
|
|
// LEVEL 3 ...
|
|
ArraySetAsSeries(fl3Buffer, true);
|
|
CopyBuffer(
|
|
mHandler,
|
|
XPV_FL3_LINE,
|
|
barIndex,
|
|
mLoopbackBars,
|
|
fl3Buffer);
|
|
}
|
|
|
|
//
|
|
// Retrieve Info at Specific Bar Index ...
|
|
XPVInfo GetInfo(
|
|
int barIndex // Given Bar Index
|
|
)
|
|
{
|
|
//
|
|
XPVInfo 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.peak = peaksBuffer[barIndex];
|
|
result.vale = valesBuffer[barIndex];
|
|
result.fl1 = fl1Buffer[barIndex];
|
|
result.fl2 = fl2Buffer[barIndex];
|
|
result.fl3 = fl3Buffer[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;
|
|
//
|
|
// Fibio 1st Level ...
|
|
double mFiboLevel1;
|
|
//
|
|
// Fibio 2st Level ...
|
|
double mFiboLevel2;
|
|
//
|
|
// Fibio 3rd Level ...
|
|
double mFiboLevel3;
|
|
//
|
|
// 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;
|
|
//
|
|
// Show Fibo 1st Level ...
|
|
bool mShowFibo1Levels;
|
|
//
|
|
// Show Fibo 2nd Level ...
|
|
bool mShowFibo2Levels;
|
|
//
|
|
// Show Fibo 3rd Level ...
|
|
bool mShowFibo3Levels;
|
|
};
|
|
|
|
//
|
|
// START Usefull Functions ...
|
|
//
|
|
|
|
//
|
|
// END Usefull Functions ...
|
|
//
|