last ....
This commit is contained in:
@@ -67,6 +67,10 @@ input group "Sar Detection";
|
||||
input double sarStep = 0.02; // Step
|
||||
input double sarMax = 0.2; // Maximum
|
||||
|
||||
//
|
||||
input group "Swing Detection";
|
||||
input int swingLength = 5;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
@@ -76,6 +80,9 @@ 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 trendArrowCode = 117; // Trend Arrow Code
|
||||
input int swingLowsArrowCode = 159; // Swing Lows Arrow Code
|
||||
input int swingHighsArrowCode = 159; // Swing Highs Arrow Code
|
||||
input int supportsArrowCode = 159; // Supports Arrow Code
|
||||
input int resistancesArrowCode = 159; // Resistances Arrow Code
|
||||
|
||||
@@ -83,6 +90,9 @@ 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 showTrend = true; // Show Trend
|
||||
input bool showSwingLows = true; // Show Swing Lows
|
||||
input bool showSwingHighs = true; // Show Swing Highs
|
||||
input bool showGoldenZones = true; // Show Golden Zones
|
||||
input bool showSupports = true; // Show Supports
|
||||
input bool showResistances = true; // Show Resistances
|
||||
@@ -96,12 +106,15 @@ input bool showResistances = true; // Show Resistances
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#define emptyValue 0.0
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 19
|
||||
#property indicator_plots 7
|
||||
#property indicator_buffers 24
|
||||
#property indicator_plots 10
|
||||
|
||||
//
|
||||
// Plot Buffers ...
|
||||
@@ -143,52 +156,92 @@ double sarBuffer[];
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
#define peaksGoldenZoneBufferIndex 3
|
||||
double peaksGoldenZoneBuffer[];
|
||||
// Swing Lows ...
|
||||
|
||||
//
|
||||
#property indicator_label4 "X121 PEAKGZ"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrGold
|
||||
#property indicator_style4 STYLE_DOT
|
||||
#define swingLowsBufferIndex 3
|
||||
double swingLowsBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "X121 SWL"
|
||||
#property indicator_type4 DRAW_ARROW
|
||||
#property indicator_color4 clrDodgerBlue
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
#define valesGoldenZoneBufferIndex 4
|
||||
double valesGoldenZoneBuffer[];
|
||||
// Swng Highs ...
|
||||
|
||||
//
|
||||
#property indicator_label5 "X121 VALEGZ"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrGold
|
||||
#property indicator_style5 STYLE_DOT
|
||||
#define swingHighsBufferIndex 4
|
||||
double swingHighsBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "X121 SWH"
|
||||
#property indicator_type5 DRAW_ARROW
|
||||
#property indicator_color5 clrSaddleBrown
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
#define supportsBufferIndex 5
|
||||
double supportsBuffer[];
|
||||
#define peaksGoldenZoneBufferIndex 5
|
||||
double peaksGoldenZoneBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "X121 SUPRT"
|
||||
#property indicator_type6 DRAW_ARROW
|
||||
#property indicator_color6 clrLime
|
||||
#property indicator_label6 "X121 PEAKGZ"
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_color6 clrGold
|
||||
#property indicator_style6 STYLE_DOT
|
||||
#property indicator_width6 1
|
||||
|
||||
//
|
||||
#define resistancesBufferIndex 6
|
||||
#define valesGoldenZoneBufferIndex 6
|
||||
double valesGoldenZoneBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "X121 VALEGZ"
|
||||
#property indicator_type7 DRAW_LINE
|
||||
#property indicator_color7 clrGold
|
||||
#property indicator_style7 STYLE_DOT
|
||||
#property indicator_width7 1
|
||||
|
||||
//
|
||||
#define supportsBufferIndex 7
|
||||
double supportsBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label8 "X121 SUPRT"
|
||||
#property indicator_type8 DRAW_ARROW
|
||||
#property indicator_color8 clrLime
|
||||
#property indicator_width8 1
|
||||
|
||||
//
|
||||
#define resistancesBufferIndex 8
|
||||
double resistancesBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "X121 RESIS"
|
||||
#property indicator_type7 DRAW_ARROW
|
||||
#property indicator_color7 clrRed
|
||||
#property indicator_width7 1
|
||||
#property indicator_label9 "X121 RESIS"
|
||||
#property indicator_type9 DRAW_ARROW
|
||||
#property indicator_color9 clrRed
|
||||
#property indicator_width9 1
|
||||
|
||||
//
|
||||
// Trend ...
|
||||
#define trendBufferIndex 9
|
||||
double trendBuffer[];
|
||||
|
||||
#define trendColorBufferIndex 10
|
||||
double trendColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label10 "X121 TRND"
|
||||
#property indicator_type10 DRAW_COLOR_ARROW
|
||||
#property indicator_color10 CLR_NONE, clrAqua, clrMagenta, clrGray
|
||||
#property indicator_width10 2
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 6;
|
||||
int mLastBufferIndex = 10;
|
||||
|
||||
//
|
||||
// CURRENT ...
|
||||
@@ -256,6 +309,10 @@ double fractalsUpperBuffer[];
|
||||
#define fractalsLowerBufferIndex mLastBufferIndex + 12
|
||||
double fractalsLowerBuffer[];
|
||||
|
||||
//
|
||||
#define trendStateBufferIndex mLastBufferIndex + 13
|
||||
double trendStateBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
@@ -531,6 +588,7 @@ bool ValidateInputs()
|
||||
// SAR ...
|
||||
sarMax > 0 &&
|
||||
sarStep > 0 &&
|
||||
swingLength > 0 &&
|
||||
sarMax > sarStep &&
|
||||
//
|
||||
// XPV ...
|
||||
@@ -555,6 +613,9 @@ int ExtractMaxLengthOfInputs()
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(0, swingLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
@@ -621,6 +682,42 @@ void DefineBuffers()
|
||||
PlotIndexSetDouble(sarBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(sarBufferIndex, PLOT_ARROW, sarArrowCode);
|
||||
|
||||
//
|
||||
// Swing Lows ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE swingLowsDrawType = showSwingLows ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(swingLowsBuffer, true);
|
||||
SetIndexBuffer(swingLowsBufferIndex, swingLowsBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(swingLowsBufferIndex, PLOT_SHOW_DATA, showSwingLows);
|
||||
PlotIndexSetInteger(swingLowsBufferIndex, PLOT_DRAW_TYPE, swingLowsDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(swingLowsBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(swingLowsBufferIndex, PLOT_ARROW, swingLowsArrowCode);
|
||||
|
||||
//
|
||||
// Swing Highs ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE swingHighsDrawType = showSwingHighs ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(swingHighsBuffer, true);
|
||||
SetIndexBuffer(swingHighsBufferIndex, swingHighsBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(swingHighsBufferIndex, PLOT_SHOW_DATA, showSwingHighs);
|
||||
PlotIndexSetInteger(swingHighsBufferIndex, PLOT_DRAW_TYPE, swingHighsDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(swingHighsBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(swingHighsBufferIndex, PLOT_ARROW, swingHighsArrowCode);
|
||||
|
||||
//
|
||||
// Support ...
|
||||
|
||||
@@ -685,6 +782,28 @@ void DefineBuffers()
|
||||
PlotIndexSetInteger(valesGoldenZoneBufferIndex, PLOT_SHOW_DATA, showGoldenZones);
|
||||
PlotIndexSetInteger(valesGoldenZoneBufferIndex, PLOT_DRAW_TYPE, goldenZonesDrawType);
|
||||
|
||||
//
|
||||
// Trends ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE trendDrawType = showTrend ? DRAW_COLOR_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(trendBuffer, true);
|
||||
SetIndexBuffer(trendBufferIndex, trendBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(trendBufferIndex, PLOT_SHOW_DATA, showTrend);
|
||||
PlotIndexSetInteger(trendBufferIndex, PLOT_DRAW_TYPE, trendDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(trendBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(trendBufferIndex, PLOT_ARROW, trendArrowCode);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(trendColorBuffer, true);
|
||||
SetIndexBuffer(trendColorBufferIndex, trendColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
@@ -753,6 +872,10 @@ void DefineBuffers()
|
||||
//
|
||||
ArraySetAsSeries(fractalsLowerBuffer, true);
|
||||
SetIndexBuffer(fractalsLowerBufferIndex, fractalsLowerBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(trendStateBuffer, true);
|
||||
SetIndexBuffer(trendStateBufferIndex, trendStateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -760,6 +883,8 @@ void DefineBuffers()
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, 2);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
@@ -817,6 +942,19 @@ void CalculateBuffers(
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
|
||||
//
|
||||
// Calcultae Swing High and Low and Trends ...
|
||||
CalculateSwingsAndTrend(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -987,6 +1125,13 @@ void FillBuffersZero(int barIndex)
|
||||
supportsBuffer[barIndex] = EMPTY_VALUE;
|
||||
resistancesBuffer[barIndex] = EMPTY_VALUE;
|
||||
|
||||
//
|
||||
trendBuffer[barIndex] = emptyValue;
|
||||
swingLowsBuffer[barIndex] = emptyValue;
|
||||
swingHighsBuffer[barIndex] = emptyValue;
|
||||
trendStateBuffer[barIndex] = emptyValue;
|
||||
trendColorBuffer[barIndex] = hideColorIDX;
|
||||
|
||||
//
|
||||
// Fractals ...
|
||||
fractalsUpperBuffer[barIndex] = EMPTY_VALUE;
|
||||
@@ -1254,4 +1399,208 @@ void CalculateSupportAndResistance(
|
||||
supportsBuffer[bar_index] = iSupport;
|
||||
resistancesBuffer[bar_index] = iResistance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Swing High and Low and Trend ...
|
||||
*
|
||||
* @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 CalculateSwingsAndTrend(
|
||||
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[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int lastBarIndex = bar_index + 1;
|
||||
bool isFirstBar =
|
||||
startCalculationForLastBars > 0
|
||||
? bar_index == startCalculationForLastBars
|
||||
: bar_index == ratesTotal;
|
||||
|
||||
//
|
||||
double iLow = low[bar_index];
|
||||
double iHigh = high[bar_index];
|
||||
double iOpen = open[bar_index];
|
||||
double iClose = close[bar_index];
|
||||
|
||||
//
|
||||
// Swing Low ...
|
||||
double lastSwingLow = isFirstBar
|
||||
? emptyValue
|
||||
: swingLowsBuffer[lastBarIndex];
|
||||
bool isSwingLow = IsSwingLow(high, low, bar_index, swingLength);
|
||||
double iSwingLow =
|
||||
!isSwingLow
|
||||
? lastSwingLow
|
||||
: iLow;
|
||||
swingLowsBuffer[bar_index] = iSwingLow;
|
||||
|
||||
//
|
||||
// Swing High ...
|
||||
double lastSwingHigh = isFirstBar
|
||||
? emptyValue
|
||||
: swingHighsBuffer[lastBarIndex];
|
||||
bool isSwingHigh = IsSwingHigh(high, low, bar_index, swingLength);
|
||||
double iSwingHigh =
|
||||
!isSwingHigh
|
||||
? lastSwingHigh
|
||||
: iHigh;
|
||||
swingHighsBuffer[bar_index] = iSwingHigh;
|
||||
|
||||
//
|
||||
// Calculate Trend ...
|
||||
|
||||
//
|
||||
double lastTrend = isFirstBar
|
||||
? emptyValue
|
||||
: trendBuffer[lastBarIndex];
|
||||
double iTrend =
|
||||
isSwingLow &&
|
||||
iSwingLow > lastSwingLow
|
||||
? iSwingLow
|
||||
: isSwingHigh &&
|
||||
iSwingHigh < lastSwingHigh
|
||||
? iSwingHigh
|
||||
: lastTrend;
|
||||
trendBuffer[bar_index] = iTrend;
|
||||
|
||||
//
|
||||
double lastTrendState = isFirstBar
|
||||
? emptyValue
|
||||
: trendStateBuffer[lastBarIndex];
|
||||
double iTrendState =
|
||||
isSwingLow &&
|
||||
iSwingLow > lastSwingLow
|
||||
? 1
|
||||
: isSwingHigh &&
|
||||
iSwingHigh < lastSwingHigh
|
||||
? -1
|
||||
: lastTrendState;
|
||||
|
||||
//
|
||||
bool isTrendBraked = false;
|
||||
if (!isTrendBraked)
|
||||
{
|
||||
//
|
||||
bool isBullishState = iTrendState > 0;
|
||||
bool isBearishState = iTrendState < 0;
|
||||
|
||||
//
|
||||
isTrendBraked = isBullishState
|
||||
? iClose < iTrend
|
||||
: isBearishState
|
||||
? iClose > iTrend
|
||||
: false;
|
||||
if (isTrendBraked)
|
||||
{
|
||||
//
|
||||
if (isBullishState)
|
||||
{
|
||||
iTrendState = -1;
|
||||
}
|
||||
|
||||
//
|
||||
if (isBearishState)
|
||||
{
|
||||
iTrendState = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
trendStateBuffer[bar_index] = iTrendState;
|
||||
|
||||
//
|
||||
double iTrendColor = iTrendState == 0
|
||||
? neuturalColorIDX
|
||||
: iTrendState > 0
|
||||
? bullishColorIDX
|
||||
: iTrendState < 0
|
||||
? bearishColorIDX
|
||||
: hideColorIDX;
|
||||
trendColorBuffer[bar_index] = iTrendColor;
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
bool IsSwingLow(
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
int index,
|
||||
int length //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = index - length > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 1; i <= length; i++)
|
||||
{
|
||||
//
|
||||
result = low[index] < low[index - 1] &&
|
||||
low[index] < low[index + i];
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool IsSwingHigh(
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
int index,
|
||||
int length //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = index - length > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 1; i <= length; i++)
|
||||
{
|
||||
//
|
||||
result = high[index] > high[index - 1] &&
|
||||
high[index] > high[index + i];
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user