last ...
This commit is contained in:
+198
-15
@@ -99,6 +99,7 @@ input bool showMAFast = true; // Show MA Fast
|
||||
input bool showMASlow = true; // Show MA Slow
|
||||
input bool showMABand = true; // Show MA Band
|
||||
input bool showZigZag = true; // Show ZigZag
|
||||
input bool showZigZagPV = true; // Show ZigZag PV
|
||||
input bool showFiboZone = true; // Show Fibo Zone
|
||||
|
||||
//
|
||||
@@ -133,8 +134,8 @@ input int valeArrowCode = 159; // Vales Arrow Code
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 29
|
||||
#property indicator_plots 11
|
||||
#property indicator_buffers 31
|
||||
#property indicator_plots 13
|
||||
|
||||
//
|
||||
// Plot Buffers ...
|
||||
@@ -277,39 +278,67 @@ double zigzagBuffer[];
|
||||
#property indicator_color9 clrYellow
|
||||
#property indicator_width9 2
|
||||
|
||||
//
|
||||
// ZG Peak ...
|
||||
|
||||
//
|
||||
#define zigzagPeakBufferIndex 12
|
||||
#define zigzagPeakBufferPlotIndex 9
|
||||
double zigzagPeakBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label10 "XZG Peak"
|
||||
#property indicator_type10 DRAW_ARROW
|
||||
#property indicator_color10 clrYellow
|
||||
#property indicator_width10 3
|
||||
|
||||
//
|
||||
// ZG Vale ...
|
||||
|
||||
//
|
||||
#define zigzagValeBufferIndex 13
|
||||
#define zigzagValeBufferPlotIndex 10
|
||||
double zigzagValeBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label11 "XZG Peak"
|
||||
#property indicator_type11 DRAW_ARROW
|
||||
#property indicator_color11 clrDarkOrange
|
||||
#property indicator_width11 3
|
||||
|
||||
//
|
||||
// MA Upper Boundary ...
|
||||
|
||||
//
|
||||
#define maUpperBufferIndex 12
|
||||
#define maUpperBufferPlotIndex 9
|
||||
#define maUpperBufferIndex 14
|
||||
#define maUpperBufferPlotIndex 11
|
||||
double maUpperBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label10 "UpperMA"
|
||||
#property indicator_type10 DRAW_LINE
|
||||
#property indicator_color10 clrAqua
|
||||
#property indicator_width10 3
|
||||
#property indicator_label12 "UpperMA"
|
||||
#property indicator_type12 DRAW_LINE
|
||||
#property indicator_color12 clrAqua
|
||||
#property indicator_width12 3
|
||||
|
||||
//
|
||||
// MA Lower Boundary ...
|
||||
|
||||
//
|
||||
#define maLowerBufferIndex 13
|
||||
#define maLowerBufferPlotIndex 10
|
||||
#define maLowerBufferIndex 15
|
||||
#define maLowerBufferPlotIndex 12
|
||||
double maLowerBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label11 "LowerMA"
|
||||
#property indicator_type11 DRAW_LINE
|
||||
#property indicator_color11 clrMagenta
|
||||
#property indicator_width11 3
|
||||
#property indicator_label13 "LowerMA"
|
||||
#property indicator_type13 DRAW_LINE
|
||||
#property indicator_color13 clrMagenta
|
||||
#property indicator_width13 3
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
#define mLastBufferIndex 13
|
||||
#define mLastBufferIndex 15
|
||||
|
||||
//
|
||||
// MA ...
|
||||
@@ -446,6 +475,14 @@ int zigzagLowersCount = 0;
|
||||
int zigzagUppersCount = 0;
|
||||
int zigzagRecalc = 3; // Number of last extremes for recalculation
|
||||
|
||||
//
|
||||
double lastZigZagPeak = 0;
|
||||
datetime lastZigZagPeakTime = NULL;
|
||||
|
||||
//
|
||||
double lastZigZagVale = 0;
|
||||
datetime lastZigZagValeTime = NULL;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
@@ -585,6 +622,32 @@ int OnCalculate(
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating Limit ...
|
||||
limit = prev_calculated == 0
|
||||
? rates_total - 1
|
||||
: rates_total - prev_calculated;
|
||||
if (limit <= 0)
|
||||
{
|
||||
limit = rates_total - 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i < rates_total - 1 && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
Print("Calculating Bar Index: ", i);
|
||||
|
||||
//
|
||||
// Calculate Peaks and Vales ...
|
||||
CalculateZigZagPV(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
@@ -921,6 +984,38 @@ void DefineBuffers()
|
||||
PlotIndexSetInteger(zigzagBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetDouble(zigzagBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
// ZigZag PV ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE zigzagPVDrawType = showZigZagPV ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// ZG Peak ...
|
||||
|
||||
//
|
||||
SetIndexBuffer(zigzagPeakBufferIndex, zigzagPeakBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(zigzagPeakBufferPlotIndex, PLOT_SHOW_DATA, showZigZagPV);
|
||||
PlotIndexSetInteger(zigzagPeakBufferPlotIndex, PLOT_DRAW_TYPE, zigzagPVDrawType);
|
||||
|
||||
PlotIndexSetInteger(zigzagPeakBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetDouble(zigzagPeakBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
// ZG Vale ...
|
||||
|
||||
//
|
||||
SetIndexBuffer(zigzagValeBufferIndex, zigzagValeBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(zigzagValeBufferPlotIndex, PLOT_SHOW_DATA, showZigZagPV);
|
||||
PlotIndexSetInteger(zigzagValeBufferPlotIndex, PLOT_DRAW_TYPE, zigzagPVDrawType);
|
||||
|
||||
PlotIndexSetInteger(zigzagValeBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetDouble(zigzagValeBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
// MA Band ...
|
||||
|
||||
@@ -1912,6 +2007,94 @@ int CalculateZigZag(
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Peaks and Vales ...
|
||||
*
|
||||
* @param barIndex: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateZigZagPV(
|
||||
int barIndex,
|
||||
const int prevCalculated,
|
||||
const int ratesTotal //
|
||||
)
|
||||
{
|
||||
//
|
||||
double iZigZagValue = zigzagBuffer[barIndex];
|
||||
|
||||
//
|
||||
// Print("Calculate Bar Index: ", barIndex, ", ZG: ", iZigZagValue, ", ", prevCalculated, ", ", ratesTotal);
|
||||
|
||||
//
|
||||
// Peak ...
|
||||
double iHighValue = highsBuffer[barIndex];
|
||||
double iHighTimeDouble = highsTimeBuffer[barIndex];
|
||||
datetime iHighTime = (datetime)((int)iHighTimeDouble);
|
||||
if (iHighValue != 0 && iHighValue != EMPTY_VALUE && iZigZagValue == iHighValue)
|
||||
{
|
||||
//
|
||||
peakBuffer[barIndex] = iHighValue;
|
||||
|
||||
//
|
||||
lastZigZagPeak = iHighValue;
|
||||
lastZigZagPeakTime = iHighTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
double iValue = emptyValue;
|
||||
if (
|
||||
lastZigZagPeak != emptyValue &&
|
||||
lastZigZagPeak != EMPTY_VALUE &&
|
||||
IsSpecifiedValid(lastZigZagPeakTime))
|
||||
{
|
||||
iValue = lastZigZagPeak;
|
||||
}
|
||||
|
||||
//
|
||||
peakBuffer[barIndex] = iValue;
|
||||
}
|
||||
|
||||
//
|
||||
// Vale ...
|
||||
double iLowValue = lowsBuffer[barIndex];
|
||||
double iLowTimeDouble = lowsTimeBuffer[barIndex];
|
||||
datetime iLowTime = (datetime)((int)iLowTimeDouble);
|
||||
if (iLowValue != 0 && iLowValue != EMPTY_VALUE && iZigZagValue == iLowValue)
|
||||
{
|
||||
//
|
||||
valeBuffer[barIndex] = iLowValue;
|
||||
|
||||
//
|
||||
lastZigZagVale = iLowValue;
|
||||
lastZigZagValeTime = iLowTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
double iValue = emptyValue;
|
||||
if (
|
||||
lastZigZagVale != emptyValue &&
|
||||
lastZigZagVale != EMPTY_VALUE &&
|
||||
IsSpecifiedValid(lastZigZagValeTime))
|
||||
{
|
||||
iValue = lastZigZagVale;
|
||||
}
|
||||
|
||||
//
|
||||
valeBuffer[barIndex] = iValue;
|
||||
}
|
||||
|
||||
//
|
||||
// ChartRedraw();
|
||||
}
|
||||
|
||||
//
|
||||
void CalculateCycleRanges(
|
||||
int barIndex,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user