Initial Commit ...
This commit is contained in:
@@ -0,0 +1,493 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XTF 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 ...
|
||||
//
|
||||
|
||||
//
|
||||
// XTF Indicator Buffer Lines ...
|
||||
enum ENUM_X_XTF_BUFFER_LINES
|
||||
{
|
||||
X_XTF_FAST_LINE = 0,
|
||||
X_XTF_SLOW_LINE = 1,
|
||||
};
|
||||
|
||||
//
|
||||
// END Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
input group "XTF Indicator";
|
||||
input ENUM_TIMEFRAMES xTFPeriod = PERIOD_H1; // Time Frame to work
|
||||
input ENUM_MA_METHOD xTFMethod = MODE_EMA; // Mode
|
||||
input ENUM_APPLIED_PRICE xTFAppliedTo = PRICE_CLOSE; // Applied To
|
||||
input int xTFFastLength = 9; // Fast Length
|
||||
input int xTFSlowLength = 18; // Slow Length
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
int xTFHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
double xTFFastBuffer[];
|
||||
double xTFSlowBuffer[];
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Handler Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Init Indicators ...
|
||||
bool XTFInitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator/Oscillator Handlers ...
|
||||
ResetLastError();
|
||||
|
||||
//
|
||||
// XTF Handler ...
|
||||
ArraySetAsSeries(xTFFastBuffer, true);
|
||||
ArraySetAsSeries(xTFSlowBuffer, true);
|
||||
|
||||
//
|
||||
xTFHandler = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
"x-saherelm.xtf.oscillator",
|
||||
//
|
||||
// Inputs ...
|
||||
xTFPeriod,
|
||||
xTFMethod,
|
||||
xTFAppliedTo,
|
||||
xTFFastLength,
|
||||
xTFSlowLength
|
||||
//
|
||||
);
|
||||
if (xTFHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
LogMessage("failed to Initialize XTF Oscillator: " + (string)GetLastError());
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Release Indicators ...
|
||||
void XTFReleaseHandlers()
|
||||
{
|
||||
IndicatorRelease(xTFHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Reading Buffers ...
|
||||
void XTFReadBuffers(
|
||||
int xTFItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
// Fast Buffer ...
|
||||
CopyBuffer(
|
||||
xTFHandler,
|
||||
X_XTF_FAST_LINE,
|
||||
0,
|
||||
xTFItemsPerTick,
|
||||
xTFFastBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Slow Buffer ...
|
||||
CopyBuffer(
|
||||
xTFHandler,
|
||||
X_XTF_SLOW_LINE,
|
||||
0,
|
||||
xTFItemsPerTick,
|
||||
xTFSlowBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// END Handler Funcions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Signal Related Conditions ...
|
||||
//
|
||||
|
||||
//
|
||||
// XTF Long Conditions ...
|
||||
bool XTFHasLongConditions(
|
||||
int xTFItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// XTF Short Conditions ...
|
||||
bool XTFHasShortConditions(
|
||||
int xTFItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Signal Related Conditions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XTF Custom Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// TODO: What we have to Implement ...
|
||||
// - []
|
||||
|
||||
//
|
||||
// Check Fast Crossed Over Slow ...
|
||||
bool XTFIsFastCrossedOverSlow(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTFIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTFFastBuffer[bar_index] > xTFSlowBuffer[bar_index] &&
|
||||
xTFFastBuffer[bar_index + 1] <= xTFSlowBuffer[bar_index + 1]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Fast Over Slow ...
|
||||
bool XTFIsFastOverSlow(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTFIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTFFastBuffer[bar_index] > xTFSlowBuffer[bar_index]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Fast Crossed Under Slow ...
|
||||
bool XTFIsFastCrossedUnderSlow(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTFIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTFFastBuffer[bar_index] < xTFSlowBuffer[bar_index] &&
|
||||
xTFFastBuffer[bar_index + 1] >= xTFSlowBuffer[bar_index + 1]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Fast Under Slow ...
|
||||
bool XTFIsFastUnderSlow(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTFIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTFFastBuffer[bar_index] < xTFSlowBuffer[bar_index]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Get Trend Power ...
|
||||
double XTFGetTrendPower(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTFIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
MathAbs(xTFFastBuffer[bar_index] - xTFSlowBuffer[bar_index])
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check XTM TrendsDown or Up ...
|
||||
bool XTFIsTrendsUp(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 15 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTFIsValidBuffersSize(bar_index + length + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double trend1 = XTFGetTrendPower(bar_index);
|
||||
|
||||
//
|
||||
int trendsUpCount = 0;
|
||||
int trendsDownCount = 0;
|
||||
for (int i = bar_index + 1; i < bar_index + length + 1; i++)
|
||||
{
|
||||
//
|
||||
double iPrevTrend = XTFGetTrendPower(i + 1);
|
||||
double iTrend = XTFGetTrendPower(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 XTFIsTrendsDown(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 15 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTFIsValidBuffersSize(bar_index + length + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double trend1 = XTFGetTrendPower(bar_index);
|
||||
|
||||
//
|
||||
int trendsUpCount = 0;
|
||||
int trendsDownCount = 0;
|
||||
for (int i = bar_index + 1; i < bar_index + length + 1; i++)
|
||||
{
|
||||
//
|
||||
double iPrevTrend = XTFGetTrendPower(i + 1);
|
||||
double iTrend = XTFGetTrendPower(i);
|
||||
|
||||
//
|
||||
if (
|
||||
trend1 > iTrend &&
|
||||
iTrend >= iPrevTrend &&
|
||||
trend1 >= iPrevTrend)
|
||||
{
|
||||
trendsUpCount++;
|
||||
}
|
||||
else if (
|
||||
trend1 < iTrend &&
|
||||
iTrend <= iPrevTrend &&
|
||||
trend1 <= iPrevTrend)
|
||||
{
|
||||
trendsDownCount++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
trendsDownCount > trendsUpCount
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check all Buffers has valid Size ...
|
||||
bool XTFIsValidBuffersSize(
|
||||
int size // the size of buffers which min size for requirements
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
size <= 0 ||
|
||||
//
|
||||
ArraySize(xTFFastBuffer) < size ||
|
||||
ArraySize(xTFSlowBuffer) < size
|
||||
//
|
||||
)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END XTF Custom Functions ...
|
||||
//
|
||||
Reference in New Issue
Block a user