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,192 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Expert Advisor
// ----------------------------------------
// Name: XEA
// Description: this is an expert controller
// advisors which provides a mechanism for use them ...
//
//
// 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 XEA"
#property strict
//
// START Inputs ...
//
input group "Commons";
//
// END Inputs ...
//
//
// START Including Providers ...
//
//
// Logger Library ...
#include "..\Libraries\x-saherelm.log.lib.mq5";
//
// Common Library ...
#include "..\Libraries\x-saherelm.common.lib.mq5";
//
// Alert Library ...
#include "..\Libraries\x-saherelm.alert.lib.mq5";
//
// Draw Library ...
#include "..\Libraries\x-saherelm.draw.lib.mq5";
//
// XTEST Signal Provider ...
#include "..\Libraries\x-saherelm.xtf.provider.lib.mq5";
//
// END Including Providers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
logTag = "XEA";
drawPrefix = logTag;
alertPrefix = logTag;
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Initialize XF Provider ...
if (!XTFInitSignalProviderLibrary())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Apply default Chart Style for EA ...
ApplyChartStyle();
//
// 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 ...
//
// De Initialize XTF Provider ...
XTFDeinitSignalProviderLibrary(reason);
//
// De Init XDraw Library ...
// OnDeinitDrawLibrary();
}
//
// On Tick Handler ...
void OnTick()
{
//
// Prevent Going Forward if user Disable it ...
if (!xTFEnableProvider) {
return;
}
//
if (!IsNewCandle())
{
return;
}
//
// Handle Processing on XTEST Signal Provider ...
XTFSignalProviderHandleTick();
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
// Validate Args ...
//
// Validate XTF Provider Inputs ...
result = XTFValidateInputs();
if (!result)
{
return false;
}
//
// Logging State ...
string message = "Validation of (" + "XEA" + ") Inputs " + (result ? "Succeeded" : "Failed") + " ...";
LogMessage(message);
//
return result;
}
//
// END Functions ...
//
@@ -0,0 +1,346 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XLH Indicator
// ---------------------------------------------
// Name: XLH
// Description: Moving Average Indicator
// Market Analysor ...
//
//
// 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 XLH Indicator"
#property strict
//
// START Constants ...
//
#define ShortName "XLH"
//
// END Constants ...
//
//
// START Inputs ...
//
input int length = 14; // Length
input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method
input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method
//
// END Inputs ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.log.lib.mq5";
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5";
//
// START Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 3
#property indicator_plots 3
//
// HH Buffer ...
#define hhBufferIndex 0
//
double hhBuffer[];
//
#property indicator_label1 "XLH HH"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrAqua
#property indicator_style1 STYLE_DOT
#property indicator_width1 1
//
// LL Buffer ...
#define llBufferIndex 1
//
double llBuffer[];
//
#property indicator_label2 "XLH LL"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrFuchsia
#property indicator_style2 STYLE_DOT
#property indicator_width2 1
//
// Signal Buffer ...
#define signalBufferIndex 2
//
double signalBuffer[];
//
#property indicator_label3 "XLH S"
#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 > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// Main Loop ...
for (int i = limit - 1; 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()
{
//
// HH Buffer ...
string hhBufferLabel = ShortName + " HH " + "(" + (string)length + ")";
ArraySetAsSeries(hhBuffer, true);
SetIndexBuffer(hhBufferIndex, hhBuffer, INDICATOR_DATA);
PlotIndexSetInteger(hhBufferIndex, PLOT_DRAW_BEGIN, length);
PlotIndexSetString(hhBufferIndex, PLOT_LABEL, hhBufferLabel);
//
// LL Buffer ...
string llBufferLabel = ShortName + " LL " + "(" + (string)length + ")";
ArraySetAsSeries(llBuffer, true);
SetIndexBuffer(llBufferIndex, llBuffer, INDICATOR_DATA);
PlotIndexSetInteger(llBufferIndex, PLOT_DRAW_BEGIN, length);
PlotIndexSetString(llBufferIndex, PLOT_LABEL, llBufferLabel);
//
// Signal Buffer ...
string signalBufferLabel = ShortName + " S " + "(" + (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, "");
//
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index // Selected Bar Index
)
{
//
// Calculate Threshold ...
//
// HH Buffer ...
int hhIndex = iHighest(
_Symbol,
_Period,
hhMode,
length,
bar_index);
double hhValue = GetAppliedPrice(
hhIndex,
hhMode);
//
hhBuffer[bar_index] = hhValue;
//
// LL Buffer ...
int llIndex = iLowest(
_Symbol,
_Period,
llMode,
length,
bar_index);
double llValue = GetAppliedPrice(
llIndex,
llMode);
//
llBuffer[bar_index] = llValue;
//
XOHCL c = GetCandle(bar_index);
double lhDiff = hhValue - llValue;
double signalValue = (lhDiff / 2);
//
signalBuffer[bar_index] = (hhValue - signalValue);
}
//
// END Functions ...
//
@@ -0,0 +1,389 @@
/////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 OrderBlock Detector Indicator
// -----------------------------------------------------
// 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 Indicator"
#property strict
//
// START Constants ...
//
#define ShortName "XOBD"
//
// END Constants ...
//
//
// START Inputs ...
//
//
input int length = 5; // Swing Length
//
input uchar swingHighArrowCode = 108; // Swing High Arrow Code
input color swingHighArrowColor = clrMagenta; // Swing High Arrow Color
//
input uchar swingLowArrowCode = 108; // Swing Low Arrow Code
input color swingLowArrowColor = clrAqua; // Swing Low Arrow Color
//
// END Inputs ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.log.lib.mq5";
//
// Include Common and Models Library ...
#include "../Libraries/x-saherelm.common.lib.mq5";
//
// Include Draw Library ...
#include "../Libraries/x-saherelm.draw.lib.mq5";
//
// START Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 1
#property indicator_plots 0
//
#define swingBufferIndex 0
double swingBuffer[];
//
// 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;
drawPrefix = 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 ...
OnDeinitDrawLibrary();
}
//
// 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 * 3);
//
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()
{
//
ArraySetAsSeries(swingBuffer, true);
SetIndexBuffer(swingBufferIndex, swingBuffer, INDICATOR_CALCULATIONS);
}
//
// 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)
{
//
// GetCandleSwing(bar_index);
ENUM_X_SWING_TYPE type = X_NO_SWING;
//
// Try To Detect Order Blocks ...
bool isSwingLow = false;
bool isSwingHigh = false;
//
// Reading Candles Data ...
XOHCL candles[];
for (int i = bar_index; i < bar_index + ((length * 2) + 2); i++)
{
//
XOHCL iCandle = GetCandle(
_Symbol,
_Period,
i);
//
Add(
iCandle,
candles);
}
//
// Swing Low ...
isSwingLow =
//
candles[1].close > candles[2].close &&
candles[2].close > candles[3].close &&
//
candles[3].close < candles[4].close &&
//
candles[5].close > candles[4].close &&
candles[6].close > candles[5].close
//
;
//
if (isSwingLow)
{
type = X_SWING_LOW;
}
//
if (!isSwingLow)
{
//
// Swing High ...
isSwingHigh =
//
candles[1].close < candles[2].close &&
candles[2].close < candles[3].close &&
//
candles[3].close > candles[4].close &&
//
candles[5].close < candles[4].close &&
candles[6].close < candles[5].close
//
;
//
if (isSwingHigh)
{
type = X_SWING_HIGH;
}
}
switch (type)
{
//
// Swing High ...
case X_SWING_HIGH:
//
swingBuffer[bar_index] = type;
DrawSwingArrow(1, bar_index);
break;
//
// Swinmg Low ...
case X_SWING_LOW:
//
swingBuffer[bar_index] = type;
DrawSwingArrow(0, bar_index);
break;
//
// No Swing ...
default:
case X_NO_SWING:
//
swingBuffer[bar_index] = 0;
break;
}
}
//
// Draw a Swing Arrow Shape ...
void DrawSwingArrow(
int type, // Swing Type: 0 - Low / 1 - High ...
int bar_index)
{
//
bool isSwingHigh = type == 1;
XOHCL candle = GetCandle(bar_index + 3);
double arrowDistanceInPoint = 0;
//
// Define Required Object Properties fro Draw an Arrow ...
datetime time = iTime(_Symbol, _Period, bar_index + 3);
double purePrice = isSwingHigh ? candle.high : candle.low;
color clr = isSwingHigh ? swingHighArrowColor : swingLowArrowColor;
ENUM_ARROW_ANCHOR anchor = isSwingHigh ? ANCHOR_BOTTOM : ANCHOR_TOP;
uchar arrowCode = uchar(isSwingHigh ? swingHighArrowCode : swingLowArrowCode);
double price = isSwingHigh ? purePrice + arrowDistanceInPoint : purePrice - arrowDistanceInPoint;
string name = "Swing " + (isSwingHigh ? "High" : "Low") + "_" + (string)time + "_" + (string)purePrice;
//
// Draw desired Arrow ...
DrawArrow(
0,
name,
0,
time,
price,
arrowCode,
anchor,
clr);
}
//
// END Functions ...
//
@@ -0,0 +1,395 @@
///////////////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Cycle Trend Finder Oscillator
// ----------------------------------------------------------------
// Name: XTF
// Description: trend detecting based on Periods ...
//
//
// 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 XTF Oscillator"
#property strict
//
// START Constants ...
//
#define ShortName "XTF"
//
// END Constants ...
//
//
// START Inputs ...
//
input ENUM_TIMEFRAMES period = PERIOD_H4; // Time Frame to work
input ENUM_MA_METHOD method = MODE_EMA; // Mode
input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To
input int fastLength = 9; // Fast Length
input int slowLength = 18; // Slow Length
//
// END Inputs ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.log.lib.mq5";
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5";
//
// START Buffers ...
//
#property indicator_separate_window
//
#property indicator_buffers 2
#property indicator_plots 2
//
// MA ...
#define fastBufferIndex 0
#define slowBufferIndex 1
//
double fastBuffer[];
double slowBuffer[];
//
#property indicator_label1 "XF"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrLime
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
#property indicator_label2 "XS"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrRed
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
// MA ...
int fastHandler = INVALID_HANDLE;
int slowHandler = INVALID_HANDLE;
//
// 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 All Required Handlers ...
if (!InitHandlers())
{
return INIT_FAILED;
}
//
// 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 ...
//
// ReDraw Chart ...
ChartRedraw();
//
Comment("");
}
//
// 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(fastLength, slowLength);
//
// Get Retrieved Values from indicators ...
//
// Ma ...
int fastCalculatedBars = BarsCalculated(fastHandler);
int slowCalculatedBars = BarsCalculated(slowHandler);
//
// Check Calculated Bars ...
if (
//
// MA ...
fastCalculatedBars < maxLength ||
slowCalculatedBars < maxLength
//
)
{
return prev_calculated;
}
//
limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated;
//
// Copy Buffers from indicators ...
//
// MA ...
int fastCopiedItems = CopyBuffer(fastHandler, 0, 0, limit + 1, fastBuffer);
int slowCopiedItems = CopyBuffer(slowHandler, 0, 0, limit + 1, slowBuffer);
//
// Check Copied Items Number ...
if (
//
// MA ...
fastCopiedItems <= 0 ||
slowCopiedItems <= 0
//
)
{
return 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 ...
bool isInputsValid = fastLength >= 4 && slowLength > fastLength;
if (isInputsValid)
{
result = true;
}
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// Fast Buffer ...
string fastBufferLabel = ShortName + " XF (" + (string)fastLength + ")";
ArraySetAsSeries(fastBuffer, true);
SetIndexBuffer(fastBufferIndex, fastBuffer, INDICATOR_DATA);
PlotIndexSetString(fastBufferIndex, PLOT_LABEL, fastBufferLabel);
PlotIndexSetInteger(fastBufferIndex, PLOT_DRAW_BEGIN, fastLength);
//
// Slow Buffer ...
string slowBufferLabel = ShortName + " XS (" + (string)slowLength + ")";
ArraySetAsSeries(slowBuffer, true);
SetIndexBuffer(slowBufferIndex, slowBuffer, INDICATOR_DATA);
PlotIndexSetString(slowBufferIndex, PLOT_LABEL, slowBufferLabel);
PlotIndexSetInteger(slowBufferIndex, PLOT_DRAW_BEGIN, slowLength);
}
//
// Init Handlers ...
bool InitHandlers()
{
//
bool result = false;
//
ResetLastError();
//
// Fast Handler ...
fastHandler = iMA(
_Symbol,
period,
fastLength,
0,
method,
appliedTo);
if (fastHandler == INVALID_HANDLE)
{
//
LogMessage("Fast Indicator initialization failed: " + (string)GetLastError());
//
result = false;
return result;
}
//
// Slow Handler ...
slowHandler = iMA(
_Symbol,
period,
slowLength,
0,
method,
appliedTo);
if (slowHandler == INVALID_HANDLE)
{
//
LogMessage("Slow Indicator initialization failed: " + (string)GetLastError());
//
result = false;
return result;
}
//
result = true;
//
return result;
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
string indicatorShortName = "";
StringConcatenate(indicatorShortName, ShortName, " ", EnumToString(period));
//
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index // Current Candle Index ...
)
{
}
//
// END Functions ...
//
@@ -0,0 +1,349 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Candle Indicator
// ---------------------------------------------
// Name: XTM
// Description: Trend Magic Indicator ...
//
//
// 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 XTM Indicator"
#property strict
//
// START Constants ...
//
#define ShortName "XTM"
//
// XTM Indicator States ...
enum ENUM_X_XTM_STATES
{
X_XTM_BULLISH = 1,
X_XTM_BEARISH = -1,
X_XTM_NEUTURAL = 0,
};
//
// END Constants ...
//
//
// START Inputs ...
//
input int maPeriod = 14; // Period
input int maShift = 0; // Shift
input ENUM_MA_METHOD maMethod = MODE_SMA; // Method
input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // Applied To
//
// END Inputs ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.log.lib.mq5";
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5";
//
// START Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 3
#property indicator_plots 1
//
// maBuffer ...
#define maBufferIndex 0
#define maColorBufferIndex 1
#define stateBufferIndex 2
double maBuffer[];
double maColorBuffer[];
double stateBuffer[];
#property indicator_label1 "XTM"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 clrLime, clrGray, clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
int maHandler = INVALID_HANDLE;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
logTag = ShortName;
//
// Initializing MA Handler ...
maHandler = iMA(
_Symbol,
_Period,
maPeriod,
maShift,
maMethod,
maAppliedTo);
if (maHandler == INVALID_HANDLE)
{
//
string message = "Error Initializing Ma Handler ...";
LogMessage(message);
//
return INIT_FAILED;
}
//
// 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, maPeriod);
//
// Check Calculated Bars ...
int maCalculatedBars = BarsCalculated(maHandler);
if (maCalculatedBars < maxLength)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
int copiedMas = CopyBuffer(maHandler, 0, 0, limit, maBuffer);
if (copiedMas <= 0)
{
return prev_calculated;
}
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
//
// Do Buffers Calculation ...
CalculateBuffers(i);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
// Validate Args ...
if (maPeriod >= 2)
{
result = true;
}
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
string maBufferLabel = "XTM " + "(" + (string)maPeriod + ")";
//
// Ma Buffer ...
ArraySetAsSeries(maBuffer, true);
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA);
PlotIndexSetString(maBufferIndex, PLOT_LABEL, maBufferLabel);
//
// Ma Color Buffer ...
ArraySetAsSeries(maColorBuffer, true);
SetIndexBuffer(maColorBufferIndex, maColorBuffer, INDICATOR_COLOR_INDEX);
//
// State Buffer ...
ArraySetAsSeries(stateBuffer, true);
SetIndexBuffer(stateBufferIndex, stateBuffer, INDICATOR_CALCULATIONS);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
string indicatorShortName = "";
StringConcatenate(indicatorShortName, ShortName, " ", "(", maPeriod, ")");
//
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(int bar_index)
{
//
// Requirements ...
XOHCL candle = GetCandle(bar_index);
//
double maValue = maBuffer[bar_index];
//
double lineColorIndex =
maValue < candle.low ? 0 : maValue > candle.high ? 2
: 1;
//
// Define State Value ...
// lineColorIndex == 0 => Bullish => 1;
// lineColorIndex == 1 => Neutural => 0;
// lineColorIndex == 2 => Bearish => -1;
double stateValue =
lineColorIndex == 0 ? X_XTM_BULLISH : lineColorIndex == 2 ? X_XTM_BEARISH
: X_XTM_NEUTURAL;
//
// Set Ma Buffer Color Index ...
maColorBuffer[bar_index] = lineColorIndex;
//
// Set State Buffer Value ...
stateBuffer[bar_index] = stateValue;
}
//
// END Functions ...
//
@@ -0,0 +1,197 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Alert Library
// --------------------------------------
// Name: XAlert
// Description: provides Alerts abilities ...
//
//
// 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
//
// START Inputs ...
//
input group "Alerts";
input bool enableAlerts = true; // Enable Alerts
input bool logAlerts = true; // Log Alerts
input bool terminalAlerts = true; // Terminal Alerts
input bool mailAlerts = true; // Mail Alerts
input bool pushAlerts = true; // Push Alerts
//
// END Inputs ...
//
//
#include "x-saherelm.log.lib.mq5";
//
// START Global Definitions: Variables, Properties and etc ...
//
string alertPrefix = "X-Alert";
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Provided Functions ...
//
//
// Initial Library if required ...
bool OnInInitAlertLibrary()
{
return false;
}
//
// DeInitial Library if required ...
void OnDeinitAlertLibrary()
{
}
//
// Attach Alert Prefix to Message ...
string PrepareAlertMessage(string message)
{
//
StringConcatenate(message, alertPrefix, " > ", message);
//
return message;
}
//
// Logging an Alert ...
void LogAlert(string message)
{
//
// Validate Args ...
if (!enableAlerts || !logAlerts)
{
return;
}
//
LogMessage(alertPrefix, message);
}
//
// Terminal Alert ...
void TerminalAlert(string message)
{
//
// Validate Args ...
if (!enableAlerts || !terminalAlerts)
{
return;
}
//
// Prepare Message ...
message = PrepareAlertMessage(message);
// Send Terminal Alert ...
Alert(message);
}
//
// Mail Alert ...
void MailAlert(string message)
{
//
// Validate Args ...
if (!enableAlerts || !mailAlerts)
{
return;
}
//
// Send Mail Alert ...
SendMail(alertPrefix, message);
}
//
// Send Push Notification ...
void PushAlert(string message)
{
//
// Validate Args ...
if (!enableAlerts || !pushAlerts)
{
return;
}
//
// Prepare Message ...
message = PrepareAlertMessage(message);
//
// Send Push Notification Alert ...
SendNotification(message);
}
//
// Alert Sending ...
void SendAlert(string message)
{
//
// Validate Args ...
if (!enableAlerts)
{
return;
}
//
// Log ...
if (logAlerts)
{
LogAlert(message);
}
//
// Terminal ...
if (terminalAlerts)
{
TerminalAlert(message);
}
//
// Mail ...
if (mailAlerts)
{
MailAlert(message);
}
//
// Push ...
if (pushAlerts)
{
PushAlert(message);
}
}
void SendAlert(
XSignal &signal, // the Signal Object which requred to Alert
bool asExecuted = true // determines Alert Signal as Executed Signal or not
)
{
//
// Prepare Message ...
string message = asExecuted ? ExecutedSignalToString(signal) : SignalToString(signal);
//
// Do Alerting ...
SendAlert(message);
}
//
// END Provided Functions ...
//
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,177 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Http Library
// ------------------------------------------
// Name: XHttp
// Description: provide http communication
// abilities ...
//
//
// 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
//
// START Model Definition ...
//
enum X_HTTP_METHOD
{
X_HTTP_GET,
X_HTTP_POST
};
//
// END Model Definition ...
//
//
// START Inputs ...
//
//
// END Inputs ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Provided Functions ...
//
//
// Initial Library if required ...
bool OnInInitHttpLibrary()
{
return false;
}
//
// DeInitial Library if required ...
void OnDeinitHttpLibrary()
{
}
//
// Convert enum to String ...
string ToString(X_HTTP_METHOD method)
{
//
string result = "";
//
switch (method)
{
//
case X_HTTP_GET:
result = "GET";
break;
//
case X_HTTP_POST:
result = "POST";
break;
}
//
return result;
}
//
// Send Global Request ...
int SendRequest(
X_HTTP_METHOD method, // Httm Request Method
const string url, // Server Address
const string headers, // Headers providing
const char &payload[], // the Data which needs to Send
char &response[], // Response of request
string responseHeaders, // Response Headers
int timeout = 500 // Timeout for response default is 500
)
{
//
int result = -1;
//
string strMethod = ToString(method);
if (StringLen(strMethod) == 0) {
return result;
}
//
result = WebRequest(
strMethod,
url,
headers,
timeout,
payload,
response,
responseHeaders
);
//
return result;
}
//
// Get Request ...
int GetRequest(
const string url, // Server Address
const string headers, // Headers providing
const char &payload[], // the Data which needs to Send
char &response[], // Response of request
string responseHeaders, // Response Headers
int timeout = 500 // Timeout for response default is 500
) {
//
int result = SendRequest(
X_HTTP_GET,
url,
headers,
payload,
response,
responseHeaders,
timeout
);
//
return result;
}
//
// Post Request ...
int PostRequest(
const string url, // Server Address
const string headers, // Headers providing
const char &payload[], // the Data which needs to Send
char &response[], // Response of request
string responseHeaders, // Response Headers
int timeout = 500 // Timeout for response default is 500
) {
//
int result = SendRequest(
X_HTTP_POST,
url,
headers,
payload,
response,
responseHeaders,
timeout
);
//
return result;
}
//
// END Provided Functions ...
//
@@ -0,0 +1,161 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Logger Library
// ---------------------------------------
// Name: XLogger
// Description: provides Logging abilities ...
//
//
// 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
//
// START Inputs ...
//
input group "Logging";
input bool enableLogging = true; // Enable Logging
//
// END Inputs ...
//
//
// Including Models ...
#include "x-saherelm.models.lib.mq5"
//
// START Global Definitions: Variables, Properties and etc ...
//
string logTag = "X-Logger"; // LogTag
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Provided Functions ...
//
//
// Logging a Message ...
void LogMessage(string message)
{
//
if (!enableLogging)
{
return;
}
//
Print(logTag, " > ", message);
}
void LogMessage(string tag, string message)
{
//
if (!enableLogging)
{
return;
}
//
Print(tag, " > ", message);
}
//
// Logging an Array ...
void LogArray(int &array[])
{
//
if (!enableLogging)
{
return;
}
//
Print(logTag, ">");
ArrayPrint(array);
}
void LogArray(double &array[])
{
//
if (!enableLogging)
{
return;
}
//
Print(logTag, ">");
ArrayPrint(array);
}
void LogArray(string &array[])
{
//
if (!enableLogging)
{
return;
}
//
Print(logTag, ">");
ArrayPrint(array);
}
//
// Convert a Signal to String Message ...
string SignalToString(XSignal &signal)
{
//
string result = "";
//
result += (signal.type == X_SIGNAL_LONG ? "Buy" : "Sell") + " Signal provided on (" + signal.symbol + " _ " + EnumToString(_Period) + ") by this comment: " + signal.comment;
//
return result;
}
//
// Convert an Executed Signal to String Message ...
string ExecutedSignalToString(XSignal &signal)
{
//
string result = "";
//
result += (signal.type == X_SIGNAL_LONG ? "Buy" : "Sell") + " Signal Executed provided on (" + signal.symbol + " _ " + EnumToString(_Period) + ") by this comment: " + signal.comment;
//
return result;
}
//
// Logging Signal ...
void LogSignal(XSignal &signal)
{
//
string message = SignalToString(signal);
//
LogMessage(message);
}
//
// Log Signal Execution ...
void LogExecutedSignal(XSignal &signal)
{
//
string message = ExecutedSignalToString(signal);
//
LogMessage(message);
}
//
// END Provided Functions ...
//
@@ -0,0 +1,187 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Models Library
// ---------------------------------------
// Name: XModels
// Description: provides all required models ...
//
//
// 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
//
// START Inputs ...
//
//
// END Inputs ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Provided Functions ...
//
//
// START Model Definitions ...
//
//
// OHCL Candel Model ...
enum ENUM_X_PRICE
{
X_PRICE_HIGH,
X_PRICE_OPEN,
X_PRICE_CLOSE,
X_PRICE_LOW
};
//
// Describe an Specific Candle ...
struct XOHCL
{
double high;
double open;
double close;
double low;
};
//
// Swing Types Enum ...
enum ENUM_X_SWING_TYPE
{
X_NO_SWING = 0,
X_SWING_HIGH = 1,
X_SWING_LOW = -1,
};
//
// XTrader Execution Signal Result ...
enum ENUM_EXECUTION_SIGNAL_RESULT
{
//
X_INVALID_SIGNAL_ERROR,
X_XTRADER_NOT_ENOUGH_BALANCE_ERROR,
X_XTRADER_NOT_ENOUGH_MARIGIN_ERROR,
X_XTRADER_MAX_ALLOWED_TRADE_KIND_REACHED_ERROR,
X_XTRADER_MAX_ALLOWED_SUPPORT_KIND_REACHED_ERROR,
//
X_TRADER_SUPPORT_DISTANCE_NOT_HAPPENS_ERROR,
//
X_UNKNOWN_ERROR,
X_SUCCEED_EXECUTION
};
//
// Signal Types ...
enum ENUM_X_SIGNAL_TYPE
{
X_SIGNAL_LONG,
X_SIGNAL_SHORT,
X_SIGNAL_UNKNOWN,
};
//
// Represent a Signal issued for Trade or Support a Trade ...
enum ENUM_X_SIGNAL_KIND
{
X_KIND_TRADE,
X_KIND_SUPPORT
};
//
// Signal Structure ...
struct XSignal
{
//
// Identifier ...
ulong id;
//
// Which Symbol used for Signal ...
string symbol;
//
// Which Type of operations ...
ENUM_X_SIGNAL_TYPE type;
//
// Signal Kind ...
ENUM_X_SIGNAL_KIND kind;
//
// Parent Ticket ...
ulong parent;
//
// Magic Number ...
ulong magicNumber;
//
// Ticket ...
ulong ticket;
//
// Entry/Open Price ...
double entry;
//
// TP ...
double tp;
//
// SL ...
double sl;
//
// Make Risk Free Trade on this Value if provided ...
double riskFree;
//
// a Multiplier for determines how much trade volume exit on risk free time ...
double riskFreeRate;
//
// Trade Profit ...
double profit;
//
// Time of Operation ...
datetime time;
//
// Volume ...
double volume;
//
// Comment ...
string comment;
};
//
// TP/SL Struct ...
struct XTPSL
{
ENUM_X_SIGNAL_TYPE type;
double tp;
double sl;
double entry;
double r2r;
};
//
// END Provided Functions ...
//
@@ -0,0 +1,258 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 NN Class Library
// ----------------------------------------
// Name: XNNClass
// Description: provides all classes for implementing
// Neural Network ...
//
//
// 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
//
// START Global Definitions: Variables, Properties and etc ...
//
class XCNNBase
{
//
// Public Definitions ...
public:
//
// Constructor ...
void XCNNBase(
int nodes = 10, // Number of Input Nodes
double starterWeight = 0.5, // start weight for each input
double coEfficient = 0.1, // COEfficient Multiplier
double upperRange = 1, // Upper Normal Range Value
double lowerRange = -1, // Lower Normal Range Value
double learningRates = 0.1 // Back Propagation Learning Rate
) {
//
mNodes = nodes;
mUpperRange = upperRange;
mLowerRange = lowerRange;
mCoEfficient = coEfficient;
mLearningRates = learningRates;
mStarterWeight = starterWeight;
//
ReConstructWeights();
}
//
// Deconstructor ...
void ~XCNNBase() {}
//
// Protected Definitions ...
void NormalizeInputs(double &inputs[], double &result[])
{
//
ArrayFree(result);
ArrayResize(result, 1);
//
// Validate inputs ...
if (ArraySize(inputs) != mNodes)
{
return;
}
//
// Prepare Result ...
ArrayResize(result, mNodes);
//
// Calculating min and max range value ...
double minRangeValue = inputs[ArrayMinimum(inputs)];
double maxRangeValue = inputs[ArrayMaximum(inputs)];
//
// Loop through Inputs nd Normalize them ...
for (int i = 0; i < mNodes; i++)
{
//
double normalValue = (((inputs[i] - minRangeValue) * (mUpperRange - mLowerRange)) / (maxRangeValue - minRangeValue)) + mLowerRange;
result[i] = normalValue;
}
}
//
// Hyperbolic Tangent Activation Function ...
double TanHActivationFunction(double weightedInputs)
{
//
double result = (exp(weightedInputs) - exp(-weightedInputs)) / (exp(weightedInputs) + exp(-weightedInputs));
return result;
}
//
// Calculate Weighted Inputs ...
double CalculateWeightedInputs(
double &inputs[],
bool applyCOEfficient = true)
{
//
double result = 0;
//
// Validate Inputs ...
if (ArraySize(inputs) != mNodes)
{
//
result = -1;
return result;
}
//
for (int i = 0; i < mNodes; i++)
{
result += inputs[i] * mWeights[i];
}
//
// Multiply if required ...
if (applyCOEfficient)
{
result *= mCoEfficient;
}
//
return result;
}
//
// Calculate Hidden Layers ...
virtual double CalculateHiddenLayer(double &inputs[])
{
//
// this is Default Activation Function which used ...
// you can override this by writing your own ...
double totalWeightedInputs = CalculateWeightedInputs(inputs);
double result = TanHActivationFunction(totalWeightedInputs);
//
return result;
}
//
// Calculate Output Layers ...
double CalculateOutputLayer(double &inputs[])
{
//
double result = -1;
//
// Validate Inputs ...
if (ArraySize(inputs) != mNodes) {
return result;
}
//
double normalizedInputs[];
NormalizeInputs(inputs, normalizedInputs);
if (ArraySize(normalizedInputs) != mNodes) {
return result;
}
//
double hiddenLayerResult = CalculateHiddenLayer(normalizedInputs);
//
result = 1 * hiddenLayerResult;
//
return result;
}
//
// Basck Propaggation Learning ...
void BackPropagation(
double &inputs[],
double &outputs,
double targetOutput
) {
//
// Validate Inputs ...
if (ArraySize(inputs) != mNodes) {
return;
}
//
double normalizedInputs[];
NormalizeInputs(inputs, normalizedInputs);
if (ArraySize(normalizedInputs) != mNodes) {
return;
}
//
double error = targetOutput - outputs;
double derivative = 1 - MathPow(outputs, 2);
//
for (int i = 0; i < mNodes; i++) {
//
double gradient = error * derivative * inputs[i];
mWeights[i] = mLearningRates * gradient;
}
}
protected:
//
// Private Definitions ...
private:
//
// Number of Input Nodes ...
int mNodes;
//
// Specify Upper range of Normal Values ...
double mUpperRange;
//
// Specify Lower range of Normal Values ...
double mLowerRange;
//
// Starter Weight for each input node ...
double mStarterWeight;
//
// double Input Node Weights ...
double mWeights[];
//
// CoEfficient is a multiplyer for weighted inputs ...
double mCoEfficient;
//
// Back Propagation Learning Rates ...
double mLearningRates;
//
// ReConstruct Weights ...
void ReConstructWeights() {
//
ArrayFree(mWeights);
ArrayResize(mWeights, mNodes);
//
for (int i = 0; i< mNodes; i++) {
mWeights[i] = mStarterWeight;
}
}
}
//
// END Global Definitions: Variables, Properties and etc ...
//
@@ -0,0 +1,464 @@
/////////////////////////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XLH 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 ...
//
//
// XLH Indicator Buffer Lines ...
enum ENUM_X_XLH_BUFFER_LINES
{
X_XLH_HH_LINE = 0,
X_XLH_LL_LINE = 1,
X_XLH_SIGNAL_LINE = 2,
};
//
// END Enum Definitions ...
//
//
// START Inputs ...
//
input group "XLH Indicator";
input int xLHLength = 72; // Length
input ENUM_SERIESMODE xLHHHMode = MODE_HIGH; // Highest High Calculation Method
input ENUM_SERIESMODE xLHLLMode = MODE_LOW; // Lowest Low Calculation Method
//
// END Inputs ...
//
//
// START Definitions ...
//
//
int xLHHandler = INVALID_HANDLE;
//
double xLHHHBuffer[];
double xLHLLBuffer[];
double xLHSignalBuffer[];
//
// END Definitions ...
//
//
// START Handler Functions ...
//
//
// Init Indicators ...
bool XLHInitHandlers()
{
//
bool result = false;
//
// Initialize Indicator/Oscillator Handlers ...
ResetLastError();
//
// XLH Handler ...
ArraySetAsSeries(xLHHHBuffer, true);
ArraySetAsSeries(xLHLLBuffer, true);
ArraySetAsSeries(xLHSignalBuffer, true);
//
xLHHandler = iCustom(
_Symbol,
_Period,
"x-saherelm.xlh.indicator",
//
// Inputs ...
xLHLength,
xLHHHMode,
xLHLLMode
//
);
if (xLHHandler == INVALID_HANDLE)
{
//
LogMessage("failed to Initialize XLH Indicator: " + (string)GetLastError());
return result;
}
//
result = true;
//
return result;
}
//
// Release Indicators ...
void XLHReleaseHandlers()
{
IndicatorRelease(xLHHandler);
}
//
// Handle Reading Buffers ...
void XLHReadBuffers(
int xLHItemsPerTick // Number Of Reading Buffer Items Per Tick
)
{
//
// HH Buffer ...
CopyBuffer(
xLHHandler,
X_XLH_HH_LINE,
0,
xLHItemsPerTick,
xLHHHBuffer
//
);
//
// LL Buffer ...
CopyBuffer(
xLHHandler,
X_XLH_LL_LINE,
0,
xLHItemsPerTick,
xLHLLBuffer
//
);
//
// Signal Buffer ...
CopyBuffer(
xLHHandler,
X_XLH_SIGNAL_LINE,
0,
xLHItemsPerTick,
xLHSignalBuffer
//
);
}
//
// END Handler Funcions ...
//
//
// START Signal Related Conditions ...
//
//
// XLH Long Conditions ...
bool XLHHasLongConditions(
int xLHItemsPerTick // Number Of Reading Buffer Items Per Tick
)
{
//
bool result = false;
//
return result;
}
//
// XLH Short Conditions ...
bool XLHHasShortConditions(
int xLHItemsPerTick // Number Of Reading Buffer Items Per Tick
)
{
//
bool result = false;
//
return result;
}
//
// END Signal Related Conditions ...
//
//
// START XLH Custom Functions ...
//
//
// TODO: What we have to Implement ...
// - []
//
// Check Candle High is HH ...
bool XLHIsHighAttachedHH(
int bar_index // Specified Index ...
)
{
//
bool result = false;
//
if (
bar_index <= 0 ||
!XLHIsValidBuffersSize(bar_index + 1))
{
return result;
}
//
XOHCL candle = GetCandle(bar_index);
//
result =
//
candle.high == xLHHHBuffer[bar_index]
//
;
//
return result;
}
//
// Check Candle Low is LL ...
bool XLHIsLowAttachedLL(
int bar_index // Specified Index ...
)
{
//
bool result = false;
//
if (
bar_index <= 0 ||
!XLHIsValidBuffersSize(bar_index + 1))
{
return result;
}
//
XOHCL candle = GetCandle(bar_index);
//
result =
//
candle.low == xLHLLBuffer[bar_index]
//
;
//
return result;
}
//
// Check Price Jumping Up Signal ...
bool XLHIsPriceCrossedOverSignal(
int bar_index // Specified Index ...
)
{
//
bool result = false;
//
if (
bar_index <= 0 ||
!XLHIsValidBuffersSize(bar_index + 2))
{
return result;
}
//
XOHCL candle1 = GetCandle(bar_index);
XOHCL candle2 = GetCandle(bar_index + 1);
//
result =
//
candle1.low > xLHSignalBuffer[bar_index] &&
candle2.low < xLHSignalBuffer[bar_index + 1]
//
;
//
return result;
}
//
// Check Price Over Signal ...
bool XLHIsPriceOverSignal(
int bar_index // Specified Index ...
)
{
//
bool result = false;
//
if (
bar_index <= 0 ||
!XLHIsValidBuffersSize(bar_index + 1))
{
return result;
}
//
XOHCL candle1 = GetCandle(bar_index);
//
result =
//
candle1.low > xLHSignalBuffer[bar_index]
//
;
//
return result;
}
//
// Check Price Jumping Down Signal ...
bool XLHIsPriceCrossedUnderSignal(
int bar_index // Specified Index ...
)
{
//
bool result = false;
//
if (
bar_index <= 0 ||
!XLHIsValidBuffersSize(bar_index + 2))
{
return result;
}
//
XOHCL candle1 = GetCandle(bar_index);
XOHCL candle2 = GetCandle(bar_index + 1);
//
result =
//
candle1.high < xLHSignalBuffer[bar_index] &&
candle2.high > xLHSignalBuffer[bar_index + 1]
//
;
//
return result;
}
//
// Check Price Down Signal ...
bool XLHIsPriceUnderSignal(
int bar_index // Specified Index ...
)
{
//
bool result = false;
//
if (
bar_index <= 0 ||
!XLHIsValidBuffersSize(bar_index + 1))
{
return result;
}
//
XOHCL candle1 = GetCandle(bar_index);
//
result =
//
candle1.high < xLHSignalBuffer[bar_index]
//
;
//
return result;
}
//
// Check Price Ranging Signal ...
bool XLHIsPriceInSignalRange(
int bar_index // Specified Index ...
)
{
//
bool result = false;
//
if (
bar_index <= 0 ||
!XLHIsValidBuffersSize(bar_index + 1))
{
return result;
}
//
XOHCL candle1 = GetCandle(bar_index);
//
result =
//
candle1.high > xLHSignalBuffer[bar_index] &&
candle1.low < xLHSignalBuffer[bar_index]
//
;
//
return result;
}
//
// Check all Buffers has valid Size ...
bool XLHIsValidBuffersSize(
int size // the size of buffers which min size for requirements
)
{
//
bool result = false;
//
if (
size <= 0 ||
//
ArraySize(xLHHHBuffer) < size ||
ArraySize(xLHLLBuffer) < size ||
ArraySize(xLHSignalBuffer) < size
//
)
{
result = false;
}
else
{
result = true;
}
//
return result;
}
//
// END XLH Custom Functions ...
//
@@ -0,0 +1,205 @@
/////////////////////////////////////////////////////////////////////////////
//
// 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
//
// END Inputs ...
//
//
// START Definitions ...
//
//
int xOBDHandler = INVALID_HANDLE;
//
double xOBDBuffer[];
//
// END Definitions ...
//
//
// START Handler Functions ...
//
//
// 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 Signal Related Conditions ...
//
//
// XOBD Long Conditions ...
bool XOBDHasLongConditions(
int xOBDItemsPerTick // Number Of Reading Buffer Items Per Tick
)
{
//
bool result = false;
//
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(xOBDBuffer) < size
//
)
{
result = false;
}
else
{
result = true;
}
//
return result;
}
//
// END XOBD Custom Functions ...
//
@@ -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 ...
//
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,82 @@
///////////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XTF Signal Provider Library Inputs
// -----------------------------------------------------------
//
// 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
//
input group "XTF Provider";
//
input group "XTF Common";
input bool xTFEnableProvider = true; // Enable Provider
input bool xTFEnableAlerts = false; // Enable Events Alert
input int xTFNumberOfItemsPerTick = 110; // Number Of items Readed In Each Tick
//
input group "XTF Trader";
input int xTFMagicNumber = 16940567; // Trader MagicNumber
input int xTFSlippage = 10; // Trader Slippage
//
input group "XTF Trade Management";
input bool xTFAllowLongTrades = true; // Allow Long Trades
input bool xTFAllowShortTrades = true; // Allow Short Trades
//
input group "XTF Risk Management";
//
// Trade Count ...
input int xTFMaxAllowedTrades = 5; // Max Allowed Trades at Same Time
input int xTFMaxAllowedSupportTrades = 3; // Max Allowed Support Trades for Single Position
//
// Trades Age ...
// 1 Day = 288
// 14 Day = 4320
input int xTFMaxInDrawDownTradeAge = 0; // Max In DrawDown Trades Age
//
// Trade Volume ...
input double xTFStaticVolume = 0.02; // Static Volume
input double xTFVolumeMultiplier = 2; // Volume Multiplier
input double xTFMaxSupportedVolumePerTradeInLots = 3; // Max Supported Volume Per Trade in Lot
//
// Trade Profits ...
input double xTFMinRewardPerTradeInPips = 8; // Min Reward Per Trade In Pips
input double xTFRiskFreeTradesInPips = 3; // Make Trades Risk Free in Pips
input int xTFMinRewardPerSupportTradesInPips = 2; // Min Reward for Support Trade
input int xTFSupportTradesPriceDistanceInPips = 2; // Distance Price to Open Support Trade In Pips
//
// 1000000 Pips = 100$ in EURUSD ...
input double xTFMaxAllowedDrawDownPerTradesInPips = 0; // Max Allowed Drawdown Per Trade In Pips
input double xTFRiskFreeRate = 0.5; // Volume Multiplier for Risk Free
//
// Account ...
input double xTFFreeMarginFactorForOpenTrades = 0.8; // Minimum Free Marging for Open Trades
input double xTFBalanceFactorForOpenTrades = 0.5; // Minimum Balance for Open Trades
//
// Validate Inputs before Initialization ...
bool XTFValidateInputs()
{
//
bool result = false;
//
// TODO: Fix this ...
result = true;
//
return result;
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,634 @@
/////////////////////////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XTM 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 ...
//
//
// XTM Indicator States ...
enum ENUM_X_XTM_STATES
{
X_XTM_BULLISH = 1,
X_XTM_BEARISH = -1,
X_XTM_NEUTURAL = 0,
};
//
// XTM Indicator Buffer Lines ...
enum ENUM_X_XTM_BUFFER_LINES
{
X_XTM_MA_LINE = 0,
X_XTM_MC_COLOR_LINE = 1,
X_XTM_STATE_LINE = 2,
};
//
// END Enum Definitions ...
//
//
// START Inputs ...
//
input group "XTM Indicator";
input int xTMMaPeriod = 18; // Period
input int xTMMaShift = 0; // Shift
input ENUM_MA_METHOD xTMMaMethod = MODE_EMA; // Method
input ENUM_APPLIED_PRICE xTMMaAppliedTo = PRICE_OPEN; // Applied To
//
// END Inputs ...
//
//
// START Definitions ...
//
int xTMHandler = INVALID_HANDLE;
double xTMMaBuffer[];
double xTMStateBuffer[];
//
// END Definitions ...
//
//
// START Handler Functions ...
//
//
// Init Indicators ...
bool XTMInitHandlers()
{
//
bool result = false;
//
// Initialize Indicator/Oscillator Handlers ...
ResetLastError();
//
// XTM Handler ...
ArraySetAsSeries(xTMMaBuffer, true);
ArraySetAsSeries(xTMStateBuffer, true);
xTMHandler = iCustom(
_Symbol,
_Period,
"x-saherelm.xtm.indicator",
//
// Inputs ...
xTMMaPeriod,
xTMMaShift,
xTMMaMethod,
xTMMaAppliedTo);
if (xTMHandler == INVALID_HANDLE)
{
//
LogMessage("failed to Initialize XTM Indicator: " + (string)GetLastError());
return result;
}
//
result = true;
//
return result;
}
//
// Release Indicators ...
void XTMReleaseHandlers()
{
IndicatorRelease(xTMHandler);
}
//
// Handle Reading Buffers ...
void XTMReadBuffers(
int xTMItemsPerTick // Number Of Reading Buffer Items Per Tick
)
{
//
// Ma Buffer ...
CopyBuffer(
xTMHandler,
X_XTM_MA_LINE,
0,
xTMItemsPerTick,
xTMMaBuffer);
//
// State Buffer ...
CopyBuffer(
xTMHandler,
X_XTM_STATE_LINE,
0,
xTMItemsPerTick,
xTMStateBuffer);
}
//
// END Handler Funcions ...
//
//
// START Signal Related Conditions ...
//
//
// XTM Long Conditions ...
bool XTMHasLongConditions(
int xTMItemsPerTick // Number Of Reading Buffer Items Per Tick
)
{
//
bool result = false;
//
bool isVale = XTMIsVale();
//
result =
//
isVale
//
;
//
return result;
}
//
// XTM Short Conditions ...
bool XTMHasShortConditions(
int xTMItemsPerTick // Number Of Reading Buffer Items Per Tick
)
{
//
bool result = false;
//
bool isPeak = XTMIsPeak();
//
result =
//
isPeak
//
;
//
return result;
}
//
// END Signal Related Conditions ...
//
//
// START XTM Custom Functions ...
//
//
// Find Peak based On this Indicator ...
bool XTMIsPeak()
{
//
bool result = false;
//
// Must Decreasing ...
bool isIncreasing = IsIncreasing(
20,
5,
xTMMaBuffer);
//
// Must Increasing ...
bool isDecreasing = IsDecreasing(
5,
1,
xTMMaBuffer);
//
// Calculate Result ...
result =
//
isIncreasing
//
&&
//
isDecreasing
//
;
//
return result;
}
//
// Find Vale based On this Indicator ...
bool XTMIsVale()
{
//
bool result = false;
//
// Must Decreasing ...
bool isIncreasing = IsIncreasing(
5,
1,
xTMMaBuffer);
//
// Must Increasing ...
bool isDecreasing = IsDecreasing(
20,
5,
xTMMaBuffer);
//
// Calculate Result ...
result =
//
isIncreasing
//
&&
//
isDecreasing
//
;
//
return result;
}
//
// Check TM Crossed Up ...
bool XTMIsStartBullish(
int bar_index // Specified Index ...
)
{
//
bool result = false;
//
if (
bar_index <= 0 ||
!XTMIsValidBuffersSize(bar_index + 2))
{
return result;
}
//
result =
//
xTMStateBuffer[bar_index] == X_XTM_BULLISH &&
xTMStateBuffer[bar_index + 1] != X_XTM_BULLISH
//
;
//
return result;
}
//
// Check TM Crossed Up After Neutural State ...
bool XTMIsStartBullishAfterNeutural(
int bar_index // Specified Index ...
)
{
//
bool result = false;
//
if (
bar_index <= 0 ||
!XTMIsValidBuffersSize(bar_index + 2))
{
return result;
}
//
result =
//
xTMStateBuffer[bar_index] == X_XTM_BULLISH &&
xTMStateBuffer[bar_index + 1] == X_XTM_NEUTURAL
//
;
//
return result;
}
//
// Check TM In Up State ...
bool XTMIsBullish(
int bar_index // Specified Index ...
)
{
//
bool result = false;
//
if (
bar_index <= 0 ||
!XTMIsValidBuffersSize(bar_index + 1))
{
return result;
}
//
result =
//
xTMStateBuffer[bar_index] == X_XTM_BULLISH
//
;
//
return result;
}
//
// Check TM Ends Up State ...
bool XTMIsEndBullish(
int bar_index // Specified Index ...
)
{
//
bool result = false;
//
if (
bar_index <= 0 ||
!XTMIsValidBuffersSize(bar_index + 2))
{
return result;
}
//
result =
//
xTMStateBuffer[bar_index] != X_XTM_BULLISH &&
xTMStateBuffer[bar_index + 1] == X_XTM_BULLISH
//
;
//
return result;
}
//
// Check TM Ends Up State By Neutural ...
bool XTMIsEndBullishByNeutural(
int bar_index // Specified Index ...
)
{
//
bool result = false;
//
if (
bar_index <= 0 ||
!XTMIsValidBuffersSize(bar_index + 2))
{
return result;
}
//
result =
//
xTMStateBuffer[bar_index] == X_XTM_NEUTURAL &&
xTMStateBuffer[bar_index + 1] == X_XTM_BULLISH
//
;
//
return result;
}
//
// Check TM Crossed Down ...
bool XTMIsStartBearish(
int bar_index // Specified Index ...
)
{
//
bool result = false;
//
if (
bar_index <= 0 ||
!XTMIsValidBuffersSize(bar_index + 2))
{
return result;
}
//
result =
//
xTMStateBuffer[bar_index] == X_XTM_BEARISH &&
xTMStateBuffer[bar_index + 1] != X_XTM_BEARISH
//
;
//
return result;
}
//
// Check TM Crossed Down After Neutural State ...
bool XTMIsStartBearishAfterNeutural(
int bar_index // Specified Index ...
)
{
//
bool result = false;
//
if (
bar_index <= 0 ||
!XTMIsValidBuffersSize(bar_index + 2))
{
return result;
}
//
result =
//
xTMStateBuffer[bar_index] == X_XTM_BEARISH &&
xTMStateBuffer[bar_index + 1] == X_XTM_NEUTURAL
//
;
//
return result;
}
//
// Check TM In Down State ...
bool XTMIsBearish(
int bar_index // Specified Index ...
)
{
//
bool result = false;
//
if (
bar_index <= 0 ||
!XTMIsValidBuffersSize(bar_index + 1))
{
return result;
}
//
result =
//
xTMStateBuffer[bar_index] == X_XTM_BEARISH
//
;
//
return result;
}
//
// Check TM Ends Down State ...
bool XTMIsEndBearish(
int bar_index // Specified Index ...
)
{
//
bool result = false;
//
if (
bar_index <= 0 ||
!XTMIsValidBuffersSize(bar_index + 2))
{
return result;
}
//
result =
//
xTMStateBuffer[bar_index] != X_XTM_BEARISH &&
xTMStateBuffer[bar_index + 1] == X_XTM_BEARISH
//
;
//
return result;
}
//
// Check TM Ends Down State By Neutural ...
bool XTMIsEndBearishByNeutural(
int bar_index // Specified Index ...
)
{
//
bool result = false;
//
if (
bar_index <= 0 ||
!XTMIsValidBuffersSize(bar_index + 2))
{
return result;
}
//
result =
//
xTMStateBuffer[bar_index] == X_XTM_NEUTURAL &&
xTMStateBuffer[bar_index + 1] == X_XTM_BEARISH
//
;
//
return result;
}
//
// Check TM In Neutural State ...
bool XTMIsNeutural(
int bar_index // Specified Index ...
)
{
//
bool result = false;
//
if (
bar_index <= 0 ||
!XTMIsValidBuffersSize(bar_index + 1))
{
return result;
}
//
result =
//
xTMStateBuffer[bar_index] == X_XTM_NEUTURAL
//
;
//
return result;
}
//
// Check all Buffers has valid Size ...
bool XTMIsValidBuffersSize(
int size // the size of buffers which min size for requirements
)
{
//
bool result = false;
//
if (
size <= 0 ||
//
ArraySize(xTMMaBuffer) < size ||
ArraySize(xTMStateBuffer) < size
//
)
{
result = false;
}
else
{
result = true;
}
//
return result;
}
//
// END XTM Custom Functions ...
//