1479 lines
31 KiB
Plaintext
1479 lines
31 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 Helper Class Library
|
|
// ----------------------------------------------
|
|
// Name: XCX121XHKHelper
|
|
// 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.x-helper.class.mq5"
|
|
|
|
//
|
|
// Definitions ...
|
|
|
|
//
|
|
// Definitions ...
|
|
enum ENUM_X121_XHK_BUFFERS
|
|
{
|
|
//
|
|
X121_XHK_RAW_OPEN_LINE = 0,
|
|
X121_XHK_RAW_HIGH_LINE = 1,
|
|
X121_XHK_RAW_LOW_LINE = 2,
|
|
X121_XHK_RAW_CLOSE_LINE = 3,
|
|
//
|
|
X121_XHK_SM_OPEN_LINE = 5,
|
|
X121_XHK_SM_HIGH_LINE = 6,
|
|
X121_XHK_SM_LOW_LINE = 7,
|
|
X121_XHK_SM_CLOSE_LINE = 8,
|
|
};
|
|
|
|
//
|
|
// Input Models ...
|
|
struct X121XHKInputs
|
|
{
|
|
//
|
|
// Props ...
|
|
int xhkSmoothingLength; // Length
|
|
ENUM_X_MA_METHOD xhkSmoothingMode; // Smoothing Method
|
|
bool xhkIgnoreSmoothingShadows; // Ignore Smoothed Bar Shadows
|
|
int startCalculationForLastBars; // Calculate Last n Bars
|
|
bool drawRawXHKCandles; // Draw Raw Candle
|
|
bool drawSmoothedXHKCandles; // Draw Smoothed Candle
|
|
|
|
//
|
|
// Constructor(s) ...
|
|
X121XHKInputs()
|
|
{
|
|
//
|
|
Clean();
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
|
|
//
|
|
// Clean ...
|
|
void Clean()
|
|
{
|
|
//
|
|
xhkSmoothingLength = 0;
|
|
xhkSmoothingMode = X_MA_MODE_NONE;
|
|
xhkIgnoreSmoothingShadows = false;
|
|
startCalculationForLastBars = 1500;
|
|
drawRawXHKCandles = false;
|
|
drawSmoothedXHKCandles = false;
|
|
|
|
//
|
|
ZeroMemory(this);
|
|
}
|
|
|
|
//
|
|
// Default ...
|
|
void Default()
|
|
{
|
|
//
|
|
xhkSmoothingLength = 14;
|
|
xhkSmoothingMode = X_MA_MODE_EMA;
|
|
xhkIgnoreSmoothingShadows = false;
|
|
startCalculationForLastBars = 1500;
|
|
drawRawXHKCandles = true;
|
|
drawSmoothedXHKCandles = true;
|
|
}
|
|
|
|
//
|
|
// Validate ...
|
|
bool IsValid()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result =
|
|
//
|
|
xhkSmoothingLength > 0
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Retrieve MAx Length ...
|
|
int Max()
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
result = MathMax(0, xhkSmoothingLength);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
};
|
|
|
|
//
|
|
// Conditions ...
|
|
struct X121XHKConditions
|
|
{
|
|
//
|
|
// Common ...
|
|
string symbol;
|
|
ENUM_TIMEFRAMES period;
|
|
datetime time;
|
|
|
|
//
|
|
// Buffers ...
|
|
|
|
//
|
|
double xhkRawOpenBuffer[];
|
|
double xhkRawHighBuffer[];
|
|
double xhkRawLowBuffer[];
|
|
double xhkRawCloseBuffer[];
|
|
|
|
//
|
|
double xhkSMOpenBuffer[];
|
|
double xhkSMHighBuffer[];
|
|
double xhkSMLowBuffer[];
|
|
double xhkSMCloseBuffer[];
|
|
|
|
//
|
|
// Conditions ...
|
|
|
|
//
|
|
bool isSMHKBullish;
|
|
bool isRawHKBullish;
|
|
bool isSMHKSwitchedToBullish;
|
|
bool isRawHKSwitchedToBullish;
|
|
|
|
//
|
|
bool isSMHKBearish;
|
|
bool isRawHKBearish;
|
|
bool isSMHKSwitchedToBearish;
|
|
bool isRawHKSwitchedToBearish;
|
|
|
|
//
|
|
bool isClosedOverSMHK;
|
|
bool isClosedUnderSMHK;
|
|
bool isClosedOverRawHK;
|
|
bool isClosedUnderRawHK;
|
|
|
|
//
|
|
bool isRawHKClosedOverSMHK;
|
|
bool isRawHKClosedUnderSMHK;
|
|
|
|
//
|
|
// Constructor ...
|
|
X121XHKConditions()
|
|
{
|
|
Clean();
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
|
|
/**
|
|
* Cleaning Up ...
|
|
*/
|
|
void Clean()
|
|
{
|
|
//
|
|
// Commons ...
|
|
symbol = NULL;
|
|
period = NULL;
|
|
time = NULL;
|
|
|
|
//
|
|
// Buffers ...
|
|
|
|
//
|
|
Clean(xhkRawOpenBuffer);
|
|
Clean(xhkRawHighBuffer);
|
|
Clean(xhkRawLowBuffer);
|
|
Clean(xhkRawCloseBuffer);
|
|
Clean(xhkSMOpenBuffer);
|
|
Clean(xhkSMHighBuffer);
|
|
Clean(xhkSMLowBuffer);
|
|
Clean(xhkSMCloseBuffer);
|
|
|
|
//
|
|
ArraySetAsSeries(xhkRawOpenBuffer, true);
|
|
ArraySetAsSeries(xhkRawHighBuffer, true);
|
|
ArraySetAsSeries(xhkRawLowBuffer, true);
|
|
ArraySetAsSeries(xhkRawCloseBuffer, true);
|
|
ArraySetAsSeries(xhkSMOpenBuffer, true);
|
|
ArraySetAsSeries(xhkSMHighBuffer, true);
|
|
ArraySetAsSeries(xhkSMLowBuffer, true);
|
|
ArraySetAsSeries(xhkSMCloseBuffer, true);
|
|
|
|
//
|
|
// Conditions ...
|
|
|
|
//
|
|
isSMHKBullish = false;
|
|
isRawHKBullish = false;
|
|
isSMHKSwitchedToBullish = false;
|
|
isRawHKSwitchedToBullish = false;
|
|
|
|
//
|
|
isSMHKBearish = false;
|
|
isRawHKBearish = false;
|
|
isSMHKSwitchedToBearish = false;
|
|
isRawHKSwitchedToBearish = false;
|
|
|
|
//
|
|
isClosedOverSMHK = false;
|
|
isClosedUnderSMHK = false;
|
|
isClosedOverRawHK = false;
|
|
isClosedUnderRawHK = false;
|
|
|
|
//
|
|
isRawHKClosedOverSMHK = false;
|
|
isRawHKClosedUnderSMHK = false;
|
|
|
|
//
|
|
ZeroMemory(this);
|
|
}
|
|
|
|
/**
|
|
* Generate Conditions Scores ...
|
|
*
|
|
* @param bullishScore: Double, Directional Scores Reference ...
|
|
* @param bearishScore: Double, Directional Scores Reference ...
|
|
*/
|
|
void GenerateScore(
|
|
double &bullishScore,
|
|
double &bearishScore //
|
|
)
|
|
{
|
|
//
|
|
bullishScore = 0;
|
|
bearishScore = 0;
|
|
|
|
//
|
|
double score = 1;
|
|
double minScore = 0.5;
|
|
double highScore = 1.5;
|
|
|
|
//
|
|
if (isSMHKBullish)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
if (isRawHKBullish)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
if (isClosedOverSMHK)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
if (isClosedOverRawHK)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
if (isRawHKClosedOverSMHK)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
if (isSMHKSwitchedToBullish)
|
|
{
|
|
bullishScore += highScore;
|
|
}
|
|
if (isRawHKSwitchedToBullish)
|
|
{
|
|
bullishScore += highScore;
|
|
}
|
|
|
|
//
|
|
if (isSMHKBearish)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
if (isRawHKBearish)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
if (isClosedUnderSMHK)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
if (isClosedUnderRawHK)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
if (isRawHKClosedUnderSMHK)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
if (isSMHKSwitchedToBearish)
|
|
{
|
|
bearishScore += highScore;
|
|
}
|
|
if (isRawHKSwitchedToBullish)
|
|
{
|
|
bearishScore += highScore;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Generate Summary String for Represent Conditions State ...
|
|
*
|
|
* @param onlyCommons: Boolean, Just Generate Only Commons Conditions ...
|
|
* @param onlyConditions: Boolean, Just Generate Only Conditions ...
|
|
* @param includeScores: Boolean, Attach Scores Representations on Result ...
|
|
* @param ignoreFalseConditions: Boolean, Ignore False Conditions on Result ...
|
|
* @param separator: String, Separate Lines ...
|
|
*
|
|
* @return ( string )
|
|
*/
|
|
string GenerateSummary(
|
|
bool onlyCommons = false,
|
|
bool onlyConditions = false,
|
|
bool includeScores = true,
|
|
bool ignoreFalseConditions = true,
|
|
string separator = "\n" //
|
|
)
|
|
{
|
|
//
|
|
string result = NULL;
|
|
|
|
//
|
|
double bullishScore = 0;
|
|
double bearishScore = 0;
|
|
GenerateScore(
|
|
bullishScore,
|
|
bearishScore //
|
|
);
|
|
|
|
//
|
|
string scoresStr =
|
|
//
|
|
"Scores: " + separator +
|
|
"---------------" + separator +
|
|
"Bullish: " + ToString(bullishScore) + separator +
|
|
"Bearish: " + ToString(bearishScore) + separator +
|
|
""
|
|
//
|
|
;
|
|
|
|
//
|
|
string commonStr = GenerateSpecifiedCommonSummary(
|
|
this,
|
|
separator,
|
|
includeScores //
|
|
);
|
|
|
|
//
|
|
string conditionsStr =
|
|
//
|
|
"-----------------------" + separator +
|
|
"XHK: " + separator +
|
|
"-----------------------" + separator +
|
|
ToString("isSMHKBullish", isSMHKBullish, ignoreFalseConditions, separator) +
|
|
ToString("isRawHKBullish", isRawHKBullish, ignoreFalseConditions, separator) +
|
|
ToString("isSMHKSwitchedToBullish", isSMHKSwitchedToBullish, ignoreFalseConditions, separator) +
|
|
ToString("isRawHKSwitchedToBullish", isRawHKSwitchedToBullish, ignoreFalseConditions, separator) +
|
|
ToString("isSMHKBearish", isSMHKBearish, ignoreFalseConditions, separator) +
|
|
ToString("isRawHKBearish", isRawHKBearish, ignoreFalseConditions, separator) +
|
|
ToString("isSMHKSwitchedToBearish", isSMHKSwitchedToBearish, ignoreFalseConditions, separator) +
|
|
ToString("isRawHKSwitchedToBearish", isRawHKSwitchedToBearish, ignoreFalseConditions, separator) +
|
|
ToString("isClosedOverSMHK", isClosedOverSMHK, ignoreFalseConditions, separator) +
|
|
ToString("isClosedUnderSMHK", isClosedUnderSMHK, ignoreFalseConditions, separator) +
|
|
ToString("isClosedOverRawHK", isClosedOverRawHK, ignoreFalseConditions, separator) +
|
|
ToString("isClosedUnderRawHK", isClosedUnderRawHK, ignoreFalseConditions, separator) +
|
|
ToString("isRawHKClosedOverSMHK", isRawHKClosedOverSMHK, ignoreFalseConditions, separator) +
|
|
ToString("isRawHKClosedUnderSMHK", isRawHKClosedUnderSMHK, ignoreFalseConditions, separator) +
|
|
//
|
|
""
|
|
//
|
|
;
|
|
|
|
//
|
|
result =
|
|
//
|
|
"[" + GetTag() + "]" + separator +
|
|
(onlyConditions
|
|
? ""
|
|
: commonStr) +
|
|
(!includeScores
|
|
? ""
|
|
: scoresStr) +
|
|
" " + separator +
|
|
(onlyCommons
|
|
? ""
|
|
: conditionsStr) +
|
|
""
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Retrieve nique Tag Identifier ...
|
|
*
|
|
* @return ( string )
|
|
*/
|
|
string GetTag()
|
|
{
|
|
return GetTypeName(this);
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
//
|
|
// Class ...
|
|
class XCX121XHKHelper : public XCBaseHelper
|
|
{
|
|
//
|
|
// Public ...
|
|
public:
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
// Constructors ...
|
|
XCX121XHKHelper()
|
|
: XCBaseHelper(_Symbol, _Period)
|
|
{
|
|
}
|
|
|
|
//
|
|
// Deconstructor ...
|
|
~XCX121XHKHelper()
|
|
{
|
|
//
|
|
Clean(xhkRawOpenBuffer);
|
|
Clean(xhkRawHighBuffer);
|
|
Clean(xhkRawLowBuffer);
|
|
Clean(xhkRawCloseBuffer);
|
|
Clean(xhkSMOpenBuffer);
|
|
Clean(xhkSMHighBuffer);
|
|
Clean(xhkSMLowBuffer);
|
|
Clean(xhkSMCloseBuffer);
|
|
|
|
//
|
|
mInputs.Clean();
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
bool Init(
|
|
string symbol, // Trading Symbol
|
|
ENUM_TIMEFRAMES period, // Trading Period
|
|
X121XHKInputs &inputs // Inputs
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
mSymbol = symbol;
|
|
mPeriod = period;
|
|
|
|
//
|
|
result = inputs.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
ArraySetAsSeries(xhkRawOpenBuffer, true);
|
|
ArraySetAsSeries(xhkRawHighBuffer, true);
|
|
ArraySetAsSeries(xhkRawLowBuffer, true);
|
|
ArraySetAsSeries(xhkRawCloseBuffer, true);
|
|
ArraySetAsSeries(xhkSMOpenBuffer, true);
|
|
ArraySetAsSeries(xhkSMHighBuffer, true);
|
|
ArraySetAsSeries(xhkSMLowBuffer, true);
|
|
ArraySetAsSeries(xhkSMCloseBuffer, true);
|
|
|
|
//
|
|
mInputs = inputs;
|
|
|
|
//
|
|
mHandler = iCustom(
|
|
mSymbol,
|
|
mPeriod,
|
|
"x-saherelm.x121.xhk",
|
|
//
|
|
// Inputs ...
|
|
//
|
|
// Market ...
|
|
"",
|
|
mInputs.xhkSmoothingLength,
|
|
mInputs.xhkSmoothingMode,
|
|
mInputs.xhkIgnoreSmoothingShadows,
|
|
//
|
|
// Presentation ...
|
|
"",
|
|
mInputs.startCalculationForLastBars,
|
|
mInputs.drawRawXHKCandles,
|
|
mInputs.drawSmoothedXHKCandles
|
|
//
|
|
);
|
|
result = mHandler != INVALID_HANDLE;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Inputs ...
|
|
|
|
//
|
|
X121XHKInputs GetInputs()
|
|
{
|
|
return mInputs;
|
|
}
|
|
|
|
//
|
|
bool SetInputs(
|
|
X121XHKInputs &inputs // Configs
|
|
)
|
|
{
|
|
//
|
|
return Init(
|
|
mSymbol,
|
|
mPeriod,
|
|
inputs
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Readers ...
|
|
|
|
//
|
|
double GetRawHKOpen(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(xhkRawOpenBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return xhkRawOpenBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyRawHKOpen(
|
|
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,
|
|
xhkRawOpenBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetRawHKHigh(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(xhkRawHighBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return xhkRawHighBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyRawHKHigh(
|
|
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,
|
|
xhkRawHighBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetRawHKLow(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(xhkRawLowBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return xhkRawLowBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyRawHKLow(
|
|
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,
|
|
xhkRawLowBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetRawHKClose(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(xhkRawCloseBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return xhkRawCloseBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyRawHKClose(
|
|
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,
|
|
xhkRawCloseBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetSMHKOpen(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(xhkSMOpenBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return xhkSMOpenBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopySMHKOpen(
|
|
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,
|
|
xhkSMOpenBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetSMHKHigh(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(xhkSMHighBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return xhkSMHighBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopySMHKHigh(
|
|
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,
|
|
xhkSMHighBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetSMHKLow(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(xhkSMLowBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return xhkSMLowBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopySMHKLow(
|
|
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,
|
|
xhkSMLowBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetSMHKClose(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(xhkSMCloseBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return xhkSMCloseBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopySMHKClose(
|
|
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,
|
|
xhkSMCloseBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
bool GetRawHKAsXOHCL(
|
|
int barIndex, // Bar Index
|
|
XOHCL &bar // Bar Result
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
bar.Clean();
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
result = bar.Init(
|
|
GetSymbol(),
|
|
GetPeriod(),
|
|
barIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bar.open = xhkRawOpenBuffer[barIndex];
|
|
bar.high = xhkRawHighBuffer[barIndex];
|
|
bar.low = xhkRawLowBuffer[barIndex];
|
|
bar.close = xhkRawCloseBuffer[barIndex];
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool GetSMHKAsXOHCL(
|
|
int barIndex, // Bar Index
|
|
XOHCL &bar // Bar Result
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
bar.Clean();
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
result = bar.Init(
|
|
GetSymbol(),
|
|
GetPeriod(),
|
|
barIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bar.open = xhkSMOpenBuffer[barIndex];
|
|
bar.high = xhkSMHighBuffer[barIndex];
|
|
bar.low = xhkSMLowBuffer[barIndex];
|
|
bar.close = xhkSMCloseBuffer[barIndex];
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
void Free() override
|
|
{
|
|
Cleanup(10);
|
|
}
|
|
|
|
//
|
|
bool GetConditions(
|
|
X121XHKConditions &conditions, //
|
|
int barIndex = 0, //
|
|
int loopback = 5 //
|
|
)
|
|
{
|
|
//
|
|
bool result = true;
|
|
|
|
//
|
|
if (loopback < 5)
|
|
{
|
|
loopback = 5;
|
|
}
|
|
|
|
//
|
|
conditions.Clean();
|
|
|
|
//
|
|
conditions.symbol = mSymbol;
|
|
conditions.period = mPeriod;
|
|
conditions.time = TimeCurrent();
|
|
|
|
//
|
|
int zIndex = barIndex;
|
|
int cIndex = zIndex + 1;
|
|
int pIndex = cIndex + 1;
|
|
int ppIndex = pIndex + 1;
|
|
|
|
//
|
|
XOHCL zBar;
|
|
result = zBar.Init(
|
|
mSymbol,
|
|
mPeriod,
|
|
zIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
mSymbol,
|
|
mPeriod,
|
|
cIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL pBar;
|
|
result = pBar.Init(
|
|
mSymbol,
|
|
mPeriod,
|
|
pIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Buffers ...
|
|
|
|
//
|
|
CopyRawHKOpen(
|
|
zIndex,
|
|
loopback,
|
|
conditions.xhkRawOpenBuffer //
|
|
);
|
|
|
|
//
|
|
CopyRawHKHigh(
|
|
zIndex,
|
|
loopback,
|
|
conditions.xhkRawHighBuffer //
|
|
);
|
|
|
|
//
|
|
CopyRawHKLow(
|
|
zIndex,
|
|
loopback,
|
|
conditions.xhkRawLowBuffer //
|
|
);
|
|
|
|
//
|
|
CopyRawHKClose(
|
|
zIndex,
|
|
loopback,
|
|
conditions.xhkRawCloseBuffer //
|
|
);
|
|
|
|
//
|
|
CopySMHKOpen(
|
|
zIndex,
|
|
loopback,
|
|
conditions.xhkSMOpenBuffer //
|
|
);
|
|
|
|
//
|
|
CopySMHKHigh(
|
|
zIndex,
|
|
loopback,
|
|
conditions.xhkSMHighBuffer //
|
|
);
|
|
|
|
//
|
|
CopySMHKLow(
|
|
zIndex,
|
|
loopback,
|
|
conditions.xhkSMLowBuffer //
|
|
);
|
|
|
|
//
|
|
CopySMHKClose(
|
|
zIndex,
|
|
loopback,
|
|
conditions.xhkSMCloseBuffer //
|
|
);
|
|
|
|
//
|
|
// Conditions ...
|
|
|
|
//
|
|
int cIDX = 1;
|
|
int pIDX = cIDX + 1;
|
|
|
|
//
|
|
double smHKLow = conditions.xhkSMLowBuffer[cIDX];
|
|
double smHKHigh = conditions.xhkSMHighBuffer[cIDX];
|
|
double smHKOpen = conditions.xhkSMOpenBuffer[cIDX];
|
|
double smHKClose = conditions.xhkSMCloseBuffer[cIDX];
|
|
|
|
//
|
|
double smHKLowPrev = conditions.xhkSMLowBuffer[pIDX];
|
|
double smHKHighPrev = conditions.xhkSMHighBuffer[pIDX];
|
|
double smHKOpenPrev = conditions.xhkSMOpenBuffer[pIDX];
|
|
double smHKClosePrev = conditions.xhkSMCloseBuffer[pIDX];
|
|
|
|
//
|
|
double rawHKLow = conditions.xhkRawLowBuffer[cIDX];
|
|
double rawHKHigh = conditions.xhkRawHighBuffer[cIDX];
|
|
double rawHKOpen = conditions.xhkRawOpenBuffer[cIDX];
|
|
double rawHKClose = conditions.xhkRawCloseBuffer[cIDX];
|
|
|
|
//
|
|
double rawHKLowPrev = conditions.xhkRawLowBuffer[pIDX];
|
|
double rawHKHighPrev = conditions.xhkRawHighBuffer[pIDX];
|
|
double rawHKOpenPrev = conditions.xhkRawOpenBuffer[pIDX];
|
|
double rawHKClosePrev = conditions.xhkRawCloseBuffer[pIDX];
|
|
|
|
//
|
|
double smHKUp = MathMax(smHKOpen, smHKClose);
|
|
double smHKUpPrev = MathMax(smHKOpenPrev, smHKClosePrev);
|
|
|
|
//
|
|
double smHKDown = MathMin(smHKOpen, smHKClose);
|
|
double smHKDownPrev = MathMin(smHKOpenPrev, smHKClosePrev);
|
|
|
|
//
|
|
double rawHKUp = MathMax(rawHKOpen, rawHKClose);
|
|
double rawHKUpPrev = MathMax(rawHKOpenPrev, rawHKClosePrev);
|
|
|
|
//
|
|
double rawHKDown = MathMin(rawHKOpen, rawHKClose);
|
|
double rawHKDownPrev = MathMin(rawHKOpenPrev, rawHKClosePrev);
|
|
|
|
//
|
|
XOHCL rawHKCBar;
|
|
bool hasRawHKBar = GetRawHKAsXOHCL(
|
|
cIndex,
|
|
rawHKCBar //
|
|
);
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
bool isSMHKBullish = smHKOpen < smHKClose;
|
|
bool isSMHKBullishPrev = smHKOpenPrev < smHKClosePrev;
|
|
|
|
//
|
|
bool isRawHKBullish = rawHKOpen < rawHKClose;
|
|
bool isRawHKBullishPrev = rawHKOpenPrev < rawHKClosePrev;
|
|
|
|
//
|
|
bool isSMHKSwitchedToBullish = isSMHKBullish &&
|
|
!isSMHKBullishPrev;
|
|
bool isRawHKSwitchedToBullish = isRawHKBullish &&
|
|
!isRawHKBullishPrev;
|
|
|
|
//
|
|
bool isSMHKBearish = smHKOpen > smHKClose;
|
|
bool isSMHKBearishPrev = smHKOpenPrev > smHKClosePrev;
|
|
|
|
//
|
|
bool isRawHKBearish = rawHKOpen > rawHKClose;
|
|
bool isRawHKBearishPrev = rawHKOpenPrev > rawHKClosePrev;
|
|
|
|
//
|
|
bool isSMHKSwitchedToBearish = isSMHKBearish &&
|
|
!isSMHKBearishPrev;
|
|
bool isRawHKSwitchedToBearish = isRawHKBearish &&
|
|
!isRawHKBearishPrev;
|
|
|
|
//
|
|
bool isClosedOverSMHK = cBar.close > smHKUp;
|
|
bool isClosedUnderSMHK = cBar.close < smHKDown;
|
|
|
|
//
|
|
bool isClosedOverRawHK = cBar.close > rawHKUp;
|
|
bool isClosedUnderRawHK = cBar.close < rawHKDown;
|
|
|
|
//
|
|
bool isRawHKClosedOverSMHK = rawHKClose > smHKUp;
|
|
bool isRawHKClosedUnderSMHK = rawHKClose < smHKDown;
|
|
|
|
//
|
|
conditions.isSMHKBullish = isSMHKBullish;
|
|
conditions.isRawHKBullish = isRawHKBullish;
|
|
conditions.isSMHKSwitchedToBullish = isSMHKSwitchedToBullish;
|
|
conditions.isRawHKSwitchedToBullish = isRawHKSwitchedToBullish;
|
|
conditions.isSMHKBearish = isSMHKBearish;
|
|
conditions.isRawHKBearish = isRawHKBearish;
|
|
conditions.isSMHKSwitchedToBearish = isSMHKSwitchedToBearish;
|
|
conditions.isRawHKSwitchedToBearish = isRawHKSwitchedToBearish;
|
|
conditions.isClosedOverSMHK = isClosedOverSMHK;
|
|
conditions.isClosedUnderSMHK = isClosedUnderSMHK;
|
|
conditions.isClosedOverRawHK = isClosedOverRawHK;
|
|
conditions.isClosedUnderRawHK = isClosedUnderRawHK;
|
|
conditions.isRawHKClosedOverSMHK = isRawHKClosedOverSMHK;
|
|
conditions.isRawHKClosedUnderSMHK = isRawHKClosedUnderSMHK;
|
|
|
|
//
|
|
Cleanup();
|
|
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
|
|
//
|
|
rawHKCBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Protected ...
|
|
protected:
|
|
//
|
|
// Private ...
|
|
private:
|
|
//
|
|
// Props ...
|
|
X121XHKInputs mInputs; // Inputs ...
|
|
|
|
//
|
|
// Buffers ...
|
|
double xhkRawOpenBuffer[];
|
|
double xhkRawHighBuffer[];
|
|
double xhkRawLowBuffer[];
|
|
double xhkRawCloseBuffer[];
|
|
double xhkSMOpenBuffer[];
|
|
double xhkSMHighBuffer[];
|
|
double xhkSMLowBuffer[];
|
|
double xhkSMCloseBuffer[];
|
|
|
|
//
|
|
void Calculate(
|
|
int maxRequiredBars = 100 //
|
|
)
|
|
{
|
|
//
|
|
// Buffers ...
|
|
|
|
//
|
|
// RAW Open ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XHK_RAW_OPEN_LINE,
|
|
0,
|
|
maxRequiredBars,
|
|
xhkRawOpenBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// RAW High ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XHK_RAW_HIGH_LINE,
|
|
0,
|
|
maxRequiredBars,
|
|
xhkRawHighBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// RAW Low ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XHK_RAW_LOW_LINE,
|
|
0,
|
|
maxRequiredBars,
|
|
xhkRawLowBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// RAW Close ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XHK_RAW_CLOSE_LINE,
|
|
0,
|
|
maxRequiredBars,
|
|
xhkRawCloseBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// SM Open ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XHK_SM_OPEN_LINE,
|
|
0,
|
|
maxRequiredBars,
|
|
xhkSMOpenBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// SM High ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XHK_SM_HIGH_LINE,
|
|
0,
|
|
maxRequiredBars,
|
|
xhkSMHighBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// SM Low ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XHK_SM_LOW_LINE,
|
|
0,
|
|
maxRequiredBars,
|
|
xhkSMLowBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// SM Close ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XHK_SM_CLOSE_LINE,
|
|
0,
|
|
maxRequiredBars,
|
|
xhkSMCloseBuffer
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
void Cleanup(
|
|
int maxAllowed = 100 //
|
|
)
|
|
{
|
|
//
|
|
CleanupArray(
|
|
xhkRawOpenBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
xhkRawHighBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
xhkRawLowBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
xhkRawCloseBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
xhkSMOpenBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
xhkSMHighBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
xhkSMLowBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
xhkSMCloseBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
//
|
|
// Tools ... |