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

422 lines
6.9 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXSTRHelper
// 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_XSTR_BUFFERS
{
X_STR_TREND_LINE = 0,
X_STR_STATE_LINE = 5,
};
//
enum ENUM_XSTR_TREND_STATES
{
X_STR_BULLISH = 1, // Bullish
X_STR_BEARISH = -1, // Bearish
};
//
// Input Models ...
struct XSTRInputs
{
//
// Props ...
//
// Market ...
int length; // Length
double multiplier; // Multiplier
ENUM_APPLIED_PRICE appliedTo; // Applied To
//
// Presentation ...
bool showTrends; // Show Trends
bool fillTrends; // Fill Trends
//
// Constructor(s) ...
XSTRInputs()
{
//
Clean();
}
//
// Tools ...
//
// Clean ...
void Clean()
{
//
length = 0;
multiplier = 0;
appliedTo = PRICE_CLOSE;
//
showTrends = false;
fillTrends = false;
}
//
// Default ...
void Default()
{
//
length = 14;
multiplier = 3.5;
appliedTo = PRICE_MEDIAN;
//
showTrends = true;
fillTrends = false;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
length > 0 &&
multiplier > 0
//
;
//
return result;
}
//
// Retrieve MAx Length ...
int Max()
{
//
int result = 0;
//
result = length;
//
return result;
}
};
//
// Class ...
class XSCXSTRHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XSCXSTRHelper() : XSCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XSCXSTRHelper() {}
//
// Tools ...
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
XSTRInputs &inputs // Inputs
)
{
//
bool result = false;
//
mSymbol = symbol;
mPeriod = period;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
mInputs = inputs;
//
ArraySetAsSeries(trendBuffer, true);
ArraySetAsSeries(stateBuffer, true);
//
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.xstr",
//
// Inputs ...
//
// ATR ...
"",
mInputs.length, // Length
mInputs.multiplier, // Multiplier
mInputs.appliedTo, // Applied To
//
// Presentation ...
"",
mInputs.showTrends, // Show Trends
mInputs.fillTrends // Fill Trends
//
);
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
//
// Inputs ...
//
XSTRInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
XSTRInputs &inputs // Configs
)
{
//
return Init(
mSymbol,
mPeriod,
inputs);
}
//
// Buffers ...
//
// Trend ...
//
double GetTrend(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return trendBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyTrend(
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,
trendBuffer,
buffer,
forceClean
//
);
}
//
// State ...
//
ENUM_XSTR_TREND_STATES GetState(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return (ENUM_XSTR_TREND_STATES)((int)stateBuffer[barIndex]);
}
//
// Copy Required Buffer ...
int CopyState(
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,
stateBuffer,
buffer,
forceClean
//
);
}
//
// Tools ...
//
ENUM_XSTR_TREND_STATES ToState(double state)
{
return (ENUM_XSTR_TREND_STATES)((int)state);
}
//
bool IsBullish(double state)
{
//
bool result = false;
//
result =
//
ToState(state) == X_STR_BULLISH;
//
;
//
return result;
}
//
bool IsBearish(double state)
{
//
bool result = false;
//
result =
//
ToState(state) == X_STR_BEARISH;
//
;
//
return result;
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
XSTRInputs mInputs; // Inputs ...
//
// Buffers ...
double trendBuffer[];
double stateBuffer[];
//
// Tools ...
//
// Calculate Values Until Now ...
void Calculate()
{
//
int totalBars = CountBars();
int calculatedBars = CountCalculatedBars();
//
// Trend ...
CopyBuffer(
mHandler,
X_STR_TREND_LINE,
0,
totalBars,
trendBuffer
//
);
//
// State ...
CopyBuffer(
mHandler,
X_STR_STATE_LINE,
0,
totalBars,
stateBuffer
//
);
}
};
//
// Tools ...