Files
xMQL5/MQLTestWorkspace/Helpers/x-saherelm.x121.xhk.helper.class.mq5
T

428 lines
7.2 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXHKHelper
// 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 XHKInputs
{
//
// Presentation ...
bool drawCandles; // Draw Hiken Ashi Candle
bool drawCandleLines; // Show HikenAshi Lines
};
//
// Index of Lines ...
enum ENUM_XHK_BUFFERS
{
//
// Main Requirements ...
XHK_OPEN_LINE = 0,
XHK_HIGH_LINE = 1,
XHK_LOW_LINE = 2,
XHK_CLOSE_LINE = 3,
};
//
// Retrieve Info Model ...
struct XHKInfo
{
//
// Symbol ...
string symbol;
//
// Period ...
ENUM_TIMEFRAMES period;
//
// Bar Time ...
datetime barTime;
//
// Bar Index ...
int barIndex;
//
// Values ...
double open;
double high;
double low;
double close;
//
// Conditions ...
//
// Detect Candle is Bullish or not ...
bool isBullish;
//
// Detect Candle is Bearish or not ...
bool isBearish;
};
//
// 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 XSCXHKHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Buffers ...
double openBuffer[];
double highBuffer[];
double lowBuffer[];
double closeBuffer[];
//
// Constructor ...
void XSCXHKHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period // Trading Time Frame
//
// Indicator Properties ...
//
// Presentation ...
//
// Draw Hiken Ashi Candle ...
) : XSCBaseHelper(symbol, period)
{
PrepareTag();
}
//
// Deconstructor ...
void ~XSCXHKHelper()
{
}
//
// START Properties ...
//
//
// Draw Candles ...
bool DrawCandles(
bool show // Show or Hide
)
{
//
bool result = false;
//
if (mDrawCandles == show)
{
return true;
}
//
mDrawCandles = show;
result = Init();
//
return result;
}
//
// Show HikenAshi Lines ...
bool DrawCandleLines(
bool show // Show or Hide
)
{
//
bool result = false;
//
if (mDrawCandleLines == show)
{
return true;
}
//
mDrawCandleLines = show;
result = Init();
//
return result;
}
//
// END Properties ...
//
//
// START Provided Functions ...
//
//
// Prepare Tag ...
virtual void PrepareTag()
{
mTag = "XHK" + GetTagPrefix();
}
//
virtual int GetMaxLength()
{
//
int result = -1;
//
result = 2;
//
return result;
}
//
// Initial Indicator Handler ...
bool Init()
{
//
bool result = false;
//
// Initialize Handler ...
mHandler = iCustom(
//
mSymbol,
mPeriod,
"x-saherelm.x121.xhk",
//
// Inputs ...
//
// Presentation ...
"",
//
// Draw Hiken Ashi Candle ...
mDrawCandles,
//
// Show HikenAshi Lines ...
mDrawCandleLines
//
);
result = mHandler != INVALID_HANDLE;
//
return result;
}
//
// Retrieve Current Config ...
XHKInputs GetConfig()
{
//
XHKInputs result;
//
result.drawCandles = mDrawCandles;
result.drawCandleLines = mDrawCandleLines;
//
return result;
}
//
// Set Config ...
bool SetConfig(XHKInputs &config)
{
//
bool result = false;
//
mDrawCandles = config.drawCandles;
mDrawCandleLines = config.drawCandleLines;
//
result = Init();
//
return result;
}
//
// Reading Buffers based on Given Bar Index ...
virtual void Calculate(
int barIndex // Given Bar Index
)
{
//
// OPEN ...
ArraySetAsSeries(openBuffer, true);
CopyBuffer(
mHandler,
XHK_OPEN_LINE,
barIndex,
mLoopbackBars,
openBuffer);
//
// HIGH ...
ArraySetAsSeries(highBuffer, true);
CopyBuffer(
mHandler,
XHK_HIGH_LINE,
barIndex,
mLoopbackBars,
highBuffer);
//
// LOW ...
ArraySetAsSeries(lowBuffer, true);
CopyBuffer(
mHandler,
XHK_LOW_LINE,
barIndex,
mLoopbackBars,
lowBuffer);
//
// CLOSE ...
ArraySetAsSeries(closeBuffer, true);
CopyBuffer(
mHandler,
XHK_CLOSE_LINE,
barIndex,
mLoopbackBars,
closeBuffer);
}
//
// Retrieve Info at Specific Bar Index ...
XHKInfo GetInfo(
int barIndex // Given Bar Index
)
{
//
XHKInfo result;
//
if (barIndex < 0)
{
return result;
}
//
barIndex--;
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 open = openBuffer[barIndex];
double high = highBuffer[barIndex];
double low = lowBuffer[barIndex];
double close = closeBuffer[barIndex];
//
result.open = open;
result.high = high;
result.low = low;
result.close = close;
//
result.isBullish = open < close;
result.isBearish = open >= close;
//
return result;
}
//
// END Provided Functions ...
//
//
// Protected ...
protected:
//
// Private ...
private:
//
// Indicator Properties ...
//
// Presentation ...
//
// Draw Hiken Ashi Candle ...
bool mDrawCandles;
//
// Show HikenAshi Lines ...
bool mDrawCandleLines;
};
//
// START Usefull Functions ...
//
//
// END Usefull Functions ...
//