Initial Commit ...

This commit is contained in:
2024-01-25 04:09:42 +03:30
commit b2037e07eb
1991 changed files with 668083 additions and 0 deletions
@@ -0,0 +1,956 @@
/////////////////////////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XCHLH Oscillator Helper for Signal Providers
// --------------------------------------------------------------------------
//
// 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
//
// Includes ...
#include "..\Libraries\x-saherelm.log.lib.mq5"
#include "..\Libraries\x-saherelm.common.lib.mq5"
//
// START Enum Definitions ...
//
//
// Cycles Enumeration ...
enum ENUM_X_XCHLH_CYCLES
{
X_XCHLH_CYCLE_LONG,
X_XCHLH_CYCLE_MEDIUM,
X_XCHLH_CYCLE_SHORT,
};
//
// XCHLH Hot States ...
enum ENUM_X_XCHLH_HOT_STATES
{
X_XCHLH_HOT_HH = 1,
X_XCHLH_NEUTURAL = 0,
X_XCHLH_HOT_LL = -1,
};
//
// XCHLH Buffer Lines ...
enum ENUM_X_XCHLH_BUFFER_LINES
{
X_XCHLH_LC_HH_LINE = 0,
X_XCHLH_LC_LL_LINE = 1,
X_XCHLH_MC_HH_LINE = 2,
X_XCHLH_MC_LL_LINE = 3,
X_XCHLH_SC_HH_LINE = 4,
X_XCHLH_SC_LL_LINE = 5,
X_XCHLH_SIGNAL_T_LINE = 6,
X_XCHLH_SIGNAL_B_LINE = 7,
X_XCHLH_HOT_STATE_LINE = 8,
};
//
// END Enum Definitions ...
//
//
// START Inputs ...
//
//
input group "XCHLH Oscillator";
//
// Common ...
input group "XCHLH Hot Areas";
input bool xCHLHDrawHotAreas = false; // Draw Hot Areas Symbol
input uchar xCHLHHotHHArrowCode = 234; // Hot HH Arrow Code
input color xCHLHHotHHArrowColor = clrAqua; // Hot HH Arrow Color
input uchar xCHLHHotLLArrowCode = 233; // Hot LL Arrow Code
input color xCHLHHotLLArrowColor = clrFuchsia; // Hot LL Arrow Color
//
// LC Inputs ...
input group "XCHLH Long Cycle";
input group "XCHLH LC Market";
input int xCHLHLcLength = 288; // Length
input double xCHLHLcThresholdInPips = 0.3; // Threshold In Pips
input ENUM_SERIESMODE xCHLHLcHHMode = MODE_HIGH; // Highest High Calculation Method
input ENUM_SERIESMODE xCHLHLcLLMode = MODE_LOW; // Lowest Low Calculation Method
input group "XCHLH LC Style";
input int xCHLHLcDrawWidth = 1; // Draw Width
input ENUM_DRAW_TYPE xCHLHLcDrawType = DRAW_LINE; // Draw Type
input ENUM_LINE_STYLE xCHLHLcDrawStyle = STYLE_DOT; // Draw Style
input color xCHLHLcHHColor = clrAqua; // Highest High Color
input color xCHLHLcLLColor = clrFuchsia; // Lowest Low Color
input group "XCHLH LC Drawings";
input bool xCHLHLcDrawHH = true; // Draw Highest High
input bool xCHLHLcDrawLL = true; // Draw Lowest Low
//
// MC Inputs ...
input group "XCHLH Medium Cycle";
input group "XCHLH MC Market";
input int xCHLHMcLength = 72; // Length
input double xCHLHMcThresholdInPips = 0.3; // Threshold In Pips
input ENUM_SERIESMODE xCHLHMcHHMode = MODE_HIGH; // Highest High Calculation Method
input ENUM_SERIESMODE xCHLHMcLLMode = MODE_LOW; // Lowest Low Calculation Method
input group "XCHLH MC Style";
input int xCHLHMcDrawWidth = 1; // Draw Width
input ENUM_DRAW_TYPE xCHLHMcDrawType = DRAW_LINE; // Draw Type
input ENUM_LINE_STYLE xCHLHMcDrawStyle = STYLE_DOT; // Draw Style
input color xCHLHMcHHColor = clrLime; // Highest High Color
input color xCHLHMcLLColor = clrRed; // Lowest Low Color
input group "XCHLH MC Drawings";
input bool xCHLHMcDrawHH = true; // Draw Highest High
input bool xCHLHMcDrawLL = true; // Draw Lowest Low
//
// SC Inputs ...
input group "XCHLH Short Cycle";
input group "XCHLH SC Market";
input int xCHLHScLength = 7; // Length
input double xCHLHScThresholdInPips = 0.3; // Threshold In Pips
input ENUM_SERIESMODE xCHLHScHHMode = MODE_HIGH; // Highest High Calculation Method
input ENUM_SERIESMODE xCHLHScLLMode = MODE_LOW; // Lowest Low Calculation Method
input group "XCHLH SC Style";
input int xCHLHScDrawWidth = 1; // Draw Width
input ENUM_DRAW_TYPE xCHLHScDrawType = DRAW_LINE; // Draw Type
input ENUM_LINE_STYLE xCHLHScDrawStyle = STYLE_DOT; // Draw Style
input color xCHLHScHHColor = clrLightBlue; // Highest High Color
input color xCHLHScLLColor = clrLightSalmon; // Lowest Low Color
input group "XCHLH SC Drawings";
input bool xCHLHScDrawHH = true; // Draw Highest High
input bool xCHLHScDrawLL = true; // Draw Lowest Low
//
// END Inputs ...
//
//
// START Definitions ...
//
int xCHLHHandler = INVALID_HANDLE;
double xCHLHLcHHBuffer[];
double xCHLHLcLLBuffer[];
double xCHLHMcHHBuffer[];
double xCHLHMcLLBuffer[];
double xCHLHScHHBuffer[];
double xCHLHScLLBuffer[];
//
// END Definitions ...
//
//
// START Handler Functions ...
//
//
// Init Oscillators ...
bool XCHLHInitHandlers()
{
//
bool result = false;
//
// Initialize Indicator/Oscillator Handlers ...
ResetLastError();
//
// XCHLH Handler ...
ArraySetAsSeries(xCHLHLcHHBuffer, true);
ArraySetAsSeries(xCHLHLcLLBuffer, true);
ArraySetAsSeries(xCHLHMcHHBuffer, true);
ArraySetAsSeries(xCHLHMcLLBuffer, true);
ArraySetAsSeries(xCHLHScHHBuffer, true);
ArraySetAsSeries(xCHLHScLLBuffer, true);
xCHLHHandler = iCustom(
_Symbol,
_Period,
"x-saherelm.xchlh.oscillator",
//
// Inputs ...
//
// Commons ...
"",
xCHLHDrawHotAreas,
xCHLHHotHHArrowCode,
xCHLHHotHHArrowColor,
xCHLHHotLLArrowCode,
xCHLHHotLLArrowColor,
//
// LC ...
"",
"",
xCHLHLcLength,
xCHLHLcThresholdInPips,
xCHLHLcHHMode,
xCHLHLcLLMode,
"",
xCHLHLcDrawWidth,
xCHLHLcDrawType,
xCHLHLcDrawStyle,
xCHLHLcHHColor,
xCHLHLcLLColor,
"",
xCHLHLcDrawHH,
xCHLHLcDrawLL,
//
// MC ...
"",
"",
xCHLHMcLength,
xCHLHMcThresholdInPips,
xCHLHMcHHMode,
xCHLHMcLLMode,
"",
xCHLHMcDrawWidth,
xCHLHMcDrawType,
xCHLHMcDrawStyle,
xCHLHMcHHColor,
xCHLHMcLLColor,
"",
xCHLHMcDrawHH,
xCHLHMcDrawLL,
//
// SC ...
"",
"",
xCHLHScLength,
xCHLHScThresholdInPips,
xCHLHScHHMode,
xCHLHScLLMode,
"",
xCHLHScDrawWidth,
xCHLHScDrawType,
xCHLHScDrawStyle,
xCHLHScHHColor,
xCHLHScLLColor,
"",
xCHLHScDrawHH,
xCHLHScDrawLL);
if (xCHLHHandler == INVALID_HANDLE)
{
//
LogMessage("failed to Initialize XCHLH Indicator: " + (string)GetLastError());
return result;
}
//
result = true;
//
return result;
}
//
// Release Oscillators ...
void XCHLHReleaseHandlers()
{
IndicatorRelease(xCHLHHandler);
}
//
// Handle Reading Buffers ...
void XCHLHReadBuffers(
int xCHLHItemsPerTick // Number Of Reading Buffer Items Per Tick
)
{
//
// XCHLH LC HH Buffer ...
CopyBuffer(
xCHLHHandler,
X_XCHLH_LC_HH_LINE,
0,
xCHLHItemsPerTick,
xCHLHLcHHBuffer);
//
// XCHLH LC LL Buffer ...
CopyBuffer(
xCHLHHandler,
X_XCHLH_LC_LL_LINE,
0,
xCHLHItemsPerTick,
xCHLHLcLLBuffer);
//
// XCHLH MC HH Buffer ...
CopyBuffer(
xCHLHHandler,
X_XCHLH_MC_HH_LINE,
0,
xCHLHItemsPerTick,
xCHLHMcHHBuffer);
//
// XCHLH MC LL Buffer ...
CopyBuffer(
xCHLHHandler,
X_XCHLH_MC_LL_LINE,
0,
xCHLHItemsPerTick,
xCHLHMcLLBuffer);
//
// XCHLH SC HH Buffer ...
CopyBuffer(
xCHLHHandler,
X_XCHLH_SC_HH_LINE,
0,
xCHLHItemsPerTick,
xCHLHScHHBuffer);
//
// XCHLH SC LL Buffer ...
CopyBuffer(
xCHLHHandler,
X_XCHLH_SC_LL_LINE,
0,
xCHLHItemsPerTick,
xCHLHScLLBuffer);
}
//
// END Handler Funcions ...
//
//
// START XCHLH Custom Functions ...
//
//
// Check LC and MC has Same HH ...
bool XCHLHIsLCMCHasSameHH(
int bar_index // Specified Bar Index ...
)
{
//
bool result = false;
//
// Validate Args ...
if (!XCHLHIsValidBufferSizes(bar_index + 1))
{
return result;
}
//
double lcValue = xCHLHLcHHBuffer[bar_index];
double mcValue = xCHLHMcHHBuffer[bar_index];
//
result = lcValue == mcValue;
//
return result;
}
//
// Check LC and MC has Same LL ...
bool XCHLHIsLCMCHasSameLL(
int bar_index // Specified Bar Index ...
)
{
//
bool result = false;
//
// Validate Args ...
if (!XCHLHIsValidBufferSizes(bar_index + 1))
{
return result;
}
//
double lcValue = xCHLHLcLLBuffer[bar_index];
double mcValue = xCHLHMcLLBuffer[bar_index];
//
result = lcValue == mcValue;
//
return result;
}
//
// Check LC and SC has Same HH ...
bool XCHLHIsLCSCHasSameHH(
int bar_index // Specified Bar Index ...
)
{
//
bool result = false;
//
// Validate Args ...
if (!XCHLHIsValidBufferSizes(bar_index + 1))
{
return result;
}
//
double lcValue = xCHLHLcHHBuffer[bar_index];
double scValue = xCHLHScHHBuffer[bar_index];
//
result = lcValue == scValue;
//
return result;
}
//
// Check LC and SC has Same LL ...
bool XCHLHIsLCSCHasSameLL(
int bar_index // Specified Bar Index ...
)
{
//
bool result = false;
//
// Validate Args ...
if (!XCHLHIsValidBufferSizes(bar_index + 1))
{
return result;
}
//
double lcValue = xCHLHLcLLBuffer[bar_index];
double scValue = xCHLHScLLBuffer[bar_index];
//
result = lcValue == scValue;
//
return result;
}
//
// Check MC and SC has Same HH ...
bool XCHLHIsMCSCHasSameHH(
int bar_index // Specified Bar Index ...
)
{
//
bool result = false;
//
// Validate Args ...
if (!XCHLHIsValidBufferSizes(bar_index + 1))
{
return result;
}
//
double mcValue = xCHLHMcHHBuffer[bar_index];
double scValue = xCHLHScHHBuffer[bar_index];
//
result = mcValue == scValue;
//
return result;
}
//
// Check MC and SC has Same LL ...
bool XCHLHIsMCSCHasSameLL(
int bar_index // Specified Bar Index ...
)
{
//
bool result = false;
//
// Validate Args ...
if (!XCHLHIsValidBufferSizes(bar_index + 1))
{
return result;
}
//
double mcValue = xCHLHMcLLBuffer[bar_index];
double scValue = xCHLHScLLBuffer[bar_index];
//
result = mcValue == scValue;
//
return result;
}
//
// Check Is Same Highest Highs ...
bool XCHLHIsSameHHs(
int bar_index // Specified Bar Index ...
)
{
//
bool result = false;
//
// Validate Args ...
if (!XCHLHIsValidBufferSizes(bar_index + 1))
{
return result;
}
//
double lcValue = xCHLHLcHHBuffer[bar_index];
double mcValue = xCHLHMcHHBuffer[bar_index];
double scValue = xCHLHScHHBuffer[bar_index];
//
result =
//
lcValue == mcValue &&
mcValue == scValue
//
;
//
return result;
}
//
// Check Is Same Lowest Lows ...
bool XCHLHIsSameLLs(
int bar_index // Specified Bar Index ...
)
{
//
bool result = false;
//
// Validate Args ...
if (!XCHLHIsValidBufferSizes(bar_index + 1))
{
return result;
}
//
double lcValue = xCHLHLcLLBuffer[bar_index];
double mcValue = xCHLHMcLLBuffer[bar_index];
double scValue = xCHLHScLLBuffer[bar_index];
//
result =
//
lcValue == mcValue &&
mcValue == scValue
//
;
//
return result;
}
//
// Check Medium Cycle is On Top of Long Cycle's Mid ...
bool XCHLHIsMCOnTopOfLC(
int bar_index // Specified Bar Index ...
)
{
//
bool result = false;
//
// Validate Args ...
if (
bar_index < 0 ||
!XCHLHIsValidBufferSizes(bar_index + 1))
{
return result;
}
//
ENUM_X_XCHLH_CYCLES sCycle = X_XCHLH_CYCLE_MEDIUM;
ENUM_X_XCHLH_CYCLES dCycle = X_XCHLH_CYCLE_LONG;
//
result =
//
XCHLHCheckCycleIsOnTopOfAnother(
bar_index,
sCycle,
dCycle)
//
;
//
return result;
}
//
// Check Medium Cycle is In Bottom of Long Cycle's Mid ...
bool XCHLHIsMCInBottomOfLC(
int bar_index // Specified Bar Index ...
)
{
//
bool result = false;
//
// Validate Args ...
if (
bar_index < 0 ||
!XCHLHIsValidBufferSizes(bar_index + 1))
{
return result;
}
//
ENUM_X_XCHLH_CYCLES sCycle = X_XCHLH_CYCLE_MEDIUM;
ENUM_X_XCHLH_CYCLES dCycle = X_XCHLH_CYCLE_LONG;
//
result =
//
XCHLHCheckCycleIsInBottomOfAnother(
bar_index,
sCycle,
dCycle)
//
;
//
return result;
}
//
// Check and Validate Buffer Sizes ...
bool XCHLHIsValidBufferSizes(
int size // Specified Min Size
)
{
//
bool result = false;
//
result =
//
ArraySize(xCHLHLcHHBuffer) > size &&
ArraySize(xCHLHLcLLBuffer) > size &&
//
ArraySize(xCHLHMcHHBuffer) > size &&
ArraySize(xCHLHMcLLBuffer) > size &&
//
ArraySize(xCHLHScHHBuffer) > size &&
ArraySize(xCHLHScLLBuffer) > size;
//
return result;
}
//
// Get Cycle Middle Value ...
double XCHLHGetCycleMid(
int bar_index, // Specified Bar Index ...
ENUM_X_XCHLH_CYCLES cycle // Specified Cycle ...
)
{
//
double result = 0;
//
// Validate Args ...
if (
bar_index < 0 ||
!XCHLHIsValidBufferSizes(bar_index + 1))
{
return result;
}
//
// Retrieve Cycle Max Value ...
double iMax = XCHLHGetCycleMax(
bar_index,
cycle);
//
// Retrieve Cycle Min Value ...
double iMin = XCHLHGetCycleMin(
bar_index,
cycle);
//
result = (iMax - iMin) / 2;
//
return result;
}
//
// Get Cycle Max Value ...
double XCHLHGetCycleMax(
int bar_index, // Specified Bar Index ...
ENUM_X_XCHLH_CYCLES cycle // Specified Cycle ...
)
{
//
double result = 0;
//
// Validate Args ...
if (
bar_index < 0 ||
!XCHLHIsValidBufferSizes(bar_index + 1))
{
return result;
}
//
switch (cycle)
{
//
// Long Cycle ...
case X_XCHLH_CYCLE_LONG:
result = xCHLHLcHHBuffer[1];
break;
//
// Medium Cycle ...
case X_XCHLH_CYCLE_MEDIUM:
result = xCHLHMcHHBuffer[1];
break;
//
// Short Cycle ...
case X_XCHLH_CYCLE_SHORT:
result = xCHLHScHHBuffer[1];
break;
}
//
return result;
}
//
// Get Specified Cycles Max Value ...
double XCHLHGetCyclesMax(
int bar_index, // Specified Bar Index ...
ENUM_X_XCHLH_CYCLES &cycles[] // Specified Cycle ...
)
{
//
bool result = 0;
//
// Validate Args ...
if (
bar_index < 0 ||
ArraySize(cycles) <= 0 ||
!XCHLHIsValidBufferSizes(bar_index + 1))
{
return result;
}
//
// Loop Through Cycles ...
for (int i = 0; i < ArraySize(cycles); i++)
{
//
ENUM_X_XCHLH_CYCLES iCycle = cycles[i];
//
double iValue = XCHLHGetCycleMax(
bar_index,
iCycle);
//
result = result == 0 || result < iValue ? iValue : result;
}
//
return result;
}
//
// Get Cycle Min Value ...
double XCHLHGetCycleMin(
int bar_index, // Specified Bar Index ...
ENUM_X_XCHLH_CYCLES cycle // Specified Cycle ...
)
{
//
double result = 0;
//
// Validate Args ...
if (
bar_index < 0 ||
!XCHLHIsValidBufferSizes(bar_index + 1))
{
return result;
}
//
switch (cycle)
{
//
// Long Cycle ...
case X_XCHLH_CYCLE_LONG:
result = xCHLHLcLLBuffer[1];
break;
//
// Medium Cycle ...
case X_XCHLH_CYCLE_MEDIUM:
result = xCHLHMcLLBuffer[1];
break;
//
// Short Cycle ...
case X_XCHLH_CYCLE_SHORT:
result = xCHLHScLLBuffer[1];
break;
}
//
return result;
}
//
// Get Specified Cycles Min Value ...
double XCHLHGetCyclesMin(
int bar_index, // Specified Bar Index ...
ENUM_X_XCHLH_CYCLES &cycles[] // Specified Cycle ...
)
{
//
bool result = 0;
//
// Validate Args ...
if (
bar_index < 0 ||
ArraySize(cycles) <= 0 ||
!XCHLHIsValidBufferSizes(bar_index + 1))
{
return result;
}
//
// Loop Through Cycles ...
for (int i = 0; i < ArraySize(cycles); i++)
{
//
ENUM_X_XCHLH_CYCLES iCycle = cycles[i];
//
double iValue = XCHLHGetCycleMin(
bar_index,
iCycle);
//
result = result == 0 || result > iValue ? iValue : result;
}
//
return result;
}
//
// Check a Cycle is On Top of Another Cycle's Mid ...
bool XCHLHCheckCycleIsOnTopOfAnother(
int bar_index, // Specified Bar Index ...
ENUM_X_XCHLH_CYCLES sourceCycle, // Specified Source Cycle which Checks ...
ENUM_X_XCHLH_CYCLES destCycle // Specified Dest Cycle which source Checked based on it ...
)
{
//
bool result = false;
//
// Validate Args ...
if (
bar_index < 0 ||
!XCHLHIsValidBufferSizes(bar_index + 1))
{
return result;
}
//
// Retrieve Min Value of Source Cycle ...
double iMin = XCHLHGetCycleMin(
bar_index,
sourceCycle);
//
// Retrieve Mid Value of Dest Cycle ...
double iMid = XCHLHGetCycleMid(
bar_index,
destCycle);
//
// Generate Result ...
result =
//
iMin >= iMid
//
;
//
return result;
}
//
// Check a Cycle is Under Bottom of Another Cycle's Mid ...
bool XCHLHCheckCycleIsInBottomOfAnother(
int bar_index, // Specified Bar Index ...
ENUM_X_XCHLH_CYCLES sourceCycle, // Specified Source Cycle which Checks ...
ENUM_X_XCHLH_CYCLES destCycle // Specified Dest Cycle which source Checked based on it ...
)
{
//
bool result = false;
//
// Validate Args ...
if (
bar_index < 0 ||
!XCHLHIsValidBufferSizes(bar_index + 1))
{
return result;
}
//
// Retrieve Max Value of Source Cycle ...
double iMax = XCHLHGetCycleMax(
bar_index,
sourceCycle);
//
// Retrieve Mid Value of Dest Cycle ...
double iMid = XCHLHGetCycleMid(
bar_index,
destCycle);
//
// Generate Result ...
result =
//
iMax <= iMid
//
;
//
return result;
}
//
// END XCHLH Custom Functions ...
//