498 lines
9.0 KiB
Plaintext
498 lines
9.0 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 Helper Class Library
|
|
// ----------------------------------------------
|
|
// Name: XSCXMCHelper
|
|
// 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
|
|
|
|
//
|
|
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
|
|
|
//
|
|
// Definitions ...
|
|
|
|
//
|
|
enum ENUM_XMC_BUFFERS
|
|
{
|
|
X_MC_FAST_LINE = 0,
|
|
X_MC_SLOW_LINE = 1,
|
|
X_MC_VERIFIER_LINE = 2,
|
|
};
|
|
|
|
//
|
|
// Input Models ...
|
|
struct XMCInputs
|
|
{
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
// Market ...
|
|
|
|
//
|
|
// Fast ...
|
|
int fastLength; // Length
|
|
int fastShift; // Shift
|
|
ENUM_MA_METHOD fastMethod; // Method
|
|
ENUM_APPLIED_PRICE fastAppliedTo; // Applied To
|
|
|
|
//
|
|
// Slow ...
|
|
int slowLength; // Length
|
|
int slowShift; // Shift
|
|
ENUM_MA_METHOD slowMethod; // Method
|
|
ENUM_APPLIED_PRICE slowAppliedTo; // Applied To
|
|
|
|
//
|
|
// Verifier ...
|
|
int verifierLength; // Length
|
|
int verifierShift; // Shift
|
|
ENUM_MA_METHOD verifierMethod; // Method
|
|
ENUM_APPLIED_PRICE verifierAppliedTo; // Applied To
|
|
|
|
//
|
|
// Presentation ...
|
|
bool showFastMa; // Show Fast
|
|
bool showSlowMa; // Show Slow
|
|
bool showVerifierMa; // Show Verifier
|
|
|
|
//
|
|
// Constructor(s) ...
|
|
XMCInputs()
|
|
{
|
|
//
|
|
Clean();
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
|
|
//
|
|
// Clean ...
|
|
void Clean()
|
|
{
|
|
//
|
|
fastLength = 0;
|
|
fastShift = 0;
|
|
fastMethod = 0;
|
|
fastAppliedTo = PRICE_CLOSE;
|
|
|
|
//
|
|
slowLength = 0;
|
|
slowShift = 0;
|
|
slowMethod = 0;
|
|
slowAppliedTo = PRICE_CLOSE;
|
|
|
|
//
|
|
verifierLength = 0;
|
|
verifierShift = 0;
|
|
verifierMethod = 0;
|
|
verifierAppliedTo = PRICE_CLOSE;
|
|
|
|
//
|
|
showFastMa = false;
|
|
showSlowMa = false;
|
|
showVerifierMa = false;
|
|
}
|
|
|
|
//
|
|
// Default ...
|
|
void Default()
|
|
{
|
|
//
|
|
fastLength = 9;
|
|
fastShift = 0;
|
|
fastMethod = MODE_EMA;
|
|
fastAppliedTo = PRICE_CLOSE;
|
|
|
|
//
|
|
slowLength = 18;
|
|
slowShift = 0;
|
|
slowMethod = MODE_EMA;
|
|
slowAppliedTo = PRICE_CLOSE;
|
|
|
|
//
|
|
verifierLength = 200;
|
|
verifierShift = 0;
|
|
verifierMethod = MODE_EMA;
|
|
verifierAppliedTo = PRICE_CLOSE;
|
|
|
|
//
|
|
showFastMa = true;
|
|
showSlowMa = true;
|
|
showVerifierMa = true;
|
|
}
|
|
|
|
//
|
|
// Validate ...
|
|
bool IsValid()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result =
|
|
//
|
|
fastLength > 1 &&
|
|
slowLength > fastLength &&
|
|
verifierLength > slowLength
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Retrieve MAx Length ...
|
|
int Max()
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
result = MathMax(fastLength, slowLength);
|
|
result = MathMax(result, verifierLength);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
};
|
|
|
|
//
|
|
// Class ...
|
|
class XSCXMCHelper : public XSCBaseHelper
|
|
{
|
|
//
|
|
// Public ...
|
|
public:
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
// Constructors ...
|
|
XSCXMCHelper() : XSCBaseHelper(_Symbol, _Period)
|
|
{
|
|
}
|
|
|
|
//
|
|
// Deconstructor ...
|
|
~XSCXMCHelper() {}
|
|
|
|
//
|
|
// Tools ...
|
|
bool Init(
|
|
string symbol, // Trading Symbol
|
|
ENUM_TIMEFRAMES period, // Trading Period
|
|
XMCInputs &inputs // Inputs
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
mSymbol = symbol;
|
|
mPeriod = period;
|
|
|
|
//
|
|
result = inputs.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
mInputs = inputs;
|
|
|
|
//
|
|
ArraySetAsSeries(fastBuffer, true);
|
|
ArraySetAsSeries(slowBuffer, true);
|
|
ArraySetAsSeries(verifierBuffer, true);
|
|
mHandler = iCustom(
|
|
mSymbol,
|
|
mPeriod,
|
|
"x-saherelm.xmc",
|
|
//
|
|
// Inputs ...
|
|
//
|
|
// Fast ...
|
|
"",
|
|
mInputs.fastLength,
|
|
mInputs.fastShift,
|
|
mInputs.fastMethod,
|
|
mInputs.fastAppliedTo,
|
|
//
|
|
// Slow ...
|
|
"",
|
|
mInputs.slowLength,
|
|
mInputs.slowShift,
|
|
mInputs.slowMethod,
|
|
mInputs.slowAppliedTo,
|
|
//
|
|
// Verifier ...
|
|
"",
|
|
mInputs.verifierLength,
|
|
mInputs.verifierShift,
|
|
mInputs.verifierMethod,
|
|
mInputs.verifierAppliedTo,
|
|
//
|
|
// Presentation ...
|
|
"",
|
|
mInputs.showFastMa, // Show Fast,
|
|
mInputs.showSlowMa, // Show Slow,
|
|
mInputs.showVerifierMa // Show Verifier
|
|
//
|
|
);
|
|
result = mHandler != INVALID_HANDLE;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Inputs ...
|
|
|
|
//
|
|
XMCInputs GetInputs()
|
|
{
|
|
return mInputs;
|
|
}
|
|
|
|
//
|
|
bool SetInputs(
|
|
XMCInputs &inputs // Configs
|
|
)
|
|
{
|
|
//
|
|
return Init(
|
|
mSymbol,
|
|
mPeriod,
|
|
inputs);
|
|
}
|
|
|
|
//
|
|
// Buffers ...
|
|
|
|
//
|
|
// Fast ...
|
|
|
|
//
|
|
double GetFast(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
return fastBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
// Copy Required Buffer ...
|
|
int CopyFast(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceClean = true // Force To Clean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate();
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
start,
|
|
count,
|
|
fastBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Slow ...
|
|
|
|
//
|
|
double GetSlow(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
return slowBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
// Copy Required Buffer ...
|
|
int CopySlow(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceClean = true // Force To Clean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate();
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
start,
|
|
count,
|
|
slowBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Verifier ...
|
|
|
|
//
|
|
double GetVerifier(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
return verifierBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
// Copy Required Buffer ...
|
|
int CopyVerifier(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceClean = true // Force To Clean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate();
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
start,
|
|
count,
|
|
verifierBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Protected ...
|
|
protected:
|
|
//
|
|
// Private ...
|
|
private:
|
|
//
|
|
// Props ...
|
|
XMCInputs mInputs; // Inputs ...
|
|
|
|
//
|
|
// Buffers ...
|
|
//
|
|
double fastBuffer[];
|
|
double slowBuffer[];
|
|
double verifierBuffer[];
|
|
|
|
//
|
|
// Tools ...
|
|
|
|
//
|
|
// Calculate Values Until Now ...
|
|
void Calculate()
|
|
{
|
|
//
|
|
int totalBars = CountBars();
|
|
int calculatedBars = CountCalculatedBars();
|
|
|
|
//
|
|
// Fast ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X_MC_FAST_LINE,
|
|
0,
|
|
totalBars,
|
|
fastBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// Slow ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X_MC_SLOW_LINE,
|
|
0,
|
|
totalBars,
|
|
slowBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// Verifier ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X_MC_VERIFIER_LINE,
|
|
0,
|
|
totalBars,
|
|
verifierBuffer
|
|
//
|
|
);
|
|
}
|
|
};
|
|
|
|
//
|
|
// Tools ...
|