last ...
This commit is contained in:
@@ -0,0 +1,36 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center MQL5 Class Library
|
||||||
|
// --------------------------------------
|
||||||
|
// Name: XBaseClass
|
||||||
|
// Description: provides all based classes for use ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
|
||||||
|
//
|
||||||
|
// XBase Class ...
|
||||||
|
class XCBase
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Public ...
|
||||||
|
public:
|
||||||
|
//
|
||||||
|
// Protected ...
|
||||||
|
protected:
|
||||||
|
|
||||||
|
//
|
||||||
|
// Private ...
|
||||||
|
private:
|
||||||
|
};
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,353 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center MQL5 XAMA Indicator
|
||||||
|
// ---------------------------------------------
|
||||||
|
// Name: XAMA
|
||||||
|
// 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 XAMA Indicator"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Constants ...
|
||||||
|
//
|
||||||
|
#define ShortName "XAMA"
|
||||||
|
|
||||||
|
//
|
||||||
|
// XAMA Indicator States ...
|
||||||
|
enum ENUM_X_XAMA_STATES
|
||||||
|
{
|
||||||
|
X_XAMA_BULLISH = 1,
|
||||||
|
X_XAMA_BEARISH = -1,
|
||||||
|
X_XAMA_NEUTURAL = 0,
|
||||||
|
};
|
||||||
|
//
|
||||||
|
// END Constants ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ...
|
||||||
|
//
|
||||||
|
input int length = 18; // Period
|
||||||
|
input int fastEMA = 2; // Fast EMA Period
|
||||||
|
input int slowEMA = 30; // Slow EMA Period
|
||||||
|
input int maShift = 0; // Shift
|
||||||
|
input ENUM_APPLIED_PRICE appliedTo = 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 "XAMA"
|
||||||
|
#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 = iAMA(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
length,
|
||||||
|
fastEMA,
|
||||||
|
slowEMA,
|
||||||
|
maShift,
|
||||||
|
appliedTo);
|
||||||
|
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 ...
|
||||||
|
IndicatorRelease(maHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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(fastEMA, slowEMA);
|
||||||
|
maxLength = MathMax(maxLength, length);
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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 (length >= 2)
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Define Indexes and Styles ...
|
||||||
|
void DefineBuffers()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
string maBufferLabel = "XAMA " + "(" + (string)length + ")";
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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, " ", "(", length, ")");
|
||||||
|
|
||||||
|
//
|
||||||
|
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_XAMA_BULLISH : lineColorIndex == 2 ? X_XAMA_BEARISH
|
||||||
|
: X_XAMA_NEUTURAL;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set Ma Buffer Color Index ...
|
||||||
|
maColorBuffer[bar_index] = lineColorIndex;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set State Buffer Value ...
|
||||||
|
stateBuffer[bar_index] = stateValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Functions ...
|
||||||
|
//
|
||||||
@@ -0,0 +1,753 @@
|
|||||||
|
//////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// 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,
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Including Models Library ...
|
||||||
|
#include "../Libraries/x-saherelm.models.lib.mq5"
|
||||||
|
//
|
||||||
|
// END Constants ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// 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 7
|
||||||
|
#property indicator_plots 6
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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[];
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hot State ...
|
||||||
|
//
|
||||||
|
#define hotStateBufferIndex 6
|
||||||
|
|
||||||
|
//
|
||||||
|
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();
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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,206 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center MQL5 XCTimer Indicator
|
||||||
|
// ---------------------------------------------
|
||||||
|
// Name: XCTimer
|
||||||
|
// 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 XCTimer Indicator"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Constants ...
|
||||||
|
//
|
||||||
|
#define ShortName "XCTimer"
|
||||||
|
//
|
||||||
|
// END Constants ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ...
|
||||||
|
//
|
||||||
|
input color clr = clrYellow;
|
||||||
|
input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER;
|
||||||
|
//
|
||||||
|
// END Inputs ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Buffers ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// END Buffers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// END Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Event Handlers ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Initialization ...
|
||||||
|
int OnInit()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate Inputs ...
|
||||||
|
CreateIndicatorObject();
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
|
||||||
|
//
|
||||||
|
// Delete Object ...
|
||||||
|
ObjectDelete(0, ShortName);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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[])
|
||||||
|
{
|
||||||
|
//
|
||||||
|
ArraySetAsSeries(time, true);
|
||||||
|
|
||||||
|
//
|
||||||
|
int m = int(time[0] + PeriodSeconds() - TimeCurrent());
|
||||||
|
int s = m % 60;
|
||||||
|
m = (m - s) / 60;
|
||||||
|
|
||||||
|
//
|
||||||
|
long mSpread = SymbolInfoInteger(Symbol(), SYMBOL_SPREAD);
|
||||||
|
|
||||||
|
string _sp = "", _m = "", _s = "";
|
||||||
|
if (mSpread < 10)
|
||||||
|
_sp = "..";
|
||||||
|
else if (mSpread < 100)
|
||||||
|
_sp = ".";
|
||||||
|
if (m < 10)
|
||||||
|
_m = "0";
|
||||||
|
if (s < 10)
|
||||||
|
_s = "0";
|
||||||
|
|
||||||
|
//
|
||||||
|
string objText = "Spread: " + IntegerToString(mSpread) + _sp + " Next Bar in " + _m + IntegerToString(m) + ":" + _s + IntegerToString(s);
|
||||||
|
|
||||||
|
//
|
||||||
|
ObjectSetInteger(0, ShortName, OBJPROP_COLOR, clr);
|
||||||
|
ObjectSetString(0, ShortName, OBJPROP_TEXT, objText);
|
||||||
|
ObjectSetInteger(0, ShortName, OBJPROP_FONTSIZE, 10);
|
||||||
|
ObjectSetString(0, ShortName, OBJPROP_FONT, "Courier");
|
||||||
|
|
||||||
|
//
|
||||||
|
return rates_total;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Event Handlers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Functions ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||||
|
void SetIndicatorName()
|
||||||
|
{
|
||||||
|
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreateIndicatorObject()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
ObjectCreate(0, ShortName, OBJ_LABEL, 0, 0, 0);
|
||||||
|
ObjectSetInteger(0, ShortName, OBJPROP_CORNER, corner);
|
||||||
|
ObjectSetInteger(0, ShortName, OBJPROP_XDISTANCE, 10);
|
||||||
|
ObjectSetInteger(0, ShortName, OBJPROP_YDISTANCE, 2);
|
||||||
|
ENUM_ANCHOR_POINT Anchor = ANCHOR_LEFT_UPPER;
|
||||||
|
switch (corner)
|
||||||
|
{
|
||||||
|
case CORNER_LEFT_UPPER:
|
||||||
|
Anchor = ANCHOR_LEFT_UPPER;
|
||||||
|
break;
|
||||||
|
case CORNER_RIGHT_UPPER:
|
||||||
|
Anchor = ANCHOR_RIGHT_UPPER;
|
||||||
|
break;
|
||||||
|
case CORNER_LEFT_LOWER:
|
||||||
|
Anchor = ANCHOR_LEFT_LOWER;
|
||||||
|
break;
|
||||||
|
case CORNER_RIGHT_LOWER:
|
||||||
|
Anchor = ANCHOR_RIGHT_LOWER;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
ObjectSetInteger(0, ShortName, OBJPROP_ANCHOR, Anchor);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Functions ...
|
||||||
|
//
|
||||||
@@ -0,0 +1,317 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center MQL5 XFI Oscillator
|
||||||
|
// ---------------------------------------------
|
||||||
|
// Name: XFI
|
||||||
|
// Description: Price Momentum Power Detection
|
||||||
|
// Market Analysor ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Maintainer:
|
||||||
|
// ------------
|
||||||
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Global Properties ...
|
||||||
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||||
|
#property link "https://saherelm.ir"
|
||||||
|
#property version "1.00"
|
||||||
|
#property description "SaherElm XFI Oscillator"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Constants ...
|
||||||
|
//
|
||||||
|
#define ShortName "XFI"
|
||||||
|
//
|
||||||
|
// END Constants ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ...
|
||||||
|
//
|
||||||
|
input int length = 18; // Length
|
||||||
|
input ENUM_MA_METHOD method = MODE_SMA; // MA Method
|
||||||
|
input ENUM_APPLIED_VOLUME appliedTo = VOLUME_TICK; // 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_separate_window
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_buffers 2
|
||||||
|
#property indicator_plots 1
|
||||||
|
|
||||||
|
//
|
||||||
|
// FI Buffer ...
|
||||||
|
#define fiBufferIndex 0
|
||||||
|
#define fiColorBufferIndex 1
|
||||||
|
|
||||||
|
//
|
||||||
|
double fiBuffer[];
|
||||||
|
double fiColorBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label1 "XFI"
|
||||||
|
#property indicator_type1 DRAW_COLOR_LINE
|
||||||
|
#property indicator_color1 clrAqua, clrGray, clrFuchsia
|
||||||
|
#property indicator_style1 STYLE_DOT
|
||||||
|
#property indicator_width1 1
|
||||||
|
//
|
||||||
|
// END Buffers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
int fiHandler = 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;
|
||||||
|
|
||||||
|
//
|
||||||
|
fiHandler = iForce(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
length,
|
||||||
|
method,
|
||||||
|
appliedTo);
|
||||||
|
if (fiHandler == INVALID_HANDLE)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
string message = "Error Initializing 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 ...
|
||||||
|
IndicatorRelease(fiHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Calculated Bars ...
|
||||||
|
int fiCalculatedBars = BarsCalculated(fiHandler);
|
||||||
|
if (fiCalculatedBars < maxLength)
|
||||||
|
{
|
||||||
|
return prev_calculated;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Buffers Copy ...
|
||||||
|
int copiedFis = CopyBuffer(fiHandler, 0, 0, limit, fiBuffer);
|
||||||
|
if (copiedFis <= 0)
|
||||||
|
{
|
||||||
|
return prev_calculated;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Main Loop ...
|
||||||
|
for (int i = 0; i < limit && !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()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
string fiBufferLabel = "XFI " + "(" + (string)length + ")";
|
||||||
|
|
||||||
|
//
|
||||||
|
// FI Buffer ...
|
||||||
|
ArraySetAsSeries(fiBuffer, true);
|
||||||
|
SetIndexBuffer(fiBufferIndex, fiBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetString(fiBufferIndex, PLOT_LABEL, fiBufferLabel);
|
||||||
|
|
||||||
|
//
|
||||||
|
// FI Color Buffer ...
|
||||||
|
ArraySetAsSeries(fiColorBuffer, true);
|
||||||
|
SetIndexBuffer(fiColorBufferIndex, fiColorBuffer, INDICATOR_COLOR_INDEX);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||||
|
void SetIndicatorName()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
string indicatorShortName = "";
|
||||||
|
StringConcatenate(indicatorShortName, ShortName, "");
|
||||||
|
|
||||||
|
//
|
||||||
|
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate Buffers ...
|
||||||
|
void CalculateBuffers(
|
||||||
|
int bar_index // Selected Bar Index
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
double iValue = fiBuffer[bar_index];
|
||||||
|
|
||||||
|
//
|
||||||
|
double iColorIndex =
|
||||||
|
iValue > 0 ? 0 : iValue < 0 ? 2
|
||||||
|
: 1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set Buffer Color Index ...
|
||||||
|
fiColorBuffer[bar_index] = iColorIndex;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Functions ...
|
||||||
|
//
|
||||||
@@ -0,0 +1,346 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center MQL5 XLH Indicator
|
||||||
|
// ---------------------------------------------
|
||||||
|
// Name: XLH
|
||||||
|
// Description: Moving Average Indicator
|
||||||
|
// Market Analysor ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Maintainer:
|
||||||
|
// ------------
|
||||||
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Global Properties ...
|
||||||
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||||
|
#property link "https://saherelm.ir"
|
||||||
|
#property version "1.00"
|
||||||
|
#property description "SaherElm XLH Indicator"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Constants ...
|
||||||
|
//
|
||||||
|
#define ShortName "XLH"
|
||||||
|
//
|
||||||
|
// END Constants ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ...
|
||||||
|
//
|
||||||
|
input int length = 14; // Length
|
||||||
|
input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method
|
||||||
|
input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method
|
||||||
|
//
|
||||||
|
// END Inputs ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Includes Logging Library ...
|
||||||
|
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||||
|
|
||||||
|
//
|
||||||
|
// Includes Common Library ...
|
||||||
|
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Buffers ...
|
||||||
|
//
|
||||||
|
#property indicator_chart_window
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_buffers 3
|
||||||
|
#property indicator_plots 3
|
||||||
|
|
||||||
|
//
|
||||||
|
// HH Buffer ...
|
||||||
|
#define hhBufferIndex 0
|
||||||
|
|
||||||
|
//
|
||||||
|
double hhBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label1 "XLH HH"
|
||||||
|
#property indicator_type1 DRAW_LINE
|
||||||
|
#property indicator_color1 clrAqua
|
||||||
|
#property indicator_style1 STYLE_DOT
|
||||||
|
#property indicator_width1 1
|
||||||
|
|
||||||
|
//
|
||||||
|
// LL Buffer ...
|
||||||
|
#define llBufferIndex 1
|
||||||
|
|
||||||
|
//
|
||||||
|
double llBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label2 "XLH LL"
|
||||||
|
#property indicator_type2 DRAW_LINE
|
||||||
|
#property indicator_color2 clrFuchsia
|
||||||
|
#property indicator_style2 STYLE_DOT
|
||||||
|
#property indicator_width2 1
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal Buffer ...
|
||||||
|
#define signalBufferIndex 2
|
||||||
|
|
||||||
|
//
|
||||||
|
double signalBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label3 "XLH S"
|
||||||
|
#property indicator_type3 DRAW_LINE
|
||||||
|
#property indicator_color3 clrGold
|
||||||
|
#property indicator_style3 STYLE_DOT
|
||||||
|
#property indicator_width3 1
|
||||||
|
//
|
||||||
|
// END Buffers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// END Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Event Handlers ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Initialization ...
|
||||||
|
int OnInit()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate Inputs ...
|
||||||
|
if (!ValidateInputs())
|
||||||
|
{
|
||||||
|
return INIT_PARAMETERS_INCORRECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
logTag = ShortName;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Define Index Buffers ...
|
||||||
|
DefineBuffers();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set Indicator ShortName ...
|
||||||
|
SetIndicatorName();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Init Succeed ...
|
||||||
|
return INIT_SUCCEEDED;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// DeInitialization ...
|
||||||
|
void OnDeinit(const int reason)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||||
|
// REASON_REMOVE 1 Program removed from a chart
|
||||||
|
// REASON_RECOMPILE 2 Program recompiled
|
||||||
|
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||||
|
// REASON_CHARTCLOSE 4 Chart closed
|
||||||
|
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||||
|
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||||
|
// REASON_TEMPLATE 7 Another chart template applied
|
||||||
|
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||||
|
// REASON_CLOSE 9 Terminal closed
|
||||||
|
|
||||||
|
//
|
||||||
|
// Here we can handle De Initialization Reasons ...
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculations ...
|
||||||
|
//
|
||||||
|
// Calculating what we want ...
|
||||||
|
int OnCalculate(
|
||||||
|
//
|
||||||
|
// total Candles on chart ...
|
||||||
|
const int rates_total,
|
||||||
|
//
|
||||||
|
// total calculated Candles on charts ...
|
||||||
|
const int prev_calculated,
|
||||||
|
//
|
||||||
|
// history of Candles Open Time ...
|
||||||
|
const datetime &time[],
|
||||||
|
//
|
||||||
|
// history of Candles Open Price ...
|
||||||
|
const double &open[],
|
||||||
|
//
|
||||||
|
// history of Candles High Price ...
|
||||||
|
const double &high[],
|
||||||
|
//
|
||||||
|
// history of Candles Low Price ...
|
||||||
|
const double &low[],
|
||||||
|
//
|
||||||
|
// history of Candles Close Price ...
|
||||||
|
const double &close[],
|
||||||
|
//
|
||||||
|
// history of Tick Volumes on Candle ...
|
||||||
|
const long &tick_volume[],
|
||||||
|
//
|
||||||
|
// history of Trade Volumes ...
|
||||||
|
const long &volume[],
|
||||||
|
//
|
||||||
|
// history of Candles Spread Price ...
|
||||||
|
const int &spread[])
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Prepare Buffers ...
|
||||||
|
ArraySetAsSeries(time, true);
|
||||||
|
ArraySetAsSeries(open, true);
|
||||||
|
ArraySetAsSeries(high, true);
|
||||||
|
ArraySetAsSeries(low, true);
|
||||||
|
ArraySetAsSeries(close, true);
|
||||||
|
ArraySetAsSeries(tick_volume, true);
|
||||||
|
ArraySetAsSeries(volume, true);
|
||||||
|
ArraySetAsSeries(spread, true);
|
||||||
|
|
||||||
|
//
|
||||||
|
// this counts Available Bars ...
|
||||||
|
int limit;
|
||||||
|
|
||||||
|
//
|
||||||
|
// because in some cases we may have more than one input for
|
||||||
|
// calculation and we must prevent any calculation
|
||||||
|
// untill we pass the biggest input length, here we get max Input length
|
||||||
|
// and then wait until pass it ...
|
||||||
|
int maxLength = MathMax(0, length);
|
||||||
|
|
||||||
|
//
|
||||||
|
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Main Loop ...
|
||||||
|
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
CalculateBuffers(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return rates_total;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Event Handlers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Functions ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Validate Input Args for Initialization ...
|
||||||
|
bool ValidateInputs()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
if (length >= 2)
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Define Indexes and Styles ...
|
||||||
|
void DefineBuffers()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// HH Buffer ...
|
||||||
|
string hhBufferLabel = ShortName + " HH " + "(" + (string)length + ")";
|
||||||
|
ArraySetAsSeries(hhBuffer, true);
|
||||||
|
SetIndexBuffer(hhBufferIndex, hhBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(hhBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||||
|
PlotIndexSetString(hhBufferIndex, PLOT_LABEL, hhBufferLabel);
|
||||||
|
|
||||||
|
//
|
||||||
|
// LL Buffer ...
|
||||||
|
string llBufferLabel = ShortName + " LL " + "(" + (string)length + ")";
|
||||||
|
ArraySetAsSeries(llBuffer, true);
|
||||||
|
SetIndexBuffer(llBufferIndex, llBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(llBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||||
|
PlotIndexSetString(llBufferIndex, PLOT_LABEL, llBufferLabel);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal Buffer ...
|
||||||
|
string signalBufferLabel = ShortName + " S " + "(" + (string)length + ")";
|
||||||
|
ArraySetAsSeries(signalBuffer, true);
|
||||||
|
SetIndexBuffer(signalBufferIndex, signalBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(signalBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||||
|
PlotIndexSetString(signalBufferIndex, PLOT_LABEL, signalBufferLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||||
|
void SetIndicatorName()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
string indicatorShortName = "";
|
||||||
|
StringConcatenate(indicatorShortName, ShortName, "");
|
||||||
|
|
||||||
|
//
|
||||||
|
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate Buffers ...
|
||||||
|
void CalculateBuffers(
|
||||||
|
int bar_index // Selected Bar Index
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Calculate Threshold ...
|
||||||
|
//
|
||||||
|
// HH Buffer ...
|
||||||
|
int hhIndex = iHighest(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
hhMode,
|
||||||
|
length,
|
||||||
|
bar_index);
|
||||||
|
double hhValue = GetAppliedPrice(
|
||||||
|
hhIndex,
|
||||||
|
hhMode);
|
||||||
|
|
||||||
|
//
|
||||||
|
hhBuffer[bar_index] = hhValue;
|
||||||
|
|
||||||
|
//
|
||||||
|
// LL Buffer ...
|
||||||
|
int llIndex = iLowest(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
llMode,
|
||||||
|
length,
|
||||||
|
bar_index);
|
||||||
|
double llValue = GetAppliedPrice(
|
||||||
|
llIndex,
|
||||||
|
llMode);
|
||||||
|
|
||||||
|
//
|
||||||
|
llBuffer[bar_index] = llValue;
|
||||||
|
|
||||||
|
//
|
||||||
|
XOHCL c = GetCandle(bar_index);
|
||||||
|
double lhDiff = hhValue - llValue;
|
||||||
|
double signalValue = (lhDiff / 2);
|
||||||
|
|
||||||
|
//
|
||||||
|
signalBuffer[bar_index] = (hhValue - signalValue);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Functions ...
|
||||||
|
//
|
||||||
@@ -0,0 +1,390 @@
|
|||||||
|
/////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center MQL5 OrderBlock Detector Indicator
|
||||||
|
// -----------------------------------------------------
|
||||||
|
// Name: XOBD
|
||||||
|
// Description: detect Order Blocks based on Swings ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Maintainer:
|
||||||
|
// ------------
|
||||||
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Global Properties ...
|
||||||
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||||
|
#property link "https://saherelm.ir"
|
||||||
|
#property version "1.00"
|
||||||
|
#property description "SaherElm XOBD Indicator"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Constants ...
|
||||||
|
//
|
||||||
|
#define ShortName "XOBD"
|
||||||
|
//
|
||||||
|
// END Constants ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
input int length = 5; // Swing Length
|
||||||
|
|
||||||
|
//
|
||||||
|
input uchar swingHighArrowCode = 108; // Swing High Arrow Code
|
||||||
|
input color swingHighArrowColor = clrMagenta; // Swing High Arrow Color
|
||||||
|
|
||||||
|
//
|
||||||
|
input uchar swingLowArrowCode = 108; // Swing Low Arrow Code
|
||||||
|
input color swingLowArrowColor = clrAqua; // Swing Low Arrow Color
|
||||||
|
//
|
||||||
|
// END Inputs ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Includes Logging Library ...
|
||||||
|
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||||
|
|
||||||
|
//
|
||||||
|
// Include Common and Models Library ...
|
||||||
|
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||||
|
|
||||||
|
//
|
||||||
|
// Include Draw Library ...
|
||||||
|
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Buffers ...
|
||||||
|
//
|
||||||
|
#property indicator_chart_window
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_buffers 1
|
||||||
|
#property indicator_plots 0
|
||||||
|
|
||||||
|
//
|
||||||
|
#define swingBufferIndex 0
|
||||||
|
double swingBuffer[];
|
||||||
|
//
|
||||||
|
// END Buffers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// END Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Event Handlers ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Initialization ...
|
||||||
|
int OnInit()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate Inputs ...
|
||||||
|
if (!ValidateInputs())
|
||||||
|
{
|
||||||
|
return INIT_PARAMETERS_INCORRECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
logTag = ShortName;
|
||||||
|
drawPrefix = ShortName;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Define Index Buffers ...
|
||||||
|
DefineBuffers();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set Indicator ShortName ...
|
||||||
|
SetIndicatorName();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Init Succeed ...
|
||||||
|
return INIT_SUCCEEDED;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// DeInitialization ...
|
||||||
|
void OnDeinit(const int reason)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||||
|
// REASON_REMOVE 1 Program removed from a chart
|
||||||
|
// REASON_RECOMPILE 2 Program recompiled
|
||||||
|
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||||
|
// REASON_CHARTCLOSE 4 Chart closed
|
||||||
|
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||||
|
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||||
|
// REASON_TEMPLATE 7 Another chart template applied
|
||||||
|
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||||
|
// REASON_CLOSE 9 Terminal closed
|
||||||
|
|
||||||
|
//
|
||||||
|
// Here we can handle De Initialization Reasons ...
|
||||||
|
OnDeinitDrawLibrary();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculations ...
|
||||||
|
//
|
||||||
|
// Calculating what we want ...
|
||||||
|
int OnCalculate(
|
||||||
|
//
|
||||||
|
// total Candles on chart ...
|
||||||
|
const int rates_total,
|
||||||
|
//
|
||||||
|
// total calculated Candles on charts ...
|
||||||
|
const int prev_calculated,
|
||||||
|
//
|
||||||
|
// history of Candles Open Time ...
|
||||||
|
const datetime &time[],
|
||||||
|
//
|
||||||
|
// history of Candles Open Price ...
|
||||||
|
const double &open[],
|
||||||
|
//
|
||||||
|
// history of Candles High Price ...
|
||||||
|
const double &high[],
|
||||||
|
//
|
||||||
|
// history of Candles Low Price ...
|
||||||
|
const double &low[],
|
||||||
|
//
|
||||||
|
// history of Candles Close Price ...
|
||||||
|
const double &close[],
|
||||||
|
//
|
||||||
|
// history of Tick Volumes on Candle ...
|
||||||
|
const long &tick_volume[],
|
||||||
|
//
|
||||||
|
// history of Trade Volumes ...
|
||||||
|
const long &volume[],
|
||||||
|
//
|
||||||
|
// history of Candles Spread Price ...
|
||||||
|
const int &spread[])
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Prepare Buffers ...
|
||||||
|
ArraySetAsSeries(time, true);
|
||||||
|
ArraySetAsSeries(open, true);
|
||||||
|
ArraySetAsSeries(high, true);
|
||||||
|
ArraySetAsSeries(low, true);
|
||||||
|
ArraySetAsSeries(close, true);
|
||||||
|
ArraySetAsSeries(tick_volume, true);
|
||||||
|
ArraySetAsSeries(volume, true);
|
||||||
|
ArraySetAsSeries(spread, true);
|
||||||
|
|
||||||
|
//
|
||||||
|
// this counts Available Bars ...
|
||||||
|
int limit;
|
||||||
|
|
||||||
|
//
|
||||||
|
// because in some cases we may have more than one input for
|
||||||
|
// calculation and we must prevent any calculation
|
||||||
|
// untill we pass the biggest input length, here we get max Input length
|
||||||
|
// and then wait until pass it ...
|
||||||
|
int maxLength = MathMax(0, length * 3);
|
||||||
|
|
||||||
|
//
|
||||||
|
limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Main Loop ...
|
||||||
|
for (int i = limit; i >= 0 && !IsStopped(); i--)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
CalculateBuffers(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return rates_total;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Event Handlers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Functions ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Validate Input Args for Initialization ...
|
||||||
|
bool ValidateInputs()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
if (length >= 2)
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Define Indexes and Styles ...
|
||||||
|
void DefineBuffers()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
ArraySetAsSeries(swingBuffer, true);
|
||||||
|
SetIndexBuffer(swingBufferIndex, swingBuffer, INDICATOR_CALCULATIONS);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||||
|
void SetIndicatorName()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
string indicatorShortName = "";
|
||||||
|
StringConcatenate(indicatorShortName, ShortName, " ", "( ", length, " )");
|
||||||
|
|
||||||
|
//
|
||||||
|
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate Buffers ...
|
||||||
|
void CalculateBuffers(int bar_index)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// GetCandleSwing(bar_index);
|
||||||
|
ENUM_X_SWING_TYPE type = X_NO_SWING;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Try To Detect Order Blocks ...
|
||||||
|
bool isSwingLow = false;
|
||||||
|
bool isSwingHigh = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Reading Candles Data ...
|
||||||
|
XOHCL candles[];
|
||||||
|
for (int i = bar_index; i < bar_index + ((length * 2) + 2); i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
XOHCL iCandle = GetCandle(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
i);
|
||||||
|
|
||||||
|
//
|
||||||
|
Add(
|
||||||
|
iCandle,
|
||||||
|
candles);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Swing Low ...
|
||||||
|
isSwingLow =
|
||||||
|
//
|
||||||
|
candles[1].close > candles[2].close &&
|
||||||
|
candles[2].close > candles[3].close &&
|
||||||
|
//
|
||||||
|
candles[3].close < candles[4].close &&
|
||||||
|
//
|
||||||
|
candles[5].close > candles[4].close &&
|
||||||
|
candles[6].close > candles[5].close
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (isSwingLow)
|
||||||
|
{
|
||||||
|
type = X_SWING_LOW;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!isSwingLow)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Swing High ...
|
||||||
|
isSwingHigh =
|
||||||
|
//
|
||||||
|
candles[1].close < candles[2].close &&
|
||||||
|
candles[2].close < candles[3].close &&
|
||||||
|
//
|
||||||
|
candles[3].close > candles[4].close &&
|
||||||
|
//
|
||||||
|
candles[5].close < candles[4].close &&
|
||||||
|
candles[6].close < candles[5].close
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (isSwingHigh)
|
||||||
|
{
|
||||||
|
type = X_SWING_HIGH;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Swing High ...
|
||||||
|
case X_SWING_HIGH:
|
||||||
|
//
|
||||||
|
swingBuffer[bar_index] = type;
|
||||||
|
DrawSwingArrow(1, bar_index);
|
||||||
|
break;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Swinmg Low ...
|
||||||
|
case X_SWING_LOW:
|
||||||
|
//
|
||||||
|
swingBuffer[bar_index] = type;
|
||||||
|
DrawSwingArrow(0, bar_index);
|
||||||
|
break;
|
||||||
|
|
||||||
|
//
|
||||||
|
// No Swing ...
|
||||||
|
default:
|
||||||
|
case X_NO_SWING:
|
||||||
|
//
|
||||||
|
swingBuffer[bar_index] = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Draw a Swing Arrow Shape ...
|
||||||
|
void DrawSwingArrow(
|
||||||
|
int type, // Swing Type: 0 - Low / 1 - High ...
|
||||||
|
int bar_index)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool isSwingHigh = type == 1;
|
||||||
|
XOHCL candle = GetCandle(bar_index + 3);
|
||||||
|
double arrowDistanceInPoint = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Define Required Object Properties fro Draw an Arrow ...
|
||||||
|
datetime time = iTime(_Symbol, _Period, bar_index + 3);
|
||||||
|
double purePrice = isSwingHigh ? candle.high : candle.low;
|
||||||
|
color clr = isSwingHigh ? swingHighArrowColor : swingLowArrowColor;
|
||||||
|
ENUM_ARROW_ANCHOR anchor = isSwingHigh ? ANCHOR_BOTTOM : ANCHOR_TOP;
|
||||||
|
uchar arrowCode = uchar(isSwingHigh ? swingHighArrowCode : swingLowArrowCode);
|
||||||
|
double price = isSwingHigh ? purePrice + arrowDistanceInPoint : purePrice - arrowDistanceInPoint;
|
||||||
|
string name = "Swing " + (isSwingHigh ? "High" : "Low") + "_" + (string)time + "_" + (string)purePrice;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Draw desired Arrow ...
|
||||||
|
DrawArrow(
|
||||||
|
0,
|
||||||
|
name,
|
||||||
|
0,
|
||||||
|
time,
|
||||||
|
price,
|
||||||
|
arrowCode,
|
||||||
|
anchor,
|
||||||
|
clr);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Functions ...
|
||||||
|
//
|
||||||
@@ -0,0 +1,397 @@
|
|||||||
|
/////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// 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_DOT; // Short Entry Style
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Short Exit";
|
||||||
|
input double shortExitValue = 40; // Short Exit Level
|
||||||
|
input color shortExitColor = clrRed; // 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 = clrRed; // Long Entry Level Color
|
||||||
|
input ENUM_LINE_STYLE longEntryLineStyle = STYLE_DOT; // Long Entry Style
|
||||||
|
|
||||||
|
//
|
||||||
|
input group "Long Exit";
|
||||||
|
input double longExitValue = 60; // Long Exit Level
|
||||||
|
input color longExitColor = clrRed; // 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 2
|
||||||
|
#property indicator_plots 1
|
||||||
|
|
||||||
|
//
|
||||||
|
#define rsiBufferIndex 0
|
||||||
|
#define rsiColorBufferIndex 1
|
||||||
|
|
||||||
|
//
|
||||||
|
double rsiBuffer[];
|
||||||
|
double rsiColorBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_label1 "XRSI"
|
||||||
|
#property indicator_type1 DRAW_COLOR_LINE
|
||||||
|
#property indicator_color1 clrAqua, clrGray, clrFuchsia
|
||||||
|
#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);
|
||||||
|
|
||||||
|
//
|
||||||
|
// RSI Color Buffer ...
|
||||||
|
ArraySetAsSeries(rsiColorBuffer, true);
|
||||||
|
SetIndexBuffer(rsiColorBufferIndex, rsiColorBuffer, INDICATOR_COLOR_INDEX);
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
double iValue = rsiBuffer[bar_index];
|
||||||
|
|
||||||
|
//
|
||||||
|
double iColorIndex = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (
|
||||||
|
iValue >= shortEntryValue ||
|
||||||
|
iValue <= longEntryValue ||
|
||||||
|
(iValue < longExitValue &&
|
||||||
|
iValue > shortExitValue))
|
||||||
|
{
|
||||||
|
iColorIndex = 0;
|
||||||
|
}
|
||||||
|
else if (
|
||||||
|
iValue <= shortEntryValue &&
|
||||||
|
iValue >= longExitValue)
|
||||||
|
{
|
||||||
|
iColorIndex = 2;
|
||||||
|
}
|
||||||
|
else if (
|
||||||
|
iValue < shortExitValue &&
|
||||||
|
iValue > longEntryValue)
|
||||||
|
{
|
||||||
|
iColorIndex = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
rsiColorBuffer[bar_index] = iColorIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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,558 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center MQL5 XTS Oscillator
|
||||||
|
// ---------------------------------------------
|
||||||
|
// Name: XTS
|
||||||
|
// Description: Time Sections Oscillator ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// 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 XTS Oscillator"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Constants ...
|
||||||
|
//
|
||||||
|
|
||||||
|
#define ShortName "XTS"
|
||||||
|
|
||||||
|
enum ENUM_X_PERIOD_METHOD
|
||||||
|
{
|
||||||
|
//
|
||||||
|
X_PERIOD_NOTHING,
|
||||||
|
//
|
||||||
|
X_PERIOD_AUTO,
|
||||||
|
//
|
||||||
|
X_PERIOD_MANUALLY
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// XTS Oscillator States ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Constants ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ...
|
||||||
|
//
|
||||||
|
input group "Current Period";
|
||||||
|
input ENUM_APPLIED_PRICE currentAppliedTo = PRICE_CLOSE; // Current Applied To
|
||||||
|
//
|
||||||
|
input group "Nearest Period";
|
||||||
|
input ENUM_X_PERIOD_METHOD nearestMethod = X_PERIOD_AUTO; // How to Find Nearest Period
|
||||||
|
input ENUM_TIMEFRAMES nearestPeriod = NULL; // Nearest Time Frame
|
||||||
|
input ENUM_APPLIED_PRICE nearestAppliedTo = PRICE_CLOSE; // Nearest Applied To
|
||||||
|
//
|
||||||
|
input group "Mediest Period";
|
||||||
|
input ENUM_X_PERIOD_METHOD mediestMethod = X_PERIOD_AUTO; // How to Find Mediest Period
|
||||||
|
input ENUM_TIMEFRAMES mediestPeriod = NULL; // Mediest Time Frame
|
||||||
|
input ENUM_APPLIED_PRICE mediestAppliedTo = PRICE_CLOSE; // Mediest Applied To
|
||||||
|
//
|
||||||
|
input group "Farest Period";
|
||||||
|
input ENUM_X_PERIOD_METHOD farestMethod = X_PERIOD_AUTO; // How to Find Farest Period
|
||||||
|
input ENUM_TIMEFRAMES farestPeriod = NULL; // Farest Time Frame
|
||||||
|
input ENUM_APPLIED_PRICE farestAppliedTo = PRICE_CLOSE; // Farest Applied To
|
||||||
|
|
||||||
|
//
|
||||||
|
// Includes Logging Library ...
|
||||||
|
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||||
|
|
||||||
|
//
|
||||||
|
// Includes Draw Library ...
|
||||||
|
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||||
|
|
||||||
|
//
|
||||||
|
// Includes Common Library ...
|
||||||
|
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Buffers ...
|
||||||
|
//
|
||||||
|
#property indicator_separate_window
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_buffers 4
|
||||||
|
#property indicator_plots 4
|
||||||
|
|
||||||
|
//
|
||||||
|
// Current ...
|
||||||
|
#define currentBufferIndex 0
|
||||||
|
|
||||||
|
double currentBuffer[];
|
||||||
|
|
||||||
|
#property indicator_label1 "XTS C"
|
||||||
|
#property indicator_type1 DRAW_LINE
|
||||||
|
#property indicator_color1 clrBrown
|
||||||
|
#property indicator_style1 STYLE_SOLID
|
||||||
|
#property indicator_width1 1
|
||||||
|
|
||||||
|
//
|
||||||
|
// Nearest ...
|
||||||
|
#define nearestBufferIndex 1
|
||||||
|
|
||||||
|
double nearestBuffer[];
|
||||||
|
|
||||||
|
#property indicator_label2 "XTS N"
|
||||||
|
#property indicator_type2 DRAW_LINE
|
||||||
|
#property indicator_color2 clrAqua
|
||||||
|
#property indicator_style2 STYLE_SOLID
|
||||||
|
#property indicator_width2 1
|
||||||
|
|
||||||
|
//
|
||||||
|
// Mediest ...
|
||||||
|
#define mediestBufferIndex 2
|
||||||
|
|
||||||
|
double mediestBuffer[];
|
||||||
|
|
||||||
|
#property indicator_label3 "XTS M"
|
||||||
|
#property indicator_type3 DRAW_LINE
|
||||||
|
#property indicator_color3 clrLime
|
||||||
|
#property indicator_style3 STYLE_SOLID
|
||||||
|
#property indicator_width3 1
|
||||||
|
|
||||||
|
//
|
||||||
|
// Farest ...
|
||||||
|
#define farestBufferIndex 3
|
||||||
|
|
||||||
|
double farestBuffer[];
|
||||||
|
|
||||||
|
#property indicator_label4 "XTS F"
|
||||||
|
#property indicator_type4 DRAW_LINE
|
||||||
|
#property indicator_color4 clrLightBlue
|
||||||
|
#property indicator_style4 STYLE_SOLID
|
||||||
|
#property indicator_width4 1
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Buffers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
ENUM_TIMEFRAMES mNearestPeriod = NULL;
|
||||||
|
ENUM_TIMEFRAMES mMediestPeriod = NULL;
|
||||||
|
ENUM_TIMEFRAMES mFarestPeriod = NULL;
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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 Oscillator ShortName ...
|
||||||
|
SetOscillatorName();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Init Succeed ...
|
||||||
|
return INIT_SUCCEEDED;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// DeInitialization ...
|
||||||
|
void OnDeinit(const int reason)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
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 = 30;
|
||||||
|
|
||||||
|
//
|
||||||
|
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Main Loop ...
|
||||||
|
for (int i = 0; i < limit && !IsStopped(); i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Do Buffers Calculation ...
|
||||||
|
CalculateBuffers(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return rates_total;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Event Handlers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Functions ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Validate Input Args for Initialization ...
|
||||||
|
bool ValidateInputs()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = true;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Define Indexes and Styles ...
|
||||||
|
void DefineBuffers()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int maxLength = 30;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Current ...
|
||||||
|
ArraySetAsSeries(currentBuffer, true);
|
||||||
|
SetIndexBuffer(currentBufferIndex, currentBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(currentBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Nearest ...
|
||||||
|
ArraySetAsSeries(nearestBuffer, true);
|
||||||
|
SetIndexBuffer(nearestBufferIndex, nearestBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(nearestBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Mediest ...
|
||||||
|
ArraySetAsSeries(mediestBuffer, true);
|
||||||
|
SetIndexBuffer(mediestBufferIndex, mediestBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(mediestBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Farest ...
|
||||||
|
ArraySetAsSeries(farestBuffer, true);
|
||||||
|
SetIndexBuffer(farestBufferIndex, farestBuffer, INDICATOR_DATA);
|
||||||
|
PlotIndexSetInteger(farestBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set Oscillator Short Name and also we can define Buffers Labels ...
|
||||||
|
void SetOscillatorName()
|
||||||
|
{
|
||||||
|
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate Buffers ...
|
||||||
|
void CalculateBuffers(int bar_index)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Current ...
|
||||||
|
CalculateCurrent(bar_index);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Nearest ...
|
||||||
|
CalculateNearest(bar_index);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Mediest ...
|
||||||
|
CalculateMediest(bar_index);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Farest ...
|
||||||
|
CalculateFarest(bar_index);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Commenting ...
|
||||||
|
string comment = GenerateDescriptionComment();
|
||||||
|
Comment(comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Current ...
|
||||||
|
void CalculateCurrent(int bar_index)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
datetime barTime = iTime(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
bar_index);
|
||||||
|
datetime startTime = GetPeriodStartTime(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
barTime);
|
||||||
|
int startBarIndex = iBarShift(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
startTime);
|
||||||
|
|
||||||
|
//
|
||||||
|
XOHCL c = GetCandle(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
startBarIndex);
|
||||||
|
|
||||||
|
//
|
||||||
|
double value = GetAppliedPrice(
|
||||||
|
c,
|
||||||
|
currentAppliedTo);
|
||||||
|
|
||||||
|
//
|
||||||
|
currentBuffer[bar_index] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Nearest ...
|
||||||
|
void CalculateNearest(int bar_index)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (mNearestPeriod == NULL)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
switch (nearestMethod)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
case X_PERIOD_AUTO:
|
||||||
|
mNearestPeriod = GetNearestTimeFrame(_Period);
|
||||||
|
break;
|
||||||
|
|
||||||
|
//
|
||||||
|
case X_PERIOD_NOTHING:
|
||||||
|
case X_PERIOD_MANUALLY:
|
||||||
|
mNearestPeriod = nearestPeriod;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
datetime barTime = iTime(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
bar_index);
|
||||||
|
datetime startTime = GetPeriodStartTime(
|
||||||
|
_Symbol,
|
||||||
|
mNearestPeriod,
|
||||||
|
barTime);
|
||||||
|
int startBarIndex = iBarShift(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
startTime);
|
||||||
|
|
||||||
|
//
|
||||||
|
XOHCL c = GetCandle(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
startBarIndex);
|
||||||
|
|
||||||
|
//
|
||||||
|
double value = GetAppliedPrice(
|
||||||
|
c,
|
||||||
|
nearestAppliedTo);
|
||||||
|
|
||||||
|
//
|
||||||
|
nearestBuffer[bar_index] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Mediest ...
|
||||||
|
void CalculateMediest(int bar_index)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (mMediestPeriod == NULL)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
switch (mediestMethod)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
case X_PERIOD_AUTO:
|
||||||
|
mMediestPeriod = GetMediestTimeFrame(_Period);
|
||||||
|
break;
|
||||||
|
|
||||||
|
//
|
||||||
|
case X_PERIOD_NOTHING:
|
||||||
|
case X_PERIOD_MANUALLY:
|
||||||
|
mMediestPeriod = mediestPeriod;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
datetime barTime = iTime(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
bar_index);
|
||||||
|
datetime startTime = GetPeriodStartTime(
|
||||||
|
_Symbol,
|
||||||
|
mMediestPeriod,
|
||||||
|
barTime);
|
||||||
|
int startBarIndex = iBarShift(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
startTime);
|
||||||
|
|
||||||
|
//
|
||||||
|
XOHCL c = GetCandle(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
startBarIndex);
|
||||||
|
|
||||||
|
//
|
||||||
|
double value = GetAppliedPrice(
|
||||||
|
c,
|
||||||
|
mediestAppliedTo);
|
||||||
|
|
||||||
|
//
|
||||||
|
mediestBuffer[bar_index] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Farest ...
|
||||||
|
void CalculateFarest(int bar_index)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (mFarestPeriod == NULL)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
switch (farestMethod)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
case X_PERIOD_AUTO:
|
||||||
|
mFarestPeriod = GetFarestTimeFrame(_Period);
|
||||||
|
break;
|
||||||
|
|
||||||
|
//
|
||||||
|
case X_PERIOD_NOTHING:
|
||||||
|
case X_PERIOD_MANUALLY:
|
||||||
|
mFarestPeriod = farestPeriod;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
datetime barTime = iTime(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
bar_index);
|
||||||
|
datetime startTime = GetPeriodStartTime(
|
||||||
|
_Symbol,
|
||||||
|
mFarestPeriod,
|
||||||
|
barTime);
|
||||||
|
int startBarIndex = iBarShift(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
startTime);
|
||||||
|
|
||||||
|
//
|
||||||
|
XOHCL c = GetCandle(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
startBarIndex);
|
||||||
|
|
||||||
|
//
|
||||||
|
double value = GetAppliedPrice(
|
||||||
|
c,
|
||||||
|
farestAppliedTo);
|
||||||
|
|
||||||
|
//
|
||||||
|
farestBuffer[bar_index] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Generate Comment ...
|
||||||
|
string GenerateDescriptionComment()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
string result = "";
|
||||||
|
|
||||||
|
//
|
||||||
|
result += "Nearest : " + EnumToString(mNearestPeriod) + "\n";
|
||||||
|
result += "Mediest : " + EnumToString(mMediestPeriod) + "\n";
|
||||||
|
result += "Farest : " + EnumToString(mFarestPeriod) + "\n";
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Functions ...
|
||||||
|
//
|
||||||
@@ -0,0 +1,187 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// 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 = false; // Terminal Alerts
|
||||||
|
input bool mailAlerts = false; // Mail Alerts
|
||||||
|
input bool pushAlerts = false; // 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)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
StringReplace(message, "\n", " | ");
|
||||||
|
|
||||||
|
//
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Provided Functions ...
|
||||||
|
//
|
||||||
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 ...
|
||||||
|
//
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user