Files
MQL5Data/Helpers/x-saherelm.xrsi.helper.mq5
T

392 lines
7.6 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXRSIHelper
// 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_XRSI_BUFFERS
{
XRSI_MAIN_LINE = 0
};
//
// Input Models ...
struct XRSIInputs
{
//
// Props ...
//
// Market ...
int length; // Market Length
ENUM_APPLIED_PRICE appliedTo; // Applied To
//
// Short Entry ...
double shortEntryValue; // Short Entry Level
color shortEntryColor; // Short Entry Level Color
ENUM_LINE_STYLE shortEntryLineStyle; // Short Entry Style
//
// Short Exit ...
double shortExitValue; // Short Exit Level
color shortExitColor; // Short Exit Level Color
ENUM_LINE_STYLE shortExitLineStyle; // Short Exit Style
//
// Long Entry ...
double longEntryValue; // Long Entry Level
color longEntryColor; // Long Entry Level Color
ENUM_LINE_STYLE longEntryLineStyle; // Long Entry Style
//
// Long Exit ...
double longExitValue; // Long Exit Level
color longExitColor; // Long Exit Level Color
ENUM_LINE_STYLE longExitLineStyle; // Long Exit Style
//
// Constructor(s) ...
XRSIInputs()
{
//
Clean();
}
//
// Tools ...
//
// Clean ...
void Clean()
{
//
// Market ...
length = 0;
appliedTo = PRICE_CLOSE;
//
// Short Entry ...
shortEntryValue = 0;
shortEntryColor = CLR_NONE;
shortEntryLineStyle = STYLE_DOT;
//
// Short Exit ...
shortExitValue = 0;
shortExitColor = CLR_NONE;
shortExitLineStyle = STYLE_DOT;
//
// Long Entry ...
longEntryValue = 0;
longEntryColor = CLR_NONE;
longEntryLineStyle = STYLE_DOT;
//
// Long Exit ...
longExitValue = 0;
longExitColor = CLR_NONE;
longExitLineStyle = STYLE_DOT;
}
//
// Default ...
void Default()
{
//
// Market ...
length = 14;
appliedTo = PRICE_CLOSE;
//
// Short Entry ...
shortEntryValue = 70;
shortEntryColor = CLR_NONE;
shortEntryLineStyle = STYLE_DOT;
//
// Short Exit ...
shortExitValue = 40;
shortExitColor = CLR_NONE;
shortExitLineStyle = STYLE_DOT;
//
// Long Entry ...
longEntryValue = 30;
longEntryColor = CLR_NONE;
longEntryLineStyle = STYLE_DOT;
//
// Long Exit ...
longExitValue = 60;
longExitColor = CLR_NONE;
longExitLineStyle = STYLE_DOT;
}
//
// 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 XSCXRSIHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XSCXRSIHelper() : XSCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XSCXRSIHelper() {}
//
// Tools ...
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
XRSIInputs &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.xrsi",
//
// Inputs ...
//
// Market ...
"",
mInputs.length, // Market Length
mInputs.appliedTo, // Applied To
//
// Short Entry ...
"",
mInputs.shortEntryValue, // Short Entry Level
mInputs.shortEntryColor, // Short Entry Level Color
mInputs.shortEntryLineStyle, // Short Entry Style
//
// Short Exit ...
"",
mInputs.shortExitValue, // Short Exit Level
mInputs.shortExitColor, // Short Exit Level Color
mInputs.shortExitLineStyle, // Short Exit Style
//
// Long Entry ...
"",
mInputs.longEntryValue, // Long Entry Level
mInputs.longEntryColor, // Long Entry Level Color
mInputs.longEntryLineStyle, // Long Entry Style
//
// Long Exit ...
"",
mInputs.longExitValue, // Long Exit Level
mInputs.longExitColor, // Long Exit Level Color
mInputs.longExitLineStyle // Long Exit Style
//
);
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
//
// Inputs ...
//
XRSIInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
XRSIInputs &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 ...
XRSIInputs mInputs; // Inputs ...
//
// Buffers ...
double mainBuffer[];
//
// Tools ...
//
// Calculate Values Until Now ...
void Calculate()
{
//
int totalBars = CountBars();
//
// Main ...
CopyBuffer(
mHandler,
XRSI_MAIN_LINE,
0,
totalBars,
mainBuffer
//
);
}
};
//
// Tools ...