Files
MQL4Data/Bkp/Used/14020425/21-00/Indicators/x-saherelm.shpd.mq4
T
2024-01-25 04:05:58 +03:30

402 lines
8.4 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center XSHPD Indicator
// ---------------------------------------------
// saherelm implementation of above indicator ...
// this indicator uses two ma line:
// - fast ma;
// - slow ma;
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm XSHPD Indicator"
#property strict
//
// START Inputs ...
//
input int marketLength = 7; // Market Length ...
input double sharpDetectMultiplier = 70; // Sharp Detect Multiplier
//
input bool drawLabels = true; // Draw Labels on Founded Sharps
//
input string sharpBullishLabel = "SH_BULL"; // Sharp Bullish Label
input color sharpBullishColor = clrAqua; // Sharp Bullish color
//
input string sharpBearishLabel = "SH_BEAR"; // Sharp Bearish Label
input color sharpBearishColor = clrFuchsia; // Sharp Bearish color
//
// END Inputs ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots 4
//
// Declare Buffers ...
#define marketHighestHighBufferIndex 0
#define marketLowestLowBufferIndex 1
#define sharpBullishBufferIndex 2
#define sharpBearishBufferIndex 3
//
double marketHighestHighBuffer[];
double marketLowestLowBuffer[];
double sharpBullishBuffer[];
double sharpBearishBuffer[];
//
#include "../Libraries/x-saherelm.lib.mq4"
#include "../Libraries/x-saherelm.draw.lib.mq4"
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// Start Event Handlers ...
//
//
// Initialization ...
int OnInit() {
//
// Initialize what we want ...
if (
marketLength <= 0
) {
return INIT_PARAMETERS_INCORRECT;
}
//
enableLogging = true;
//
logTag = "X_SHPD";
//
// Highest High ...
SetIndexLabel(marketHighestHighBufferIndex, "");
SetIndexBuffer(marketHighestHighBufferIndex, marketHighestHighBuffer);
SetIndexStyle(
marketHighestHighBufferIndex,
DRAW_LINE, // DRAW_NONE,
STYLE_DOT,
1, // 0,
clrAqua // clrNONE
);
//
// Lowest Low ...
SetIndexLabel(marketLowestLowBufferIndex, "");
SetIndexBuffer(marketLowestLowBufferIndex, marketLowestLowBuffer);
SetIndexStyle(
marketLowestLowBufferIndex,
DRAW_NONE,
STYLE_DOT,
0,
clrNONE
);
//
// Sharp Bullish Buffer ...
SetIndexLabel(sharpBullishBufferIndex, "");
SetIndexBuffer(sharpBullishBufferIndex, sharpBullishBuffer);
SetIndexStyle(
sharpBullishBufferIndex,
DRAW_NONE,
STYLE_DOT,
0,
clrNONE
);
//
// Sharp Bearish Buffer ...
SetIndexLabel(sharpBearishBufferIndex, "");
SetIndexBuffer(sharpBearishBufferIndex, sharpBearishBuffer);
SetIndexStyle(
sharpBearishBufferIndex,
DRAW_NONE,
STYLE_DOT,
0,
clrNONE
);
//
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
void OnDeinit(const int reason) {
//
RemoveDraws(logTag);
}
//
// Calculating what we want ...
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[]
) {
//
// this counts Available Bars ...
int limit;
//
// because in some cases we may have more than one input for
// calculation and we must prevent any calculation
// untill we pass the biggest input length, here we get max Input length
// and then wait until pass it ...
int maxLength = MathMax(0, marketLength);
//
// input variable, we return 0 means nothing passed ...
if (rates_total < maxLength) {
return 0;
}
//
// found which candles calculated before ...
limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1;
//
// this is the main loop of calculations, for each bar index ...
for (int i = limit - 1; i >= 0; i--) {
//
// Start Calculation here ...
// i is bar_index ...
//
// Calculate Sharp ...
CalculateSharp(i);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Calculating Sharp ...
void CalculateSharp(
const int &bar_index
) {
//
int index = 0;
//
double high = iHigh(
_Symbol,
_Period,
bar_index + 1
);
//
double low = iLow(
_Symbol,
_Period,
bar_index + 1
);
//
double open = iOpen(
_Symbol,
_Period,
bar_index + 1
);
//
double close = iClose(
_Symbol,
_Period,
bar_index + 1
);
//
marketHighestHighBuffer[bar_index] = GetMarketHighestHigh(
bar_index,
marketLength
);
//
marketLowestLowBuffer[bar_index] = GetMarketLowestLow(
bar_index,
marketLength
);
//
double maHHs[];
ArrayResize(
maHHs,
marketLength
);
//
double maLLs[];
ArrayResize(
maLLs,
marketLength
);
//
index = 0;
for (int i = bar_index; i < bar_index + marketLength; i++) {
//
maLLs[index] = marketLowestLowBuffer[i];
maHHs[index] = marketHighestHighBuffer[i];
//
index++;
}
//
int maxHighIdx = ArrayMaximum(maHHs);
double maxHigh = maHHs[maxHighIdx];
//
int minHighIdx = ArrayMinimum(maHHs);
double minHigh = maHHs[minHighIdx];
//
double highDiffRate = (maxHigh - minHigh) / 100;
//
int maxLowIdx = ArrayMaximum(maLLs);
double maxLow = maLLs[maxLowIdx];
//
int minLowIdx = ArrayMinimum(maLLs);
double minLow = maLLs[minLowIdx];
//
double lowDiffRate = (maxLow - minLow) / 100;
//
bool isSharpBullishDetected =
high == maxHigh
&& low > minLow
&& marketHighestHighBuffer[bar_index] == maxHigh
&& maxHigh - minHigh > highDiffRate * sharpDetectMultiplier
;
sharpBullishBuffer[bar_index] = isSharpBullishDetected ? 1 : 0;
//
bool isSharpBearishDetected =
low == minLow
&& high < maxHigh
&& marketLowestLowBuffer[bar_index] == minLow
&& maxLow - minLow > lowDiffRate * sharpDetectMultiplier
;
sharpBearishBuffer[bar_index] = isSharpBearishDetected ? 1 : 0;
//
if (
drawLabels
&& (
isSharpBearishDetected
|| isSharpBullishDetected
)
) {
//
datetime time = iTime(
_Symbol,
_Period,
bar_index
);
//
string lbl = StringConcatenate(
logTag,
isSharpBullishDetected ? "Bullish_" : "Bearish_",
bar_index
);
//
double price =
isSharpBullishDetected
?
marketLowestLowBuffer[bar_index] - (10 * _Point)
:
marketHighestHighBuffer[bar_index] + (10 * _Point)
;
//
uchar arrowCode =
isSharpBullishDetected
?
SYMBOL_ARROWUP
:
SYMBOL_ARROWDOWN
;
//
ENUM_ARROW_ANCHOR anchor =
isSharpBullishDetected
?
ANCHOR_BOTTOM
:
ANCHOR_TOP
;
//
color clr =
isSharpBullishDetected
?
sharpBullishColor
:
sharpBearishColor
;
//
string lblText =
isSharpBullishDetected
?
sharpBullishLabel
:
sharpBearishLabel
;
//
DrawText(
0,
lbl,
0,
time,
price,
lblText,
"Tahoma",
5,
clr
);
}
}
//
// END Functions ...
//