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,417 @@
/////////////////////////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XOBD 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 ...
//
//
// XOBD Oscillator Buffer Lines ...
enum ENUM_X_XOBD_BUFFER_LINES
{
X_XOBD_SWING_HIGH_LINE = 0,
X_XOBD_SWING_LOW_LINE = 1,
X_XOBD_SIGNAL_LINE = 2,
};
//
// END Enum Definitions ...
//
//
// START Inputs ...
//
input group "XOBD Oscillator";
input int xOBDLength = 72; // Market Length
//
// END Inputs ...
//
//
// START Definitions ...
//
int xOBDHandler = INVALID_HANDLE;
double xOBDSwingHighBuffer[];
double xOBDSwingLowBuffer[];
double xOBDSignalBuffer[];
//
// END Definitions ...
//
//
// START Handler Functions ...
//
//
// Init Oscillators ...
bool XOBDInitHandlers()
{
//
bool result = false;
//
// Initialize Indicator/Oscillator Handlers ...
ResetLastError();
//
// XOBD Handler ...
ArraySetAsSeries(xOBDSwingHighBuffer, true);
ArraySetAsSeries(xOBDSwingLowBuffer, true);
ArraySetAsSeries(xOBDSignalBuffer, true);
xOBDHandler = iCustom(
_Symbol,
_Period,
"x-saherelm.xobd.oscillator",
//
// Inputs ...
xOBDLength
//
);
if (xOBDHandler == INVALID_HANDLE)
{
//
LogMessage("failed to Initialize XOBD Oscillator: " + (string)GetLastError());
return result;
}
//
result = true;
//
return result;
}
//
// Release Oscillators ...
void XOBDReleaseHandlers()
{
IndicatorRelease(xOBDHandler);
}
//
// Handle Reading Buffers ...
void XOBDReadBuffers(
int xOBDItemsPerTick // Number Of Reading Buffer Items Per Tick
)
{
// XOBD Swing High ...
CopyBuffer(
xOBDHandler,
X_XOBD_SWING_HIGH_LINE,
0,
xOBDItemsPerTick,
xOBDSwingHighBuffer);
//
// XOBD Swing Low ...
CopyBuffer(
xOBDHandler,
X_XOBD_SWING_LOW_LINE,
0,
xOBDItemsPerTick,
xOBDSwingLowBuffer);
//
// XOBD Signal ...
CopyBuffer(
xOBDHandler,
X_XOBD_SIGNAL_LINE,
0,
xOBDItemsPerTick,
xOBDSignalBuffer);
}
//
// END Handler Funcions ...
//
//
// START Signal Related Conditions ...
//
//
// XOBD Long Conditions ...
bool XOBDHasLongConditions(
int xOBDItemsPerTick // Number Of Reading Buffer Items Per Tick
)
{
//
bool result = false;
//
bool isVale = XOBDIsVale();
bool isInPeak = IsInPeak(
xOBDItemsPerTick,
xOBDSignalBuffer);
//
result =
//
isVale
//
&&
//
!isInPeak
//
;
//
return result;
}
//
// XOBD Short Conditions ...
bool XOBDHasShortConditions(
int xOBDItemsPerTick // Number Of Reading Buffer Items Per Tick
)
{
//
bool result = false;
//
return result;
}
//
// END Signal Related Conditions ...
//
//
// START XOBD Custom Functions ...
//
//
// 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(xOBDSignalBuffer) < size ||
ArraySize(xOBDSwingLowBuffer) < size ||
ArraySize(xOBDSwingHighBuffer) < size
//
)
{
result = false;
}
else
{
result = true;
}
//
return result;
}
//
// Check SC is Peak ...
bool XOBDIsPeak()
{
//
bool result = false;
//
bool isIncreasing = IsIncreasing(
10,
3,
xOBDSignalBuffer);
//
bool isDecreasing = IsDecreasing(
3,
1,
xOBDSignalBuffer);
//
// Generating Result ...
result =
//
isIncreasing
//
&&
//
isDecreasing
//
;
//
return result;
}
//
// Check SC is Vale ...
bool XOBDIsVale()
{
//
bool result = false;
//
bool isIncreasing = IsIncreasing(
5,
1,
xOBDSignalBuffer);
//
bool isDecreasing = IsDecreasing(
20,
5,
xOBDSignalBuffer);
//
// Generating Result ...
result =
//
isIncreasing
//
&&
//
isDecreasing
//
;
//
return result;
}
//
// Check Signal Crossed Over Swing High ...
bool XOBDIsSignalCrossedOverSwingHigh(
int bar_index // Specified Index ...
)
{
//
bool result = false;
//
if (
bar_index <= 0 ||
!XOBDIsValidBuffersSize(bar_index + 2))
{
return result;
}
//
result = IsCrossOver(
xOBDSignalBuffer,
xOBDSwingHighBuffer,
bar_index);
//
return result;
}
//
// Check Signal Over Swing High ...
bool XOBDIsSignalOverSwingHigh(
int bar_index // Specified Index ...
)
{
//
bool result = false;
//
if (
bar_index <= 0 ||
!XOBDIsValidBuffersSize(bar_index + 2))
{
return result;
}
//
result = IsOver(
xOBDSignalBuffer,
xOBDSwingHighBuffer,
bar_index);
//
return result;
}
//
// Check Signal Crossed Under Swing High ...
bool XOBDIsSignalCrossedUnderSwingHigh(
int bar_index // Specified Index ...
)
{
//
bool result = false;
//
if (
bar_index <= 0 ||
!XOBDIsValidBuffersSize(bar_index + 2))
{
return result;
}
//
result = IsCrossUnder(
xOBDSignalBuffer,
xOBDSwingHighBuffer,
bar_index);
//
return result;
}
//
// Check Signal Under Swing High ...
bool XOBDIsSignalUnderSwingHigh(
int bar_index // Specified Index ...
)
{
//
bool result = false;
//
if (
bar_index <= 0 ||
!XOBDIsValidBuffersSize(bar_index + 2))
{
return result;
}
//
result = IsUnder(
xOBDSignalBuffer,
xOBDSwingHighBuffer,
bar_index);
//
return result;
}
//
// END XOBD Custom Functions ...
//
@@ -0,0 +1,328 @@
/////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 OrderBlock Detector Oscillator
// ------------------------------------------------------
// Name: XOBD
// Description: detect Order Blocks based on Swings ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm XOBD Oscillator"
#property strict
//
// START Constants ...
//
#define ShortName "XOBD"
//
// END Constants ...
//
//
// START Inputs ...
//
//
input int length = 288; // Market Length
//
// START Inputs ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.log.lib.mq5";
//
// Include Common and Models Library ...
#include "../Libraries/x-saherelm.common.lib.mq5";
//
// START Buffers ...
//
//
#property indicator_separate_window
//
#property indicator_buffers 3
#property indicator_plots 3
//
#define swingHighBufferIndex 0
#define swingLowBufferIndex 1
#define signalBufferIndex 2
//
double swingHighBuffer[];
double swingLowBuffer[];
double signalBuffer[];
//
#property indicator_label1 "XSwing High"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrAqua
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
#property indicator_label2 "XSwing Low"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrFuchsia
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//
#property indicator_label3 "XSignal"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrGold
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
logTag = ShortName;
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs changed by a user
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
// REASON_TEMPLATE 7 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
//
// Here we can handle De Initialization Reasons ...
}
//
// Calculations ...
//
// Calculating what we want ...
int OnCalculate(
//
// total Candles on chart ...
const int rates_total,
//
// total calculated Candles on charts ...
const int prev_calculated,
//
// history of Candles Open Time ...
const datetime &time[],
//
// history of Candles Open Price ...
const double &open[],
//
// history of Candles High Price ...
const double &high[],
//
// history of Candles Low Price ...
const double &low[],
//
// history of Candles Close Price ...
const double &close[],
//
// history of Tick Volumes on Candle ...
const long &tick_volume[],
//
// history of Trade Volumes ...
const long &volume[],
//
// history of Candles Spread Price ...
const int &spread[])
{
//
// Prepare Buffers ...
ArraySetAsSeries(time, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);
ArraySetAsSeries(volume, true);
ArraySetAsSeries(spread, true);
//
// this counts Available Bars ...
int limit;
//
// because in some cases we may have more than one input for
// calculation and we must prevent any calculation
// untill we pass the biggest input length, here we get max Input length
// and then wait until pass it ...
int maxLength = MathMax(0, length);
//
limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated;
//
// Main Loop ...
for (int i = limit; i >= 0 && !IsStopped(); i--)
{
//
CalculateBuffers(i);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
// Validate Args ...
if (length >= 2)
{
result = true;
}
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// Swing High ...
string swingHighBufferLabel = ShortName + " Swing H (" + (string) length + ")";
ArraySetAsSeries(swingHighBuffer, true);
SetIndexBuffer(swingHighBufferIndex, swingHighBuffer, INDICATOR_DATA);
PlotIndexSetInteger(swingHighBufferIndex, PLOT_DRAW_BEGIN, length);
PlotIndexSetString(swingHighBufferIndex, PLOT_LABEL, swingHighBufferLabel);
//
// Swing Low ...
string swingLowBufferLabel = ShortName + " Swing L (" + (string) length + ")";
ArraySetAsSeries(swingLowBuffer, true);
SetIndexBuffer(swingLowBufferIndex, swingLowBuffer, INDICATOR_DATA);
PlotIndexSetInteger(swingLowBufferIndex, PLOT_DRAW_BEGIN, length);
PlotIndexSetString(swingLowBufferIndex, PLOT_LABEL, swingLowBufferLabel);
//
// Signal ...
string signalBufferLabel = ShortName + " Signal (" + (string) length + ")";
ArraySetAsSeries(signalBuffer, true);
SetIndexBuffer(signalBufferIndex, signalBuffer, INDICATOR_DATA);
PlotIndexSetInteger(signalBufferIndex, PLOT_DRAW_BEGIN, length);
PlotIndexSetString(signalBufferIndex, PLOT_LABEL, signalBufferLabel);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
string indicatorShortName = "";
StringConcatenate(indicatorShortName, ShortName, " ", "( ", length, " )");
//
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(int bar_index)
{
//
int inCycleSwingHighCount = 0;
int inCycleSwingLowCount = 0;
//
// Loop Back Through Cycle ...
for (int i = bar_index; i < bar_index + length; i++) {
//
ENUM_X_SWING_TYPE iSwingType = GetCandleSwing(i);
if (iSwingType == X_NO_SWING) {
continue;
}
//
if (iSwingType == X_SWING_HIGH) {
inCycleSwingHighCount++;
} else if (iSwingType == X_SWING_LOW) {
inCycleSwingLowCount++;
}
}
//
swingHighBuffer[bar_index] = inCycleSwingHighCount;
swingLowBuffer[bar_index] = inCycleSwingLowCount;
//
signalBuffer[bar_index] = inCycleSwingLowCount - inCycleSwingHighCount;
}
//
// END Functions ...
//