Files
xMQL5/BKPS/Series2/XTMPack/x-saherelm.xmap.provider.xobd.indicator.helper.lib.mq5
T
2024-01-25 04:09:42 +03:30

288 lines
5.5 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
//
#include "..\Libraries\x-saherelm.log.lib.mq5"
#include "..\Libraries\x-saherelm.common.lib.mq5"
#include "x-saherelm.xmap.provider.inputs.lib.mq5"
//
// START Enum Definitions ...
//
//
// END Enum Definitions ...
//
//
// START Inputs ...
//
input group "XOBD Indicator";
input int xOBDLength = 14; // Market Length
input double xOBDArrowDistanceFromPrice = 0; // Arrow Distrance from Price
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
//
// END Inputs ...
//
//
// START Definitions ...
//
int xOBDHandler = INVALID_HANDLE;
double xOBDSwingsBuffer[];
//
// END Definitions ...
//
//
// START Handler Functions ...
//
//
// Init Indicators ...
bool XOBDInitHandlers()
{
//
bool result = false;
//
// Initialize Indicator/Oscillator Handlers ...
ResetLastError();
//
// XOBD Handler ...
ArraySetAsSeries(xOBDSwingsBuffer, true);
xOBDHandler = iCustom(
_Symbol,
_Period,
"x-saherelm.xobd.indicator",
//
// Inputs ...
xOBDLength,
xOBDArrowDistanceFromPrice,
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()
{
CopyBuffer(
xOBDHandler,
0,
0,
xMAPNumberOfItemsPerTick,
xOBDSwingsBuffer);
}
//
// END Handler Funcions ...
//
//
// START XOBD Custom Functions ...
//
//
// Find Peak based On this Indicator ...
bool XOBDIsPeak(
int loopback // loopback length
)
{
//
bool result = false;
//
return result;
}
//
// Find Vale based On this Indicator ...
bool XOBDIsVale(
int loopback // loopback length
)
{
//
bool result = false;
//
return result;
}
//
// Find Lesser Swing Low ...
double XOBDGetSmallestSwingLow(
double price, // a price which swings compare with it
int numberOfSwingsCheck = 4 // number of Swing Lows to Check
)
{
//
double result = price;
//
double swings[];
ArraySetAsSeries(swings, true);
XOBDRetrieveSwings(
numberOfSwingsCheck,
X_SWING_LOW,
swings);
//
for (int i = 0; i < ArraySize(swings); i++)
{
//
double swingVal = swings[i];
//
result = swingVal < result ? swingVal : result;
}
//
return result;
}
//
// Find Bigger Swing High ...
double XOBDGetBiggestSwingHigh(
double price, // a price which swings compare with it
int numberOfSwingsCheck = 4 // number of Swing Lows to Check
)
{
//
double result = price;
//
double swings[];
ArraySetAsSeries(swings, true);
XOBDRetrieveSwings(
numberOfSwingsCheck,
X_SWING_HIGH,
swings);
//
for (int i = 0; i < ArraySize(swings); i++)
{
//
double swingVal = swings[i];
//
result = swingVal > result ? swingVal : result;
}
//
return result;
}
//
// Reading Special Type of Swings from Buffer until specific count passed ...
void XOBDRetrieveSwings(
int count, // Number of Swings to Retrieve
ENUM_X_SWING_TYPE type, // Which Type of Swing to Retrieve
double &result[] // Holds result
)
{
//
static int xMAPSwingsBufferReadItems = 50;
//
// Clear Result ...
ArrayFree(result);
ArrayResize(result, 0);
//
// Validate Args ...
if (count <= 0 || type == X_NO_SWING)
{
return;
}
//
double swingsBuffer[];
ArraySetAsSeries(swingsBuffer, true);
//
// TODO:
// CopyBuffer(xOBDHandler, 0, 0, xMAPSwingsBufferReadItems, swingsBuffer);
int foundedSwings = ArraySize(swingsBuffer);
if (foundedSwings <= 0)
{
return;
}
//
// Loop through Swings ...
for (int i = 0; i < foundedSwings; i++)
{
//
double swingValue = swingsBuffer[i];
if (swingValue != type)
{
continue;
}
//
ArrayResize(
result,
ArraySize(result) + 1);
result[ArraySize(result) - 1] = swingValue;
}
//
// Check Result count ...
if (ArraySize(result) < count)
{
//
xMAPSwingsBufferReadItems *= 2;
XOBDRetrieveSwings(
count,
type,
result);
//
return;
}
//
xMAPSwingsBufferReadItems = 50;
}
//
// END XOBD Custom Functions ...
//