add new indicators ...
This commit is contained in:
@@ -0,0 +1,264 @@
|
||||
///////////////////////////////////////////////////////
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------
|
||||
// Name: XSLN
|
||||
// Description: HULL Trend Detector ...
|
||||
//
|
||||
// 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 XSLN Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "XSLN"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool show = true; // Show
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
#define mainBufferIndex 0
|
||||
double mainBuffer[];
|
||||
|
||||
//
|
||||
#define mainBufferColorIndex 1
|
||||
double mainBufferColor[];
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullColorIDX 1
|
||||
#define bearColorIDX 2
|
||||
|
||||
//
|
||||
#property indicator_label1 "XSLN"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 CLR_NONE, clrGreen, clrDarkRed
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// Variables ...
|
||||
|
||||
//
|
||||
double work[][5];
|
||||
#define hHi 0
|
||||
#define hLo 1
|
||||
#define lHi 2
|
||||
#define lLo 3
|
||||
#define trend 4
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// 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
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
if (ArrayRange(work, 0) != rates_total)
|
||||
{
|
||||
ArrayResize(work, rates_total);
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = (int)MathMax(prev_calculated - 1, 0); i < rates_total; i++)
|
||||
{
|
||||
//
|
||||
if (i == 0)
|
||||
{
|
||||
//
|
||||
work[i][hHi] = high[i];
|
||||
work[i][hLo] = low[i];
|
||||
work[i][lHi] = high[i];
|
||||
work[i][lLo] = low[i];
|
||||
work[i][trend] = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
work[i][trend] = work[i - 1][trend];
|
||||
work[i][hHi] = work[i - 1][hHi];
|
||||
work[i][hLo] = work[i - 1][hLo];
|
||||
work[i][lHi] = work[i - 1][lHi];
|
||||
work[i][lLo] = work[i - 1][lLo];
|
||||
|
||||
//
|
||||
if (work[i - 1][trend] == 1)
|
||||
{
|
||||
//
|
||||
work[i][hHi] = MathMax(work[i - 1][hHi], high[i]);
|
||||
work[i][hLo] = MathMax(work[i - 1][hLo], low[i]);
|
||||
|
||||
//
|
||||
if (high[i] < work[i][hLo])
|
||||
{
|
||||
//
|
||||
work[i][trend] = -1;
|
||||
work[i][lHi] = high[i];
|
||||
work[i][lLo] = low[i];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (work[i - 1][trend] == -1)
|
||||
{
|
||||
//
|
||||
work[i][lHi] = MathMin(work[i - 1][lHi], high[i]);
|
||||
work[i][lLo] = MathMin(work[i - 1][lLo], low[i]);
|
||||
|
||||
//
|
||||
if (low[i] > work[i][lHi])
|
||||
{
|
||||
//
|
||||
work[i][trend] = 1;
|
||||
work[i][hHi] = high[i];
|
||||
work[i][hLo] = low[i];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (work[i][trend] == 1)
|
||||
{
|
||||
mainBuffer[i] = work[i][hLo];
|
||||
}
|
||||
else
|
||||
{
|
||||
mainBuffer[i] = work[i][lHi];
|
||||
}
|
||||
|
||||
//
|
||||
mainBufferColor[i] = mainBufferColor[i - 1];
|
||||
|
||||
//
|
||||
if (work[i][trend] == 1)
|
||||
{
|
||||
mainBufferColor[i] = bullColorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
if (work[i][trend] == -1)
|
||||
{
|
||||
mainBufferColor[i] = bearColorIDX;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Main ...
|
||||
ENUM_DRAW_TYPE mainDrawType = show ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
|
||||
PlotIndexSetInteger(mainBufferIndex, PLOT_SHOW_DATA, true);
|
||||
SetIndexBuffer(mainBufferIndex, mainBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(mainBufferIndex, PLOT_DRAW_TYPE, mainDrawType);
|
||||
SetIndexBuffer(mainBufferColorIndex, mainBufferColor, INDICATOR_COLOR_INDEX);
|
||||
}
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user