250 lines
4.3 KiB
Plaintext
250 lines
4.3 KiB
Plaintext
/////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 XOBD Indicator 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 ...
|
|
//
|
|
|
|
//
|
|
// END Enum Definitions ...
|
|
//
|
|
|
|
//
|
|
// START Inputs ...
|
|
//
|
|
|
|
// input group "XOBD Indicator";
|
|
|
|
// input int xOBDLength = 5; // Swing Length
|
|
// input uchar xOBDSwingHighArrowCode = 108; // Swing High Arrow Code
|
|
// input color xOBDSwingHighArrowColor = clrMagenta; // Swing High Arrow Color
|
|
// input uchar xOBDSwingLowArrowCode = 108; // Swing Low Arrow Code
|
|
// input color xOBDSwingLowArrowColor = clrAqua; // Swing Low Arrow Color
|
|
|
|
//
|
|
// Configurations ...
|
|
int xOBDLength = 5; // Swing Length
|
|
uchar xOBDSwingHighArrowCode = 108; // Swing High Arrow Code
|
|
color xOBDSwingHighArrowColor = clrMagenta; // Swing High Arrow Color
|
|
uchar xOBDSwingLowArrowCode = 108; // Swing Low Arrow Code
|
|
color xOBDSwingLowArrowColor = clrAqua; // Swing Low Arrow Color
|
|
|
|
//
|
|
// END Inputs ...
|
|
//
|
|
|
|
//
|
|
// START Definitions ...
|
|
//
|
|
|
|
//
|
|
int xOBDHandler = INVALID_HANDLE;
|
|
|
|
//
|
|
double xOBDBuffer[];
|
|
|
|
//
|
|
// END Definitions ...
|
|
//
|
|
|
|
//
|
|
// START Handler Functions ...
|
|
//
|
|
|
|
//
|
|
// Validate Inputs ...
|
|
bool XOBDValidateInputs()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = xOBDLength >= 2;
|
|
|
|
//
|
|
if (!result)
|
|
{
|
|
//
|
|
LogMessage("XOBD Indicator Inputs Validation Failed ...");
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Init Indicators ...
|
|
bool XOBDInitHandlers()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Initialize Indicator/Oscillator Handlers ...
|
|
ResetLastError();
|
|
|
|
//
|
|
// XOBD Handler ...
|
|
ArraySetAsSeries(xOBDBuffer, true);
|
|
|
|
//
|
|
xOBDHandler = iCustom(
|
|
_Symbol,
|
|
_Period,
|
|
"x-saherelm.xobd.indicator",
|
|
//
|
|
// Inputs ...
|
|
xOBDLength,
|
|
xOBDSwingHighArrowCode,
|
|
xOBDSwingHighArrowColor,
|
|
xOBDSwingLowArrowCode,
|
|
xOBDSwingLowArrowColor
|
|
//
|
|
);
|
|
if (xOBDHandler == INVALID_HANDLE)
|
|
{
|
|
//
|
|
LogMessage("failed to Initialize XOBD Indicator: " + (string)GetLastError());
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = true;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Release Indicators ...
|
|
void XOBDReleaseHandlers()
|
|
{
|
|
IndicatorRelease(xOBDHandler);
|
|
}
|
|
|
|
//
|
|
// Handle Reading Buffers ...
|
|
void XOBDReadBuffers(
|
|
int xOBDItemsPerTick // Number Of Reading Buffer Items Per Tick
|
|
)
|
|
{
|
|
//
|
|
// OBD Buffer ...
|
|
CopyBuffer(
|
|
xOBDHandler,
|
|
0,
|
|
0,
|
|
xOBDItemsPerTick,
|
|
xOBDBuffer
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// END Handler Funcions ...
|
|
//
|
|
|
|
//
|
|
// START XOBD Custom Functions ...
|
|
//
|
|
|
|
//
|
|
// Check is Swing Low Occured or not ...
|
|
bool XOBDIsSwingLow(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XOBDIsValidBuffersSize(bar_index + 2))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = xOBDBuffer[bar_index] == X_SWING_LOW;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check is Swing High Occured or not ...
|
|
bool XOBDIsSwingHigh(
|
|
int bar_index // Specified Index ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
bar_index <= 0 ||
|
|
!XOBDIsValidBuffersSize(bar_index + 2))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = xOBDBuffer[bar_index] == X_SWING_HIGH;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check all Buffers has valid Size ...
|
|
bool XOBDIsValidBuffersSize(
|
|
int size // the size of buffers which min size for requirements
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (
|
|
size <= 0 ||
|
|
//
|
|
ArraySize(xOBDBuffer) < size
|
|
//
|
|
)
|
|
{
|
|
result = false;
|
|
}
|
|
else
|
|
{
|
|
result = true;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// END XOBD Custom Functions ...
|
|
//
|