Initial Commit ...
This commit is contained in:
@@ -0,0 +1,355 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 Fast Buffer ...
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrGreen
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// Short Cycle Slow Buffer ...
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Medium Cycle Fast Buffer ...
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrAqua
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Medium Cycle Slow Buffer ...
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrFuchsia
|
||||
#property indicator_style4 STYLE_DOT
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// Long Cycle Fast Buffer ...
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 C'62,82,6'
|
||||
#property indicator_style5 STYLE_DOT
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
// Long Cycle Slow 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 ...
|
||||
//
|
||||
// Ma Buffers ...
|
||||
#define scFastBufferIndex 0
|
||||
#define scSlowBufferIndex 1
|
||||
#define mcFastBufferIndex 2
|
||||
#define mcSlowBufferIndex 3
|
||||
#define lcFastBufferIndex 4
|
||||
#define lcSlowBufferIndex 5
|
||||
|
||||
double scFastBuffer[];
|
||||
double scSlowBuffer[];
|
||||
double mcFastBuffer[];
|
||||
double mcSlowBuffer[];
|
||||
double lcFastBuffer[];
|
||||
double lcSlowBuffer[];
|
||||
|
||||
//
|
||||
// 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;
|
||||
|
||||
//
|
||||
// Ma Buffers ...
|
||||
//
|
||||
// Short Cycle ...
|
||||
string scFLbl = StringConcatenate(
|
||||
"SC F(", shortCycleLength, ")"
|
||||
);
|
||||
SetIndexBuffer(scFastBufferIndex, scFastBuffer);
|
||||
SetIndexLabel(scFastBufferIndex, scFLbl);
|
||||
|
||||
//
|
||||
string scSLbl = StringConcatenate(
|
||||
"SC S(", shortCycleLength, ")"
|
||||
);
|
||||
SetIndexBuffer(scSlowBufferIndex, scSlowBuffer);
|
||||
SetIndexLabel(scSlowBufferIndex, scSLbl);
|
||||
|
||||
//
|
||||
// Medium Cycle ...
|
||||
string mcFLbl = StringConcatenate(
|
||||
"MC F(", mediumCycleLength, ")"
|
||||
);
|
||||
SetIndexBuffer(mcFastBufferIndex, mcFastBuffer);
|
||||
SetIndexLabel(mcFastBufferIndex, mcFLbl);
|
||||
|
||||
//
|
||||
string mcSLbl = StringConcatenate(
|
||||
"MC S(", mediumCycleLength, ")"
|
||||
);
|
||||
SetIndexBuffer(mcSlowBufferIndex, mcSlowBuffer);
|
||||
SetIndexLabel(mcSlowBufferIndex, mcSLbl);
|
||||
|
||||
//
|
||||
// Long Cycle ...
|
||||
string lcFLbl = StringConcatenate(
|
||||
"LC F(", longCycleLength, ")"
|
||||
);
|
||||
SetIndexBuffer(lcFastBufferIndex, lcFastBuffer);
|
||||
SetIndexLabel(lcFastBufferIndex, lcFLbl);
|
||||
|
||||
//
|
||||
string lcSLbl = StringConcatenate(
|
||||
"LC S(", longCycleLength, ")"
|
||||
);
|
||||
SetIndexBuffer(lcSlowBufferIndex, lcSlowBuffer);
|
||||
SetIndexLabel(lcSlowBufferIndex, lcSLbl);
|
||||
//
|
||||
// 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
|
||||
) {
|
||||
//
|
||||
double scFast = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
shortCycleLength,
|
||||
0,
|
||||
maMethod,
|
||||
PRICE_OPEN,
|
||||
bar_index
|
||||
);
|
||||
scFastBuffer[bar_index] = scFast;
|
||||
|
||||
//
|
||||
double scSlow = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
shortCycleLength,
|
||||
0,
|
||||
maMethod,
|
||||
PRICE_CLOSE,
|
||||
bar_index
|
||||
);
|
||||
scSlowBuffer[bar_index] = scSlow;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating Medium Cycle ...
|
||||
void CalculateMediumCycle(
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
double mcFast = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mediumCycleLength,
|
||||
0,
|
||||
maMethod,
|
||||
PRICE_OPEN,
|
||||
bar_index
|
||||
);
|
||||
mcFastBuffer[bar_index] = mcFast;
|
||||
|
||||
//
|
||||
double mcSlow = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mediumCycleLength,
|
||||
0,
|
||||
maMethod,
|
||||
PRICE_CLOSE,
|
||||
bar_index
|
||||
);
|
||||
mcSlowBuffer[bar_index] = mcSlow;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating Long Cycle ...
|
||||
void CalculateLongCycle(
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
double lcFast = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
longCycleLength,
|
||||
0,
|
||||
maMethod,
|
||||
PRICE_OPEN,
|
||||
bar_index
|
||||
);
|
||||
lcFastBuffer[bar_index] = lcFast;
|
||||
|
||||
//
|
||||
double lcSlow = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
longCycleLength,
|
||||
0,
|
||||
maMethod,
|
||||
PRICE_CLOSE,
|
||||
bar_index
|
||||
);
|
||||
lcSlowBuffer[bar_index] = lcSlow;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Reference in New Issue
Block a user