220 lines
4.6 KiB
Plaintext
220 lines
4.6 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// 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 ...
|
|
// |