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

412 lines
8.5 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center X Indicator
// ---------------------------------------------
// saherelm implementation of above 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 X Indicator"
#property strict
//
// START Inputs ...
//
//
input int marketLength = 7; // Market Length
//
input int shortCycleMultiplier = 2; // Market Short Cycle Multiplier
input int mediumCycleMultiplier = 6; // Market Medium Cycle Multiplier
input int longCycleMultiplier = 36; // Market Medium Cycle Multiplier
//
input ENUM_MA_METHOD maMethod = MODE_SMA; // Ma Method
//
// 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 ...
//
// HH Buffers ...
#define scHHBufferIndex 0
#define scLLBufferIndex 1
#define mcHHBufferIndex 2
#define mcLLBufferIndex 3
#define lcHHBufferIndex 4
#define lcLLBufferIndex 5
double scHHBuffer[];
double scLLBuffer[];
double mcHHBuffer[];
double mcLLBuffer[];
double lcHHBuffer[];
double lcLLBuffer[];
//
// Variables ...
int shortCycleLength;
int mediumCycleLength;
int longCycleLength;
//
// 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;
//
// Highest High and Lowest Low Buffers ...
//
// Short Cycle Highest High ...
string scHHLbl = StringConcatenate(
"SC HH(", shortCycleLength, ")"
);
SetIndexBuffer(scHHBufferIndex, scHHBuffer);
SetIndexLabel(scHHBufferIndex, scHHLbl);
//
// Short Cycle Lowest Low ...
string scLLLbl = StringConcatenate(
"SC LL(", shortCycleLength, ")"
);
SetIndexBuffer(scLLBufferIndex, scLLBuffer);
SetIndexLabel(scLLBufferIndex, scLLLbl);
//
// Medium Cycle Highest High ...
string mcHHLbl = StringConcatenate(
"MC HH(", mediumCycleLength, ")"
);
SetIndexBuffer(mcHHBufferIndex, mcHHBuffer);
SetIndexLabel(mcHHBufferIndex, mcHHLbl);
//
// Medium Cycle Lowest Low ...
string mcLLLbl = StringConcatenate(
"MC LL(", mediumCycleLength, ")"
);
SetIndexBuffer(mcLLBufferIndex, mcLLBuffer);
SetIndexLabel(mcLLBufferIndex, mcLLLbl);
//
// Long Cycle Highest High ...
string lcHHLbl = StringConcatenate(
"LC HH(", longCycleLength, ")"
);
SetIndexBuffer(lcHHBufferIndex, lcHHBuffer);
SetIndexLabel(lcHHBufferIndex, lcHHLbl);
//
// Long Cycle Lowest Low ...
string lcLLLbl = StringConcatenate(
"LC LL(", longCycleLength, ")"
);
SetIndexBuffer(lcLLBufferIndex, lcLLBuffer);
SetIndexLabel(lcLLBufferIndex, 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 ...
//
// Calculat Ma's ...
//
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
);
//
scHHBuffer[bar_index] = scHH;
//
// Short Cycle Lowest Low ...
//
int scLLIdx = iLowest(
_Symbol,
_Period,
MODE_LOW,
shortCycleLength,
bar_index
);
//
double scLL = iLow(
_Symbol,
_Period,
scLLIdx
);
//
scLLBuffer[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
);
//
mcHHBuffer[bar_index] = mcHH;
//
// Medium Cycle Lowest Low ...
//
int mcLLIdx = iLowest(
_Symbol,
_Period,
MODE_LOW,
mediumCycleLength,
bar_index
);
//
double mcLL = iLow(
_Symbol,
_Period,
mcLLIdx
);
//
mcLLBuffer[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
);
//
lcHHBuffer[bar_index] = lcHH;
//
// Long Cycle Lowest Low ...
//
int lcLLIdx = iLowest(
_Symbol,
_Period,
MODE_LOW,
longCycleLength,
bar_index
);
//
double lcLL = iLow(
_Symbol,
_Period,
lcLLIdx
);
//
lcLLBuffer[bar_index] = lcLL;
}
//
// END Functions ...
//