fix xpv and add support for providing fractals based Supports and Resistances ...
This commit is contained in:
@@ -60,7 +60,7 @@ input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period
|
||||
input group "Boundary Detection";
|
||||
input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method
|
||||
input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method
|
||||
input ENUM_X_FIBO_LEVELS goldenZoneLevel = X_FIBO_LEVEL_382; // Golden Zone Detection
|
||||
input ENUM_X_FIBO_LEVELS goldenZoneLevel = X_FIBO_LEVEL_236; // Golden Zone Detection
|
||||
|
||||
//
|
||||
input group "Sar Detection";
|
||||
@@ -76,12 +76,16 @@ input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
input int sarArrowCode = 159; // Parabolic Sar Arrow Code
|
||||
input int peaksArrowCode = 159; // Peaks Arrow Code
|
||||
input int valesArrowCode = 159; // Vales Arrow Code
|
||||
input int supportsArrowCode = 159; // Supports Arrow Code
|
||||
input int resistancesArrowCode = 159; // Resistances Arrow Code
|
||||
|
||||
//
|
||||
input bool showSar = true; // Show Parabolic Sar
|
||||
input bool showPeaks = true; // Show Peaks
|
||||
input bool showVales = true; // Show Vales
|
||||
input bool showSar = true; // Show Parabolic Sar
|
||||
input bool showPeaks = true; // Show Peaks
|
||||
input bool showVales = true; // Show Vales
|
||||
input bool showGoldenZones = true; // Show Golden Zones
|
||||
input bool showSupports = true; // Show Supports
|
||||
input bool showResistances = true; // Show Resistances
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
@@ -96,8 +100,8 @@ input bool showGoldenZones = true; // Show Golden Zones
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 15
|
||||
#property indicator_plots 5
|
||||
#property indicator_buffers 19
|
||||
#property indicator_plots 7
|
||||
|
||||
//
|
||||
// Plot Buffers ...
|
||||
@@ -112,7 +116,7 @@ double peaksBuffer[];
|
||||
//
|
||||
#property indicator_label1 "X121 PEAKS"
|
||||
#property indicator_type1 DRAW_ARROW
|
||||
#property indicator_color1 clrAqua
|
||||
#property indicator_color1 clrMagenta
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
@@ -125,7 +129,7 @@ double valesBuffer[];
|
||||
//
|
||||
#property indicator_label2 "X121 VALES"
|
||||
#property indicator_type2 DRAW_ARROW
|
||||
#property indicator_color2 clrMagenta
|
||||
#property indicator_color2 clrAqua
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
@@ -160,11 +164,31 @@ double valesGoldenZoneBuffer[];
|
||||
#property indicator_style5 STYLE_DOT
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
#define supportsBufferIndex 5
|
||||
double supportsBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "X121 SUPRT"
|
||||
#property indicator_type6 DRAW_ARROW
|
||||
#property indicator_color6 clrLime
|
||||
#property indicator_width6 1
|
||||
|
||||
//
|
||||
#define resistancesBufferIndex 6
|
||||
double resistancesBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "X121 RESIS"
|
||||
#property indicator_type7 DRAW_ARROW
|
||||
#property indicator_color7 clrRed
|
||||
#property indicator_width7 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 4;
|
||||
int mLastBufferIndex = 6;
|
||||
|
||||
//
|
||||
// CURRENT ...
|
||||
@@ -221,6 +245,17 @@ double hHHBuffer[];
|
||||
#define hLLBufferIndex mLastBufferIndex + 10
|
||||
double hLLBuffer[];
|
||||
|
||||
//
|
||||
// Support and Resistances ...
|
||||
|
||||
//
|
||||
#define fractalsUpperBufferIndex mLastBufferIndex + 11
|
||||
double fractalsUpperBuffer[];
|
||||
|
||||
//
|
||||
#define fractalsLowerBufferIndex mLastBufferIndex + 12
|
||||
double fractalsLowerBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
@@ -235,6 +270,10 @@ int maxLength;
|
||||
// SAR Handler ...
|
||||
int sarHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// FRACTALS Handler ...
|
||||
int fractalHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// XMarketCycle sc;
|
||||
int mSCLength = 0;
|
||||
@@ -289,6 +328,18 @@ int OnInit()
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Fractal ...
|
||||
fractalHandler = iFractals(
|
||||
_Symbol,
|
||||
_Period //
|
||||
);
|
||||
isInited = fractalHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
if (!InitMarketCycles())
|
||||
{
|
||||
@@ -336,6 +387,7 @@ void OnDeinit(const int reason)
|
||||
|
||||
//
|
||||
IndicatorRelease(sarHandler);
|
||||
IndicatorRelease(fractalHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -385,11 +437,18 @@ int OnCalculate(
|
||||
// SAR ...
|
||||
int sarCalculatedBars = BarsCalculated(sarHandler);
|
||||
|
||||
//
|
||||
// FRACTALS ...
|
||||
int fractalsCalculatedBars = BarsCalculated(fractalHandler);
|
||||
|
||||
//
|
||||
bool isPassedRequiredCalculatedBars =
|
||||
//
|
||||
// SAR ...
|
||||
sarCalculatedBars >= maxLength
|
||||
sarCalculatedBars >= maxLength &&
|
||||
//
|
||||
// FRACTALS ...
|
||||
fractalsCalculatedBars >= maxLength
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCalculatedBars)
|
||||
@@ -409,12 +468,21 @@ int OnCalculate(
|
||||
// SAR ...
|
||||
int copiedSars = CopyBuffer(sarHandler, 0, 0, limit, sarBuffer);
|
||||
|
||||
//
|
||||
// FRACTALS ...
|
||||
int copiedFractalsUppers = CopyBuffer(fractalHandler, UPPER_LINE, 0, limit + 1, fractalsUpperBuffer);
|
||||
int copiedFractalsLowers = CopyBuffer(fractalHandler, LOWER_LINE, 0, limit + 1, fractalsLowerBuffer);
|
||||
|
||||
//
|
||||
// Validate Copied Items ...
|
||||
bool isPassedRequiredCopiedItems =
|
||||
//
|
||||
// SAR ...
|
||||
copiedSars > 0
|
||||
copiedSars > 0 &&
|
||||
//
|
||||
// FRACTALS ...
|
||||
copiedFractalsUppers > 0 &&
|
||||
copiedFractalsLowers > 0
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCopiedItems)
|
||||
@@ -514,7 +582,7 @@ void DefineBuffers()
|
||||
PlotIndexSetInteger(peaksBufferIndex, PLOT_DRAW_TYPE, peaksDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(peaksBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetDouble(peaksBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(peaksBufferIndex, PLOT_ARROW, peaksArrowCode);
|
||||
|
||||
//
|
||||
@@ -532,7 +600,7 @@ void DefineBuffers()
|
||||
PlotIndexSetInteger(valesBufferIndex, PLOT_DRAW_TYPE, valesDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(valesBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetDouble(valesBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(valesBufferIndex, PLOT_ARROW, valesArrowCode);
|
||||
|
||||
//
|
||||
@@ -550,9 +618,45 @@ void DefineBuffers()
|
||||
PlotIndexSetInteger(sarBufferIndex, PLOT_DRAW_TYPE, sarDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(sarBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetDouble(sarBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(sarBufferIndex, PLOT_ARROW, sarArrowCode);
|
||||
|
||||
//
|
||||
// Support ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE supportsDrawType = showSupports ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(supportsBuffer, true);
|
||||
SetIndexBuffer(supportsBufferIndex, supportsBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(supportsBufferIndex, PLOT_SHOW_DATA, showSupports);
|
||||
PlotIndexSetInteger(supportsBufferIndex, PLOT_DRAW_TYPE, supportsDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(supportsBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(supportsBufferIndex, PLOT_ARROW, supportsArrowCode);
|
||||
|
||||
//
|
||||
// Resistances...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE resistancesDrawType = showResistances ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(resistancesBuffer, true);
|
||||
SetIndexBuffer(resistancesBufferIndex, resistancesBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(resistancesBufferIndex, PLOT_SHOW_DATA, showResistances);
|
||||
PlotIndexSetInteger(resistancesBufferIndex, PLOT_DRAW_TYPE, resistancesDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(resistancesBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(resistancesBufferIndex, PLOT_ARROW, resistancesArrowCode);
|
||||
|
||||
//
|
||||
// Golden Zones ...
|
||||
|
||||
@@ -638,6 +742,17 @@ void DefineBuffers()
|
||||
//
|
||||
ArraySetAsSeries(hLLBuffer, true);
|
||||
SetIndexBuffer(hLLBufferIndex, hLLBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// FRACTALS ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fractalsUpperBuffer, true);
|
||||
SetIndexBuffer(fractalsUpperBufferIndex, fractalsUpperBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fractalsLowerBuffer, true);
|
||||
SetIndexBuffer(fractalsLowerBufferIndex, fractalsLowerBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -689,6 +804,19 @@ void CalculateBuffers(
|
||||
//
|
||||
// Calculate Peaks and Vales ...
|
||||
CalculatePeaksAndVales(bar_index);
|
||||
|
||||
//
|
||||
// Calculate Support nad Resistance ...
|
||||
CalculateSupportAndResistance(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -853,6 +981,16 @@ void FillBuffersZero(int barIndex)
|
||||
//
|
||||
// SARS ...
|
||||
sarBuffer[barIndex] = EMPTY_VALUE;
|
||||
|
||||
//
|
||||
// Support and Resistances ...
|
||||
supportsBuffer[barIndex] = EMPTY_VALUE;
|
||||
resistancesBuffer[barIndex] = EMPTY_VALUE;
|
||||
|
||||
//
|
||||
// Fractals ...
|
||||
fractalsUpperBuffer[barIndex] = EMPTY_VALUE;
|
||||
fractalsLowerBuffer[barIndex] = EMPTY_VALUE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1069,6 +1207,51 @@ void CalculatePeaksAndVales(int barIndex)
|
||||
X_DIRECTION_BEARISH //
|
||||
);
|
||||
valesGoldenZoneBuffer[barIndex] = iValeGoldenZone;
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Support nad Resistances ...
|
||||
*
|
||||
* @param bar_index: int, Specified Bar Index ...
|
||||
* @param prevCalculated: int, Provides Previous Calculated Bars ...
|
||||
* @param ratesTotal: int, Provides All Availabled Bars ...
|
||||
* @param open: double Collection, Provides Open Prices Time Series ...
|
||||
* @param high: double Collection, Provides High Prices Time Series ...
|
||||
* @param close: double Collection, Provides Close Prices Time Series ...
|
||||
* @param low: double Collection, Provides Low Prices Time Series ...
|
||||
* @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ...
|
||||
*/
|
||||
void CalculateSupportAndResistance(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
double iUpperFractalsPrev = fractalsUpperBuffer[bar_index + 1];
|
||||
double iLowerFractalsPrev = fractalsLowerBuffer[bar_index + 1];
|
||||
|
||||
//
|
||||
double iHigh = high[bar_index];
|
||||
double iLow = low[bar_index];
|
||||
|
||||
//
|
||||
double iSupport = iLowerFractalsPrev != EMPTY_VALUE
|
||||
? iLow
|
||||
: supportsBuffer[bar_index + 1];
|
||||
double iResistance = iUpperFractalsPrev != EMPTY_VALUE
|
||||
? iHigh
|
||||
: resistancesBuffer[bar_index + 1];
|
||||
|
||||
//
|
||||
supportsBuffer[bar_index] = iSupport;
|
||||
resistancesBuffer[bar_index] = iResistance;
|
||||
}
|
||||
//
|
||||
Reference in New Issue
Block a user