Files
xMQL5/MQLTestWorkspace/BKPS/X121/Old/Helpers/x-saherelm.x121.xstr.helper.class.mq5
T
2024-05-17 04:54:01 +03:30

474 lines
8.0 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
//
// START Definitions ...
//
//
// Inputs ...
struct XSTRInputs
{
//
// Market ...
//
// Length ...
int atrLength;
//
// Multiplier ...
double atrMultiplier;
//
// Applied To ...
ENUM_APPLIED_PRICE atrAppliedTo;
//
// Presentation ...
//
// Show Trends ...
bool showTrends;
//
// Fill Trends ...
bool fillTrends;
};
//
// Index of Lines ...
enum ENUM_XSTR_BUFFERS
{
//
// Main Requirements ...
XSTR_LINE = 2,
XSTR_TREND_LINE = 5
};
//
// Trend State ...
enum ENUM_XSTR_TREND
{
XSTR_BULLISH = 1,
XSTR_BEARISH = -1
};
//
// Retrieve Info Model ...
struct XSTRInfo
{
//
// Symbol ...
string symbol;
//
// Period ...
ENUM_TIMEFRAMES period;
//
// Bar Time ...
datetime barTime;
//
// Bar Index ...
int barIndex;
//
// Values ...
double main;
ENUM_XSTR_TREND trend;
//
double mains[];
double trends[];
//
// Conditions ...
bool isTrendBullish;
bool isTrendBearish;
bool isTrendSwitchedToBullish;
bool isTrendSwitchedToBearish;
};
//
// END Definitions ...
//
//
// START Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Classes/x-saherelm.xhelper.class.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
//
// a Class for Helping Indicators Requirements ...
class XSCXSTRHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Buffers ...
double mainBuffer[];
double trendBuffer[];
//
// Constructor ...
void XSCXSTRHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period // Trading Time Frame
) : XSCBaseHelper(symbol, period)
{
PrepareTag();
}
//
// Deconstructor ...
void ~XSCXSTRHelper()
{
}
//
// START Properties ...
//
//
// END Properties ...
//
//
// START Provided Functions ...
//
//
// Prepare Tag ...
virtual void PrepareTag()
{
mTag = "XSTR" + GetTagPrefix();
}
//
virtual int GetMaxLength()
{
//
int result = -1;
//
result = mAtrLength;
//
return result;
}
//
// Initial Indicator Handler ...
bool Init()
{
//
bool result = false;
//
// Validate Args ...
result =
//
(mAtrLength >= 2 &&
mAtrMultiplier >= 0)
//
;
if (!result)
{
return false;
}
//
// Initialize Handler ...
mHandler = iCustom(
//
mSymbol,
mPeriod,
"x-saherelm.x121.xstr",
//
// Inputs ...
//
// Makret ...
"",
//
// Length ...
mAtrLength,
//
// Multiplier ...
mAtrMultiplier,
//
// Applied To ...
mAtrAppliedTo,
//
// Presentation ...
"",
//
// Show Trends ...
mShowTrends,
//
// Fill Trends ...
mFillTrends);
result = mHandler != INVALID_HANDLE;
//
return result;
}
//
// Retrieve Current Config ...
XSTRInputs GetConfig()
{
//
XSTRInputs result;
//
result.atrLength = mAtrLength;
result.atrMultiplier = mAtrMultiplier;
result.atrAppliedTo = mAtrAppliedTo;
result.showTrends = mShowTrends;
result.fillTrends = mFillTrends;
//
return result;
}
//
// Set Config ...
bool SetConfig(XSTRInputs &config)
{
//
bool result = false;
//
mAtrLength = config.atrLength;
mAtrMultiplier = config.atrMultiplier;
mAtrAppliedTo = config.atrAppliedTo;
mShowTrends = config.showTrends;
mFillTrends = config.fillTrends;
//
result = Init();
//
return result;
}
//
// Show Trends ...
bool ShowTrends(
bool show // Show or Hide
)
{
//
bool result = false;
//
if (mShowTrends == show)
{
return true;
}
//
mShowTrends = show;
result = Init();
//
return result;
}
//
// Fill Trends ...
bool FillTrends(
bool show // Show or Hide
)
{
//
bool result = false;
//
if (mFillTrends == show)
{
return true;
}
//
mFillTrends = show;
result = Init();
//
return result;
}
//
// Reading Buffers based on Given Bar Index ...
virtual void Calculate(
int barIndex // Given Bar Index
)
{
//
// MAIN ...
ArraySetAsSeries(mainBuffer, true);
CopyBuffer(
mHandler,
XSTR_LINE,
barIndex,
mLoopbackBars,
mainBuffer);
//
// TREND ...
ArraySetAsSeries(trendBuffer, true);
CopyBuffer(
mHandler,
XSTR_TREND_LINE,
barIndex,
mLoopbackBars,
trendBuffer);
}
//
// Retrieve Info at Specific Bar Index ...
XSTRInfo GetInfo(
int barIndex // Given Bar Index
)
{
//
XSTRInfo result;
//
if (barIndex < 0)
{
barIndex = 0;
}
//
// Do Calculations ...
Calculate(barIndex);
//
// Generate Candle Time ...
datetime barTime = GetCandleTime(
mSymbol,
mPeriod,
barIndex);
//
// Fill Result ...
result.symbol = mSymbol;
result.period = mPeriod;
result.barTime = barTime;
result.barIndex = barIndex;
//
double main = mainBuffer[barIndex];
ENUM_XSTR_TREND trend = (ENUM_XSTR_TREND)trendBuffer[barIndex];
ENUM_XSTR_TREND trendPrev = (ENUM_XSTR_TREND)trendBuffer[barIndex + 1];
//
Copy(
mainBuffer,
result.mains);
Copy(
trendBuffer,
result.trends);
//
result.main = main;
result.trend = trend;
//
result.isTrendBullish =
trend == XSTR_BULLISH;
//
result.isTrendBearish =
trend == XSTR_BEARISH;
//
result.isTrendSwitchedToBullish =
trend == XSTR_BULLISH &&
trendPrev != XSTR_BULLISH;
//
result.isTrendSwitchedToBearish =
trend == XSTR_BEARISH &&
trendPrev != XSTR_BEARISH;
//
return result;
}
//
// END Provided Functions ...
//
//
// Protected ...
protected:
//
// Private ...
private:
//
// Indicator Properties ...
//
// Market ...
//
// Length ...
int mAtrLength;
//
// Multiplier ...
double mAtrMultiplier;
//
// Applied To ...
ENUM_APPLIED_PRICE mAtrAppliedTo;
//
// Presentation ...
//
// Show Trends ...
bool mShowTrends;
//
// Fill Trends ...
bool mFillTrends;
};
//
// START Usefull Functions ...
//
//
// END Usefull Functions ...
//