Initial Commit ...
This commit is contained in:
@@ -0,0 +1,220 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center ADX Oscillator
|
||||
// ---------------------------------------------
|
||||
// saherelm implementation of above oscillator ...
|
||||
//
|
||||
// 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 ADX Oscillator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int length = 7; // Averaging Length
|
||||
input ENUM_APPLIED_PRICE appliedPrice = PRICE_WEIGHTED; // Averaging Applied Price
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_minimum 0
|
||||
#property indicator_maximum 100
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
|
||||
//
|
||||
#property indicator_level1 0.0
|
||||
#property indicator_level2 50.0
|
||||
#property indicator_level3 70.0
|
||||
#property indicator_level4 100.0
|
||||
#property indicator_levelcolor clrSilver
|
||||
#property indicator_levelstyle STYLE_DOT
|
||||
|
||||
//
|
||||
// ADX ...
|
||||
#property indicator_width1 1
|
||||
#property indicator_color1 clrLightBlue
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
|
||||
//
|
||||
// Positive Direction ...
|
||||
#property indicator_width2 1
|
||||
#property indicator_color2 clrLime
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_style2 STYLE_DOT
|
||||
|
||||
//
|
||||
// Negative Direction ...
|
||||
#property indicator_width3 1
|
||||
#property indicator_color3 clrRed
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_style3 STYLE_DOT
|
||||
|
||||
//
|
||||
// Declare Buffers ...
|
||||
#define adxBufferIndex 0
|
||||
#define positiveBufferIndex 1
|
||||
#define negativeBufferIndex 2
|
||||
|
||||
double adxBuffer[];
|
||||
double positiveBuffer[];
|
||||
double negativeBuffer[];
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
|
||||
//
|
||||
// Validating Input Parameters ...
|
||||
if (length < 0) {
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
IndicatorBuffers(3);
|
||||
|
||||
//
|
||||
SetIndexBuffer(positiveBufferIndex, positiveBuffer);
|
||||
SetIndexLabel(positiveBufferIndex, "DI+");
|
||||
|
||||
//
|
||||
SetIndexBuffer(negativeBufferIndex, negativeBuffer);
|
||||
SetIndexLabel(negativeBufferIndex, "DI-");
|
||||
|
||||
//
|
||||
SetIndexBuffer(adxBufferIndex, adxBuffer);
|
||||
SetIndexLabel(adxBufferIndex, "ADX");
|
||||
|
||||
//
|
||||
// initialization done ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculation ...
|
||||
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, length);
|
||||
|
||||
//
|
||||
// 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 Long TP ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
void CalculateBuffers(
|
||||
const int bar_index
|
||||
) {
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
|
||||
//
|
||||
// Retrieves the current ADX value ...
|
||||
double adx = iADX(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
appliedPrice,
|
||||
MODE_MAIN,
|
||||
bar_index
|
||||
);
|
||||
adxBuffer[bar_index] = adx;
|
||||
|
||||
//
|
||||
// Retrieves the current DI+ value ...
|
||||
double plusDi = iADX(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
appliedPrice,
|
||||
MODE_PLUSDI,
|
||||
bar_index
|
||||
);
|
||||
positiveBuffer[bar_index] = plusDi;
|
||||
|
||||
//
|
||||
// Retrieves the current DI- value ...
|
||||
double minusDi = iADX(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
appliedPrice,
|
||||
MODE_MINUSDI,
|
||||
bar_index
|
||||
);
|
||||
negativeBuffer[bar_index] = minusDi;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,173 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MA 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 MA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
// Fast MA ...
|
||||
input int maLength = 20; // MA Length
|
||||
input int maShift = 0; // MA Shift
|
||||
input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method
|
||||
input ENUM_APPLIED_PRICE maAppliedPrice = PRICE_CLOSE; // MA Applied Price
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 1
|
||||
|
||||
//
|
||||
#property indicator_plots 1
|
||||
|
||||
//
|
||||
// Start Define Indicator Buffer Styles ...
|
||||
//
|
||||
//
|
||||
// Fast Ma Buffer ...
|
||||
#property indicator_label1 "Ma"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrYellow
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 2
|
||||
|
||||
//
|
||||
// End Define Indicator Buffer Styles ...
|
||||
//
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
#define maBufferIndex 0
|
||||
|
||||
double maBuffer[];
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
if (maLength <= 0) {
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Start Set Index Buffers ...
|
||||
//
|
||||
//
|
||||
// Ma ...
|
||||
SetIndexBuffer(maBufferIndex, maBuffer);
|
||||
SetIndexDrawBegin(maBufferIndex, maLength + 1);
|
||||
//
|
||||
// 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, maLength);
|
||||
|
||||
//
|
||||
// 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 Ma ...
|
||||
CalculateMa(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Calculating Ma ...
|
||||
void CalculateMa(
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
// Calculating Fast Ma ...
|
||||
double ma = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
maLength,
|
||||
maShift,
|
||||
maMethod,
|
||||
maAppliedPrice,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
maBuffer[bar_index] = ma;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,160 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center Momentum Oscillator
|
||||
// ---------------------------------------------
|
||||
// saherelm implementation of above oscillator ...
|
||||
//
|
||||
// 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 Momentum Oscillator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int length = 7; // Market Length
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 1
|
||||
|
||||
//
|
||||
#property indicator_level1 0.0
|
||||
#property indicator_level2 100.0
|
||||
#property indicator_levelcolor clrSilver
|
||||
#property indicator_levelstyle STYLE_DOT
|
||||
|
||||
//
|
||||
// MOMENTUM ...
|
||||
#property indicator_width1 1
|
||||
#property indicator_color1 clrLightBlue
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
|
||||
//
|
||||
// Declare Buffers ...
|
||||
#define momentumBufferIndex 0
|
||||
|
||||
double momentumBuffer[];
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
|
||||
//
|
||||
// Validating Input Parameters ...
|
||||
if (length < 0) {
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
IndicatorBuffers(1);
|
||||
|
||||
//
|
||||
SetIndexBuffer(momentumBufferIndex, momentumBuffer);
|
||||
SetIndexLabel(momentumBufferIndex, "Momentum");
|
||||
SetIndexDrawBegin(momentumBufferIndex, length);
|
||||
|
||||
//
|
||||
// initialization done ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculation ...
|
||||
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, length);
|
||||
|
||||
//
|
||||
// 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 Long TP ...
|
||||
CalculateBuffers(
|
||||
i,
|
||||
close
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
void CalculateBuffers(
|
||||
const int bar_index,
|
||||
const double &close[]
|
||||
) {
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
double momentum = close[bar_index] * 100 / close[bar_index + length];
|
||||
|
||||
//
|
||||
momentumBuffer[bar_index] = momentum;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,257 @@
|
||||
/////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center OSC Indicator
|
||||
// -------------------------------------------------------------
|
||||
// this indicator provides OSC ...
|
||||
//
|
||||
// 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 OSC Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
// FastOSC ...
|
||||
// Short Cycle (Fast OSC) ...
|
||||
input int fastOSCLength = 10; // FastOSC Length
|
||||
input double fastOSCMultiplier = 1.0; // FastOSC Multiplier
|
||||
|
||||
//
|
||||
// SlowOSC ...
|
||||
// Medium Cycle (Slow OSC) ...
|
||||
input int slowOSCLength = 30; // SlowOSC Length
|
||||
input double slowOSCMultiplier = 3.0; // SlowOSC Multiplier
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
// Includes our shared library ...
|
||||
#include "../Libraries/x-saherelm.lib.mq4"
|
||||
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
// we have 2 buffer in this indicator ...
|
||||
#property indicator_buffers 2
|
||||
|
||||
//
|
||||
// also we have 2 line for draw on this indicator ...
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
// Fast OSC ...
|
||||
#property indicator_width1 1
|
||||
#property indicator_color1 clrAqua
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
|
||||
//
|
||||
// Slow OSC ...
|
||||
#property indicator_width2 1
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrFuchsia
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
|
||||
//
|
||||
// set color of horizontal levels ...
|
||||
#property indicator_levelcolor clrGray
|
||||
|
||||
//
|
||||
// set style of horizontal levels ...
|
||||
#property indicator_levelstyle STYLE_DOT
|
||||
|
||||
//
|
||||
// Declare Buffers ...
|
||||
#define fastOSCBufferIndex 0
|
||||
#define slowOSCBufferIndex 1
|
||||
|
||||
//
|
||||
double fastOSCBuffer[];
|
||||
double slowOSCBuffer[];
|
||||
|
||||
//
|
||||
// Used Indicators List ...
|
||||
string rmaIndicatorName = "x-saherelm.rma";
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
|
||||
//
|
||||
// Validating Input Parameters ...
|
||||
if (
|
||||
fastOSCLength < 0 ||
|
||||
slowOSCLength < 0 ||
|
||||
slowOSCLength <= fastOSCLength
|
||||
) {
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// here we specify logging enabled or not ...
|
||||
enableLogging = true;
|
||||
|
||||
//
|
||||
// this is a Tag which attached to our Logger ...
|
||||
logTag = "XS_OSC";
|
||||
|
||||
//
|
||||
// set descriptions of horizontal levels ...
|
||||
SetLevelValue(0, 0.0);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT,0,"");
|
||||
|
||||
//
|
||||
// set descriptions of horizontal levels ...
|
||||
SetLevelValue(1, 0.5);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT,1,"");
|
||||
|
||||
//
|
||||
// set descriptions of horizontal levels ...
|
||||
SetLevelValue(2, 1);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT,2,"");
|
||||
|
||||
//
|
||||
// Fast OSC Buffer ...
|
||||
SetIndexBuffer(fastOSCBufferIndex, fastOSCBuffer);
|
||||
SetIndexLabel(fastOSCBufferIndex, "Fast OSC");
|
||||
SetIndexDrawBegin(fastOSCBufferIndex, fastOSCLength - 1);
|
||||
|
||||
//
|
||||
// Slow OSC Buffer ...
|
||||
SetIndexBuffer(slowOSCBufferIndex, slowOSCBuffer);
|
||||
SetIndexLabel(slowOSCBufferIndex, "Slow OSC");
|
||||
SetIndexDrawBegin(slowOSCBufferIndex, slowOSCLength - 1);
|
||||
|
||||
//
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculation ...
|
||||
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(fastOSCLength, slowOSCLength);
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
|
||||
//
|
||||
CalculateOscillators(close, i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// De Initialization ...
|
||||
void OnDeinit(const int reason) {
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
void CalculateOscillators(
|
||||
const double &close[],
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
// FastOSC ...
|
||||
// Short Cycle Calculations ...
|
||||
int scl = fastOSCLength / 2;
|
||||
int scl2 = scl / 2;
|
||||
double maScl = iCustom(_Symbol, _Period, rmaIndicatorName, scl, 0, bar_index);
|
||||
double scmAtr = iATR(_Symbol, _Period, scl, bar_index);
|
||||
double scmOff = fastOSCMultiplier * scmAtr;
|
||||
double maScl2 = iCustom(_Symbol, _Period, rmaIndicatorName, scl2, 0, bar_index);
|
||||
double sctParam = maScl2 != 0 ? maScl2 : close[bar_index + 1];
|
||||
double sct = sctParam + scmOff;
|
||||
double scb = sctParam - scmOff;
|
||||
|
||||
//
|
||||
// SlowOSC ...
|
||||
// Medium Cycle Calculations ...
|
||||
int mcl = slowOSCLength / 2;
|
||||
int mcl2 = mcl / 2;
|
||||
double maMcl = iCustom(_Symbol, _Period, rmaIndicatorName, mcl, 0, bar_index);
|
||||
double mcmAtr = iATR(_Symbol, _Period, mcl, bar_index);
|
||||
double mcmOff = slowOSCMultiplier * mcmAtr;
|
||||
double maMcl2 = iCustom(_Symbol, _Period, rmaIndicatorName, mcl2, 0, bar_index);
|
||||
double mctParam = maMcl2 != 0 ? maMcl2 : close[bar_index + 1];
|
||||
double mct = mctParam + mcmOff;
|
||||
double mcb = mctParam - mcmOff;
|
||||
|
||||
//
|
||||
double scMM = (sct + scb) / 2;
|
||||
|
||||
//
|
||||
double fastOCS = (close[bar_index] - mcb) / (mct - mcb);
|
||||
fastOSCBuffer[bar_index] = fastOCS;
|
||||
|
||||
//
|
||||
double slowOCS = (scMM - mcb) / (mct - mcb);
|
||||
slowOSCBuffer[bar_index] = slowOCS;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,215 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center PSAR Oscillator
|
||||
// ---------------------------------------------
|
||||
// saherelm implementation of above oscillator ...
|
||||
//
|
||||
// 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 PSAR Oscillator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int shift = 0; // Shift
|
||||
input double step = 0.02; // Step
|
||||
input double maximum = 0.2; // Maximum
|
||||
input bool drawAsDots = false; // Draw As Dots
|
||||
//
|
||||
input int priceSmoothing = 0; // Price Smoothing
|
||||
input ENUM_APPLIED_PRICE priceLow = PRICE_CLOSE; // Psar low price
|
||||
input ENUM_APPLIED_PRICE priceHigh = PRICE_OPEN; // Psar high price
|
||||
input ENUM_MA_METHOD priceSmoothingMethod = MODE_SMA; // Price Smoothing Method
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
|
||||
//
|
||||
#property indicator_color1 clrLimeGreen
|
||||
#property indicator_width1 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_style1 STYLE_DOT
|
||||
|
||||
//
|
||||
#property indicator_color2 clrAqua
|
||||
#property indicator_width2 1
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_style2 STYLE_DOT
|
||||
|
||||
//
|
||||
#property indicator_color3 clrFuchsia
|
||||
#property indicator_width3 1
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_style3 STYLE_DOT
|
||||
|
||||
//
|
||||
//
|
||||
// Declare Buffers ...
|
||||
//
|
||||
#define sarBufferIndex 0
|
||||
#define upBufferIndex 1
|
||||
#define downBufferIndex 2
|
||||
|
||||
//
|
||||
double sarBuffer[];
|
||||
double upBuffer[];
|
||||
double downBuffer[];
|
||||
|
||||
//
|
||||
// Includes Logger library ...
|
||||
#include "../Libraries/x-saherelm.lib.mq4"
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
|
||||
//
|
||||
SetIndexBuffer(sarBufferIndex, sarBuffer);
|
||||
SetIndexLabel(sarBufferIndex, "SAR");
|
||||
|
||||
//
|
||||
SetIndexBuffer(upBufferIndex, upBuffer);
|
||||
SetIndexLabel(upBufferIndex, "Up");
|
||||
|
||||
//
|
||||
SetIndexBuffer(downBufferIndex, downBuffer);
|
||||
SetIndexLabel(downBufferIndex, "Down");
|
||||
|
||||
//
|
||||
// here we specify logging enabled or not ...
|
||||
enableLogging = true;
|
||||
|
||||
//
|
||||
// this is a Tag which attached to our Logger ...
|
||||
logTag = "XS_PSAR";
|
||||
|
||||
//
|
||||
// initialization done ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculation ...
|
||||
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, length);
|
||||
|
||||
//
|
||||
// input variable, we return 0 means nothing passed ...
|
||||
if (rates_total < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// found which candles calculated before ...
|
||||
limit = (prev_calculated == 0) ? rates_total - 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 Long TP ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
void CalculateBuffers(
|
||||
const int bar_index
|
||||
) {
|
||||
//
|
||||
// Calculate isarValue ...
|
||||
double sarValue = iSAR(
|
||||
NULL,
|
||||
_Period,
|
||||
step,
|
||||
maximum,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
double pHigh = iMA(
|
||||
NULL,
|
||||
_Period,
|
||||
priceSmoothing,
|
||||
0,
|
||||
priceSmoothingMethod,
|
||||
priceHigh,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
double pLow = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
priceSmoothing,
|
||||
0,
|
||||
priceSmoothingMethod,
|
||||
priceLow,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
upBuffer[bar_index] = pHigh;
|
||||
sarBuffer[bar_index] = sarValue;
|
||||
downBuffer[bar_index] = pLow;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,141 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center RMA Indicator
|
||||
// ---------------------------------------------
|
||||
// saherelm implementation of above oscillator ...
|
||||
//
|
||||
// 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 RMA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
// Set the RMA Length ...
|
||||
input int RMALength = 10; // Length
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
// we have 2 buffer in this indicator ...
|
||||
#property indicator_buffers 1
|
||||
|
||||
//
|
||||
// also we have 1 line for draw on this indicator ...
|
||||
#property indicator_plots 1
|
||||
|
||||
//
|
||||
// here we declare plot SlowOCS to system ...
|
||||
#property indicator_label1 "RMA"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrFuchsia
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// Declare Buffers ...
|
||||
#define RMABufferIndex 0
|
||||
|
||||
//
|
||||
double RMABuffer[];
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
SetIndexBuffer(RMABufferIndex, RMABuffer);
|
||||
|
||||
//
|
||||
// initialization done ...
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculation ...
|
||||
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 maxLength = MathMax(0, RMALength);
|
||||
|
||||
//
|
||||
// wait to pass bars until we have rights ...
|
||||
if (rates_total <= maxLength) {
|
||||
//
|
||||
// return not calculated ...
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// find loop count for bars manipulation ...
|
||||
int count = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1;
|
||||
|
||||
//
|
||||
// Print("Count: ", count, ", Bars: ", Bars);
|
||||
|
||||
//
|
||||
// this is the main loop of calculations, for each bar index ...
|
||||
for (int i = count - 1; i >= 0; i--) {
|
||||
//
|
||||
// Start Calculation with Formula 1 ...
|
||||
//
|
||||
double shortSMA = iMA(_Symbol, _Period, RMALength, 0, MODE_SMA, PRICE_CLOSE, i);
|
||||
double mediumSMA = iMA(_Symbol, _Period, RMALength * 2, 0, MODE_SMA, PRICE_CLOSE, i);
|
||||
double longSMA = iMA(_Symbol, _Period, RMALength * 3, 0, MODE_SMA, PRICE_CLOSE, i);
|
||||
|
||||
//
|
||||
double rma1 = longSMA - mediumSMA + shortSMA;
|
||||
rma1 = NormalizeDouble(rma1, _Digits);
|
||||
//
|
||||
// End Calculation with Formula 1 ...
|
||||
//
|
||||
|
||||
//
|
||||
RMABuffer[i] = rma1;
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,234 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center RSI Oscillator
|
||||
// ---------------------------------------------
|
||||
// saherelm implementation of above oscillator ...
|
||||
//
|
||||
// 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 RSI Oscillator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int rsiPeriod=14; // RSI Period
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_minimum 0
|
||||
#property indicator_maximum 100
|
||||
|
||||
//
|
||||
#property indicator_buffers 1
|
||||
#property indicator_color1 DodgerBlue
|
||||
|
||||
//
|
||||
#property indicator_level1 30.0
|
||||
#property indicator_level2 50.0
|
||||
#property indicator_level3 70.0
|
||||
#property indicator_levelcolor clrSilver
|
||||
#property indicator_levelstyle STYLE_DOT
|
||||
|
||||
//
|
||||
// Declare Buffers ...
|
||||
#define rsiBufferIndex 0
|
||||
#define positiveBufferIndex 1
|
||||
#define negativeBufferIndex 2
|
||||
|
||||
double rsiBuffer[];
|
||||
double positiveBuffer[];
|
||||
double negativeBuffer[];
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
|
||||
//
|
||||
string short_name;
|
||||
|
||||
//
|
||||
IndicatorBuffers(3);
|
||||
|
||||
//
|
||||
SetIndexBuffer(positiveBufferIndex, positiveBuffer);
|
||||
SetIndexBuffer(negativeBufferIndex, negativeBuffer);
|
||||
|
||||
//
|
||||
SetIndexStyle(rsiBufferIndex, DRAW_LINE);
|
||||
SetIndexBuffer(rsiBufferIndex, rsiBuffer);
|
||||
|
||||
//
|
||||
// name for DataWindow and indicator subwindow label
|
||||
short_name="RSI("+string(rsiPeriod)+")";
|
||||
IndicatorShortName(short_name);
|
||||
SetIndexLabel(rsiBufferIndex, short_name);
|
||||
|
||||
//
|
||||
// check for input
|
||||
if (rsiPeriod < 2) {
|
||||
//
|
||||
Print("Incorrect value for input variable InpRSIPeriod = ", rsiPeriod);
|
||||
|
||||
//
|
||||
// Failed Initialization ...
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// set where to start draw ...
|
||||
SetIndexDrawBegin(0, rsiPeriod);
|
||||
|
||||
//
|
||||
// initialization done ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculation ...
|
||||
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 i,pos;
|
||||
double diff;
|
||||
|
||||
//
|
||||
// Prevent from run calculations if there is no fulfilled conditions ...
|
||||
if (Bars <= rsiPeriod || rsiPeriod < 2) {
|
||||
//
|
||||
// return nothing calculated result ...
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// counting from 0 to rates_total, this is most important ...
|
||||
ArraySetAsSeries(rsiBuffer, false);
|
||||
ArraySetAsSeries(positiveBuffer, false);
|
||||
ArraySetAsSeries(negativeBuffer, false);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(close, false);
|
||||
|
||||
//
|
||||
// preliminary calculations ...
|
||||
pos = prev_calculated - 1;
|
||||
if (pos <= rsiPeriod) {
|
||||
//
|
||||
// first RSIPeriod values of the indicator are not calculated
|
||||
rsiBuffer[0] = 0.0;
|
||||
positiveBuffer[0] = 0.0;
|
||||
negativeBuffer[0] = 0.0;
|
||||
|
||||
//
|
||||
double sump=0.0;
|
||||
double sumn=0.0;
|
||||
for (i = 1; i <= rsiPeriod; i++) {
|
||||
//
|
||||
rsiBuffer[i]=0.0;
|
||||
positiveBuffer[i]=0.0;
|
||||
negativeBuffer[i]=0.0;
|
||||
|
||||
//
|
||||
diff = close[i] - close[i - 1];
|
||||
if(diff > 0) {
|
||||
sump += diff;
|
||||
} else {
|
||||
sumn -= diff;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// calculate first visible value ...
|
||||
positiveBuffer[rsiPeriod] = sump / rsiPeriod;
|
||||
negativeBuffer[rsiPeriod] = sumn / rsiPeriod;
|
||||
if (negativeBuffer[rsiPeriod] != 0.0) {
|
||||
//
|
||||
rsiBuffer[rsiPeriod] = 100.0 - (
|
||||
100.0 / (
|
||||
1.0 + positiveBuffer[rsiPeriod] / negativeBuffer[rsiPeriod]
|
||||
)
|
||||
);
|
||||
} else {
|
||||
//
|
||||
if (positiveBuffer[rsiPeriod] != 0.0) {
|
||||
rsiBuffer[rsiPeriod] = 100.0;
|
||||
} else {
|
||||
rsiBuffer[rsiPeriod] = 50.0;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// prepare the position value for main calculation ...
|
||||
pos = rsiPeriod + 1;
|
||||
}
|
||||
|
||||
//
|
||||
// the main loop of calculations ...
|
||||
for (i = pos; i < rates_total && !IsStopped(); i++) {
|
||||
//
|
||||
diff = close[i] - close[i-1];
|
||||
|
||||
//
|
||||
positiveBuffer[i] = (positiveBuffer[i-1] * (rsiPeriod - 1) + (diff > 0.0 ? diff : 0.0)) / rsiPeriod;
|
||||
negativeBuffer[i] = (negativeBuffer[i-1] * (rsiPeriod - 1) + (diff < 0.0 ? -diff : 0.0)) / rsiPeriod;
|
||||
|
||||
//
|
||||
if (negativeBuffer[i] != 0.0) {
|
||||
rsiBuffer[i] = 100.0 - 100.0 / (1 + positiveBuffer[i] / negativeBuffer[i]);
|
||||
} else {
|
||||
//
|
||||
if (positiveBuffer[i] != 0.0) {
|
||||
rsiBuffer[i] = 100.0;
|
||||
} else {
|
||||
rsiBuffer[i] = 50.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return(rates_total);
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,402 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 ...
|
||||
//
|
||||
@@ -0,0 +1,154 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center StopLoss 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 StopLoss Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int swingLoopback = 7; // Swing Loopback
|
||||
input double thrshold = 10; // Threshold
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
// Specify this is an Chart Indicator ...
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
// we have 2 buffer in this indicator ...
|
||||
#property indicator_buffers 2
|
||||
|
||||
//
|
||||
// also we have 2 line for draw on this indicator ...
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
// here we declare plot Long Stop Loss to system ...
|
||||
#property indicator_label1 "Long Stop Loss"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrFuchsia
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// here we declare plot Short Stop Loss to system ...
|
||||
#property indicator_label2 "Short Stop Loss"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrAqua
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// here we declare indicator buffers ...
|
||||
//
|
||||
double longStopLossBuffer[];
|
||||
double shortStopLossBuffer[];
|
||||
|
||||
//
|
||||
#define longStopLossIndex 0
|
||||
#define shortStopLossIndex 1
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
SetIndexBuffer(longStopLossIndex, longStopLossBuffer);
|
||||
SetIndexBuffer(shortStopLossIndex, shortStopLossBuffer);
|
||||
|
||||
//
|
||||
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[]
|
||||
) {
|
||||
//
|
||||
int limit;
|
||||
|
||||
//
|
||||
// input variable, we return 0 means nothing passed ...
|
||||
if (rates_total < swingLoopback) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// found which candles calculated before ...
|
||||
limit = rates_total - prev_calculated;
|
||||
if (prev_calculated > 0) {
|
||||
limit++;
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculation ...
|
||||
for (int i = limit - 1; i >= 0; i--) {
|
||||
//
|
||||
int lastMarketHighestIndex = iHighest(_Symbol, _Period, MODE_HIGH, swingLoopback, i);
|
||||
double lastMarketHighest = high[lastMarketHighestIndex];
|
||||
|
||||
//
|
||||
int lastMarketLowestIndex = iLowest(_Symbol, _Period, MODE_LOW, swingLoopback, i);
|
||||
double lastMarketLowest = low[lastMarketLowestIndex];
|
||||
|
||||
//
|
||||
double longStopLoss = lastMarketLowest - (thrshold * _Point);
|
||||
longStopLoss = NormalizeDouble(longStopLoss, _Digits);
|
||||
|
||||
//
|
||||
double shortStopLoss = lastMarketHighest + (thrshold * _Point);
|
||||
shortStopLoss = NormalizeDouble(shortStopLoss, _Digits);
|
||||
|
||||
//
|
||||
longStopLossBuffer[i] = longStopLoss;
|
||||
shortStopLossBuffer[i] = shortStopLoss;
|
||||
}
|
||||
|
||||
//
|
||||
// return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,221 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center TP Indicator
|
||||
// ---------------------------------------------
|
||||
// saherelm implementation of above oscillator ...
|
||||
//
|
||||
// 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 TP Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
// Set the R2R Length ...
|
||||
input int swingLoopback = 7; // Swing Loopback
|
||||
input double slThrshold = 10; // SL Threshold
|
||||
input double riskToRewardRatio = 1.5; // Risk to Reward Ratio
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
// define indicator buffers ...
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
// here we declare plot to system ...
|
||||
#property indicator_label1 "Long TP"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrLime
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// here we declare plot to system ...
|
||||
#property indicator_label2 "Short TP"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Declare Buffers ...
|
||||
#define longTPBufferIndex 0
|
||||
#define shortTPBufferIndex 1
|
||||
|
||||
//
|
||||
double longTPBuffer[];
|
||||
double shortTPBuffer[];
|
||||
|
||||
//
|
||||
string slIndicatorName = "x-saherelm.sl";
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
SetIndexBuffer(longTPBufferIndex, longTPBuffer);
|
||||
SetIndexDrawBegin(longTPBufferIndex, swingLoopback);
|
||||
|
||||
//
|
||||
SetIndexBuffer(shortTPBufferIndex, shortTPBuffer);
|
||||
SetIndexDrawBegin(shortTPBufferIndex, swingLoopback);
|
||||
|
||||
//
|
||||
// initialization done ...
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculation ...
|
||||
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, swingLoopback);
|
||||
|
||||
//
|
||||
// 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 Long TP ...
|
||||
CalculateLongTP(
|
||||
open,
|
||||
i
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Short TP ...
|
||||
CalculateShortTP(
|
||||
open,
|
||||
i
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Calculate Long TPs based on SL and Open Price ...
|
||||
void CalculateLongTP(
|
||||
const double &open[],
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
// read long sl ...
|
||||
double longSL = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slIndicatorName,
|
||||
swingLoopback,
|
||||
slThrshold,
|
||||
0, // Long SL Buffer Index ...
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
double longRisk = open[bar_index] - longSL;
|
||||
double longReward = longRisk * riskToRewardRatio;
|
||||
|
||||
//
|
||||
double longTP = open[bar_index] + longReward;
|
||||
longTP = NormalizeDouble(longTP, _Digits);
|
||||
|
||||
//
|
||||
longTPBuffer[bar_index] = longTP;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Short TPs based on SL and Open Price ...
|
||||
void CalculateShortTP(
|
||||
const double &open[],
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
// read short sl ...
|
||||
double shortSL = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slIndicatorName,
|
||||
swingLoopback,
|
||||
slThrshold,
|
||||
1, // Short SL Buffer Index ...
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
double shortRisk = shortSL - open[bar_index];
|
||||
double shortReward = shortRisk * riskToRewardRatio;
|
||||
|
||||
//
|
||||
double shortTP = open[bar_index] - shortReward;
|
||||
shortTP = NormalizeDouble(shortTP, _Digits);
|
||||
|
||||
//
|
||||
shortTPBuffer[bar_index] = shortTP;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,250 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center ADX Oscillator
|
||||
// ---------------------------------------------
|
||||
// saherelm implementation of above oscillator ...
|
||||
//
|
||||
// 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 ADX Oscillator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int length = 7; // Averaging Length
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
// #property indicator_buffers 3
|
||||
|
||||
//
|
||||
// Declare Buffers ...
|
||||
//
|
||||
datetime startTime;
|
||||
double lHigh;
|
||||
double lLow;
|
||||
|
||||
//
|
||||
datetime highTimes[];
|
||||
|
||||
//
|
||||
datetime lowTimes[];
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
|
||||
//
|
||||
// Validating Input Parameters ...
|
||||
if (length < 0) {
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// initialization done ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculation ...
|
||||
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, length);
|
||||
|
||||
//
|
||||
// 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 Long TP ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
void CalculateBuffers(
|
||||
const int bar_index
|
||||
) {
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
//
|
||||
int startBarIndex = iBarShift(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startTime
|
||||
);
|
||||
|
||||
//
|
||||
datetime barTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
if (startTime == 0) {
|
||||
//
|
||||
startTime = barTime;
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
if (
|
||||
startTime > 0
|
||||
&& startBarIndex - bar_index == length
|
||||
) {
|
||||
//
|
||||
int hhIdx = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_HIGH,
|
||||
length,
|
||||
bar_index
|
||||
);
|
||||
datetime hhTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhIdx
|
||||
);
|
||||
double hh = iHigh(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhIdx
|
||||
);
|
||||
|
||||
//
|
||||
int hhSize = ArraySize(highTimes);
|
||||
datetime tempTimes[];
|
||||
ArrayResize(
|
||||
tempTimes,
|
||||
hhSize
|
||||
);
|
||||
ArrayCopy(
|
||||
tempTimes,
|
||||
highTimes
|
||||
);
|
||||
ArrayResize(
|
||||
highTimes,
|
||||
hhSize + 1
|
||||
);
|
||||
highTimes[0] = hhTime;
|
||||
ArrayCopy(
|
||||
highTimes,
|
||||
tempTimes,
|
||||
1
|
||||
);
|
||||
|
||||
//
|
||||
int llIdx = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_LOW,
|
||||
length,
|
||||
bar_index
|
||||
);
|
||||
datetime llTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llIdx
|
||||
);
|
||||
double ll = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llIdx
|
||||
);
|
||||
|
||||
//
|
||||
int llSize = ArraySize(lowTimes);
|
||||
ArrayFree(tempTimes);
|
||||
ArrayResize(
|
||||
tempTimes,
|
||||
llSize
|
||||
);
|
||||
ArrayCopy(
|
||||
tempTimes,
|
||||
lowTimes
|
||||
);
|
||||
ArrayResize(
|
||||
lowTimes,
|
||||
llSize + 1
|
||||
);
|
||||
lowTimes[0] = llTime;
|
||||
ArrayCopy(
|
||||
lowTimes,
|
||||
tempTimes,
|
||||
1
|
||||
);
|
||||
|
||||
//
|
||||
startTime = 0;
|
||||
ArrayFree(tempTimes);
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,270 @@
|
||||
/////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center Volume Indicator
|
||||
// -------------------------------------------------------------
|
||||
// this indicator provides Volume ...
|
||||
//
|
||||
// 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 Volume Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int length = 11; // Length
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
// Includes our shared library ...
|
||||
#include "../Libraries/x-saherelm.lib.mq4"
|
||||
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
// we have 2 buffer in this indicator ...
|
||||
#property indicator_buffers 3
|
||||
|
||||
//
|
||||
// also we have 2 line for draw on this indicator ...
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
// Buy Volume ...
|
||||
#property indicator_width1 1
|
||||
#property indicator_color1 clrGreen
|
||||
#property indicator_type1 DRAW_HISTOGRAM
|
||||
#property indicator_style1 STYLE_DOT
|
||||
|
||||
//
|
||||
// Sell Volume ...
|
||||
#property indicator_width2 1
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_DOT
|
||||
|
||||
//
|
||||
// Diff ...
|
||||
#property indicator_width3 1
|
||||
#property indicator_type3 DRAW_HISTOGRAM
|
||||
#property indicator_color3 clrYellow
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
|
||||
//
|
||||
//#property indicator_minimum 0
|
||||
//#property indicator_maximum 1
|
||||
|
||||
//
|
||||
// set color of horizontal levels ...
|
||||
#property indicator_levelcolor clrGray
|
||||
|
||||
//
|
||||
// set style of horizontal levels ...
|
||||
#property indicator_levelstyle STYLE_DOT
|
||||
|
||||
//
|
||||
// Declare Buffers ...
|
||||
#define buyVolumeBufferIndex 0
|
||||
#define sellVolumeBufferIndex 1
|
||||
#define diffBufferIndex 2
|
||||
|
||||
//
|
||||
double buyVolumeBuffer[];
|
||||
double sellVolumeBuffer[];
|
||||
double diffBuffer[];
|
||||
|
||||
//
|
||||
// here we specify logging enabled or not ...
|
||||
bool enableLogging = true;
|
||||
|
||||
//
|
||||
// this is a Tag which attached to our Logger ...
|
||||
string logTag = "XS_VOLUME";
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
|
||||
//
|
||||
// Validating Input Parameters ...
|
||||
if (length < 0) {
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// set descriptions of horizontal levels ...
|
||||
SetLevelValue(0, 0.0);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT,0,"");
|
||||
|
||||
//
|
||||
// Buy Volume Buffer ...
|
||||
SetIndexBuffer(buyVolumeBufferIndex, buyVolumeBuffer);
|
||||
SetIndexLabel(buyVolumeBufferIndex, "Buy Volume");
|
||||
|
||||
//
|
||||
// Sell Volume Buffer ...
|
||||
SetIndexBuffer(sellVolumeBufferIndex, sellVolumeBuffer);
|
||||
SetIndexLabel(sellVolumeBufferIndex, "Sell Volume");
|
||||
|
||||
//
|
||||
// Diff Buffer ...
|
||||
SetIndexBuffer(diffBufferIndex, diffBuffer);
|
||||
SetIndexLabel(diffBufferIndex, "Diff");
|
||||
|
||||
//
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculation ...
|
||||
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, length);
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
|
||||
//
|
||||
CalculateBuffers(
|
||||
open,
|
||||
close,
|
||||
high,
|
||||
low,
|
||||
i
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// De Initialization ...
|
||||
void OnDeinit(const int reason) {
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
void CalculateBuffers(
|
||||
const double &open[],
|
||||
const double &close[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
long volume = iVolume(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
double buyVolume = 0.0;
|
||||
double sellVolume = 0.0;
|
||||
|
||||
//
|
||||
// Up ...
|
||||
if (close[bar_index] > open[bar_index]) {
|
||||
//
|
||||
double cuenta = (high[bar_index] - low[bar_index]) * 10000;
|
||||
double cuenta1 = volume - cuenta;
|
||||
|
||||
//
|
||||
buyVolume = ((volume - cuenta) / 2) + cuenta;
|
||||
|
||||
//
|
||||
buyVolumeBuffer[bar_index] = buyVolume;
|
||||
sellVolumeBuffer[bar_index] = volume - buyVolume;
|
||||
} else
|
||||
//
|
||||
// Down ...
|
||||
if (close[bar_index] < open[bar_index]) {
|
||||
//
|
||||
double cuenta1 = (high[bar_index] - low[bar_index]) * 10000;
|
||||
double cuenta = volume - cuenta1;
|
||||
|
||||
//
|
||||
sellVolume = ((volume - cuenta1) / 2) + cuenta1;
|
||||
|
||||
//
|
||||
sellVolumeBuffer[bar_index] = sellVolume;
|
||||
buyVolumeBuffer[bar_index] = volume - sellVolume;
|
||||
} else
|
||||
//
|
||||
// Neutral ...
|
||||
if (close[bar_index] == open[bar_index]) {
|
||||
//
|
||||
double cuenta = (volume / 2) * 1.0;
|
||||
|
||||
//
|
||||
sellVolumeBuffer[bar_index] = cuenta;
|
||||
buyVolumeBuffer[bar_index] = volume - cuenta;
|
||||
}
|
||||
|
||||
//
|
||||
diffBuffer[bar_index] = MathAbs(buyVolumeBuffer[bar_index]) - MathAbs(sellVolumeBuffer[bar_index]);
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,412 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 ...
|
||||
//
|
||||
@@ -0,0 +1,265 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center Trend Power 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 MA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int marketLength = 7; // Market Length
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_plots 3
|
||||
#property indicator_buffers 3
|
||||
#property indicator_minimum 0
|
||||
#property indicator_maximum 100
|
||||
|
||||
//
|
||||
#property indicator_levelcolor clrGray
|
||||
#property indicator_levelstyle STYLE_DOT
|
||||
|
||||
//
|
||||
// Start Define Indicator Buffer Styles ...
|
||||
//
|
||||
#property indicator_type1 DRAW_HISTOGRAM
|
||||
#property indicator_color1 clrLime
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
#property indicator_type2 DRAW_HISTOGRAM
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrYellow
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
//
|
||||
// End Define Indicator Buffer Styles ...
|
||||
//
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
#define powerUpBufferIndex 0
|
||||
#define powerDownBufferIndex 1
|
||||
#define signalBufferIndex 2
|
||||
#define diBufferIndex 3
|
||||
|
||||
double powerUpBuffer[];
|
||||
double powerDownBuffer[];
|
||||
double signalBuffer[];
|
||||
double diBuffer[];
|
||||
|
||||
//
|
||||
#include "../Libraries/x-saherelm.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;
|
||||
}
|
||||
|
||||
//
|
||||
SetLevelValue(0, 0.0);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT,0,"");
|
||||
|
||||
//
|
||||
SetLevelValue(1, 50);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT,1,"");
|
||||
|
||||
//
|
||||
SetLevelValue(2, 100);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT,2,"");
|
||||
|
||||
//
|
||||
string pUpLbl = StringConcatenate(
|
||||
"P Up (", marketLength, ")"
|
||||
);
|
||||
SetIndexLabel(powerUpBufferIndex, pUpLbl);
|
||||
SetIndexBuffer(powerUpBufferIndex, powerUpBuffer);
|
||||
SetIndexDrawBegin(powerUpBufferIndex, marketLength + 1);
|
||||
|
||||
//
|
||||
string pDownLbl = StringConcatenate(
|
||||
"P Down (", marketLength, ")"
|
||||
);
|
||||
SetIndexLabel(powerDownBufferIndex, pDownLbl);
|
||||
SetIndexBuffer(powerDownBufferIndex, powerDownBuffer);
|
||||
SetIndexDrawBegin(powerDownBufferIndex, marketLength + 1);
|
||||
|
||||
//
|
||||
string pSignalLbl = StringConcatenate(
|
||||
"P Signal (", marketLength, ")"
|
||||
);
|
||||
SetIndexLabel(signalBufferIndex, pSignalLbl);
|
||||
SetIndexBuffer(signalBufferIndex, signalBuffer);
|
||||
SetIndexDrawBegin(signalBufferIndex, marketLength + 1);
|
||||
|
||||
//
|
||||
// here we specify logging enabled or not ...
|
||||
enableLogging = true;
|
||||
|
||||
//
|
||||
// this is a Tag which attached to our Logger ...
|
||||
logTag = "X_TPW_OSC";
|
||||
|
||||
//
|
||||
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 ...
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Calculating Ma ...
|
||||
void CalculateBuffers(
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
double powerUp = 0;
|
||||
double powerDown = 0;
|
||||
|
||||
//
|
||||
int dailyCount = GetDailyCandleCount();
|
||||
double dailyHH = GetMarketHighestHigh(
|
||||
bar_index,
|
||||
dailyCount
|
||||
);
|
||||
double dailyLL = GetMarketLowestLow(
|
||||
bar_index,
|
||||
dailyCount
|
||||
);
|
||||
double dailyDiff = dailyHH - dailyLL;
|
||||
double rate = dailyDiff / 100;
|
||||
|
||||
//
|
||||
for (int i = bar_index; i < bar_index + marketLength; i++) {
|
||||
//
|
||||
XOHCL c = GetCandleModel(i);
|
||||
|
||||
//
|
||||
double cRange =
|
||||
MathAbs(c.open - c.close)
|
||||
// MathAbs(c.high - c.low)
|
||||
;
|
||||
bool isBullish = c.open < c.close;
|
||||
|
||||
//
|
||||
if (isBullish) {
|
||||
powerUp += cRange;
|
||||
} else {
|
||||
powerDown += cRange;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
powerUp = powerUp / rate;
|
||||
powerDown = powerDown / rate;
|
||||
|
||||
//
|
||||
double ema = GetMA(
|
||||
bar_index,
|
||||
marketLength,
|
||||
0,
|
||||
MODE_EMA,
|
||||
PRICE_WEIGHTED
|
||||
);
|
||||
|
||||
//
|
||||
double signal = (ema / 100) * rate;
|
||||
double signalAddition = MathMin(powerUp, powerDown);
|
||||
|
||||
//
|
||||
powerUpBuffer[bar_index] = powerUp;
|
||||
powerDownBuffer[bar_index] = powerDown;
|
||||
signalBuffer[bar_index] = signal + signalAddition;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,291 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center Trend Power 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 MA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int marketLength = 7; // Market Length
|
||||
input int shift = 0; // Shift
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_plots 3
|
||||
#property indicator_buffers 3
|
||||
// #property indicator_minimum 0
|
||||
// #property indicator_maximum 200
|
||||
|
||||
//
|
||||
#property indicator_levelcolor clrGray
|
||||
#property indicator_levelstyle STYLE_DOT
|
||||
|
||||
//
|
||||
// Start Define Indicator Buffer Styles ...
|
||||
//
|
||||
#property indicator_type1 DRAW_HISTOGRAM
|
||||
#property indicator_color1 clrLime
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
#property indicator_type2 DRAW_HISTOGRAM
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrYellow
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// #property indicator_type4 DRAW_LINE
|
||||
// #property indicator_color4 clrAqua
|
||||
// #property indicator_style4 STYLE_DASHDOT
|
||||
// #property indicator_width4 1
|
||||
//
|
||||
// End Define Indicator Buffer Styles ...
|
||||
//
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
#define powerUpBufferIndex 0
|
||||
#define powerDownBufferIndex 1
|
||||
#define signalBufferIndex 2
|
||||
// #define diBufferIndex 3
|
||||
|
||||
double powerUpBuffer[];
|
||||
double powerDownBuffer[];
|
||||
double signalBuffer[];
|
||||
// double diBuffer[];
|
||||
|
||||
//
|
||||
#include "../Libraries/x-saherelm.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;
|
||||
}
|
||||
|
||||
// //
|
||||
// SetLevelValue(0, 0.0);
|
||||
// IndicatorSetString(INDICATOR_LEVELTEXT,0,"");
|
||||
|
||||
// //
|
||||
// SetLevelValue(1, 50);
|
||||
// IndicatorSetString(INDICATOR_LEVELTEXT,1,"");
|
||||
|
||||
// //
|
||||
// SetLevelValue(2, 100);
|
||||
// IndicatorSetString(INDICATOR_LEVELTEXT,2,"");
|
||||
|
||||
//
|
||||
string pUpLbl = StringConcatenate(
|
||||
"P Up (", marketLength, ")"
|
||||
);
|
||||
SetIndexLabel(powerUpBufferIndex, pUpLbl);
|
||||
SetIndexBuffer(powerUpBufferIndex, powerUpBuffer);
|
||||
SetIndexDrawBegin(powerUpBufferIndex, marketLength + 1);
|
||||
|
||||
//
|
||||
string pDownLbl = StringConcatenate(
|
||||
"P Down (", marketLength, ")"
|
||||
);
|
||||
SetIndexLabel(powerDownBufferIndex, pDownLbl);
|
||||
SetIndexBuffer(powerDownBufferIndex, powerDownBuffer);
|
||||
SetIndexDrawBegin(powerDownBufferIndex, marketLength + 1);
|
||||
|
||||
//
|
||||
string pSignalLbl = StringConcatenate(
|
||||
"P Signal (", marketLength, ")"
|
||||
);
|
||||
SetIndexLabel(signalBufferIndex, pSignalLbl);
|
||||
SetIndexBuffer(signalBufferIndex, signalBuffer);
|
||||
SetIndexDrawBegin(signalBufferIndex, marketLength + 1);
|
||||
|
||||
// //
|
||||
// string pDiLbl = StringConcatenate(
|
||||
// "P DI (", marketLength, ")"
|
||||
// );
|
||||
// SetIndexLabel(diBufferIndex, pDiLbl);
|
||||
// SetIndexBuffer(diBufferIndex, diBuffer);
|
||||
// SetIndexDrawBegin(diBufferIndex, marketLength + 1);
|
||||
|
||||
//
|
||||
// here we specify logging enabled or not ...
|
||||
enableLogging = true;
|
||||
|
||||
//
|
||||
// this is a Tag which attached to our Logger ...
|
||||
logTag = "X_TPW_OSC";
|
||||
|
||||
//
|
||||
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 ...
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Calculating Ma ...
|
||||
void CalculateBuffers(
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
double powerUp = 0;
|
||||
double powerDown = 0;
|
||||
|
||||
//
|
||||
int dailyCount = GetDailyCandleCount();
|
||||
double dailyHH = GetMarketHighestHigh(
|
||||
bar_index,
|
||||
dailyCount
|
||||
);
|
||||
double dailyLL = GetMarketLowestLow(
|
||||
bar_index,
|
||||
dailyCount
|
||||
);
|
||||
double dailyDiff = dailyHH - dailyLL;
|
||||
double rate = dailyDiff / 100;
|
||||
|
||||
//
|
||||
for (int i = bar_index + shift; i < bar_index + marketLength + shift; i++) {
|
||||
//
|
||||
XOHCL c = GetCandleModel(i);
|
||||
|
||||
//
|
||||
double cRange =
|
||||
MathAbs(c.open - c.close)
|
||||
// MathAbs(c.high - c.low)
|
||||
;
|
||||
bool isBullish = c.open < c.close;
|
||||
|
||||
//
|
||||
if (isBullish) {
|
||||
powerUp += cRange;
|
||||
} else {
|
||||
powerDown += cRange;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
powerUp = powerUp / rate;
|
||||
powerDown = powerDown / rate;
|
||||
|
||||
|
||||
//
|
||||
double ema = GetMA(
|
||||
bar_index,
|
||||
(marketLength * 2),
|
||||
0,
|
||||
MODE_EMA,
|
||||
PRICE_WEIGHTED
|
||||
);
|
||||
|
||||
//
|
||||
powerUpBuffer[bar_index] = powerUp;
|
||||
|
||||
//
|
||||
powerDownBuffer[bar_index] = -1 * powerDown;
|
||||
|
||||
//
|
||||
double emaRate = MathAbs(powerUp - MathAbs(powerDown)) / 100;
|
||||
double signal = (ema / 100) * emaRate;
|
||||
|
||||
//
|
||||
bool isPowerUp = powerUp > MathAbs(powerDown);
|
||||
double signalAddition = isPowerUp ? (-1 * powerDown) : powerUp;
|
||||
signalBuffer[bar_index] = signal + signalAddition;
|
||||
//
|
||||
// double pDiff = powerUpBuffer[bar_index] - powerDownBuffer[bar_index];
|
||||
// double cDiValue = pDiff + signalBuffer[bar_index];
|
||||
// diBuffer[bar_index] = cDiValue;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -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 ...
|
||||
//
|
||||
@@ -0,0 +1,425 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XBand Indicator
|
||||
// ---------------------------------------------
|
||||
// saherelm implementation of xBand 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 XBND Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#include "../Libraries/x-saherelm.lib.mq4"
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq4"
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int marketLength = 5; // Averaging Length
|
||||
input int ignoreLastCross = 4; // Ignore Last Cross
|
||||
input int shift = 0; // Averaging Shift
|
||||
input ENUM_MA_METHOD method = MODE_SMA; // Averaging Mode
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 4
|
||||
|
||||
//
|
||||
// Declare Buffers ...
|
||||
//
|
||||
// High ...
|
||||
#property indicator_width1 1
|
||||
#property indicator_color1 clrAqua
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_style1 STYLE_DASHDOT
|
||||
|
||||
//
|
||||
// Open ...
|
||||
#property indicator_width2 1
|
||||
#property indicator_color2 clrGreen
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_style2 STYLE_DASH
|
||||
|
||||
//
|
||||
// Close ...
|
||||
#property indicator_width3 1
|
||||
#property indicator_color3 clrRed
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_style3 STYLE_DASH
|
||||
|
||||
//
|
||||
// Low ...
|
||||
#property indicator_width4 1
|
||||
#property indicator_color4 clrFuchsia
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_style4 STYLE_DASHDOT
|
||||
|
||||
//
|
||||
#define highBufferIndex 0
|
||||
#define openBufferIndex 1
|
||||
#define closeBufferIndex 2
|
||||
#define lowBufferIndex 3
|
||||
|
||||
//
|
||||
double highBuffer[];
|
||||
double openBuffer[];
|
||||
double closeBuffer[];
|
||||
double lowBuffer[];
|
||||
|
||||
//
|
||||
datetime lastCrossTime;
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
|
||||
//
|
||||
// Validating Input Parameters ...
|
||||
if (
|
||||
marketLength < 2
|
||||
|| ignoreLastCross < 0
|
||||
) {
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// here we specify logging enabled or not ...
|
||||
enableLogging = true;
|
||||
|
||||
//
|
||||
// this is a Tag which attached to our Logger ...
|
||||
logTag = "XBND";
|
||||
|
||||
//
|
||||
// High ...
|
||||
string highLabel = StringConcatenate(
|
||||
"High(", marketLength, ")"
|
||||
);
|
||||
SetIndexBuffer(highBufferIndex, highBuffer);
|
||||
SetIndexLabel(highBufferIndex, highLabel);
|
||||
|
||||
//
|
||||
// Open ...
|
||||
string openLabel = StringConcatenate(
|
||||
"Open(", marketLength, ")"
|
||||
);
|
||||
SetIndexBuffer(openBufferIndex, openBuffer);
|
||||
SetIndexLabel(openBufferIndex, openLabel);
|
||||
|
||||
//
|
||||
// Close ...
|
||||
string closeLabel = StringConcatenate(
|
||||
"Close(", marketLength, ")"
|
||||
);
|
||||
SetIndexBuffer(closeBufferIndex, closeBuffer);
|
||||
SetIndexLabel(closeBufferIndex, closeLabel);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
string lowLabel = StringConcatenate(
|
||||
"Low(", marketLength, ")"
|
||||
);
|
||||
SetIndexBuffer(lowBufferIndex, lowBuffer);
|
||||
SetIndexLabel(lowBufferIndex, lowLabel);
|
||||
|
||||
//
|
||||
// initialization done ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason) {
|
||||
RemoveDraws(logTag);
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculation ...
|
||||
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 Buffers ...
|
||||
CalculateBuffers(i);
|
||||
|
||||
//
|
||||
// Calculate Market Changes ...
|
||||
CalculateInfo(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
void CalculateBuffers(
|
||||
const int bar_index
|
||||
) {
|
||||
//
|
||||
// High ...
|
||||
double high = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
marketLength,
|
||||
shift,
|
||||
method,
|
||||
PRICE_HIGH,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
highBuffer[bar_index] = high;
|
||||
|
||||
//
|
||||
// Open ...
|
||||
double open = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
marketLength,
|
||||
shift,
|
||||
method,
|
||||
PRICE_OPEN,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
openBuffer[bar_index] = open;
|
||||
|
||||
//
|
||||
// Close ...
|
||||
double close = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
marketLength,
|
||||
shift,
|
||||
method,
|
||||
PRICE_CLOSE,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
closeBuffer[bar_index] = close;
|
||||
|
||||
//
|
||||
// Low ...
|
||||
double low = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
marketLength,
|
||||
shift,
|
||||
method,
|
||||
PRICE_LOW,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
lowBuffer[bar_index] = low;
|
||||
}
|
||||
|
||||
//
|
||||
void CalculateInfo(
|
||||
const int bar_index
|
||||
) {
|
||||
//
|
||||
XOHCL pCandle = GetCandleModel(bar_index);
|
||||
|
||||
//
|
||||
bool isTrendingUp =
|
||||
pCandle.low > highBuffer[bar_index]
|
||||
&& pCandle.high > highBuffer[bar_index];
|
||||
|
||||
//
|
||||
bool isTrendingDown =
|
||||
pCandle.high < lowBuffer[bar_index]
|
||||
&& pCandle.low < lowBuffer[bar_index];
|
||||
|
||||
//
|
||||
bool isOpenCrossOverClose =
|
||||
true
|
||||
// &&
|
||||
// (
|
||||
// pCandle.high > highBuffer[bar_index + 1]
|
||||
// || pCandle.low < lowBuffer[bar_index + 1]
|
||||
// )
|
||||
&& openBuffer[bar_index + 1] > closeBuffer[bar_index + 1]
|
||||
&& !(openBuffer[bar_index + 2] >= closeBuffer[bar_index + 2])
|
||||
;
|
||||
|
||||
//
|
||||
bool isOpenCrossUnderClose =
|
||||
true
|
||||
// &&
|
||||
// (
|
||||
// pCandle.high > highBuffer[bar_index + 1]
|
||||
// || pCandle.low < lowBuffer[bar_index + 1]
|
||||
// )
|
||||
&& openBuffer[bar_index + 1] < closeBuffer[bar_index + 1]
|
||||
&& !(openBuffer[bar_index + 2] <= closeBuffer[bar_index + 2])
|
||||
;
|
||||
|
||||
//
|
||||
isTrendingUp = isOpenCrossUnderClose;
|
||||
isTrendingDown = isOpenCrossOverClose;
|
||||
|
||||
//
|
||||
datetime time = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
if (
|
||||
isTrendingUp
|
||||
|| isTrendingDown
|
||||
) {
|
||||
//
|
||||
if (lastCrossTime == 0) {
|
||||
lastCrossTime = time;
|
||||
} else {
|
||||
//
|
||||
int lastCrossBarIndex = iBarShift(
|
||||
_Symbol,
|
||||
_Period,
|
||||
lastCrossTime
|
||||
);
|
||||
|
||||
//
|
||||
int diff = lastCrossBarIndex - bar_index;
|
||||
if (diff <= ignoreLastCross) {
|
||||
return;
|
||||
} else {
|
||||
lastCrossTime = time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
string lbl = StringConcatenate(
|
||||
logTag,
|
||||
"_Arrow_",
|
||||
isTrendingUp ? "UP" : "Down",
|
||||
"_", time
|
||||
);
|
||||
|
||||
//
|
||||
color clr = isTrendingUp ?
|
||||
clrAqua :
|
||||
clrFuchsia;
|
||||
|
||||
//
|
||||
ENUM_ARROW_ANCHOR anchor = isTrendingUp ?
|
||||
ANCHOR_BOTTOM :
|
||||
ANCHOR_TOP;
|
||||
|
||||
//
|
||||
uchar arrowCode = isTrendingUp ?
|
||||
SYMBOL_ARROWUP :
|
||||
SYMBOL_ARROWDOWN;
|
||||
|
||||
//
|
||||
double price = isTrendingUp ?
|
||||
pCandle.low - 20 * _Point :
|
||||
pCandle.high + 20 * _Point;
|
||||
|
||||
//
|
||||
if (isTrendingUp) {
|
||||
//
|
||||
// this means Market Going Up ...
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
if (isTrendingDown) {
|
||||
//
|
||||
// this means Market Going Downm ...
|
||||
}
|
||||
|
||||
//
|
||||
if (
|
||||
isTrendingUp
|
||||
|| isTrendingDown
|
||||
) {
|
||||
//
|
||||
bool isDrawn = DrawArrow(
|
||||
0,
|
||||
lbl,
|
||||
0,
|
||||
time,
|
||||
price,
|
||||
arrowCode,
|
||||
anchor,
|
||||
clr
|
||||
);
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,410 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 ...
|
||||
//
|
||||
@@ -0,0 +1,337 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XMA Indicator
|
||||
// ---------------------------------------------
|
||||
// saherelm implementation of above oscillator ...
|
||||
//
|
||||
// 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 XMA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
// Set the R2R Length ...
|
||||
input int swingLoopback = 7; // Swing Loopback
|
||||
input int xmaFlowMultiplier = 3; // XMA Flow Multiplier
|
||||
input int xmaMarkMultiplier = 5; // XMA Mark Multiplier
|
||||
input int xmaFastMultiplier = 7; // XMA Fast Multiplier
|
||||
input int xmaSlowMultiplier = 14; // XMA Slow Multiplier
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
// define indicator buffers ...
|
||||
#property indicator_buffers 6
|
||||
#property indicator_plots 6
|
||||
|
||||
//
|
||||
// XMA High ...
|
||||
#property indicator_label1 "XMA High"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrLime
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// XMA Low ...
|
||||
#property indicator_label2 "XMA Low"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrOrange
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// XMA Mark ...
|
||||
#property indicator_label3 "XMA Mark"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrCornflowerBlue
|
||||
#property indicator_style3 STYLE_DASH
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// XMA Mid ...
|
||||
#property indicator_label4 "XMA Mid"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrBisque
|
||||
#property indicator_style4 STYLE_DASHDOT
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// XMA Fast ...
|
||||
#property indicator_label5 "XMA Fast"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrGreen
|
||||
#property indicator_style5 STYLE_DOT
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
// XMA Slow ...
|
||||
#property indicator_label6 "XMA Slow"
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_color6 clrRed
|
||||
#property indicator_style6 STYLE_DOT
|
||||
#property indicator_width6 1
|
||||
|
||||
//
|
||||
// Declare Buffers ...
|
||||
#define xmaHighBufferIndex 0
|
||||
#define xmaLowBufferIndex 1
|
||||
#define xmaMarkBufferIndex 2
|
||||
#define xmaMidBufferIndex 3
|
||||
#define xmaFastBufferIndex 4
|
||||
#define xmaSlowBufferIndex 5
|
||||
|
||||
//
|
||||
double xmaHighBuffer[];
|
||||
double xmaLowBuffer[];
|
||||
double xmaMarkBuffer[];
|
||||
double xmaMidBuffer[];
|
||||
double xmaFastBuffer[];
|
||||
double xmaSlowBuffer[];
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
|
||||
|
||||
//
|
||||
// Validating Input Parameters ...
|
||||
if (swingLoopback <= 0) {
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// XMA High ...
|
||||
SetIndexBuffer(xmaHighBufferIndex, xmaHighBuffer);
|
||||
SetIndexDrawBegin(xmaHighBufferIndex, swingLoopback * xmaFlowMultiplier);
|
||||
|
||||
//
|
||||
// XMA Low ...
|
||||
SetIndexBuffer(xmaLowBufferIndex, xmaLowBuffer);
|
||||
SetIndexDrawBegin(xmaLowBufferIndex, swingLoopback * xmaFlowMultiplier);
|
||||
|
||||
//
|
||||
// XMA Mark ...
|
||||
SetIndexBuffer(xmaMarkBufferIndex, xmaMarkBuffer);
|
||||
SetIndexDrawBegin(xmaMarkBufferIndex, swingLoopback * xmaMarkMultiplier);
|
||||
|
||||
//
|
||||
// XMA Mid ...
|
||||
SetIndexBuffer(xmaMidBufferIndex, xmaMidBuffer);
|
||||
SetIndexDrawBegin(xmaMidBufferIndex, swingLoopback);
|
||||
|
||||
//
|
||||
// XMA Fast ...
|
||||
SetIndexBuffer(xmaFastBufferIndex, xmaFastBuffer);
|
||||
SetIndexDrawBegin(xmaFastBufferIndex, swingLoopback * xmaFastMultiplier);
|
||||
|
||||
//
|
||||
// XMA Slow ...
|
||||
SetIndexBuffer(xmaSlowBufferIndex, xmaSlowBuffer);
|
||||
SetIndexDrawBegin(xmaSlowBufferIndex, swingLoopback * xmaSlowMultiplier);
|
||||
|
||||
//
|
||||
// initialization done ...
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculation ...
|
||||
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, swingLoopback);
|
||||
|
||||
//
|
||||
// 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 XMA Flow ...
|
||||
CalculateXMAFlow(i);
|
||||
|
||||
//
|
||||
// Calculate XMA Mark ...
|
||||
CalculateXMAMark(i);
|
||||
|
||||
//
|
||||
// Calculate XMA Mid ...
|
||||
CalculateXMAMid(i);
|
||||
|
||||
//
|
||||
// Calculate XMA Fast/Slow ...
|
||||
CalculateXMAFastSlow(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Calculate XMA Flow ...
|
||||
void CalculateXMAFlow(const int &bar_index) {
|
||||
//
|
||||
int xmaFlowLength = swingLoopback * xmaFlowMultiplier;
|
||||
|
||||
//
|
||||
// Calculating XMa High ...
|
||||
double xmaHigh = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
xmaFlowLength,
|
||||
0,
|
||||
MODE_SMA,
|
||||
PRICE_HIGH,
|
||||
bar_index
|
||||
);
|
||||
xmaHighBuffer[bar_index] = xmaHigh;
|
||||
|
||||
//
|
||||
// Calculating XMa Low ...
|
||||
double xmaLow = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
xmaFlowLength,
|
||||
0,
|
||||
MODE_SMA,
|
||||
PRICE_LOW,
|
||||
bar_index
|
||||
);
|
||||
xmaLowBuffer[bar_index] = xmaLow;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate XMA Mark ...
|
||||
void CalculateXMAMark(const int &bar_index) {
|
||||
//
|
||||
int xmaMarkLength = swingLoopback * xmaMarkMultiplier;
|
||||
|
||||
//
|
||||
// Calculating XMa Mark ...
|
||||
double xmaMark = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
xmaMarkLength,
|
||||
0,
|
||||
MODE_SMA,
|
||||
PRICE_HIGH,
|
||||
bar_index
|
||||
);
|
||||
xmaMarkBuffer[bar_index] = xmaMark;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate XMA Mid ...
|
||||
void CalculateXMAMid(const int &bar_index) {
|
||||
//
|
||||
// Calculating XMa Mid ...
|
||||
double xmaMid = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
swingLoopback,
|
||||
0,
|
||||
MODE_EMA,
|
||||
PRICE_HIGH,
|
||||
bar_index
|
||||
);
|
||||
xmaMidBuffer[bar_index] = xmaMid;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate XMA Fast/Slow ...
|
||||
void CalculateXMAFastSlow(const int &bar_index) {
|
||||
//
|
||||
int xmaFastLength = swingLoopback * xmaFastMultiplier;
|
||||
int xmaSlowLength = swingLoopback * xmaSlowMultiplier;
|
||||
|
||||
//
|
||||
// Calculating XMa Fast ...
|
||||
double xmaFast = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
xmaFastLength,
|
||||
0,
|
||||
MODE_SMA,
|
||||
PRICE_CLOSE,
|
||||
bar_index
|
||||
);
|
||||
xmaFastBuffer[bar_index] = xmaFast;
|
||||
|
||||
//
|
||||
// Calculating XMa Slow ...
|
||||
double xmaSlow = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
xmaSlowLength,
|
||||
0,
|
||||
MODE_SMA,
|
||||
PRICE_CLOSE,
|
||||
bar_index
|
||||
);
|
||||
xmaSlowBuffer[bar_index] = xmaSlow;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,695 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XMA Indicator
|
||||
// ---------------------------------------------
|
||||
// saherelm implementation of above oscillator ...
|
||||
//
|
||||
// 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 XMA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
// Market Specifications ...
|
||||
input int marketLength = 7; // Market Length
|
||||
input double step = 0.02; // SAR Step
|
||||
input double maximum = 0.2; // SAR Maximum
|
||||
//
|
||||
// Cycle Definitions ...
|
||||
input int shortCycleFastMultiplier = 1; // Short Cycle Fast Multiplier
|
||||
input int shortCycleSlowMultiplier = 4; // Short Cycle Slow Multiplier
|
||||
input int mediumCycleFastMultiplier = 7; // Medium Cycle Fast Multiplier
|
||||
input int mediumCycleSlowMultiplier = 14; // Medium Cycle Slow Multiplier
|
||||
input int longCycleFastMultiplier = 70; // Long Cycle Fast Multiplier
|
||||
input int longCycleSlowMultiplier = 140; // Long Cycle Slow Multiplier
|
||||
//
|
||||
// Show Inputs ...
|
||||
input bool showPSar = true; // Show Parabolic Sar
|
||||
input bool showMarketMiddle = true; // Show Market Middle
|
||||
input bool showShortCycle = true; // Show Short Cycle
|
||||
input bool showShortCycleCrossLines = true; // Show Short Cycle Vertical Lines
|
||||
input bool showMediumCycle = true; // Show Medium Cycle
|
||||
input bool showMediumCycleCrossLines = true; // Show Medium Cycle Vertical Lines
|
||||
input bool showLongCycle = true; // Show Long Cycle
|
||||
input bool showLongCycleCrossLines = true; // Show Long Cycle Vertical Lines
|
||||
//
|
||||
// Color Inputs ...
|
||||
input color pSarColor = clrCornflowerBlue; // Parabolic Sar Color
|
||||
input color shortCycleFastColor = clrGreen; // Short Cycle Fast Color
|
||||
input color shortCycleSlowColor = clrRed; // Short Cycle Slow Color
|
||||
input color mediumCycleFastColor = clrAqua; // Medium Cycle Fast Color
|
||||
input color mediumCycleSlowColor = clrFuchsia; // Medium Cycle Slow Color
|
||||
input color longCycleFastColor = clrGoldenrod; // Medium Cycle Fast Color
|
||||
input color longCycleSlowColor = clrBrown; // Medium Cycle Slow Color
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
// define indicator buffers ...
|
||||
#property indicator_buffers 8
|
||||
#property indicator_plots 8
|
||||
|
||||
//
|
||||
// Declare Buffers ...
|
||||
#define scFastBufferIndex 0
|
||||
#define scSlowBufferIndex 1
|
||||
#define mcFastBufferIndex 2
|
||||
#define mcSlowBufferIndex 3
|
||||
#define lcFastBufferIndex 4
|
||||
#define lcSlowBufferIndex 5
|
||||
#define midBufferIndex 6
|
||||
#define pSarBufferIndex 7
|
||||
|
||||
//
|
||||
double scFastBuffer[];
|
||||
double scSlowBuffer[];
|
||||
double mcFastBuffer[];
|
||||
double mcSlowBuffer[];
|
||||
double lcFastBuffer[];
|
||||
double lcSlowBuffer[];
|
||||
double midBuffer[];
|
||||
double pSarBuffer[];
|
||||
|
||||
//
|
||||
int shortCycleFastLength;
|
||||
int shortCycleSlowLength;
|
||||
int mediumCycleFastLength;
|
||||
int mediumCycleSlowLength;
|
||||
int longCycleFastLength;
|
||||
int longCycleSlowLength;
|
||||
|
||||
//
|
||||
// Includes our shared library ...
|
||||
#include "../Libraries/x-saherelm.lib.mq4"
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
|
||||
//
|
||||
// Validating Input Parameters ...
|
||||
if (
|
||||
//
|
||||
// Validate Market Length ...
|
||||
marketLength <= 0
|
||||
//
|
||||
// Validate Short Cycle ...
|
||||
|| shortCycleFastMultiplier <= 0
|
||||
|| shortCycleSlowMultiplier <= 0
|
||||
|| shortCycleFastMultiplier >= shortCycleSlowMultiplier
|
||||
//
|
||||
// Validate Medium Cycle ...
|
||||
|| mediumCycleFastMultiplier <= 0
|
||||
|| mediumCycleSlowMultiplier <= 0
|
||||
|| mediumCycleFastMultiplier >= mediumCycleSlowMultiplier
|
||||
//
|
||||
// Validate Long Cycle ...
|
||||
|| longCycleFastMultiplier <= 0
|
||||
|| longCycleSlowMultiplier <= 0
|
||||
|| longCycleFastMultiplier >= longCycleSlowMultiplier
|
||||
//
|
||||
// Validate Series of Multipliers ...
|
||||
|| shortCycleFastMultiplier >= mediumCycleFastMultiplier
|
||||
|| mediumCycleFastMultiplier >= longCycleFastMultiplier
|
||||
) {
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// here we specify logging enabled or not ...
|
||||
enableLogging = true;
|
||||
|
||||
//
|
||||
// this is a Tag which attached to our Logger ...
|
||||
logTag = "XST_XMA";
|
||||
|
||||
//
|
||||
// Calculate Cycle Length based on given Multipliers ...
|
||||
shortCycleFastLength = marketLength * shortCycleFastMultiplier;
|
||||
shortCycleSlowLength = marketLength * shortCycleSlowMultiplier;
|
||||
mediumCycleFastLength = marketLength * mediumCycleFastMultiplier;
|
||||
mediumCycleSlowLength = marketLength * mediumCycleSlowMultiplier;
|
||||
longCycleFastLength = marketLength * longCycleFastMultiplier;
|
||||
longCycleSlowLength = marketLength * longCycleSlowMultiplier;
|
||||
|
||||
//
|
||||
// Short Cycle Fast ...
|
||||
SetIndexLabel(scFastBufferIndex, "SCFast");
|
||||
SetIndexBuffer(scFastBufferIndex, scFastBuffer);
|
||||
SetIndexDrawBegin(scFastBufferIndex, shortCycleFastLength);
|
||||
SetIndexStyle(
|
||||
scFastBufferIndex,
|
||||
DRAW_LINE,
|
||||
STYLE_DOT,
|
||||
1,
|
||||
showShortCycle ?
|
||||
shortCycleFastColor :
|
||||
clrNONE
|
||||
);
|
||||
|
||||
//
|
||||
// Short Cycle Slow ...
|
||||
SetIndexLabel(scSlowBufferIndex, "SCSLow");
|
||||
SetIndexBuffer(scSlowBufferIndex, scSlowBuffer);
|
||||
SetIndexDrawBegin(scSlowBufferIndex, shortCycleSlowLength);
|
||||
SetIndexStyle(
|
||||
scSlowBufferIndex,
|
||||
DRAW_LINE,
|
||||
STYLE_DOT,
|
||||
1,
|
||||
showShortCycle ?
|
||||
shortCycleSlowColor :
|
||||
clrNONE
|
||||
);
|
||||
|
||||
//
|
||||
// Medium Cycle Fast ...
|
||||
SetIndexLabel(mcFastBufferIndex, "MCFast");
|
||||
SetIndexBuffer(mcFastBufferIndex, mcFastBuffer);
|
||||
SetIndexDrawBegin(mcFastBufferIndex, mediumCycleFastLength);
|
||||
SetIndexStyle(
|
||||
mcFastBufferIndex,
|
||||
DRAW_LINE,
|
||||
STYLE_DOT,
|
||||
1,
|
||||
showMediumCycle ?
|
||||
mediumCycleFastColor :
|
||||
clrNONE
|
||||
);
|
||||
|
||||
//
|
||||
// Medium Cycle Slow ...
|
||||
SetIndexLabel(mcSlowBufferIndex, "MCSlow");
|
||||
SetIndexBuffer(mcSlowBufferIndex, mcSlowBuffer);
|
||||
SetIndexDrawBegin(mcSlowBufferIndex, mediumCycleSlowLength);
|
||||
SetIndexStyle(
|
||||
mcSlowBufferIndex,
|
||||
DRAW_LINE,
|
||||
STYLE_DOT,
|
||||
1,
|
||||
showMediumCycle ?
|
||||
mediumCycleSlowColor :
|
||||
clrNONE
|
||||
);
|
||||
|
||||
//
|
||||
// Long Cycle Fast ...
|
||||
SetIndexLabel(lcFastBufferIndex, "LCFast");
|
||||
SetIndexBuffer(lcFastBufferIndex, lcFastBuffer);
|
||||
SetIndexDrawBegin(lcFastBufferIndex, longCycleFastLength);
|
||||
SetIndexStyle(
|
||||
lcFastBufferIndex,
|
||||
DRAW_LINE,
|
||||
STYLE_DOT,
|
||||
1,
|
||||
showLongCycle ?
|
||||
longCycleFastColor :
|
||||
clrNONE
|
||||
);
|
||||
|
||||
//
|
||||
// Long Cycle Slow ...
|
||||
SetIndexLabel(lcSlowBufferIndex, "LCSlow");
|
||||
SetIndexBuffer(lcSlowBufferIndex, lcSlowBuffer);
|
||||
SetIndexDrawBegin(lcSlowBufferIndex, longCycleSlowLength);
|
||||
SetIndexStyle(
|
||||
lcSlowBufferIndex,
|
||||
DRAW_LINE,
|
||||
STYLE_DOT,
|
||||
1,
|
||||
showLongCycle ?
|
||||
longCycleSlowColor :
|
||||
clrNONE
|
||||
);
|
||||
|
||||
//
|
||||
// Market Middleage ...
|
||||
SetIndexBuffer(midBufferIndex, midBuffer);
|
||||
SetIndexDrawBegin(midBufferIndex, marketLength);
|
||||
SetIndexLabel(midBufferIndex, "Market Mid");
|
||||
|
||||
//
|
||||
// Parabolic Sar ...
|
||||
SetIndexBuffer(pSarBufferIndex, pSarBuffer);
|
||||
SetIndexLabel(pSarBufferIndex, "P Sar");
|
||||
SetIndexStyle(
|
||||
pSarBufferIndex,
|
||||
DRAW_LINE,
|
||||
STYLE_DOT,
|
||||
1,
|
||||
showPSar ?
|
||||
pSarColor :
|
||||
clrNONE
|
||||
);
|
||||
|
||||
//
|
||||
// Market Middle ...
|
||||
SetIndexBuffer(midBufferIndex, midBuffer);
|
||||
SetIndexLabel(midBufferIndex, "Mid");
|
||||
SetIndexStyle(
|
||||
midBufferIndex,
|
||||
DRAW_LINE,
|
||||
STYLE_DOT,
|
||||
1,
|
||||
showMarketMiddle ?
|
||||
clrAntiqueWhite :
|
||||
clrNONE
|
||||
);
|
||||
|
||||
//
|
||||
// initialization done ...
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason) {
|
||||
//
|
||||
RemoveDraws(logTag);
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculation ...
|
||||
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(marketLength, longCycleSlowLength);
|
||||
|
||||
//
|
||||
// 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 Short Cycle ...
|
||||
CalculateShortCycle(i);
|
||||
|
||||
//
|
||||
// Calculate Medium Cycle ...
|
||||
CalculateMediumCycle(i);
|
||||
|
||||
//
|
||||
// Calculate Long Cycle ...
|
||||
CalculateLongCycle(i);
|
||||
|
||||
//
|
||||
// Calculate Market Middleage ...
|
||||
CalculateMarketMiddleage(i);
|
||||
|
||||
//
|
||||
// Calculate Cross Points ...
|
||||
CalculateCrossPoints(i);
|
||||
|
||||
//
|
||||
// Calculate Parabolic Sar ...
|
||||
CalculateParabolicSar(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Calculate Short Cycle ...
|
||||
void CalculateShortCycle(
|
||||
const int bar_index
|
||||
) {
|
||||
//
|
||||
// Fast ...
|
||||
double shortCycleFast = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
shortCycleFastLength,
|
||||
0,
|
||||
MODE_SMA,
|
||||
PRICE_WEIGHTED,
|
||||
bar_index
|
||||
);
|
||||
scFastBuffer[bar_index] = shortCycleFast;
|
||||
|
||||
//
|
||||
// Slow ...
|
||||
double shortCycleSlow = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
shortCycleSlowLength,
|
||||
0,
|
||||
MODE_SMA,
|
||||
PRICE_WEIGHTED,
|
||||
bar_index
|
||||
);
|
||||
scSlowBuffer[bar_index] = shortCycleSlow;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Medium Cycle ...
|
||||
void CalculateMediumCycle(
|
||||
const int bar_index
|
||||
) {
|
||||
//
|
||||
// Fast ...
|
||||
double mediumCycleFast = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mediumCycleFastLength,
|
||||
0,
|
||||
MODE_SMA,
|
||||
PRICE_MEDIAN,
|
||||
bar_index
|
||||
);
|
||||
mcFastBuffer[bar_index] = mediumCycleFast;
|
||||
|
||||
//
|
||||
// Slow ...
|
||||
double mediumCycleSlow = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mediumCycleSlowLength,
|
||||
0,
|
||||
MODE_SMA,
|
||||
PRICE_MEDIAN,
|
||||
bar_index
|
||||
);
|
||||
mcSlowBuffer[bar_index] = mediumCycleSlow;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Long Cycle ...
|
||||
void CalculateLongCycle(
|
||||
const int bar_index
|
||||
) {
|
||||
//
|
||||
// Fast ...
|
||||
double longCycleFast = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
longCycleFastLength,
|
||||
0,
|
||||
MODE_SMA,
|
||||
PRICE_CLOSE,
|
||||
bar_index
|
||||
);
|
||||
lcFastBuffer[bar_index] = longCycleFast;
|
||||
|
||||
//
|
||||
// Slow ...
|
||||
double longCycleSlow = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
longCycleSlowLength,
|
||||
0,
|
||||
MODE_SMA,
|
||||
PRICE_CLOSE,
|
||||
bar_index
|
||||
);
|
||||
lcSlowBuffer[bar_index] = longCycleSlow;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Market Middleage ...
|
||||
void CalculateMarketMiddleage(
|
||||
const int bar_index
|
||||
) {
|
||||
//
|
||||
// Mid ...
|
||||
double marketMiddleage = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
(int)(marketLength * 1.5),
|
||||
0,
|
||||
MODE_EMA,
|
||||
PRICE_MEDIAN,
|
||||
bar_index
|
||||
);
|
||||
midBuffer[bar_index] = marketMiddleage;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Cross Points and Draw Section Line on theme ...
|
||||
void CalculateCrossPoints(
|
||||
const int bar_index
|
||||
) {
|
||||
//
|
||||
// START Draw Cross Lines ...
|
||||
//
|
||||
//
|
||||
// Short Cycle ...
|
||||
bool isSCFastCrossOverSlow = scFastBuffer[bar_index] > scSlowBuffer[bar_index]
|
||||
&& !(scFastBuffer[bar_index + 1] > scSlowBuffer[bar_index + 1]);
|
||||
|
||||
//
|
||||
bool isSCFastCrossUnderSlow = scFastBuffer[bar_index] < scSlowBuffer[bar_index]
|
||||
&& !(scFastBuffer[bar_index + 1] < scSlowBuffer[bar_index + 1]);
|
||||
|
||||
//
|
||||
// Medium Cycle ...
|
||||
bool isMCFastCrossOverSlow = mcFastBuffer[bar_index] > mcSlowBuffer[bar_index]
|
||||
&& !(mcFastBuffer[bar_index + 1] > mcSlowBuffer[bar_index + 1]);
|
||||
|
||||
//
|
||||
bool isMCFastCrossUnderSlow = mcFastBuffer[bar_index] < mcSlowBuffer[bar_index]
|
||||
&& !(mcFastBuffer[bar_index + 1] < mcSlowBuffer[bar_index + 1]);
|
||||
|
||||
//
|
||||
// Long Cycle ...
|
||||
bool isLCFastCrossOverSlow = lcFastBuffer[bar_index] > lcSlowBuffer[bar_index]
|
||||
&& !(lcFastBuffer[bar_index + 1] > lcSlowBuffer[bar_index + 1]);
|
||||
|
||||
//
|
||||
bool isLCFastCrossUnderSlow = lcFastBuffer[bar_index] < lcSlowBuffer[bar_index]
|
||||
&& !(lcFastBuffer[bar_index + 1] < lcSlowBuffer[bar_index + 1]);
|
||||
|
||||
//
|
||||
// START Drawing CrossPoints ...
|
||||
//
|
||||
//
|
||||
datetime currentTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
if (showShortCycleCrossLines) {
|
||||
//
|
||||
// Draw Line ...
|
||||
if (isSCFastCrossOverSlow) {
|
||||
//
|
||||
string lbl = StringConcatenate(
|
||||
logTag,
|
||||
"_SC_F_OV_S_",
|
||||
currentTime
|
||||
);
|
||||
|
||||
//
|
||||
DrawVerticalLine(
|
||||
0,
|
||||
lbl,
|
||||
0,
|
||||
currentTime,
|
||||
showShortCycleCrossLines ?
|
||||
shortCycleFastColor :
|
||||
clrNONE
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Line ...
|
||||
if (isSCFastCrossUnderSlow) {
|
||||
//
|
||||
string lbl = StringConcatenate(
|
||||
logTag,
|
||||
"_SC_F_UN_S_",
|
||||
currentTime
|
||||
);
|
||||
|
||||
//
|
||||
DrawVerticalLine(
|
||||
0,
|
||||
lbl,
|
||||
0,
|
||||
currentTime,
|
||||
showShortCycleCrossLines ?
|
||||
shortCycleSlowColor :
|
||||
clrNONE
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (showMediumCycleCrossLines) {
|
||||
//
|
||||
// Draw Line ...
|
||||
if (isMCFastCrossOverSlow) {
|
||||
//
|
||||
string lbl = StringConcatenate(
|
||||
logTag,
|
||||
"_MC_F_OV_S_",
|
||||
currentTime
|
||||
);
|
||||
|
||||
//
|
||||
DrawVerticalLine(
|
||||
0,
|
||||
lbl,
|
||||
0,
|
||||
currentTime,
|
||||
showMediumCycleCrossLines ?
|
||||
mediumCycleFastColor :
|
||||
clrNONE
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Line ...
|
||||
if (isMCFastCrossUnderSlow) {
|
||||
//
|
||||
string lbl = StringConcatenate(
|
||||
logTag,
|
||||
"_MC_F_UN_S_",
|
||||
currentTime
|
||||
);
|
||||
|
||||
//
|
||||
DrawVerticalLine(
|
||||
0,
|
||||
lbl,
|
||||
0,
|
||||
currentTime,
|
||||
showMediumCycleCrossLines ?
|
||||
mediumCycleSlowColor :
|
||||
clrNONE
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (showLongCycleCrossLines) {
|
||||
//
|
||||
// Draw Line ...
|
||||
if (isLCFastCrossOverSlow) {
|
||||
//
|
||||
string lbl = StringConcatenate(
|
||||
logTag,
|
||||
"_LC_F_OV_S_",
|
||||
currentTime
|
||||
);
|
||||
|
||||
//
|
||||
DrawVerticalLine(
|
||||
0,
|
||||
lbl,
|
||||
0,
|
||||
currentTime,
|
||||
showLongCycleCrossLines ?
|
||||
longCycleFastColor :
|
||||
clrNONE
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Line ...
|
||||
if (isLCFastCrossUnderSlow) {
|
||||
//
|
||||
string lbl = StringConcatenate(
|
||||
logTag,
|
||||
"_LC_F_UN_S_",
|
||||
currentTime
|
||||
);
|
||||
|
||||
//
|
||||
DrawVerticalLine(
|
||||
0,
|
||||
lbl,
|
||||
0,
|
||||
currentTime,
|
||||
showLongCycleCrossLines ?
|
||||
longCycleSlowColor :
|
||||
clrNONE
|
||||
);
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Drawing CrossPoints ...
|
||||
//
|
||||
}
|
||||
|
||||
void CalculateParabolicSar(
|
||||
const int bar_index
|
||||
) {
|
||||
//
|
||||
double sarValue = iSAR(
|
||||
NULL,
|
||||
_Period,
|
||||
step,
|
||||
maximum,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
pSarBuffer[bar_index] = sarValue;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,394 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XMKT Indicator
|
||||
// ---------------------------------------------
|
||||
// retrieve market base info ...
|
||||
//
|
||||
// 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 XMKT Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
// Market Specifications ...
|
||||
input int marketLength = 7; // Market Length
|
||||
//
|
||||
input bool showHighestHigh = true; // Show Market Highest High
|
||||
input bool showHighestLow = true; // Show Market Highest Low
|
||||
input bool showHighestOpen = true; // Show Market Highest Open
|
||||
input bool showHighestClose = true; // Show Market Highest Close
|
||||
input bool showLowestHigh = true; // Show Market Lowest High
|
||||
input bool showLowestLow = true; // Show Market Lowest Low
|
||||
input bool showLowestOpen = true; // Show Market Lowest Open
|
||||
input bool showLowestClose = true; // Show Market Lowest Close
|
||||
//
|
||||
input color highestHighColor = clrDeepPink; // Market Highest High Color
|
||||
input color highestLowColor = clrDarkOrange; // Market Highest Low Color
|
||||
input color highestOpenColor = clrDodgerBlue; // Market Highest Open Color
|
||||
input color highestCloseColor = clrOrchid; // Market Highest Close Color
|
||||
input color lowestHighColor = clrHotPink; // Market Lowest High Color
|
||||
input color lowestLowColor = clrOrange; // Market Lowest Low Color
|
||||
input color lowestOpenColor = clrPowderBlue; // Market Lowest Open Color
|
||||
input color lowestCloseColor = clrMediumOrchid; // Market Lowest Close Color
|
||||
//
|
||||
input ENUM_LINE_STYLE highestHighStyle = STYLE_DOT; // Market Highest High Line Style
|
||||
input ENUM_LINE_STYLE highestLowStyle = STYLE_DOT; // Market Highest Low Line Style
|
||||
input ENUM_LINE_STYLE highestOpenStyle = STYLE_DOT; // Market Highest Open Line Style
|
||||
input ENUM_LINE_STYLE highestCloseStyle = STYLE_DOT; // Market Highest Close Line Style
|
||||
input ENUM_LINE_STYLE lowestHighStyle = STYLE_DOT; // Market Lowest High Line Style
|
||||
input ENUM_LINE_STYLE lowestLowStyle = STYLE_DOT; // Market Lowest Low Line Style
|
||||
input ENUM_LINE_STYLE lowestOpenStyle = STYLE_DOT; // Market Lowest Open Line Style
|
||||
input ENUM_LINE_STYLE lowestCloseStyle = STYLE_DOT; // Market Lowest Close Line Style
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
// define indicator buffers ...
|
||||
#property indicator_buffers 8
|
||||
#property indicator_plots 8
|
||||
|
||||
//
|
||||
// Declare Buffers ...
|
||||
#define marketHighestHighBufferIndex 0
|
||||
#define marketHighestLowBufferIndex 1
|
||||
#define marketHighestOpenBufferIndex 2
|
||||
#define marketHighestCloseBufferIndex 3
|
||||
#define marketLowestHighBufferIndex 4
|
||||
#define marketLowestLowBufferIndex 5
|
||||
#define marketLowestOpenBufferIndex 6
|
||||
#define marketLowestCloseBufferIndex 7
|
||||
|
||||
//
|
||||
double marketHighestHighBuffer[];
|
||||
double marketHighestLowBuffer[];
|
||||
double marketHighestOpenBuffer[];
|
||||
double marketHighestCloseBuffer[];
|
||||
double marketLowestHighBuffer[];
|
||||
double marketLowestLowBuffer[];
|
||||
double marketLowestOpenBuffer[];
|
||||
double marketLowestCloseBuffer[];
|
||||
|
||||
//
|
||||
// Includes our shared library ...
|
||||
#include "../Libraries/x-saherelm.lib.mq4"
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
|
||||
//
|
||||
// Validating Input Parameters ...
|
||||
if (marketLength <= 0) {
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// here we specify logging enabled or not ...
|
||||
enableLogging = true;
|
||||
|
||||
//
|
||||
// this is a Tag which attached to our Logger ...
|
||||
logTag = "XST_XMKT";
|
||||
|
||||
//
|
||||
// Highest High ...
|
||||
string highestHighLbl = StringConcatenate("HH(", marketLength,")");
|
||||
SetIndexLabel(marketHighestHighBufferIndex, highestHighLbl);
|
||||
SetIndexBuffer(marketHighestHighBufferIndex, marketHighestHighBuffer);
|
||||
SetIndexStyle(
|
||||
marketHighestHighBufferIndex,
|
||||
showHighestHigh ?
|
||||
DRAW_LINE :
|
||||
DRAW_NONE,
|
||||
highestHighStyle,
|
||||
1,
|
||||
showHighestHigh ?
|
||||
highestHighColor :
|
||||
clrNONE
|
||||
);
|
||||
|
||||
//
|
||||
// Highest Low ...
|
||||
string highestLowLbl = StringConcatenate("HL(", marketLength,")");
|
||||
SetIndexLabel(marketHighestLowBufferIndex, highestLowLbl);
|
||||
SetIndexBuffer(marketHighestLowBufferIndex, marketHighestLowBuffer);
|
||||
SetIndexStyle(
|
||||
marketHighestLowBufferIndex,
|
||||
showHighestLow ?
|
||||
DRAW_LINE :
|
||||
DRAW_NONE,
|
||||
highestLowStyle,
|
||||
1,
|
||||
showHighestLow ?
|
||||
highestLowColor :
|
||||
clrNONE
|
||||
);
|
||||
|
||||
//
|
||||
// Highest Open ...
|
||||
string highestOpenLbl = StringConcatenate("HO(", marketLength,")");
|
||||
SetIndexLabel(marketHighestOpenBufferIndex, highestOpenLbl);
|
||||
SetIndexBuffer(marketHighestOpenBufferIndex, marketHighestOpenBuffer);
|
||||
SetIndexStyle(
|
||||
marketHighestOpenBufferIndex,
|
||||
showHighestOpen ?
|
||||
DRAW_LINE :
|
||||
DRAW_NONE,
|
||||
highestOpenStyle,
|
||||
1,
|
||||
showHighestOpen ?
|
||||
highestOpenColor :
|
||||
clrNONE
|
||||
);
|
||||
|
||||
//
|
||||
// Highest Close ...
|
||||
string highestCloseLbl = StringConcatenate("HC(", marketLength,")");
|
||||
SetIndexLabel(marketHighestCloseBufferIndex, highestCloseLbl);
|
||||
SetIndexBuffer(marketHighestCloseBufferIndex, marketHighestCloseBuffer);
|
||||
SetIndexStyle(
|
||||
marketHighestCloseBufferIndex,
|
||||
showHighestClose ?
|
||||
DRAW_LINE :
|
||||
DRAW_NONE,
|
||||
highestCloseStyle,
|
||||
1,
|
||||
showHighestClose ?
|
||||
highestCloseColor :
|
||||
clrNONE
|
||||
);
|
||||
|
||||
//
|
||||
// Lowest High ...
|
||||
string lowestHighLbl = StringConcatenate("LH(", marketLength,")");
|
||||
SetIndexLabel(marketLowestHighBufferIndex, lowestHighLbl);
|
||||
SetIndexBuffer(marketLowestHighBufferIndex, marketLowestHighBuffer);
|
||||
SetIndexStyle(
|
||||
marketLowestHighBufferIndex,
|
||||
showLowestHigh ?
|
||||
DRAW_LINE :
|
||||
DRAW_NONE,
|
||||
lowestHighStyle,
|
||||
1,
|
||||
showLowestHigh ?
|
||||
lowestHighColor :
|
||||
clrNONE
|
||||
);
|
||||
|
||||
//
|
||||
// Lowest Low ...
|
||||
string lowestLowLbl = StringConcatenate("LL(", marketLength,")");
|
||||
SetIndexLabel(marketLowestLowBufferIndex, lowestLowLbl);
|
||||
SetIndexBuffer(marketLowestLowBufferIndex, marketLowestLowBuffer);
|
||||
SetIndexStyle(
|
||||
marketLowestLowBufferIndex,
|
||||
showLowestLow ?
|
||||
DRAW_LINE :
|
||||
DRAW_NONE,
|
||||
lowestLowStyle,
|
||||
1,
|
||||
showLowestLow ?
|
||||
lowestLowColor :
|
||||
clrNONE
|
||||
);
|
||||
|
||||
//
|
||||
// Lowest Open ...
|
||||
string lowestOpenLbl = StringConcatenate("LO(", marketLength,")");
|
||||
SetIndexLabel(marketLowestOpenBufferIndex, lowestOpenLbl);
|
||||
SetIndexBuffer(marketLowestOpenBufferIndex, marketLowestOpenBuffer);
|
||||
SetIndexStyle(
|
||||
marketLowestOpenBufferIndex,
|
||||
showLowestOpen ?
|
||||
DRAW_LINE :
|
||||
DRAW_NONE,
|
||||
lowestOpenStyle,
|
||||
1,
|
||||
showLowestOpen ?
|
||||
lowestOpenColor :
|
||||
clrNONE
|
||||
);
|
||||
|
||||
//
|
||||
// Lowest Close ...
|
||||
string lowestCloseLbl = StringConcatenate("LC(", marketLength,")");
|
||||
SetIndexLabel(marketLowestCloseBufferIndex, lowestCloseLbl);
|
||||
SetIndexBuffer(marketLowestCloseBufferIndex, marketLowestCloseBuffer);
|
||||
SetIndexStyle(
|
||||
marketLowestCloseBufferIndex,
|
||||
showLowestClose ?
|
||||
DRAW_LINE :
|
||||
DRAW_NONE,
|
||||
lowestCloseStyle,
|
||||
1,
|
||||
showLowestClose ?
|
||||
lowestCloseColor :
|
||||
clrNONE
|
||||
);
|
||||
|
||||
//
|
||||
// initialization done ...
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason) {
|
||||
//
|
||||
RemoveDraws(logTag);
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculation ...
|
||||
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(marketLength, 3);
|
||||
|
||||
//
|
||||
// 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 Short Cycle ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Calculate Short Cycle ...
|
||||
void CalculateBuffers(
|
||||
const int bar_index
|
||||
) {
|
||||
//
|
||||
// Highest High ...
|
||||
double highestHighValue = GetMarketHighestHigh(
|
||||
bar_index,
|
||||
marketLength
|
||||
);
|
||||
marketHighestHighBuffer[bar_index] = highestHighValue;
|
||||
|
||||
//
|
||||
// Highest Low ...
|
||||
double highestLowValue = GetMarketHighestLow(
|
||||
bar_index,
|
||||
marketLength
|
||||
);
|
||||
marketHighestLowBuffer[bar_index] = highestLowValue;
|
||||
|
||||
//
|
||||
// Highest Open ...
|
||||
double highestOpenValue = GetMarketHighestOpen(
|
||||
bar_index,
|
||||
marketLength
|
||||
);
|
||||
marketHighestOpenBuffer[bar_index] = highestOpenValue;
|
||||
|
||||
//
|
||||
// Highest Close ...
|
||||
double highestCloseValue = GetMarketHighestClose(
|
||||
bar_index,
|
||||
marketLength
|
||||
);
|
||||
marketHighestCloseBuffer[bar_index] = highestCloseValue;
|
||||
|
||||
//
|
||||
// Lowest High ...
|
||||
double lowestHighValue = GetMarketLowestHigh(
|
||||
bar_index,
|
||||
marketLength
|
||||
);
|
||||
marketLowestHighBuffer[bar_index] = lowestHighValue;
|
||||
|
||||
//
|
||||
// Lowest Low ...
|
||||
double lowestLowValue = GetMarketLowestLow(
|
||||
bar_index,
|
||||
marketLength
|
||||
);
|
||||
marketLowestLowBuffer[bar_index] = lowestLowValue;
|
||||
|
||||
//
|
||||
// Lowest Open ...
|
||||
double lowestOpenValue = GetMarketLowestOpen(
|
||||
bar_index,
|
||||
marketLength
|
||||
);
|
||||
marketLowestOpenBuffer[bar_index] = lowestOpenValue;
|
||||
|
||||
//
|
||||
// Lowest Close ...
|
||||
double lowestCloseValue = GetMarketLowestClose(
|
||||
bar_index,
|
||||
marketLength
|
||||
);
|
||||
marketLowestCloseBuffer[bar_index] = lowestCloseValue;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,408 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XMMA Indicator
|
||||
// ---------------------------------------------
|
||||
// this is an indicator which going to analyse
|
||||
// Market based on Price Movements and provide
|
||||
// some informations to act based on current market
|
||||
// state ...
|
||||
//
|
||||
// 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 Market Analyser (XMMA) Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int marketLength = 7; // Market Length
|
||||
input int fastShift = 1; // Fast Shift
|
||||
input int slowShift = 3; // Slow Shift
|
||||
input int longMarketFastMultiplier = 100; // Long Market Fast Multiplier
|
||||
input int longMarketSlowMultiplier = 200; // Long Market Slow Multiplier
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
// define indicator buffers ...
|
||||
#property indicator_buffers 7
|
||||
#property indicator_plots 7
|
||||
|
||||
//
|
||||
// Fast ...
|
||||
#property indicator_label1 "Fast"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrGreen
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// Slow ...
|
||||
#property indicator_label2 "SLow"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
#property indicator_label3 "Mid"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrBisque
|
||||
#property indicator_style3 STYLE_DASH
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Long SL ...
|
||||
#property indicator_label4 "Long SL"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrAqua
|
||||
#property indicator_style4 STYLE_DASH
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// Short SL ...
|
||||
#property indicator_label5 "Short SL"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrFuchsia
|
||||
#property indicator_style5 STYLE_DASH
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
// Long Market Fast ...
|
||||
#property indicator_label6 "Long Fast"
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_color6 clrAqua
|
||||
#property indicator_style6 STYLE_DOT
|
||||
#property indicator_width6 1
|
||||
//
|
||||
// Long Market Slow ...
|
||||
#property indicator_label7 "Long Market Slow"
|
||||
#property indicator_type7 DRAW_LINE
|
||||
#property indicator_color7 clrFuchsia
|
||||
#property indicator_style7 STYLE_DOT
|
||||
#property indicator_width7 1
|
||||
|
||||
//
|
||||
// Declare Buffers ...
|
||||
#define fastBufferIndex 0
|
||||
#define slowBufferIndex 1
|
||||
#define midBufferIndex 2
|
||||
#define longSLBufferIndex 3
|
||||
#define shortSLBufferIndex 4
|
||||
#define longMarketFastBufferIndex 5
|
||||
#define longMarketSlowBufferIndex 6
|
||||
|
||||
//
|
||||
double fastBuffer[];
|
||||
double slowBuffer[];
|
||||
double midBuffer[];
|
||||
double longSLBuffer[];
|
||||
double shortSLBuffer[];
|
||||
double longMarketFastBuffer[];
|
||||
double longMarketSlowBuffer[];
|
||||
|
||||
//
|
||||
int lastCrossOverIndex = 0;
|
||||
double lastCrossOver = 0.0;
|
||||
|
||||
//
|
||||
int lastCrossUnderIndex = 0;
|
||||
double lastCrossUnder = 0.0;
|
||||
|
||||
//
|
||||
double lastLongSL = 0.0;
|
||||
int lastLongSLIndex = 0;
|
||||
|
||||
//
|
||||
double lastShortSL = 0.0;
|
||||
int lastShortSLIndex = 0;
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
|
||||
//
|
||||
// Validating Input Parameters ...
|
||||
if (
|
||||
fastShift < 0 ||
|
||||
slowShift < 0 ||
|
||||
marketLength <= 0 ||
|
||||
slowShift < fastShift
|
||||
) {
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Fast ...
|
||||
SetIndexBuffer(fastBufferIndex, fastBuffer);
|
||||
|
||||
//
|
||||
// Slow ...
|
||||
SetIndexBuffer(slowBufferIndex, slowBuffer);
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
SetIndexBuffer(midBufferIndex, midBuffer);
|
||||
|
||||
//
|
||||
// Long SL ...
|
||||
SetIndexBuffer(longSLBufferIndex, longSLBuffer);
|
||||
|
||||
//
|
||||
// Short SL ...
|
||||
SetIndexBuffer(shortSLBufferIndex, shortSLBuffer);
|
||||
|
||||
//
|
||||
// Long Market Fast ...
|
||||
SetIndexBuffer(longMarketFastBufferIndex, longMarketFastBuffer);
|
||||
|
||||
//
|
||||
// Long Market Slow ...
|
||||
SetIndexBuffer(longMarketSlowBufferIndex, longMarketSlowBuffer);
|
||||
|
||||
//
|
||||
// initialization done ...
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculation ...
|
||||
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 Flow ...
|
||||
CalculateFlow(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Calculate Flow ...
|
||||
void CalculateFlow(
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
int fastLength = marketLength + fastShift;
|
||||
int slowLength = marketLength + fastShift + slowShift;
|
||||
|
||||
//
|
||||
// Calculating Fast ...
|
||||
double fast = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
fastLength,
|
||||
0,
|
||||
MODE_EMA,
|
||||
PRICE_WEIGHTED,
|
||||
bar_index
|
||||
);
|
||||
fastBuffer[bar_index] = fast;
|
||||
|
||||
//
|
||||
// Calculating Slow ...
|
||||
double slow = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slowLength,
|
||||
0,
|
||||
MODE_EMA,
|
||||
PRICE_WEIGHTED,
|
||||
bar_index
|
||||
);
|
||||
slowBuffer[bar_index] = slow;
|
||||
|
||||
//
|
||||
// Calculating XMa Mid ...
|
||||
double xmaMid = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
marketLength,
|
||||
0,
|
||||
MODE_EMA,
|
||||
PRICE_HIGH,
|
||||
bar_index
|
||||
);
|
||||
midBuffer[bar_index] = xmaMid;
|
||||
|
||||
//
|
||||
// Calculating XMa Long Market Fast ...
|
||||
double xmaLongMarketFast = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
marketLength * longMarketFastMultiplier,
|
||||
0,
|
||||
MODE_SMA,
|
||||
PRICE_CLOSE,
|
||||
bar_index
|
||||
);
|
||||
longMarketFastBuffer[bar_index] = xmaLongMarketFast;
|
||||
|
||||
//
|
||||
// Calculating XMa Long Market Slow ...
|
||||
double xmaLongMarketSlow = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
marketLength * longMarketSlowMultiplier,
|
||||
0,
|
||||
MODE_SMA,
|
||||
PRICE_CLOSE,
|
||||
bar_index
|
||||
);
|
||||
longMarketSlowBuffer[bar_index] = xmaLongMarketSlow;
|
||||
|
||||
//
|
||||
// Find Cross Points ...
|
||||
//
|
||||
bool isCrossOver = fastBuffer[bar_index] > slowBuffer[bar_index]
|
||||
&& !(
|
||||
fastBuffer[bar_index + 1] > slowBuffer[bar_index + 1]
|
||||
);
|
||||
|
||||
//
|
||||
bool isCrossUnder = fastBuffer[bar_index] < slowBuffer[bar_index]
|
||||
&& !(
|
||||
fastBuffer[bar_index + 1] < slowBuffer[bar_index + 1]
|
||||
);
|
||||
|
||||
//
|
||||
// Find Trending ...
|
||||
//
|
||||
bool isTrendUp = fastBuffer[bar_index] > slowBuffer[bar_index]
|
||||
&& fastBuffer[bar_index] > fastBuffer[bar_index + 1]
|
||||
&& slowBuffer[bar_index] > slowBuffer[bar_index + 1];
|
||||
|
||||
//
|
||||
bool isTrendDown = fastBuffer[bar_index] < slowBuffer[bar_index]
|
||||
&& fastBuffer[bar_index] < fastBuffer[bar_index + 1]
|
||||
&& slowBuffer[bar_index] < slowBuffer[bar_index + 1];
|
||||
|
||||
//
|
||||
// Do Some Calculations ...
|
||||
if (isCrossOver) {
|
||||
//
|
||||
lastCrossOverIndex = bar_index;
|
||||
lastCrossOver = fastBuffer[bar_index];
|
||||
} else if (isCrossUnder) {
|
||||
//
|
||||
lastCrossUnderIndex = bar_index;
|
||||
lastCrossUnder = fastBuffer[bar_index];
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate SLs ...
|
||||
//
|
||||
// Long SL ...
|
||||
if (lastCrossOver > 0) {
|
||||
//
|
||||
lastLongSLIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_LOW,
|
||||
marketLength,
|
||||
lastCrossOverIndex
|
||||
);
|
||||
|
||||
//
|
||||
lastLongSL = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
lastLongSLIndex
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Short SL ...
|
||||
if (lastCrossUnder > 0) {
|
||||
//
|
||||
lastShortSLIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_HIGH,
|
||||
marketLength,
|
||||
lastCrossUnderIndex
|
||||
);
|
||||
|
||||
//
|
||||
lastShortSL = iHigh(
|
||||
_Symbol,
|
||||
_Period,
|
||||
lastShortSLIndex
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
longSLBuffer[bar_index] = lastLongSL;
|
||||
shortSLBuffer[bar_index] = lastShortSL;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,249 @@
|
||||
/////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XMMA Signalling Indicator
|
||||
// -------------------------------------------------------------
|
||||
// this indicator provides signals for XMMA Based Strategy ...
|
||||
//
|
||||
// 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 XMMA Signalling Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
// Signal Show/Hide ...
|
||||
input bool showSignals = true; // Show Signals
|
||||
input bool showLongSignals = true; // Show Long Signals
|
||||
input bool showShortSignals = true; // Show Short Signals
|
||||
|
||||
//
|
||||
// Signal Prefixe ...
|
||||
input string signalPrefix = "XS_SG_OSC"; // Signal Prefix
|
||||
input double signalArrowPositionThresholdFactor = 100; // Signal Arrow Dist of Price
|
||||
|
||||
//
|
||||
// Signal Colors ...
|
||||
input string bullishSignalLabel = "X_BUY"; // Bullish Signal Label
|
||||
input color bullishSignalColor = clrAqua; // Bullish Signal Color
|
||||
|
||||
//
|
||||
input string bearishSignalLabel = "X_SELL"; // Bearish Signal Label
|
||||
input color bearishSignalColor = clrFuchsia; // Bearish Signal Color
|
||||
|
||||
//
|
||||
// here we specify alerting signals ...
|
||||
input bool alertSignals = false; // Alert Signals
|
||||
input bool pushNotificationSignals = false; // Push Notification Alert Signals
|
||||
|
||||
//
|
||||
// Indicator Inputs ...
|
||||
input int marketLength = 7; // Market Length
|
||||
input int fastShift = 1; // Fast Shift
|
||||
input int slowShift = 3; // Slow Shift
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
// Includes our shared library ...
|
||||
#include "../Libraries/x-saherelm.lib.mq4"
|
||||
|
||||
//
|
||||
// Includes our shared library ...
|
||||
#include "../Libraries/x-saherelm.xmma.signal.lib.mq4"
|
||||
|
||||
//
|
||||
// Last Signalled Bar ...
|
||||
int lastSignalledBar = 0;
|
||||
|
||||
//
|
||||
// here we specify logging enabled or not ...
|
||||
bool enableLogging = true;
|
||||
|
||||
//
|
||||
// this is a Tag which attached to our Logger ...
|
||||
string logTag = "XS_SG_OSC";
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
|
||||
//
|
||||
// Validating Input Parameters ...
|
||||
if (
|
||||
fastShift < 0 ||
|
||||
slowShift < 0 ||
|
||||
marketLength <= 0 ||
|
||||
slowShift < fastShift
|
||||
) {
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculation ...
|
||||
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 ...
|
||||
|
||||
//
|
||||
CalculateSignals(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// De Initialization ...
|
||||
void OnDeinit(const int reason) {
|
||||
//
|
||||
RemoveDraws(signalPrefix);
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Here we are Calculate Signals based on Oscillators and fill up
|
||||
// related buffers ...
|
||||
void CalculateSignals(const int &bar_index) {
|
||||
//
|
||||
// Retrieve Signal Exists ...
|
||||
XSignalRequest request = CalculateSignal(
|
||||
bar_index,
|
||||
marketLength,
|
||||
fastShift,
|
||||
slowShift
|
||||
);
|
||||
|
||||
//
|
||||
if (!request.hasSignal) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Prevent Multiple Alerting at same Candle ...
|
||||
if (lastSignalledBar == bar_index) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
lastSignalledBar = bar_index;
|
||||
|
||||
//
|
||||
bool hasLongSignal = request.type == X_LONG;
|
||||
bool hasShortSignal = request.type == X_SHORT;
|
||||
|
||||
//
|
||||
// Signal Tag ...
|
||||
string signalTAG = GenerateSignalTAG(
|
||||
request.signal,
|
||||
signalPrefix,
|
||||
bullishSignalLabel,
|
||||
bearishSignalLabel
|
||||
);
|
||||
|
||||
//
|
||||
// Handle Alerts ...
|
||||
if (alertSignals && bar_index == 0) {
|
||||
//
|
||||
// General Alert ...
|
||||
Alert(signalTAG);
|
||||
|
||||
//
|
||||
// Push Notifications ...
|
||||
if (pushNotificationSignals) {
|
||||
SendNotification(signalTAG);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Can Show Signals ...
|
||||
bool canShowSignals = showSignals &&
|
||||
(hasLongSignal ? showLongSignals : hasShortSignal ? showShortSignals : false);
|
||||
if (canShowSignals) {
|
||||
//
|
||||
// Here i must to Draw Signal Shapes ...
|
||||
DrawSignal(
|
||||
request.signal,
|
||||
0,
|
||||
0,
|
||||
signalArrowPositionThresholdFactor,
|
||||
signalPrefix, // Signal Tag ...
|
||||
bullishSignalLabel, // Long Signal Label ...
|
||||
bullishSignalColor,
|
||||
bearishSignalLabel, // Short Signal Label ...
|
||||
bearishSignalColor
|
||||
);
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,221 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XMTR Indicator
|
||||
// ---------------------------------------------
|
||||
// retrieve market base info ...
|
||||
//
|
||||
// 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 XMKT Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
// Market Specifications ...
|
||||
input int marketLength = 20; // Market Length
|
||||
input int atrMultiplier = 1; // ATR Multiplier
|
||||
input int atrLength = 5; // ATR Period
|
||||
input ENUM_APPLIED_PRICE source = PRICE_CLOSE; // Source
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
// define indicator buffers ...
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
// Declare Buffers ...
|
||||
#define trendBufferIndex 0
|
||||
#define upTrendBufferIndex 1
|
||||
#define downTrendBufferIndex 2
|
||||
|
||||
//
|
||||
double trendBuffer[];
|
||||
double upTrendBuffer[];
|
||||
double downTrendBuffer[];
|
||||
|
||||
//
|
||||
// Includes our shared library ...
|
||||
#include "../Libraries/x-saherelm.lib.mq4"
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
|
||||
//
|
||||
// Validating Input Parameters ...
|
||||
if (marketLength <= 0) {
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// here we specify logging enabled or not ...
|
||||
enableLogging = true;
|
||||
|
||||
//
|
||||
// this is a Tag which attached to our Logger ...
|
||||
logTag = "XMTR";
|
||||
|
||||
//
|
||||
// TREND ...
|
||||
SetIndexLabel(trendBufferIndex, "Trend");
|
||||
SetIndexBuffer(trendBufferIndex, trendBuffer);
|
||||
SetIndexStyle(
|
||||
trendBufferIndex,
|
||||
DRAW_LINE,
|
||||
STYLE_DOT,
|
||||
1,
|
||||
clrNONE
|
||||
);
|
||||
|
||||
//
|
||||
// UP Trend ...
|
||||
SetIndexLabel(upTrendBufferIndex, "Up Trend");
|
||||
SetIndexBuffer(upTrendBufferIndex, upTrendBuffer);
|
||||
SetIndexStyle(
|
||||
upTrendBufferIndex,
|
||||
DRAW_LINE,
|
||||
STYLE_DOT,
|
||||
1,
|
||||
clrNONE
|
||||
);
|
||||
|
||||
//
|
||||
// DOWN Trend ...
|
||||
SetIndexLabel(downTrendBufferIndex, "Down Trend");
|
||||
SetIndexBuffer(downTrendBufferIndex, downTrendBuffer);
|
||||
SetIndexStyle(
|
||||
downTrendBufferIndex,
|
||||
DRAW_LINE,
|
||||
STYLE_DOT,
|
||||
1,
|
||||
clrNONE
|
||||
);
|
||||
|
||||
//
|
||||
// initialization done ...
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason) {
|
||||
//
|
||||
RemoveDraws(logTag);
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculation ...
|
||||
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(marketLength, 3);
|
||||
|
||||
//
|
||||
// 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 Short Cycle ...
|
||||
CalculateBuffers(
|
||||
i,
|
||||
low
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Calculate Short Cycle ...
|
||||
void CalculateBuffers(
|
||||
const int bar_index,
|
||||
const double &low[]
|
||||
) {
|
||||
//
|
||||
double atr = GetMarketTRSMA(
|
||||
bar_index,
|
||||
atrLength
|
||||
);
|
||||
|
||||
//
|
||||
double smoothedAtr = (atr * atrMultiplier);
|
||||
double upTrend = low[bar_index] - smoothedAtr;
|
||||
double downTrend = low[bar_index] + smoothedAtr;
|
||||
|
||||
//
|
||||
double cciValue = GetMarketCCI(
|
||||
bar_index,
|
||||
marketLength,
|
||||
source
|
||||
);
|
||||
|
||||
//
|
||||
// TODO: Complete this ...
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,294 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XRange 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 XRange Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int marketLength = 14;
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
|
||||
//
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
// Start Define Indicator Buffer Styles ...
|
||||
//
|
||||
//
|
||||
// Highest High Buffer ...
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrGreen
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// Lowest Low Buffer ...
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Middle Buffer ...
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrYellow
|
||||
#property indicator_style3 STYLE_DASH
|
||||
#property indicator_width3 1
|
||||
//
|
||||
// End Define Indicator Buffer Styles ...
|
||||
//
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
//
|
||||
#define highestHighBufferIndex 0
|
||||
#define lowestLowBufferIndex 1
|
||||
#define middleBufferIndex 2
|
||||
|
||||
//
|
||||
double highestHighBuffer[];
|
||||
double lowestLowBuffer[];
|
||||
double middleBuffer[];
|
||||
|
||||
//
|
||||
datetime startTime;
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
if (
|
||||
marketLength <= 0
|
||||
) {
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
string hhLbl = StringConcatenate(
|
||||
"XR HH(", marketLength, ")"
|
||||
);
|
||||
SetIndexBuffer(highestHighBufferIndex, highestHighBuffer);
|
||||
SetIndexLabel(highestHighBufferIndex, hhLbl);
|
||||
|
||||
//
|
||||
string llLbl = StringConcatenate(
|
||||
"XR LL(", marketLength, ")"
|
||||
);
|
||||
SetIndexBuffer(lowestLowBufferIndex, lowestLowBuffer);
|
||||
SetIndexLabel(lowestLowBufferIndex, llLbl);
|
||||
|
||||
//
|
||||
string midLbl = StringConcatenate(
|
||||
"XR Mid(", marketLength, ")"
|
||||
);
|
||||
SetIndexBuffer(middleBufferIndex, middleBuffer);
|
||||
SetIndexLabel(middleBufferIndex, midLbl);
|
||||
|
||||
//
|
||||
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 ...
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Calculations ...
|
||||
void CalculateBuffers(
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
// Retrieve Bar Time ...
|
||||
datetime barTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
if (startTime == 0) {
|
||||
//
|
||||
startTime = barTime;
|
||||
SetIndicatorBuffersNone(bar_index);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
int startBarIndex = iBarShift(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startTime
|
||||
);
|
||||
|
||||
//
|
||||
int startDistance = startBarIndex - bar_index;
|
||||
if (startDistance < marketLength) {
|
||||
//
|
||||
SetIndicatorBuffersNone(bar_index);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Highest High ...
|
||||
int hhIdx = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_HIGH,
|
||||
marketLength,
|
||||
bar_index
|
||||
);
|
||||
double hh = iHigh(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhIdx
|
||||
);
|
||||
highestHighBuffer[bar_index] = hh;
|
||||
|
||||
//
|
||||
// Lowest Low ...
|
||||
int llIdx = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_LOW,
|
||||
marketLength,
|
||||
bar_index
|
||||
);
|
||||
double ll = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llIdx
|
||||
);
|
||||
lowestLowBuffer[bar_index] = ll;
|
||||
|
||||
//
|
||||
// Middle Buffer ...
|
||||
double mid = (hh + ll) / 2;
|
||||
middleBuffer[bar_index] = mid;
|
||||
|
||||
//
|
||||
// Reset Start Time ...
|
||||
startTime = 0;
|
||||
}
|
||||
|
||||
//
|
||||
void SetIndicatorBuffersNone(
|
||||
const int bar_index
|
||||
) {
|
||||
//
|
||||
int lastBarIndex = bar_index + 1;
|
||||
|
||||
//
|
||||
double lastHighestHigh;
|
||||
double lastLowestLow;
|
||||
|
||||
//
|
||||
// Highest High ...
|
||||
if (ArraySize(highestHighBuffer) > lastBarIndex) {
|
||||
lastHighestHigh = highestHighBuffer[lastBarIndex];
|
||||
} else {
|
||||
lastHighestHigh = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Lowest Low ...
|
||||
if (ArraySize(lowestLowBuffer) > lastBarIndex) {
|
||||
lastLowestLow = lowestLowBuffer[lastBarIndex];
|
||||
} else {
|
||||
lastLowestLow = 0;
|
||||
}
|
||||
|
||||
//
|
||||
highestHighBuffer[bar_index] = lastHighestHigh;
|
||||
lowestLowBuffer[bar_index] = lastLowestLow;
|
||||
|
||||
//
|
||||
double mid = (lastHighestHigh + lastLowestLow) / 2;
|
||||
middleBuffer[bar_index] = mid;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,275 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center Trend Power 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 MA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int marketLength = 7; // Market Length
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_plots 3
|
||||
#property indicator_buffers 3
|
||||
#property indicator_minimum 0
|
||||
#property indicator_maximum 100
|
||||
|
||||
//
|
||||
#property indicator_levelcolor clrGray
|
||||
#property indicator_levelstyle STYLE_DOT
|
||||
|
||||
//
|
||||
// Start Define Indicator Buffer Styles ...
|
||||
//
|
||||
#property indicator_type1 DRAW_HISTOGRAM
|
||||
#property indicator_color1 clrLime
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
#property indicator_type2 DRAW_HISTOGRAM
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrYellow
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
//
|
||||
// End Define Indicator Buffer Styles ...
|
||||
//
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
#define powerUpBufferIndex 0
|
||||
#define powerDownBufferIndex 1
|
||||
#define signalBufferIndex 2
|
||||
|
||||
double powerUpBuffer[];
|
||||
double powerDownBuffer[];
|
||||
double signalBuffer[];
|
||||
|
||||
//
|
||||
#include "../Libraries/x-saherelm.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;
|
||||
}
|
||||
|
||||
//
|
||||
SetLevelValue(0, 0.0);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT,0,"");
|
||||
|
||||
//
|
||||
SetLevelValue(1, 20.0);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT,1,"");
|
||||
|
||||
//
|
||||
SetLevelValue(2, 50);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT,2,"");
|
||||
|
||||
//
|
||||
SetLevelValue(3, 100);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT,3,"");
|
||||
|
||||
//
|
||||
string pUpLbl = StringConcatenate(
|
||||
"P Up (", marketLength, ")"
|
||||
);
|
||||
SetIndexLabel(powerUpBufferIndex, pUpLbl);
|
||||
SetIndexBuffer(powerUpBufferIndex, powerUpBuffer);
|
||||
SetIndexDrawBegin(powerUpBufferIndex, marketLength + 1);
|
||||
|
||||
//
|
||||
string pDownLbl = StringConcatenate(
|
||||
"P Down (", marketLength, ")"
|
||||
);
|
||||
SetIndexLabel(powerDownBufferIndex, pDownLbl);
|
||||
SetIndexBuffer(powerDownBufferIndex, powerDownBuffer);
|
||||
SetIndexDrawBegin(powerDownBufferIndex, marketLength + 1);
|
||||
|
||||
//
|
||||
string pSignalLbl = StringConcatenate(
|
||||
"P Signal (", marketLength, ")"
|
||||
);
|
||||
SetIndexLabel(signalBufferIndex, pSignalLbl);
|
||||
SetIndexBuffer(signalBufferIndex, signalBuffer);
|
||||
SetIndexDrawBegin(signalBufferIndex, marketLength + 1);
|
||||
|
||||
//
|
||||
// here we specify logging enabled or not ...
|
||||
enableLogging = true;
|
||||
|
||||
//
|
||||
// this is a Tag which attached to our Logger ...
|
||||
logTag = "X_TPW_OSC";
|
||||
|
||||
//
|
||||
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 ...
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Calculating Ma ...
|
||||
void CalculateBuffers(
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
double powerUp = 0;
|
||||
double powerDown = 0;
|
||||
|
||||
//
|
||||
int dailyCount = GetDailyCandleCount();
|
||||
double dailyHH = GetMarketHighestHigh(
|
||||
bar_index,
|
||||
dailyCount
|
||||
);
|
||||
double dailyLL = GetMarketLowestLow(
|
||||
bar_index,
|
||||
dailyCount
|
||||
);
|
||||
double dailyDiff = dailyHH - dailyLL;
|
||||
double rate = dailyDiff / 100;
|
||||
|
||||
//
|
||||
for (int i = bar_index; i < bar_index + marketLength; i++) {
|
||||
//
|
||||
XOHCL c = GetCandleModel(i);
|
||||
|
||||
//
|
||||
double cRange =
|
||||
MathAbs(c.open - c.close)
|
||||
// MathAbs(c.high - c.low)
|
||||
;
|
||||
bool isBullish = c.open < c.close;
|
||||
|
||||
//
|
||||
if (isBullish) {
|
||||
powerUp += cRange;
|
||||
} else {
|
||||
powerDown += cRange;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
powerUp = powerUp / rate;
|
||||
powerDown = powerDown / rate;
|
||||
|
||||
//
|
||||
int doubleMarketLength = (marketLength * 2);
|
||||
double ema = GetMA(
|
||||
bar_index,
|
||||
doubleMarketLength,
|
||||
0,
|
||||
MODE_EMA,
|
||||
PRICE_WEIGHTED
|
||||
);
|
||||
|
||||
//
|
||||
double emaRate = GetMarketHighestHigh(bar_index, doubleMarketLength) - GetMarketLowestLow(bar_index, doubleMarketLength) / 100;
|
||||
|
||||
//
|
||||
double signal = (ema / 100) * rate;
|
||||
double signalAddition = MathMin(powerUp, powerDown);
|
||||
|
||||
//
|
||||
powerUpBuffer[bar_index] = powerUp;
|
||||
powerDownBuffer[bar_index] = powerDown;
|
||||
signalBuffer[bar_index] = signal + signalAddition;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,476 @@
|
||||
/////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center ZigZag Indicator
|
||||
// -------------------------------------------------------------
|
||||
// this indicator provides signals for Main strategy ...
|
||||
//
|
||||
// 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 ZigZag Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int depth = 12; // Depth
|
||||
input int deviation = 5; // Deviation
|
||||
input int backStep = 3; // BackStep
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
// 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 = "XS_ZG";
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 1
|
||||
|
||||
//
|
||||
#property indicator_width1 1
|
||||
#property indicator_color1 clrAqua
|
||||
// #property indicator_type1 DRAW_SECTION
|
||||
// #property indicator_style1 STYLE_SOLID
|
||||
|
||||
// //
|
||||
// #property indicator_width2 1
|
||||
// #property indicator_color2 clrNONE
|
||||
// #property indicator_type2 DRAW_NONE
|
||||
// #property indicator_style2 STYLE_SOLID
|
||||
|
||||
// //
|
||||
// #property indicator_width3 1
|
||||
// #property indicator_color3 clrNONE
|
||||
// #property indicator_type3 DRAW_NONE
|
||||
// #property indicator_style3 STYLE_SOLID
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
//
|
||||
#define zigzagBufferIndex 0
|
||||
#define highBufferIndex 1
|
||||
#define lowBufferIndex 2
|
||||
// #define ziggyBufferIndex 3
|
||||
|
||||
//
|
||||
double zigzagBuffer[];
|
||||
double highBuffer[];
|
||||
double lowBuffer[];
|
||||
// double ziggyBuffer[];
|
||||
|
||||
//
|
||||
// recounting's depth of extremums ...
|
||||
int level=3;
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
|
||||
//
|
||||
// Validating Input Parameters ...
|
||||
if (
|
||||
depth <= 0 ||
|
||||
backStep < 0 ||
|
||||
deviation < 0 ||
|
||||
backStep >= depth
|
||||
) {
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Index Buffers of ZigZag ...
|
||||
IndicatorBuffers(3);
|
||||
|
||||
//
|
||||
// ZigZag Buffer ...
|
||||
SetIndexBuffer(zigzagBufferIndex, zigzagBuffer);
|
||||
SetIndexStyle(zigzagBufferIndex, DRAW_SECTION);
|
||||
SetIndexLabel(zigzagBufferIndex, "ZigZag");
|
||||
|
||||
//
|
||||
// High Buffer ...
|
||||
SetIndexBuffer(highBufferIndex, highBuffer);
|
||||
SetIndexLabel(highBufferIndex, "");
|
||||
|
||||
//
|
||||
// Low Buffer ...
|
||||
SetIndexBuffer(lowBufferIndex, lowBuffer);
|
||||
SetIndexLabel(lowBufferIndex, "");
|
||||
|
||||
//
|
||||
// Ziggy Buffer ...
|
||||
// SetIndexBuffer(ziggyBufferIndex, ziggyBuffer);
|
||||
// SetIndexLabel(ziggyBufferIndex, "");
|
||||
|
||||
//
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculation ...
|
||||
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;
|
||||
|
||||
//
|
||||
int maxLength = MathMax(depth, backStep);
|
||||
|
||||
int i;
|
||||
int counterZ;
|
||||
int back;
|
||||
int pos;
|
||||
|
||||
//
|
||||
int lastlowpos = 0;
|
||||
int lasthighpos = 0;
|
||||
int whatlookfor = 0;
|
||||
|
||||
//
|
||||
double extremum;
|
||||
|
||||
//
|
||||
double curlow = 0.0;
|
||||
double curhigh = 0.0;
|
||||
double lasthigh = 0.0;
|
||||
double lastlow = 0.0;
|
||||
|
||||
//
|
||||
// input variable, we return 0 means nothing passed ...
|
||||
if (rates_total < maxLength) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// first calculations ...
|
||||
if (prev_calculated == 0) {
|
||||
limit = InitializeBuffers();
|
||||
} else {
|
||||
//
|
||||
// find first extremum in the depth ExtLevel or 100 last bars ...
|
||||
i = counterZ = 0;
|
||||
while(counterZ < level && i < 100) {
|
||||
//
|
||||
if(zigzagBuffer[i] != 0.0) {
|
||||
counterZ++;
|
||||
}
|
||||
|
||||
//
|
||||
i++;
|
||||
}
|
||||
|
||||
//
|
||||
// no extremum found - recounting all from begin ...
|
||||
if(counterZ == 0) {
|
||||
limit = InitializeBuffers();
|
||||
} else {
|
||||
//
|
||||
// set start position to found extremum position ...
|
||||
limit = i-1;
|
||||
|
||||
//
|
||||
//--- what kind of extremum?
|
||||
if(lowBuffer[i] != 0.0) {
|
||||
//
|
||||
// low extremum ...
|
||||
curlow = lowBuffer[i];
|
||||
|
||||
//
|
||||
// will look for the next high extremum ...
|
||||
whatlookfor=1;
|
||||
} else {
|
||||
//
|
||||
// high extremum ...
|
||||
curhigh = highBuffer[i];
|
||||
|
||||
//
|
||||
// will look for the next low extremum ...
|
||||
whatlookfor=-1;
|
||||
}
|
||||
|
||||
//
|
||||
// clear the rest data ...
|
||||
for(i = limit - 1; i >= 0; i--) {
|
||||
//
|
||||
lowBuffer[i]=0.0;
|
||||
highBuffer[i]=0.0;
|
||||
zigzagBuffer[i]=0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Main Calculation Loop ...
|
||||
for (i = limit; i >= 0; i--) {
|
||||
//
|
||||
// find lowest low in depth of bars ...
|
||||
extremum = low[
|
||||
iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_LOW,
|
||||
depth,
|
||||
i
|
||||
)
|
||||
];
|
||||
|
||||
//
|
||||
// this lowest has been found previously ...
|
||||
if (extremum == lastlow) {
|
||||
extremum = 0.0;
|
||||
} else {
|
||||
//
|
||||
// new last low ...
|
||||
lastlow=extremum;
|
||||
|
||||
//
|
||||
// discard extremum if current low is too high ...
|
||||
if(low[i] - extremum > deviation * _Point) {
|
||||
extremum=0.0;
|
||||
} else {
|
||||
//
|
||||
// clear previous extremums in backstep bars ...
|
||||
for(back = 1; back <= backStep; back++) {
|
||||
//
|
||||
pos = i + back;
|
||||
|
||||
//
|
||||
if(lowBuffer[pos] != 0 && lowBuffer[pos] > extremum) {
|
||||
lowBuffer[pos] = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// found extremum is current low ...
|
||||
if (low[i] == extremum) {
|
||||
lowBuffer[i] = extremum;
|
||||
} else {
|
||||
lowBuffer[i] = 0.0;
|
||||
}
|
||||
|
||||
//
|
||||
// find highest high in depth of bars ...
|
||||
extremum = high[
|
||||
iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_HIGH,
|
||||
depth,
|
||||
i
|
||||
)
|
||||
];
|
||||
|
||||
//
|
||||
// this highest has been found previously ...
|
||||
if (extremum == lasthigh) {
|
||||
extremum = 0.0;
|
||||
} else {
|
||||
//
|
||||
// new last high ...
|
||||
lasthigh=extremum;
|
||||
|
||||
//
|
||||
// discard extremum if current high is too low ...
|
||||
if (extremum - high[i] > deviation * Point) {
|
||||
extremum = 0.0;
|
||||
} else {
|
||||
//
|
||||
// clear previous extremums in backstep bars ...
|
||||
for(back = 1; back <= backStep; back++) {
|
||||
//
|
||||
pos = i + back;
|
||||
|
||||
//
|
||||
if (highBuffer[pos] != 0 && highBuffer[pos] < extremum) {
|
||||
highBuffer[pos] = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// found extremum is current high ...
|
||||
if (high[i] == extremum) {
|
||||
highBuffer[i] = extremum;
|
||||
} else {
|
||||
highBuffer[i] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// final cutting ...
|
||||
if( whatlookfor == 0) {
|
||||
//
|
||||
lastlow = 0.0;
|
||||
lasthigh = 0.0;
|
||||
} else {
|
||||
//
|
||||
lastlow = curlow;
|
||||
lasthigh = curhigh;
|
||||
}
|
||||
|
||||
//
|
||||
for(i = limit; i >= 0; i--) {
|
||||
switch(whatlookfor) {
|
||||
//
|
||||
// look for peak or lawn ...
|
||||
case 0:
|
||||
//
|
||||
if (lastlow == 0.0 && lasthigh == 0.0) {
|
||||
if(highBuffer[i]!=0.0) {
|
||||
//
|
||||
lasthigh = High[i];
|
||||
lasthighpos = i;
|
||||
whatlookfor = -1;
|
||||
|
||||
//
|
||||
zigzagBuffer[i] = lasthigh;
|
||||
}
|
||||
|
||||
//
|
||||
if(lowBuffer[i] != 0.0) {
|
||||
//
|
||||
lastlow = Low[i];
|
||||
lastlowpos = i;
|
||||
whatlookfor = 1;
|
||||
|
||||
//
|
||||
zigzagBuffer[i] = lastlow;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
//
|
||||
// look for peak ...
|
||||
case 1:
|
||||
//
|
||||
if (
|
||||
lowBuffer[i] != 0.0 &&
|
||||
lowBuffer[i] < lastlow &&
|
||||
highBuffer[i] == 0.0
|
||||
) {
|
||||
//
|
||||
zigzagBuffer[lastlowpos] = 0.0;
|
||||
lastlowpos = i;
|
||||
lastlow = lowBuffer[i];
|
||||
zigzagBuffer[i] = lastlow;
|
||||
}
|
||||
|
||||
//
|
||||
if(highBuffer[i] != 0.0 && lowBuffer[i] == 0.0) {
|
||||
//
|
||||
lasthigh = highBuffer[i];
|
||||
lasthighpos = i;
|
||||
zigzagBuffer[i] = lasthigh;
|
||||
|
||||
//
|
||||
whatlookfor=-1;
|
||||
}
|
||||
break;
|
||||
|
||||
//
|
||||
// look for lawn ...
|
||||
case -1:
|
||||
//
|
||||
if(
|
||||
highBuffer[i] != 0.0 &&
|
||||
highBuffer[i] > lasthigh &&
|
||||
lowBuffer[i] == 0.0
|
||||
) {
|
||||
//
|
||||
zigzagBuffer[lasthighpos] = 0.0;
|
||||
lasthighpos = i;
|
||||
lasthigh = highBuffer[i];
|
||||
zigzagBuffer[i] = lasthigh;
|
||||
}
|
||||
|
||||
//
|
||||
if(
|
||||
lowBuffer[i] !=0.0 &&
|
||||
highBuffer[i] == 0.0
|
||||
) {
|
||||
//
|
||||
lastlow = lowBuffer[i];
|
||||
lastlowpos = i;
|
||||
zigzagBuffer[i] = lastlow;
|
||||
whatlookfor=1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Done ...
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// De Initialization ...
|
||||
void OnDeinit(const int reason) {
|
||||
//
|
||||
// RemoveDraws(signalPrefix);
|
||||
ChartRedraw(0);
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
int InitializeBuffers() {
|
||||
//
|
||||
ArrayInitialize(lowBuffer,0.0);
|
||||
ArrayInitialize(highBuffer, 0.0);
|
||||
ArrayInitialize(zigzagBuffer, 0.0);
|
||||
|
||||
//
|
||||
//--- first counting position
|
||||
return(Bars - depth);
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Reference in New Issue
Block a user