2230 lines
43 KiB
Plaintext
2230 lines
43 KiB
Plaintext
/////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 XCHMA 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 ...
|
|
//
|
|
|
|
//
|
|
// XCHMA Cycles ...
|
|
enum ENUM_XCHMA_CYCLES
|
|
{
|
|
X_XCHMA_CYCLE_LONG,
|
|
X_XCHMA_CYCLE_MEDIUM,
|
|
X_XCHMA_CYCLE_SHORT,
|
|
};
|
|
|
|
//
|
|
// XCHMA Oscillator Hot State Presentation ...
|
|
enum ENUM_XCHMA_HOT_STATES
|
|
{
|
|
X_XCHMA_HOT_BULLISH = 1,
|
|
X_XCHMA_HOT_NEUTURAL = 0,
|
|
X_XCHMA_HOT_BEARISH = -1,
|
|
};
|
|
|
|
//
|
|
// XCHMA Oscillator Cycles State Presentation ...
|
|
enum ENUM_XCHMA_CYCLE_STATES
|
|
{
|
|
X_XCHMA_FAST_CROSSED_OVER_SLOW = 2,
|
|
X_XCHMA_FAST_OVER_SLOW = 1,
|
|
X_XCHMA_NEUTURAL = 0,
|
|
X_XCHMA_FAST_UNDER_SLOW = -1,
|
|
X_XCHMA_FAST_CROSSED_UNDER_SLOW = -2,
|
|
};
|
|
|
|
//
|
|
// XCHMA Oscillator Buffer Lines ...
|
|
enum ENUM_X_XCHMA_BUFFER_LINES
|
|
{
|
|
X_XCHMA_LC_FAST_LINE = 0,
|
|
X_XCHMA_LC_SLOW_LINE = 1,
|
|
X_XCHMA_LC_STATE_LINE = 6,
|
|
X_XCHMA_MC_FAST_LINE = 2,
|
|
X_XCHMA_MC_SLOW_LINE = 3,
|
|
X_XCHMA_MC_STATE_LINE = 7,
|
|
X_XCHMA_SC_FAST_LINE = 4,
|
|
X_XCHMA_SC_SLOW_LINE = 5,
|
|
X_XCHMA_SC_STATE_LINE = 8,
|
|
X_XCHMA_HOT_STATE_LINE = 9,
|
|
};
|
|
|
|
//
|
|
// END Enum Definitions ...
|
|
//
|
|
|
|
//
|
|
// START Inputs ...
|
|
//
|
|
|
|
// input group "XCHMA Oscillator";
|
|
|
|
// //
|
|
// // Commons ...
|
|
// input group "XCHMA Hot Areas";
|
|
// input bool xCHMADrawHotAreas = false; // Draw Hot Areas Symbol;
|
|
// input uchar xCHMAHotBullishArrowCode = 228; // Hot Bullish Arrow Code;
|
|
// input color xCHMAHotBullishArrowColor = clrAqua; // Hot Bullish Arrow Color;
|
|
// input uchar xCHMAHotBearishArrowCode = 230; // Hot Bearish Arrow Code;
|
|
// input color xCHMAHotBearishArrowColor = clrFuchsia; // Hot Bearish Arrow Color;
|
|
|
|
// //
|
|
// // LC Inputs ...
|
|
// input group "XCHMA Long Cycle";
|
|
// input group "XCHMA LC Market";
|
|
// input int xCHMALcFastLength = 288; // Fast Length
|
|
// input int xCHMALcSlowLength = 576; // Slow Length
|
|
// input ENUM_MA_METHOD xCHMALcMethod = MODE_EMA; // Calculation Method
|
|
// input ENUM_APPLIED_PRICE xCHMALcAppliedTo = PRICE_CLOSE; // Applied To
|
|
// input group "XCHMA LC Style";
|
|
// input int xCHMALcDrawWidth = 1; // Draw Width
|
|
// input ENUM_DRAW_TYPE xCHMALcDrawType = DRAW_LINE; // Draw Type
|
|
// input ENUM_LINE_STYLE xCHMALcDrawStyle = STYLE_DOT; // Draw Style
|
|
// input color xCHMALcFastColor = clrAqua; // Fast Color
|
|
// input color xCHMALcSlowColor = clrFuchsia; // Slow Color
|
|
// input group "XCHMA LC Drawings";
|
|
// input bool xCHMALcDrawFast = true; // Draw Fast
|
|
// input bool xCHMALcDrawSlow = true; // Draw Slow
|
|
// input bool xCHMALcDrawCrosses = false; // Draw Cross Lines
|
|
|
|
// //
|
|
// // MC Inputs ...
|
|
// input group "XCHMA Medium Cycle";
|
|
// input group "XCHMA MC Market";
|
|
// input int xCHMAMcFastLength = 72; // Fast Length
|
|
// input int xCHMAMcSlowLength = 144; // Slow Length
|
|
// input ENUM_MA_METHOD xCHMAMcMethod = MODE_EMA; // Calculation Method
|
|
// input ENUM_APPLIED_PRICE xCHMAMcAppliedTo = PRICE_CLOSE; // Applied To
|
|
// input group "XCHMA MC Style";
|
|
// input int xCHMAMcDrawWidth = 1; // Draw Width
|
|
// input ENUM_DRAW_TYPE xCHMAMcDrawType = DRAW_LINE; // Draw Type
|
|
// input ENUM_LINE_STYLE xCHMAMcDrawStyle = STYLE_DOT; // Draw Style
|
|
// input color xCHMAMcFastColor = clrLime; // Fast Color
|
|
// input color xCHMAMcSlowColor = clrRed; // Slow Color
|
|
// input group "XCHMA MC Drawings";
|
|
// input bool xCHMAMcDrawFast = true; // Draw Fast
|
|
// input bool xCHMAMcDrawSlow = true; // Draw Slow
|
|
// input bool xCHMAMcDrawCrosses = false; // Draw Cross Lines
|
|
|
|
// //
|
|
// // SC Inputs ...
|
|
// input group "XCHMA Short Cycle";
|
|
// input group "XCHMA SC Market";
|
|
// input int xCHMAScFastLength = 7; // Fast Length
|
|
// input int xCHMAScSlowLength = 14; // Slow Length
|
|
// input ENUM_MA_METHOD xCHMAScMethod = MODE_SMA; // Calculation Method
|
|
// input ENUM_APPLIED_PRICE xCHMAScAppliedTo = PRICE_CLOSE; // Applied To
|
|
// input group "XCHMA SC Style";
|
|
// input int xCHMAScDrawWidth = 1; // Draw Width
|
|
// input ENUM_DRAW_TYPE xCHMAScDrawType = DRAW_LINE; // Draw Type
|
|
// input ENUM_LINE_STYLE xCHMAScDrawStyle = STYLE_SOLID; // Draw Style
|
|
// input color xCHMAScFastColor = clrLightBlue; // Fast Color
|
|
// input color xCHMAScSlowColor = clrLightSalmon; // Slow Color
|
|
// input group "XCHMA SC Drawings";
|
|
// input bool xCHMAScDrawFast = true; // Draw Fast
|
|
// input bool xCHMAScDrawSlow = true; // Draw Slow
|
|
// input bool xCHMAScDrawCrosses = false; // Draw Cross Lines
|
|
|
|
//
|
|
// Configurations ...
|
|
//
|
|
// Commons ...
|
|
bool xCHMADrawHotAreas = false; // Draw Hot Areas Symbol;
|
|
uchar xCHMAHotBullishArrowCode = 228; // Hot Bullish Arrow Code;
|
|
color xCHMAHotBullishArrowColor = clrAqua; // Hot Bullish Arrow Color;
|
|
uchar xCHMAHotBearishArrowCode = 230; // Hot Bearish Arrow Code;
|
|
color xCHMAHotBearishArrowColor = clrFuchsia; // Hot Bearish Arrow Color;
|
|
|
|
//
|
|
// LC Inputs ...
|
|
int xCHMALcFastLength = 288; // Fast Length
|
|
int xCHMALcSlowLength = 576; // Slow Length
|
|
ENUM_MA_METHOD xCHMALcMethod = MODE_EMA; // Calculation Method
|
|
ENUM_APPLIED_PRICE xCHMALcAppliedTo = PRICE_CLOSE; // Applied To
|
|
int xCHMALcDrawWidth = 1; // Draw Width
|
|
ENUM_DRAW_TYPE xCHMALcDrawType = DRAW_LINE; // Draw Type
|
|
ENUM_LINE_STYLE xCHMALcDrawStyle = STYLE_DOT; // Draw Style
|
|
color xCHMALcFastColor = clrAqua; // Fast Color
|
|
color xCHMALcSlowColor = clrFuchsia; // Slow Color
|
|
bool xCHMALcDrawFast = true; // Draw Fast
|
|
bool xCHMALcDrawSlow = true; // Draw Slow
|
|
bool xCHMALcDrawCrosses = false; // Draw Cross Lines
|
|
|
|
//
|
|
// MC Inputs ...
|
|
int xCHMAMcFastLength = 72; // Fast Length
|
|
int xCHMAMcSlowLength = 144; // Slow Length
|
|
ENUM_MA_METHOD xCHMAMcMethod = MODE_EMA; // Calculation Method
|
|
ENUM_APPLIED_PRICE xCHMAMcAppliedTo = PRICE_CLOSE; // Applied To
|
|
int xCHMAMcDrawWidth = 1; // Draw Width
|
|
ENUM_DRAW_TYPE xCHMAMcDrawType = DRAW_LINE; // Draw Type
|
|
ENUM_LINE_STYLE xCHMAMcDrawStyle = STYLE_DOT; // Draw Style
|
|
color xCHMAMcFastColor = clrLime; // Fast Color
|
|
color xCHMAMcSlowColor = clrRed; // Slow Color
|
|
bool xCHMAMcDrawFast = true; // Draw Fast
|
|
bool xCHMAMcDrawSlow = true; // Draw Slow
|
|
bool xCHMAMcDrawCrosses = false; // Draw Cross Lines
|
|
|
|
//
|
|
// SC Inputs ...
|
|
int xCHMAScFastLength = 7; // Fast Length
|
|
int xCHMAScSlowLength = 14; // Slow Length
|
|
ENUM_MA_METHOD xCHMAScMethod = MODE_SMA; // Calculation Method
|
|
ENUM_APPLIED_PRICE xCHMAScAppliedTo = PRICE_CLOSE; // Applied To
|
|
int xCHMAScDrawWidth = 1; // Draw Width
|
|
ENUM_DRAW_TYPE xCHMAScDrawType = DRAW_LINE; // Draw Type
|
|
ENUM_LINE_STYLE xCHMAScDrawStyle = STYLE_SOLID; // Draw Style
|
|
color xCHMAScFastColor = clrLightBlue; // Fast Color
|
|
color xCHMAScSlowColor = clrLightSalmon; // Slow Color
|
|
bool xCHMAScDrawFast = true; // Draw Fast
|
|
bool xCHMAScDrawSlow = true; // Draw Slow
|
|
bool xCHMAScDrawCrosses = false; // Draw Cross Lines
|
|
|
|
//
|
|
// END Inputs ...
|
|
//
|
|
|
|
//
|
|
// START Definitions ...
|
|
//
|
|
|
|
int xCHMAHandler = INVALID_HANDLE;
|
|
double xCHMALcFastBuffer[];
|
|
double xCHMALcSlowBuffer[];
|
|
double xCHMAMcFastBuffer[];
|
|
double xCHMAMcSlowBuffer[];
|
|
double xCHMAScFastBuffer[];
|
|
double xCHMAScSlowBuffer[];
|
|
|
|
//
|
|
// END Definitions ...
|
|
//
|
|
|
|
//
|
|
// START Handler Functions ...
|
|
//
|
|
|
|
//
|
|
// Validate Inputs ...
|
|
bool XCHMAValidateInputs()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result =
|
|
xCHMAScFastLength >= 2 &&
|
|
xCHMAScSlowLength > xCHMAScFastLength &&
|
|
xCHMAMcFastLength > xCHMAScSlowLength &&
|
|
xCHMAMcSlowLength > xCHMAMcFastLength &&
|
|
xCHMALcFastLength > xCHMAMcSlowLength &&
|
|
xCHMALcSlowLength > xCHMALcFastLength;
|
|
|
|
//
|
|
if (!result)
|
|
{
|
|
//
|
|
LogMessage("XCHMA Oscillator Inputs Validation Failed ...");
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Init Oscillators ...
|
|
bool XCHMAInitHandlers()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Initialize Indicator/Oscillator Handlers ...
|
|
ResetLastError();
|
|
|
|
//
|
|
// XCHMA Handler ...
|
|
ArraySetAsSeries(xCHMALcFastBuffer, true);
|
|
ArraySetAsSeries(xCHMALcSlowBuffer, true);
|
|
ArraySetAsSeries(xCHMAMcFastBuffer, true);
|
|
ArraySetAsSeries(xCHMAMcSlowBuffer, true);
|
|
ArraySetAsSeries(xCHMAScFastBuffer, true);
|
|
ArraySetAsSeries(xCHMAScSlowBuffer, true);
|
|
xCHMAHandler = iCustom(
|
|
_Symbol,
|
|
_Period,
|
|
"x-saherelm.xchma.oscillator",
|
|
//
|
|
// Inputs ...
|
|
"",
|
|
xCHMADrawHotAreas,
|
|
xCHMAHotBullishArrowCode,
|
|
xCHMAHotBullishArrowColor,
|
|
xCHMAHotBearishArrowCode,
|
|
xCHMAHotBearishArrowColor,
|
|
//
|
|
// Long Cycle ...
|
|
"",
|
|
"",
|
|
xCHMALcFastLength,
|
|
xCHMALcSlowLength,
|
|
xCHMALcMethod,
|
|
xCHMALcAppliedTo,
|
|
"",
|
|
xCHMALcDrawWidth,
|
|
xCHMALcDrawType,
|
|
xCHMALcDrawStyle,
|
|
xCHMALcFastColor,
|
|
xCHMALcSlowColor,
|
|
"",
|
|
xCHMALcDrawFast,
|
|
xCHMALcDrawSlow,
|
|
xCHMALcDrawCrosses,
|
|
//
|
|
// Medium Cycle ...
|
|
"",
|
|
"",
|
|
xCHMAMcFastLength,
|
|
xCHMAMcSlowLength,
|
|
xCHMAMcMethod,
|
|
xCHMAMcAppliedTo,
|
|
"",
|
|
xCHMAMcDrawWidth,
|
|
xCHMAMcDrawType,
|
|
xCHMAMcDrawStyle,
|
|
xCHMAMcFastColor,
|
|
xCHMAMcSlowColor,
|
|
"",
|
|
xCHMAMcDrawFast,
|
|
xCHMAMcDrawSlow,
|
|
xCHMAMcDrawCrosses,
|
|
//
|
|
// Short Cycle ...
|
|
"",
|
|
"",
|
|
xCHMAScFastLength,
|
|
xCHMAScSlowLength,
|
|
xCHMAScMethod,
|
|
xCHMAScAppliedTo,
|
|
"",
|
|
xCHMAScDrawWidth,
|
|
xCHMAScDrawType,
|
|
xCHMAScDrawStyle,
|
|
xCHMAScFastColor,
|
|
xCHMAScSlowColor,
|
|
"",
|
|
xCHMAScDrawFast,
|
|
xCHMAScDrawSlow,
|
|
xCHMAScDrawCrosses);
|
|
if (xCHMAHandler == INVALID_HANDLE)
|
|
{
|
|
//
|
|
LogMessage("failed to Initialize XCHMA Oscillator: " + (string)GetLastError());
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = true;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Release Oscillators ...
|
|
void XCHMAReleaseHandlers()
|
|
{
|
|
IndicatorRelease(xCHMAHandler);
|
|
}
|
|
|
|
//
|
|
// Handle Reading Buffers ...
|
|
void XCHMAReadBuffers(
|
|
int xCHMAItemsPerTick // Number Of Reading Buffer Items Per Tick
|
|
)
|
|
{
|
|
//
|
|
// XCHMA Long Cycle ...
|
|
//
|
|
// XCHMA Fast ...
|
|
CopyBuffer(
|
|
xCHMAHandler,
|
|
X_XCHMA_LC_FAST_LINE,
|
|
0,
|
|
xCHMAItemsPerTick,
|
|
xCHMALcFastBuffer);
|
|
|
|
//
|
|
// XCHMA Slow ...
|
|
CopyBuffer(
|
|
xCHMAHandler,
|
|
X_XCHMA_LC_SLOW_LINE,
|
|
0,
|
|
xCHMAItemsPerTick,
|
|
xCHMALcSlowBuffer);
|
|
|
|
//
|
|
// XCHMA Medium Cycle ...
|
|
//
|
|
// XCHMA Fast ...
|
|
CopyBuffer(
|
|
xCHMAHandler,
|
|
X_XCHMA_MC_FAST_LINE,
|
|
0,
|
|
xCHMAItemsPerTick,
|
|
xCHMAMcFastBuffer);
|
|
|
|
//
|
|
// XCHMA Slow ...
|
|
CopyBuffer(
|
|
xCHMAHandler,
|
|
X_XCHMA_MC_SLOW_LINE,
|
|
0,
|
|
xCHMAItemsPerTick,
|
|
xCHMAMcSlowBuffer);
|
|
|
|
//
|
|
// XCHMA Short Cycle ...
|
|
//
|
|
// XCHMA Fast ...
|
|
CopyBuffer(
|
|
xCHMAHandler,
|
|
X_XCHMA_SC_FAST_LINE,
|
|
0,
|
|
xCHMAItemsPerTick,
|
|
xCHMAScFastBuffer);
|
|
|
|
//
|
|
// XCHMA Slow ...
|
|
CopyBuffer(
|
|
xCHMAHandler,
|
|
X_XCHMA_SC_SLOW_LINE,
|
|
0,
|
|
xCHMAItemsPerTick,
|
|
xCHMAScSlowBuffer);
|
|
}
|
|
|
|
//
|
|
// END Handler Funcions ...
|
|
//
|
|
|
|
//
|
|
// START XCHMA Custom Functions ...
|
|
//
|
|
|
|
//
|
|
// Retrieve Max Cycles Value ...
|
|
double XCHMAGetMax(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
double result = 0;
|
|
|
|
//
|
|
// Validate Args ...
|
|
if (!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// SC Fast ...
|
|
result = MathMax(
|
|
result,
|
|
xCHMAScFastBuffer[bar_index]);
|
|
|
|
//
|
|
// SC Slow ...
|
|
result = MathMax(
|
|
result,
|
|
xCHMAScSlowBuffer[bar_index]);
|
|
|
|
//
|
|
// MC Fast ...
|
|
result = MathMax(
|
|
result,
|
|
xCHMAMcFastBuffer[bar_index]);
|
|
|
|
//
|
|
// MC Slow ...
|
|
result = MathMax(
|
|
result,
|
|
xCHMAMcSlowBuffer[bar_index]);
|
|
|
|
//
|
|
// LC Fast ...
|
|
result = MathMax(
|
|
result,
|
|
xCHMALcFastBuffer[bar_index]);
|
|
|
|
//
|
|
// LC Slow ...
|
|
result = MathMax(
|
|
result,
|
|
xCHMALcSlowBuffer[bar_index]);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Retrieve Max Cycles Value ...
|
|
double XCHMAGetMin(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
double result = 0;
|
|
|
|
//
|
|
// Validate Args ...
|
|
if (!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = xCHMAScFastBuffer[bar_index];
|
|
|
|
//
|
|
// SC Fast ...
|
|
result = MathMin(
|
|
result,
|
|
xCHMAScFastBuffer[bar_index]);
|
|
|
|
//
|
|
// SC Slow ...
|
|
result = MathMin(
|
|
result,
|
|
xCHMAScSlowBuffer[bar_index]);
|
|
|
|
//
|
|
// MC Fast ...
|
|
result = MathMin(
|
|
result,
|
|
xCHMAMcFastBuffer[bar_index]);
|
|
|
|
//
|
|
// MC Slow ...
|
|
result = MathMin(
|
|
result,
|
|
xCHMAMcSlowBuffer[bar_index]);
|
|
|
|
//
|
|
// LC Fast ...
|
|
result = MathMin(
|
|
result,
|
|
xCHMALcFastBuffer[bar_index]);
|
|
|
|
//
|
|
// LC Slow ...
|
|
result = MathMin(
|
|
result,
|
|
xCHMALcSlowBuffer[bar_index]);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Short Cycle Over Max Of Cycle Channels ...
|
|
bool XCHMAIsSCOverMax(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Validate Args ...
|
|
if (
|
|
bar_index < 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double shortCycleMax1 = XCHMAGetCycleMaxValue(
|
|
bar_index,
|
|
X_XCHMA_CYCLE_SHORT);
|
|
|
|
//
|
|
ENUM_XCHMA_CYCLES cycles[];
|
|
Add(
|
|
X_XCHMA_CYCLE_MEDIUM,
|
|
cycles);
|
|
Add(
|
|
X_XCHMA_CYCLE_LONG,
|
|
cycles);
|
|
|
|
//
|
|
double nonOfShortCycleMax1 = XCHMAGetCyclesMaxValue(
|
|
bar_index,
|
|
cycles);
|
|
|
|
//
|
|
// Calculate Result ...
|
|
result =
|
|
//
|
|
shortCycleMax1 > nonOfShortCycleMax1
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Short Cycle Under Max Of Cycle Channels ...
|
|
bool XCHMAIsSCUnderMax(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Validate Args ...
|
|
if (
|
|
bar_index < 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double shortCycleMin1 = XCHMAGetCycleMinValue(
|
|
bar_index,
|
|
X_XCHMA_CYCLE_SHORT);
|
|
|
|
//
|
|
ENUM_XCHMA_CYCLES cycles[];
|
|
Add(
|
|
X_XCHMA_CYCLE_MEDIUM,
|
|
cycles);
|
|
Add(
|
|
X_XCHMA_CYCLE_LONG,
|
|
cycles);
|
|
|
|
//
|
|
double nonOfShortCycleMax1 = XCHMAGetCyclesMaxValue(
|
|
bar_index,
|
|
cycles);
|
|
|
|
//
|
|
// Calculate Result ...
|
|
result =
|
|
//
|
|
shortCycleMin1 < nonOfShortCycleMax1
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Short Cycle Over Min Of Cycle Channels ...
|
|
bool XCHMAIsSCOverMin(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Validate Args ...
|
|
if (
|
|
bar_index < 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double shortCycleMax1 = XCHMAGetCycleMaxValue(
|
|
bar_index,
|
|
X_XCHMA_CYCLE_SHORT);
|
|
|
|
//
|
|
ENUM_XCHMA_CYCLES cycles[];
|
|
Add(
|
|
X_XCHMA_CYCLE_MEDIUM,
|
|
cycles);
|
|
Add(
|
|
X_XCHMA_CYCLE_LONG,
|
|
cycles);
|
|
|
|
//
|
|
double nonOfShortCycleMin1 = XCHMAGetCyclesMinValue(
|
|
bar_index,
|
|
cycles);
|
|
|
|
//
|
|
// Calculate Result ...
|
|
result =
|
|
//
|
|
shortCycleMax1 > nonOfShortCycleMin1
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Short Cycle Under Min Of Cycle Channels ...
|
|
bool XCHMAIsSCUnderMin(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Validate Args ...
|
|
if (
|
|
bar_index < 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double shortCycleMin1 = XCHMAGetCycleMinValue(
|
|
bar_index,
|
|
X_XCHMA_CYCLE_SHORT);
|
|
|
|
//
|
|
ENUM_XCHMA_CYCLES cycles[];
|
|
Add(
|
|
X_XCHMA_CYCLE_MEDIUM,
|
|
cycles);
|
|
Add(
|
|
X_XCHMA_CYCLE_LONG,
|
|
cycles);
|
|
|
|
//
|
|
double nonOfShortCycleMin1 = XCHMAGetCyclesMinValue(
|
|
bar_index,
|
|
cycles);
|
|
|
|
//
|
|
// Calculate Result ...
|
|
result =
|
|
//
|
|
shortCycleMin1 < nonOfShortCycleMin1
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Short Cycle Crossed Over Max Of Cycle Channels ...
|
|
bool XCHMAIsSCCrossedOverMax(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Validate Args ...
|
|
if (
|
|
bar_index < 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 2))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double shortCycleMin1 = XCHMAGetCycleMinValue(
|
|
bar_index,
|
|
X_XCHMA_CYCLE_SHORT);
|
|
double shortCycleMin2 = XCHMAGetCycleMinValue(
|
|
bar_index + 1,
|
|
X_XCHMA_CYCLE_SHORT);
|
|
|
|
//
|
|
ENUM_XCHMA_CYCLES cycles[];
|
|
Add(
|
|
X_XCHMA_CYCLE_MEDIUM,
|
|
cycles);
|
|
Add(
|
|
X_XCHMA_CYCLE_LONG,
|
|
cycles);
|
|
|
|
//
|
|
double nonOfShortCycleMax1 = XCHMAGetCyclesMaxValue(
|
|
bar_index,
|
|
cycles);
|
|
double nonOfShortCycleMax2 = XCHMAGetCyclesMaxValue(
|
|
bar_index + 1,
|
|
cycles);
|
|
|
|
//
|
|
// Calculate Result ...
|
|
result =
|
|
//
|
|
shortCycleMin1 > nonOfShortCycleMax1 &&
|
|
shortCycleMin2 <= nonOfShortCycleMax2
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Short Cycle Crossed Under Max Of Cycle Channels ...
|
|
bool XCHMAIsSCCrossedUnderMax(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Validate Args ...
|
|
if (
|
|
bar_index < 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 2))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double shortCycleMax1 = XCHMAGetCycleMaxValue(
|
|
bar_index,
|
|
X_XCHMA_CYCLE_SHORT);
|
|
double shortCycleMax2 = XCHMAGetCycleMaxValue(
|
|
bar_index + 1,
|
|
X_XCHMA_CYCLE_SHORT);
|
|
|
|
//
|
|
ENUM_XCHMA_CYCLES cycles[];
|
|
Add(
|
|
X_XCHMA_CYCLE_MEDIUM,
|
|
cycles);
|
|
Add(
|
|
X_XCHMA_CYCLE_LONG,
|
|
cycles);
|
|
|
|
//
|
|
double nonOfShortCycleMax1 = XCHMAGetCyclesMaxValue(
|
|
bar_index,
|
|
cycles);
|
|
double nonOfShortCycleMax2 = XCHMAGetCyclesMaxValue(
|
|
bar_index + 1,
|
|
cycles);
|
|
|
|
//
|
|
// Calculate Result ...
|
|
result =
|
|
//
|
|
shortCycleMax1 < nonOfShortCycleMax1 &&
|
|
shortCycleMax2 >= nonOfShortCycleMax2
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Short Cycle Crossed Over Min Of Cycle Channels ...
|
|
bool XCHMAIsSCCrossedOverMin(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Validate Args ...
|
|
if (
|
|
bar_index < 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 2))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double shortCycleMin1 = XCHMAGetCycleMinValue(
|
|
bar_index,
|
|
X_XCHMA_CYCLE_SHORT);
|
|
double shortCycleMin2 = XCHMAGetCycleMinValue(
|
|
bar_index + 1,
|
|
X_XCHMA_CYCLE_SHORT);
|
|
|
|
//
|
|
ENUM_XCHMA_CYCLES cycles[];
|
|
Add(
|
|
X_XCHMA_CYCLE_MEDIUM,
|
|
cycles);
|
|
Add(
|
|
X_XCHMA_CYCLE_LONG,
|
|
cycles);
|
|
|
|
//
|
|
double nonOfShortCycleMin1 = XCHMAGetCyclesMinValue(
|
|
bar_index,
|
|
cycles);
|
|
double nonOfShortCycleMin2 = XCHMAGetCyclesMinValue(
|
|
bar_index + 1,
|
|
cycles);
|
|
|
|
//
|
|
// Calculate Result ...
|
|
result =
|
|
//
|
|
shortCycleMin1 > nonOfShortCycleMin1 &&
|
|
shortCycleMin2 <= nonOfShortCycleMin2
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Short Cycle Crossed Under Min Of Cycle Channels ...
|
|
bool XCHMAIsSCCrossedUnderMin(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Validate Args ...
|
|
if (
|
|
bar_index < 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 2))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double shortCycleMax1 = XCHMAGetCycleMaxValue(
|
|
bar_index,
|
|
X_XCHMA_CYCLE_SHORT);
|
|
double shortCycleMax2 = XCHMAGetCycleMaxValue(
|
|
bar_index + 1,
|
|
X_XCHMA_CYCLE_SHORT);
|
|
|
|
//
|
|
ENUM_XCHMA_CYCLES cycles[];
|
|
Add(
|
|
X_XCHMA_CYCLE_MEDIUM,
|
|
cycles);
|
|
Add(
|
|
X_XCHMA_CYCLE_LONG,
|
|
cycles);
|
|
|
|
//
|
|
double nonOfShortCycleMin1 = XCHMAGetCyclesMinValue(
|
|
bar_index,
|
|
cycles);
|
|
double nonOfShortCycleMin2 = XCHMAGetCyclesMinValue(
|
|
bar_index + 1,
|
|
cycles);
|
|
|
|
//
|
|
// Calculate Result ...
|
|
result =
|
|
//
|
|
shortCycleMax1 < nonOfShortCycleMin1 &&
|
|
shortCycleMax2 >= nonOfShortCycleMin2
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Long Cycle ...
|
|
//
|
|
|
|
//
|
|
// Check LC is Peak ...
|
|
bool XCHMAIsLCPeak(
|
|
int bar_index, // Specified Index ...
|
|
int length = 10 // Specified Length ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
length <= 0 ||
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + length + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = IsIncreasing(
|
|
bar_index + length,
|
|
bar_index,
|
|
xCHMALcSlowBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check LC is Vale ...
|
|
bool XCHMAIsLCVale(
|
|
int bar_index, // Specified Index ...
|
|
int length = 10 // Specified Length ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
length <= 0 ||
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + length + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = IsDecreasing(
|
|
bar_index + length,
|
|
bar_index,
|
|
xCHMALcSlowBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check LC Fast Crossed Over Slow ...
|
|
bool XCHMAIsLCFastCrossedOverSlow(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = IsCrossOver(
|
|
xCHMALcFastBuffer,
|
|
xCHMALcSlowBuffer,
|
|
bar_index);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check LC Fast Over Slow ...
|
|
bool XCHMAIsLCFastOverSlow(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = IsOver(
|
|
xCHMALcFastBuffer,
|
|
xCHMALcSlowBuffer,
|
|
bar_index);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check LC Fast Crossed Under Slow ...
|
|
bool XCHMAIsLCFastCrossedUnderSlow(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = IsCrossUnder(
|
|
xCHMALcFastBuffer,
|
|
xCHMALcSlowBuffer,
|
|
bar_index);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check LC Fast Under Slow ...
|
|
bool XCHMAIsLCFastUnderSlow(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = IsUnder(
|
|
xCHMALcFastBuffer,
|
|
xCHMALcSlowBuffer,
|
|
bar_index);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Get Trend Power ...
|
|
double XCHMAGetLCTrendPower(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
double result = 0;
|
|
|
|
//
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result =
|
|
//
|
|
MathAbs(xCHMALcFastBuffer[bar_index] - xCHMALcSlowBuffer[bar_index])
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check XTM TrendsDown or Up ...
|
|
bool XCHMAIsLCTrendsUp(
|
|
int bar_index, // Specified Index ...
|
|
int length = 10 // Specified Length ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + length + 2))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double trend1 = XCHMAGetLCTrendPower(bar_index);
|
|
|
|
//
|
|
int trendsUpCount = 0;
|
|
int trendsDownCount = 0;
|
|
for (int i = bar_index + 1; i < bar_index + length + 1; i++)
|
|
{
|
|
//
|
|
double iPrevTrend = XCHMAGetLCTrendPower(i + 1);
|
|
double iTrend = XCHMAGetLCTrendPower(i);
|
|
|
|
//
|
|
if (
|
|
trend1 > iTrend &&
|
|
iTrend >= iPrevTrend &&
|
|
trend1 >= iPrevTrend)
|
|
{
|
|
trendsUpCount++;
|
|
}
|
|
else if (
|
|
trend1 < iTrend &&
|
|
iTrend <= iPrevTrend &&
|
|
trend1 <= iPrevTrend)
|
|
{
|
|
trendsDownCount++;
|
|
}
|
|
}
|
|
|
|
//
|
|
result =
|
|
//
|
|
trendsUpCount > trendsDownCount
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check XTM TrendsDown or Up ...
|
|
bool XCHMAIsLCTrendsDown(
|
|
int bar_index, // Specified Index ...
|
|
int length = 10 // Specified Length ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + length + 2))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double trend1 = XCHMAGetLCTrendPower(bar_index);
|
|
|
|
//
|
|
int trendsUpCount = 0;
|
|
int trendsDownCount = 0;
|
|
for (int i = bar_index + 1; i < bar_index + length + 1; i++)
|
|
{
|
|
//
|
|
double iPrevTrend = XCHMAGetLCTrendPower(i + 1);
|
|
double iTrend = XCHMAGetLCTrendPower(i);
|
|
|
|
//
|
|
if (
|
|
trend1 > iTrend &&
|
|
iTrend >= iPrevTrend &&
|
|
trend1 >= iPrevTrend)
|
|
{
|
|
trendsUpCount++;
|
|
}
|
|
else if (
|
|
trend1 < iTrend &&
|
|
iTrend <= iPrevTrend &&
|
|
trend1 <= iPrevTrend)
|
|
{
|
|
trendsDownCount++;
|
|
}
|
|
}
|
|
|
|
//
|
|
result =
|
|
//
|
|
trendsDownCount > trendsUpCount
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Medium Cycle ...
|
|
//
|
|
|
|
//
|
|
// Check MC is Peak ...
|
|
bool XCHMAIsMCPeak(
|
|
int bar_index, // Specified Index ...
|
|
int length = 10 // Specified Length ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
length <= 0 ||
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + length + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = IsIncreasing(
|
|
bar_index + length,
|
|
bar_index,
|
|
xCHMAMcSlowBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check MC is Vale ...
|
|
bool XCHMAIsMCVale(
|
|
int bar_index, // Specified Index ...
|
|
int length = 10 // Specified Length ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
length <= 0 ||
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + length + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = IsDecreasing(
|
|
bar_index + length,
|
|
bar_index,
|
|
xCHMAMcSlowBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check MC Fast Crossed Over Slow ...
|
|
bool XCHMAIsMCFastCrossedOverSlow(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = IsCrossOver(
|
|
xCHMAMcFastBuffer,
|
|
xCHMAMcSlowBuffer,
|
|
bar_index);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check MC Fast Over Slow ...
|
|
bool XCHMAIsMCFastOverSlow(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = IsOver(
|
|
xCHMAMcFastBuffer,
|
|
xCHMAMcSlowBuffer,
|
|
bar_index);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check MC Fast Crossed Under Slow ...
|
|
bool XCHMAIsMCFastCrossedUnderSlow(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = IsCrossUnder(
|
|
xCHMAMcFastBuffer,
|
|
xCHMAMcSlowBuffer,
|
|
bar_index);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check MC Fast Under Slow ...
|
|
bool XCHMAIsMCFastUnderSlow(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = IsUnder(
|
|
xCHMAMcFastBuffer,
|
|
xCHMAMcSlowBuffer,
|
|
bar_index);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Get Trend Power ...
|
|
double XCHMAGetMCTrendPower(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
double result = 0;
|
|
|
|
//
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result =
|
|
//
|
|
MathAbs(xCHMAMcFastBuffer[bar_index] - xCHMAMcSlowBuffer[bar_index])
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check XTM TrendsDown or Up ...
|
|
bool XCHMAIsMCTrendsUp(
|
|
int bar_index, // Specified Index ...
|
|
int length = 10 // Specified Length ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + length + 2))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double trend1 = XCHMAGetMCTrendPower(bar_index);
|
|
|
|
//
|
|
int trendsUpCount = 0;
|
|
int trendsDownCount = 0;
|
|
for (int i = bar_index + 1; i < bar_index + length + 1; i++)
|
|
{
|
|
//
|
|
double iPrevTrend = XCHMAGetMCTrendPower(i + 1);
|
|
double iTrend = XCHMAGetMCTrendPower(i);
|
|
|
|
//
|
|
if (
|
|
trend1 > iTrend &&
|
|
iTrend >= iPrevTrend &&
|
|
trend1 >= iPrevTrend)
|
|
{
|
|
trendsUpCount++;
|
|
}
|
|
else if (
|
|
trend1 < iTrend &&
|
|
iTrend <= iPrevTrend &&
|
|
trend1 <= iPrevTrend)
|
|
{
|
|
trendsDownCount++;
|
|
}
|
|
}
|
|
|
|
//
|
|
result =
|
|
//
|
|
trendsUpCount > trendsDownCount
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check XTM TrendsDown or Up ...
|
|
bool XCHMAIsMCTrendsDown(
|
|
int bar_index, // Specified Index ...
|
|
int length = 10 // Specified Length ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + length + 2))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double trend1 = XCHMAGetMCTrendPower(bar_index);
|
|
|
|
//
|
|
int trendsUpCount = 0;
|
|
int trendsDownCount = 0;
|
|
for (int i = bar_index + 1; i < bar_index + length + 1; i++)
|
|
{
|
|
//
|
|
double iPrevTrend = XCHMAGetMCTrendPower(i + 1);
|
|
double iTrend = XCHMAGetMCTrendPower(i);
|
|
|
|
//
|
|
if (
|
|
trend1 > iTrend &&
|
|
iTrend >= iPrevTrend &&
|
|
trend1 >= iPrevTrend)
|
|
{
|
|
trendsUpCount++;
|
|
}
|
|
else if (
|
|
trend1 < iTrend &&
|
|
iTrend <= iPrevTrend &&
|
|
trend1 <= iPrevTrend)
|
|
{
|
|
trendsDownCount++;
|
|
}
|
|
}
|
|
|
|
//
|
|
result =
|
|
//
|
|
trendsDownCount > trendsUpCount
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Short Cycle ...
|
|
//
|
|
|
|
//
|
|
// Check SC is Peak ...
|
|
bool XCHMAIsSCPeak(
|
|
int bar_index, // Specified Index ...
|
|
int length = 10 // Specified Length ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
length <= 0 ||
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + length + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = IsIncreasing(
|
|
bar_index + length,
|
|
bar_index,
|
|
xCHMAScSlowBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check SC is Vale ...
|
|
bool XCHMAIsSCVale(
|
|
int bar_index, // Specified Index ...
|
|
int length = 10 // Specified Length ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
length <= 0 ||
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + length + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = IsDecreasing(
|
|
bar_index + length,
|
|
bar_index,
|
|
xCHMAScSlowBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check SC Fast Crossed Over Slow ...
|
|
bool XCHMAIsSCFastCrossedOverSlow(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = IsCrossOver(
|
|
xCHMAScFastBuffer,
|
|
xCHMAScSlowBuffer,
|
|
bar_index);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check SC Fast Over Slow ...
|
|
bool XCHMAIsSCFastOverSlow(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = IsOver(
|
|
xCHMAScFastBuffer,
|
|
xCHMAScSlowBuffer,
|
|
bar_index);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check SC Fast Crossed Under Slow ...
|
|
bool XCHMAIsSCFastCrossedUnderSlow(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = IsCrossUnder(
|
|
xCHMAScFastBuffer,
|
|
xCHMAScSlowBuffer,
|
|
bar_index);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check SC Fast Under Slow ...
|
|
bool XCHMAIsSCFastUnderSlow(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = IsUnder(
|
|
xCHMAScFastBuffer,
|
|
xCHMAScSlowBuffer,
|
|
bar_index);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Get SC Trend Power ...
|
|
double XCHMAGetSCTrendPower(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
double result = 0;
|
|
|
|
//
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result =
|
|
//
|
|
MathAbs(xCHMAScFastBuffer[bar_index] - xCHMAScSlowBuffer[bar_index])
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check SC Trends Up ...
|
|
bool XCHMAIsSCTrendsUp(
|
|
int bar_index, // Specified Index ...
|
|
int length = 10 // Specified Length ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + length + 2))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double trend1 = XCHMAGetSCTrendPower(bar_index);
|
|
|
|
//
|
|
int trendsUpCount = 0;
|
|
int trendsDownCount = 0;
|
|
for (int i = bar_index + 1; i < bar_index + length + 1; i++)
|
|
{
|
|
//
|
|
double iPrevTrend = XCHMAGetSCTrendPower(i + 1);
|
|
double iTrend = XCHMAGetSCTrendPower(i);
|
|
|
|
//
|
|
if (
|
|
trend1 > iTrend &&
|
|
iTrend >= iPrevTrend &&
|
|
trend1 >= iPrevTrend)
|
|
{
|
|
trendsUpCount++;
|
|
}
|
|
else if (
|
|
trend1 < iTrend &&
|
|
iTrend <= iPrevTrend &&
|
|
trend1 <= iPrevTrend)
|
|
{
|
|
trendsDownCount++;
|
|
}
|
|
}
|
|
|
|
//
|
|
result =
|
|
//
|
|
trendsUpCount > trendsDownCount
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check SC Trends Down ...
|
|
bool XCHMAIsSCTrendsDown(
|
|
int bar_index, // Specified Index ...
|
|
int length = 10 // Specified Length ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + length + 2))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double trend1 = XCHMAGetSCTrendPower(bar_index);
|
|
|
|
//
|
|
int trendsUpCount = 0;
|
|
int trendsDownCount = 0;
|
|
for (int i = bar_index + 1; i < bar_index + length + 1; i++)
|
|
{
|
|
//
|
|
double iPrevTrend = XCHMAGetSCTrendPower(i + 1);
|
|
double iTrend = XCHMAGetSCTrendPower(i);
|
|
|
|
//
|
|
if (
|
|
trend1 > iTrend &&
|
|
iTrend >= iPrevTrend &&
|
|
trend1 >= iPrevTrend)
|
|
{
|
|
trendsUpCount++;
|
|
}
|
|
else if (
|
|
trend1 < iTrend &&
|
|
iTrend <= iPrevTrend &&
|
|
trend1 <= iPrevTrend)
|
|
{
|
|
trendsDownCount++;
|
|
}
|
|
}
|
|
|
|
//
|
|
result =
|
|
//
|
|
trendsDownCount > trendsUpCount
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Utility Functions ...
|
|
//
|
|
|
|
//
|
|
// Check a Cycle is Over of Another ...
|
|
bool XCHMAIsCycleOverAnother(
|
|
int bar_index, // Specified Index ...
|
|
ENUM_XCHMA_CYCLES sourceCycle, // Specified Cycle ...
|
|
ENUM_XCHMA_CYCLES destCycle // Specified Cycle ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Validate BufferSize ...
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double sourceMinValue = XCHMAGetCycleMinValue(bar_index, sourceCycle);
|
|
double destMaxValue = XCHMAGetCycleMaxValue(bar_index, destCycle);
|
|
|
|
//
|
|
result =
|
|
//
|
|
sourceMinValue > destMaxValue
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check a Cycle is Under of Another ...
|
|
bool XCHMAIsCycleUnderAnother(
|
|
int bar_index, // Specified Index ...
|
|
ENUM_XCHMA_CYCLES sourceCycle, // Specified Cycle ...
|
|
ENUM_XCHMA_CYCLES destCycle // Specified Cycle ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Validate BufferSize ...
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double sourceMaxValue = XCHMAGetCycleMaxValue(bar_index, sourceCycle);
|
|
double destMinValue = XCHMAGetCycleMinValue(bar_index, destCycle);
|
|
|
|
//
|
|
result =
|
|
//
|
|
sourceMaxValue < destMinValue
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Get Cycle Min Value ...
|
|
double XCHMAGetCycleMinValue(
|
|
int bar_index, // Specified Index ...
|
|
ENUM_XCHMA_CYCLES cycle // Specified Cycle ...
|
|
)
|
|
{
|
|
//
|
|
double result = 0;
|
|
|
|
//
|
|
// Validate BufferSize ...
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
switch (cycle)
|
|
{
|
|
//
|
|
case X_XCHMA_CYCLE_LONG:
|
|
result = MathMin(
|
|
xCHMALcFastBuffer[bar_index],
|
|
xCHMALcSlowBuffer[bar_index]);
|
|
break;
|
|
|
|
//
|
|
case X_XCHMA_CYCLE_MEDIUM:
|
|
result = MathMin(
|
|
xCHMAMcFastBuffer[bar_index],
|
|
xCHMAMcSlowBuffer[bar_index]);
|
|
break;
|
|
|
|
//
|
|
case X_XCHMA_CYCLE_SHORT:
|
|
result = MathMin(
|
|
xCHMAScFastBuffer[bar_index],
|
|
xCHMAScSlowBuffer[bar_index]);
|
|
break;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Get Cycles Min Value ...
|
|
double XCHMAGetCyclesMinValue(
|
|
int bar_index, // Specified Index ...
|
|
ENUM_XCHMA_CYCLES &cycle[] // Specified Cycles ...
|
|
)
|
|
{
|
|
//
|
|
double result = 0;
|
|
|
|
//
|
|
// Validate Args ...
|
|
if (
|
|
//
|
|
bar_index <= 0 ||
|
|
ArraySize(cycle) <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1)
|
|
//
|
|
)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Loop Through Cycles ...
|
|
for (int i = 0; i < ArraySize(cycle); i++)
|
|
{
|
|
//
|
|
ENUM_XCHMA_CYCLES iCycle = cycle[i];
|
|
double iValue = XCHMAGetCycleMinValue(
|
|
bar_index,
|
|
iCycle);
|
|
|
|
//
|
|
result = result == 0 || result > iValue ? iValue : result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Get Cycle Max Value ...
|
|
double XCHMAGetCycleMaxValue(
|
|
int bar_index, // Specified Index ...
|
|
ENUM_XCHMA_CYCLES cycle // Specified Cycle ...
|
|
)
|
|
{
|
|
//
|
|
double result = 0;
|
|
|
|
//
|
|
// Validate BufferSize ...
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
switch (cycle)
|
|
{
|
|
//
|
|
case X_XCHMA_CYCLE_LONG:
|
|
result = MathMax(
|
|
xCHMALcFastBuffer[bar_index],
|
|
xCHMALcSlowBuffer[bar_index]);
|
|
break;
|
|
|
|
//
|
|
case X_XCHMA_CYCLE_MEDIUM:
|
|
result = MathMax(
|
|
xCHMAMcFastBuffer[bar_index],
|
|
xCHMAMcSlowBuffer[bar_index]);
|
|
break;
|
|
|
|
//
|
|
case X_XCHMA_CYCLE_SHORT:
|
|
result = MathMax(
|
|
xCHMAScFastBuffer[bar_index],
|
|
xCHMAScSlowBuffer[bar_index]);
|
|
break;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Get Cycles Max Value ...
|
|
double XCHMAGetCyclesMaxValue(
|
|
int bar_index, // Specified Index ...
|
|
ENUM_XCHMA_CYCLES &cycle[] // Specified Cycles ...
|
|
)
|
|
{
|
|
//
|
|
double result = 0;
|
|
|
|
//
|
|
// Validate Args ...
|
|
if (
|
|
//
|
|
bar_index <= 0 ||
|
|
ArraySize(cycle) <= 0 ||
|
|
!XCHMAIsValidBuffersSize(bar_index + 1)
|
|
//
|
|
)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Loop Through Cycles ...
|
|
for (int i = 0; i < ArraySize(cycle); i++)
|
|
{
|
|
//
|
|
ENUM_XCHMA_CYCLES iCycle = cycle[i];
|
|
double iValue = XCHMAGetCycleMaxValue(
|
|
bar_index,
|
|
iCycle);
|
|
|
|
//
|
|
result = result == 0 || result < iValue ? iValue : result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check all Buffers has valid Size ...
|
|
bool XCHMAIsValidBuffersSize(
|
|
int size // the size of buffers which min size for requirements
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
size <= 0 ||
|
|
//
|
|
ArraySize(xCHMALcFastBuffer) < size ||
|
|
ArraySize(xCHMALcSlowBuffer) < size ||
|
|
//
|
|
ArraySize(xCHMAMcFastBuffer) < size ||
|
|
ArraySize(xCHMAMcSlowBuffer) < size ||
|
|
//
|
|
ArraySize(xCHMAScFastBuffer) < size ||
|
|
ArraySize(xCHMAScSlowBuffer) < size
|
|
//
|
|
)
|
|
{
|
|
result = false;
|
|
}
|
|
else
|
|
{
|
|
result = true;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Add Specified Object to it's correspond Buffer ...
|
|
void Add(
|
|
ENUM_XCHMA_CYCLES item,
|
|
ENUM_XCHMA_CYCLES &buffer[])
|
|
{
|
|
//
|
|
ArrayResize(
|
|
buffer,
|
|
ArraySize(buffer) + 1);
|
|
|
|
//
|
|
buffer[ArraySize(buffer) - 1] = item;
|
|
}
|
|
|
|
//
|
|
// END XCHMA Custom Functions ...
|
|
//
|