Initial Commit ...
This commit is contained in:
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,258 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 NN Class Library
|
||||
// ----------------------------------------
|
||||
// Name: XNNClass
|
||||
// Description: provides all classes for implementing
|
||||
// Neural Network ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
class XCNNBase
|
||||
{
|
||||
//
|
||||
// Public Definitions ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XCNNBase(
|
||||
int nodes = 10, // Number of Input Nodes
|
||||
double starterWeight = 0.5, // start weight for each input
|
||||
double coEfficient = 0.1, // COEfficient Multiplier
|
||||
double upperRange = 1, // Upper Normal Range Value
|
||||
double lowerRange = -1, // Lower Normal Range Value
|
||||
double learningRates = 0.1 // Back Propagation Learning Rate
|
||||
) {
|
||||
//
|
||||
mNodes = nodes;
|
||||
mUpperRange = upperRange;
|
||||
mLowerRange = lowerRange;
|
||||
mCoEfficient = coEfficient;
|
||||
mLearningRates = learningRates;
|
||||
mStarterWeight = starterWeight;
|
||||
|
||||
//
|
||||
ReConstructWeights();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XCNNBase() {}
|
||||
|
||||
//
|
||||
// Protected Definitions ...
|
||||
void NormalizeInputs(double &inputs[], double &result[])
|
||||
{
|
||||
//
|
||||
ArrayFree(result);
|
||||
ArrayResize(result, 1);
|
||||
|
||||
//
|
||||
// Validate inputs ...
|
||||
if (ArraySize(inputs) != mNodes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Result ...
|
||||
ArrayResize(result, mNodes);
|
||||
|
||||
//
|
||||
// Calculating min and max range value ...
|
||||
double minRangeValue = inputs[ArrayMinimum(inputs)];
|
||||
double maxRangeValue = inputs[ArrayMaximum(inputs)];
|
||||
|
||||
//
|
||||
// Loop through Inputs nd Normalize them ...
|
||||
for (int i = 0; i < mNodes; i++)
|
||||
{
|
||||
//
|
||||
double normalValue = (((inputs[i] - minRangeValue) * (mUpperRange - mLowerRange)) / (maxRangeValue - minRangeValue)) + mLowerRange;
|
||||
result[i] = normalValue;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Hyperbolic Tangent Activation Function ...
|
||||
double TanHActivationFunction(double weightedInputs)
|
||||
{
|
||||
//
|
||||
double result = (exp(weightedInputs) - exp(-weightedInputs)) / (exp(weightedInputs) + exp(-weightedInputs));
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Weighted Inputs ...
|
||||
double CalculateWeightedInputs(
|
||||
double &inputs[],
|
||||
bool applyCOEfficient = true)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (ArraySize(inputs) != mNodes)
|
||||
{
|
||||
//
|
||||
result = -1;
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < mNodes; i++)
|
||||
{
|
||||
result += inputs[i] * mWeights[i];
|
||||
}
|
||||
|
||||
//
|
||||
// Multiply if required ...
|
||||
if (applyCOEfficient)
|
||||
{
|
||||
result *= mCoEfficient;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Hidden Layers ...
|
||||
virtual double CalculateHiddenLayer(double &inputs[])
|
||||
{
|
||||
//
|
||||
// this is Default Activation Function which used ...
|
||||
// you can override this by writing your own ...
|
||||
double totalWeightedInputs = CalculateWeightedInputs(inputs);
|
||||
double result = TanHActivationFunction(totalWeightedInputs);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Output Layers ...
|
||||
double CalculateOutputLayer(double &inputs[])
|
||||
{
|
||||
//
|
||||
double result = -1;
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (ArraySize(inputs) != mNodes) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double normalizedInputs[];
|
||||
NormalizeInputs(inputs, normalizedInputs);
|
||||
if (ArraySize(normalizedInputs) != mNodes) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double hiddenLayerResult = CalculateHiddenLayer(normalizedInputs);
|
||||
|
||||
//
|
||||
result = 1 * hiddenLayerResult;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Basck Propaggation Learning ...
|
||||
void BackPropagation(
|
||||
double &inputs[],
|
||||
double &outputs,
|
||||
double targetOutput
|
||||
) {
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (ArraySize(inputs) != mNodes) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double normalizedInputs[];
|
||||
NormalizeInputs(inputs, normalizedInputs);
|
||||
if (ArraySize(normalizedInputs) != mNodes) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double error = targetOutput - outputs;
|
||||
double derivative = 1 - MathPow(outputs, 2);
|
||||
|
||||
//
|
||||
for (int i = 0; i < mNodes; i++) {
|
||||
//
|
||||
double gradient = error * derivative * inputs[i];
|
||||
mWeights[i] = mLearningRates * gradient;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
//
|
||||
// Private Definitions ...
|
||||
private:
|
||||
//
|
||||
// Number of Input Nodes ...
|
||||
int mNodes;
|
||||
|
||||
//
|
||||
// Specify Upper range of Normal Values ...
|
||||
double mUpperRange;
|
||||
|
||||
//
|
||||
// Specify Lower range of Normal Values ...
|
||||
double mLowerRange;
|
||||
|
||||
//
|
||||
// Starter Weight for each input node ...
|
||||
double mStarterWeight;
|
||||
|
||||
//
|
||||
// double Input Node Weights ...
|
||||
double mWeights[];
|
||||
|
||||
//
|
||||
// CoEfficient is a multiplyer for weighted inputs ...
|
||||
double mCoEfficient;
|
||||
|
||||
//
|
||||
// Back Propagation Learning Rates ...
|
||||
double mLearningRates;
|
||||
|
||||
//
|
||||
// ReConstruct Weights ...
|
||||
void ReConstructWeights() {
|
||||
//
|
||||
ArrayFree(mWeights);
|
||||
ArrayResize(mWeights, mNodes);
|
||||
|
||||
//
|
||||
for (int i = 0; i< mNodes; i++) {
|
||||
mWeights[i] = mStarterWeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,192 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Expert Advisor
|
||||
// ----------------------------------------
|
||||
// Name: XEA
|
||||
// Description: this is an expert controller
|
||||
// advisors which provides a mechanism for use them ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XEA"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
input group "Commons";
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Including Providers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Logger Library ...
|
||||
#include "..\Libraries\x-saherelm.log.lib.mq5";
|
||||
|
||||
//
|
||||
// Common Library ...
|
||||
#include "..\Libraries\x-saherelm.common.lib.mq5";
|
||||
|
||||
//
|
||||
// Alert Library ...
|
||||
#include "..\Libraries\x-saherelm.alert.lib.mq5";
|
||||
|
||||
//
|
||||
// Draw Library ...
|
||||
#include "..\Libraries\x-saherelm.draw.lib.mq5";
|
||||
|
||||
//
|
||||
// XEU5 Signal Provider ...
|
||||
#include "..\Providers\x-saherelm.xeu5.provider.lib.mq5";
|
||||
|
||||
//
|
||||
// END Including Providers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
logTag = "XEA";
|
||||
drawPrefix = logTag;
|
||||
alertPrefix = logTag;
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize XEU5 Provider ...
|
||||
if (!XEU5InitSignalProviderLibrary())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Apply default Chart Style for EA ...
|
||||
ApplyChartStyle();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
|
||||
//
|
||||
// De Initialize XEU5 Provider ...
|
||||
XEU5DeinitSignalProviderLibrary(reason);
|
||||
|
||||
//
|
||||
// De Init XDraw Library ...
|
||||
// OnDeinitDrawLibrary();
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
// Prevent Going Forward if user Disable it ...
|
||||
if (!xEU5EnableProvider)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
if (!IsNewCandle())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Processing on XEU5 Signal Provider ...
|
||||
XEU5SignalProviderHandleTick();
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
|
||||
//
|
||||
// Validate XEU5 Provider Inputs ...
|
||||
result = XEU5ValidateInputs();
|
||||
if (!result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Logging State ...
|
||||
string message = "Validation of (" + "XEA" + ") Inputs " + (result ? "Succeeded" : "Failed") + " ...";
|
||||
LogMessage(message);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,956 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XCHLH Oscillator Helper for Signal Providers
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "..\Libraries\x-saherelm.log.lib.mq5"
|
||||
#include "..\Libraries\x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Cycles Enumeration ...
|
||||
enum ENUM_X_XCHLH_CYCLES
|
||||
{
|
||||
X_XCHLH_CYCLE_LONG,
|
||||
X_XCHLH_CYCLE_MEDIUM,
|
||||
X_XCHLH_CYCLE_SHORT,
|
||||
};
|
||||
|
||||
//
|
||||
// XCHLH Hot States ...
|
||||
enum ENUM_X_XCHLH_HOT_STATES
|
||||
{
|
||||
X_XCHLH_HOT_HH = 1,
|
||||
X_XCHLH_NEUTURAL = 0,
|
||||
X_XCHLH_HOT_LL = -1,
|
||||
};
|
||||
|
||||
//
|
||||
// XCHLH Buffer Lines ...
|
||||
enum ENUM_X_XCHLH_BUFFER_LINES
|
||||
{
|
||||
X_XCHLH_LC_HH_LINE = 0,
|
||||
X_XCHLH_LC_LL_LINE = 1,
|
||||
X_XCHLH_MC_HH_LINE = 2,
|
||||
X_XCHLH_MC_LL_LINE = 3,
|
||||
X_XCHLH_SC_HH_LINE = 4,
|
||||
X_XCHLH_SC_LL_LINE = 5,
|
||||
X_XCHLH_SIGNAL_T_LINE = 6,
|
||||
X_XCHLH_SIGNAL_B_LINE = 7,
|
||||
X_XCHLH_HOT_STATE_LINE = 8,
|
||||
};
|
||||
|
||||
//
|
||||
// END Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "XCHLH Oscillator";
|
||||
|
||||
//
|
||||
// Common ...
|
||||
input group "XCHLH Hot Areas";
|
||||
input bool xCHLHDrawHotAreas = false; // Draw Hot Areas Symbol
|
||||
input uchar xCHLHHotHHArrowCode = 234; // Hot HH Arrow Code
|
||||
input color xCHLHHotHHArrowColor = clrAqua; // Hot HH Arrow Color
|
||||
input uchar xCHLHHotLLArrowCode = 233; // Hot LL Arrow Code
|
||||
input color xCHLHHotLLArrowColor = clrFuchsia; // Hot LL Arrow Color
|
||||
|
||||
//
|
||||
// LC Inputs ...
|
||||
input group "XCHLH Long Cycle";
|
||||
input group "XCHLH LC Market";
|
||||
input int xCHLHLcLength = 288; // Length
|
||||
input double xCHLHLcThresholdInPips = 0.3; // Threshold In Pips
|
||||
input ENUM_SERIESMODE xCHLHLcHHMode = MODE_HIGH; // Highest High Calculation Method
|
||||
input ENUM_SERIESMODE xCHLHLcLLMode = MODE_LOW; // Lowest Low Calculation Method
|
||||
input group "XCHLH LC Style";
|
||||
input int xCHLHLcDrawWidth = 1; // Draw Width
|
||||
input ENUM_DRAW_TYPE xCHLHLcDrawType = DRAW_LINE; // Draw Type
|
||||
input ENUM_LINE_STYLE xCHLHLcDrawStyle = STYLE_DOT; // Draw Style
|
||||
input color xCHLHLcHHColor = clrAqua; // Highest High Color
|
||||
input color xCHLHLcLLColor = clrFuchsia; // Lowest Low Color
|
||||
input group "XCHLH LC Drawings";
|
||||
input bool xCHLHLcDrawHH = true; // Draw Highest High
|
||||
input bool xCHLHLcDrawLL = true; // Draw Lowest Low
|
||||
|
||||
//
|
||||
// MC Inputs ...
|
||||
input group "XCHLH Medium Cycle";
|
||||
input group "XCHLH MC Market";
|
||||
input int xCHLHMcLength = 72; // Length
|
||||
input double xCHLHMcThresholdInPips = 0.3; // Threshold In Pips
|
||||
input ENUM_SERIESMODE xCHLHMcHHMode = MODE_HIGH; // Highest High Calculation Method
|
||||
input ENUM_SERIESMODE xCHLHMcLLMode = MODE_LOW; // Lowest Low Calculation Method
|
||||
input group "XCHLH MC Style";
|
||||
input int xCHLHMcDrawWidth = 1; // Draw Width
|
||||
input ENUM_DRAW_TYPE xCHLHMcDrawType = DRAW_LINE; // Draw Type
|
||||
input ENUM_LINE_STYLE xCHLHMcDrawStyle = STYLE_DOT; // Draw Style
|
||||
input color xCHLHMcHHColor = clrLime; // Highest High Color
|
||||
input color xCHLHMcLLColor = clrRed; // Lowest Low Color
|
||||
input group "XCHLH MC Drawings";
|
||||
input bool xCHLHMcDrawHH = true; // Draw Highest High
|
||||
input bool xCHLHMcDrawLL = true; // Draw Lowest Low
|
||||
|
||||
//
|
||||
// SC Inputs ...
|
||||
input group "XCHLH Short Cycle";
|
||||
input group "XCHLH SC Market";
|
||||
input int xCHLHScLength = 7; // Length
|
||||
input double xCHLHScThresholdInPips = 0.3; // Threshold In Pips
|
||||
input ENUM_SERIESMODE xCHLHScHHMode = MODE_HIGH; // Highest High Calculation Method
|
||||
input ENUM_SERIESMODE xCHLHScLLMode = MODE_LOW; // Lowest Low Calculation Method
|
||||
input group "XCHLH SC Style";
|
||||
input int xCHLHScDrawWidth = 1; // Draw Width
|
||||
input ENUM_DRAW_TYPE xCHLHScDrawType = DRAW_LINE; // Draw Type
|
||||
input ENUM_LINE_STYLE xCHLHScDrawStyle = STYLE_DOT; // Draw Style
|
||||
input color xCHLHScHHColor = clrLightBlue; // Highest High Color
|
||||
input color xCHLHScLLColor = clrLightSalmon; // Lowest Low Color
|
||||
input group "XCHLH SC Drawings";
|
||||
input bool xCHLHScDrawHH = true; // Draw Highest High
|
||||
input bool xCHLHScDrawLL = true; // Draw Lowest Low
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
int xCHLHHandler = INVALID_HANDLE;
|
||||
double xCHLHLcHHBuffer[];
|
||||
double xCHLHLcLLBuffer[];
|
||||
double xCHLHMcHHBuffer[];
|
||||
double xCHLHMcLLBuffer[];
|
||||
double xCHLHScHHBuffer[];
|
||||
double xCHLHScLLBuffer[];
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Handler Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Init Oscillators ...
|
||||
bool XCHLHInitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator/Oscillator Handlers ...
|
||||
ResetLastError();
|
||||
|
||||
//
|
||||
// XCHLH Handler ...
|
||||
ArraySetAsSeries(xCHLHLcHHBuffer, true);
|
||||
ArraySetAsSeries(xCHLHLcLLBuffer, true);
|
||||
ArraySetAsSeries(xCHLHMcHHBuffer, true);
|
||||
ArraySetAsSeries(xCHLHMcLLBuffer, true);
|
||||
ArraySetAsSeries(xCHLHScHHBuffer, true);
|
||||
ArraySetAsSeries(xCHLHScLLBuffer, true);
|
||||
xCHLHHandler = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
"x-saherelm.xchlh.oscillator",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Commons ...
|
||||
"",
|
||||
xCHLHDrawHotAreas,
|
||||
xCHLHHotHHArrowCode,
|
||||
xCHLHHotHHArrowColor,
|
||||
xCHLHHotLLArrowCode,
|
||||
xCHLHHotLLArrowColor,
|
||||
//
|
||||
// LC ...
|
||||
"",
|
||||
"",
|
||||
xCHLHLcLength,
|
||||
xCHLHLcThresholdInPips,
|
||||
xCHLHLcHHMode,
|
||||
xCHLHLcLLMode,
|
||||
"",
|
||||
xCHLHLcDrawWidth,
|
||||
xCHLHLcDrawType,
|
||||
xCHLHLcDrawStyle,
|
||||
xCHLHLcHHColor,
|
||||
xCHLHLcLLColor,
|
||||
"",
|
||||
xCHLHLcDrawHH,
|
||||
xCHLHLcDrawLL,
|
||||
//
|
||||
// MC ...
|
||||
"",
|
||||
"",
|
||||
xCHLHMcLength,
|
||||
xCHLHMcThresholdInPips,
|
||||
xCHLHMcHHMode,
|
||||
xCHLHMcLLMode,
|
||||
"",
|
||||
xCHLHMcDrawWidth,
|
||||
xCHLHMcDrawType,
|
||||
xCHLHMcDrawStyle,
|
||||
xCHLHMcHHColor,
|
||||
xCHLHMcLLColor,
|
||||
"",
|
||||
xCHLHMcDrawHH,
|
||||
xCHLHMcDrawLL,
|
||||
//
|
||||
// SC ...
|
||||
"",
|
||||
"",
|
||||
xCHLHScLength,
|
||||
xCHLHScThresholdInPips,
|
||||
xCHLHScHHMode,
|
||||
xCHLHScLLMode,
|
||||
"",
|
||||
xCHLHScDrawWidth,
|
||||
xCHLHScDrawType,
|
||||
xCHLHScDrawStyle,
|
||||
xCHLHScHHColor,
|
||||
xCHLHScLLColor,
|
||||
"",
|
||||
xCHLHScDrawHH,
|
||||
xCHLHScDrawLL);
|
||||
if (xCHLHHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
LogMessage("failed to Initialize XCHLH Indicator: " + (string)GetLastError());
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Release Oscillators ...
|
||||
void XCHLHReleaseHandlers()
|
||||
{
|
||||
IndicatorRelease(xCHLHHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Reading Buffers ...
|
||||
void XCHLHReadBuffers(
|
||||
int xCHLHItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
// XCHLH LC HH Buffer ...
|
||||
CopyBuffer(
|
||||
xCHLHHandler,
|
||||
X_XCHLH_LC_HH_LINE,
|
||||
0,
|
||||
xCHLHItemsPerTick,
|
||||
xCHLHLcHHBuffer);
|
||||
|
||||
//
|
||||
// XCHLH LC LL Buffer ...
|
||||
CopyBuffer(
|
||||
xCHLHHandler,
|
||||
X_XCHLH_LC_LL_LINE,
|
||||
0,
|
||||
xCHLHItemsPerTick,
|
||||
xCHLHLcLLBuffer);
|
||||
|
||||
//
|
||||
// XCHLH MC HH Buffer ...
|
||||
CopyBuffer(
|
||||
xCHLHHandler,
|
||||
X_XCHLH_MC_HH_LINE,
|
||||
0,
|
||||
xCHLHItemsPerTick,
|
||||
xCHLHMcHHBuffer);
|
||||
|
||||
//
|
||||
// XCHLH MC LL Buffer ...
|
||||
CopyBuffer(
|
||||
xCHLHHandler,
|
||||
X_XCHLH_MC_LL_LINE,
|
||||
0,
|
||||
xCHLHItemsPerTick,
|
||||
xCHLHMcLLBuffer);
|
||||
|
||||
//
|
||||
// XCHLH SC HH Buffer ...
|
||||
CopyBuffer(
|
||||
xCHLHHandler,
|
||||
X_XCHLH_SC_HH_LINE,
|
||||
0,
|
||||
xCHLHItemsPerTick,
|
||||
xCHLHScHHBuffer);
|
||||
|
||||
//
|
||||
// XCHLH SC LL Buffer ...
|
||||
CopyBuffer(
|
||||
xCHLHHandler,
|
||||
X_XCHLH_SC_LL_LINE,
|
||||
0,
|
||||
xCHLHItemsPerTick,
|
||||
xCHLHScLLBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// END Handler Funcions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XCHLH Custom Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Check LC and MC has Same HH ...
|
||||
bool XCHLHIsLCMCHasSameHH(
|
||||
int bar_index // Specified Bar Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double lcValue = xCHLHLcHHBuffer[bar_index];
|
||||
double mcValue = xCHLHMcHHBuffer[bar_index];
|
||||
|
||||
//
|
||||
result = lcValue == mcValue;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check LC and MC has Same LL ...
|
||||
bool XCHLHIsLCMCHasSameLL(
|
||||
int bar_index // Specified Bar Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double lcValue = xCHLHLcLLBuffer[bar_index];
|
||||
double mcValue = xCHLHMcLLBuffer[bar_index];
|
||||
|
||||
//
|
||||
result = lcValue == mcValue;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check LC and SC has Same HH ...
|
||||
bool XCHLHIsLCSCHasSameHH(
|
||||
int bar_index // Specified Bar Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double lcValue = xCHLHLcHHBuffer[bar_index];
|
||||
double scValue = xCHLHScHHBuffer[bar_index];
|
||||
|
||||
//
|
||||
result = lcValue == scValue;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check LC and SC has Same LL ...
|
||||
bool XCHLHIsLCSCHasSameLL(
|
||||
int bar_index // Specified Bar Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double lcValue = xCHLHLcLLBuffer[bar_index];
|
||||
double scValue = xCHLHScLLBuffer[bar_index];
|
||||
|
||||
//
|
||||
result = lcValue == scValue;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check MC and SC has Same HH ...
|
||||
bool XCHLHIsMCSCHasSameHH(
|
||||
int bar_index // Specified Bar Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double mcValue = xCHLHMcHHBuffer[bar_index];
|
||||
double scValue = xCHLHScHHBuffer[bar_index];
|
||||
|
||||
//
|
||||
result = mcValue == scValue;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check MC and SC has Same LL ...
|
||||
bool XCHLHIsMCSCHasSameLL(
|
||||
int bar_index // Specified Bar Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double mcValue = xCHLHMcLLBuffer[bar_index];
|
||||
double scValue = xCHLHScLLBuffer[bar_index];
|
||||
|
||||
//
|
||||
result = mcValue == scValue;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Is Same Highest Highs ...
|
||||
bool XCHLHIsSameHHs(
|
||||
int bar_index // Specified Bar Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double lcValue = xCHLHLcHHBuffer[bar_index];
|
||||
double mcValue = xCHLHMcHHBuffer[bar_index];
|
||||
double scValue = xCHLHScHHBuffer[bar_index];
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
lcValue == mcValue &&
|
||||
mcValue == scValue
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Is Same Lowest Lows ...
|
||||
bool XCHLHIsSameLLs(
|
||||
int bar_index // Specified Bar Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double lcValue = xCHLHLcLLBuffer[bar_index];
|
||||
double mcValue = xCHLHMcLLBuffer[bar_index];
|
||||
double scValue = xCHLHScLLBuffer[bar_index];
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
lcValue == mcValue &&
|
||||
mcValue == scValue
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Medium Cycle is On Top of Long Cycle's Mid ...
|
||||
bool XCHLHIsMCOnTopOfLC(
|
||||
int bar_index // Specified Bar Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
bar_index < 0 ||
|
||||
!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
ENUM_X_XCHLH_CYCLES sCycle = X_XCHLH_CYCLE_MEDIUM;
|
||||
ENUM_X_XCHLH_CYCLES dCycle = X_XCHLH_CYCLE_LONG;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
XCHLHCheckCycleIsOnTopOfAnother(
|
||||
bar_index,
|
||||
sCycle,
|
||||
dCycle)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Medium Cycle is In Bottom of Long Cycle's Mid ...
|
||||
bool XCHLHIsMCInBottomOfLC(
|
||||
int bar_index // Specified Bar Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
bar_index < 0 ||
|
||||
!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
ENUM_X_XCHLH_CYCLES sCycle = X_XCHLH_CYCLE_MEDIUM;
|
||||
ENUM_X_XCHLH_CYCLES dCycle = X_XCHLH_CYCLE_LONG;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
XCHLHCheckCycleIsInBottomOfAnother(
|
||||
bar_index,
|
||||
sCycle,
|
||||
dCycle)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check and Validate Buffer Sizes ...
|
||||
bool XCHLHIsValidBufferSizes(
|
||||
int size // Specified Min Size
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
ArraySize(xCHLHLcHHBuffer) > size &&
|
||||
ArraySize(xCHLHLcLLBuffer) > size &&
|
||||
//
|
||||
ArraySize(xCHLHMcHHBuffer) > size &&
|
||||
ArraySize(xCHLHMcLLBuffer) > size &&
|
||||
//
|
||||
ArraySize(xCHLHScHHBuffer) > size &&
|
||||
ArraySize(xCHLHScLLBuffer) > size;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Get Cycle Middle Value ...
|
||||
double XCHLHGetCycleMid(
|
||||
int bar_index, // Specified Bar Index ...
|
||||
ENUM_X_XCHLH_CYCLES cycle // Specified Cycle ...
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
bar_index < 0 ||
|
||||
!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Cycle Max Value ...
|
||||
double iMax = XCHLHGetCycleMax(
|
||||
bar_index,
|
||||
cycle);
|
||||
|
||||
//
|
||||
// Retrieve Cycle Min Value ...
|
||||
double iMin = XCHLHGetCycleMin(
|
||||
bar_index,
|
||||
cycle);
|
||||
|
||||
//
|
||||
result = (iMax - iMin) / 2;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Get Cycle Max Value ...
|
||||
double XCHLHGetCycleMax(
|
||||
int bar_index, // Specified Bar Index ...
|
||||
ENUM_X_XCHLH_CYCLES cycle // Specified Cycle ...
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
bar_index < 0 ||
|
||||
!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
switch (cycle)
|
||||
{
|
||||
//
|
||||
// Long Cycle ...
|
||||
case X_XCHLH_CYCLE_LONG:
|
||||
result = xCHLHLcHHBuffer[1];
|
||||
break;
|
||||
|
||||
//
|
||||
// Medium Cycle ...
|
||||
case X_XCHLH_CYCLE_MEDIUM:
|
||||
result = xCHLHMcHHBuffer[1];
|
||||
break;
|
||||
|
||||
//
|
||||
// Short Cycle ...
|
||||
case X_XCHLH_CYCLE_SHORT:
|
||||
result = xCHLHScHHBuffer[1];
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Get Specified Cycles Max Value ...
|
||||
double XCHLHGetCyclesMax(
|
||||
int bar_index, // Specified Bar Index ...
|
||||
ENUM_X_XCHLH_CYCLES &cycles[] // Specified Cycle ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = 0;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
bar_index < 0 ||
|
||||
ArraySize(cycles) <= 0 ||
|
||||
!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through Cycles ...
|
||||
for (int i = 0; i < ArraySize(cycles); i++)
|
||||
{
|
||||
//
|
||||
ENUM_X_XCHLH_CYCLES iCycle = cycles[i];
|
||||
|
||||
//
|
||||
double iValue = XCHLHGetCycleMax(
|
||||
bar_index,
|
||||
iCycle);
|
||||
|
||||
//
|
||||
result = result == 0 || result < iValue ? iValue : result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Get Cycle Min Value ...
|
||||
double XCHLHGetCycleMin(
|
||||
int bar_index, // Specified Bar Index ...
|
||||
ENUM_X_XCHLH_CYCLES cycle // Specified Cycle ...
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
bar_index < 0 ||
|
||||
!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
switch (cycle)
|
||||
{
|
||||
//
|
||||
// Long Cycle ...
|
||||
case X_XCHLH_CYCLE_LONG:
|
||||
result = xCHLHLcLLBuffer[1];
|
||||
break;
|
||||
|
||||
//
|
||||
// Medium Cycle ...
|
||||
case X_XCHLH_CYCLE_MEDIUM:
|
||||
result = xCHLHMcLLBuffer[1];
|
||||
break;
|
||||
|
||||
//
|
||||
// Short Cycle ...
|
||||
case X_XCHLH_CYCLE_SHORT:
|
||||
result = xCHLHScLLBuffer[1];
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Get Specified Cycles Min Value ...
|
||||
double XCHLHGetCyclesMin(
|
||||
int bar_index, // Specified Bar Index ...
|
||||
ENUM_X_XCHLH_CYCLES &cycles[] // Specified Cycle ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = 0;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
bar_index < 0 ||
|
||||
ArraySize(cycles) <= 0 ||
|
||||
!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through Cycles ...
|
||||
for (int i = 0; i < ArraySize(cycles); i++)
|
||||
{
|
||||
//
|
||||
ENUM_X_XCHLH_CYCLES iCycle = cycles[i];
|
||||
|
||||
//
|
||||
double iValue = XCHLHGetCycleMin(
|
||||
bar_index,
|
||||
iCycle);
|
||||
|
||||
//
|
||||
result = result == 0 || result > iValue ? iValue : result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check a Cycle is On Top of Another Cycle's Mid ...
|
||||
bool XCHLHCheckCycleIsOnTopOfAnother(
|
||||
int bar_index, // Specified Bar Index ...
|
||||
ENUM_X_XCHLH_CYCLES sourceCycle, // Specified Source Cycle which Checks ...
|
||||
ENUM_X_XCHLH_CYCLES destCycle // Specified Dest Cycle which source Checked based on it ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
bar_index < 0 ||
|
||||
!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Min Value of Source Cycle ...
|
||||
double iMin = XCHLHGetCycleMin(
|
||||
bar_index,
|
||||
sourceCycle);
|
||||
|
||||
//
|
||||
// Retrieve Mid Value of Dest Cycle ...
|
||||
double iMid = XCHLHGetCycleMid(
|
||||
bar_index,
|
||||
destCycle);
|
||||
|
||||
//
|
||||
// Generate Result ...
|
||||
result =
|
||||
//
|
||||
iMin >= iMid
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check a Cycle is Under Bottom of Another Cycle's Mid ...
|
||||
bool XCHLHCheckCycleIsInBottomOfAnother(
|
||||
int bar_index, // Specified Bar Index ...
|
||||
ENUM_X_XCHLH_CYCLES sourceCycle, // Specified Source Cycle which Checks ...
|
||||
ENUM_X_XCHLH_CYCLES destCycle // Specified Dest Cycle which source Checked based on it ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
bar_index < 0 ||
|
||||
!XCHLHIsValidBufferSizes(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Max Value of Source Cycle ...
|
||||
double iMax = XCHLHGetCycleMax(
|
||||
bar_index,
|
||||
sourceCycle);
|
||||
|
||||
//
|
||||
// Retrieve Mid Value of Dest Cycle ...
|
||||
double iMid = XCHLHGetCycleMid(
|
||||
bar_index,
|
||||
destCycle);
|
||||
|
||||
//
|
||||
// Generate Result ...
|
||||
result =
|
||||
//
|
||||
iMax <= iMid
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END XCHLH Custom Functions ...
|
||||
//
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,640 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XLH Indicator Helper for Signal Providers
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "..\Libraries\x-saherelm.log.lib.mq5"
|
||||
#include "..\Libraries\x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// XLH Indicator Buffer Lines ...
|
||||
enum ENUM_X_XLH_BUFFER_LINES
|
||||
{
|
||||
X_XLH_HH_LINE = 0,
|
||||
X_XLH_LL_LINE = 1,
|
||||
X_XLH_SIGNAL_LINE = 2,
|
||||
};
|
||||
|
||||
//
|
||||
// END Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
input group "XLH Indicator";
|
||||
input int xLHLength = 72; // Length
|
||||
input ENUM_SERIESMODE xLHHHMode = MODE_HIGH; // Highest High Calculation Method
|
||||
input ENUM_SERIESMODE xLHLLMode = MODE_LOW; // Lowest Low Calculation Method
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
int xLHHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
double xLHHHBuffer[];
|
||||
double xLHLLBuffer[];
|
||||
double xLHSignalBuffer[];
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Handler Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Init Indicators ...
|
||||
bool XLHInitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator/Oscillator Handlers ...
|
||||
ResetLastError();
|
||||
|
||||
//
|
||||
// XLH Handler ...
|
||||
ArraySetAsSeries(xLHHHBuffer, true);
|
||||
ArraySetAsSeries(xLHLLBuffer, true);
|
||||
ArraySetAsSeries(xLHSignalBuffer, true);
|
||||
|
||||
//
|
||||
xLHHandler = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
"x-saherelm.xlh.indicator",
|
||||
//
|
||||
// Inputs ...
|
||||
xLHLength,
|
||||
xLHHHMode,
|
||||
xLHLLMode
|
||||
//
|
||||
);
|
||||
if (xLHHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
LogMessage("failed to Initialize XLH Indicator: " + (string)GetLastError());
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Release Indicators ...
|
||||
void XLHReleaseHandlers()
|
||||
{
|
||||
IndicatorRelease(xLHHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Reading Buffers ...
|
||||
void XLHReadBuffers(
|
||||
int xLHItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
// HH Buffer ...
|
||||
CopyBuffer(
|
||||
xLHHandler,
|
||||
X_XLH_HH_LINE,
|
||||
0,
|
||||
xLHItemsPerTick,
|
||||
xLHHHBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// LL Buffer ...
|
||||
CopyBuffer(
|
||||
xLHHandler,
|
||||
X_XLH_LL_LINE,
|
||||
0,
|
||||
xLHItemsPerTick,
|
||||
xLHLLBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Signal Buffer ...
|
||||
CopyBuffer(
|
||||
xLHHandler,
|
||||
X_XLH_SIGNAL_LINE,
|
||||
0,
|
||||
xLHItemsPerTick,
|
||||
xLHSignalBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// END Handler Funcions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XLH Custom Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// TODO: What we have to Implement ...
|
||||
// - []
|
||||
|
||||
//
|
||||
// Check Candle High is HH ...
|
||||
bool XLHIsHighAttachedHH(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL candle = GetCandle(bar_index);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
candle.high == xLHHHBuffer[bar_index]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Candle Low is LL ...
|
||||
bool XLHIsLowAttachedLL(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL candle = GetCandle(bar_index);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
candle.low == xLHLLBuffer[bar_index]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Price Jumping Up Signal ...
|
||||
bool XLHIsPriceCrossedOverSignal(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL candle1 = GetCandle(bar_index);
|
||||
XOHCL candle2 = GetCandle(bar_index + 1);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
candle1.low > xLHSignalBuffer[bar_index] &&
|
||||
candle2.low < xLHSignalBuffer[bar_index + 1]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Price Over Signal ...
|
||||
bool XLHIsPriceOverSignal(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL candle1 = GetCandle(bar_index);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
candle1.low > xLHSignalBuffer[bar_index]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Price Jumping Down Signal ...
|
||||
bool XLHIsPriceCrossedUnderSignal(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL candle1 = GetCandle(bar_index);
|
||||
XOHCL candle2 = GetCandle(bar_index + 1);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
candle1.high < xLHSignalBuffer[bar_index] &&
|
||||
candle2.high > xLHSignalBuffer[bar_index + 1]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Price Down Signal ...
|
||||
bool XLHIsPriceUnderSignal(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL candle1 = GetCandle(bar_index);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
candle1.high < xLHSignalBuffer[bar_index]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Price Ranging Signal ...
|
||||
bool XLHIsPriceInSignalRange(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL candle1 = GetCandle(bar_index);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
candle1.high > xLHSignalBuffer[bar_index] &&
|
||||
candle1.low < xLHSignalBuffer[bar_index]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check HH Increased ...
|
||||
bool XLHIsHHIncreased(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xLHHHBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check HH Decreased ...
|
||||
bool XLHIsHHDecreased(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xLHHHBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check LL Increased ...
|
||||
bool XLHIsLLIncreased(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xLHLLBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check LL Decreased ...
|
||||
bool XLHIsLLDecreased(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xLHLLBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check HH Same in Length ...
|
||||
bool XLHIsHHSameInLength(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 5 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double value1 = xLHHHBuffer[bar_index];
|
||||
|
||||
//
|
||||
// Loop ...
|
||||
result = true;
|
||||
for (int i = bar_index + 1; i < bar_index + length + 1; i++) {
|
||||
//
|
||||
double iValue = xLHHHBuffer[i];
|
||||
if (iValue != value1) {
|
||||
//
|
||||
result = false;
|
||||
|
||||
//
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check LL Same in Length ...
|
||||
bool XLHIsLLSameInLength(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 5 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XLHIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double value1 = xLHLLBuffer[bar_index];
|
||||
|
||||
//
|
||||
// Loop ...
|
||||
result = true;
|
||||
for (int i = bar_index + 1; i < bar_index + length + 1; i++) {
|
||||
//
|
||||
double iValue = xLHLLBuffer[i];
|
||||
if (iValue != value1) {
|
||||
//
|
||||
result = false;
|
||||
|
||||
//
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check all Buffers has valid Size ...
|
||||
bool XLHIsValidBuffersSize(
|
||||
int size // the size of buffers which min size for requirements
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
size <= 0 ||
|
||||
//
|
||||
ArraySize(xLHHHBuffer) < size ||
|
||||
ArraySize(xLHLLBuffer) < size ||
|
||||
ArraySize(xLHSignalBuffer) < size
|
||||
//
|
||||
)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END XLH Custom Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,219 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XOBD Indicator Helper for Signal Providers
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "..\Libraries\x-saherelm.log.lib.mq5"
|
||||
#include "..\Libraries\x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
input group "XOBD Indicator";
|
||||
input int xOBDLength = 5; // Swing Length
|
||||
input uchar xOBDSwingHighArrowCode = 108; // Swing High Arrow Code
|
||||
input color xOBDSwingHighArrowColor = clrMagenta; // Swing High Arrow Color
|
||||
input uchar xOBDSwingLowArrowCode = 108; // Swing Low Arrow Code
|
||||
input color xOBDSwingLowArrowColor = clrAqua; // Swing Low Arrow Color
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
int xOBDHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
double xOBDBuffer[];
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Handler Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Init Indicators ...
|
||||
bool XOBDInitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator/Oscillator Handlers ...
|
||||
ResetLastError();
|
||||
|
||||
//
|
||||
// XOBD Handler ...
|
||||
ArraySetAsSeries(xOBDBuffer, true);
|
||||
|
||||
//
|
||||
xOBDHandler = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
"x-saherelm.xobd.indicator",
|
||||
//
|
||||
// Inputs ...
|
||||
xOBDLength,
|
||||
xOBDSwingHighArrowCode,
|
||||
xOBDSwingHighArrowColor,
|
||||
xOBDSwingLowArrowCode,
|
||||
xOBDSwingLowArrowColor
|
||||
//
|
||||
);
|
||||
if (xOBDHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
LogMessage("failed to Initialize XOBD Indicator: " + (string)GetLastError());
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Release Indicators ...
|
||||
void XOBDReleaseHandlers()
|
||||
{
|
||||
IndicatorRelease(xOBDHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Reading Buffers ...
|
||||
void XOBDReadBuffers(
|
||||
int xOBDItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
// OBD Buffer ...
|
||||
CopyBuffer(
|
||||
xOBDHandler,
|
||||
0,
|
||||
0,
|
||||
xOBDItemsPerTick,
|
||||
xOBDBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// END Handler Funcions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XOBD Custom Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Check is Swing Low Occured or not ...
|
||||
bool XOBDIsSwingLow(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XOBDIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = xOBDBuffer[bar_index] == X_SWING_LOW;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check is Swing High Occured or not ...
|
||||
bool XOBDIsSwingHigh(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XOBDIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = xOBDBuffer[bar_index] == X_SWING_HIGH;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check all Buffers has valid Size ...
|
||||
bool XOBDIsValidBuffersSize(
|
||||
int size // the size of buffers which min size for requirements
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
size <= 0 ||
|
||||
//
|
||||
ArraySize(xOBDBuffer) < size
|
||||
//
|
||||
)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END XOBD Custom Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,383 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XRSI Oscillator Helper for Signal Providers
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "..\Libraries\x-saherelm.log.lib.mq5"
|
||||
#include "..\Libraries\x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// XRSI Oscillator Buffer Lines ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
input group "XRSI Oscillator";
|
||||
|
||||
//
|
||||
input group "XRSI Market";
|
||||
input int xRSILength = 18; // Market Length
|
||||
input ENUM_APPLIED_PRICE xRSIAppliedTo = PRICE_OPEN; // Applied To
|
||||
|
||||
//
|
||||
input group "XRSI Short Entry";
|
||||
input double xRSIShortEntryValue = 70; // Short Entry Level
|
||||
input color xRSIShortEntryColor = clrRed; // Short Entry Level Color
|
||||
input ENUM_LINE_STYLE xRSIShortEntryLineStyle = STYLE_SOLID; // Short Entry Style
|
||||
|
||||
//
|
||||
input group "XRSI Short Exit";
|
||||
input double xRSIShortExitValue = 40; // Short Exit Level
|
||||
input color xRSIShortExitColor = clrFuchsia; // Short Exit Level Color
|
||||
input ENUM_LINE_STYLE xRSIShortExitLineStyle = STYLE_DOT; // Short Exit Style
|
||||
|
||||
//
|
||||
input group "XRSI Long Entry";
|
||||
input double xRSILongEntryValue = 30; // Long Entry Level
|
||||
input color xRSILongEntryColor = clrGreen; // Long Entry Level Color
|
||||
input ENUM_LINE_STYLE xRSILongEntryLineStyle = STYLE_SOLID; // Long Entry Style
|
||||
|
||||
//
|
||||
input group "XRSI Long Exit";
|
||||
input double xRSILongExitValue = 60; // Long Exit Level
|
||||
input color xRSILongExitColor = clrAqua; // Long Exit Level Color
|
||||
input ENUM_LINE_STYLE xRSILongExitLineStyle = STYLE_DOT; // Long Exit Style
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
int xRSIHandler = INVALID_HANDLE;
|
||||
double xRSIBuffer[];
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Handler Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Init Oscillators ...
|
||||
bool XRSIInitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator/Oscillator Handlers ...
|
||||
ResetLastError();
|
||||
|
||||
//
|
||||
// XRSI Handler ...
|
||||
ArraySetAsSeries(xRSIBuffer, true);
|
||||
xRSIHandler = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
"x-saherelm.xrsi.oscillator",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Market ...
|
||||
"",
|
||||
xRSILength,
|
||||
xRSIAppliedTo,
|
||||
//
|
||||
// Short Entry ...
|
||||
"",
|
||||
xRSIShortEntryValue,
|
||||
xRSIShortEntryColor,
|
||||
xRSIShortEntryLineStyle,
|
||||
//
|
||||
// Short Exit ...
|
||||
"",
|
||||
xRSIShortExitValue,
|
||||
xRSIShortExitColor,
|
||||
xRSIShortExitLineStyle,
|
||||
//
|
||||
// Long Entry ...
|
||||
"",
|
||||
xRSILongEntryValue,
|
||||
xRSILongEntryColor,
|
||||
xRSILongEntryLineStyle,
|
||||
//
|
||||
// Long Exit ...
|
||||
"",
|
||||
xRSILongExitValue,
|
||||
xRSILongExitColor,
|
||||
xRSILongExitLineStyle
|
||||
//
|
||||
);
|
||||
if (xRSIHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
LogMessage("failed to Initialize XRSI Oscillator: " + (string)GetLastError());
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Release Oscillators ...
|
||||
void XRSIReleaseHandlers()
|
||||
{
|
||||
IndicatorRelease(xRSIHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Reading Buffers ...
|
||||
void XRSIReadBuffers(
|
||||
int xRSIItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
// XRSI Signal ...
|
||||
CopyBuffer(
|
||||
xRSIHandler,
|
||||
0,
|
||||
0,
|
||||
xRSIItemsPerTick,
|
||||
xRSIBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// END Handler Funcions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XRSI Custom Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Check SC is Peak ...
|
||||
bool XRSIIsPeak(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XRSIIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Must Decreasing ...
|
||||
bool isIncreasing = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xRSIBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check SC is Vale ...
|
||||
bool XRSIIsVale(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XRSIIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xRSIBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// RSI Value GO Up from Long Entry ...
|
||||
bool XRSIIsCrossedOverLongEntry(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XRSIIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
xRSIBuffer[bar_index + 1] > xRSILongEntryValue &&
|
||||
xRSIBuffer[bar_index + 2] <= xRSILongEntryValue;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// RSI Value GO Up from Long Exit ...
|
||||
bool XRSIIsCrossedOverLongExit(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XRSIIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
xRSIBuffer[bar_index + 1] > xRSILongExitValue &&
|
||||
xRSIBuffer[bar_index + 2] <= xRSILongExitValue;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// RSI Value Go Down Short Entry ...
|
||||
bool XRSIIsCrossedUnderShortEntry(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XRSIIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
xRSIBuffer[bar_index + 1] < xRSIShortEntryValue &&
|
||||
xRSIBuffer[bar_index + 2] >= xRSIShortEntryValue;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// RSI Value Go Down Short Exit ...
|
||||
bool XRSIIsCrossedUnderShortExit(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XRSIIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
xRSIBuffer[bar_index + 1] < xRSIShortExitValue &&
|
||||
xRSIBuffer[bar_index + 2] >= xRSIShortExitValue;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check all Buffers has valid Size ...
|
||||
bool XRSIIsValidBuffersSize(
|
||||
int size // the size of buffers which min size for requirements
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
size <= 0 ||
|
||||
//
|
||||
ArraySize(xRSIBuffer) < size
|
||||
//
|
||||
)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END XRSI Custom Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,900 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XTD Oscillator Helper for Signal Providers
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "..\Libraries\x-saherelm.log.lib.mq5"
|
||||
#include "..\Libraries\x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// XTD Oscillator States ...
|
||||
enum ENUM_X_XTD_STATES
|
||||
{
|
||||
X_XTD_BULLISH_CROSSED_OVER_BEARISH = 2,
|
||||
X_XTD_BULLISH_OVER_BEARISH = 1,
|
||||
X_XTD_NEUTURAL = 0,
|
||||
X_XTD_BULLISH_UNDER_BEARISH = -1,
|
||||
X_XTD_BULLISH_CROSSED_UNDER_BEARISH = -2
|
||||
};
|
||||
|
||||
//
|
||||
// XTD Oscillator Buffer Lines ...
|
||||
enum ENUM_X_XTD_BUFFER_LINES
|
||||
{
|
||||
X_XTD_BULLISH_POWER_LINE = 0,
|
||||
X_XTD_BEARISH_POWER_LINE = 1,
|
||||
X_XTD_SIGNAL_LINE = 2,
|
||||
};
|
||||
|
||||
//
|
||||
// END Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
input group "XTD Oscillator";
|
||||
input int xTDLength = 18; // Market Length
|
||||
input bool xTDDrawCrosses = false; // Draw Cross Arrows
|
||||
input uchar xTDBullishArrowCode = 228; // Cross Over Arrow Code
|
||||
input color xTDBullishArrowColor = clrAqua; // Cross Over Arrow Color
|
||||
input uchar xTDBearishArrowCode = 230; // Cross Under Arrow Code
|
||||
input color xTDBearishArrowColor = clrMagenta; // Cross Under Arrow Color
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
int xTDHandler = INVALID_HANDLE;
|
||||
double xTDBullishBuffer[];
|
||||
double xTDBearishBuffer[];
|
||||
double xTDSignalBuffer[];
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Handler Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Init Oscillators ...
|
||||
bool XTDInitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator/Oscillator Handlers ...
|
||||
ResetLastError();
|
||||
|
||||
//
|
||||
// XTD Handler ...
|
||||
ArraySetAsSeries(xTDBullishBuffer, true);
|
||||
ArraySetAsSeries(xTDBearishBuffer, true);
|
||||
ArraySetAsSeries(xTDSignalBuffer, true);
|
||||
xTDHandler = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
"x-saherelm.xtd.oscillator",
|
||||
//
|
||||
// Inputs ...
|
||||
xTDLength,
|
||||
xTDDrawCrosses,
|
||||
xTDBullishArrowCode,
|
||||
xTDBullishArrowColor,
|
||||
xTDBearishArrowCode,
|
||||
xTDBearishArrowColor);
|
||||
if (xTDHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
LogMessage("failed to Initialize XTD Oscillator: " + (string)GetLastError());
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Release Oscillators ...
|
||||
void XTDReleaseHandlers()
|
||||
{
|
||||
IndicatorRelease(xTDHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Reading Buffers ...
|
||||
void XTDReadBuffers(
|
||||
int xTDItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
// XTD Bullish Buffer ...
|
||||
CopyBuffer(
|
||||
xTDHandler,
|
||||
X_XTD_BULLISH_POWER_LINE,
|
||||
0,
|
||||
xTDItemsPerTick,
|
||||
xTDBullishBuffer);
|
||||
|
||||
//
|
||||
// XTD Bullish Buffer ...
|
||||
CopyBuffer(
|
||||
xTDHandler,
|
||||
X_XTD_BEARISH_POWER_LINE,
|
||||
0,
|
||||
xTDItemsPerTick,
|
||||
xTDBearishBuffer);
|
||||
|
||||
//
|
||||
// XTD Signal Buffer ...
|
||||
CopyBuffer(
|
||||
xTDHandler,
|
||||
X_XTD_SIGNAL_LINE,
|
||||
0,
|
||||
xTDItemsPerTick,
|
||||
xTDSignalBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// END Handler Funcions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XTD Custom Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Check Signal Vale ...
|
||||
bool XTDIsSignalVale(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xTDSignalBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Peak ...
|
||||
bool XTDIsSignalPeak(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Must Decreasing ...
|
||||
bool isIncreasing = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xTDSignalBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Vale ...
|
||||
bool XTDIsBullishVale(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xTDBullishBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Peak ...
|
||||
bool XTDIsBullishPeak(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Must Decreasing ...
|
||||
bool isIncreasing = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xTDBullishBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Vale ...
|
||||
bool XTDIsBearishVale(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xTDBearishBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Peak ...
|
||||
bool XTDIsBearishPeak(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Must Decreasing ...
|
||||
bool isIncreasing = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xTDBearishBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Peak ...
|
||||
|
||||
//
|
||||
// Check Bullish Crossed Over Bearish ...
|
||||
bool XTDIsBullCrossedOverBear(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsCrossOver(
|
||||
xTDBullishBuffer,
|
||||
xTDBearishBuffer,
|
||||
1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Bullish Over Bearish ...
|
||||
bool XTDIsBullOverBear(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsOver(
|
||||
xTDBullishBuffer,
|
||||
xTDBearishBuffer,
|
||||
1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Bullish Crossed Under Bearish ...
|
||||
bool XTDIsBullCrossedUnderBear(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsCrossUnder(
|
||||
xTDBullishBuffer,
|
||||
xTDBearishBuffer,
|
||||
1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Bullish Under Bearish ...
|
||||
bool XTDIsBullUnderBear(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsUnder(
|
||||
xTDBullishBuffer,
|
||||
xTDBearishBuffer,
|
||||
1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Crossed Over Bearish ...
|
||||
bool XTDIsSignalCrossedOverBear(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsCrossOver(
|
||||
xTDSignalBuffer,
|
||||
xTDBearishBuffer,
|
||||
1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Over Bearish ...
|
||||
bool XTDIsSignalOverBear(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsOver(
|
||||
xTDSignalBuffer,
|
||||
xTDBearishBuffer,
|
||||
1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Crossed Under Bearish ...
|
||||
bool XTDIsSignalCrossedUnderBear(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsCrossUnder(
|
||||
xTDSignalBuffer,
|
||||
xTDBearishBuffer,
|
||||
1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Under Bearish ...
|
||||
bool XTDIsSignalUnderBear(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTDIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsUnder(
|
||||
xTDSignalBuffer,
|
||||
xTDBearishBuffer,
|
||||
1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check all Buffers has valid Size ...
|
||||
bool XTDIsValidBuffersSize(
|
||||
int size // the size of buffers which min size for requirements
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
size <= 0 ||
|
||||
ArraySize(xTDBullishBuffer) < size ||
|
||||
ArraySize(xTDBullishBuffer) < size ||
|
||||
ArraySize(xTDSignalBuffer) < size)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Count Signal Crossed Over Bear ...
|
||||
int XTDCountSignalCrossedOverBearIndex(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
count <= bar_index + 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through ...
|
||||
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||
{
|
||||
//
|
||||
// Check Cross On i Point ...
|
||||
bool isCrossedOnI = XTDIsSignalCrossedOverBear(i);
|
||||
if (isCrossedOnI)
|
||||
{
|
||||
result++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Count Signal Crossed Under Bear ...
|
||||
int XTDCountSignalCrossedUnderBearIndex(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
count <= bar_index + 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through ...
|
||||
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||
{
|
||||
//
|
||||
// Check Cross On i Point ...
|
||||
bool isCrossedOnI = XTDIsSignalCrossedUnderBear(i);
|
||||
if (isCrossedOnI)
|
||||
{
|
||||
result++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Count Bull Crossed Over Bear ...
|
||||
int XTDCountBullCrossedOverBearIndex(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
count <= bar_index + 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through ...
|
||||
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||
{
|
||||
//
|
||||
// Check Cross On i Point ...
|
||||
bool isCrossedOnI = XTDIsBullCrossedOverBear(i);
|
||||
if (isCrossedOnI)
|
||||
{
|
||||
result++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Count Bull Crossed Under Bear ...
|
||||
int XTDCountBullCrossedUnderBearIndex(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
count <= bar_index + 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through ...
|
||||
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||
{
|
||||
//
|
||||
// Check Cross On i Point ...
|
||||
bool isCrossedOnI = XTDIsBullCrossedUnderBear(i);
|
||||
if (isCrossedOnI)
|
||||
{
|
||||
result++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Last Signal Crossed Over Bear ...
|
||||
int XTDFindLastSignalCrossedOverBearIndex(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
count <= bar_index + 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through ...
|
||||
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||
{
|
||||
//
|
||||
// Check Cross On i Point ...
|
||||
bool isCrossedOnI = XTDIsSignalCrossedOverBear(i);
|
||||
if (isCrossedOnI)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Last Signal Crossed Onder Bear ...
|
||||
int XTDFindLastSignalCrossedUnderBearIndex(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
count <= bar_index + 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through ...
|
||||
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||
{
|
||||
//
|
||||
// Check Cross On i Point ...
|
||||
bool isCrossedOnI = XTDIsSignalCrossedUnderBear(i);
|
||||
if (isCrossedOnI)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Last Bull Crossed Over Bear ...
|
||||
int XTDFindLastBullCrossedOverBearIndex(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
count <= bar_index + 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through ...
|
||||
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||
{
|
||||
//
|
||||
// Check Cross On i Point ...
|
||||
bool isCrossedOnI = XTDIsBullCrossedOverBear(i);
|
||||
if (isCrossedOnI)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Last Bull Crossed Under Bear ...
|
||||
int XTDFindLastBullCrossedUnderBearIndex(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
int count = ArraySize(xTDSignalBuffer) - 1;
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
count <= bar_index + 1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through ...
|
||||
for (int i = bar_index + 1; i < count && result == -1; i++)
|
||||
{
|
||||
//
|
||||
// Check Cross On i Point ...
|
||||
bool isCrossedOnI = XTDIsBullCrossedUnderBear(i);
|
||||
if (isCrossedOnI)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END XTD Custom Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,569 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XTM Indicator Helper for Signal Providers
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "..\Libraries\x-saherelm.log.lib.mq5"
|
||||
#include "..\Libraries\x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// XTM Indicator States ...
|
||||
enum ENUM_X_XTM_STATES
|
||||
{
|
||||
X_XTM_BULLISH = 1,
|
||||
X_XTM_BEARISH = -1,
|
||||
X_XTM_NEUTURAL = 0,
|
||||
};
|
||||
|
||||
//
|
||||
// XTM Indicator Buffer Lines ...
|
||||
enum ENUM_X_XTM_BUFFER_LINES
|
||||
{
|
||||
X_XTM_MA_LINE = 0,
|
||||
X_XTM_MC_COLOR_LINE = 1,
|
||||
X_XTM_STATE_LINE = 2,
|
||||
};
|
||||
|
||||
//
|
||||
// END Enum Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
input group "XTM Indicator";
|
||||
input int xTMMaPeriod = 18; // Period
|
||||
input int xTMMaShift = 0; // Shift
|
||||
input ENUM_MA_METHOD xTMMaMethod = MODE_EMA; // Method
|
||||
input ENUM_APPLIED_PRICE xTMMaAppliedTo = PRICE_OPEN; // Applied To
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
int xTMHandler = INVALID_HANDLE;
|
||||
double xTMMaBuffer[];
|
||||
double xTMStateBuffer[];
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Handler Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Init Indicators ...
|
||||
bool XTMInitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator/Oscillator Handlers ...
|
||||
ResetLastError();
|
||||
|
||||
//
|
||||
// XTM Handler ...
|
||||
ArraySetAsSeries(xTMMaBuffer, true);
|
||||
ArraySetAsSeries(xTMStateBuffer, true);
|
||||
xTMHandler = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
"x-saherelm.xtm.indicator",
|
||||
//
|
||||
// Inputs ...
|
||||
xTMMaPeriod,
|
||||
xTMMaShift,
|
||||
xTMMaMethod,
|
||||
xTMMaAppliedTo);
|
||||
if (xTMHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
LogMessage("failed to Initialize XTM Indicator: " + (string)GetLastError());
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Release Indicators ...
|
||||
void XTMReleaseHandlers()
|
||||
{
|
||||
IndicatorRelease(xTMHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Reading Buffers ...
|
||||
void XTMReadBuffers(
|
||||
int xTMItemsPerTick // Number Of Reading Buffer Items Per Tick
|
||||
)
|
||||
{
|
||||
//
|
||||
// Ma Buffer ...
|
||||
CopyBuffer(
|
||||
xTMHandler,
|
||||
X_XTM_MA_LINE,
|
||||
0,
|
||||
xTMItemsPerTick,
|
||||
xTMMaBuffer);
|
||||
|
||||
//
|
||||
// State Buffer ...
|
||||
CopyBuffer(
|
||||
xTMHandler,
|
||||
X_XTM_STATE_LINE,
|
||||
0,
|
||||
xTMItemsPerTick,
|
||||
xTMStateBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// END Handler Funcions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XTM Custom Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Find Peak based On this Indicator ...
|
||||
bool XTMIsPeak(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Must Decreasing ...
|
||||
bool isIncreasing = IsIncreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xTMMaBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Vale based On this Indicator ...
|
||||
bool XTMIsVale(
|
||||
int bar_index, // Specified Index ...
|
||||
int length = 10 // Specified Length ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
length <= 0 ||
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + length + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = IsDecreasing(
|
||||
bar_index + length,
|
||||
bar_index,
|
||||
xTMMaBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Crossed Up ...
|
||||
bool XTMIsStartBullish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_BULLISH &&
|
||||
xTMStateBuffer[bar_index + 1] != X_XTM_BULLISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Crossed Up After Neutural State ...
|
||||
bool XTMIsStartBullishAfterNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_BULLISH &&
|
||||
xTMStateBuffer[bar_index + 1] == X_XTM_NEUTURAL
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM In Up State ...
|
||||
bool XTMIsBullish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_BULLISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Ends Up State ...
|
||||
bool XTMIsEndBullish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] != X_XTM_BULLISH &&
|
||||
xTMStateBuffer[bar_index + 1] == X_XTM_BULLISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Ends Up State By Neutural ...
|
||||
bool XTMIsEndBullishByNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_NEUTURAL &&
|
||||
xTMStateBuffer[bar_index + 1] == X_XTM_BULLISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Crossed Down ...
|
||||
bool XTMIsStartBearish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_BEARISH &&
|
||||
xTMStateBuffer[bar_index + 1] != X_XTM_BEARISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Crossed Down After Neutural State ...
|
||||
bool XTMIsStartBearishAfterNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_BEARISH &&
|
||||
xTMStateBuffer[bar_index + 1] == X_XTM_NEUTURAL
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM In Down State ...
|
||||
bool XTMIsBearish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_BEARISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Ends Down State ...
|
||||
bool XTMIsEndBearish(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] != X_XTM_BEARISH &&
|
||||
xTMStateBuffer[bar_index + 1] == X_XTM_BEARISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM Ends Down State By Neutural ...
|
||||
bool XTMIsEndBearishByNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 2))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_NEUTURAL &&
|
||||
xTMStateBuffer[bar_index + 1] == X_XTM_BEARISH
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check TM In Neutural State ...
|
||||
bool XTMIsNeutural(
|
||||
int bar_index // Specified Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
bar_index <= 0 ||
|
||||
!XTMIsValidBuffersSize(bar_index + 1))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xTMStateBuffer[bar_index] == X_XTM_NEUTURAL
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check all Buffers has valid Size ...
|
||||
bool XTMIsValidBuffersSize(
|
||||
int size // the size of buffers which min size for requirements
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (
|
||||
size <= 0 ||
|
||||
//
|
||||
ArraySize(xTMMaBuffer) < size ||
|
||||
ArraySize(xTMStateBuffer) < size
|
||||
//
|
||||
)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END XTM Custom Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -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 ...
|
||||
//
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -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 ...
|
||||
//
|
||||
Binary file not shown.
@@ -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 ...
|
||||
//
|
||||
Binary file not shown.
@@ -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 ...
|
||||
//
|
||||
Binary file not shown.
@@ -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 ...
|
||||
//
|
||||
Binary file not shown.
@@ -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 ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,197 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Alert Library
|
||||
// --------------------------------------
|
||||
// Name: XAlert
|
||||
// Description: provides Alerts abilities ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input group "Alerts";
|
||||
input bool enableAlerts = true; // Enable Alerts
|
||||
input bool logAlerts = true; // Log Alerts
|
||||
input bool terminalAlerts = true; // Terminal Alerts
|
||||
input bool mailAlerts = true; // Mail Alerts
|
||||
input bool pushAlerts = true; // Push Alerts
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
#include "x-saherelm.log.lib.mq5";
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
string alertPrefix = "X-Alert";
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
//
|
||||
// Initial Library if required ...
|
||||
bool OnInInitAlertLibrary()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitial Library if required ...
|
||||
void OnDeinitAlertLibrary()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Attach Alert Prefix to Message ...
|
||||
string PrepareAlertMessage(string message)
|
||||
{
|
||||
//
|
||||
StringConcatenate(message, alertPrefix, " > ", message);
|
||||
|
||||
//
|
||||
return message;
|
||||
}
|
||||
|
||||
//
|
||||
// Logging an Alert ...
|
||||
void LogAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts || !logAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
LogMessage(alertPrefix, message);
|
||||
}
|
||||
|
||||
//
|
||||
// Terminal Alert ...
|
||||
void TerminalAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts || !terminalAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Message ...
|
||||
message = PrepareAlertMessage(message);
|
||||
|
||||
// Send Terminal Alert ...
|
||||
Alert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Mail Alert ...
|
||||
void MailAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts || !mailAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Send Mail Alert ...
|
||||
SendMail(alertPrefix, message);
|
||||
}
|
||||
|
||||
//
|
||||
// Send Push Notification ...
|
||||
void PushAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts || !pushAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Message ...
|
||||
message = PrepareAlertMessage(message);
|
||||
|
||||
//
|
||||
// Send Push Notification Alert ...
|
||||
SendNotification(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Alert Sending ...
|
||||
void SendAlert(string message)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!enableAlerts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Log ...
|
||||
if (logAlerts)
|
||||
{
|
||||
LogAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Terminal ...
|
||||
if (terminalAlerts)
|
||||
{
|
||||
TerminalAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Mail ...
|
||||
if (mailAlerts)
|
||||
{
|
||||
MailAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Push ...
|
||||
if (pushAlerts)
|
||||
{
|
||||
PushAlert(message);
|
||||
}
|
||||
}
|
||||
void SendAlert(
|
||||
XSignal &signal, // the Signal Object which requred to Alert
|
||||
bool asExecuted = true // determines Alert Signal as Executed Signal or not
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Message ...
|
||||
string message = asExecuted ? ExecutedSignalToString(signal) : SignalToString(signal);
|
||||
|
||||
//
|
||||
// Do Alerting ...
|
||||
SendAlert(message);
|
||||
}
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -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 ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,161 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Logger Library
|
||||
// ---------------------------------------
|
||||
// Name: XLogger
|
||||
// Description: provides Logging abilities ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input group "Logging";
|
||||
input bool enableLogging = true; // Enable Logging
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Including Models ...
|
||||
#include "x-saherelm.models.lib.mq5"
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
string logTag = "X-Logger"; // LogTag
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
//
|
||||
// Logging a Message ...
|
||||
void LogMessage(string message)
|
||||
{
|
||||
//
|
||||
if (!enableLogging)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
Print(logTag, " > ", message);
|
||||
}
|
||||
void LogMessage(string tag, string message)
|
||||
{
|
||||
//
|
||||
if (!enableLogging)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
Print(tag, " > ", message);
|
||||
}
|
||||
|
||||
//
|
||||
// Logging an Array ...
|
||||
void LogArray(int &array[])
|
||||
{
|
||||
//
|
||||
if (!enableLogging)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
Print(logTag, ">");
|
||||
ArrayPrint(array);
|
||||
}
|
||||
void LogArray(double &array[])
|
||||
{
|
||||
//
|
||||
if (!enableLogging)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
Print(logTag, ">");
|
||||
ArrayPrint(array);
|
||||
}
|
||||
void LogArray(string &array[])
|
||||
{
|
||||
//
|
||||
if (!enableLogging)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
Print(logTag, ">");
|
||||
ArrayPrint(array);
|
||||
}
|
||||
|
||||
//
|
||||
// Convert a Signal to String Message ...
|
||||
string SignalToString(XSignal &signal)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
result += (signal.type == X_SIGNAL_LONG ? "Buy" : "Sell") + " Signal provided on (" + signal.symbol + " _ " + EnumToString(_Period) + ") by this comment: " + signal.comment;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Convert an Executed Signal to String Message ...
|
||||
string ExecutedSignalToString(XSignal &signal)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
result += (signal.type == X_SIGNAL_LONG ? "Buy" : "Sell") + " Signal Executed provided on (" + signal.symbol + " _ " + EnumToString(_Period) + ") by this comment: " + signal.comment;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Logging Signal ...
|
||||
void LogSignal(XSignal &signal)
|
||||
{
|
||||
//
|
||||
string message = SignalToString(signal);
|
||||
|
||||
//
|
||||
LogMessage(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Log Signal Execution ...
|
||||
void LogExecutedSignal(XSignal &signal)
|
||||
{
|
||||
//
|
||||
string message = ExecutedSignalToString(signal);
|
||||
|
||||
//
|
||||
LogMessage(message);
|
||||
}
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,158 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Models Library
|
||||
// ---------------------------------------
|
||||
// Name: XModels
|
||||
// Description: provides all required models ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Model Definitions ...
|
||||
//
|
||||
//
|
||||
// OHCL Candel Model ...
|
||||
enum ENUM_X_PRICE
|
||||
{
|
||||
X_PRICE_HIGH,
|
||||
X_PRICE_OPEN,
|
||||
X_PRICE_CLOSE,
|
||||
X_PRICE_LOW
|
||||
};
|
||||
|
||||
//
|
||||
// Describe an Specific Candle ...
|
||||
struct XOHCL
|
||||
{
|
||||
double high;
|
||||
double open;
|
||||
double close;
|
||||
double low;
|
||||
};
|
||||
|
||||
//
|
||||
// Swing Types Enum ...
|
||||
enum ENUM_X_SWING_TYPE
|
||||
{
|
||||
X_NO_SWING = 0,
|
||||
X_SWING_HIGH = 1,
|
||||
X_SWING_LOW = -1,
|
||||
};
|
||||
|
||||
//
|
||||
// XTrader Execution Signal Result ...
|
||||
enum ENUM_EXECUTION_SIGNAL_RESULT
|
||||
{
|
||||
//
|
||||
X_TRADER_UNKNOWN_ERROR,
|
||||
X_TRADER_SUCCEED_EXECUTION,
|
||||
X_TRADER_INVALID_SIGNAL_ERROR,
|
||||
X_TRADER_NOT_ENOUGH_EQUITY_ERROR,
|
||||
X_TRADER_MAX_TRADES_REACHED_ERROR,
|
||||
X_TRADER_NOT_ENOUGH_BALANCE_ERROR,
|
||||
X_TRADER_NOT_ENOUGH_MARIGIN_ERROR
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Signal Types ...
|
||||
enum ENUM_X_SIGNAL_TYPE
|
||||
{
|
||||
X_SIGNAL_LONG,
|
||||
X_SIGNAL_SHORT,
|
||||
X_SIGNAL_UNKNOWN,
|
||||
};
|
||||
|
||||
//
|
||||
// Signal Structure ...
|
||||
struct XSignal
|
||||
{
|
||||
//
|
||||
// Identifier ...
|
||||
ulong id;
|
||||
|
||||
//
|
||||
// Which Symbol used for Signal ...
|
||||
string symbol;
|
||||
|
||||
//
|
||||
// Which Type of operations ...
|
||||
ENUM_X_SIGNAL_TYPE type;
|
||||
|
||||
//
|
||||
// Magic Number ...
|
||||
ulong magicNumber;
|
||||
|
||||
//
|
||||
// Ticket ...
|
||||
ulong ticket;
|
||||
|
||||
//
|
||||
// Entry/Open Price ...
|
||||
double entry;
|
||||
|
||||
//
|
||||
// TP ...
|
||||
double tp;
|
||||
|
||||
//
|
||||
// SL ...
|
||||
double sl;
|
||||
|
||||
//
|
||||
// Make Risk Free Trade on this Value if provided ...
|
||||
double riskFreeStep;
|
||||
|
||||
//
|
||||
// a Multiplier for determines how much trade volume exit on risk free time ...
|
||||
double riskFreeRate;
|
||||
|
||||
//
|
||||
// Trade Profit ...
|
||||
double profit;
|
||||
|
||||
//
|
||||
// Time of Operation ...
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Volume ...
|
||||
double volume;
|
||||
|
||||
//
|
||||
// Comment ...
|
||||
string comment;
|
||||
};
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,85 @@
|
||||
///////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XEU5 Signal Provider Library Inputs
|
||||
// -----------------------------------------------------------
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
input group "XEU5 Provider";
|
||||
|
||||
//
|
||||
input group "XEU5 Common";
|
||||
input bool xEU5EnableProvider = true; // Enable Provider
|
||||
input bool xEU5EnableAlerts = false; // Enable Events Alert
|
||||
input int xEU5NumberOfItemsPerTick = 30; // Number Of items Readed In Each Tick
|
||||
|
||||
//
|
||||
input group "XEU5 Trader";
|
||||
input int xEU5MagicNumber = 16940561; // Trader MagicNumber
|
||||
input int xEU5Slippage = 10; // Trader Slippage
|
||||
|
||||
//
|
||||
input group "XEU5 Trade Management";
|
||||
input bool xEU5AllowLongTrades = false; // Allow Long Trades
|
||||
input bool xEU5AllowShortTrades = true; // Allow Short Trades
|
||||
|
||||
//
|
||||
input group "XEU5 Risk Management";
|
||||
//
|
||||
// Trade Count ...
|
||||
input int xEU5MaxAllowedTrades = 1; // Max Allowed Trades at Same Time
|
||||
//
|
||||
// Trades Age ...
|
||||
// 1 Day = 288
|
||||
// 14 Day = 4320
|
||||
input int xEU5MaxInProfitTradeAge = 0; // Max In Profit Trades Age
|
||||
input int xEU5MaxInDrawDownTradeAge = 0; // Max In DrawDown Trades Age
|
||||
//
|
||||
// Trade Volume ...
|
||||
input double xEU5StaticVolume = 0.3; // Static Volume
|
||||
input double xEU5VolumeMultiplier = 2; // Volume Multiplier
|
||||
input double xEU5MaxSupportedVolumePerTradeInLots = 1.5; // Max Supported Volume Per Trade in Lot
|
||||
//
|
||||
// Trade Profits ...
|
||||
input double xEU5MinRewardInPips = 15; // Minimum Reward Per Trade in Pips
|
||||
input double xEU5RiskFreeStepInPips = 3; // Risk Free Steps in Pips
|
||||
input double xEU5RiskFreeRate = 0.5; // Volume Multiplier for Risk Free
|
||||
//
|
||||
input double xEU5MaxAllowedRiskPerTradesMultiplier = 0; // Max Allowed Drawdown Per Trade Multiplier
|
||||
//
|
||||
// Account ...
|
||||
input double xEU5FreeMarginFactorForOpenTrades = 0.8; // Minimum Free Marging for Open Trades
|
||||
input double xEU5BalanceFactorForOpenTrades = 0.5; // Minimum Balance for Open Trades
|
||||
|
||||
//
|
||||
input group "XEU5 Support Trades";
|
||||
input bool xEU5EnableIndirectionalSupportPositions = false; // Enable Reversal Support Positions
|
||||
input int xEU5MaxAllowedSupportTrades = 0; // Max Allowed Support Trades for Single Position
|
||||
input double xEU5SupportTradesPriceDistanceInPips = 0; // Distance Price to Open Support Trade In Pips
|
||||
|
||||
//
|
||||
// Validate Inputs before Initialization ...
|
||||
bool XEU5ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// TODO: Fix this ...
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,192 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Expert Advisor
|
||||
// ----------------------------------------
|
||||
// Name: XEA
|
||||
// Description: this is an expert controller
|
||||
// advisors which provides a mechanism for use them ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XEA"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
input group "Commons";
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Including Providers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Logger Library ...
|
||||
#include "..\Libraries\x-saherelm.log.lib.mq5";
|
||||
|
||||
//
|
||||
// Common Library ...
|
||||
#include "..\Libraries\x-saherelm.common.lib.mq5";
|
||||
|
||||
//
|
||||
// Alert Library ...
|
||||
#include "..\Libraries\x-saherelm.alert.lib.mq5";
|
||||
|
||||
//
|
||||
// Draw Library ...
|
||||
#include "..\Libraries\x-saherelm.draw.lib.mq5";
|
||||
|
||||
//
|
||||
// XEU5 Signal Provider ...
|
||||
#include "..\Libraries\x-saherelm.xeu5.provider.lib.mq5";
|
||||
|
||||
//
|
||||
// END Including Providers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
logTag = "XEA";
|
||||
drawPrefix = logTag;
|
||||
alertPrefix = logTag;
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize XEU5 Provider ...
|
||||
if (!XEU5InitSignalProviderLibrary())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Apply default Chart Style for EA ...
|
||||
ApplyChartStyle();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
|
||||
//
|
||||
// De Initialize XEU5 Provider ...
|
||||
XEU5DeinitSignalProviderLibrary(reason);
|
||||
|
||||
//
|
||||
// De Init XDraw Library ...
|
||||
// OnDeinitDrawLibrary();
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
// Prevent Going Forward if user Disable it ...
|
||||
if (!xEU5EnableProvider)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
if (!IsNewCandle())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Processing on XEU5 Signal Provider ...
|
||||
XEU5SignalProviderHandleTick();
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
|
||||
//
|
||||
// Validate XEU5 Provider Inputs ...
|
||||
result = XEU5ValidateInputs();
|
||||
if (!result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Logging State ...
|
||||
string message = "Validation of (" + "XEA" + ") Inputs " + (result ? "Succeeded" : "Failed") + " ...";
|
||||
LogMessage(message);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,90 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| AD.mq5 |
|
||||
//| Copyright 2000-2023, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2023, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Accumulation/Distribution"
|
||||
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 1
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 LightSeaGreen
|
||||
#property indicator_label1 "A/D"
|
||||
//--- input params
|
||||
input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volume type
|
||||
//--- indicator buffer
|
||||
double ExtADbuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator digits
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,0);
|
||||
//--- indicator short name
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"A/D");
|
||||
//--- index buffer
|
||||
SetIndexBuffer(0,ExtADbuffer);
|
||||
//--- set index draw begin
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,1);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Accumulation/Distribution |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
//--- check for bars count
|
||||
if(rates_total<2)
|
||||
return(0); //exit with zero result
|
||||
//--- get current position
|
||||
int pos=prev_calculated-1;
|
||||
if(pos<0)
|
||||
pos=0;
|
||||
//--- calculate with appropriate volumes
|
||||
if(InpVolumeType==VOLUME_TICK)
|
||||
Calculate(rates_total,pos,high,low,close,tick_volume);
|
||||
else
|
||||
Calculate(rates_total,pos,high,low,close,volume);
|
||||
//---
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Calculating with selected volume |
|
||||
//+------------------------------------------------------------------+
|
||||
void Calculate(const int rates_total,const int pos,
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &volume[])
|
||||
{
|
||||
//--- main cycle
|
||||
for(int i=pos; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//--- get some data from arrays
|
||||
double hi=high[i];
|
||||
double lo=low[i];
|
||||
double cl=close[i];
|
||||
//--- calculate new AD
|
||||
double sum=(cl-lo)-(hi-cl);
|
||||
if(hi==lo)
|
||||
sum=0.0;
|
||||
else
|
||||
sum=(sum/(hi-lo))*volume[i];
|
||||
if(i>0)
|
||||
sum+=ExtADbuffer[i-1];
|
||||
ExtADbuffer[i]=sum;
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,155 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| ADX.mq5 |
|
||||
//| Copyright 2000-2023, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2023, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Average Directional Movement Index"
|
||||
#include <MovingAverages.mqh>
|
||||
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 6
|
||||
#property indicator_plots 3
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 LightSeaGreen
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 YellowGreen
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 Wheat
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
#property indicator_label1 "ADX"
|
||||
#property indicator_label2 "+DI"
|
||||
#property indicator_label3 "-DI"
|
||||
//--- input parameters
|
||||
input int InpPeriodADX=14; // Period ADX
|
||||
//--- indicator buffers
|
||||
double ExtADXBuffer[];
|
||||
double ExtPDIBuffer[];
|
||||
double ExtNDIBuffer[];
|
||||
double ExtPDBuffer[];
|
||||
double ExtNDBuffer[];
|
||||
double ExtTmpBuffer[];
|
||||
|
||||
int ExtADXPeriod;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- check for input parameters
|
||||
if(InpPeriodADX>=100 || InpPeriodADX<=0)
|
||||
{
|
||||
ExtADXPeriod=14;
|
||||
PrintFormat("Incorrect value for input variable Period_ADX=%d. Indicator will use value=%d for calculations.",InpPeriodADX,ExtADXPeriod);
|
||||
}
|
||||
else
|
||||
ExtADXPeriod=InpPeriodADX;
|
||||
//--- indicator buffers
|
||||
SetIndexBuffer(0,ExtADXBuffer);
|
||||
SetIndexBuffer(1,ExtPDIBuffer);
|
||||
SetIndexBuffer(2,ExtNDIBuffer);
|
||||
SetIndexBuffer(3,ExtPDBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(4,ExtNDBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(5,ExtTmpBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- indicator digits
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,2);
|
||||
//--- set draw begin
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtADXPeriod<<1);
|
||||
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtADXPeriod);
|
||||
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtADXPeriod);
|
||||
//--- indicator short name
|
||||
string short_name="ADX("+string(ExtADXPeriod)+")";
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
PlotIndexSetString(0,PLOT_LABEL,short_name);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
//--- checking for bars count
|
||||
if(rates_total<ExtADXPeriod)
|
||||
return(0);
|
||||
//--- detect start position
|
||||
int start;
|
||||
if(prev_calculated>1)
|
||||
start=prev_calculated-1;
|
||||
else
|
||||
{
|
||||
start=1;
|
||||
ExtPDIBuffer[0]=0.0;
|
||||
ExtNDIBuffer[0]=0.0;
|
||||
ExtADXBuffer[0]=0.0;
|
||||
}
|
||||
//--- main cycle
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//--- get some data
|
||||
double high_price=high[i];
|
||||
double prev_high =high[i-1];
|
||||
double low_price =low[i];
|
||||
double prev_low =low[i-1];
|
||||
double prev_close=close[i-1];
|
||||
//--- fill main positive and main negative buffers
|
||||
double tmp_pos=high_price-prev_high;
|
||||
double tmp_neg=prev_low-low_price;
|
||||
if(tmp_pos<0.0)
|
||||
tmp_pos=0.0;
|
||||
if(tmp_neg<0.0)
|
||||
tmp_neg=0.0;
|
||||
if(tmp_pos>tmp_neg)
|
||||
tmp_neg=0.0;
|
||||
else
|
||||
{
|
||||
if(tmp_pos<tmp_neg)
|
||||
tmp_pos=0.0;
|
||||
else
|
||||
{
|
||||
tmp_pos=0.0;
|
||||
tmp_neg=0.0;
|
||||
}
|
||||
}
|
||||
//--- define TR
|
||||
double tr=MathMax(MathMax(MathAbs(high_price-low_price),MathAbs(high_price-prev_close)),MathAbs(low_price-prev_close));
|
||||
if(tr!=0.0)
|
||||
{
|
||||
ExtPDBuffer[i]=100.0*tmp_pos/tr;
|
||||
ExtNDBuffer[i]=100.0*tmp_neg/tr;
|
||||
}
|
||||
else
|
||||
{
|
||||
ExtPDBuffer[i]=0.0;
|
||||
ExtNDBuffer[i]=0.0;
|
||||
}
|
||||
//--- fill smoothed positive and negative buffers
|
||||
ExtPDIBuffer[i]=ExponentialMA(i,ExtADXPeriod,ExtPDIBuffer[i-1],ExtPDBuffer);
|
||||
ExtNDIBuffer[i]=ExponentialMA(i,ExtADXPeriod,ExtNDIBuffer[i-1],ExtNDBuffer);
|
||||
//--- fill ADXTmp buffer
|
||||
double tmp=ExtPDIBuffer[i]+ExtNDIBuffer[i];
|
||||
if(tmp!=0.0)
|
||||
tmp=100.0*MathAbs((ExtPDIBuffer[i]-ExtNDIBuffer[i])/tmp);
|
||||
else
|
||||
tmp=0.0;
|
||||
ExtTmpBuffer[i]=tmp;
|
||||
//--- fill smoothed ADX buffer
|
||||
ExtADXBuffer[i]=ExponentialMA(i,ExtADXPeriod,ExtADXBuffer[i-1],ExtTmpBuffer);
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,189 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| ADXW.mq5 |
|
||||
//| Copyright 2000-2023, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2023, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Average Directional Movement Index"
|
||||
#property description "by Welles Wilder"
|
||||
#include <MovingAverages.mqh>
|
||||
//---
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 10
|
||||
#property indicator_plots 3
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
#property indicator_color1 LightSeaGreen
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
#property indicator_color2 YellowGreen
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
#property indicator_color3 Wheat
|
||||
#property indicator_label1 "ADX Wilder"
|
||||
#property indicator_label2 "+DI"
|
||||
#property indicator_label3 "-DI"
|
||||
//--- input parameters
|
||||
input int InpPeriodADXW=14; // Period ADX
|
||||
//--- indicator buffers
|
||||
double ExtADXWBuffer[];
|
||||
double ExtPDIBuffer[];
|
||||
double ExtNDIBuffer[];
|
||||
double ExtPDSBuffer[];
|
||||
double ExtNDSBuffer[];
|
||||
double ExtPDBuffer[];
|
||||
double ExtNDBuffer[];
|
||||
double ExtTRBuffer[];
|
||||
double ExtATRBuffer[];
|
||||
double ExtDXBuffer[];
|
||||
|
||||
int ExtADXWPeriod;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- check for input parameters
|
||||
if(InpPeriodADXW>=100 || InpPeriodADXW<=0)
|
||||
{
|
||||
ExtADXWPeriod=14;
|
||||
PrintFormat("Incorrect value for input variable InpPeriodADXW=%d. Indicator will use value=%d for calculations.",InpPeriodADXW,ExtADXWPeriod);
|
||||
}
|
||||
else
|
||||
ExtADXWPeriod=InpPeriodADXW;
|
||||
//--- indicator buffers
|
||||
SetIndexBuffer(0,ExtADXWBuffer);
|
||||
SetIndexBuffer(1,ExtPDIBuffer);
|
||||
SetIndexBuffer(2,ExtNDIBuffer);
|
||||
//--- calculation buffers
|
||||
SetIndexBuffer(3,ExtPDBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(4,ExtNDBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(5,ExtDXBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(6,ExtTRBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(7,ExtATRBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(8,ExtPDSBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(9,ExtNDSBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- set draw begin
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtADXWPeriod<<1);
|
||||
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtADXWPeriod+1);
|
||||
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtADXWPeriod+1);
|
||||
//--- indicator short name
|
||||
string short_name="ADX Wilder("+string(ExtADXWPeriod)+")";
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
PlotIndexSetString(0,PLOT_LABEL,short_name);
|
||||
//--- indicator digits
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,2);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
//--- checking for bars count
|
||||
if(rates_total<ExtADXWPeriod)
|
||||
return(0);
|
||||
//--- detect start position
|
||||
int start;
|
||||
if(prev_calculated>1)
|
||||
start=prev_calculated-1;
|
||||
else
|
||||
{
|
||||
start=1;
|
||||
for(int i=0; i<ExtADXWPeriod; i++)
|
||||
{
|
||||
ExtADXWBuffer[i]=0;
|
||||
ExtPDIBuffer[i]=0;
|
||||
ExtNDIBuffer[i]=0;
|
||||
ExtPDSBuffer[i]=0;
|
||||
ExtNDSBuffer[i]=0;
|
||||
ExtPDBuffer[i]=0;
|
||||
ExtNDBuffer[i]=0;
|
||||
ExtTRBuffer[i]=0;
|
||||
ExtATRBuffer[i]=0;
|
||||
ExtDXBuffer[i]=0;
|
||||
}
|
||||
}
|
||||
//--- main cycle
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//--- get some data
|
||||
double high_price=high[i];
|
||||
double prev_high =high[i-1];
|
||||
double low_price =low[i];
|
||||
double prev_low =low[i-1];
|
||||
double prev_close=close[i-1];
|
||||
//--- fill main positive and main negative buffers
|
||||
double tmp_pos=high_price-prev_high;
|
||||
double tmp_neg=prev_low-low_price;
|
||||
if(tmp_pos<0.0)
|
||||
tmp_pos=0.0;
|
||||
if(tmp_neg<0.0)
|
||||
tmp_neg=0.0;
|
||||
if(tmp_neg==tmp_pos)
|
||||
{
|
||||
tmp_neg=0.0;
|
||||
tmp_pos=0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(tmp_pos<tmp_neg)
|
||||
tmp_pos=0.0;
|
||||
else
|
||||
tmp_neg=0.0;
|
||||
}
|
||||
ExtPDBuffer[i]=tmp_pos;
|
||||
ExtNDBuffer[i]=tmp_neg;
|
||||
//--- define TR
|
||||
double tr=MathMax(MathMax(MathAbs(high_price-low_price),MathAbs(high_price-prev_close)),MathAbs(low_price-prev_close));
|
||||
ExtTRBuffer[i]=tr; // write down TR to TR buffer
|
||||
//--- fill smoothed positive and negative buffers and TR buffer
|
||||
if(i<ExtADXWPeriod)
|
||||
{
|
||||
ExtATRBuffer[i]=0.0;
|
||||
ExtPDIBuffer[i]=0.0;
|
||||
ExtNDIBuffer[i]=0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ExtATRBuffer[i]=SmoothedMA(i,ExtADXWPeriod,ExtATRBuffer[i-1],ExtTRBuffer);
|
||||
ExtPDSBuffer[i]=SmoothedMA(i,ExtADXWPeriod,ExtPDSBuffer[i-1],ExtPDBuffer);
|
||||
ExtNDSBuffer[i]=SmoothedMA(i,ExtADXWPeriod,ExtNDSBuffer[i-1],ExtNDBuffer);
|
||||
}
|
||||
//--- calculate PDI and NDI buffers
|
||||
if(ExtATRBuffer[i]!=0.0)
|
||||
{
|
||||
ExtPDIBuffer[i]=100.0*ExtPDSBuffer[i]/ExtATRBuffer[i];
|
||||
ExtNDIBuffer[i]=100.0*ExtNDSBuffer[i]/ExtATRBuffer[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
ExtPDIBuffer[i]=0.0;
|
||||
ExtNDIBuffer[i]=0.0;
|
||||
}
|
||||
//--- Calculate DX buffer
|
||||
double dTmp=ExtPDIBuffer[i]+ExtNDIBuffer[i];
|
||||
if(dTmp!=0.0)
|
||||
dTmp=100.0*MathAbs((ExtPDIBuffer[i]-ExtNDIBuffer[i])/dTmp);
|
||||
else
|
||||
dTmp=0.0;
|
||||
ExtDXBuffer[i]=dTmp;
|
||||
//--- fill ADXW buffer as smoothed DX buffer
|
||||
ExtADXWBuffer[i]=SmoothedMA(i,ExtADXWPeriod,ExtADXWBuffer[i-1],ExtDXBuffer);
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,130 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| AMA.mq5 |
|
||||
//| Copyright 2000-2023, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2023, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property version "1.00"
|
||||
#property description "Adaptive Moving Average"
|
||||
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 1
|
||||
#property indicator_plots 1
|
||||
//--- plot ExtAMABuffer
|
||||
#property indicator_label1 "AMA"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 Red
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
//--- default applied price
|
||||
#property indicator_applied_price PRICE_OPEN
|
||||
//--- input parameters
|
||||
input int InpPeriodAMA=10; // AMA period
|
||||
input int InpFastPeriodEMA=2; // Fast EMA period
|
||||
input int InpSlowPeriodEMA=30; // Slow EMA period
|
||||
input int InpShiftAMA=0; // AMA shift
|
||||
//--- indicator buffer
|
||||
double ExtAMABuffer[];
|
||||
|
||||
double ExtFastSC;
|
||||
double ExtSlowSC;
|
||||
int ExtPeriodAMA;
|
||||
int ExtSlowPeriodEMA;
|
||||
int ExtFastPeriodEMA;
|
||||
//+------------------------------------------------------------------+
|
||||
//| AMA initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- check for input values
|
||||
if(InpPeriodAMA<=0)
|
||||
{
|
||||
ExtPeriodAMA=10;
|
||||
PrintFormat("Input parameter InpPeriodAMA has incorrect value (%d). Indicator will use value %d for calculations.",
|
||||
InpPeriodAMA,ExtPeriodAMA);
|
||||
}
|
||||
else
|
||||
ExtPeriodAMA=InpPeriodAMA;
|
||||
if(InpSlowPeriodEMA<=0)
|
||||
{
|
||||
ExtSlowPeriodEMA=30;
|
||||
PrintFormat("Input parameter InpSlowPeriodEMA has incorrect value (%d). Indicator will use value %d for calculations.",
|
||||
InpSlowPeriodEMA,ExtSlowPeriodEMA);
|
||||
}
|
||||
else
|
||||
ExtSlowPeriodEMA=InpSlowPeriodEMA;
|
||||
if(InpFastPeriodEMA<=0)
|
||||
{
|
||||
ExtFastPeriodEMA=2;
|
||||
PrintFormat("Input parameter InpFastPeriodEMA has incorrect value (%d). Indicator will use value %d for calculations.",
|
||||
InpFastPeriodEMA,ExtFastPeriodEMA);
|
||||
}
|
||||
else
|
||||
ExtFastPeriodEMA=InpFastPeriodEMA;
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtAMABuffer,INDICATOR_DATA);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPeriodAMA);
|
||||
//--- set index shift
|
||||
PlotIndexSetInteger(0,PLOT_SHIFT,InpShiftAMA);
|
||||
//--- set shortname and change label
|
||||
string short_name=StringFormat("AMA(%d,%d,%d)",ExtPeriodAMA,ExtFastPeriodEMA,ExtSlowPeriodEMA);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
PlotIndexSetString(0,PLOT_LABEL,short_name);
|
||||
//--- calculate ExtFastSC & ExtSlowSC
|
||||
ExtFastSC=2.0/(ExtFastPeriodEMA+1.0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| AMA iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const int begin,
|
||||
const double &price[])
|
||||
{
|
||||
int i;
|
||||
//--- check for rates count
|
||||
if(rates_total<ExtPeriodAMA+begin)
|
||||
return(0);
|
||||
//--- draw begin may be corrected
|
||||
if(begin!=0)
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPeriodAMA+begin);
|
||||
//--- detect position
|
||||
int pos=prev_calculated-1;
|
||||
//--- first calculations
|
||||
if(pos<ExtPeriodAMA+begin)
|
||||
{
|
||||
pos=ExtPeriodAMA+begin;
|
||||
for(i=0; i<pos-1; i++)
|
||||
ExtAMABuffer[i]=0.0;
|
||||
ExtAMABuffer[pos-1]=price[pos-1];
|
||||
}
|
||||
//--- main cycle
|
||||
for(i=pos; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//--- calculate SSC
|
||||
double currentSSC=(CalculateER(i,price)*(ExtFastSC-ExtSlowSC))+ExtSlowSC;
|
||||
//--- calculate AMA
|
||||
double prevAMA=ExtAMABuffer[i-1];
|
||||
ExtAMABuffer[i]=MathPow(currentSSC,2)*(price[i]-prevAMA)+prevAMA;
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Calculate ER value |
|
||||
//+------------------------------------------------------------------+
|
||||
double CalculateER(const int pos,const double& price[])
|
||||
{
|
||||
double signal=MathAbs(price[pos]-price[pos-ExtPeriodAMA]);
|
||||
double noise=0.0;
|
||||
for(int delta=0; delta<ExtPeriodAMA; delta++)
|
||||
noise+=MathAbs(price[pos-delta]-price[pos-delta-1]);
|
||||
if(noise!=0.0)
|
||||
return(signal/noise);
|
||||
return(0.0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,112 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| ASI.mq5 |
|
||||
//| Copyright 2000-2023, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2023, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Accumulation Swing Index"
|
||||
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 DodgerBlue
|
||||
#property indicator_style1 0
|
||||
#property indicator_width1 1
|
||||
#property indicator_label1 "ASI"
|
||||
//--- input parameter
|
||||
input double InpT=300.0; // T (maximum price changing)
|
||||
//--- indicator buffers
|
||||
double ExtASIBuffer[];
|
||||
double ExtSIBuffer[];
|
||||
double ExtTRBuffer[];
|
||||
|
||||
double ExtTpoints,ExtT;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- check for input value
|
||||
if(MathAbs(InpT)>1e-7)
|
||||
ExtT=InpT;
|
||||
else
|
||||
{
|
||||
ExtT=300.0;
|
||||
PrintFormat("Input parameter T has wrong value. Indicator will use T = %f.",ExtT);
|
||||
}
|
||||
//--- define buffers
|
||||
SetIndexBuffer(0,ExtASIBuffer);
|
||||
SetIndexBuffer(1,ExtSIBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(2,ExtTRBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- draw begin settings
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,1);
|
||||
//--- number of digits of indicator value
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,2);
|
||||
//--- calculate ExtTpoints value
|
||||
if(_Point>1e-7)
|
||||
ExtTpoints=ExtT*_Point;
|
||||
else
|
||||
ExtTpoints=ExtT*MathPow(10,-_Digits);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<2)
|
||||
return(0);
|
||||
//--- start calculation
|
||||
int pos=prev_calculated-1;
|
||||
//--- correct position, when it's first iteration
|
||||
if(pos<=0)
|
||||
{
|
||||
pos=1;
|
||||
ExtASIBuffer[0]=0.0;
|
||||
ExtSIBuffer[0]=0.0;
|
||||
ExtTRBuffer[0]=high[0]-low[0];
|
||||
}
|
||||
//--- main cycle
|
||||
for(int i=pos; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//--- get some data
|
||||
double dPrevClose=close[i-1];
|
||||
double dPrevOpen=open[i-1];
|
||||
double dClose=close[i];
|
||||
double dHigh=high[i];
|
||||
double dLow=low[i];
|
||||
//--- fill TR buffer
|
||||
ExtTRBuffer[i]=MathMax(dHigh,dPrevClose)-MathMin(dLow,dPrevClose);
|
||||
double ER=0.0;
|
||||
if(!(dPrevClose>=dLow && dPrevClose<=dHigh))
|
||||
{
|
||||
if(dPrevClose>dHigh)
|
||||
ER=MathAbs(dHigh-dPrevClose);
|
||||
if(dPrevClose<dLow)
|
||||
ER=MathAbs(dLow-dPrevClose);
|
||||
}
|
||||
double K=MathMax(MathAbs(dHigh-dPrevClose),MathAbs(dLow-dPrevClose));
|
||||
double SH=MathAbs(dPrevClose-dPrevOpen);
|
||||
double R=ExtTRBuffer[i]-0.5*ER+0.25*SH;
|
||||
//--- calculate SI value
|
||||
if(R==0.0 || ExtTpoints==0.0)
|
||||
ExtSIBuffer[i]=0.0;
|
||||
else
|
||||
ExtSIBuffer[i]=50*(dClose-dPrevClose+0.5*(dClose-open[i])+0.25*(dPrevClose-dPrevOpen))*(K/ExtTpoints)/R;
|
||||
//--- write down ASI buffer value
|
||||
ExtASIBuffer[i]=ExtASIBuffer[i-1]+ExtSIBuffer[i];
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,97 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| ATR.mq5 |
|
||||
//| Copyright 2000-2023, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2023, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Average True Range"
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 DodgerBlue
|
||||
#property indicator_label1 "ATR"
|
||||
//--- input parameters
|
||||
input int InpAtrPeriod=14; // ATR period
|
||||
//--- indicator buffers
|
||||
double ExtATRBuffer[];
|
||||
double ExtTRBuffer[];
|
||||
|
||||
int ExtPeriodATR;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- check for input value
|
||||
if(InpAtrPeriod<=0)
|
||||
{
|
||||
ExtPeriodATR=14;
|
||||
PrintFormat("Incorrect input parameter InpAtrPeriod = %d. Indicator will use value %d for calculations.",InpAtrPeriod,ExtPeriodATR);
|
||||
}
|
||||
else
|
||||
ExtPeriodATR=InpAtrPeriod;
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtATRBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtTRBuffer,INDICATOR_CALCULATIONS);
|
||||
//---
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpAtrPeriod);
|
||||
//--- name for DataWindow and indicator subwindow label
|
||||
string short_name=StringFormat("ATR(%d)",ExtPeriodATR);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
PlotIndexSetString(0,PLOT_LABEL,short_name);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Average True Range |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<=ExtPeriodATR)
|
||||
return(0);
|
||||
|
||||
int i,start;
|
||||
//--- preliminary calculations
|
||||
if(prev_calculated==0)
|
||||
{
|
||||
ExtTRBuffer[0]=0.0;
|
||||
ExtATRBuffer[0]=0.0;
|
||||
//--- filling out the array of True Range values for each period
|
||||
for(i=1; i<rates_total && !IsStopped(); i++)
|
||||
ExtTRBuffer[i]=MathMax(high[i],close[i-1])-MathMin(low[i],close[i-1]);
|
||||
//--- first AtrPeriod values of the indicator are not calculated
|
||||
double firstValue=0.0;
|
||||
for(i=1; i<=ExtPeriodATR; i++)
|
||||
{
|
||||
ExtATRBuffer[i]=0.0;
|
||||
firstValue+=ExtTRBuffer[i];
|
||||
}
|
||||
//--- calculating the first value of the indicator
|
||||
firstValue/=ExtPeriodATR;
|
||||
ExtATRBuffer[ExtPeriodATR]=firstValue;
|
||||
start=ExtPeriodATR+1;
|
||||
}
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- the main loop of calculations
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
ExtTRBuffer[i]=MathMax(high[i],close[i-1])-MathMin(low[i],close[i-1]);
|
||||
ExtATRBuffer[i]=ExtATRBuffer[i-1]+(ExtTRBuffer[i]-ExtTRBuffer[i-ExtPeriodATR])/ExtPeriodATR;
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,147 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Accelerator.mq5 |
|
||||
//| Copyright 2000-2023, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2023, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Accelerator/Decelerator"
|
||||
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 6
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_COLOR_HISTOGRAM
|
||||
#property indicator_color1 Green,Red
|
||||
#property indicator_width1 2
|
||||
#property indicator_label1 "AC"
|
||||
//--- indicator buffers
|
||||
double ExtACBuffer[];
|
||||
double ExtColorBuffer[];
|
||||
double ExtFastBuffer[];
|
||||
double ExtSlowBuffer[];
|
||||
double ExtAOBuffer[];
|
||||
double ExtSMABuffer[];
|
||||
//--- handles for MAs
|
||||
int ExtFastSMAHandle;
|
||||
int ExtSlowSMAHandle;
|
||||
//--- bars minimum for calculation
|
||||
#define DATA_LIMIT 37 // FAST_PERIOD-1 + SLOW_PERIOD-1
|
||||
//--- MA periods
|
||||
#define FAST_PERIOD 5
|
||||
#define SLOW_PERIOD 34
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtACBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtColorBuffer,INDICATOR_COLOR_INDEX);
|
||||
SetIndexBuffer(2,ExtFastBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(3,ExtSlowBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(4,ExtAOBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(5,ExtSMABuffer,INDICATOR_CALCULATIONS);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+2);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,DATA_LIMIT);
|
||||
//--- name for DataWindow
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"AC");
|
||||
//--- get handles
|
||||
ExtFastSMAHandle=iMA(NULL,0,FAST_PERIOD,0,MODE_SMA,PRICE_MEDIAN);
|
||||
ExtSlowSMAHandle=iMA(NULL,0,SLOW_PERIOD,0,MODE_SMA,PRICE_MEDIAN);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Accelerator/Decelerator Oscillator |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<DATA_LIMIT)
|
||||
return(0);
|
||||
//--- not all data may be calculated
|
||||
int calculated=BarsCalculated(ExtFastSMAHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtFastSMAHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
calculated=BarsCalculated(ExtSlowSMAHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtSlowSMAHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- we can copy not all data
|
||||
int to_copy;
|
||||
if(prev_calculated>rates_total || prev_calculated<0)
|
||||
to_copy=rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-prev_calculated;
|
||||
if(prev_calculated>0)
|
||||
to_copy++;
|
||||
}
|
||||
//--- get FastSMA buffer
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtFastSMAHandle,0,0,to_copy,ExtFastBuffer)<=0)
|
||||
{
|
||||
Print("Getting fast SMA is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- get SlowSMA buffer
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtSlowSMAHandle,0,0,to_copy,ExtSlowBuffer)<=0)
|
||||
{
|
||||
Print("Getting slow SMA is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- calculations
|
||||
int i,start;
|
||||
//--- first calculation or number of bars was changed
|
||||
if(prev_calculated<SLOW_PERIOD)
|
||||
{
|
||||
for(i=0; i<SLOW_PERIOD-1; i++)
|
||||
{
|
||||
ExtACBuffer[i]=0.0;
|
||||
ExtAOBuffer[i]=0.0;
|
||||
}
|
||||
start=SLOW_PERIOD-1;
|
||||
}
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- main loop of calculations
|
||||
for(i=start; i<DATA_LIMIT; i++)
|
||||
{
|
||||
ExtACBuffer[i]=0.0;
|
||||
ExtAOBuffer[i]=ExtFastBuffer[i]-ExtSlowBuffer[i];
|
||||
}
|
||||
for(; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
ExtAOBuffer[i]=ExtFastBuffer[i]-ExtSlowBuffer[i];
|
||||
double sumAO=0.0;
|
||||
for(int j=0; j<FAST_PERIOD; j++)
|
||||
sumAO+=ExtAOBuffer[i-j];
|
||||
ExtSMABuffer[i]=sumAO/FAST_PERIOD;
|
||||
ExtACBuffer[i]=ExtAOBuffer[i]-ExtSMABuffer[i];
|
||||
if(ExtACBuffer[i]>=ExtACBuffer[i-1])
|
||||
ExtColorBuffer[i]=0.0; // set color Green
|
||||
else
|
||||
ExtColorBuffer[i]=1.0; // set color Red
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,148 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Alligator.mq5 |
|
||||
//| Copyright 2000-2023, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2023, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
|
||||
//--- indicator settings
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 3
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color1 Blue
|
||||
#property indicator_color2 Red
|
||||
#property indicator_color3 Lime
|
||||
#property indicator_width1 1
|
||||
#property indicator_width2 1
|
||||
#property indicator_width3 1
|
||||
#property indicator_label1 "Jaws"
|
||||
#property indicator_label2 "Teeth"
|
||||
#property indicator_label3 "Lips"
|
||||
//--- input parameters
|
||||
input int InpJawsPeriod=13; // Jaws period
|
||||
input int InpJawsShift=8; // Jaws shift
|
||||
input int InpTeethPeriod=8; // Teeth period
|
||||
input int InpTeethShift=5; // Teeth shift
|
||||
input int InpLipsPeriod=5; // Lips period
|
||||
input int InpLipsShift=3; // Lips shift
|
||||
input ENUM_MA_METHOD InpMAMethod=MODE_SMMA; // Moving average method
|
||||
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_MEDIAN; // Applied price
|
||||
//--- indicator buffers
|
||||
double ExtJaws[];
|
||||
double ExtTeeth[];
|
||||
double ExtLips[];
|
||||
//--- handles for moving averages
|
||||
int ExtJawsHandle;
|
||||
int ExtTeethHandle;
|
||||
int ExtLipsHandle;
|
||||
//--- bars minimum for calculation
|
||||
int ExtBarsMinimum;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtJaws,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtTeeth,INDICATOR_DATA);
|
||||
SetIndexBuffer(2,ExtLips,INDICATOR_DATA);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpJawsPeriod-1);
|
||||
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpTeethPeriod-1);
|
||||
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,InpLipsPeriod-1);
|
||||
//--- line shifts when drawing
|
||||
PlotIndexSetInteger(0,PLOT_SHIFT,InpJawsShift);
|
||||
PlotIndexSetInteger(1,PLOT_SHIFT,InpTeethShift);
|
||||
PlotIndexSetInteger(2,PLOT_SHIFT,InpLipsShift);
|
||||
//--- name for DataWindow
|
||||
PlotIndexSetString(0,PLOT_LABEL,"Jaws("+string(InpJawsPeriod)+")");
|
||||
PlotIndexSetString(1,PLOT_LABEL,"Teeth("+string(InpTeethPeriod)+")");
|
||||
PlotIndexSetString(2,PLOT_LABEL,"Lips("+string(InpLipsPeriod)+")");
|
||||
//--- get MA's handles
|
||||
ExtJawsHandle=iMA(NULL,0,InpJawsPeriod,0,InpMAMethod,InpAppliedPrice);
|
||||
ExtTeethHandle=iMA(NULL,0,InpTeethPeriod,0,InpMAMethod,InpAppliedPrice);
|
||||
ExtLipsHandle=iMA(NULL,0,InpLipsPeriod,0,InpMAMethod,InpAppliedPrice);
|
||||
//--- bars minimum for calculation
|
||||
ExtBarsMinimum=InpJawsPeriod+InpJawsShift;
|
||||
if(ExtBarsMinimum<(InpTeethPeriod+InpTeethShift))
|
||||
ExtBarsMinimum=InpTeethPeriod+InpTeethShift;
|
||||
if(ExtBarsMinimum<(InpLipsPeriod+InpLipsPeriod))
|
||||
ExtBarsMinimum=InpLipsPeriod+InpLipsPeriod;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Alligator OnCalculate function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<ExtBarsMinimum)
|
||||
return(0);
|
||||
//--- not all data may be calculated
|
||||
int calculated=BarsCalculated(ExtJawsHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtJawsHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
calculated=BarsCalculated(ExtTeethHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtTeethHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
calculated=BarsCalculated(ExtLipsHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtLipsHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- we can copy not all data
|
||||
int to_copy;
|
||||
if(prev_calculated>rates_total || prev_calculated<0)
|
||||
to_copy=rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-prev_calculated;
|
||||
if(prev_calculated>0)
|
||||
to_copy++;
|
||||
}
|
||||
//--- get ma buffers
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtJawsHandle,0,0,to_copy,ExtJaws)<=0)
|
||||
{
|
||||
Print("getting ExtJawsHandle is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtTeethHandle,0,0,to_copy,ExtTeeth)<=0)
|
||||
{
|
||||
Print("getting ExtTeethHandle is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtLipsHandle,0,0,to_copy,ExtLips)<=0)
|
||||
{
|
||||
Print("getting ExtLipsHandle is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,127 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Awesome_Oscillator.mq5 |
|
||||
//| Copyright 2000-2023, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2023, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_COLOR_HISTOGRAM
|
||||
#property indicator_color1 Green,Red
|
||||
#property indicator_width1 1
|
||||
#property indicator_label1 "AO"
|
||||
//--- indicator buffers
|
||||
double ExtAOBuffer[];
|
||||
double ExtColorBuffer[];
|
||||
double ExtFastBuffer[];
|
||||
double ExtSlowBuffer[];
|
||||
//--- handles for MAs
|
||||
int ExtFastSMAHandle;
|
||||
int ExtSlowSMAHandle;
|
||||
|
||||
#define DATA_LIMIT 33
|
||||
#define FAST_PERIOD 5
|
||||
#define SLOW_PERIOD 34
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtAOBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtColorBuffer,INDICATOR_COLOR_INDEX);
|
||||
SetIndexBuffer(2,ExtFastBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(3,ExtSlowBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,33);
|
||||
//--- name for DataWindow
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"AO");
|
||||
//--- get handles
|
||||
ExtFastSMAHandle=iMA(NULL,0,FAST_PERIOD,0,MODE_SMA,PRICE_MEDIAN);
|
||||
ExtSlowSMAHandle=iMA(NULL,0,SLOW_PERIOD,0,MODE_SMA,PRICE_MEDIAN);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Awesome Oscillator |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<=DATA_LIMIT)
|
||||
return(0);
|
||||
//--- not all data may be calculated
|
||||
int calculated=BarsCalculated(ExtFastSMAHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtFastSMAHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
calculated=BarsCalculated(ExtSlowSMAHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtSlowSMAHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- we can copy not all data
|
||||
int to_copy;
|
||||
if(prev_calculated>rates_total || prev_calculated<0)
|
||||
to_copy=rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-prev_calculated;
|
||||
if(prev_calculated>0)
|
||||
to_copy++;
|
||||
}
|
||||
//--- get FastSMA buffer
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtFastSMAHandle,0,0,to_copy,ExtFastBuffer)<=0)
|
||||
{
|
||||
Print("Getting fast SMA is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- get SlowSMA buffer
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtSlowSMAHandle,0,0,to_copy,ExtSlowBuffer)<=0)
|
||||
{
|
||||
Print("Getting slow SMA is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- first calculation or number of bars was changed
|
||||
int i,start;
|
||||
if(prev_calculated<=DATA_LIMIT)
|
||||
{
|
||||
for(i=0; i<DATA_LIMIT; i++)
|
||||
ExtAOBuffer[i]=0.0;
|
||||
start=DATA_LIMIT;
|
||||
}
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- main loop of calculations
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
ExtAOBuffer[i]=ExtFastBuffer[i]-ExtSlowBuffer[i];
|
||||
if(ExtAOBuffer[i]>ExtAOBuffer[i-1])
|
||||
ExtColorBuffer[i]=0.0; // set color Green
|
||||
else
|
||||
ExtColorBuffer[i]=1.0; // set color Red
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,141 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| BB.mq5 |
|
||||
//| Copyright 2000-2023, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2023, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Bollinger Bands"
|
||||
#include <MovingAverages.mqh>
|
||||
//---
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 3
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 LightSeaGreen
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 LightSeaGreen
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 LightSeaGreen
|
||||
#property indicator_label1 "Bands middle"
|
||||
#property indicator_label2 "Bands upper"
|
||||
#property indicator_label3 "Bands lower"
|
||||
//--- input parametrs
|
||||
input int InpBandsPeriod=20; // Period
|
||||
input int InpBandsShift=0; // Shift
|
||||
input double InpBandsDeviations=2.0; // Deviation
|
||||
//--- global variables
|
||||
int ExtBandsPeriod,ExtBandsShift;
|
||||
double ExtBandsDeviations;
|
||||
int ExtPlotBegin=0;
|
||||
//--- indicator buffer
|
||||
double ExtMLBuffer[];
|
||||
double ExtTLBuffer[];
|
||||
double ExtBLBuffer[];
|
||||
double ExtStdDevBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- check for input values
|
||||
if(InpBandsPeriod<2)
|
||||
{
|
||||
ExtBandsPeriod=20;
|
||||
PrintFormat("Incorrect value for input variable InpBandsPeriod=%d. Indicator will use value=%d for calculations.",InpBandsPeriod,ExtBandsPeriod);
|
||||
}
|
||||
else
|
||||
ExtBandsPeriod=InpBandsPeriod;
|
||||
if(InpBandsShift<0)
|
||||
{
|
||||
ExtBandsShift=0;
|
||||
PrintFormat("Incorrect value for input variable InpBandsShift=%d. Indicator will use value=%d for calculations.",InpBandsShift,ExtBandsShift);
|
||||
}
|
||||
else
|
||||
ExtBandsShift=InpBandsShift;
|
||||
if(InpBandsDeviations==0.0)
|
||||
{
|
||||
ExtBandsDeviations=2.0;
|
||||
PrintFormat("Incorrect value for input variable InpBandsDeviations=%f. Indicator will use value=%f for calculations.",InpBandsDeviations,ExtBandsDeviations);
|
||||
}
|
||||
else
|
||||
ExtBandsDeviations=InpBandsDeviations;
|
||||
//--- define buffers
|
||||
SetIndexBuffer(0,ExtMLBuffer);
|
||||
SetIndexBuffer(1,ExtTLBuffer);
|
||||
SetIndexBuffer(2,ExtBLBuffer);
|
||||
SetIndexBuffer(3,ExtStdDevBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- set index labels
|
||||
PlotIndexSetString(0,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Middle");
|
||||
PlotIndexSetString(1,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Upper");
|
||||
PlotIndexSetString(2,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Lower");
|
||||
//--- indicator name
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"Bollinger Bands");
|
||||
//--- indexes draw begin settings
|
||||
ExtPlotBegin=ExtBandsPeriod-1;
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtBandsPeriod);
|
||||
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtBandsPeriod);
|
||||
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtBandsPeriod);
|
||||
//--- indexes shift settings
|
||||
PlotIndexSetInteger(0,PLOT_SHIFT,ExtBandsShift);
|
||||
PlotIndexSetInteger(1,PLOT_SHIFT,ExtBandsShift);
|
||||
PlotIndexSetInteger(2,PLOT_SHIFT,ExtBandsShift);
|
||||
//--- number of digits of indicator value
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Bollinger Bands |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const int begin,
|
||||
const double &price[])
|
||||
{
|
||||
if(rates_total<ExtPlotBegin)
|
||||
return(0);
|
||||
//--- indexes draw begin settings, when we've recieved previous begin
|
||||
if(ExtPlotBegin!=ExtBandsPeriod+begin)
|
||||
{
|
||||
ExtPlotBegin=ExtBandsPeriod+begin;
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPlotBegin);
|
||||
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtPlotBegin);
|
||||
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtPlotBegin);
|
||||
}
|
||||
//--- starting calculation
|
||||
int pos;
|
||||
if(prev_calculated>1)
|
||||
pos=prev_calculated-1;
|
||||
else
|
||||
pos=0;
|
||||
//--- main cycle
|
||||
for(int i=pos; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//--- middle line
|
||||
ExtMLBuffer[i]=SimpleMA(i,ExtBandsPeriod,price);
|
||||
//--- calculate and write down StdDev
|
||||
ExtStdDevBuffer[i]=StdDev_Func(i,price,ExtMLBuffer,ExtBandsPeriod);
|
||||
//--- upper line
|
||||
ExtTLBuffer[i]=ExtMLBuffer[i]+ExtBandsDeviations*ExtStdDevBuffer[i];
|
||||
//--- lower line
|
||||
ExtBLBuffer[i]=ExtMLBuffer[i]-ExtBandsDeviations*ExtStdDevBuffer[i];
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Calculate Standard Deviation |
|
||||
//+------------------------------------------------------------------+
|
||||
double StdDev_Func(const int position,const double &price[],const double &ma_price[],const int period)
|
||||
{
|
||||
double std_dev=0.0;
|
||||
//--- calcualte StdDev
|
||||
if(position>=period)
|
||||
{
|
||||
for(int i=0; i<period; i++)
|
||||
std_dev+=MathPow(price[position-i]-ma_price[position],2.0);
|
||||
std_dev=MathSqrt(std_dev/period);
|
||||
}
|
||||
//--- return calculated value
|
||||
return(std_dev);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,134 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| BW-ZoneTrade.mq5 |
|
||||
//| Copyright 2000-2023, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2023, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
//--- indicator settings
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 7
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_COLOR_CANDLES
|
||||
#property indicator_color1 Green,Red,Gray
|
||||
#property indicator_width1 3
|
||||
#property indicator_label1 "Open;High;Low;Close"
|
||||
//--- indicator buffers
|
||||
double ExtOBuffer[];
|
||||
double ExtHBuffer[];
|
||||
double ExtLBuffer[];
|
||||
double ExtCBuffer[];
|
||||
double ExtColorBuffer[];
|
||||
double ExtAOBuffer[];
|
||||
double ExtACBuffer[];
|
||||
//--- handles of indicators
|
||||
int ExtACHandle;
|
||||
int ExtAOHandle;
|
||||
//--- bars minimum for calculation
|
||||
#define DATA_LIMIT 38
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtOBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtHBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(2,ExtLBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(3,ExtCBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(4,ExtColorBuffer,INDICATOR_COLOR_INDEX);
|
||||
SetIndexBuffer(5,ExtACBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(6,ExtAOBuffer,INDICATOR_CALCULATIONS);
|
||||
//---
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
//--- sets first bar from what index will be drawn
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"BW ZoneTrade");
|
||||
//--- don't show indicator data in DataWindow
|
||||
PlotIndexSetInteger(0,PLOT_SHOW_DATA,false);
|
||||
//--- sets first candle from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,DATA_LIMIT);
|
||||
//--- get handles
|
||||
ExtACHandle=iAC(NULL,0);
|
||||
ExtAOHandle=iAO(NULL,0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Trade zone by Bill Williams |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<DATA_LIMIT)
|
||||
return(0);
|
||||
//--- not all data may be calculated
|
||||
int calculated=BarsCalculated(ExtACHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtACHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
calculated=BarsCalculated(ExtAOHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtAOHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- we can copy not all data
|
||||
int to_copy;
|
||||
if(prev_calculated>rates_total || prev_calculated<0)
|
||||
to_copy=rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-prev_calculated;
|
||||
if(prev_calculated>0)
|
||||
to_copy++;
|
||||
}
|
||||
//--- get AC buffer
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtACHandle,0,0,to_copy,ExtACBuffer)<=0)
|
||||
{
|
||||
Print("Getting iAC is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- get AO buffer
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtAOHandle,0,0,to_copy,ExtAOBuffer)<=0)
|
||||
{
|
||||
Print("Getting iAO is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- set first bar from what calculation will start
|
||||
int start;
|
||||
if(prev_calculated<DATA_LIMIT)
|
||||
start=DATA_LIMIT;
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- the main loop of calculations
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
ExtOBuffer[i]=open[i];
|
||||
ExtHBuffer[i]=high[i];
|
||||
ExtLBuffer[i]=low[i];
|
||||
ExtCBuffer[i]=close[i];
|
||||
//--- set color for candle
|
||||
ExtColorBuffer[i]=2.0; // set gray Color
|
||||
//--- check for Green Zone and set Color Green
|
||||
if(ExtACBuffer[i]>ExtACBuffer[i-1] && ExtAOBuffer[i]>ExtAOBuffer[i-1])
|
||||
ExtColorBuffer[i]=0.0;
|
||||
//--- check for Red Zone and set Color Red
|
||||
if(ExtACBuffer[i]<ExtACBuffer[i-1] && ExtAOBuffer[i]<ExtAOBuffer[i-1])
|
||||
ExtColorBuffer[i]=1.0;
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,94 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Bears.mq5 |
|
||||
//| Copyright 2000-2023, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2023, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Bears Power"
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_HISTOGRAM
|
||||
#property indicator_color1 Silver
|
||||
#property indicator_width1 2
|
||||
//--- input parameters
|
||||
input int InpBearsPeriod=13; // Period
|
||||
//--- indicator buffers
|
||||
double ExtBearsBuffer[];
|
||||
double ExtTempBuffer[];
|
||||
//--- handle of EMA
|
||||
int ExtEmaHandle;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtBearsBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtTempBuffer,INDICATOR_CALCULATIONS);
|
||||
//---
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpBearsPeriod-1);
|
||||
//--- name for DataWindow and indicator subwindow label
|
||||
string short_name=StringFormat("Bears(%d)",InpBearsPeriod);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
//--- get MA handle
|
||||
ExtEmaHandle=iMA(_Symbol,_Period,InpBearsPeriod,0,MODE_EMA,PRICE_CLOSE);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Average True Range |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<InpBearsPeriod)
|
||||
return(0);
|
||||
//--- not all data may be calculated
|
||||
int calculated=BarsCalculated(ExtEmaHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtEmaHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- we can copy not all data
|
||||
int to_copy;
|
||||
if(prev_calculated>rates_total || prev_calculated<0)
|
||||
to_copy=rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-prev_calculated;
|
||||
if(prev_calculated>0)
|
||||
to_copy++;
|
||||
}
|
||||
//--- get ma buffers
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtEmaHandle,0,0,to_copy,ExtTempBuffer)<=0)
|
||||
{
|
||||
Print("getting ExtEmaHandle is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- first calculation or number of bars was changed
|
||||
int start;
|
||||
if(prev_calculated<InpBearsPeriod)
|
||||
start=InpBearsPeriod;
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- the main loop of calculations
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
ExtBearsBuffer[i]=low[i]-ExtTempBuffer[i];
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,94 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Bulls.mq5 |
|
||||
//| Copyright 2000-2023, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2023, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Bulls Power"
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_HISTOGRAM
|
||||
#property indicator_color1 Silver
|
||||
#property indicator_width1 2
|
||||
//--- input parameters
|
||||
input int InpBullsPeriod=13; // Period
|
||||
//--- indicator buffers
|
||||
double ExtBullsBuffer[];
|
||||
double ExtTempBuffer[];
|
||||
//--- MA handle
|
||||
int ExtEmaHandle;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtBullsBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtTempBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpBullsPeriod-1);
|
||||
//--- name for DataWindow and indicator subwindow label
|
||||
string short_name=StringFormat("Bulls(%d)",InpBullsPeriod);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
//--- get handle for MA
|
||||
ExtEmaHandle=iMA(NULL,0,InpBullsPeriod,0,MODE_EMA,PRICE_CLOSE);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Average True Range |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<InpBullsPeriod)
|
||||
return(0);
|
||||
//--- not all data may be calculated
|
||||
int calculated=BarsCalculated(ExtEmaHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtEmaHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- we can copy not all data
|
||||
int to_copy;
|
||||
if(prev_calculated>rates_total || prev_calculated<0)
|
||||
to_copy=rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-prev_calculated;
|
||||
if(prev_calculated>0)
|
||||
to_copy++;
|
||||
}
|
||||
//--- get ma buffers
|
||||
if(IsStopped()) // checking for stop flag
|
||||
return(0);
|
||||
if(CopyBuffer(ExtEmaHandle,0,0,to_copy,ExtTempBuffer)<=0)
|
||||
{
|
||||
Print("getting ExtEmaHandle is failed! Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- first calculation or number of bars was changed
|
||||
int start;
|
||||
if(prev_calculated<InpBullsPeriod)
|
||||
start=InpBullsPeriod;
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- the main loop of calculations
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
ExtBullsBuffer[i]=high[i]-ExtTempBuffer[i];
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,94 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| CCI.mq5 |
|
||||
//| Copyright 2000-2023, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2023, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Commodity Channel Index"
|
||||
#include <MovingAverages.mqh>
|
||||
//---
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 LightSeaGreen
|
||||
#property indicator_level1 -100.0
|
||||
#property indicator_level2 100.0
|
||||
#property indicator_applied_price PRICE_TYPICAL
|
||||
//--- input parametrs
|
||||
input int InpCCIPeriod=14; // Period
|
||||
//--- indicator buffers
|
||||
double ExtSPBuffer[];
|
||||
double ExtDBuffer[];
|
||||
double ExtMBuffer[];
|
||||
double ExtCCIBuffer[];
|
||||
|
||||
int ExtCCIPeriod;
|
||||
double ExtMultiplyer;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- check for input value of period
|
||||
if(InpCCIPeriod<=0)
|
||||
{
|
||||
ExtCCIPeriod=14;
|
||||
PrintFormat("Incorrect value for input variable InpCCIPeriod=%d. Indicator will use value=%d for calculations.",InpCCIPeriod,ExtCCIPeriod);
|
||||
}
|
||||
else
|
||||
ExtCCIPeriod=InpCCIPeriod;
|
||||
ExtMultiplyer=0.015/ExtCCIPeriod;
|
||||
//--- define buffers
|
||||
SetIndexBuffer(0,ExtCCIBuffer);
|
||||
SetIndexBuffer(1,ExtDBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(2,ExtMBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(3,ExtSPBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- indicator name
|
||||
string short_name=StringFormat("CCI(%d)",ExtCCIPeriod);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
//--- indexes draw begin settings
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtCCIPeriod-1);
|
||||
//--- number of digits of indicator value
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,2);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const int begin,
|
||||
const double &price[])
|
||||
{
|
||||
int start=(ExtCCIPeriod-1)+begin;
|
||||
if(rates_total<start)
|
||||
return(0);
|
||||
//--- correct draw begin
|
||||
if(begin>0)
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,start+(ExtCCIPeriod-1));
|
||||
//--- calculate position
|
||||
int pos=prev_calculated-1;
|
||||
if(pos<start)
|
||||
pos=start;
|
||||
//--- main cycle
|
||||
for(int i=pos; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
ExtSPBuffer[i]=SimpleMA(i,ExtCCIPeriod,price);
|
||||
//--- calculate D
|
||||
double tmp_d=0.0;
|
||||
for(int j=0; j<ExtCCIPeriod; j++)
|
||||
tmp_d+=MathAbs(price[i-j]-ExtSPBuffer[i]);
|
||||
ExtDBuffer[i]=tmp_d*ExtMultiplyer;
|
||||
//--- calculate M
|
||||
ExtMBuffer[i]=price[i]-ExtSPBuffer[i];
|
||||
//--- calculate CCI
|
||||
if(ExtDBuffer[i]!=0.0)
|
||||
ExtCCIBuffer[i]=ExtMBuffer[i]/ExtDBuffer[i];
|
||||
else
|
||||
ExtCCIBuffer[i]=0.0;
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,131 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| CHO.mq5 |
|
||||
//| Copyright 2000-2023, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2023, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Chaikin Oscillator"
|
||||
#include <MovingAverages.mqh>
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 LightSeaGreen
|
||||
//--- input parameters
|
||||
input int InpFastMA=3; // Fast MA period
|
||||
input int InpSlowMA=10; // Slow MA period
|
||||
input ENUM_MA_METHOD InpSmoothMethod=MODE_EMA; // MA method
|
||||
input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volumes
|
||||
//--- indicator buffers
|
||||
double ExtCHOBuffer[];
|
||||
double ExtFastEMABuffer[];
|
||||
double ExtSlowEMABuffer[];
|
||||
double ExtADBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtCHOBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtFastEMABuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(2,ExtSlowEMABuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(3,ExtADBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,0);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpSlowMA);
|
||||
//--- name for DataWindow and indicator subwindow label
|
||||
string short_name=StringFormat("CHO(%d,%d)",InpSlowMA,InpFastMA);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Chaikin Oscillator |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
if(rates_total<InpSlowMA)
|
||||
return(0);
|
||||
//--- preliminary calculations
|
||||
int i,start;
|
||||
if(prev_calculated<2)
|
||||
start=0;
|
||||
else
|
||||
start=prev_calculated-2;
|
||||
//--- calculate AD buffer
|
||||
if(InpVolumeType==VOLUME_TICK)
|
||||
{
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
ExtADBuffer[i]=AD(high[i],low[i],close[i],tick_volume[i]);
|
||||
if(i>0)
|
||||
ExtADBuffer[i]+=ExtADBuffer[i-1];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
ExtADBuffer[i]=AD(high[i],low[i],close[i],volume[i]);
|
||||
if(i>0)
|
||||
ExtADBuffer[i]+=ExtADBuffer[i-1];
|
||||
}
|
||||
}
|
||||
//--- calculate EMA on array ExtADBuffer
|
||||
AverageOnArray(InpSmoothMethod,rates_total,prev_calculated,0,InpFastMA,ExtADBuffer,ExtFastEMABuffer);
|
||||
AverageOnArray(InpSmoothMethod,rates_total,prev_calculated,0,InpSlowMA,ExtADBuffer,ExtSlowEMABuffer);
|
||||
//--- calculate chaikin oscillator
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
ExtCHOBuffer[i]=ExtFastEMABuffer[i]-ExtSlowEMABuffer[i];
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| calculate AD |
|
||||
//+------------------------------------------------------------------+
|
||||
double AD(double high,double low,double close,long volume)
|
||||
{
|
||||
double res=0.0;
|
||||
//---
|
||||
double sum=(close-low)-(high-close);
|
||||
if(sum!=0.0)
|
||||
{
|
||||
if(high!=low)
|
||||
res=(sum/(high-low))*volume;
|
||||
}
|
||||
//---
|
||||
return(res);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| calculate average on array |
|
||||
//+------------------------------------------------------------------+
|
||||
void AverageOnArray(const int mode,const int rates_total,const int prev_calculated,const int begin,
|
||||
const int period,const double& source[],double& destination[])
|
||||
{
|
||||
switch(mode)
|
||||
{
|
||||
case MODE_EMA:
|
||||
ExponentialMAOnBuffer(rates_total,prev_calculated,begin,period,source,destination);
|
||||
break;
|
||||
case MODE_SMMA:
|
||||
SmoothedMAOnBuffer(rates_total,prev_calculated,begin,period,source,destination);
|
||||
break;
|
||||
case MODE_LWMA:
|
||||
LinearWeightedMAOnBuffer(rates_total,prev_calculated,begin,period,source,destination);
|
||||
break;
|
||||
default:
|
||||
SimpleMAOnBuffer(rates_total,prev_calculated,begin,period,source,destination);
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,118 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| CHV.mq5 |
|
||||
//| Copyright 2000-2023, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2023, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Chaikin Volatility"
|
||||
#include <MovingAverages.mqh>
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 DodgerBlue
|
||||
//--- enum
|
||||
enum SmoothMethod
|
||||
{
|
||||
SMA=0,// Simple MA
|
||||
EMA=1 // Exponential MA
|
||||
};
|
||||
//--- input parameters
|
||||
input int InpSmoothPeriod=10; // Smoothing period
|
||||
input int InpCHVPeriod=10; // CHV period
|
||||
input SmoothMethod InpSmoothType=EMA; // Smoothing method
|
||||
//--- indicator buffers
|
||||
double ExtCHVBuffer[];
|
||||
double ExtHLBuffer[];
|
||||
double ExtSHLBuffer[];
|
||||
|
||||
int ExtSmoothPeriod,ExtCHVPeriod;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
string ma_name=EnumToString(InpSmoothType);
|
||||
//--- check inputs
|
||||
if(InpSmoothPeriod<=0)
|
||||
{
|
||||
ExtSmoothPeriod=10;
|
||||
PrintFormat("Incorrect value for input variable InpSmoothPeriod=%d. Indicator will use value=%d for calculations.",InpSmoothPeriod,ExtSmoothPeriod);
|
||||
}
|
||||
else
|
||||
ExtSmoothPeriod=InpSmoothPeriod;
|
||||
if(InpCHVPeriod<=0)
|
||||
{
|
||||
ExtCHVPeriod=10;
|
||||
PrintFormat("Incorrect value for input variable InpCHVPeriod=%d. Indicator will use value=%d for calculations.",InpCHVPeriod,ExtCHVPeriod);
|
||||
}
|
||||
else
|
||||
ExtCHVPeriod=InpCHVPeriod;
|
||||
//--- define buffers
|
||||
SetIndexBuffer(0,ExtCHVBuffer);
|
||||
SetIndexBuffer(1,ExtHLBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(2,ExtSHLBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- set draw begin
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtSmoothPeriod+ExtCHVPeriod-1);
|
||||
//--- set name and index label
|
||||
string params=StringFormat("(%d,%s)",ExtSmoothPeriod,ma_name);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"Chaikin Volatility"+params);
|
||||
PlotIndexSetString(0,PLOT_LABEL,"CHV"+params);
|
||||
//--- round settings
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,1);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
int i,pos,pos_chv;
|
||||
//--- check for rates total
|
||||
pos_chv=ExtCHVPeriod+ExtSmoothPeriod-2;
|
||||
if(rates_total<pos_chv)
|
||||
return(0);
|
||||
//--- start working
|
||||
if(prev_calculated<1)
|
||||
pos=0;
|
||||
else
|
||||
pos=prev_calculated-1;
|
||||
//--- fill H-L(i) buffer
|
||||
for(i=pos; i<rates_total && !IsStopped(); i++)
|
||||
ExtHLBuffer[i]=high[i]-low[i];
|
||||
//--- calculate smoothed H-L(i) buffer
|
||||
if(pos<ExtSmoothPeriod-1)
|
||||
{
|
||||
pos=ExtSmoothPeriod-1;
|
||||
for(i=0; i<pos; i++)
|
||||
ExtSHLBuffer[i]=0.0;
|
||||
}
|
||||
if(InpSmoothType==SMA)
|
||||
SimpleMAOnBuffer(rates_total,prev_calculated,0,ExtSmoothPeriod,ExtHLBuffer,ExtSHLBuffer);
|
||||
else
|
||||
ExponentialMAOnBuffer(rates_total,prev_calculated,0,ExtSmoothPeriod,ExtHLBuffer,ExtSHLBuffer);
|
||||
//--- correct calc position
|
||||
if(pos<pos_chv)
|
||||
pos=pos_chv;
|
||||
//--- calculate CHV buffer
|
||||
for(i=pos; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
if(ExtSHLBuffer[i-ExtCHVPeriod]!=0.0)
|
||||
ExtCHVBuffer[i]=100.0*(ExtSHLBuffer[i]-ExtSHLBuffer[i-ExtCHVPeriod])/ExtSHLBuffer[i-ExtCHVPeriod];
|
||||
else
|
||||
ExtCHVBuffer[i]=0.0;
|
||||
}
|
||||
//---
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,73 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| FlameChart.mq5 |
|
||||
//| Copyright 2000-2023, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2023, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#include <Canvas\FlameCanvas.mqh>
|
||||
//+------------------------------------------------------------------+
|
||||
//| Indicator properties |
|
||||
//+------------------------------------------------------------------+
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 0
|
||||
#property indicator_plots 0
|
||||
//+------------------------------------------------------------------+
|
||||
//| Input parameters |
|
||||
//+------------------------------------------------------------------+
|
||||
input int InpFuturefBars =50;
|
||||
//+------------------------------------------------------------------+
|
||||
//| global variables |
|
||||
//+------------------------------------------------------------------+
|
||||
CFlameCanvas ExtCanvas;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
if(!ExtCanvas.FlameCreate("FlameChart",TimeCurrent(),InpFuturefBars,0))
|
||||
return(INIT_FAILED);
|
||||
//--- succeed
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator deinitialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
datetime xb1=time[rates_total-1];
|
||||
double yb1=high[rates_total-1];
|
||||
datetime xe1=xb1+InpFuturefBars*PeriodSeconds();
|
||||
double ye1=ChartGetDouble(0,CHART_PRICE_MAX);
|
||||
datetime xb2=xb1;
|
||||
double yb2=low[rates_total-1];
|
||||
datetime xe2=xe1;
|
||||
double ye2=ChartGetDouble(0,CHART_PRICE_MIN);
|
||||
//--- "nozzle" is defined using two lines: ((xb1,yb1),(xe1,ye1)) and ((xb2,yb2),(xe2,ye2))
|
||||
ExtCanvas.FlameSet(xb1,yb1,xe1,ye1,xb2,yb2,xe2,ye2);
|
||||
//--- result
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator chart's event handler |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnChartEvent(const int id,const long& lparam,const double& dparam,const string& sparam)
|
||||
{
|
||||
ExtCanvas.ChartEventHandler(id,lparam,dparam,sparam);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,82 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| ColorBars.mq5 |
|
||||
//| Copyright 2000-2023, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2023, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 5
|
||||
#property indicator_plots 1
|
||||
//--- plot ColorBars
|
||||
#property indicator_label1 "ColorBars"
|
||||
#property indicator_type1 DRAW_COLOR_BARS
|
||||
#property indicator_color1 Green,Red
|
||||
#property indicator_label1 "Open;High;Low;Close"
|
||||
//--- indicator buffers
|
||||
double ExtOpenBuffer[];
|
||||
double ExtHighBuffer[];
|
||||
double ExtLowBuffer[];
|
||||
double ExtCloseBuffer[];
|
||||
double ExtColorsBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicators
|
||||
SetIndexBuffer(0,ExtOpenBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtHighBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(2,ExtLowBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(3,ExtCloseBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(4,ExtColorsBuffer,INDICATOR_COLOR_INDEX);
|
||||
//--- don't show indicator data in DataWindow
|
||||
PlotIndexSetInteger(0,PLOT_SHOW_DATA,false);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
int i=0;
|
||||
bool vol_up=true;
|
||||
//--- set position for beginning
|
||||
if(i<prev_calculated)
|
||||
i=prev_calculated-1;
|
||||
//--- start calculations
|
||||
while(i<rates_total && !IsStopped())
|
||||
{
|
||||
ExtOpenBuffer[i]=open[i];
|
||||
ExtHighBuffer[i]=high[i];
|
||||
ExtLowBuffer[i]=low[i];
|
||||
ExtCloseBuffer[i]=close[i];
|
||||
//--- determine volume change
|
||||
if(i>0)
|
||||
{
|
||||
if(tick_volume[i]>tick_volume[i-1])
|
||||
vol_up=true;
|
||||
if(tick_volume[i]<tick_volume[i-1])
|
||||
vol_up=false;
|
||||
}
|
||||
if(vol_up)
|
||||
ExtColorsBuffer[i]=0.0;
|
||||
else
|
||||
ExtColorsBuffer[i]=1.0;
|
||||
i++;
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,78 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| ColorCandlesDaily.mq5 |
|
||||
//| Copyright 2000-2023, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2023, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 5
|
||||
#property indicator_plots 1
|
||||
//--- plot ColorCandles
|
||||
#property indicator_type1 DRAW_COLOR_CANDLES
|
||||
#property indicator_label1 "Open;High;Low;Close"
|
||||
//--- indicator buffers
|
||||
double ExtOpenBuffer[];
|
||||
double ExtHighBuffer[];
|
||||
double ExtLowBuffer[];
|
||||
double ExtCloseBuffer[];
|
||||
double ExtColorsBuffer[];
|
||||
//---
|
||||
color ExtColorOfDay[6]= {CLR_NONE,MediumSlateBlue,DarkGoldenrod,ForestGreen,BlueViolet,Red};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtOpenBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtHighBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(2,ExtLowBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(3,ExtCloseBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(4,ExtColorsBuffer,INDICATOR_COLOR_INDEX);
|
||||
//--- set number of colors in color buffer
|
||||
PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,6);
|
||||
//--- set colors for color buffer
|
||||
for(int i=1; i<6; i++)
|
||||
PlotIndexSetInteger(0,PLOT_LINE_COLOR,i,ExtColorOfDay[i]);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
PrintFormat("We have %i colors of days",PlotIndexGetInteger(0,PLOT_COLOR_INDEXES));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
int pos;
|
||||
MqlDateTime tstruct;
|
||||
//---
|
||||
if(prev_calculated<1)
|
||||
pos=0;
|
||||
else
|
||||
pos=prev_calculated-1;
|
||||
//--- main cycle
|
||||
for(int i=pos; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
ExtOpenBuffer[i]=open[i];
|
||||
ExtHighBuffer[i]=high[i];
|
||||
ExtLowBuffer[i]=low[i];
|
||||
ExtCloseBuffer[i]=close[i];
|
||||
//--- set color for every candle
|
||||
TimeToStruct(time[i],tstruct);
|
||||
ExtColorsBuffer[i]=tstruct.day_of_week;
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,133 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| ColorLine.mq5 |
|
||||
//| Copyright 2000-2023, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2023, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 1
|
||||
//--- plot ColorLine
|
||||
#property indicator_label1 "ColorLine"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 Red,Green,Blue
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 3
|
||||
//--- indicator buffers
|
||||
double ExtColorLineBuffer[];
|
||||
double ExtColorsBuffer[];
|
||||
|
||||
int ExtMAHandle;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtColorLineBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtColorsBuffer,INDICATOR_COLOR_INDEX);
|
||||
//--- get MA handle
|
||||
ExtMAHandle=iMA(Symbol(),0,10,0,MODE_EMA,PRICE_CLOSE);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
static int ticks=0,modified=0;
|
||||
//--- check data
|
||||
int calculated=BarsCalculated(ExtMAHandle);
|
||||
if(calculated<rates_total)
|
||||
{
|
||||
Print("Not all data of ExtMAHandle is calculated (",calculated," bars). Error ",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
//--- first calculation or number of bars was changed
|
||||
if(prev_calculated==0)
|
||||
{
|
||||
//--- copy values of MA into indicator buffer ExtColorLineBuffer
|
||||
if(CopyBuffer(ExtMAHandle,0,0,rates_total,ExtColorLineBuffer)<=0)
|
||||
return(0);
|
||||
//--- now set line color for every bar
|
||||
for(int i=0; i<rates_total && !IsStopped(); i++)
|
||||
ExtColorsBuffer[i]=getIndexOfColor(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
//--- we can copy not all data
|
||||
int to_copy;
|
||||
if(prev_calculated>rates_total || prev_calculated<0)
|
||||
to_copy=rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-prev_calculated;
|
||||
if(prev_calculated>0)
|
||||
to_copy++;
|
||||
}
|
||||
//--- copy values of MA into indicator buffer ExtColorLineBuffer
|
||||
int copied=CopyBuffer(ExtMAHandle,0,0,rates_total,ExtColorLineBuffer);
|
||||
if(copied<=0)
|
||||
return(0);
|
||||
|
||||
ticks++; // ticks counting
|
||||
if(ticks>=5) //it's time to change color scheme
|
||||
{
|
||||
ticks=0; // reset counter
|
||||
modified++; // counter of color changes
|
||||
if(modified>=3)
|
||||
modified=0;// reset counter
|
||||
ResetLastError();
|
||||
switch(modified)
|
||||
{
|
||||
case 0: // first color scheme
|
||||
PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,Red);
|
||||
PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,Blue);
|
||||
PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,Green);
|
||||
break;
|
||||
case 1: // second color scheme
|
||||
PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,Yellow);
|
||||
PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,Pink);
|
||||
PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,LightSlateGray);
|
||||
break;
|
||||
default: // third color scheme
|
||||
PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,LightGoldenrod);
|
||||
PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,Orchid);
|
||||
PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,LimeGreen);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//--- set start position
|
||||
int start=prev_calculated-1;
|
||||
//--- now we set line color for every bar
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
ExtColorsBuffer[i]=getIndexOfColor(i);
|
||||
}
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| get color index |
|
||||
//+------------------------------------------------------------------+
|
||||
int getIndexOfColor(const int i)
|
||||
{
|
||||
int j=i%300;
|
||||
if(j<100) // first index
|
||||
return(0);
|
||||
if(j<200) // second index
|
||||
return(1);
|
||||
return(2); // third index
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,199 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom Moving Average.mq5 |
|
||||
//| Copyright 2000-2023, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2023, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
|
||||
//--- indicator settings
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 1
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 Red
|
||||
//--- input parameters
|
||||
input int InpMAPeriod=13; // Period
|
||||
input int InpMAShift=0; // Shift
|
||||
input ENUM_MA_METHOD InpMAMethod=MODE_SMMA; // Method
|
||||
//--- indicator buffer
|
||||
double ExtLineBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtLineBuffer,INDICATOR_DATA);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
|
||||
//--- set first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpMAPeriod);
|
||||
//--- line shifts when drawing
|
||||
PlotIndexSetInteger(0,PLOT_SHIFT,InpMAShift);
|
||||
//--- name for DataWindow
|
||||
string short_name;
|
||||
switch(InpMAMethod)
|
||||
{
|
||||
case MODE_EMA :
|
||||
short_name="EMA";
|
||||
break;
|
||||
case MODE_LWMA :
|
||||
short_name="LWMA";
|
||||
break;
|
||||
case MODE_SMA :
|
||||
short_name="SMA";
|
||||
break;
|
||||
case MODE_SMMA :
|
||||
short_name="SMMA";
|
||||
break;
|
||||
default :
|
||||
short_name="unknown ma";
|
||||
}
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name+"("+string(InpMAPeriod)+")");
|
||||
//--- set drawing line empty value
|
||||
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Moving Average |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const int begin,
|
||||
const double &price[])
|
||||
{
|
||||
if(rates_total<InpMAPeriod-1+begin)
|
||||
return(0);
|
||||
//--- first calculation or number of bars was changed
|
||||
if(prev_calculated==0)
|
||||
{
|
||||
ArrayInitialize(ExtLineBuffer,0);
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpMAPeriod-1+begin);
|
||||
}
|
||||
//--- calculation
|
||||
switch(InpMAMethod)
|
||||
{
|
||||
case MODE_EMA:
|
||||
CalculateEMA(rates_total,prev_calculated,begin,price);
|
||||
break;
|
||||
case MODE_LWMA:
|
||||
CalculateLWMA(rates_total,prev_calculated,begin,price);
|
||||
break;
|
||||
case MODE_SMMA:
|
||||
CalculateSmoothedMA(rates_total,prev_calculated,begin,price);
|
||||
break;
|
||||
case MODE_SMA:
|
||||
CalculateSimpleMA(rates_total,prev_calculated,begin,price);
|
||||
break;
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| simple moving average |
|
||||
//+------------------------------------------------------------------+
|
||||
void CalculateSimpleMA(int rates_total,int prev_calculated,int begin,const double &price[])
|
||||
{
|
||||
int i,start;
|
||||
//--- first calculation or number of bars was changed
|
||||
if(prev_calculated==0)
|
||||
{
|
||||
start=InpMAPeriod+begin;
|
||||
//--- set empty value for first start bars
|
||||
for(i=0; i<start-1; i++)
|
||||
ExtLineBuffer[i]=0.0;
|
||||
//--- calculate first visible value
|
||||
double first_value=0;
|
||||
for(i=begin; i<start; i++)
|
||||
first_value+=price[i];
|
||||
first_value/=InpMAPeriod;
|
||||
ExtLineBuffer[start-1]=first_value;
|
||||
}
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- main loop
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
ExtLineBuffer[i]=ExtLineBuffer[i-1]+(price[i]-price[i-InpMAPeriod])/InpMAPeriod;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| exponential moving average |
|
||||
//+------------------------------------------------------------------+
|
||||
void CalculateEMA(int rates_total,int prev_calculated,int begin,const double &price[])
|
||||
{
|
||||
int i,start;
|
||||
double SmoothFactor=2.0/(1.0+InpMAPeriod);
|
||||
//--- first calculation or number of bars was changed
|
||||
if(prev_calculated==0)
|
||||
{
|
||||
start=InpMAPeriod+begin;
|
||||
ExtLineBuffer[begin]=price[begin];
|
||||
for(i=begin+1; i<start; i++)
|
||||
ExtLineBuffer[i]=price[i]*SmoothFactor+ExtLineBuffer[i-1]*(1.0-SmoothFactor);
|
||||
}
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- main loop
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
ExtLineBuffer[i]=price[i]*SmoothFactor+ExtLineBuffer[i-1]*(1.0-SmoothFactor);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| linear weighted moving average |
|
||||
//+------------------------------------------------------------------+
|
||||
void CalculateLWMA(int rates_total,int prev_calculated,int begin,const double &price[])
|
||||
{
|
||||
int weight=0;
|
||||
int i,l,start;
|
||||
double sum=0.0,lsum=0.0;
|
||||
//--- first calculation or number of bars was changed
|
||||
if(prev_calculated<=InpMAPeriod+begin+2)
|
||||
{
|
||||
start=InpMAPeriod+begin;
|
||||
//--- set empty value for first start bars
|
||||
for(i=0; i<start; i++)
|
||||
ExtLineBuffer[i]=0.0;
|
||||
}
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
|
||||
for(i=start-InpMAPeriod,l=1; i<start; i++,l++)
|
||||
{
|
||||
sum +=price[i]*l;
|
||||
lsum +=price[i];
|
||||
weight+=l;
|
||||
}
|
||||
ExtLineBuffer[start-1]=sum/weight;
|
||||
//--- main loop
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
sum =sum-lsum+price[i]*InpMAPeriod;
|
||||
lsum =lsum-price[i-InpMAPeriod]+price[i];
|
||||
ExtLineBuffer[i]=sum/weight;
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| smoothed moving average |
|
||||
//+------------------------------------------------------------------+
|
||||
void CalculateSmoothedMA(int rates_total,int prev_calculated,int begin,const double &price[])
|
||||
{
|
||||
int i,start;
|
||||
//--- first calculation or number of bars was changed
|
||||
if(prev_calculated==0)
|
||||
{
|
||||
start=InpMAPeriod+begin;
|
||||
//--- set empty value for first start bars
|
||||
for(i=0; i<start-1; i++)
|
||||
ExtLineBuffer[i]=0.0;
|
||||
//--- calculate first visible value
|
||||
double first_value=0;
|
||||
for(i=begin; i<start; i++)
|
||||
first_value+=price[i];
|
||||
first_value/=InpMAPeriod;
|
||||
ExtLineBuffer[start-1]=first_value;
|
||||
}
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- main loop
|
||||
for(i=start; i<rates_total && !IsStopped(); i++)
|
||||
ExtLineBuffer[i]=(ExtLineBuffer[i-1]*(InpMAPeriod-1)+price[i])/InpMAPeriod;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,70 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| DEMA.mq5 |
|
||||
//| Copyright 2000-2023, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2023, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property description "Double Exponential Moving Average"
|
||||
#include <MovingAverages.mqh>
|
||||
//--- indicator settings
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 DarkBlue
|
||||
#property indicator_width1 1
|
||||
#property indicator_label1 "DEMA"
|
||||
#property indicator_applied_price PRICE_CLOSE
|
||||
//--- input parameters
|
||||
input int InpPeriodEMA=14; // EMA period
|
||||
input int InpShift=0; // Indicator's shift
|
||||
//--- indicator buffers
|
||||
double DemaBuffer[];
|
||||
double Ema[];
|
||||
double EmaOfEma[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,DemaBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,Ema,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(2,EmaOfEma,INDICATOR_CALCULATIONS);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,2*InpPeriodEMA-2);
|
||||
//--- sets indicator shift
|
||||
PlotIndexSetInteger(0,PLOT_SHIFT,InpShift);
|
||||
//--- name of label
|
||||
string short_name=StringFormat("DEMA(%d)",InpPeriodEMA);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
PlotIndexSetString(0,PLOT_LABEL,short_name);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Double Exponential Moving Average |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const int begin,
|
||||
const double &price[])
|
||||
{
|
||||
if(rates_total<2*InpPeriodEMA-2)
|
||||
return(0);
|
||||
//---
|
||||
int start;
|
||||
if(prev_calculated==0)
|
||||
start=0;
|
||||
else
|
||||
start=prev_calculated-1;
|
||||
//--- calculate EMA
|
||||
ExponentialMAOnBuffer(rates_total,prev_calculated,0,InpPeriodEMA,price,Ema);
|
||||
//--- calculate EMA on EMA array
|
||||
ExponentialMAOnBuffer(rates_total,prev_calculated,InpPeriodEMA-1,InpPeriodEMA,Ema,EmaOfEma);
|
||||
//--- calculate DEMA
|
||||
for(int i=start; i<rates_total && !IsStopped(); i++)
|
||||
DemaBuffer[i]=2.0*Ema[i]-EmaOfEma[i];
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user