Files
2024-05-28 08:03:47 +03:30

292 lines
4.7 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXFIHelper
// 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_XFI_BUFFERS
{
XFI_MAIN_LINE = 0
};
//
// Input Models ...
struct XFIInputs
{
//
// Props ...
int length; // Length
ENUM_MA_METHOD method; // MA Method
ENUM_APPLIED_VOLUME appliedTo; // Applied To
//
// Constructor(s) ...
XFIInputs()
{
//
Clean();
}
//
// Tools ...
//
// Clean ...
void Clean()
{
//
length = 0;
method = MODE_SMA;
appliedTo = VOLUME_TICK;
}
//
// Default ...
void Default()
{
//
length = 18;
method = MODE_SMA;
appliedTo = VOLUME_TICK;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
length >= 2
//
;
//
return result;
}
//
// Retrieve MAx Length ...
int Max()
{
//
int result = 0;
//
result = MathMax(result, length);
//
return result;
}
};
//
// Class ...
class XSCXFIHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XSCXFIHelper() : XSCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XSCXFIHelper() {}
//
// Tools ...
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
XFIInputs &inputs // Inputs
)
{
//
bool result = false;
//
mSymbol = symbol;
mPeriod = period;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
mInputs = inputs;
//
ArraySetAsSeries(mainBuffer, true);
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.xfi",
//
// Inputs ...
mInputs.length, // Length
mInputs.method, // MA Method
mInputs.appliedTo // Applied To
//
);
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
//
// Inputs ...
//
XFIInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
XFIInputs &inputs // Configs
)
{
//
return Init(
mSymbol,
mPeriod,
inputs
//
);
}
//
// Buffers ...
//
double GetMain(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(mainBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return mainBuffer[barIndex];
}
//
// Copy Required Items ...
int CopyMain(
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,
mainBuffer,
buffer,
forceClean
//
);
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
XFIInputs mInputs; // Inputs ...
//
// Buffers ...
double mainBuffer[];
//
// Tools ...
//
// Calculate Values Until Now ...
void Calculate()
{
//
int totalBars = CountBars();
//
// Short Exit 2 ...
CopyBuffer(
mHandler,
XFI_MAIN_LINE,
0,
totalBars,
mainBuffer
//
);
}
};
//
// Tools ...