complete xrl indicator ...
This commit is contained in:
+214
-167
@@ -30,16 +30,16 @@
|
||||
//
|
||||
input group "Market";
|
||||
input group "Fast";
|
||||
input int fastLength = 9; // Length
|
||||
input ENUM_APPLIED_PRICE fastAppliedTo = PRICE_CLOSE; // Applied To
|
||||
input int slowLength = 18; // Length
|
||||
input ENUM_APPLIED_PRICE slowAppliedTo = PRICE_CLOSE; // Applied To
|
||||
input int fastLength = 9; // Length
|
||||
input ENUM_APPLIED_PRICE fastAppliedTo = PRICE_CLOSE; // Applied To
|
||||
input int slowLength = 18; // Length
|
||||
input ENUM_APPLIED_PRICE slowAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showFast = true; // Show Fast
|
||||
input bool showSlow = true; // Show Slow
|
||||
input bool showVerifier = true; // Show Verifier
|
||||
input bool showFast = true; // Show Fast
|
||||
input bool showSlow = true; // Show Slow
|
||||
input bool showVerifier = true; // Show Verifier
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
@@ -52,16 +52,16 @@ input bool showVerifier = true; // Show Verifier
|
||||
#property indicator_plots 6
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define hideColorIDX 0
|
||||
#define neuturalColorIDX 1
|
||||
#define bullColorIDX 2
|
||||
#define bearColorIDX 3
|
||||
#define bullColorIDX 2
|
||||
#define bearColorIDX 3
|
||||
|
||||
//
|
||||
// Fast ...
|
||||
|
||||
//
|
||||
#define fastBufferIndex 0
|
||||
#define fastBufferIndex 0
|
||||
#define fastBufferPlotIndex 0
|
||||
double fastBuffer[];
|
||||
|
||||
@@ -80,7 +80,7 @@ double fastBufferColor[];
|
||||
// Slow ...
|
||||
|
||||
//
|
||||
#define slowBufferIndex 2
|
||||
#define slowBufferIndex 2
|
||||
#define slowBufferPlotIndex 1
|
||||
double slowBuffer[];
|
||||
|
||||
@@ -99,7 +99,7 @@ double slowBufferColor[];
|
||||
// Verifier ...
|
||||
|
||||
//
|
||||
#define verifierBufferIndex 4
|
||||
#define verifierBufferIndex 4
|
||||
#define verifierBufferPlotIndex 2
|
||||
double verifierBuffer[];
|
||||
|
||||
@@ -137,12 +137,10 @@ XLinearRegression verifierCalculator;
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
int OnInit() {
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
if(!ValidateInputs()) {
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
@@ -168,8 +166,7 @@ int OnInit()
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
void OnDeinit(const int reason) {
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
@@ -186,150 +183,52 @@ void OnDeinit(const int reason)
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
) {
|
||||
//
|
||||
int limit = (prev_calculated > 0) ? prev_calculated - 1 : 0;
|
||||
|
||||
//
|
||||
// Calculate Verifier ...
|
||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
double verifierSlope;
|
||||
double verifierIntercept;
|
||||
|
||||
//
|
||||
double verifierAppliedPrice = iGetPrice(slowAppliedTo, open[i], high[i], low[i], close[i]);
|
||||
|
||||
//
|
||||
double verifier = verifierCalculator.Calculate(
|
||||
verifierAppliedPrice,
|
||||
slowLength,
|
||||
verifierSlope,
|
||||
verifierIntercept,
|
||||
i,
|
||||
rates_total //
|
||||
);
|
||||
verifierBuffer[i] = verifier;
|
||||
|
||||
//
|
||||
double verifierColor =
|
||||
(i > 0)
|
||||
? (verifierBuffer[i] > verifierBuffer[i - 1])
|
||||
? bullColorIDX
|
||||
: (verifierBuffer[i] < verifierBuffer[i - 1])
|
||||
? bearColorIDX
|
||||
: verifierBuffer[i - 1]
|
||||
: neuturalColorIDX;
|
||||
verifierBufferColor[i] = verifierColor;
|
||||
}
|
||||
|
||||
//
|
||||
// Fast ...
|
||||
|
||||
//
|
||||
// Calculate Fast Intercept and Slope ...
|
||||
double fastSlope = 0;
|
||||
double fastIntercept = 0;
|
||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
double fastAppliedPrice = iGetPrice(fastAppliedTo, open[i], high[i], low[i], close[i]);
|
||||
|
||||
//
|
||||
double fastLRValue = fastCalculator.Calculate(
|
||||
fastAppliedPrice,
|
||||
fastLength,
|
||||
fastSlope,
|
||||
fastIntercept,
|
||||
i,
|
||||
rates_total //
|
||||
);
|
||||
fastLRBuffer[i] = fastLRValue;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Fast ...
|
||||
for (int i = 0; i < fastLength && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
double fast = fastIntercept + fastSlope * (fastLength - i - 1);
|
||||
fastBuffer[rates_total - i - 1] = fast;
|
||||
|
||||
//
|
||||
double fastColor =
|
||||
(fastSlope > 0)
|
||||
? bullColorIDX
|
||||
: (fastSlope < 0)
|
||||
? bearColorIDX
|
||||
: neuturalColorIDX;
|
||||
|
||||
//
|
||||
fastBufferColor[rates_total - i - 1] = fastColor;
|
||||
}
|
||||
|
||||
//
|
||||
int fastDrawBegin = rates_total - fastLength;
|
||||
PlotIndexSetInteger(fastBufferIndex, PLOT_DRAW_BEGIN, fastDrawBegin);
|
||||
|
||||
//
|
||||
// Slow ...
|
||||
|
||||
//
|
||||
// Calculate Slow Intercept and Slope ...
|
||||
double slowSlope = 0;
|
||||
double slowIntercept = 0;
|
||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
double slowAppliedPrice = iGetPrice(slowAppliedTo, open[i], high[i], low[i], close[i]);
|
||||
|
||||
//
|
||||
double slowLRValue = slowCalculator.Calculate(
|
||||
slowAppliedPrice,
|
||||
slowLength,
|
||||
slowSlope,
|
||||
slowIntercept,
|
||||
i,
|
||||
rates_total //
|
||||
);
|
||||
slowLRBuffer[i] = slowLRValue;
|
||||
}
|
||||
CalculateFast(
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
limit,
|
||||
rates_total //
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Slow ...
|
||||
for (int i = 0; i < slowLength && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
double slow = slowIntercept + slowSlope * (slowLength - i - 1);
|
||||
slowBuffer[rates_total - i - 1] = slow;
|
||||
|
||||
//
|
||||
double slowColor =
|
||||
(slowSlope > 0)
|
||||
? bullColorIDX
|
||||
: (slowSlope < 0)
|
||||
? bearColorIDX
|
||||
: neuturalColorIDX;
|
||||
|
||||
//
|
||||
slowBufferColor[rates_total - i - 1] = slowColor;
|
||||
}
|
||||
CalculateSlow(
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
limit,
|
||||
rates_total //
|
||||
);
|
||||
|
||||
//
|
||||
int slowDrawBegin = rates_total - slowLength;
|
||||
PlotIndexSetInteger(slowBufferIndex, PLOT_DRAW_BEGIN, slowDrawBegin);
|
||||
// Calculate Verifier ...
|
||||
CalculateVerifier(
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
limit,
|
||||
rates_total //
|
||||
);
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
@@ -340,8 +239,7 @@ int OnCalculate(
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
bool ValidateInputs() {
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
@@ -356,8 +254,7 @@ bool ValidateInputs()
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
int ExtractMaxLengthOfInputs() {
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
@@ -371,15 +268,13 @@ int ExtractMaxLengthOfInputs()
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
void SetIndicatorName() {
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
void DefineBuffers() {
|
||||
//
|
||||
// Fast ...
|
||||
|
||||
@@ -391,8 +286,9 @@ void DefineBuffers()
|
||||
SetIndexBuffer(fastBufferColorIndex, fastBufferColor, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(fastBufferIndex, PLOT_SHOW_DATA, showFast);
|
||||
PlotIndexSetInteger(fastBufferIndex, PLOT_DRAW_TYPE, fastDrawType);
|
||||
PlotIndexSetDouble(fastBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(fastBufferPlotIndex, PLOT_SHOW_DATA, showFast);
|
||||
PlotIndexSetInteger(fastBufferPlotIndex, PLOT_DRAW_TYPE, fastDrawType);
|
||||
|
||||
//
|
||||
// Slow ...
|
||||
@@ -405,8 +301,9 @@ void DefineBuffers()
|
||||
SetIndexBuffer(slowBufferColorIndex, slowBufferColor, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(slowBufferIndex, PLOT_SHOW_DATA, showSlow);
|
||||
PlotIndexSetInteger(slowBufferIndex, PLOT_DRAW_TYPE, slowDrawType);
|
||||
PlotIndexSetDouble(slowBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(slowBufferPlotIndex, PLOT_SHOW_DATA, showSlow);
|
||||
PlotIndexSetInteger(slowBufferPlotIndex, PLOT_DRAW_TYPE, slowDrawType);
|
||||
|
||||
//
|
||||
// Verifier ...
|
||||
@@ -419,8 +316,9 @@ void DefineBuffers()
|
||||
SetIndexBuffer(verifierBufferColorIndex, verifierBufferColor, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(verifierBufferIndex, PLOT_SHOW_DATA, showVerifier);
|
||||
PlotIndexSetInteger(verifierBufferIndex, PLOT_DRAW_TYPE, verifierDrawType);
|
||||
PlotIndexSetDouble(verifierBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(verifierBufferPlotIndex, PLOT_SHOW_DATA, showVerifier);
|
||||
PlotIndexSetInteger(verifierBufferPlotIndex, PLOT_DRAW_TYPE, verifierDrawType);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
@@ -430,4 +328,153 @@ void DefineBuffers()
|
||||
SetIndexBuffer(slowLRBufferIndex, slowLRBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
//
|
||||
void CalculateFast(
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
int limit,
|
||||
const int rates_total //
|
||||
) {
|
||||
//
|
||||
// Fast ...
|
||||
|
||||
//
|
||||
// Calculate Fast Intercept and Slope ...
|
||||
double fastSlope = 0;
|
||||
double fastIntercept = 0;
|
||||
for(int i = limit; i < rates_total && !IsStopped(); i++) {
|
||||
//
|
||||
double fastAppliedPrice = iGetPrice(fastAppliedTo, open[i], high[i], low[i], close[i]);
|
||||
|
||||
//
|
||||
double fastLRValue = fastCalculator.Calculate(
|
||||
fastAppliedPrice,
|
||||
fastLength,
|
||||
fastSlope,
|
||||
fastIntercept,
|
||||
i,
|
||||
rates_total //
|
||||
);
|
||||
fastLRBuffer[i] = fastLRValue;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Fast ...
|
||||
for(int i = 0; i < fastLength && !IsStopped(); i++) {
|
||||
//
|
||||
double fast = fastIntercept + fastSlope * (fastLength - i - 1);
|
||||
fastBuffer[rates_total - i - 1] = fast;
|
||||
|
||||
//
|
||||
double fastColor =
|
||||
(fastSlope > 0) ? bullColorIDX : (fastSlope < 0) ? bearColorIDX :
|
||||
neuturalColorIDX;
|
||||
|
||||
//
|
||||
fastBufferColor[rates_total - i - 1] = fastColor;
|
||||
}
|
||||
|
||||
//
|
||||
int fastDrawBegin = rates_total - fastLength;
|
||||
PlotIndexSetInteger(fastBufferPlotIndex, PLOT_DRAW_BEGIN, fastDrawBegin);
|
||||
}
|
||||
|
||||
//
|
||||
void CalculateSlow(
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
int limit,
|
||||
const int rates_total //
|
||||
) {
|
||||
//
|
||||
// Slow ...
|
||||
|
||||
//
|
||||
// Calculate Slow Intercept and Slope ...
|
||||
double slowSlope = 0;
|
||||
double slowIntercept = 0;
|
||||
for(int i = limit; i < rates_total && !IsStopped(); i++) {
|
||||
//
|
||||
double slowAppliedPrice = iGetPrice(slowAppliedTo, open[i], high[i], low[i], close[i]);
|
||||
|
||||
//
|
||||
double slowLRValue = slowCalculator.Calculate(
|
||||
slowAppliedPrice,
|
||||
slowLength,
|
||||
slowSlope,
|
||||
slowIntercept,
|
||||
i,
|
||||
rates_total //
|
||||
);
|
||||
slowLRBuffer[i] = slowLRValue;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Slow ...
|
||||
for(int i = 0; i < slowLength && !IsStopped(); i++) {
|
||||
//
|
||||
double slow = slowIntercept + slowSlope * (slowLength - i - 1);
|
||||
slowBuffer[rates_total - i - 1] = slow;
|
||||
|
||||
//
|
||||
double slowColor =
|
||||
(slowSlope > 0) ? bullColorIDX : (slowSlope < 0) ? bearColorIDX :
|
||||
neuturalColorIDX;
|
||||
|
||||
//
|
||||
slowBufferColor[rates_total - i - 1] = slowColor;
|
||||
}
|
||||
|
||||
//
|
||||
int slowDrawBegin = rates_total - slowLength;
|
||||
PlotIndexSetInteger(slowBufferPlotIndex, PLOT_DRAW_BEGIN, slowDrawBegin);
|
||||
}
|
||||
|
||||
//
|
||||
void CalculateVerifier(
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
int limit,
|
||||
const int rates_total //
|
||||
) {
|
||||
//
|
||||
// Calculate Verifier ...
|
||||
for(int i = limit; i < rates_total && !IsStopped(); i++) {
|
||||
//
|
||||
double verifierSlope;
|
||||
double verifierIntercept;
|
||||
|
||||
//
|
||||
double verifierAppliedPrice = iGetPrice(slowAppliedTo, open[i], high[i], low[i], close[i]);
|
||||
|
||||
//
|
||||
double verifier = verifierCalculator.Calculate(
|
||||
verifierAppliedPrice,
|
||||
slowLength,
|
||||
verifierSlope,
|
||||
verifierIntercept,
|
||||
i,
|
||||
rates_total //
|
||||
);
|
||||
verifierBuffer[i] = verifier;
|
||||
|
||||
//
|
||||
double verifierColor =
|
||||
(i > 0) ?
|
||||
(verifierBuffer[i] > verifierBuffer[i - 1]) ? bullColorIDX : (verifierBuffer[i] < verifierBuffer[i - 1]) ? bearColorIDX :
|
||||
verifierBuffer[i - 1] :
|
||||
neuturalColorIDX;
|
||||
verifierBufferColor[i] = verifierColor;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user