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

533 lines
14 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center Sharp Market Pump/Dump Indicator
// ---------------------------------------------
// this indicator detects market
// sharp pump and dumps ...
//
// 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 SHPD Indicator"
#property strict
//
// START Inputs ...
//
input int marketLength = 7; // Market Length
input int loopback = 5; // Loopback for Sharp
input double multiplier = 2.0; // Multiplier
input double minimumMarketGap = 0.03; // Minimum Market Gap
//
// END Inputs ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
// Specify this is an Chart Indicator ...
// #property indicator_chart_window
#property indicator_separate_window
//
#property indicator_buffers 6
#property indicator_plots 6
//
#property indicator_label1 "Market Highest"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrAqua
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
#property indicator_label2 "Market Lowest"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrAqua
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//
#property indicator_label3 "Market Highest Low"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrFuchsia
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
//
#property indicator_label4 "Market Lowest High"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrBlueViolet
#property indicator_style4 STYLE_DOT
#property indicator_width4 1
//
#property indicator_label5 "Market Moving Average"
#property indicator_type5 DRAW_LINE
#property indicator_color5 clrYellow
#property indicator_style5 STYLE_DASHDOT
#property indicator_width5 1
//
#property indicator_label6 "Market Moving Average T"
#property indicator_type6 DRAW_LINE
#property indicator_color6 clrLime
#property indicator_style6 STYLE_DASHDOT
#property indicator_width6 1
//
// here we declare indicator buffers ...
//
double marketHighestBuffer[];
double marketLowestBuffer[];
double marketHighestLowBuffer[];
double marketLowestHighBuffer[];
//
double marketMovingAverageBuffer[];
double marketMovingAverageTBuffer[];
//
#define marketHighestBufferIndex 0
#define marketLowestBufferIndex 1
#define marketHighestLowBufferIndex 2
#define marketLowestHighBufferIndex 3
#define marketMovingAverageBufferIndex 4
#define marketMovingAverageTBufferIndex 5
//
// Includes our shared library ...
#include "../Libraries/x-saherelm.lib.mq4"
//
// here we specify logging enabled or not ...
bool enableLogging = true;
//
// this is a Tag which attached to our Logger ...
string logTag = "X_SHPD_IND";
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// Start Event Handlers ...
//
//
// Initialization ...
int OnInit() {
//
// Validate Inputs ...
if (
loopback < 0
|| marketLength < 0
|| loopback > marketLength
) {
return INIT_PARAMETERS_INCORRECT;
}
//
// Initialize what we want ...
SetIndexBuffer(marketHighestBufferIndex, marketHighestBuffer);
SetIndexBuffer(marketLowestBufferIndex, marketLowestBuffer);
//
SetIndexBuffer(marketHighestLowBufferIndex, marketHighestLowBuffer);
SetIndexBuffer(marketLowestHighBufferIndex, marketLowestHighBuffer);
//
SetIndexBuffer(marketMovingAverageBufferIndex, marketMovingAverageBuffer);
SetIndexBuffer(marketMovingAverageTBufferIndex, marketMovingAverageTBuffer);
//
return INIT_SUCCEEDED;
}
//
// De Initialization ...
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[]
) {
//
int limit;
//
static int lastMarketTrend = 0;
static datetime lastMarketTrendTime = 0;
//
// input variable, we return 0 means nothing passed ...
if (rates_total < marketLength) {
return 0;
}
//
// found which candles calculated before ...
limit = rates_total - prev_calculated;
if (prev_calculated > 0) {
limit++;
}
//
// Do Calculation ...
for (int i = limit - 1 - (loopback + 1); i >= 0; i--) {
//
int lastMarketHighestIndex = iHighest(
_Symbol,
_Period,
MODE_HIGH,
marketLength,
i
);
double lastMarketHighest = high[lastMarketHighestIndex];
marketHighestBuffer[i] = lastMarketHighest;
//
int lastMarketLowestIndex = iLowest(
_Symbol,
_Period,
MODE_LOW,
marketLength,
i
);
double lastMarketLowest = low[lastMarketLowestIndex];
marketLowestBuffer[i] = lastMarketLowest;
//
int lastMarketHighestLowIndex = iLowest(
_Symbol,
_Period,
MODE_HIGH,
marketLength,
i
);
double lastMarketHighestLow = high[lastMarketHighestLowIndex];
marketHighestLowBuffer[i] = lastMarketHighestLow;
//
int lastMarketLowestHighIndex = iHighest(
_Symbol,
_Period,
MODE_LOW,
marketLength,
i
);
double lastMarketLowestHigh = low[lastMarketLowestHighIndex];
marketLowestHighBuffer[i] = lastMarketLowestHigh;
//
double marketMovingAverage = iMA(
_Symbol,
_Period,
marketLength * 2, // Ma Length ...
0, // Ma Shift ...
MODE_SMA, // Ma Method ...
PRICE_MEDIAN, // Ma Applied Price ...
i // Bar Index ...
);
marketMovingAverageBuffer[i] = marketMovingAverage;
//
double marketMovingAverageT = iMA(
_Symbol,
_Period,
marketLength * 2, // Ma Length ...
0, // Ma Shift ...
MODE_SMA, // Ma Method ...
PRICE_TYPICAL, // Ma Applied Price ...
i // Bar Index ...
);
marketMovingAverageTBuffer[i] = marketMovingAverageT;
//
double marketGap = MathAbs(marketMovingAverageBuffer[i] - marketMovingAverageTBuffer[i]);
//
// this means Market Going to Trend Down ...
bool isMCrossOverMT = marketMovingAverageBuffer[i] > marketMovingAverageTBuffer[i]
&& !(
marketMovingAverageBuffer[i + 1] > marketMovingAverageTBuffer[i + 1]
);
bool isTrendDown = isMCrossOverMT &&
marketGap > minimumMarketGap;
//
// this means Market Going to Trend Up ...
bool isMCrossUnderMT = marketMovingAverageBuffer[i] < marketMovingAverageTBuffer[i]
&& !(
marketMovingAverageBuffer[i + 1] < marketMovingAverageTBuffer[i + 1]
);
bool isTrendUp =
// !isTrendDown
// &&
isMCrossUnderMT
&& marketGap > minimumMarketGap;
//
bool isTrendRange = (
!isMCrossUnderMT
&& !isMCrossOverMT
) || (
!isTrendUp
&& !isTrendDown
);
//
// Detect Last Market Trend State & Last Market Trend Time ...
int currentMarketTrend =
isTrendDown ? -1 :
isTrendUp ? 1 :
0;
if (currentMarketTrend != lastMarketTrend) {
//
lastMarketTrend = currentMarketTrend;
lastMarketTrendTime = iTime(
_Symbol,
_Period,
i
);
//
if (isTrendDown) {
//
datetime arrowTime = iTime(
_Symbol,
_Period,
i
);
//
double arrowPrice = iHigh(
_Symbol,
_Period,
i
);
arrowPrice = arrowPrice + (50 * _Point);
//
string lbl = StringConcatenate(
logTag,
"_TrendDown_",
arrowTime
);
//
DrawArrow(
0,
lbl,
0,
arrowTime,
arrowPrice,
SYMBOL_ARROWDOWN,
ANCHOR_TOP,
clrFuchsia,
STYLE_SOLID,
3
);
}
//
if (isTrendUp) {
//
datetime arrowTime = iTime(
_Symbol,
_Period,
i
);
//
double arrowPrice = iLow(
_Symbol,
_Period,
i
);
arrowPrice = arrowPrice - (50 * _Point);
//
string lbl = StringConcatenate(
logTag,
"_TrendUp_",
arrowTime
);
//
DrawArrow(
0,
lbl,
0,
arrowTime,
arrowPrice,
SYMBOL_ARROWUP,
ANCHOR_BOTTOM,
clrAqua,
STYLE_SOLID,
3
);
}
//
if (isTrendRange) {
//
datetime arrowTime = iTime(
_Symbol,
_Period,
i
);
//
double arrowUpPrice = iHigh(
_Symbol,
_Period,
i
);
arrowUpPrice = arrowUpPrice + (50 * _Point);
//
double arrowDownPrice = iLow(
_Symbol,
_Period,
i
);
arrowDownPrice = arrowDownPrice - (50 * _Point);
//
string lblUp = StringConcatenate(
logTag,
"_TrendRange_UP_",
arrowTime
);
//
string lblDown = StringConcatenate(
logTag,
"_TrendRange_DOWN_",
arrowTime
);
//
DrawArrow(
0,
lblUp,
0,
arrowTime,
arrowUpPrice,
SYMBOL_ARROWDOWN,
ANCHOR_TOP,
clrGray,
STYLE_SOLID,
3
);
//
DrawArrow(
0,
lblDown,
0,
arrowTime,
arrowDownPrice,
SYMBOL_ARROWUP,
ANCHOR_BOTTOM,
clrGray,
STYLE_SOLID,
3
);
}
//
bool isSharp = false;
double marketHLGap = marketHighestBuffer[i] - marketLowestBuffer[i];
for (int j = i + loopback; j > i; j--) {
//
double prevMarketHLGap = marketHighestBuffer[j] - marketLowestBuffer[j + 1];
bool isThisSharp =
marketHLGap > prevMarketHLGap * multiplier;
//
isSharp = isSharp ||
(
// (
// isTrendUp || isTrendDown
// )
// &&
(
isThisSharp
&& marketGap > minimumMarketGap
)
);
}
//
if (isSharp) {
//
datetime arrowTime = iTime(
_Symbol,
_Period,
i
);
//
double arrowPrice = iHigh(
_Symbol,
_Period,
i
);
arrowPrice = arrowPrice + (50 * _Point);
//
string lbl = StringConcatenate(
logTag,
"_SHARP_",
arrowTime
);
//
DrawArrow(
0,
lbl,
0,
arrowTime,
arrowPrice,
SYMBOL_ARROWDOWN,
ANCHOR_TOP,
clrYellow,
STYLE_SOLID,
3
);
}
}
}
//
// return value of prev_calculated for next call
return(rates_total);
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// END Functions ...
//