Files
xMQL4/xIndicators/x-saherelm.xhh.mq4
2024-01-25 04:03:36 +03:30

410 lines
9.0 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center XHH 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 XHH Indicator"
#property strict
//
// START Inputs ...
//
//
input int marketLength = 7; // Market Length
//
input int shortCycleMultiplier = 4; // Market Short Cycle Multiplier
input int mediumCycleMultiplier = 14; // Market Medium Cycle Multiplier
input int longCycleMultiplier = 27; // Market Medium Cycle Multiplier
//
// END Inputs ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
#property indicator_chart_window
//
#property indicator_buffers 6
//
#property indicator_plots 6
//
// Start Define Indicator Buffer Styles ...
//
//
// Short Cycle Highest High Buffer ...
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrGreen
#property indicator_style1 STYLE_DOT
#property indicator_width1 1
//
// Short Cycle Lowest Low Buffer ...
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrRed
#property indicator_style2 STYLE_DOT
#property indicator_width2 1
//
// Medium Cycle Highest High Buffer ...
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrAqua
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
//
// Medium Cycle Lowest Low Buffer ...
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrFuchsia
#property indicator_style4 STYLE_DOT
#property indicator_width4 1
//
// Long Cycle Highest High Buffer ...
#property indicator_type5 DRAW_LINE
#property indicator_color5 C'62,82,6'
#property indicator_style5 STYLE_DOT
#property indicator_width5 1
//
// Long Cycle Lowest Low Buffer ...
#property indicator_type6 DRAW_LINE
#property indicator_color6 C'255,81,0'
#property indicator_style6 STYLE_DOT
#property indicator_width6 1
//
// End Define Indicator Buffer Styles ...
//
//
// Buffers ...
#define shortCycleHighestHighBufferIndex 0
#define shortCycleLowestLowBufferIndex 1
#define mediumCycleHighestHighBufferIndex 2
#define mediumCycleLowestLowBufferIndex 3
#define longCycleHighestHighBufferIndex 4
#define longCycleLowestLowBufferIndex 5
double shortCycleHighestHighBuffer[];
double shortCycleLowestLowBuffer[];
double mediumCycleHighestHighBuffer[];
double mediumCycleLowestLowBuffer[];
double longCycleHighestHighBuffer[];
double longCycleLowestLowBuffer[];
//
// Variables ...
int shortCycleLength;
int mediumCycleLength;
int longCycleLength;
//
double highestHighTimes[];
double lowestLowTimes[];
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// Start Event Handlers ...
//
//
// Initialization ...
int OnInit() {
//
// Initialize what we want ...
if (
marketLength <= 0 ||
shortCycleMultiplier <= 0 ||
mediumCycleMultiplier <= 0 ||
shortCycleMultiplier > mediumCycleMultiplier
) {
return INIT_PARAMETERS_INCORRECT;
}
//
// Start Set Index Buffers ...
//
shortCycleLength = shortCycleMultiplier * marketLength;
mediumCycleLength = mediumCycleMultiplier * marketLength;
longCycleLength = longCycleMultiplier * marketLength;
//
// Short Cycle Highest High ...
string scHHLbl = StringConcatenate(
"SC HH(", shortCycleLength, ")"
);
SetIndexBuffer(shortCycleHighestHighBufferIndex, shortCycleHighestHighBuffer);
SetIndexLabel(shortCycleHighestHighBufferIndex, scHHLbl);
//
// Short Cycle Lowest Low ...
string scLLLbl = StringConcatenate(
"SC LL(", shortCycleLength, ")"
);
SetIndexBuffer(shortCycleLowestLowBufferIndex, shortCycleLowestLowBuffer);
SetIndexLabel(shortCycleLowestLowBufferIndex, scLLLbl);
//
// Medium Cycle Highest High ...
string mcHHLbl = StringConcatenate(
"MC HH(", mediumCycleLength, ")"
);
SetIndexBuffer(mediumCycleHighestHighBufferIndex, mediumCycleHighestHighBuffer);
SetIndexLabel(mediumCycleHighestHighBufferIndex, mcHHLbl);
//
// Medium Cycle Lowest Low ...
string mcLLLbl = StringConcatenate(
"MC LL(", mediumCycleLength, ")"
);
SetIndexBuffer(mediumCycleLowestLowBufferIndex, mediumCycleLowestLowBuffer);
SetIndexLabel(mediumCycleLowestLowBufferIndex, mcLLLbl);
//
// Long Cycle Highest High ...
string lcHHLbl = StringConcatenate(
"LC HH(", longCycleLength, ")"
);
SetIndexBuffer(longCycleHighestHighBufferIndex, longCycleHighestHighBuffer);
SetIndexLabel(longCycleHighestHighBufferIndex, lcHHLbl);
//
// Long Cycle Lowest Low ...
string lcLLLbl = StringConcatenate(
"LC LL(", longCycleLength, ")"
);
SetIndexBuffer(longCycleLowestLowBufferIndex, longCycleLowestLowBuffer);
SetIndexLabel(longCycleLowestLowBufferIndex, lcLLLbl);
//
// End Set Index Buffers ...
//
//
return INIT_SUCCEEDED;
}
//
// 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 ...
//
CalculateShortCycle(i);
//
CalculateMediumCycle(i);
//
CalculateLongCycle(i);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Calculating Short Cycle ...
void CalculateShortCycle(
const int &bar_index
) {
//
// Short Cycle Highest High ...
//
int scHHIdx = iHighest(
_Symbol,
_Period,
MODE_HIGH,
shortCycleLength,
bar_index
);
//
double scHH = iHigh(
_Symbol,
_Period,
scHHIdx
);
//
shortCycleHighestHighBuffer[bar_index] = scHH;
//
// Short Cycle Lowest Low ...
//
int scLLIdx = iLowest(
_Symbol,
_Period,
MODE_LOW,
shortCycleLength,
bar_index
);
//
double scLL = iLow(
_Symbol,
_Period,
scLLIdx
);
//
shortCycleLowestLowBuffer[bar_index] = scLL;
}
//
// Calculating Medium Cycle ...
void CalculateMediumCycle(
const int &bar_index
) {
//
// Medium Cycle Highest High ...
//
int mcHHIdx = iHighest(
_Symbol,
_Period,
MODE_HIGH,
mediumCycleLength,
bar_index
);
//
double mcHH = iHigh(
_Symbol,
_Period,
mcHHIdx
);
//
mediumCycleHighestHighBuffer[bar_index] = mcHH;
//
// Medium Cycle Lowest Low ...
//
int mcLLIdx = iLowest(
_Symbol,
_Period,
MODE_LOW,
mediumCycleLength,
bar_index
);
//
double mcLL = iLow(
_Symbol,
_Period,
mcLLIdx
);
//
mediumCycleLowestLowBuffer[bar_index] = mcLL;
}
//
// Calculating Long Cycle ...
void CalculateLongCycle(
const int &bar_index
) {
//
// Long Cycle Highest High ...
//
int lcHHIdx = iHighest(
_Symbol,
_Period,
MODE_HIGH,
longCycleLength,
bar_index
);
//
double lcHH = iHigh(
_Symbol,
_Period,
lcHHIdx
);
//
longCycleHighestHighBuffer[bar_index] = lcHH;
//
// Long Cycle Lowest Low ...
//
int lcLLIdx = iLowest(
_Symbol,
_Period,
MODE_LOW,
longCycleLength,
bar_index
);
//
double lcLL = iLow(
_Symbol,
_Period,
lcLLIdx
);
//
longCycleLowestLowBuffer[bar_index] = lcLL;
}
//
// END Functions ...
//