Files
xMQL5/MQLTestWorkspace/BKPS/14030308/Helpers/x-saherelm.xts.helper.mq5
T
2024-05-28 08:03:47 +03:30

550 lines
11 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXTSHelper
// 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
//
// Imports ...
#include "../Classes/x-saherelm.xhelper.class.mq5"
//
// Definitions ...
//
enum ENUM_XTS_BUFFERS
{
XTS_CURRENT_LINE = 0,
XTS_NEAREST_LINE = 1,
XTS_MEDIEST_LINE = 2,
XTS_FAREST_LINE = 3,
};
//
// Input Models ...
struct XTSInputs
{
//
// Props ...
//
// Current Period ...
ENUM_APPLIED_PRICE currentAppliedTo; // Current Applied To
//
// Nearest Period ...
ENUM_X_PERIOD_METHOD nearestMethod; // How to Find Nearest Period
ENUM_TIMEFRAMES nearestPeriod; // Nearest Time Frame
ENUM_APPLIED_PRICE nearestAppliedTo; // Nearest Applied To
//
// Mediest Period ...
ENUM_X_PERIOD_METHOD mediestMethod; // How to Find Mediest Period
ENUM_TIMEFRAMES mediestPeriod; // Mediest Time Frame
ENUM_APPLIED_PRICE mediestAppliedTo; // Mediest Applied To
//
// Farest Period ...
ENUM_X_PERIOD_METHOD farestMethod; // How to Find Farest Period
ENUM_TIMEFRAMES farestPeriod; // Farest Time Frame
ENUM_APPLIED_PRICE farestAppliedTo; // Farest Applied To
//
// Constructor(s) ...
XTSInputs()
{
//
Clean();
}
//
// Tools ...
//
// Clean ...
void Clean()
{
//
// Current Period ...
currentAppliedTo = PRICE_CLOSE;
//
// Nearest Period ...
nearestMethod = X_PERIOD_NOTHING;
nearestPeriod = NULL;
nearestAppliedTo = PRICE_CLOSE;
//
// Mediest Period ...
mediestMethod = X_PERIOD_NOTHING;
mediestPeriod = NULL;
mediestAppliedTo = PRICE_CLOSE;
//
// Farest Period ...
farestMethod = X_PERIOD_NOTHING;
farestPeriod = NULL;
farestAppliedTo = PRICE_CLOSE;
}
//
// Default ...
void Default()
{
//
// Current Period ...
currentAppliedTo = PRICE_CLOSE;
//
// Nearest Period ...
nearestMethod = X_PERIOD_AUTO;
nearestPeriod = NULL;
nearestAppliedTo = PRICE_CLOSE;
//
// Mediest Period ...
mediestMethod = X_PERIOD_AUTO;
mediestPeriod = NULL;
mediestAppliedTo = PRICE_CLOSE;
//
// Farest Period ...
farestMethod = X_PERIOD_AUTO;
farestPeriod = NULL;
farestAppliedTo = PRICE_CLOSE;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
IsValid(nearestMethod, nearestPeriod) &&
IsValid(mediestMethod, mediestPeriod) &&
IsValid(farestMethod, farestPeriod)
//
;
//
return result;
}
//
// Retrieve MAx Length ...
int Max()
{
//
int result = 0;
//
result = MathMax(result, 0);
//
return result;
}
};
//
// Class ...
class XSCXTSHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XSCXTSHelper() : XSCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XSCXTSHelper() {}
//
// Tools ...
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
XTSInputs &inputs // Inputs
)
{
//
bool result = false;
//
mSymbol = symbol;
mPeriod = period;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
mInputs = inputs;
//
ArraySetAsSeries(currentBuffer, true);
ArraySetAsSeries(nearestBuffer, true);
ArraySetAsSeries(mediestBuffer, true);
ArraySetAsSeries(farestBuffer, true);
//
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.xts",
//
// Inputs ...
//
// Current Period ...
"",
mInputs.currentAppliedTo, // Current Applied To
//
// Nearest Period ...
"",
mInputs.nearestMethod, // How to Find Nearest Period
mInputs.nearestPeriod, // Nearest Time Frame
mInputs.nearestAppliedTo, // Nearest Applied To
//
// Mediest Period ...
"",
mInputs.mediestMethod, // How to Find Mediest Period
mInputs.mediestPeriod, // Mediest Time Frame
mInputs.mediestAppliedTo, // Mediest Applied To
//
// Farest Period ...
"",
mInputs.farestMethod, // How to Find Farest Period
mInputs.farestPeriod, // Farest Time Frame
mInputs.farestAppliedTo // Farest Applied To
//
);
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
//
// Inputs ...
//
XTSInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
XTSInputs &inputs // Configs
)
{
//
return Init(
mSymbol,
mPeriod,
inputs
//
);
}
//
// Buffers ...
//
double GetCurrent(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(currentBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return currentBuffer[barIndex];
}
//
// Copy Required Items ...
int CopyCurrent(
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,
currentBuffer,
buffer,
forceClean
//
);
}
//
double GetNearest(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(nearestBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return nearestBuffer[barIndex];
}
//
// Copy Required Items ...
int CopyNearest(
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,
nearestBuffer,
buffer,
forceClean
//
);
}
//
double GetMediest(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(mediestBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return mediestBuffer[barIndex];
}
//
// Copy Required Items ...
int CopyMediest(
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,
mediestBuffer,
buffer,
forceClean
//
);
}
//
double GetFarest(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(farestBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return farestBuffer[barIndex];
}
//
// Copy Required Items ...
int CopyFarest(
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,
farestBuffer,
buffer,
forceClean
//
);
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
XTSInputs mInputs; // Inputs ...
//
// Buffers ...
double currentBuffer[];
double nearestBuffer[];
double mediestBuffer[];
double farestBuffer[];
//
// Tools ...
//
// Calculate Values Until Now ...
void Calculate()
{
//
int totalBars = CountBars();
//
// Current ...
CopyBuffer(
mHandler,
XTS_CURRENT_LINE,
0,
totalBars,
currentBuffer
//
);
//
// Nearest ...
CopyBuffer(
mHandler,
XTS_NEAREST_LINE,
0,
totalBars,
nearestBuffer
//
);
//
// Mediest ...
CopyBuffer(
mHandler,
XTS_MEDIEST_LINE,
0,
totalBars,
mediestBuffer
//
);
//
// Farest ...
CopyBuffer(
mHandler,
XTS_FAREST_LINE,
0,
totalBars,
farestBuffer
//
);
}
};
//
// Tools ...