Initial Commit ...
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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.xtest.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 XTEST Provider ...
|
||||||
|
if (!XTESTInitSignalProviderLibrary())
|
||||||
|
{
|
||||||
|
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 XTEST Provider ...
|
||||||
|
XTESTDeinitSignalProviderLibrary(reason);
|
||||||
|
|
||||||
|
//
|
||||||
|
// De Init XDraw Library ...
|
||||||
|
// OnDeinitDrawLibrary();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// On Tick Handler ...
|
||||||
|
void OnTick()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Prevent Going Forward if user Disable it ...
|
||||||
|
if (!xTESTEnableProvider) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!IsNewCandle())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handle Processing on XTEST Signal Provider ...
|
||||||
|
XTESTSignalProviderHandleTick();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Event Handlers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Functions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Input Args for Initialization ...
|
||||||
|
bool ValidateInputs()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate XTEST Provider Inputs ...
|
||||||
|
result = XTESTValidateInputs();
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Logging State ...
|
||||||
|
string message = "Validation of (" + "XEA" + ") Inputs " + (result ? "Succeeded" : "Failed") + " ...";
|
||||||
|
LogMessage(message);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Functions ...
|
||||||
|
//
|
||||||
|
|
||||||
@@ -0,0 +1,838 @@
|
|||||||
|
//////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center MQL5 Cycle Channel LH Oscillator
|
||||||
|
// ---------------------------------------------------
|
||||||
|
// Name: XCHLH
|
||||||
|
// Description: detecting HH and LL based on cycles ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// 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 XCHLH Oscillator"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Constants ...
|
||||||
|
//
|
||||||
|
#define ShortName "XCHLH"
|
||||||
|
|
||||||
|
//
|
||||||
|
// XCHLH Hot States ...
|
||||||
|
enum ENUM_X_XCHLH_HOT_STATES
|
||||||
|
{
|
||||||
|
X_XCHLH_HOT_HH = 1,
|
||||||
|
X_XCHLH_NEUTURAL = 0,
|
||||||
|
X_XCHLH_HOT_LL = -1,
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// XCHLH Signal Calculation Types ...
|
||||||
|
enum ENUM_X_XCHLH_SIGNAL_TYPES
|
||||||
|
{
|
||||||
|
X_XCHLH_AVG_SIGNAL,
|
||||||
|
X_XCHLH_DELTA_SIGNAL,
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Including Models Library ...
|
||||||
|
#include "..\Libraries\x-saherelm.models.lib.mq5";
|
||||||
|
//
|
||||||
|
// END Constants ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal Calculations ...
|
||||||
|
input group "Signal Calculations";
|
||||||
|
input ENUM_X_XCHLH_SIGNAL_TYPES signalType = X_XCHLH_AVG_SIGNAL; // Signal Method
|
||||||
|
|
||||||
|
//
|
||||||
|
// Common ...
|
||||||
|
input group "Hot Areas";
|
||||||
|
input bool drawHotAreas = true; // Draw Hot Areas Symbol
|
||||||
|
input uchar hotHHArrowCode = 234; // Hot HH Arrow Code
|
||||||
|
input color hotHHArrowColor = clrAqua; // Hot HH Arrow Color
|
||||||
|
input uchar hotLLArrowCode = 233; // Hot LL Arrow Code
|
||||||
|
input color hotLLArrowColor = clrFuchsia; // Hot LL Arrow Color
|
||||||
|
|
||||||
|
//
|
||||||
|
// LC Inputs ...
|
||||||
|
input group "Long Cycle";
|
||||||
|
input group "LC Market";
|
||||||
|
input int lcLength = 28; // Length
|
||||||
|
input double lcThresholdInPips = 0.3; // Threshold In Pips
|
||||||
|
input ENUM_SERIESMODE lcHHMode = MODE_HIGH; // Highest High Calculation Method
|
||||||
|
input ENUM_SERIESMODE lcLLMode = MODE_LOW; // Lowest Low Calculation Method
|
||||||
|
input group "LC Style";
|
||||||
|
input int lcDrawWidth = 1; // Draw Width
|
||||||
|
input ENUM_DRAW_TYPE lcDrawType = DRAW_LINE; // Draw Type
|
||||||
|
input ENUM_LINE_STYLE lcDrawStyle = STYLE_DOT; // Draw Style
|
||||||
|
input color lcHHColor = clrAqua; // Highest High Color
|
||||||
|
input color lcLLColor = clrFuchsia; // Lowest Low Color
|
||||||
|
input group "LC Drawings";
|
||||||
|
input bool lcDrawHH = true; // Draw Highest High
|
||||||
|
input bool lcDrawLL = true; // Draw Lowest Low
|
||||||
|
|
||||||
|
//
|
||||||
|
// MC Inputs ...
|
||||||
|
input group "Medium Cycle";
|
||||||
|
input group "MC Market";
|
||||||
|
input int mcLength = 14; // Length
|
||||||
|
input double mcThresholdInPips = 0.3; // Threshold In Pips
|
||||||
|
input ENUM_SERIESMODE mcHHMode = MODE_HIGH; // Highest High Calculation Method
|
||||||
|
input ENUM_SERIESMODE mcLLMode = MODE_LOW; // Lowest Low Calculation Method
|
||||||
|
input group "MC Style";
|
||||||
|
input int mcDrawWidth = 1; // Draw Width
|
||||||
|
input ENUM_DRAW_TYPE mcDrawType = DRAW_LINE; // Draw Type
|
||||||
|
input ENUM_LINE_STYLE mcDrawStyle = STYLE_DOT; // Draw Style
|
||||||
|
input color mcHHColor = clrLime; // Highest High Color
|
||||||
|
input color mcLLColor = clrRed; // Lowest Low Color
|
||||||
|
input group "MC Drawings";
|
||||||
|
input bool mcDrawHH = true; // Draw Highest High
|
||||||
|
input bool mcDrawLL = true; // Draw Lowest Low
|
||||||
|
|
||||||
|
//
|
||||||
|
// SC Inputs ...
|
||||||
|
input group "Short Cycle";
|
||||||
|
input group "SC Market";
|
||||||
|
input int scLength = 7; // Length
|
||||||
|
input double scThresholdInPips = 0.3; // Threshold In Pips
|
||||||
|
input ENUM_SERIESMODE scHHMode = MODE_HIGH; // Highest High Calculation Method
|
||||||
|
input ENUM_SERIESMODE scLLMode = MODE_LOW; // Lowest Low Calculation Method
|
||||||
|
input group "SC Style";
|
||||||
|
input int scDrawWidth = 1; // Draw Width
|
||||||
|
input ENUM_DRAW_TYPE scDrawType = DRAW_LINE; // Draw Type
|
||||||
|
input ENUM_LINE_STYLE scDrawStyle = STYLE_DOT; // Draw Style
|
||||||
|
input color scHHColor = clrLightBlue; // Highest High Color
|
||||||
|
input color scLLColor = clrLightSalmon; // Lowest Low Color
|
||||||
|
input group "SC Drawings";
|
||||||
|
input bool scDrawHH = true; // Draw Highest High
|
||||||
|
input bool scDrawLL = true; // Draw Lowest Low
|
||||||
|
//
|
||||||
|
// END Inputs ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Includes Logging Library ...
|
||||||
|
#include "../Libraries/x-saherelm.log.lib.mq5";
|
||||||
|
|
||||||
|
//
|
||||||
|
// Includes Common Library ...
|
||||||
|
#include "../Libraries/x-saherelm.common.lib.mq5";
|
||||||
|
|
||||||
|
//
|
||||||
|
// Includes Draw Library ...
|
||||||
|
#include "../Libraries/x-saherelm.draw.lib.mq5";
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Buffers ...
|
||||||
|
//
|
||||||
|
#property indicator_separate_window
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_buffers 9
|
||||||
|
#property indicator_plots 8
|
||||||
|
|
||||||
|
//
|
||||||
|
// LC ...
|
||||||
|
#define lcHHBufferIndex 0
|
||||||
|
#define lcLLBufferIndex 1
|
||||||
|
|
||||||
|
//
|
||||||
|
double lcHHBuffer[];
|
||||||
|
double lcLLBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
// MC ...
|
||||||
|
#define mcHHBufferIndex 2
|
||||||
|
#define mcLLBufferIndex 3
|
||||||
|
|
||||||
|
//
|
||||||
|
double mcHHBuffer[];
|
||||||
|
double mcLLBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
// SC ...
|
||||||
|
#define scHHBufferIndex 4
|
||||||
|
#define scLLBufferIndex 5
|
||||||
|
|
||||||
|
//
|
||||||
|
double scHHBuffer[];
|
||||||
|
double scLLBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
// SIGNAL ...
|
||||||
|
#define signalTBufferIndex 6
|
||||||
|
#define signalBBufferIndex 7
|
||||||
|
|
||||||
|
//
|
||||||
|
double signalTBuffer[];
|
||||||
|
double signalBBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label7 "XSignal T"
|
||||||
|
#property indicator_type7 DRAW_LINE
|
||||||
|
#property indicator_color7 clrGold
|
||||||
|
#property indicator_style7 STYLE_DOT
|
||||||
|
#property indicator_width7 1
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label8 "XSignal B"
|
||||||
|
#property indicator_type8 DRAW_LINE
|
||||||
|
#property indicator_color8 clrBlueViolet
|
||||||
|
#property indicator_style8 STYLE_DOT
|
||||||
|
#property indicator_width8 1
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hot State ...
|
||||||
|
//
|
||||||
|
#define hotStateBufferIndex 8
|
||||||
|
|
||||||
|
//
|
||||||
|
double hotStateBuffer[];
|
||||||
|
//
|
||||||
|
// 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 ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// ReDraw Chart ...
|
||||||
|
ChartRedraw();
|
||||||
|
|
||||||
|
//
|
||||||
|
// De Init Draw Library ...
|
||||||
|
OnDeinitDrawLibrary();
|
||||||
|
|
||||||
|
//
|
||||||
|
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(lcLength, mcLength);
|
||||||
|
maxLength = MathMax(maxLength, scLength);
|
||||||
|
|
||||||
|
//
|
||||||
|
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 ...
|
||||||
|
bool isLCInputsValid =
|
||||||
|
lcLength >= 4 &&
|
||||||
|
lcLength > mcLength &&
|
||||||
|
lcLength > scLength;
|
||||||
|
bool isMCInputsValid =
|
||||||
|
mcLength >= 4 &&
|
||||||
|
mcLength > scLength &&
|
||||||
|
mcLength < lcLength;
|
||||||
|
bool isSCInputsValid =
|
||||||
|
scLength >= 4 &&
|
||||||
|
scLength < mcLength &&
|
||||||
|
scLength < lcLength;
|
||||||
|
if (
|
||||||
|
isLCInputsValid &&
|
||||||
|
isMCInputsValid &&
|
||||||
|
isSCInputsValid)
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Define Indexes and Styles ...
|
||||||
|
void DefineBuffers()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// LC ...
|
||||||
|
LCDefineBuffers();
|
||||||
|
|
||||||
|
//
|
||||||
|
// MC ...
|
||||||
|
MCDefineBuffers();
|
||||||
|
|
||||||
|
//
|
||||||
|
// SC ...
|
||||||
|
SCDefineBuffers();
|
||||||
|
|
||||||
|
//
|
||||||
|
// SIGNAL ...
|
||||||
|
SignalDefineBuffers();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hot State Buffer ...
|
||||||
|
HotStateDefineBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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 // Current Candle Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// LC ...
|
||||||
|
LCCalculateBuffers(bar_index);
|
||||||
|
|
||||||
|
//
|
||||||
|
// MC ...
|
||||||
|
MCCalculateBuffers(bar_index);
|
||||||
|
|
||||||
|
//
|
||||||
|
// SC ...
|
||||||
|
SCCalculateBuffers(bar_index);
|
||||||
|
|
||||||
|
//
|
||||||
|
// SIGNAL ...
|
||||||
|
SignalCalculateBuffers(bar_index);
|
||||||
|
|
||||||
|
//
|
||||||
|
// HOT State Buffer ...
|
||||||
|
HotStateCalculateBuffers(bar_index);
|
||||||
|
|
||||||
|
//
|
||||||
|
// After all Calculations we are ready to Draw what we want ...
|
||||||
|
DrawBuffers(bar_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// LC Buffers Definitions ...
|
||||||
|
void LCDefineBuffers()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// LC HH Buffer ...
|
||||||
|
string lcHHBufferLabel = ShortName + " LC HH (" + (string)lcLength + ")";
|
||||||
|
ENUM_DRAW_TYPE lcHHDrawType = lcDrawHH ? lcDrawType : DRAW_NONE;
|
||||||
|
ArraySetAsSeries(lcHHBuffer, true);
|
||||||
|
SetIndexBuffer(lcHHBufferIndex, lcHHBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(lcHHBufferIndex, PLOT_DRAW_BEGIN, lcLength);
|
||||||
|
PlotIndexSetString(lcHHBufferIndex, PLOT_LABEL, lcHHBufferLabel);
|
||||||
|
PlotIndexSetInteger(lcHHBufferIndex, PLOT_LINE_COLOR, lcHHColor);
|
||||||
|
PlotIndexSetInteger(lcHHBufferIndex, PLOT_LINE_STYLE, lcDrawStyle);
|
||||||
|
PlotIndexSetInteger(lcHHBufferIndex, PLOT_LINE_WIDTH, lcDrawWidth);
|
||||||
|
PlotIndexSetInteger(lcHHBufferIndex, PLOT_DRAW_TYPE, lcHHDrawType);
|
||||||
|
|
||||||
|
//
|
||||||
|
// LC LL Buffer ...
|
||||||
|
string lcLLBufferLabel = ShortName + " LC LL (" + (string)lcLength + ")";
|
||||||
|
ENUM_DRAW_TYPE lcLLDrawType = lcDrawLL ? lcDrawType : DRAW_NONE;
|
||||||
|
ArraySetAsSeries(lcLLBuffer, true);
|
||||||
|
SetIndexBuffer(lcLLBufferIndex, lcLLBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(lcLLBufferIndex, PLOT_DRAW_BEGIN, lcLength);
|
||||||
|
PlotIndexSetString(lcLLBufferIndex, PLOT_LABEL, lcLLBufferLabel);
|
||||||
|
PlotIndexSetInteger(lcLLBufferIndex, PLOT_LINE_COLOR, lcLLColor);
|
||||||
|
PlotIndexSetInteger(lcLLBufferIndex, PLOT_LINE_STYLE, lcDrawStyle);
|
||||||
|
PlotIndexSetInteger(lcLLBufferIndex, PLOT_LINE_WIDTH, lcDrawWidth);
|
||||||
|
PlotIndexSetInteger(lcLLBufferIndex, PLOT_DRAW_TYPE, lcLLDrawType);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// MC Buffers Definitions ...
|
||||||
|
void MCDefineBuffers()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// MC HH Buffer ...
|
||||||
|
string mcHHBufferLabel = ShortName + " MC HH (" + (string)mcLength + ")";
|
||||||
|
ENUM_DRAW_TYPE mcHHDrawType = mcDrawHH ? lcDrawType : DRAW_NONE;
|
||||||
|
ArraySetAsSeries(mcHHBuffer, true);
|
||||||
|
SetIndexBuffer(mcHHBufferIndex, mcHHBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(mcHHBufferIndex, PLOT_DRAW_BEGIN, mcLength);
|
||||||
|
PlotIndexSetString(mcHHBufferIndex, PLOT_LABEL, mcHHBufferLabel);
|
||||||
|
PlotIndexSetInteger(mcHHBufferIndex, PLOT_LINE_COLOR, mcHHColor);
|
||||||
|
PlotIndexSetInteger(mcHHBufferIndex, PLOT_LINE_STYLE, mcDrawStyle);
|
||||||
|
PlotIndexSetInteger(mcHHBufferIndex, PLOT_LINE_WIDTH, mcDrawWidth);
|
||||||
|
PlotIndexSetInteger(mcHHBufferIndex, PLOT_DRAW_TYPE, mcHHDrawType);
|
||||||
|
|
||||||
|
//
|
||||||
|
// MC LL Buffer ...
|
||||||
|
string mcLLBufferLabel = ShortName + " MC LL (" + (string)mcLength + ")";
|
||||||
|
ENUM_DRAW_TYPE mcLLDrawType = mcDrawLL ? lcDrawType : DRAW_NONE;
|
||||||
|
ArraySetAsSeries(mcLLBuffer, true);
|
||||||
|
SetIndexBuffer(mcLLBufferIndex, mcLLBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(mcLLBufferIndex, PLOT_DRAW_BEGIN, mcLength);
|
||||||
|
PlotIndexSetString(mcLLBufferIndex, PLOT_LABEL, mcLLBufferLabel);
|
||||||
|
PlotIndexSetInteger(mcLLBufferIndex, PLOT_LINE_COLOR, mcLLColor);
|
||||||
|
PlotIndexSetInteger(mcLLBufferIndex, PLOT_LINE_STYLE, mcDrawStyle);
|
||||||
|
PlotIndexSetInteger(mcLLBufferIndex, PLOT_LINE_WIDTH, mcDrawWidth);
|
||||||
|
PlotIndexSetInteger(mcLLBufferIndex, PLOT_DRAW_TYPE, mcLLDrawType);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// SC Buffers Definitions ...
|
||||||
|
void SCDefineBuffers()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// SC HH Buffer ...
|
||||||
|
string scHHBufferLabel = ShortName + " SC HH (" + (string)scLength + ")";
|
||||||
|
ENUM_DRAW_TYPE scHHDrawType = scDrawHH ? lcDrawType : DRAW_NONE;
|
||||||
|
ArraySetAsSeries(scHHBuffer, true);
|
||||||
|
SetIndexBuffer(scHHBufferIndex, scHHBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(scHHBufferIndex, PLOT_DRAW_BEGIN, scLength);
|
||||||
|
PlotIndexSetString(scHHBufferIndex, PLOT_LABEL, scHHBufferLabel);
|
||||||
|
PlotIndexSetInteger(scHHBufferIndex, PLOT_LINE_COLOR, scHHColor);
|
||||||
|
PlotIndexSetInteger(scHHBufferIndex, PLOT_LINE_STYLE, scDrawStyle);
|
||||||
|
PlotIndexSetInteger(scHHBufferIndex, PLOT_LINE_WIDTH, scDrawWidth);
|
||||||
|
PlotIndexSetInteger(scHHBufferIndex, PLOT_DRAW_TYPE, scHHDrawType);
|
||||||
|
|
||||||
|
//
|
||||||
|
// SC LL Buffer ...
|
||||||
|
string scLLBufferLabel = ShortName + " SC LL (" + (string)scLength + ")";
|
||||||
|
ENUM_DRAW_TYPE scLLDrawType = scDrawLL ? lcDrawType : DRAW_NONE;
|
||||||
|
ArraySetAsSeries(scLLBuffer, true);
|
||||||
|
SetIndexBuffer(scLLBufferIndex, scLLBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(scLLBufferIndex, PLOT_DRAW_BEGIN, scLength);
|
||||||
|
PlotIndexSetString(scLLBufferIndex, PLOT_LABEL, scLLBufferLabel);
|
||||||
|
PlotIndexSetInteger(scLLBufferIndex, PLOT_LINE_COLOR, scLLColor);
|
||||||
|
PlotIndexSetInteger(scLLBufferIndex, PLOT_LINE_STYLE, scDrawStyle);
|
||||||
|
PlotIndexSetInteger(scLLBufferIndex, PLOT_LINE_WIDTH, scDrawWidth);
|
||||||
|
PlotIndexSetInteger(scLLBufferIndex, PLOT_DRAW_TYPE, scLLDrawType);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// SIGNAL Buffers Definitions ...
|
||||||
|
void SignalDefineBuffers()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// SIGNAL T Buffer ...
|
||||||
|
string signalTBufferLabel = ShortName + " Signal T";
|
||||||
|
ArraySetAsSeries(signalTBuffer, true);
|
||||||
|
SetIndexBuffer(signalTBufferIndex, signalTBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(signalTBufferIndex, PLOT_DRAW_BEGIN, lcLength);
|
||||||
|
PlotIndexSetString(signalTBufferIndex, PLOT_LABEL, signalTBufferLabel);
|
||||||
|
|
||||||
|
//
|
||||||
|
// SIGNAL B Buffer ...
|
||||||
|
string signalBBufferLabel = ShortName + " Signal B";
|
||||||
|
ArraySetAsSeries(signalBBuffer, true);
|
||||||
|
SetIndexBuffer(signalBBufferIndex, signalBBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(signalBBufferIndex, PLOT_DRAW_BEGIN, lcLength);
|
||||||
|
PlotIndexSetString(signalBBufferIndex, PLOT_LABEL, signalBBufferLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hot State Buffer ...
|
||||||
|
void HotStateDefineBuffers()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Hot State Buffer ...
|
||||||
|
ArraySetAsSeries(hotStateBuffer, true);
|
||||||
|
SetIndexBuffer(hotStateBufferIndex, hotStateBuffer, INDICATOR_CALCULATIONS);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// LC Calculations ...
|
||||||
|
void LCCalculateBuffers(
|
||||||
|
int bar_index // Current Candle Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Detect Cycle HH and LL ...
|
||||||
|
int length = lcLength;
|
||||||
|
ENUM_SERIESMODE hhMode = lcHHMode;
|
||||||
|
ENUM_SERIESMODE llMode = lcLLMode;
|
||||||
|
double threshold = PipsToPrice(lcThresholdInPips);
|
||||||
|
double hh = GetHighestHigh(
|
||||||
|
length,
|
||||||
|
bar_index,
|
||||||
|
hhMode);
|
||||||
|
double hhValue = hh + threshold;
|
||||||
|
double ll = GetLowestLow(
|
||||||
|
length,
|
||||||
|
bar_index,
|
||||||
|
llMode);
|
||||||
|
double llValue = ll - threshold;
|
||||||
|
|
||||||
|
//
|
||||||
|
lcHHBuffer[bar_index] = hhValue;
|
||||||
|
lcLLBuffer[bar_index] = llValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// MC Calculations ...
|
||||||
|
void MCCalculateBuffers(
|
||||||
|
int bar_index // Current Candle Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Detect Cycle HH and LL ...
|
||||||
|
int length = mcLength;
|
||||||
|
ENUM_SERIESMODE hhMode = mcHHMode;
|
||||||
|
ENUM_SERIESMODE llMode = mcLLMode;
|
||||||
|
double threshold = PipsToPrice(mcThresholdInPips);
|
||||||
|
double hh = GetHighestHigh(
|
||||||
|
length,
|
||||||
|
bar_index,
|
||||||
|
hhMode);
|
||||||
|
double hhValue = hh + threshold;
|
||||||
|
double ll = GetLowestLow(
|
||||||
|
length,
|
||||||
|
bar_index,
|
||||||
|
llMode);
|
||||||
|
double llValue = ll - threshold;
|
||||||
|
|
||||||
|
//
|
||||||
|
mcHHBuffer[bar_index] = hhValue;
|
||||||
|
mcLLBuffer[bar_index] = llValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// SC Calculations ...
|
||||||
|
void SCCalculateBuffers(
|
||||||
|
int bar_index // Current Candle Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Detect Cycle HH and LL ...
|
||||||
|
int length = scLength;
|
||||||
|
ENUM_SERIESMODE hhMode = scHHMode;
|
||||||
|
ENUM_SERIESMODE llMode = scLLMode;
|
||||||
|
double threshold = PipsToPrice(scThresholdInPips);
|
||||||
|
double hh = GetHighestHigh(
|
||||||
|
length,
|
||||||
|
bar_index,
|
||||||
|
hhMode);
|
||||||
|
double hhValue = hh + threshold;
|
||||||
|
double ll = GetLowestLow(
|
||||||
|
length,
|
||||||
|
bar_index,
|
||||||
|
llMode);
|
||||||
|
double llValue = ll - threshold;
|
||||||
|
|
||||||
|
//
|
||||||
|
scHHBuffer[bar_index] = hhValue;
|
||||||
|
scLLBuffer[bar_index] = llValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// SIGNAL Calculations ...
|
||||||
|
void SignalCalculateBuffers(
|
||||||
|
int bar_index // Current Candle Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// LC Values ...
|
||||||
|
double lcHH = lcHHBuffer[bar_index];
|
||||||
|
double lcLL = lcLLBuffer[bar_index];
|
||||||
|
double lcDelta = lcHH - lcLL;
|
||||||
|
double lcAvg = lcDelta / 2;
|
||||||
|
|
||||||
|
//
|
||||||
|
// MC Values ...
|
||||||
|
double mcHH = mcHHBuffer[bar_index];
|
||||||
|
double mcLL = mcLLBuffer[bar_index];
|
||||||
|
double mcDelta = mcHH - mcLL;
|
||||||
|
double mcAvg = mcDelta / 2;
|
||||||
|
|
||||||
|
//
|
||||||
|
// SC Values ...
|
||||||
|
double scHH = scHHBuffer[bar_index];
|
||||||
|
double scLL = scLLBuffer[bar_index];
|
||||||
|
double scDelta = scHH - scLL;
|
||||||
|
double scAvg = scDelta / 2;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Min Value ...
|
||||||
|
double minValue = MathMin(
|
||||||
|
scLL, mcLL);
|
||||||
|
minValue = MathMin(
|
||||||
|
lcLL, minValue);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Max Value ...
|
||||||
|
double maxValue = MathMin(
|
||||||
|
scHH, mcHH);
|
||||||
|
maxValue = MathMin(
|
||||||
|
lcHH, maxValue);
|
||||||
|
|
||||||
|
//
|
||||||
|
double operationalValue = 0;
|
||||||
|
switch(signalType) {
|
||||||
|
//
|
||||||
|
case X_XCHLH_DELTA_SIGNAL:
|
||||||
|
operationalValue = ((lcDelta + mcDelta + scDelta) / 3);
|
||||||
|
break;
|
||||||
|
|
||||||
|
//
|
||||||
|
case X_XCHLH_AVG_SIGNAL:
|
||||||
|
default:
|
||||||
|
operationalValue = ((lcAvg + mcAvg + scAvg) / 3);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
double signalTValue = minValue + operationalValue;
|
||||||
|
double signalBValue = maxValue - operationalValue;
|
||||||
|
|
||||||
|
//
|
||||||
|
signalTBuffer[bar_index] = signalTValue;
|
||||||
|
signalBBuffer[bar_index] = signalBValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// HOT State Calculate Buffers ...
|
||||||
|
void HotStateCalculateBuffers(
|
||||||
|
int bar_index // Current Candle Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// LC ...
|
||||||
|
double lcHH = lcHHBuffer[bar_index];
|
||||||
|
double lcLL = lcLLBuffer[bar_index];
|
||||||
|
//
|
||||||
|
double lcHH1 = lcHHBuffer[bar_index + 1];
|
||||||
|
double lcLL1 = lcLLBuffer[bar_index + 1];
|
||||||
|
|
||||||
|
//
|
||||||
|
// MC ...
|
||||||
|
double mcHH = mcHHBuffer[bar_index];
|
||||||
|
double mcLL = mcLLBuffer[bar_index];
|
||||||
|
//
|
||||||
|
double mcHH1 = mcHHBuffer[bar_index + 1];
|
||||||
|
double mcLL1 = mcLLBuffer[bar_index + 1];
|
||||||
|
|
||||||
|
//
|
||||||
|
// SC ...
|
||||||
|
double scHH = scHHBuffer[bar_index];
|
||||||
|
double scLL = scLLBuffer[bar_index];
|
||||||
|
//
|
||||||
|
double scHH1 = scHHBuffer[bar_index + 1];
|
||||||
|
double scLL1 = scLLBuffer[bar_index + 1];
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isHotLLState = scLL == mcLL && mcLL == lcLL;
|
||||||
|
bool isHotLLState1 = scLL1 == mcLL1 && mcLL1 == lcLL1;
|
||||||
|
//
|
||||||
|
bool isHotHHState = scHH == mcHH && mcHH == lcHH;
|
||||||
|
bool isHotHHState1 = scHH1 == mcHH1 && mcHH1 == lcHH1;
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isHotLL = isHotLLState && !isHotLLState1;
|
||||||
|
bool isHotHH = isHotHHState && !isHotHHState1;
|
||||||
|
|
||||||
|
//
|
||||||
|
double hotStateValue = X_XCHLH_NEUTURAL;
|
||||||
|
if (isHotHH)
|
||||||
|
{
|
||||||
|
hotStateValue = X_XCHLH_HOT_HH;
|
||||||
|
}
|
||||||
|
else if (isHotLL)
|
||||||
|
{
|
||||||
|
hotStateValue = X_XCHLH_HOT_LL;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
hotStateBuffer[bar_index] = hotStateValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Draw Buffers ...
|
||||||
|
void DrawBuffers(
|
||||||
|
int bar_index // Current Candle Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// General Requirements ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Candle Model ...
|
||||||
|
XOHCL candle = GetCandle(bar_index);
|
||||||
|
datetime time = iTime(_Symbol, _Period, bar_index);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Draw Arrow on Hot Areas ...
|
||||||
|
if (drawHotAreas)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
double hotStateValue = hotStateBuffer[bar_index];
|
||||||
|
bool isHotHHArea = hotStateValue == 1;
|
||||||
|
bool isHotLLArea = hotStateValue == -1;
|
||||||
|
if (isHotHHArea || isHotLLArea)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool isHH = isHotHHArea;
|
||||||
|
|
||||||
|
//
|
||||||
|
double price = isHH ? candle.high : candle.low;
|
||||||
|
ENUM_ARROW_ANCHOR anchor = isHH ? ANCHOR_BOTTOM : ANCHOR_TOP;
|
||||||
|
color clr = isHH ? hotHHArrowColor : hotLLArrowColor;
|
||||||
|
uchar arrowCode = isHH ? hotHHArrowCode : hotLLArrowCode;
|
||||||
|
string name = "HOT " + (isHH ? "HH" : "LL") + "_" + (string)price + "_" + (string)time;
|
||||||
|
|
||||||
|
//
|
||||||
|
DrawArrow(
|
||||||
|
0,
|
||||||
|
name,
|
||||||
|
0,
|
||||||
|
time,
|
||||||
|
price,
|
||||||
|
arrowCode,
|
||||||
|
anchor,
|
||||||
|
clr,
|
||||||
|
STYLE_SOLID,
|
||||||
|
1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Functions ...
|
||||||
|
//
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -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 ...
|
||||||
|
//
|
||||||
@@ -0,0 +1,358 @@
|
|||||||
|
/////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center MQL5 OrderBlock Detector Oscillator
|
||||||
|
// ------------------------------------------------------
|
||||||
|
// Name: XRSI
|
||||||
|
// Description: detect market conditions based on RSI ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// 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 XRSI Oscillator"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Constants ...
|
||||||
|
//
|
||||||
|
|
||||||
|
#define ShortName "XRSI"
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Constants ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Market";
|
||||||
|
input int length = 14; // Market Length
|
||||||
|
input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Short Entry";
|
||||||
|
input double shortEntryValue = 70; // Short Entry Level
|
||||||
|
input color shortEntryColor = clrRed; // Short Entry Level Color
|
||||||
|
input ENUM_LINE_STYLE shortEntryLineStyle = STYLE_SOLID; // Short Entry Style
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Short Exit";
|
||||||
|
input double shortExitValue = 40; // Short Exit Level
|
||||||
|
input color shortExitColor = clrFuchsia; // Short Exit Level Color
|
||||||
|
input ENUM_LINE_STYLE shortExitLineStyle = STYLE_DOT; // Short Exit Style
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Long Entry";
|
||||||
|
input double longEntryValue = 30; // Long Entry Level
|
||||||
|
input color longEntryColor = clrGreen; // Long Entry Level Color
|
||||||
|
input ENUM_LINE_STYLE longEntryLineStyle = STYLE_SOLID; // Long Entry Style
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Long Exit";
|
||||||
|
input double longExitValue = 60; // Long Exit Level
|
||||||
|
input color longExitColor = clrAqua; // Long Exit Level Color
|
||||||
|
input ENUM_LINE_STYLE longExitLineStyle = STYLE_DOT; // Long Exit Style
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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 1
|
||||||
|
#property indicator_plots 1
|
||||||
|
|
||||||
|
//
|
||||||
|
#define rsiBufferIndex 0
|
||||||
|
|
||||||
|
double rsiBuffer[];
|
||||||
|
|
||||||
|
#property indicator_label1 "XRSI"
|
||||||
|
#property indicator_type1 DRAW_LINE
|
||||||
|
#property indicator_color1 clrAqua
|
||||||
|
#property indicator_style1 STYLE_DOT
|
||||||
|
#property indicator_width1 1
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Buffers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
int rsiHandler = 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;
|
||||||
|
|
||||||
|
//
|
||||||
|
rsiHandler = iRSI(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
length,
|
||||||
|
appliedTo);
|
||||||
|
if (rsiHandler == INVALID_HANDLE)
|
||||||
|
{
|
||||||
|
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 ...
|
||||||
|
|
||||||
|
//
|
||||||
|
IndicatorRelease(rsiHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
//
|
||||||
|
int rsiCalculatedBars = BarsCalculated(rsiHandler);
|
||||||
|
if (rsiCalculatedBars < maxLength)
|
||||||
|
{
|
||||||
|
return prev_calculated;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated;
|
||||||
|
|
||||||
|
//
|
||||||
|
int rsiCopiedItems = CopyBuffer(rsiHandler, 0, 0, limit, rsiBuffer);
|
||||||
|
if (rsiCopiedItems <= 0)
|
||||||
|
{
|
||||||
|
return prev_calculated;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// RSI ...
|
||||||
|
string rsiBufferLabel = ShortName + " (" + (string)length + ")";
|
||||||
|
ArraySetAsSeries(rsiBuffer, true);
|
||||||
|
SetIndexBuffer(rsiBufferIndex, rsiBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(rsiBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||||
|
PlotIndexSetString(rsiBufferIndex, PLOT_LABEL, rsiBufferLabel);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set Indicator Levels here ...
|
||||||
|
// OB, ExitLong, ExitShort, OS ...
|
||||||
|
IndicatorSetInteger(INDICATOR_LEVELS, 4);
|
||||||
|
|
||||||
|
//
|
||||||
|
// SHORTENTRY ...
|
||||||
|
IndicatorSetDouble(INDICATOR_LEVELVALUE, 0, shortEntryValue);
|
||||||
|
IndicatorSetInteger(INDICATOR_LEVELCOLOR, 0, shortEntryColor);
|
||||||
|
IndicatorSetInteger(INDICATOR_LEVELSTYLE, 0, shortEntryLineStyle);
|
||||||
|
IndicatorSetString(INDICATOR_LEVELTEXT, 0, "Short Entry");
|
||||||
|
|
||||||
|
//
|
||||||
|
// LONGEXIT ...
|
||||||
|
IndicatorSetDouble(INDICATOR_LEVELVALUE, 1, longExitValue);
|
||||||
|
IndicatorSetInteger(INDICATOR_LEVELCOLOR, 1, longExitColor);
|
||||||
|
IndicatorSetInteger(INDICATOR_LEVELSTYLE, 1, shortExitLineStyle);
|
||||||
|
IndicatorSetString(INDICATOR_LEVELTEXT, 1, "Long Exit");
|
||||||
|
|
||||||
|
//
|
||||||
|
// SHORTEXIT ...
|
||||||
|
IndicatorSetDouble(INDICATOR_LEVELVALUE, 2, shortExitValue);
|
||||||
|
IndicatorSetInteger(INDICATOR_LEVELCOLOR, 2, shortExitColor);
|
||||||
|
IndicatorSetInteger(INDICATOR_LEVELSTYLE, 2, longEntryLineStyle);
|
||||||
|
IndicatorSetString(INDICATOR_LEVELTEXT, 2, "Short Exit");
|
||||||
|
|
||||||
|
//
|
||||||
|
// LONGENTRY ...
|
||||||
|
IndicatorSetDouble(INDICATOR_LEVELVALUE, 3, longEntryValue);
|
||||||
|
IndicatorSetInteger(INDICATOR_LEVELCOLOR, 3, longEntryColor);
|
||||||
|
IndicatorSetInteger(INDICATOR_LEVELSTYLE, 3, longExitLineStyle);
|
||||||
|
IndicatorSetString(INDICATOR_LEVELTEXT, 3, "Long Entry");
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set Maximum and Minimum for subwindow
|
||||||
|
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||||
|
IndicatorSetDouble(INDICATOR_MINIMUM, 0);
|
||||||
|
IndicatorSetDouble(INDICATOR_MAXIMUM, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Functions ...
|
||||||
|
//
|
||||||
@@ -0,0 +1,465 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center MQL5 Trend Detector Oscillator
|
||||||
|
// --------------------------------------------------
|
||||||
|
// Name: XTD
|
||||||
|
// Description: trend detecting in both sides ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// 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 XTD Oscillator"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Constants ...
|
||||||
|
//
|
||||||
|
#define ShortName "XTD"
|
||||||
|
|
||||||
|
//
|
||||||
|
// XTD Oscillator States ...
|
||||||
|
enum ENUM_X_XTD_STATES
|
||||||
|
{
|
||||||
|
X_XTD_BULLISH_CROSSED_OVER_BEARISH = 2,
|
||||||
|
X_XTD_BULLISH_OVER_BEARISH = 1,
|
||||||
|
X_XTD_NEUTURAL = 0,
|
||||||
|
X_XTD_BULLISH_UNDER_BEARISH = -1,
|
||||||
|
X_XTD_BULLISH_CROSSED_UNDER_BEARISH = -2
|
||||||
|
};
|
||||||
|
//
|
||||||
|
// END Constants ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Include Models Library ...
|
||||||
|
#include "../Libraries/x-saherelm.models.lib.mq5";
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ...
|
||||||
|
//
|
||||||
|
input int length = 14; // Market Length
|
||||||
|
input bool drawCrosses = true; // Draw Cross Arrows
|
||||||
|
|
||||||
|
//
|
||||||
|
// Bullish ...
|
||||||
|
input uchar bullishArrowCode = 228; // Cross Over Arrow Code
|
||||||
|
input color bullishArrowColor = clrAqua; // Cross Over Arrow Color
|
||||||
|
|
||||||
|
//
|
||||||
|
// Bearish ...
|
||||||
|
input uchar bearishArrowCode = 230; // Cross Under Arrow Code
|
||||||
|
input color bearishArrowColor = clrMagenta; // Cross Under Arrow Color
|
||||||
|
//
|
||||||
|
// END Inputs ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Includes Logging Library ...
|
||||||
|
#include "../Libraries/x-saherelm.log.lib.mq5";
|
||||||
|
|
||||||
|
//
|
||||||
|
// Includes Common Library ...
|
||||||
|
#include "../Libraries/x-saherelm.common.lib.mq5";
|
||||||
|
|
||||||
|
//
|
||||||
|
// Includes Draw Library ...
|
||||||
|
#include "../Libraries/x-saherelm.draw.lib.mq5";
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Buffers ...
|
||||||
|
//
|
||||||
|
#property indicator_separate_window
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_buffers 3
|
||||||
|
#property indicator_plots 3
|
||||||
|
|
||||||
|
//
|
||||||
|
#define bullishBufferIndex 0
|
||||||
|
#define bearishBufferIndex 1
|
||||||
|
#define signalBufferIndex 2
|
||||||
|
|
||||||
|
//
|
||||||
|
double bullishBuffer[];
|
||||||
|
double bearishBuffer[];
|
||||||
|
double signalBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label1 "XBullPower"
|
||||||
|
#property indicator_type1 DRAW_LINE
|
||||||
|
#property indicator_color1 clrLime
|
||||||
|
#property indicator_style1 STYLE_SOLID
|
||||||
|
#property indicator_width1 1
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label2 "XBearPower"
|
||||||
|
#property indicator_type2 DRAW_LINE
|
||||||
|
#property indicator_color2 clrRed
|
||||||
|
#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 ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
int xtdBullishCandleCount = 0;
|
||||||
|
int xtdBearishCandleCount = 0;
|
||||||
|
//
|
||||||
|
// 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 ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// De Init Draw Library ...
|
||||||
|
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);
|
||||||
|
|
||||||
|
//
|
||||||
|
limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Main Loop ...
|
||||||
|
for (int i = limit; i >= 0 && !IsStopped(); i--)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
CalculateBuffers(i, close);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return rates_total;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Event Handlers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Functions ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Validate Input Args for Initialization ...
|
||||||
|
bool ValidateInputs()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
if (length >= 5)
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Define Indexes and Styles ...
|
||||||
|
void DefineBuffers()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Bullish Buffer ...
|
||||||
|
string bullishBufferLabel = ShortName + "BullPow " + "(" + (string)length + ")";
|
||||||
|
ArraySetAsSeries(bullishBuffer, true);
|
||||||
|
SetIndexBuffer(bullishBufferIndex, bullishBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(bullishBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||||
|
PlotIndexSetString(bullishBufferIndex, PLOT_LABEL, bullishBufferLabel);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Bearish Buffer ...
|
||||||
|
string bearishBufferLabel = ShortName + "BearPow " + "(" + (string)length + ")";
|
||||||
|
ArraySetAsSeries(bearishBuffer, true);
|
||||||
|
SetIndexBuffer(bearishBufferIndex, bearishBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(bearishBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||||
|
PlotIndexSetString(bearishBufferIndex, PLOT_LABEL, bearishBufferLabel);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal Buffer ...
|
||||||
|
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,
|
||||||
|
const double &close[])
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Reset Global Counters ...
|
||||||
|
xtdBullishCandleCount = 0;
|
||||||
|
xtdBearishCandleCount = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Loop through Closes ...
|
||||||
|
for (int i = bar_index; i <= bar_index + length; i++)
|
||||||
|
{
|
||||||
|
for (int j = i + 1; j <= bar_index + length; j++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (close[i] > close[j])
|
||||||
|
{
|
||||||
|
xtdBullishCandleCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (close[i] < close[j])
|
||||||
|
{
|
||||||
|
xtdBearishCandleCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Bullish Power Buffer ...
|
||||||
|
bullishBuffer[bar_index] = MathAbs(xtdBullishCandleCount);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Bearish Power Buffer ...
|
||||||
|
bearishBuffer[bar_index] = MathAbs(xtdBearishCandleCount);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal Buffer ...
|
||||||
|
signalBuffer[bar_index] = bullishBuffer[bar_index] - bearishBuffer[bar_index];
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check and Draw Crosses if it's Specified ...
|
||||||
|
if (drawCrosses)
|
||||||
|
{
|
||||||
|
DrawCrosses(bar_index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
//
|
||||||
|
double GetState(
|
||||||
|
int bar_index // Specified Bar Index
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Check Cross Points ...
|
||||||
|
// bullishCrossedOverBearish = 2;
|
||||||
|
// bullishOverBearish = 1;
|
||||||
|
// bullishCrossedUnderBearish = -2;
|
||||||
|
// bullishUnderBearish = -1;
|
||||||
|
// OtherWise = 0;
|
||||||
|
bool isBullishCrossedOverBearish = IsCrossOver(
|
||||||
|
bullishBuffer,
|
||||||
|
bearishBuffer,
|
||||||
|
bar_index);
|
||||||
|
bool isBullishCrossedUnderBearish = IsCrossUnder(
|
||||||
|
bullishBuffer,
|
||||||
|
bearishBuffer,
|
||||||
|
bar_index);
|
||||||
|
bool isBullishOverBearish = IsOver(
|
||||||
|
bullishBuffer,
|
||||||
|
bearishBuffer,
|
||||||
|
bar_index);
|
||||||
|
bool isBullishUnderBearish = IsUnder(
|
||||||
|
bullishBuffer,
|
||||||
|
bearishBuffer,
|
||||||
|
bar_index);
|
||||||
|
|
||||||
|
//
|
||||||
|
double result = X_XTD_NEUTURAL;
|
||||||
|
if (isBullishCrossedOverBearish)
|
||||||
|
{
|
||||||
|
result = X_XTD_BULLISH_CROSSED_OVER_BEARISH;
|
||||||
|
}
|
||||||
|
else if (isBullishCrossedUnderBearish)
|
||||||
|
{
|
||||||
|
result = X_XTD_BULLISH_CROSSED_UNDER_BEARISH;
|
||||||
|
}
|
||||||
|
else if (isBullishOverBearish)
|
||||||
|
{
|
||||||
|
result = X_XTD_BULLISH_OVER_BEARISH;
|
||||||
|
}
|
||||||
|
else if (isBullishUnderBearish)
|
||||||
|
{
|
||||||
|
result = X_XTD_BULLISH_UNDER_BEARISH;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = X_XTD_NEUTURAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Draw Crosses ...
|
||||||
|
void DrawCrosses(
|
||||||
|
int bar_index // the bars which required to draw cross arrow on it ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
double stateValue = GetState(bar_index);
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isOver = stateValue == 2;
|
||||||
|
double low = iLow(_Symbol, _Period, bar_index);
|
||||||
|
double high = iHigh(_Symbol, _Period, bar_index);
|
||||||
|
|
||||||
|
//
|
||||||
|
double price = isOver ? low : high;
|
||||||
|
datetime time = iTime(_Symbol, _Period, bar_index);
|
||||||
|
ENUM_ARROW_ANCHOR anchor = isOver ? ANCHOR_TOP : ANCHOR_BOTTOM;
|
||||||
|
uchar arrowCode = isOver ? bullishArrowCode : bearishArrowCode;
|
||||||
|
color arrowColor = isOver ? bullishArrowColor : bearishArrowColor;
|
||||||
|
string crossName = "Trend " + (isOver ? "Up" : "Down") + "_" + (string)time + "_" + (string)price;
|
||||||
|
|
||||||
|
//
|
||||||
|
DrawArrow(
|
||||||
|
0,
|
||||||
|
crossName,
|
||||||
|
0,
|
||||||
|
time,
|
||||||
|
price,
|
||||||
|
arrowCode,
|
||||||
|
anchor,
|
||||||
|
arrowColor);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// 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,925 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center MQL5 XCHLH 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 ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// XCHLH Hot States ...
|
||||||
|
enum ENUM_X_XCHLH_HOT_STATES
|
||||||
|
{
|
||||||
|
X_XCHLH_HOT_HH = 1,
|
||||||
|
X_XCHLH_NEUTURAL = 0,
|
||||||
|
X_XCHLH_HOT_LL = -1,
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// XCHLH Signal Calculation Types ...
|
||||||
|
enum ENUM_X_XCHLH_SIGNAL_TYPES
|
||||||
|
{
|
||||||
|
X_XCHLH_AVG_SIGNAL,
|
||||||
|
X_XCHLH_DELTA_SIGNAL,
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// XCHLH Buffer Lines ...
|
||||||
|
enum ENUM_X_XCHLH_BUFFER_LINES
|
||||||
|
{
|
||||||
|
X_XCHLH_LC_HH_LINE = 0,
|
||||||
|
X_XCHLH_LC_LL_LINE = 1,
|
||||||
|
X_XCHLH_MC_HH_LINE = 2,
|
||||||
|
X_XCHLH_MC_LL_LINE = 3,
|
||||||
|
X_XCHLH_SC_HH_LINE = 4,
|
||||||
|
X_XCHLH_SC_LL_LINE = 5,
|
||||||
|
X_XCHLH_SIGNAL_T_LINE = 6,
|
||||||
|
X_XCHLH_SIGNAL_B_LINE = 7,
|
||||||
|
X_XCHLH_HOT_STATE_LINE = 8,
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Enum Definitions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "XCHLH Oscillator";
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal Calculations ...
|
||||||
|
input group "XCHLH Signal Calculations";
|
||||||
|
input ENUM_X_XCHLH_SIGNAL_TYPES xCHLHSignalType = X_XCHLH_AVG_SIGNAL; // Signal Method
|
||||||
|
|
||||||
|
//
|
||||||
|
// Common ...
|
||||||
|
input group "XCHLH Hot Areas";
|
||||||
|
input bool xCHLHDrawHotAreas = false; // Draw Hot Areas Symbol
|
||||||
|
input uchar xCHLHHotHHArrowCode = 234; // Hot HH Arrow Code
|
||||||
|
input color xCHLHHotHHArrowColor = clrAqua; // Hot HH Arrow Color
|
||||||
|
input uchar xCHLHHotLLArrowCode = 233; // Hot LL Arrow Code
|
||||||
|
input color xCHLHHotLLArrowColor = clrFuchsia; // Hot LL Arrow Color
|
||||||
|
|
||||||
|
//
|
||||||
|
// LC Inputs ...
|
||||||
|
input group "XCHLH Long Cycle";
|
||||||
|
input group "XCHLH LC Market";
|
||||||
|
input int xCHLHLcLength = 288; // Length
|
||||||
|
input double xCHLHLcThresholdInPips = 0.3; // Threshold In Pips
|
||||||
|
input ENUM_SERIESMODE xCHLHLcHHMode = MODE_HIGH; // Highest High Calculation Method
|
||||||
|
input ENUM_SERIESMODE xCHLHLcLLMode = MODE_LOW; // Lowest Low Calculation Method
|
||||||
|
input group "XCHLH LC Style";
|
||||||
|
input int xCHLHLcDrawWidth = 1; // Draw Width
|
||||||
|
input ENUM_DRAW_TYPE xCHLHLcDrawType = DRAW_LINE; // Draw Type
|
||||||
|
input ENUM_LINE_STYLE xCHLHLcDrawStyle = STYLE_DOT; // Draw Style
|
||||||
|
input color xCHLHLcHHColor = clrAqua; // Highest High Color
|
||||||
|
input color xCHLHLcLLColor = clrFuchsia; // Lowest Low Color
|
||||||
|
input group "XCHLH LC Drawings";
|
||||||
|
input bool xCHLHLcDrawHH = true; // Draw Highest High
|
||||||
|
input bool xCHLHLcDrawLL = true; // Draw Lowest Low
|
||||||
|
|
||||||
|
//
|
||||||
|
// MC Inputs ...
|
||||||
|
input group "XCHLH Medium Cycle";
|
||||||
|
input group "XCHLH MC Market";
|
||||||
|
input int xCHLHMcLength = 72; // Length
|
||||||
|
input double xCHLHMcThresholdInPips = 0.3; // Threshold In Pips
|
||||||
|
input ENUM_SERIESMODE xCHLHMcHHMode = MODE_HIGH; // Highest High Calculation Method
|
||||||
|
input ENUM_SERIESMODE xCHLHMcLLMode = MODE_LOW; // Lowest Low Calculation Method
|
||||||
|
input group "XCHLH MC Style";
|
||||||
|
input int xCHLHMcDrawWidth = 1; // Draw Width
|
||||||
|
input ENUM_DRAW_TYPE xCHLHMcDrawType = DRAW_LINE; // Draw Type
|
||||||
|
input ENUM_LINE_STYLE xCHLHMcDrawStyle = STYLE_DOT; // Draw Style
|
||||||
|
input color xCHLHMcHHColor = clrLime; // Highest High Color
|
||||||
|
input color xCHLHMcLLColor = clrRed; // Lowest Low Color
|
||||||
|
input group "XCHLH MC Drawings";
|
||||||
|
input bool xCHLHMcDrawHH = true; // Draw Highest High
|
||||||
|
input bool xCHLHMcDrawLL = true; // Draw Lowest Low
|
||||||
|
|
||||||
|
//
|
||||||
|
// SC Inputs ...
|
||||||
|
input group "XCHLH Short Cycle";
|
||||||
|
input group "XCHLH SC Market";
|
||||||
|
input int xCHLHScLength = 7; // Length
|
||||||
|
input double xCHLHScThresholdInPips = 0.3; // Threshold In Pips
|
||||||
|
input ENUM_SERIESMODE xCHLHScHHMode = MODE_HIGH; // Highest High Calculation Method
|
||||||
|
input ENUM_SERIESMODE xCHLHScLLMode = MODE_LOW; // Lowest Low Calculation Method
|
||||||
|
input group "XCHLH SC Style";
|
||||||
|
input int xCHLHScDrawWidth = 1; // Draw Width
|
||||||
|
input ENUM_DRAW_TYPE xCHLHScDrawType = DRAW_LINE; // Draw Type
|
||||||
|
input ENUM_LINE_STYLE xCHLHScDrawStyle = STYLE_DOT; // Draw Style
|
||||||
|
input color xCHLHScHHColor = clrLightBlue; // Highest High Color
|
||||||
|
input color xCHLHScLLColor = clrLightSalmon; // Lowest Low Color
|
||||||
|
input group "XCHLH SC Drawings";
|
||||||
|
input bool xCHLHScDrawHH = true; // Draw Highest High
|
||||||
|
input bool xCHLHScDrawLL = true; // Draw Lowest Low
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Inputs ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Definitions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
int xCHLHHandler = INVALID_HANDLE;
|
||||||
|
double xCHLHLcHHBuffer[];
|
||||||
|
double xCHLHLcLLBuffer[];
|
||||||
|
double xCHLHMcHHBuffer[];
|
||||||
|
double xCHLHMcLLBuffer[];
|
||||||
|
double xCHLHScHHBuffer[];
|
||||||
|
double xCHLHScLLBuffer[];
|
||||||
|
double xCHLHSignalTBuffer[];
|
||||||
|
double xCHLHSignalBBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Definitions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Handler Functions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Init Oscillators ...
|
||||||
|
bool XCHLHInitHandlers()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Initialize Indicator/Oscillator Handlers ...
|
||||||
|
ResetLastError();
|
||||||
|
|
||||||
|
//
|
||||||
|
// XCHLH Handler ...
|
||||||
|
ArraySetAsSeries(xCHLHLcHHBuffer, true);
|
||||||
|
ArraySetAsSeries(xCHLHLcLLBuffer, true);
|
||||||
|
ArraySetAsSeries(xCHLHMcHHBuffer, true);
|
||||||
|
ArraySetAsSeries(xCHLHMcLLBuffer, true);
|
||||||
|
ArraySetAsSeries(xCHLHScHHBuffer, true);
|
||||||
|
ArraySetAsSeries(xCHLHScLLBuffer, true);
|
||||||
|
ArraySetAsSeries(xCHLHSignalTBuffer, true);
|
||||||
|
ArraySetAsSeries(xCHLHSignalBBuffer, true);
|
||||||
|
xCHLHHandler = iCustom(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
"x-saherelm.xchlh.oscillator",
|
||||||
|
//
|
||||||
|
// Inputs ...
|
||||||
|
//
|
||||||
|
// Signal Calculations ...
|
||||||
|
"",
|
||||||
|
xCHLHSignalType,
|
||||||
|
//
|
||||||
|
// Commons ...
|
||||||
|
"",
|
||||||
|
xCHLHDrawHotAreas,
|
||||||
|
xCHLHHotHHArrowCode,
|
||||||
|
xCHLHHotHHArrowColor,
|
||||||
|
xCHLHHotLLArrowCode,
|
||||||
|
xCHLHHotLLArrowColor,
|
||||||
|
//
|
||||||
|
// LC ...
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
xCHLHLcLength,
|
||||||
|
xCHLHLcThresholdInPips,
|
||||||
|
xCHLHLcHHMode,
|
||||||
|
xCHLHLcLLMode,
|
||||||
|
"",
|
||||||
|
xCHLHLcDrawWidth,
|
||||||
|
xCHLHLcDrawType,
|
||||||
|
xCHLHLcDrawStyle,
|
||||||
|
xCHLHLcHHColor,
|
||||||
|
xCHLHLcLLColor,
|
||||||
|
"",
|
||||||
|
xCHLHLcDrawHH,
|
||||||
|
xCHLHLcDrawLL,
|
||||||
|
//
|
||||||
|
// MC ...
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
xCHLHMcLength,
|
||||||
|
xCHLHMcThresholdInPips,
|
||||||
|
xCHLHMcHHMode,
|
||||||
|
xCHLHMcLLMode,
|
||||||
|
"",
|
||||||
|
xCHLHMcDrawWidth,
|
||||||
|
xCHLHMcDrawType,
|
||||||
|
xCHLHMcDrawStyle,
|
||||||
|
xCHLHMcHHColor,
|
||||||
|
xCHLHMcLLColor,
|
||||||
|
"",
|
||||||
|
xCHLHMcDrawHH,
|
||||||
|
xCHLHMcDrawLL,
|
||||||
|
//
|
||||||
|
// SC ...
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
xCHLHScLength,
|
||||||
|
xCHLHScThresholdInPips,
|
||||||
|
xCHLHScHHMode,
|
||||||
|
xCHLHScLLMode,
|
||||||
|
"",
|
||||||
|
xCHLHScDrawWidth,
|
||||||
|
xCHLHScDrawType,
|
||||||
|
xCHLHScDrawStyle,
|
||||||
|
xCHLHScHHColor,
|
||||||
|
xCHLHScLLColor,
|
||||||
|
"",
|
||||||
|
xCHLHScDrawHH,
|
||||||
|
xCHLHScDrawLL);
|
||||||
|
if (xCHLHHandler == INVALID_HANDLE)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
LogMessage("failed to Initialize XCHLH Indicator: " + (string)GetLastError());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = true;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Release Oscillators ...
|
||||||
|
void XCHLHReleaseHandlers()
|
||||||
|
{
|
||||||
|
IndicatorRelease(xCHLHHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handle Reading Buffers ...
|
||||||
|
void XCHLHReadBuffers(
|
||||||
|
int xCHLHItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// XCHLH LC HH Buffer ...
|
||||||
|
CopyBuffer(
|
||||||
|
xCHLHHandler,
|
||||||
|
X_XCHLH_LC_HH_LINE,
|
||||||
|
0,
|
||||||
|
xCHLHItemsPerTick,
|
||||||
|
xCHLHLcHHBuffer);
|
||||||
|
|
||||||
|
//
|
||||||
|
// XCHLH LC LL Buffer ...
|
||||||
|
CopyBuffer(
|
||||||
|
xCHLHHandler,
|
||||||
|
X_XCHLH_LC_LL_LINE,
|
||||||
|
0,
|
||||||
|
xCHLHItemsPerTick,
|
||||||
|
xCHLHLcLLBuffer);
|
||||||
|
|
||||||
|
//
|
||||||
|
// XCHLH MC HH Buffer ...
|
||||||
|
CopyBuffer(
|
||||||
|
xCHLHHandler,
|
||||||
|
X_XCHLH_MC_HH_LINE,
|
||||||
|
0,
|
||||||
|
xCHLHItemsPerTick,
|
||||||
|
xCHLHMcHHBuffer);
|
||||||
|
|
||||||
|
//
|
||||||
|
// XCHLH MC LL Buffer ...
|
||||||
|
CopyBuffer(
|
||||||
|
xCHLHHandler,
|
||||||
|
X_XCHLH_MC_LL_LINE,
|
||||||
|
0,
|
||||||
|
xCHLHItemsPerTick,
|
||||||
|
xCHLHMcLLBuffer);
|
||||||
|
|
||||||
|
//
|
||||||
|
// XCHLH SC HH Buffer ...
|
||||||
|
CopyBuffer(
|
||||||
|
xCHLHHandler,
|
||||||
|
X_XCHLH_SC_HH_LINE,
|
||||||
|
0,
|
||||||
|
xCHLHItemsPerTick,
|
||||||
|
xCHLHScHHBuffer);
|
||||||
|
|
||||||
|
//
|
||||||
|
// XCHLH SC LL Buffer ...
|
||||||
|
CopyBuffer(
|
||||||
|
xCHLHHandler,
|
||||||
|
X_XCHLH_SC_LL_LINE,
|
||||||
|
0,
|
||||||
|
xCHLHItemsPerTick,
|
||||||
|
xCHLHScLLBuffer);
|
||||||
|
|
||||||
|
//
|
||||||
|
// XCHLH Signal T Buffer ...
|
||||||
|
CopyBuffer(
|
||||||
|
xCHLHHandler,
|
||||||
|
X_XCHLH_SIGNAL_T_LINE,
|
||||||
|
0,
|
||||||
|
xCHLHItemsPerTick,
|
||||||
|
xCHLHSignalTBuffer);
|
||||||
|
|
||||||
|
//
|
||||||
|
// XCHLH Signal B Buffer ...
|
||||||
|
CopyBuffer(
|
||||||
|
xCHLHHandler,
|
||||||
|
X_XCHLH_SIGNAL_B_LINE,
|
||||||
|
0,
|
||||||
|
xCHLHItemsPerTick,
|
||||||
|
xCHLHSignalBBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Handler Funcions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Signal Related Conditions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// XCHLH Long Conditions ...
|
||||||
|
bool XCHLHHasLongConditions(
|
||||||
|
int xCHLHItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isSignalBCrossedOverLCLL = XCHLHIsSignalBCrossedOverLCLL(1);
|
||||||
|
|
||||||
|
//
|
||||||
|
result =
|
||||||
|
//
|
||||||
|
isSignalBCrossedOverLCLL
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// XCHLH Close Long Conditions ...
|
||||||
|
bool XCHLHHasLongCloseConditions(
|
||||||
|
int xCHLHItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isSignalBCrossedOverSignalT = XCHLHIsSignalBCrossedOverSignalT(1);
|
||||||
|
|
||||||
|
//
|
||||||
|
result =
|
||||||
|
//
|
||||||
|
isSignalBCrossedOverSignalT
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// XCHLH Short Conditions ...
|
||||||
|
bool XCHLHHasShortConditions(
|
||||||
|
int xCHLHItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isSignalBCrossedUnderSignalT = XCHLHIsSignalBCrossedUnderSignalT(1);
|
||||||
|
|
||||||
|
//
|
||||||
|
result =
|
||||||
|
//
|
||||||
|
isSignalBCrossedUnderSignalT
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// XCHLH Close Short Conditions ...
|
||||||
|
bool XCHLHHasShortCloseConditions(
|
||||||
|
int xCHLHItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isSignalBCrossedUnderLCLL = XCHLHIsSignalBCrossedUnderLCLL(1);
|
||||||
|
|
||||||
|
//
|
||||||
|
result =
|
||||||
|
//
|
||||||
|
isSignalBCrossedUnderLCLL
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Signal Related Conditions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START XCHLH Custom Functions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Signal B Crossed Over LC LL ...
|
||||||
|
bool XCHLHIsSignalBCrossedOverLCLL(
|
||||||
|
int bar_index // Specified Bar Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
if (!XCHLHIsValidBufferSizes(bar_index + 2))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsCrossOver(
|
||||||
|
xCHLHSignalBBuffer,
|
||||||
|
xCHLHLcLLBuffer,
|
||||||
|
bar_index);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Signal B Over LC LL ...
|
||||||
|
bool XCHLHIsSignalBOverLCLL(
|
||||||
|
int bar_index // Specified Bar Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
if (!XCHLHIsValidBufferSizes(bar_index + 2))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsOver(
|
||||||
|
xCHLHSignalBBuffer,
|
||||||
|
xCHLHLcLLBuffer,
|
||||||
|
bar_index);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Signal B Crossed Under LC LL ...
|
||||||
|
bool XCHLHIsSignalBCrossedUnderLCLL(
|
||||||
|
int bar_index // Specified Bar Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
if (!XCHLHIsValidBufferSizes(bar_index + 2))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsCrossUnder(
|
||||||
|
xCHLHSignalBBuffer,
|
||||||
|
xCHLHLcLLBuffer,
|
||||||
|
bar_index);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Signal B Under LC LL ...
|
||||||
|
bool XCHLHIsSignalBUnderLCLL(
|
||||||
|
int bar_index // Specified Bar Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
if (!XCHLHIsValidBufferSizes(bar_index + 2))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsUnder(
|
||||||
|
xCHLHSignalBBuffer,
|
||||||
|
xCHLHLcLLBuffer,
|
||||||
|
bar_index);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Signal B Crossed Over Signal T ...
|
||||||
|
bool XCHLHIsSignalBCrossedOverSignalT(
|
||||||
|
int bar_index // Specified Bar Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
if (!XCHLHIsValidBufferSizes(bar_index + 2))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsCrossOver(
|
||||||
|
xCHLHSignalBBuffer,
|
||||||
|
xCHLHSignalTBuffer,
|
||||||
|
bar_index);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Signal B Over Signal T ...
|
||||||
|
bool XCHLHIsSignalBOverSignalT(
|
||||||
|
int bar_index // Specified Bar Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
if (!XCHLHIsValidBufferSizes(bar_index + 2))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsOver(
|
||||||
|
xCHLHSignalBBuffer,
|
||||||
|
xCHLHSignalTBuffer,
|
||||||
|
bar_index);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Signal B Crossed Under Signal T ...
|
||||||
|
bool XCHLHIsSignalBCrossedUnderSignalT(
|
||||||
|
int bar_index // Specified Bar Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
if (!XCHLHIsValidBufferSizes(bar_index + 2))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsCrossUnder(
|
||||||
|
xCHLHSignalBBuffer,
|
||||||
|
xCHLHSignalTBuffer,
|
||||||
|
bar_index);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Signal B Under Signal T ...
|
||||||
|
bool XCHLHIsSignalBUnderSignalT(
|
||||||
|
int bar_index // Specified Bar Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
if (!XCHLHIsValidBufferSizes(bar_index + 2))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsUnder(
|
||||||
|
xCHLHSignalBBuffer,
|
||||||
|
xCHLHSignalTBuffer,
|
||||||
|
bar_index);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check LC and MC has Same HH ...
|
||||||
|
bool XCHLHIsLCMCHasSameHH(
|
||||||
|
int bar_index // Specified Bar Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
if (!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
double lcValue = xCHLHLcHHBuffer[bar_index];
|
||||||
|
double mcValue = xCHLHMcHHBuffer[bar_index];
|
||||||
|
|
||||||
|
//
|
||||||
|
result = lcValue == mcValue;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check LC and MC has Same LL ...
|
||||||
|
bool XCHLHIsLCMCHasSameLL(
|
||||||
|
int bar_index // Specified Bar Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
if (!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
double lcValue = xCHLHLcLLBuffer[bar_index];
|
||||||
|
double mcValue = xCHLHMcLLBuffer[bar_index];
|
||||||
|
|
||||||
|
//
|
||||||
|
result = lcValue == mcValue;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check LC and SC has Same HH ...
|
||||||
|
bool XCHLHIsLCSCHasSameHH(
|
||||||
|
int bar_index // Specified Bar Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
if (!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
double lcValue = xCHLHLcHHBuffer[bar_index];
|
||||||
|
double scValue = xCHLHScHHBuffer[bar_index];
|
||||||
|
|
||||||
|
//
|
||||||
|
result = lcValue == scValue;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check LC and SC has Same LL ...
|
||||||
|
bool XCHLHIsLCSCHasSameLL(
|
||||||
|
int bar_index // Specified Bar Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
if (!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
double lcValue = xCHLHLcLLBuffer[bar_index];
|
||||||
|
double scValue = xCHLHScLLBuffer[bar_index];
|
||||||
|
|
||||||
|
//
|
||||||
|
result = lcValue == scValue;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check MC and SC has Same HH ...
|
||||||
|
bool XCHLHIsMCSCHasSameHH(
|
||||||
|
int bar_index // Specified Bar Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
if (!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
double mcValue = xCHLHMcHHBuffer[bar_index];
|
||||||
|
double scValue = xCHLHScHHBuffer[bar_index];
|
||||||
|
|
||||||
|
//
|
||||||
|
result = mcValue == scValue;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check MC and SC has Same LL ...
|
||||||
|
bool XCHLHIsMCSCHasSameLL(
|
||||||
|
int bar_index // Specified Bar Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
if (!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
double mcValue = xCHLHMcLLBuffer[bar_index];
|
||||||
|
double scValue = xCHLHScLLBuffer[bar_index];
|
||||||
|
|
||||||
|
//
|
||||||
|
result = mcValue == scValue;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Is Same Highest Highs ...
|
||||||
|
bool XCHLHIsSameHHs(
|
||||||
|
int bar_index // Specified Bar Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
if (!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
double lcValue = xCHLHLcHHBuffer[bar_index];
|
||||||
|
double mcValue = xCHLHMcHHBuffer[bar_index];
|
||||||
|
double scValue = xCHLHScHHBuffer[bar_index];
|
||||||
|
|
||||||
|
//
|
||||||
|
result =
|
||||||
|
//
|
||||||
|
lcValue == mcValue &&
|
||||||
|
mcValue == scValue
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Is Same Lowest Lows ...
|
||||||
|
bool XCHLHIsSameLLs(
|
||||||
|
int bar_index // Specified Bar Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
if (!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
double lcValue = xCHLHLcLLBuffer[bar_index];
|
||||||
|
double mcValue = xCHLHMcLLBuffer[bar_index];
|
||||||
|
double scValue = xCHLHScLLBuffer[bar_index];
|
||||||
|
|
||||||
|
//
|
||||||
|
result =
|
||||||
|
//
|
||||||
|
lcValue == mcValue &&
|
||||||
|
mcValue == scValue
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check and Validate Buffer Sizes ...
|
||||||
|
bool XCHLHIsValidBufferSizes(
|
||||||
|
int size // Specified Min Size
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
result =
|
||||||
|
//
|
||||||
|
ArraySize(xCHLHLcHHBuffer) > size &&
|
||||||
|
ArraySize(xCHLHLcLLBuffer) > size &&
|
||||||
|
//
|
||||||
|
ArraySize(xCHLHMcHHBuffer) > size &&
|
||||||
|
ArraySize(xCHLHMcLLBuffer) > size &&
|
||||||
|
//
|
||||||
|
ArraySize(xCHLHScHHBuffer) > size &&
|
||||||
|
ArraySize(xCHLHScLLBuffer) > size;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// END XCHLH Custom Functions ...
|
||||||
|
//
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -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,424 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center MQL5 XRSI 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 ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// XRSI Oscillator Buffer Lines ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Enum Definitions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ...
|
||||||
|
//
|
||||||
|
|
||||||
|
input group "XRSI Oscillator";
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "XRSI Market";
|
||||||
|
input int xRSILength = 14; // Market Length
|
||||||
|
input ENUM_APPLIED_PRICE xRSIAppliedTo = PRICE_CLOSE; // Applied To
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "XRSI Short Entry";
|
||||||
|
input double xRSIShortEntryValue = 70; // Short Entry Level
|
||||||
|
input color xRSIShortEntryColor = clrRed; // Short Entry Level Color
|
||||||
|
input ENUM_LINE_STYLE xRSIShortEntryLineStyle = STYLE_SOLID; // Short Entry Style
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "XRSI Short Exit";
|
||||||
|
input double xRSIShortExitValue = 40; // Short Exit Level
|
||||||
|
input color xRSIShortExitColor = clrFuchsia; // Short Exit Level Color
|
||||||
|
input ENUM_LINE_STYLE xRSIShortExitLineStyle = STYLE_DOT; // Short Exit Style
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "XRSI Long Entry";
|
||||||
|
input double xRSILongEntryValue = 30; // Long Entry Level
|
||||||
|
input color xRSILongEntryColor = clrGreen; // Long Entry Level Color
|
||||||
|
input ENUM_LINE_STYLE xRSILongEntryLineStyle = STYLE_SOLID; // Long Entry Style
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "XRSI Long Exit";
|
||||||
|
input double xRSILongExitValue = 60; // Long Exit Level
|
||||||
|
input color xRSILongExitColor = clrAqua; // Long Exit Level Color
|
||||||
|
input ENUM_LINE_STYLE xRSILongExitLineStyle = STYLE_DOT; // Long Exit Style
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Inputs ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Definitions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
int xRSIHandler = INVALID_HANDLE;
|
||||||
|
double xRSIBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Definitions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Handler Functions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Init Oscillators ...
|
||||||
|
bool XRSIInitHandlers()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Initialize Indicator/Oscillator Handlers ...
|
||||||
|
ResetLastError();
|
||||||
|
|
||||||
|
//
|
||||||
|
// XRSI Handler ...
|
||||||
|
ArraySetAsSeries(xRSIBuffer, true);
|
||||||
|
xRSIHandler = iCustom(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
"x-saherelm.xrsi.oscillator",
|
||||||
|
//
|
||||||
|
// Inputs ...
|
||||||
|
//
|
||||||
|
// Market ...
|
||||||
|
"",
|
||||||
|
xRSILength,
|
||||||
|
xRSIAppliedTo,
|
||||||
|
//
|
||||||
|
// Short Entry ...
|
||||||
|
"",
|
||||||
|
xRSIShortEntryValue,
|
||||||
|
xRSIShortEntryColor,
|
||||||
|
xRSIShortEntryLineStyle,
|
||||||
|
//
|
||||||
|
// Short Exit ...
|
||||||
|
"",
|
||||||
|
xRSIShortExitValue,
|
||||||
|
xRSIShortExitColor,
|
||||||
|
xRSIShortExitLineStyle,
|
||||||
|
//
|
||||||
|
// Long Entry ...
|
||||||
|
"",
|
||||||
|
xRSILongEntryValue,
|
||||||
|
xRSILongEntryColor,
|
||||||
|
xRSILongEntryLineStyle,
|
||||||
|
//
|
||||||
|
// Long Exit ...
|
||||||
|
"",
|
||||||
|
xRSILongExitValue,
|
||||||
|
xRSILongExitColor,
|
||||||
|
xRSILongExitLineStyle
|
||||||
|
//
|
||||||
|
);
|
||||||
|
if (xRSIHandler == INVALID_HANDLE)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
LogMessage("failed to Initialize XRSI Oscillator: " + (string)GetLastError());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = true;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Release Oscillators ...
|
||||||
|
void XRSIReleaseHandlers()
|
||||||
|
{
|
||||||
|
IndicatorRelease(xRSIHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handle Reading Buffers ...
|
||||||
|
void XRSIReadBuffers(
|
||||||
|
int xRSIItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// XRSI Signal ...
|
||||||
|
CopyBuffer(
|
||||||
|
xRSIHandler,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
xRSIItemsPerTick,
|
||||||
|
xRSIBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Handler Funcions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Signal Related Conditions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// XRSI Long Conditions ...
|
||||||
|
bool XRSIHasLongConditions(
|
||||||
|
int xRSIItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// XRSI Short Conditions ...
|
||||||
|
bool XRSIHasShortConditions(
|
||||||
|
int xRSIItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Signal Related Conditions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START XRSI Custom Functions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check SC is Peak ...
|
||||||
|
bool XRSIIsPeak()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isIncreasing = IsIncreasing(
|
||||||
|
11,
|
||||||
|
3,
|
||||||
|
xRSIBuffer);
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isDecreasing = IsDecreasing(
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
xRSIBuffer);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Generating Result ...
|
||||||
|
result =
|
||||||
|
//
|
||||||
|
isIncreasing
|
||||||
|
//
|
||||||
|
&&
|
||||||
|
//
|
||||||
|
isDecreasing
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check SC is Vale ...
|
||||||
|
bool XRSIIsVale()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isIncreasing = IsIncreasing(
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
xRSIBuffer);
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isDecreasing = IsDecreasing(
|
||||||
|
11,
|
||||||
|
3,
|
||||||
|
xRSIBuffer);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Generating Result ...
|
||||||
|
result =
|
||||||
|
//
|
||||||
|
isIncreasing
|
||||||
|
//
|
||||||
|
&&
|
||||||
|
//
|
||||||
|
isDecreasing
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// RSI Value GO Up from Long Entry ...
|
||||||
|
bool XRSIIsCrossedOverLongEntry(
|
||||||
|
int bar_index // Specified Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (
|
||||||
|
bar_index <= 0 ||
|
||||||
|
!XRSIIsValidBuffersSize(bar_index + 2))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result =
|
||||||
|
xRSIBuffer[bar_index + 1] > xRSILongEntryValue &&
|
||||||
|
xRSIBuffer[bar_index + 2] <= xRSILongEntryValue;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// RSI Value GO Up from Long Exit ...
|
||||||
|
bool XRSIIsCrossedOverLongExit(
|
||||||
|
int bar_index // Specified Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (
|
||||||
|
bar_index <= 0 ||
|
||||||
|
!XRSIIsValidBuffersSize(bar_index + 2))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result =
|
||||||
|
xRSIBuffer[bar_index + 1] > xRSILongExitValue &&
|
||||||
|
xRSIBuffer[bar_index + 2] <= xRSILongExitValue;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// RSI Value Go Down Short Entry ...
|
||||||
|
bool XRSIIsCrossedUnderShortEntry(
|
||||||
|
int bar_index // Specified Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (
|
||||||
|
bar_index <= 0 ||
|
||||||
|
!XRSIIsValidBuffersSize(bar_index + 2))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result =
|
||||||
|
xRSIBuffer[bar_index + 1] < xRSIShortEntryValue &&
|
||||||
|
xRSIBuffer[bar_index + 2] >= xRSIShortEntryValue;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// RSI Value Go Down Short Exit ...
|
||||||
|
bool XRSIIsCrossedUnderShortExit(
|
||||||
|
int bar_index // Specified Index ...
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (
|
||||||
|
bar_index <= 0 ||
|
||||||
|
!XRSIIsValidBuffersSize(bar_index + 2))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result =
|
||||||
|
xRSIBuffer[bar_index + 1] < xRSIShortExitValue &&
|
||||||
|
xRSIBuffer[bar_index + 2] >= xRSIShortExitValue;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check all Buffers has valid Size ...
|
||||||
|
bool XRSIIsValidBuffersSize(
|
||||||
|
int size // the size of buffers which min size for requirements
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (
|
||||||
|
size <= 0 ||
|
||||||
|
//
|
||||||
|
ArraySize(xRSIBuffer) < size
|
||||||
|
//
|
||||||
|
)
|
||||||
|
{
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// END XRSI Custom Functions ...
|
||||||
|
//
|
||||||
@@ -0,0 +1,917 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center MQL5 XTD 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 ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// XTD Oscillator States ...
|
||||||
|
enum ENUM_X_XTD_STATES
|
||||||
|
{
|
||||||
|
X_XTD_BULLISH_CROSSED_OVER_BEARISH = 2,
|
||||||
|
X_XTD_BULLISH_OVER_BEARISH = 1,
|
||||||
|
X_XTD_NEUTURAL = 0,
|
||||||
|
X_XTD_BULLISH_UNDER_BEARISH = -1,
|
||||||
|
X_XTD_BULLISH_CROSSED_UNDER_BEARISH = -2
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// XTD Oscillator Buffer Lines ...
|
||||||
|
enum ENUM_X_XTD_BUFFER_LINES
|
||||||
|
{
|
||||||
|
X_XTD_BULLISH_POWER_LINE = 0,
|
||||||
|
X_XTD_BEARISH_POWER_LINE = 1,
|
||||||
|
X_XTD_SIGNAL_LINE = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Enum Definitions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ...
|
||||||
|
//
|
||||||
|
|
||||||
|
input group "XTD Oscillator";
|
||||||
|
input int xTDLength = 14; // Market Length
|
||||||
|
input bool xTDDrawCrosses = false; // Draw Cross Arrows
|
||||||
|
input uchar xTDBullishArrowCode = 228; // Cross Over Arrow Code
|
||||||
|
input color xTDBullishArrowColor = clrAqua; // Cross Over Arrow Color
|
||||||
|
input uchar xTDBearishArrowCode = 230; // Cross Under Arrow Code
|
||||||
|
input color xTDBearishArrowColor = clrMagenta; // Cross Under Arrow Color
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Inputs ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Definitions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
int xTDHandler = INVALID_HANDLE;
|
||||||
|
double xTDBullishBuffer[];
|
||||||
|
double xTDBearishBuffer[];
|
||||||
|
double xTDSignalBuffer[];
|
||||||
|
//
|
||||||
|
// END Definitions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Handler Functions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Init Oscillators ...
|
||||||
|
bool XTDInitHandlers()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Initialize Indicator/Oscillator Handlers ...
|
||||||
|
ResetLastError();
|
||||||
|
|
||||||
|
//
|
||||||
|
// XTD Handler ...
|
||||||
|
ArraySetAsSeries(xTDBullishBuffer, true);
|
||||||
|
ArraySetAsSeries(xTDBearishBuffer, true);
|
||||||
|
ArraySetAsSeries(xTDSignalBuffer, true);
|
||||||
|
xTDHandler = iCustom(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
"x-saherelm.xtd.oscillator",
|
||||||
|
//
|
||||||
|
// Inputs ...
|
||||||
|
xTDLength,
|
||||||
|
xTDDrawCrosses,
|
||||||
|
xTDBullishArrowCode,
|
||||||
|
xTDBullishArrowColor,
|
||||||
|
xTDBearishArrowCode,
|
||||||
|
xTDBearishArrowColor);
|
||||||
|
if (xTDHandler == INVALID_HANDLE)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
LogMessage("failed to Initialize XTD Oscillator: " + (string)GetLastError());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = true;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Release Oscillators ...
|
||||||
|
void XTDReleaseHandlers()
|
||||||
|
{
|
||||||
|
IndicatorRelease(xTDHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handle Reading Buffers ...
|
||||||
|
void XTDReadBuffers(
|
||||||
|
int xTDItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// XTD Bullish Buffer ...
|
||||||
|
CopyBuffer(
|
||||||
|
xTDHandler,
|
||||||
|
X_XTD_BULLISH_POWER_LINE,
|
||||||
|
0,
|
||||||
|
xTDItemsPerTick,
|
||||||
|
xTDBullishBuffer);
|
||||||
|
|
||||||
|
//
|
||||||
|
// XTD Bullish Buffer ...
|
||||||
|
CopyBuffer(
|
||||||
|
xTDHandler,
|
||||||
|
X_XTD_BEARISH_POWER_LINE,
|
||||||
|
0,
|
||||||
|
xTDItemsPerTick,
|
||||||
|
xTDBearishBuffer);
|
||||||
|
|
||||||
|
//
|
||||||
|
// XTD Signal Buffer ...
|
||||||
|
CopyBuffer(
|
||||||
|
xTDHandler,
|
||||||
|
X_XTD_SIGNAL_LINE,
|
||||||
|
0,
|
||||||
|
xTDItemsPerTick,
|
||||||
|
xTDSignalBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Handler Funcions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Signal Related Conditions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// XTD Long Conditions ...
|
||||||
|
bool XTDHasLongConditions(
|
||||||
|
int xTDItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isVale = XTDIsSignalVale();
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isInPeak = IsInPeak(
|
||||||
|
15,
|
||||||
|
xTDSignalBuffer);
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isSharpChanged = IsSharpChanged(
|
||||||
|
15,
|
||||||
|
1,
|
||||||
|
xTDSignalBuffer);
|
||||||
|
|
||||||
|
//
|
||||||
|
double entry = GetEntry(X_SIGNAL_LONG);
|
||||||
|
double maxPrice = GetHighestHigh(
|
||||||
|
7,
|
||||||
|
0);
|
||||||
|
double minPrice = GetLowestLow(
|
||||||
|
7,
|
||||||
|
0);
|
||||||
|
double priceDelta = maxPrice - minPrice;
|
||||||
|
double priceStep = priceDelta / 7;
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isPricePassed =
|
||||||
|
entry < maxPrice &&
|
||||||
|
maxPrice - entry < (priceDelta / 4) * 3;
|
||||||
|
|
||||||
|
//
|
||||||
|
result =
|
||||||
|
//
|
||||||
|
isVale
|
||||||
|
//
|
||||||
|
&&
|
||||||
|
//
|
||||||
|
!isInPeak
|
||||||
|
//
|
||||||
|
&&
|
||||||
|
//
|
||||||
|
!isSharpChanged
|
||||||
|
//
|
||||||
|
&&
|
||||||
|
//
|
||||||
|
isPricePassed
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// XTD Short Conditions ...
|
||||||
|
bool XTDHasShortConditions(
|
||||||
|
int xTDItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isPeak = XTDIsSignalPeak();
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isInVale = IsInVale(
|
||||||
|
15,
|
||||||
|
xTDSignalBuffer);
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isSharpChanged = IsSharpChanged(
|
||||||
|
15,
|
||||||
|
1,
|
||||||
|
xTDSignalBuffer);
|
||||||
|
|
||||||
|
//
|
||||||
|
double entry = GetEntry(X_SIGNAL_SHORT);
|
||||||
|
double maxPrice = GetHighestHigh(
|
||||||
|
7,
|
||||||
|
0);
|
||||||
|
double minPrice = GetLowestLow(
|
||||||
|
7,
|
||||||
|
0);
|
||||||
|
double priceDelta = maxPrice - minPrice;
|
||||||
|
double priceStep = priceDelta / 7;
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isPricePassed =
|
||||||
|
entry > minPrice &&
|
||||||
|
minPrice + entry > (priceDelta / 4);
|
||||||
|
|
||||||
|
//
|
||||||
|
result =
|
||||||
|
//
|
||||||
|
isPeak
|
||||||
|
//
|
||||||
|
&&
|
||||||
|
//
|
||||||
|
!isInVale
|
||||||
|
//
|
||||||
|
&&
|
||||||
|
//
|
||||||
|
!isSharpChanged
|
||||||
|
//
|
||||||
|
&&
|
||||||
|
//
|
||||||
|
isPricePassed
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Signal Related Conditions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START XTD Custom Functions ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Signal Vale ...
|
||||||
|
bool XTDIsSignalVale()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Must Decreasing ...
|
||||||
|
bool isIncreasing = IsIncreasing(
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
xTDSignalBuffer);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Must Increasing ...
|
||||||
|
bool isDecreasing = IsDecreasing(
|
||||||
|
15,
|
||||||
|
3,
|
||||||
|
xTDSignalBuffer);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Generating Result ...
|
||||||
|
result =
|
||||||
|
//
|
||||||
|
isIncreasing
|
||||||
|
//
|
||||||
|
&&
|
||||||
|
//
|
||||||
|
isDecreasing
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Signal Peak ...
|
||||||
|
bool XTDIsSignalPeak()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Must Decreasing ...
|
||||||
|
bool isIncreasing = IsIncreasing(
|
||||||
|
15,
|
||||||
|
3,
|
||||||
|
xTDSignalBuffer);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Must Increasing ...
|
||||||
|
bool isDecreasing = IsDecreasing(
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
xTDSignalBuffer);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Generating Result ...
|
||||||
|
result =
|
||||||
|
//
|
||||||
|
isIncreasing
|
||||||
|
//
|
||||||
|
&&
|
||||||
|
//
|
||||||
|
isDecreasing
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Signal Peak ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Bullish Crossed Over Bearish ...
|
||||||
|
bool XTDIsBullCrossedOverBear(
|
||||||
|
int bar_index // Specified Bar Index
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (
|
||||||
|
bar_index <= 0 ||
|
||||||
|
!XTDIsValidBuffersSize(bar_index + 1))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsCrossOver(
|
||||||
|
xTDBullishBuffer,
|
||||||
|
xTDBearishBuffer,
|
||||||
|
1);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Bullish Over Bearish ...
|
||||||
|
bool XTDIsBullOverBear(
|
||||||
|
int bar_index // Specified Bar Index
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (
|
||||||
|
bar_index <= 0 ||
|
||||||
|
!XTDIsValidBuffersSize(bar_index + 1))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsOver(
|
||||||
|
xTDBullishBuffer,
|
||||||
|
xTDBearishBuffer,
|
||||||
|
1);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Bullish Crossed Under Bearish ...
|
||||||
|
bool XTDIsBullCrossedUnderBear(
|
||||||
|
int bar_index // Specified Bar Index
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (
|
||||||
|
bar_index <= 0 ||
|
||||||
|
!XTDIsValidBuffersSize(bar_index + 1))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsCrossUnder(
|
||||||
|
xTDBullishBuffer,
|
||||||
|
xTDBearishBuffer,
|
||||||
|
1);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Bullish Under Bearish ...
|
||||||
|
bool XTDIsBullUnderBear(
|
||||||
|
int bar_index // Specified Bar Index
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (
|
||||||
|
bar_index <= 0 ||
|
||||||
|
!XTDIsValidBuffersSize(bar_index + 1))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsUnder(
|
||||||
|
xTDBullishBuffer,
|
||||||
|
xTDBearishBuffer,
|
||||||
|
1);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Signal Crossed Over Bearish ...
|
||||||
|
bool XTDIsSignalCrossedOverBear(
|
||||||
|
int bar_index // Specified Bar Index
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (
|
||||||
|
bar_index <= 0 ||
|
||||||
|
!XTDIsValidBuffersSize(bar_index + 1))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsCrossOver(
|
||||||
|
xTDSignalBuffer,
|
||||||
|
xTDBearishBuffer,
|
||||||
|
1);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Signal Over Bearish ...
|
||||||
|
bool XTDIsSignalOverBear(
|
||||||
|
int bar_index // Specified Bar Index
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (
|
||||||
|
bar_index <= 0 ||
|
||||||
|
!XTDIsValidBuffersSize(bar_index + 1))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsOver(
|
||||||
|
xTDSignalBuffer,
|
||||||
|
xTDBearishBuffer,
|
||||||
|
1);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Signal Crossed Under Bearish ...
|
||||||
|
bool XTDIsSignalCrossedUnderBear(
|
||||||
|
int bar_index // Specified Bar Index
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (
|
||||||
|
bar_index <= 0 ||
|
||||||
|
!XTDIsValidBuffersSize(bar_index + 1))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsCrossUnder(
|
||||||
|
xTDSignalBuffer,
|
||||||
|
xTDBearishBuffer,
|
||||||
|
1);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Signal Under Bearish ...
|
||||||
|
bool XTDIsSignalUnderBear(
|
||||||
|
int bar_index // Specified Bar Index
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (
|
||||||
|
bar_index <= 0 ||
|
||||||
|
!XTDIsValidBuffersSize(bar_index + 1))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsUnder(
|
||||||
|
xTDSignalBuffer,
|
||||||
|
xTDBearishBuffer,
|
||||||
|
1);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check all Buffers has valid Size ...
|
||||||
|
bool XTDIsValidBuffersSize(
|
||||||
|
int size // the size of buffers which min size for requirements
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (
|
||||||
|
size <= 0 ||
|
||||||
|
ArraySize(xTDBullishBuffer) < size ||
|
||||||
|
ArraySize(xTDBullishBuffer) < size ||
|
||||||
|
ArraySize(xTDSignalBuffer) < size)
|
||||||
|
{
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Count Signal Crossed Over Bear ...
|
||||||
|
int XTDCountSignalCrossedOverBearIndex(
|
||||||
|
int bar_index // Specified Bar Index
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||||
|
if (
|
||||||
|
bar_index <= 0 ||
|
||||||
|
count <= bar_index + 1)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Loop Through ...
|
||||||
|
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Check Cross On i Point ...
|
||||||
|
bool isCrossedOnI = XTDIsSignalCrossedOverBear(i);
|
||||||
|
if (isCrossedOnI)
|
||||||
|
{
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Count Signal Crossed Under Bear ...
|
||||||
|
int XTDCountSignalCrossedUnderBearIndex(
|
||||||
|
int bar_index // Specified Bar Index
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||||
|
if (
|
||||||
|
bar_index <= 0 ||
|
||||||
|
count <= bar_index + 1)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Loop Through ...
|
||||||
|
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Check Cross On i Point ...
|
||||||
|
bool isCrossedOnI = XTDIsSignalCrossedUnderBear(i);
|
||||||
|
if (isCrossedOnI)
|
||||||
|
{
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Count Bull Crossed Over Bear ...
|
||||||
|
int XTDCountBullCrossedOverBearIndex(
|
||||||
|
int bar_index // Specified Bar Index
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||||
|
if (
|
||||||
|
bar_index <= 0 ||
|
||||||
|
count <= bar_index + 1)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Loop Through ...
|
||||||
|
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Check Cross On i Point ...
|
||||||
|
bool isCrossedOnI = XTDIsBullCrossedOverBear(i);
|
||||||
|
if (isCrossedOnI)
|
||||||
|
{
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Count Bull Crossed Under Bear ...
|
||||||
|
int XTDCountBullCrossedUnderBearIndex(
|
||||||
|
int bar_index // Specified Bar Index
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||||
|
if (
|
||||||
|
bar_index <= 0 ||
|
||||||
|
count <= bar_index + 1)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Loop Through ...
|
||||||
|
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Check Cross On i Point ...
|
||||||
|
bool isCrossedOnI = XTDIsBullCrossedUnderBear(i);
|
||||||
|
if (isCrossedOnI)
|
||||||
|
{
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Find Last Signal Crossed Over Bear ...
|
||||||
|
int XTDFindLastSignalCrossedOverBearIndex(
|
||||||
|
int bar_index // Specified Bar Index
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = -1;
|
||||||
|
|
||||||
|
//
|
||||||
|
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||||
|
if (
|
||||||
|
bar_index <= 0 ||
|
||||||
|
count <= bar_index + 1)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Loop Through ...
|
||||||
|
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Check Cross On i Point ...
|
||||||
|
bool isCrossedOnI = XTDIsSignalCrossedOverBear(i);
|
||||||
|
if (isCrossedOnI)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
result = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Find Last Signal Crossed Onder Bear ...
|
||||||
|
int XTDFindLastSignalCrossedUnderBearIndex(
|
||||||
|
int bar_index // Specified Bar Index
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = -1;
|
||||||
|
|
||||||
|
//
|
||||||
|
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||||
|
if (
|
||||||
|
bar_index <= 0 ||
|
||||||
|
count <= bar_index + 1)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Loop Through ...
|
||||||
|
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Check Cross On i Point ...
|
||||||
|
bool isCrossedOnI = XTDIsSignalCrossedUnderBear(i);
|
||||||
|
if (isCrossedOnI)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
result = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Find Last Bull Crossed Over Bear ...
|
||||||
|
int XTDFindLastBullCrossedOverBearIndex(
|
||||||
|
int bar_index // Specified Bar Index
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = -1;
|
||||||
|
|
||||||
|
//
|
||||||
|
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||||
|
if (
|
||||||
|
bar_index <= 0 ||
|
||||||
|
count <= bar_index + 1)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Loop Through ...
|
||||||
|
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Check Cross On i Point ...
|
||||||
|
bool isCrossedOnI = XTDIsBullCrossedOverBear(i);
|
||||||
|
if (isCrossedOnI)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
result = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Find Last Bull Crossed Under Bear ...
|
||||||
|
int XTDFindLastBullCrossedUnderBearIndex(
|
||||||
|
int bar_index // Specified Bar Index
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = -1;
|
||||||
|
|
||||||
|
//
|
||||||
|
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||||
|
if (
|
||||||
|
bar_index <= 0 ||
|
||||||
|
count <= bar_index + 1)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Loop Through ...
|
||||||
|
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Check Cross On i Point ...
|
||||||
|
bool isCrossedOnI = XTDIsBullCrossedUnderBear(i);
|
||||||
|
if (isCrossedOnI)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
result = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// END XTD Custom Functions ...
|
||||||
|
//
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,82 @@
|
|||||||
|
///////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center MQL5 XTEST 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 "XTEST Provider";
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "XTEST Common";
|
||||||
|
input bool xTESTEnableProvider = true; // Enable Provider
|
||||||
|
input bool xTESTEnableAlerts = false; // Enable Events Alert
|
||||||
|
input int xTESTNumberOfItemsPerTick = 110; // Number Of items Readed In Each Tick
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "XTEST Trader";
|
||||||
|
input int xTESTMagicNumber = 16940567; // Trader MagicNumber
|
||||||
|
input int xTESTSlippage = 10; // Trader Slippage
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "XTEST Trade Management";
|
||||||
|
input bool xTESTAllowLongTrades = true; // Allow Long Trades
|
||||||
|
input bool xTESTAllowShortTrades = true; // Allow Short Trades
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "XTEST Risk Management";
|
||||||
|
//
|
||||||
|
// Trade Count ...
|
||||||
|
input int xTESTMaxAllowedTrades = 5; // Max Allowed Trades at Same Time
|
||||||
|
input int xTESTMaxAllowedSupportTrades = 3; // Max Allowed Support Trades for Single Position
|
||||||
|
//
|
||||||
|
// Trades Age ...
|
||||||
|
// 1 Day = 288
|
||||||
|
// 14 Day = 4320
|
||||||
|
input int xTESTMaxInDrawDownTradeAge = 0; // Max In DrawDown Trades Age
|
||||||
|
//
|
||||||
|
// Trade Volume ...
|
||||||
|
input double xTESTStaticVolume = 0.3; // Static Volume
|
||||||
|
input double xTESTVolumeMultiplier = 2; // Volume Multiplier
|
||||||
|
input double xTESTMaxSupportedVolumePerTradeInLots = 2.4; // Max Supported Volume Per Trade in Lot
|
||||||
|
//
|
||||||
|
// Trade Profits ...
|
||||||
|
input double xTESTMinRewardPerTradeInPips = 8; // Min Reward Per Trade In Pips
|
||||||
|
input double xTESTRiskFreeTradesInPips = 3; // Make Trades Risk Free in Pips
|
||||||
|
input int xTESTMinRewardPerSupportTradesInPips = 2; // Min Reward for Support Trade
|
||||||
|
input int xTESTSupportTradesPriceDistanceInPips = 5; // Distance Price to Open Support Trade In Pips
|
||||||
|
//
|
||||||
|
// 1000000 Pips = 100$ in EURUSD ...
|
||||||
|
input double xTESTMaxAllowedDrawDownPerTradesInPips = 0; // Max Allowed Drawdown Per Trade In Pips
|
||||||
|
input double xTESTRiskFreeRate = 0.5; // Volume Multiplier for Risk Free
|
||||||
|
//
|
||||||
|
// Account ...
|
||||||
|
input double xTESTFreeMarginFactorForOpenTrades = 0.8; // Minimum Free Marging for Open Trades
|
||||||
|
input double xTESTBalanceFactorForOpenTrades = 0.5; // Minimum Balance for Open Trades
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Inputs before Initialization ...
|
||||||
|
bool XTESTValidateInputs()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// TODO: Fix this ...
|
||||||
|
result = true;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,319 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// 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 = 14; // Period
|
||||||
|
input int xTMMaShift = 0; // Shift
|
||||||
|
input ENUM_MA_METHOD xTMMaMethod = MODE_EMA; // Method
|
||||||
|
input ENUM_APPLIED_PRICE xTMMaAppliedTo = PRICE_WEIGHTED; // 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// xTMOHandler ...
|
||||||
|
// ArraySetAsSeries(xTMOBuffer, true);
|
||||||
|
// xTMOHandler = iCustom(
|
||||||
|
// _Symbol,
|
||||||
|
// _Period,
|
||||||
|
// "x-saherelm.xma.indicator",
|
||||||
|
// //
|
||||||
|
// // Inputs ...
|
||||||
|
// xTMMaPeriod,
|
||||||
|
// xTMMaShift,
|
||||||
|
// MODE_SMA,
|
||||||
|
// PRICE_OPEN);
|
||||||
|
// if (xTMOHandler == INVALID_HANDLE)
|
||||||
|
// {
|
||||||
|
// //
|
||||||
|
// LogMessage("failed to Initialize XMA Indicator: " + (string)GetLastError());
|
||||||
|
// return result;
|
||||||
|
// }
|
||||||
|
|
||||||
|
//
|
||||||
|
result = true;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Release Indicators ...
|
||||||
|
void XTMReleaseHandlers()
|
||||||
|
{
|
||||||
|
IndicatorRelease(xTMHandler);
|
||||||
|
// IndicatorRelease(xTMOHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
//
|
||||||
|
// XTMO Buffer ...
|
||||||
|
// CopyBuffer(
|
||||||
|
// xTMOHandler,
|
||||||
|
// 0,
|
||||||
|
// 0,
|
||||||
|
// xTMItemsPerTick,
|
||||||
|
// xTMOBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// END XTM Custom Functions ...
|
||||||
|
//
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
packed at: Sunday, December 3, 2023 7:12:48 PM
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# xSaherElmEAPacks
|
||||||
|
|
||||||
|
this is a submodule repo of **xTradeBotWorkspace** which contains all published packs of SaherElm IT Center EAs.
|
||||||
|
|
||||||
|
## Maintainer
|
||||||
|
|
||||||
|
Hadi Khazaee asl
|
||||||
|
|
||||||
|
[https://www.saherelm.ir](https://www.saherelm.ir)
|
||||||
|
|
||||||
|
[hadi_khazaee_asl@yahoo.com](mailto:hadi_khazaee_asl@yahoo.com)
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,173 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center MA Indicator
|
||||||
|
// ---------------------------------------------
|
||||||
|
// saherelm implementation of above indicator ...
|
||||||
|
// this indicator uses two ma line:
|
||||||
|
// - fast ma;
|
||||||
|
// - slow ma;
|
||||||
|
//
|
||||||
|
// 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 MA Indicator"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Fast MA ...
|
||||||
|
input int maLength = 20; // MA Length
|
||||||
|
input int maShift = 0; // MA Shift
|
||||||
|
input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method
|
||||||
|
input ENUM_APPLIED_PRICE maAppliedPrice = PRICE_CLOSE; // MA Applied Price
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
#property indicator_chart_window
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_buffers 1
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_plots 1
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start Define Indicator Buffer Styles ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Fast Ma Buffer ...
|
||||||
|
#property indicator_label1 "Ma"
|
||||||
|
#property indicator_type1 DRAW_LINE
|
||||||
|
#property indicator_color1 clrYellow
|
||||||
|
#property indicator_style1 STYLE_DOT
|
||||||
|
#property indicator_width1 2
|
||||||
|
|
||||||
|
//
|
||||||
|
// End Define Indicator Buffer Styles ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Buffers ...
|
||||||
|
#define maBufferIndex 0
|
||||||
|
|
||||||
|
double maBuffer[];
|
||||||
|
//
|
||||||
|
// END Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start Event Handlers ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Initialization ...
|
||||||
|
int OnInit() {
|
||||||
|
//
|
||||||
|
// Initialize what we want ...
|
||||||
|
if (maLength <= 0) {
|
||||||
|
return INIT_PARAMETERS_INCORRECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start Set Index Buffers ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Ma ...
|
||||||
|
SetIndexBuffer(maBufferIndex, maBuffer);
|
||||||
|
SetIndexDrawBegin(maBufferIndex, maLength + 1);
|
||||||
|
//
|
||||||
|
// End Set Index Buffers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
return INIT_SUCCEEDED;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculating what we want ...
|
||||||
|
int OnCalculate(const int rates_total,
|
||||||
|
const int prev_calculated,
|
||||||
|
const datetime &time[],
|
||||||
|
const double &open[],
|
||||||
|
const double &high[],
|
||||||
|
const double &low[],
|
||||||
|
const double &close[],
|
||||||
|
const long &tick_volume[],
|
||||||
|
const long &volume[],
|
||||||
|
const int &spread[]
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
// 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, maLength);
|
||||||
|
|
||||||
|
//
|
||||||
|
// input variable, we return 0 means nothing passed ...
|
||||||
|
if (rates_total < maxLength) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// found which candles calculated before ...
|
||||||
|
limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// this is the main loop of calculations, for each bar index ...
|
||||||
|
for (int i = limit - 1; i >= 0; i--) {
|
||||||
|
//
|
||||||
|
// Start Calculation here ...
|
||||||
|
// i is bar_index ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate Ma ...
|
||||||
|
CalculateMa(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return rates_total;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Event Handlers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Functions ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Calculating Ma ...
|
||||||
|
void CalculateMa(
|
||||||
|
const int &bar_index
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
// Calculating Fast Ma ...
|
||||||
|
double ma = iMA(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
maLength,
|
||||||
|
maShift,
|
||||||
|
maMethod,
|
||||||
|
maAppliedPrice,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
maBuffer[bar_index] = ma;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Functions ...
|
||||||
|
//
|
||||||
@@ -0,0 +1,294 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center XRange Indicator
|
||||||
|
// ---------------------------------------------
|
||||||
|
// saherelm implementation of above 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 XRange Indicator"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ...
|
||||||
|
//
|
||||||
|
input int marketLength = 14;
|
||||||
|
//
|
||||||
|
// END Inputs ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
#property indicator_chart_window
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_buffers 3
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_plots 3
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start Define Indicator Buffer Styles ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Highest High Buffer ...
|
||||||
|
#property indicator_type1 DRAW_LINE
|
||||||
|
#property indicator_color1 clrGreen
|
||||||
|
#property indicator_style1 STYLE_DOT
|
||||||
|
#property indicator_width1 1
|
||||||
|
|
||||||
|
//
|
||||||
|
// Lowest Low Buffer ...
|
||||||
|
#property indicator_type2 DRAW_LINE
|
||||||
|
#property indicator_color2 clrRed
|
||||||
|
#property indicator_style2 STYLE_DOT
|
||||||
|
#property indicator_width2 1
|
||||||
|
|
||||||
|
//
|
||||||
|
// Middle Buffer ...
|
||||||
|
#property indicator_type3 DRAW_LINE
|
||||||
|
#property indicator_color3 clrYellow
|
||||||
|
#property indicator_style3 STYLE_DASH
|
||||||
|
#property indicator_width3 1
|
||||||
|
//
|
||||||
|
// End Define Indicator Buffer Styles ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Buffers ...
|
||||||
|
//
|
||||||
|
#define highestHighBufferIndex 0
|
||||||
|
#define lowestLowBufferIndex 1
|
||||||
|
#define middleBufferIndex 2
|
||||||
|
|
||||||
|
//
|
||||||
|
double highestHighBuffer[];
|
||||||
|
double lowestLowBuffer[];
|
||||||
|
double middleBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
datetime startTime;
|
||||||
|
//
|
||||||
|
// END Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start Event Handlers ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Initialization ...
|
||||||
|
int OnInit() {
|
||||||
|
//
|
||||||
|
// Initialize what we want ...
|
||||||
|
if (
|
||||||
|
marketLength <= 0
|
||||||
|
) {
|
||||||
|
return INIT_PARAMETERS_INCORRECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
string hhLbl = StringConcatenate(
|
||||||
|
"XR HH(", marketLength, ")"
|
||||||
|
);
|
||||||
|
SetIndexBuffer(highestHighBufferIndex, highestHighBuffer);
|
||||||
|
SetIndexLabel(highestHighBufferIndex, hhLbl);
|
||||||
|
|
||||||
|
//
|
||||||
|
string llLbl = StringConcatenate(
|
||||||
|
"XR LL(", marketLength, ")"
|
||||||
|
);
|
||||||
|
SetIndexBuffer(lowestLowBufferIndex, lowestLowBuffer);
|
||||||
|
SetIndexLabel(lowestLowBufferIndex, llLbl);
|
||||||
|
|
||||||
|
//
|
||||||
|
string midLbl = StringConcatenate(
|
||||||
|
"XR Mid(", marketLength, ")"
|
||||||
|
);
|
||||||
|
SetIndexBuffer(middleBufferIndex, middleBuffer);
|
||||||
|
SetIndexLabel(middleBufferIndex, midLbl);
|
||||||
|
|
||||||
|
//
|
||||||
|
return INIT_SUCCEEDED;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculating what we want ...
|
||||||
|
int OnCalculate(const int rates_total,
|
||||||
|
const int prev_calculated,
|
||||||
|
const datetime &time[],
|
||||||
|
const double &open[],
|
||||||
|
const double &high[],
|
||||||
|
const double &low[],
|
||||||
|
const double &close[],
|
||||||
|
const long &tick_volume[],
|
||||||
|
const long &volume[],
|
||||||
|
const int &spread[]
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
// 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, marketLength);
|
||||||
|
|
||||||
|
//
|
||||||
|
// input variable, we return 0 means nothing passed ...
|
||||||
|
if (rates_total < maxLength) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// found which candles calculated before ...
|
||||||
|
limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// this is the main loop of calculations, for each bar index ...
|
||||||
|
for (int i = limit - 1; i >= 0; i--) {
|
||||||
|
//
|
||||||
|
// Start Calculation here ...
|
||||||
|
// i is bar_index ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculations ...
|
||||||
|
CalculateBuffers(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return rates_total;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Event Handlers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Functions ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Calculations ...
|
||||||
|
void CalculateBuffers(
|
||||||
|
const int &bar_index
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
// Retrieve Bar Time ...
|
||||||
|
datetime barTime = iTime(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (startTime == 0) {
|
||||||
|
//
|
||||||
|
startTime = barTime;
|
||||||
|
SetIndicatorBuffersNone(bar_index);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
int startBarIndex = iBarShift(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
startTime
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
int startDistance = startBarIndex - bar_index;
|
||||||
|
if (startDistance < marketLength) {
|
||||||
|
//
|
||||||
|
SetIndicatorBuffersNone(bar_index);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Highest High ...
|
||||||
|
int hhIdx = iHighest(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
MODE_HIGH,
|
||||||
|
marketLength,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
double hh = iHigh(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
hhIdx
|
||||||
|
);
|
||||||
|
highestHighBuffer[bar_index] = hh;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Lowest Low ...
|
||||||
|
int llIdx = iLowest(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
MODE_LOW,
|
||||||
|
marketLength,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
double ll = iLow(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
llIdx
|
||||||
|
);
|
||||||
|
lowestLowBuffer[bar_index] = ll;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Middle Buffer ...
|
||||||
|
double mid = (hh + ll) / 2;
|
||||||
|
middleBuffer[bar_index] = mid;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Reset Start Time ...
|
||||||
|
startTime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
void SetIndicatorBuffersNone(
|
||||||
|
const int bar_index
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
int lastBarIndex = bar_index + 1;
|
||||||
|
|
||||||
|
//
|
||||||
|
double lastHighestHigh;
|
||||||
|
double lastLowestLow;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Highest High ...
|
||||||
|
if (ArraySize(highestHighBuffer) > lastBarIndex) {
|
||||||
|
lastHighestHigh = highestHighBuffer[lastBarIndex];
|
||||||
|
} else {
|
||||||
|
lastHighestHigh = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Lowest Low ...
|
||||||
|
if (ArraySize(lowestLowBuffer) > lastBarIndex) {
|
||||||
|
lastLowestLow = lowestLowBuffer[lastBarIndex];
|
||||||
|
} else {
|
||||||
|
lastLowestLow = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
highestHighBuffer[bar_index] = lastHighestHigh;
|
||||||
|
lowestLowBuffer[bar_index] = lastLowestLow;
|
||||||
|
|
||||||
|
//
|
||||||
|
double mid = (lastHighestHigh + lastLowestLow) / 2;
|
||||||
|
middleBuffer[bar_index] = mid;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Functions ...
|
||||||
|
//
|
||||||
@@ -0,0 +1,275 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center Trend Power Indicator
|
||||||
|
// ---------------------------------------------
|
||||||
|
// saherelm implementation of above indicator ...
|
||||||
|
// this indicator uses two ma line:
|
||||||
|
// - fast ma;
|
||||||
|
// - slow ma;
|
||||||
|
//
|
||||||
|
// 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 MA Indicator"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ...
|
||||||
|
//
|
||||||
|
input int marketLength = 7; // Market Length
|
||||||
|
//
|
||||||
|
// END Inputs ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
#property indicator_separate_window
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_plots 3
|
||||||
|
#property indicator_buffers 3
|
||||||
|
#property indicator_minimum 0
|
||||||
|
#property indicator_maximum 100
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_levelcolor clrGray
|
||||||
|
#property indicator_levelstyle STYLE_DOT
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start Define Indicator Buffer Styles ...
|
||||||
|
//
|
||||||
|
#property indicator_type1 DRAW_HISTOGRAM
|
||||||
|
#property indicator_color1 clrLime
|
||||||
|
#property indicator_style1 STYLE_DOT
|
||||||
|
#property indicator_width1 1
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_type2 DRAW_HISTOGRAM
|
||||||
|
#property indicator_color2 clrRed
|
||||||
|
#property indicator_style2 STYLE_DOT
|
||||||
|
#property indicator_width2 1
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_type3 DRAW_LINE
|
||||||
|
#property indicator_color3 clrYellow
|
||||||
|
#property indicator_style3 STYLE_DOT
|
||||||
|
#property indicator_width3 1
|
||||||
|
//
|
||||||
|
// End Define Indicator Buffer Styles ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Buffers ...
|
||||||
|
#define powerUpBufferIndex 0
|
||||||
|
#define powerDownBufferIndex 1
|
||||||
|
#define signalBufferIndex 2
|
||||||
|
|
||||||
|
double powerUpBuffer[];
|
||||||
|
double powerDownBuffer[];
|
||||||
|
double signalBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#include "../Libraries/x-saherelm.lib.mq4"
|
||||||
|
//
|
||||||
|
// END Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start Event Handlers ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Initialization ...
|
||||||
|
int OnInit() {
|
||||||
|
//
|
||||||
|
// Initialize what we want ...
|
||||||
|
if (marketLength <= 0) {
|
||||||
|
return INIT_PARAMETERS_INCORRECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
SetLevelValue(0, 0.0);
|
||||||
|
IndicatorSetString(INDICATOR_LEVELTEXT,0,"");
|
||||||
|
|
||||||
|
//
|
||||||
|
SetLevelValue(1, 20.0);
|
||||||
|
IndicatorSetString(INDICATOR_LEVELTEXT,1,"");
|
||||||
|
|
||||||
|
//
|
||||||
|
SetLevelValue(2, 50);
|
||||||
|
IndicatorSetString(INDICATOR_LEVELTEXT,2,"");
|
||||||
|
|
||||||
|
//
|
||||||
|
SetLevelValue(3, 100);
|
||||||
|
IndicatorSetString(INDICATOR_LEVELTEXT,3,"");
|
||||||
|
|
||||||
|
//
|
||||||
|
string pUpLbl = StringConcatenate(
|
||||||
|
"P Up (", marketLength, ")"
|
||||||
|
);
|
||||||
|
SetIndexLabel(powerUpBufferIndex, pUpLbl);
|
||||||
|
SetIndexBuffer(powerUpBufferIndex, powerUpBuffer);
|
||||||
|
SetIndexDrawBegin(powerUpBufferIndex, marketLength + 1);
|
||||||
|
|
||||||
|
//
|
||||||
|
string pDownLbl = StringConcatenate(
|
||||||
|
"P Down (", marketLength, ")"
|
||||||
|
);
|
||||||
|
SetIndexLabel(powerDownBufferIndex, pDownLbl);
|
||||||
|
SetIndexBuffer(powerDownBufferIndex, powerDownBuffer);
|
||||||
|
SetIndexDrawBegin(powerDownBufferIndex, marketLength + 1);
|
||||||
|
|
||||||
|
//
|
||||||
|
string pSignalLbl = StringConcatenate(
|
||||||
|
"P Signal (", marketLength, ")"
|
||||||
|
);
|
||||||
|
SetIndexLabel(signalBufferIndex, pSignalLbl);
|
||||||
|
SetIndexBuffer(signalBufferIndex, signalBuffer);
|
||||||
|
SetIndexDrawBegin(signalBufferIndex, marketLength + 1);
|
||||||
|
|
||||||
|
//
|
||||||
|
// here we specify logging enabled or not ...
|
||||||
|
enableLogging = true;
|
||||||
|
|
||||||
|
//
|
||||||
|
// this is a Tag which attached to our Logger ...
|
||||||
|
logTag = "X_TPW_OSC";
|
||||||
|
|
||||||
|
//
|
||||||
|
return INIT_SUCCEEDED;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculating what we want ...
|
||||||
|
int OnCalculate(const int rates_total,
|
||||||
|
const int prev_calculated,
|
||||||
|
const datetime &time[],
|
||||||
|
const double &open[],
|
||||||
|
const double &high[],
|
||||||
|
const double &low[],
|
||||||
|
const double &close[],
|
||||||
|
const long &tick_volume[],
|
||||||
|
const long &volume[],
|
||||||
|
const int &spread[]
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
// 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, marketLength);
|
||||||
|
|
||||||
|
//
|
||||||
|
// input variable, we return 0 means nothing passed ...
|
||||||
|
if (rates_total < maxLength) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// found which candles calculated before ...
|
||||||
|
limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// this is the main loop of calculations, for each bar index ...
|
||||||
|
for (int i = limit - 1; i >= 0; i--) {
|
||||||
|
//
|
||||||
|
// Start Calculation here ...
|
||||||
|
// i is bar_index ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate Buffers ...
|
||||||
|
CalculateBuffers(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return rates_total;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Event Handlers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Functions ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Calculating Ma ...
|
||||||
|
void CalculateBuffers(
|
||||||
|
const int &bar_index
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
double powerUp = 0;
|
||||||
|
double powerDown = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
int dailyCount = GetDailyCandleCount();
|
||||||
|
double dailyHH = GetMarketHighestHigh(
|
||||||
|
bar_index,
|
||||||
|
dailyCount
|
||||||
|
);
|
||||||
|
double dailyLL = GetMarketLowestLow(
|
||||||
|
bar_index,
|
||||||
|
dailyCount
|
||||||
|
);
|
||||||
|
double dailyDiff = dailyHH - dailyLL;
|
||||||
|
double rate = dailyDiff / 100;
|
||||||
|
|
||||||
|
//
|
||||||
|
for (int i = bar_index; i < bar_index + marketLength; i++) {
|
||||||
|
//
|
||||||
|
XOHCL c = GetCandleModel(i);
|
||||||
|
|
||||||
|
//
|
||||||
|
double cRange =
|
||||||
|
MathAbs(c.open - c.close)
|
||||||
|
// MathAbs(c.high - c.low)
|
||||||
|
;
|
||||||
|
bool isBullish = c.open < c.close;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (isBullish) {
|
||||||
|
powerUp += cRange;
|
||||||
|
} else {
|
||||||
|
powerDown += cRange;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
powerUp = powerUp / rate;
|
||||||
|
powerDown = powerDown / rate;
|
||||||
|
|
||||||
|
//
|
||||||
|
int doubleMarketLength = (marketLength * 2);
|
||||||
|
double ema = GetMA(
|
||||||
|
bar_index,
|
||||||
|
doubleMarketLength,
|
||||||
|
0,
|
||||||
|
MODE_EMA,
|
||||||
|
PRICE_WEIGHTED
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double emaRate = GetMarketHighestHigh(bar_index, doubleMarketLength) - GetMarketLowestLow(bar_index, doubleMarketLength) / 100;
|
||||||
|
|
||||||
|
//
|
||||||
|
double signal = (ema / 100) * rate;
|
||||||
|
double signalAddition = MathMin(powerUp, powerDown);
|
||||||
|
|
||||||
|
//
|
||||||
|
powerUpBuffer[bar_index] = powerUp;
|
||||||
|
powerDownBuffer[bar_index] = powerDown;
|
||||||
|
signalBuffer[bar_index] = signal + signalAddition;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Functions ...
|
||||||
|
//
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center MQL4 Dialog Library
|
||||||
|
// ---------------------------------------------
|
||||||
|
// saherelm useful tools and definitions
|
||||||
|
// for handling dialogs ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Maintainer:
|
||||||
|
// ------------
|
||||||
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
#property library
|
||||||
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||||
|
#property link "https://www.saherelm.ir"
|
||||||
|
#property version "1.00"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// Includes Logger library ...
|
||||||
|
// #include "../Libraries/x-saherelm.lib.mq4"
|
||||||
|
#include "../Libraries/x-saherelm.log.lib.mq4"
|
||||||
|
|
||||||
|
//
|
||||||
|
#include <Controls\Dialog.mqh>
|
||||||
|
|
||||||
|
//
|
||||||
|
CAppDialog AppWindow;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Prefix for Created Dialogs ...
|
||||||
|
string windowPrefix = "XWinD";
|
||||||
|
|
||||||
|
//
|
||||||
|
// Generate a random number for dialogs ...
|
||||||
|
int GenerateWindowNumber() {
|
||||||
|
//
|
||||||
|
int result = MathRand() + 1;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Generate a Window Prefix ID ...
|
||||||
|
string GenerateWindowID() {
|
||||||
|
//
|
||||||
|
string result = windowPrefix;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Generate INT ID ...
|
||||||
|
int idNum = GenerateWindowNumber();
|
||||||
|
|
||||||
|
//
|
||||||
|
result += "_" + StringConcatenate(idNum);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool CreateDialog(
|
||||||
|
const string title = ""
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
// string windowID = GenerateWindowID();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Try to Create Window ...
|
||||||
|
bool result = AppWindow.Create(
|
||||||
|
0,
|
||||||
|
title,
|
||||||
|
0,
|
||||||
|
20,
|
||||||
|
20,
|
||||||
|
360,
|
||||||
|
324
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (result) {
|
||||||
|
AppWindow.Run();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
void DestroyDialog(const int reason) {
|
||||||
|
AppWindow.Destroy(reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Apply Chart Event on Created Window ...
|
||||||
|
void DialogChartEvent(
|
||||||
|
const int id, // event ID
|
||||||
|
const long& lparam, // event parameter of the long type
|
||||||
|
const double& dparam, // event parameter of the double type
|
||||||
|
const string& sparam // event parameter of the string type
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
AppWindow.ChartEvent(
|
||||||
|
id,
|
||||||
|
lparam,
|
||||||
|
dparam,
|
||||||
|
sparam
|
||||||
|
);
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,450 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center MQL4 Indicator Global Library
|
||||||
|
// ---------------------------------------------------
|
||||||
|
// saherelm useful tools and definitions ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Maintainer:
|
||||||
|
// ------------
|
||||||
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
#property library
|
||||||
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||||
|
#property link "https://www.saherelm.ir"
|
||||||
|
#property version "1.00"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// Includes library ...
|
||||||
|
#include "../Libraries/x-saherelm.lib.mq4"
|
||||||
|
|
||||||
|
//
|
||||||
|
// Includes Models library ...
|
||||||
|
#include "../Libraries/x-saherelm.models.lib.mq4"
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Global Requirement Functions ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Reading specified Buffer From ADX Indicator ...
|
||||||
|
double ReadXMABuffer(
|
||||||
|
const int bar_index,
|
||||||
|
const int buffer_index,
|
||||||
|
//
|
||||||
|
const int marketLen,
|
||||||
|
//
|
||||||
|
const double stp,
|
||||||
|
const double mxm,
|
||||||
|
//
|
||||||
|
const int shortCycleMult,
|
||||||
|
const int mediumCycleMult,
|
||||||
|
const int longCycleMult
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
string xmaIndicatorName = "x-saherelm.x.xma";
|
||||||
|
|
||||||
|
//
|
||||||
|
double result = iCustom(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
xmaIndicatorName,
|
||||||
|
//
|
||||||
|
// Inputs ...
|
||||||
|
marketLen,
|
||||||
|
stp,
|
||||||
|
mxm,
|
||||||
|
shortCycleMult,
|
||||||
|
mediumCycleMult,
|
||||||
|
longCycleMult,
|
||||||
|
MODE_SMA,
|
||||||
|
//
|
||||||
|
buffer_index,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Reading specified Buffer from XHL Indicator ...
|
||||||
|
double ReadXHLBuffer(
|
||||||
|
const int bar_index,
|
||||||
|
const int buffer_index,
|
||||||
|
//
|
||||||
|
const int marketLen,
|
||||||
|
//
|
||||||
|
const int shortCycleMult,
|
||||||
|
const int mediumCycleMult,
|
||||||
|
const int longCycleMult
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
string xhlIndicatorName = "x-saherelm.x.hl";
|
||||||
|
|
||||||
|
//
|
||||||
|
double result = iCustom(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
xhlIndicatorName,
|
||||||
|
//
|
||||||
|
// Inputs ...
|
||||||
|
marketLen,
|
||||||
|
shortCycleMult,
|
||||||
|
mediumCycleMult,
|
||||||
|
longCycleMult,
|
||||||
|
MODE_SMA,
|
||||||
|
//
|
||||||
|
buffer_index,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Reading ADX Values ...
|
||||||
|
double ReadADX(
|
||||||
|
const int bar_index,
|
||||||
|
const int marketLen,
|
||||||
|
const int mult
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
double result;
|
||||||
|
|
||||||
|
//
|
||||||
|
int period = marketLen * mult;
|
||||||
|
|
||||||
|
//
|
||||||
|
result = iADX(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
period,
|
||||||
|
PRICE_CLOSE,
|
||||||
|
MODE_MAIN,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Reading Pivot States ...
|
||||||
|
XPvtState GetPVTState(
|
||||||
|
const int bar_index,
|
||||||
|
const int marketLen
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
XPvtState result = {};
|
||||||
|
|
||||||
|
//
|
||||||
|
double hh = GetMarketHighestHigh(
|
||||||
|
bar_index,
|
||||||
|
marketLen
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double ho = GetMarketHighestOpen(
|
||||||
|
bar_index,
|
||||||
|
marketLen
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double hc = GetMarketHighestClose(
|
||||||
|
bar_index,
|
||||||
|
marketLen
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double hl = GetMarketHighestLow(
|
||||||
|
bar_index,
|
||||||
|
marketLen
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double ll = GetMarketLowestLow(
|
||||||
|
bar_index,
|
||||||
|
marketLen
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double lo = GetMarketLowestOpen(
|
||||||
|
bar_index,
|
||||||
|
marketLen
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double lc = GetMarketLowestClose(
|
||||||
|
bar_index,
|
||||||
|
marketLen
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double lh = GetMarketLowestHigh(
|
||||||
|
bar_index,
|
||||||
|
marketLen
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Filling Result ...
|
||||||
|
//
|
||||||
|
result.hh = hh;
|
||||||
|
result.ho = ho;
|
||||||
|
result.hc = hc;
|
||||||
|
result.hl = hl;
|
||||||
|
|
||||||
|
//
|
||||||
|
result.ll = ll;
|
||||||
|
result.lo = lo;
|
||||||
|
result.lc = lc;
|
||||||
|
result.lh = lh;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate XRange from Market ...
|
||||||
|
static XRState lastXRState;
|
||||||
|
XRState GetXRange(
|
||||||
|
const int bar_index,
|
||||||
|
const int rangeMarketLength
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
XRState result = {};
|
||||||
|
|
||||||
|
//
|
||||||
|
datetime barTime = iTime(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
int marketBarIndex = bar_index + rangeMarketLength;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Highest High ...
|
||||||
|
//
|
||||||
|
int hhIdx = iHighest(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
MODE_HIGH,
|
||||||
|
marketBarIndex,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double hh = iHigh(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
hhIdx
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Lowest Low ...
|
||||||
|
//
|
||||||
|
int llIdx = iLowest(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
MODE_LOW,
|
||||||
|
marketBarIndex,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double ll = iLow(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
llIdx
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (lastXRState.start == 0) {
|
||||||
|
//
|
||||||
|
lastXRState.start = barTime;
|
||||||
|
lastXRState.length = rangeMarketLength;
|
||||||
|
|
||||||
|
//
|
||||||
|
lastXRState.hh = hh;
|
||||||
|
lastXRState.ll = ll;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Middle ...
|
||||||
|
double mid = (hh + ll) / 2;
|
||||||
|
lastXRState.mid = mid;
|
||||||
|
} else {
|
||||||
|
//
|
||||||
|
int startBarIndex = iBarShift(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
lastXRState.start
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (startBarIndex - bar_index >= rangeMarketLength) {
|
||||||
|
//
|
||||||
|
lastXRState.start = barTime;
|
||||||
|
lastXRState.length = rangeMarketLength;
|
||||||
|
|
||||||
|
//
|
||||||
|
lastXRState.hh = hh;
|
||||||
|
lastXRState.ll = ll;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Middle ...
|
||||||
|
double mid = (hh + ll) / 2;
|
||||||
|
lastXRState.mid = mid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = lastXRState;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Reading XTPowState from Indicatoe ...
|
||||||
|
XTPOWState GetXTPowState(
|
||||||
|
const int bar_index,
|
||||||
|
const int marketLen
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
XTPOWState result = {};
|
||||||
|
|
||||||
|
//
|
||||||
|
//
|
||||||
|
double powerUp = 0;
|
||||||
|
double powerDown = 0;
|
||||||
|
double signal = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
string indicatorName = "x-saherelm.xtpow";
|
||||||
|
|
||||||
|
//
|
||||||
|
int pUpIndex = 0;
|
||||||
|
int pDownIndex = 1;
|
||||||
|
int signalIndex = 2;
|
||||||
|
|
||||||
|
//
|
||||||
|
powerUp = iCustom(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
indicatorName,
|
||||||
|
//
|
||||||
|
marketLen,
|
||||||
|
//
|
||||||
|
pUpIndex,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
powerDown = iCustom(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
indicatorName,
|
||||||
|
//
|
||||||
|
marketLen,
|
||||||
|
//
|
||||||
|
pDownIndex,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
signal = iCustom(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
indicatorName,
|
||||||
|
//
|
||||||
|
marketLen,
|
||||||
|
//
|
||||||
|
signalIndex,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
result.signal = signal;
|
||||||
|
result.powerUp = powerUp;
|
||||||
|
result.powerDown = powerDown;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Reading XRState From Indicator ...
|
||||||
|
XRState ReadXRange(
|
||||||
|
const int bar_index,
|
||||||
|
const int marketLen
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
XRState result = {};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Define Buffer Indexes ...
|
||||||
|
int hhBufferIndex = 0;
|
||||||
|
int llBufferIndex = 1;
|
||||||
|
int midBufferIndex = 2;
|
||||||
|
|
||||||
|
//
|
||||||
|
string indicatorName = "x-saherelm.xrange";
|
||||||
|
|
||||||
|
//
|
||||||
|
// Read Values From XRange Indicator ...
|
||||||
|
|
||||||
|
//
|
||||||
|
double hh = iCustom(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
indicatorName,
|
||||||
|
//
|
||||||
|
// Inputs ...
|
||||||
|
marketLen,
|
||||||
|
//
|
||||||
|
hhBufferIndex, // Buffer Index ...
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double ll = iCustom(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
indicatorName,
|
||||||
|
//
|
||||||
|
// Inputs ...
|
||||||
|
marketLen,
|
||||||
|
//
|
||||||
|
llBufferIndex, // Buffer Index ...
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double mid = iCustom(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
indicatorName,
|
||||||
|
//
|
||||||
|
// Inputs ...
|
||||||
|
marketLen,
|
||||||
|
//
|
||||||
|
midBufferIndex, // Buffer Index ...
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Filling Result ...
|
||||||
|
result.hh = hh;
|
||||||
|
result.ll = ll;
|
||||||
|
result.mid = mid;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Indicator Reading Data ...
|
||||||
|
//
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,91 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center MQL4 Draw Global Library
|
||||||
|
// ---------------------------------------------
|
||||||
|
// saherelm useful tools and definitions ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Maintainer:
|
||||||
|
// ------------
|
||||||
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
#property library
|
||||||
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||||
|
#property link "https://www.saherelm.ir"
|
||||||
|
#property version "1.00"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// Log Tag ...
|
||||||
|
static string logTag = "";
|
||||||
|
|
||||||
|
//
|
||||||
|
// Enable or Disable Logging ...
|
||||||
|
static bool enableLogging = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start Log Messages ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Logging a Message, specified for this EA ...
|
||||||
|
// using provided LogTag ...
|
||||||
|
void LogMessage(string message) {
|
||||||
|
//
|
||||||
|
if (!enableLogging) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
Print(logTag, " > ", message);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// this used for logging series ...
|
||||||
|
void LogSeries(
|
||||||
|
double &series[], // which series to Log ...
|
||||||
|
int length = 0, // number of items to Log, 0 means all ...
|
||||||
|
int skip = 0 // number of items which skip before logging ...
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
string msg = "";
|
||||||
|
|
||||||
|
//
|
||||||
|
int seriesSize = ArraySize(series);
|
||||||
|
if (
|
||||||
|
skip < 0
|
||||||
|
|| length < 0
|
||||||
|
|| seriesSize == 0
|
||||||
|
|| skip > seriesSize
|
||||||
|
|| skip + length > seriesSize
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
length = length == 0 ?
|
||||||
|
seriesSize :
|
||||||
|
length;
|
||||||
|
int start = skip > 1 ?
|
||||||
|
skip - 1 :
|
||||||
|
skip == 1 ?
|
||||||
|
1 :
|
||||||
|
0;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Loop through series items ...
|
||||||
|
for (int i = start; i < start + length; i++) {
|
||||||
|
//
|
||||||
|
msg += StringConcatenate(
|
||||||
|
"i[", i, "]: ", series[i], ", "
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
LogMessage(msg);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// End Log Messages ...
|
||||||
|
//
|
||||||
|
|
||||||
@@ -0,0 +1,155 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center MQL4 Models Global Library
|
||||||
|
// ---------------------------------------------
|
||||||
|
// saherelm useful tools and definitions ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Maintainer:
|
||||||
|
// ------------
|
||||||
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
#property library
|
||||||
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||||
|
#property link "https://www.saherelm.ir"
|
||||||
|
#property version "1.00"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// START STATIC Variables ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
static int totalSignals = 0;
|
||||||
|
static int totalLongSignals = 0;
|
||||||
|
static int totalShortSignals = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
static double initialBalance = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
static int countedBars = 0;
|
||||||
|
static bool isNewBar = false;
|
||||||
|
static bool isNewDay = false;
|
||||||
|
static bool isNewHour = false;
|
||||||
|
//
|
||||||
|
// END STATIC Variables ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start Models ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Signal Providers ...
|
||||||
|
enum ENUM_X_SIGNAL_PROVIDER {
|
||||||
|
X_UNKNOWN_PROVIDER,
|
||||||
|
X_XXX_PROVIDER,
|
||||||
|
X_XR_PROVIDER,
|
||||||
|
X_XTPW_PROVIDER
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// these are different signal types ...
|
||||||
|
enum ENUM_X_SIGNAL_TYPE {
|
||||||
|
X_SIGNAL_NONE,
|
||||||
|
X_SIGNAL_LONG,
|
||||||
|
X_SIGNAL_SHORT,
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Model Market Highs and Lows ...
|
||||||
|
struct XPvtState {
|
||||||
|
//
|
||||||
|
double hh;
|
||||||
|
double ho;
|
||||||
|
double hc;
|
||||||
|
double hl;
|
||||||
|
|
||||||
|
//
|
||||||
|
double ll;
|
||||||
|
double lo;
|
||||||
|
double lc;
|
||||||
|
double lh;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// we Model each signals as this type ...
|
||||||
|
struct XSignal {
|
||||||
|
//
|
||||||
|
// Signal Symbol ...
|
||||||
|
string symbol;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal Type ...
|
||||||
|
ENUM_X_SIGNAL_TYPE type;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal ID ...
|
||||||
|
int id;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal Ticket Number, when Opening Trade ...
|
||||||
|
int ticket;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal Provider ...
|
||||||
|
ENUM_X_SIGNAL_PROVIDER provider;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Target Point ...
|
||||||
|
double tp;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Stop Loss ...
|
||||||
|
double sl;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal Entry Price ...
|
||||||
|
double entry;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signalling Time ...
|
||||||
|
datetime time;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal Comments ...
|
||||||
|
string comment;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal TAG ...
|
||||||
|
string tag;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// this is Signal Request Response model ...
|
||||||
|
struct XSignalRequest {
|
||||||
|
bool hasSignal;
|
||||||
|
XSignal signal;
|
||||||
|
ENUM_X_SIGNAL_TYPE type;
|
||||||
|
ENUM_X_SIGNAL_PROVIDER provider;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
struct XRState {
|
||||||
|
//
|
||||||
|
datetime start;
|
||||||
|
int length;
|
||||||
|
|
||||||
|
//
|
||||||
|
double hh;
|
||||||
|
double ll;
|
||||||
|
double mid;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
struct XTPOWState {
|
||||||
|
//
|
||||||
|
double powerUp;
|
||||||
|
double powerDown;
|
||||||
|
|
||||||
|
//
|
||||||
|
double signal;
|
||||||
|
};
|
||||||
|
//
|
||||||
|
// End Models ...
|
||||||
|
//
|
||||||
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
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1 @@
|
|||||||
|
packed at: Tue Oct 10 2023 01:05:43 GMT+0330 (Iran Standard Time)
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -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 ...
|
||||||
|
//
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user