last works and apply fix on ZigZag Reading ...

This commit is contained in:
2025-09-20 13:55:34 +03:30
parent 6788675c4a
commit becac9983d
5 changed files with 851 additions and 41 deletions
+49 -4
View File
@@ -101,6 +101,7 @@ input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method
input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // MA Applied To
input int maFastLength = 7; // Fast MA Length
input int maSlowLength = 20; // Slow MA Length
input int maBandLength = 7; // MA Band Length
input int zigzagDepth = 12; // ZigZag Depth
input int zigzagDeviation = 5; // ZigZag Deviation
input int zigzagBackStep = 3; // ZigZag Back Step
@@ -121,6 +122,7 @@ input bool showPV = true; // Show PV
input bool showSAR = true; // Show Sar
input bool showMAFast = true; // Show MA Fast
input bool showMASlow = true; // Show MA Slow
input bool showMABand = true; // Show MA Band
input bool showBarTime = true; // Show Bar Time
input bool showZigZag = true; // Show ZigZag
input bool showFiboZone = true; // Show Fibo Zone
@@ -137,15 +139,19 @@ input int valeArrowCode = 159; // Vales Arrow Code
// Define Local Variables ...
//
// Requirements ...
string eaLogTag; // EA Log Prefix ...
XCBackTesterEA *eaExpert; // EA Expert ...
XCXFIMAPOIDetector *fimaPOIDetector; // EA Fima POI Detector ...
XCMarketPatternDetector *eaPatternDetector; // EA Pattern Detector ...
//
// Registered Signallers ...
XCXFIMAStrategy1Signaller *fima1Signaller; // XFIMA1 Signaller ...
XCXFIMAStrategy2Signaller *fima2Signaller; // XFIMA2 Signaller ...
//
// Drawer and Draws ...
XCPOIDrawer *eaDrawer; // Ea POI Drawer ...
CArrayObj draws; // Drawn Objects ...
@@ -153,7 +159,7 @@ CArrayObj draws; // Drawn Objects ...
XBarTracker eaBarTracker; // EA Bar Traker ...
//
int eaHandler = INVALID_HANDLE; // Indicator Handler ...
// Registered Handlers ...
int eaCTHandler = INVALID_HANDLE; // Candle Timer Handler ...
//
@@ -280,6 +286,7 @@ int OnInit()
fimaInputs.maAppliedTo = maAppliedTo;
fimaInputs.maFastLength = maFastLength;
fimaInputs.maSlowLength = maSlowLength;
fimaInputs.maBandLength = maBandLength;
fimaInputs.zigzagDepth = zigzagDepth;
fimaInputs.zigzagDeviation = zigzagDeviation;
fimaInputs.zigzagBackStep = zigzagBackStep;
@@ -289,6 +296,7 @@ int OnInit()
fimaInputs.showSAR = showSAR;
fimaInputs.showMAFast = showMAFast;
fimaInputs.showMASlow = showMASlow;
fimaInputs.showMABand = showMABand;
fimaInputs.showZigZag = showZigZag;
fimaInputs.showFiboZone = showFiboZone;
fimaInputs.startCalculationForLastBars = startCalculationForLastBars;
@@ -379,6 +387,9 @@ int OnInit()
// Instantiate Market Pattern Detector ...
eaPatternDetector = new XCMarketPatternDetector();
//
fimaPOIDetector = new XCXFIMAPOIDetector();
//
// Instantiate POI Drawer ...
eaDrawer = new XCPOIDrawer();
@@ -410,7 +421,7 @@ void OnDeinit(const int reason)
//
// De Init Indicator ...
IndicatorRelease(eaHandler);
IndicatorRelease(eaCTHandler);
//
eaBarTracker.Clean();
@@ -431,6 +442,10 @@ void OnDeinit(const int reason)
delete fima2Signaller;
ZeroMemory(fima2Signaller);
//
delete fimaPOIDetector;
ZeroMemory(fimaPOIDetector);
//
delete eaExpert;
ZeroMemory(eaExpert);
@@ -608,7 +623,8 @@ void OnSignalTriggered(XSignal &signal)
{
//
// Validate Signal ...
if (!signal.IsValid()) {
if (!signal.IsValid())
{
return;
}
@@ -642,7 +658,6 @@ void OnSignalTriggered(XSignal &signal)
//
// Alert Issued Signal ...
string message = signal.GetMessage();
}
//
@@ -825,6 +840,11 @@ void DetectPatterns()
bool detectSupports = true;
bool detectResistance = true;
//
// XFIMA Patetrns ...
bool detectFIMAPatterns = true;
bool detectZIGZAGPatterns = true;
//
// Checking Momentum Bar ...
if (detectMomentum)
@@ -1164,6 +1184,31 @@ void DetectPatterns()
resistance.Clean();
}
//
// Detecting FIMA Patterns ...
if (detectFIMAPatterns)
{
//
// ZIGZAG Pattern ...
if (detectZIGZAGPatterns)
{
//
XZigZagPoint zigzags[];
int zigzagsCount = fimaPOIDetector.GetZigZagPoint(
cBar,
fima2Signaller.fimaHelper,
zigzags,
3 //
);
has = IsValidSize(zigzagsCount);
if (has)
{
//
Print("Detected ZigZags Points: ", zigzagsCount);
}
}
}
//
cBar.Clean();
}
+219 -29
View File
@@ -42,29 +42,31 @@ enum ENUM_XFIMA_BUFFERS
XFIMA_SAR_STATE_LINE = 14,
XFIMA_PEAK_LINE = 6,
XFIMA_VALE_LINE = 7,
XFIMA_FINO_UPPER_LINE = 8,
XFIMA_FINO_MIDDLE_LINE = 9,
XFIMA_FINO_LOWER_LINE = 10,
XFIMA_FIBO_UPPER_LINE = 8,
XFIMA_FIBO_MIDDLE_LINE = 9,
XFIMA_FIBO_LOWER_LINE = 10,
XFIMA_ZIGZAG_LINE = 11,
XFIMA_ZIGZAG_HIGHS_LINE = 23,
XFIMA_ZIGZAG_HIGHS_TIME_LINE = 24,
XFIMA_ZIGZAG_LOWS_LINE = 25,
XFIMA_ZIGZAG_LOWS_TIME_LINE = 26,
// 12 Ma Fast State
// 13 Ma Slow State
// 14 Sar State
XFIMA_SC_HH_LINE = 15,
XFIMA_SC_LL_LINE = 16,
XFIMA_MC_HH_LINE = 17,
XFIMA_MC_LL_LINE = 18,
XFIMA_LC_HH_LINE = 19,
XFIMA_LC_LL_LINE = 20,
XFIMA_HC_HH_LINE = 21,
XFIMA_HC_LL_LINE = 22,
// 23 ZigZag Highs
// 24 ZigZag Highs Time
// 25 ZigZag Lows
// 26 ZigZag Lows Time
XFIMA_MA_BAND_UPPER_LINE = 12,
XFIMA_MA_BAND_LOWER_LINE = 13,
XFIMA_ZIGZAG_HIGHS_LINE = 25,
XFIMA_ZIGZAG_HIGHS_TIME_LINE = 26,
XFIMA_ZIGZAG_LOWS_LINE = 27,
XFIMA_ZIGZAG_LOWS_TIME_LINE = 28,
// 14 Ma Fast State
// 15 Ma Slow State
// 16 Sar State
XFIMA_SC_HH_LINE = 17,
XFIMA_SC_LL_LINE = 18,
XFIMA_MC_HH_LINE = 19,
XFIMA_MC_LL_LINE = 20,
XFIMA_LC_HH_LINE = 21,
XFIMA_LC_LL_LINE = 22,
XFIMA_HC_HH_LINE = 23,
XFIMA_HC_LL_LINE = 24,
// 25 ZigZag Highs
// 26 ZigZag Highs Time
// 27 ZigZag Lows
// 28 ZigZag Lows Time
};
//
@@ -95,6 +97,7 @@ struct XFIMAInputs
ENUM_APPLIED_PRICE maAppliedTo; // MA Applied To
int maFastLength; // Fast MA Length
int maSlowLength; // Slow MA Length
int maBandLength; // MA Band Length
int zigzagDepth; // ZigZag Depth
int zigzagDeviation; // ZigZag Deviation
int zigzagBackStep; // ZigZag Back Step
@@ -107,6 +110,7 @@ struct XFIMAInputs
bool showSAR; // Show Sar
bool showMAFast; // Show MA Fast
bool showMASlow; // Show MA Slow
bool showMABand; // Show MA Band
bool showZigZag; // Show ZigZag
bool showFiboZone; // Show Fibo Zone
int startCalculationForLastBars; // Calculate Last n Bars
@@ -156,6 +160,7 @@ struct XFIMAInputs
maAppliedTo = PRICE_CLOSE; // MA Applied To
maFastLength = 7; // Fast MA Length
maSlowLength = 20; // Slow MA Length
maBandLength = 7; // MA Band Length
zigzagDepth = 12; // ZigZag Depth
zigzagDeviation = 5; // ZigZag Deviation
zigzagBackStep = 3; // ZigZag Back Step
@@ -168,6 +173,7 @@ struct XFIMAInputs
showSAR = true; // Show Sar
showMAFast = true; // Show MA Fast
showMASlow = true; // Show MA Slow
showMABand = true; // Show MA Band
showZigZag = true; // Show ZigZag
showFiboZone = true; // Show Fibo Zone
startCalculationForLastBars = 1500; // Calculate Last n Bars
@@ -185,6 +191,7 @@ struct XFIMAInputs
showSAR = false;
showMAFast = false;
showMASlow = false;
showMABand = false;
showZigZag = false;
showFiboZone = false;
}
@@ -202,6 +209,7 @@ struct XFIMAInputs
// MA ...
maFastLength >= 2 &&
maSlowLength >= 2 &&
maBandLength >= 2 &&
maSlowLength > maFastLength &&
//
// SAR ...
@@ -256,6 +264,8 @@ struct XFIMAConditions
double maSlowBuffer[];
double maSlowColorBuffer[];
double maSlowStateBuffer[];
double maBandUpperBuffer[];
double maBandLowerBuffer[];
double sarBuffer[];
double sarColorBuffer[];
double sarStateBuffer[];
@@ -317,6 +327,8 @@ struct XFIMAConditions
SpecifiedClean(maSlowBuffer);
SpecifiedClean(maSlowColorBuffer);
SpecifiedClean(maSlowStateBuffer);
SpecifiedClean(maBandUpperBuffer);
SpecifiedClean(maBandLowerBuffer);
SpecifiedClean(sarBuffer);
SpecifiedClean(sarColorBuffer);
SpecifiedClean(sarStateBuffer);
@@ -352,6 +364,8 @@ struct XFIMAConditions
ArraySetAsSeries(maSlowBuffer, true);
ArraySetAsSeries(maSlowColorBuffer, true);
ArraySetAsSeries(maSlowStateBuffer, true);
ArraySetAsSeries(maBandUpperBuffer, true);
ArraySetAsSeries(maBandLowerBuffer, true);
ArraySetAsSeries(sarBuffer, true);
ArraySetAsSeries(sarColorBuffer, true);
ArraySetAsSeries(sarStateBuffer, true);
@@ -360,7 +374,7 @@ struct XFIMAConditions
ArraySetAsSeries(fiboUpperBuffer, true);
ArraySetAsSeries(fiboMiddleBuffer, true);
ArraySetAsSeries(fiboLowerBuffer, true);
ArraySetAsSeries(zigzagBuffer, true);
ArraySetAsSeries(zigzagBuffer, false); // Fix this ...
ArraySetAsSeries(sHHBuffer, true);
ArraySetAsSeries(sLLBuffer, true);
ArraySetAsSeries(mHHBuffer, true);
@@ -442,6 +456,8 @@ class XCXFIMAHelper : public XCBaseHelper
double maSlowBuffer[];
double maSlowColorBuffer[];
double maSlowStateBuffer[];
double maBandUpperBuffer[];
double maBandLowerBuffer[];
double sarBuffer[];
double sarColorBuffer[];
double sarStateBuffer[];
@@ -509,6 +525,8 @@ class XCXFIMAHelper : public XCBaseHelper
ArraySetAsSeries(maSlowBuffer, true);
ArraySetAsSeries(maSlowColorBuffer, true);
ArraySetAsSeries(maSlowStateBuffer, true);
ArraySetAsSeries(maBandUpperBuffer, true);
ArraySetAsSeries(maBandLowerBuffer, true);
ArraySetAsSeries(sarBuffer, true);
ArraySetAsSeries(sarColorBuffer, true);
ArraySetAsSeries(sarStateBuffer, true);
@@ -517,7 +535,7 @@ class XCXFIMAHelper : public XCBaseHelper
ArraySetAsSeries(fiboUpperBuffer, true);
ArraySetAsSeries(fiboMiddleBuffer, true);
ArraySetAsSeries(fiboLowerBuffer, true);
ArraySetAsSeries(zigzagBuffer, true);
ArraySetAsSeries(zigzagBuffer, false); // TODO: FIX This ...
ArraySetAsSeries(sHHBuffer, true);
ArraySetAsSeries(sLLBuffer, true);
ArraySetAsSeries(mHHBuffer, true);
@@ -559,6 +577,7 @@ class XCXFIMAHelper : public XCBaseHelper
mInputs.maAppliedTo,
mInputs.maFastLength,
mInputs.maSlowLength,
mInputs.maBandLength,
mInputs.zigzagDepth,
mInputs.zigzagDeviation,
mInputs.zigzagBackStep,
@@ -569,6 +588,7 @@ class XCXFIMAHelper : public XCBaseHelper
mInputs.showSAR,
mInputs.showMAFast,
mInputs.showMASlow,
mInputs.showMABand,
mInputs.showZigZag,
mInputs.showFiboZone,
mInputs.startCalculationForLastBars,
@@ -715,6 +735,20 @@ class XCXFIMAHelper : public XCBaseHelper
conditions.maSlowStateBuffer //
);
//
CopyMABandUpper(
zIndex,
loopback,
conditions.maBandUpperBuffer //
);
//
CopyMABandLower(
zIndex,
loopback,
conditions.maBandLowerBuffer //
);
//
CopySar(
zIndex,
@@ -1045,6 +1079,110 @@ class XCXFIMAHelper : public XCBaseHelper
);
}
//
// Upper MA ...
//
double GetMABandUpper(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(maBandUpperBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return maBandUpperBuffer[barIndex];
}
//
int CopyMABandUpper(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate(start);
//
// Copy Items ...
return Copy(
0,
count,
maBandUpperBuffer,
buffer,
forceClean
//
);
}
//
// Lower MA ...
//
double GetMABandLower(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(maBandLowerBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return maBandLowerBuffer[barIndex];
}
//
int CopyMABandLower(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate(start);
//
// Copy Items ...
return Copy(
0,
count,
maBandLowerBuffer,
buffer,
forceClean
//
);
}
//
// SAR ...
@@ -1427,7 +1565,18 @@ class XCXFIMAHelper : public XCBaseHelper
}
//
Calculate(barIndex);
// Calculate(barIndex);
SpecifiedClean(zigzagBuffer);
//
CopyBuffer(
mHandler,
XFIMA_ZIGZAG_LINE,
barIndex,
1,
zigzagBuffer //
);
//
int count = ArraySize(zigzagBuffer);
@@ -1450,7 +1599,18 @@ class XCXFIMAHelper : public XCBaseHelper
{
//
// Update Calculations ...
Calculate(start);
// Calculate(start);
SpecifiedClean(zigzagBuffer);
//
CopyBuffer(
mHandler,
XFIMA_ZIGZAG_LINE,
start,
0,
zigzagBuffer //
);
//
// Copy Items ...
@@ -1976,6 +2136,24 @@ class XCXFIMAHelper : public XCBaseHelper
maSlowStateBuffer //
);
//
CopyBuffer(
mHandler,
XFIMA_MA_BAND_UPPER_LINE,
barIndex,
maxRequiredBars,
maBandUpperBuffer //
);
//
CopyBuffer(
mHandler,
XFIMA_MA_BAND_LOWER_LINE,
barIndex,
maxRequiredBars,
maBandLowerBuffer //
);
//
CopyBuffer(
mHandler,
@@ -2024,7 +2202,7 @@ class XCXFIMAHelper : public XCBaseHelper
//
CopyBuffer(
mHandler,
XFIMA_FINO_UPPER_LINE,
XFIMA_FIBO_UPPER_LINE,
barIndex,
maxRequiredBars,
fiboUpperBuffer //
@@ -2033,7 +2211,7 @@ class XCXFIMAHelper : public XCBaseHelper
//
CopyBuffer(
mHandler,
XFIMA_FINO_MIDDLE_LINE,
XFIMA_FIBO_MIDDLE_LINE,
barIndex,
maxRequiredBars,
fiboMiddleBuffer //
@@ -2042,7 +2220,7 @@ class XCXFIMAHelper : public XCBaseHelper
//
CopyBuffer(
mHandler,
XFIMA_FINO_LOWER_LINE,
XFIMA_FIBO_LOWER_LINE,
barIndex,
maxRequiredBars,
fiboLowerBuffer //
@@ -2207,6 +2385,18 @@ class XCXFIMAHelper : public XCBaseHelper
maxAllowed //
);
//
CleanupArray(
maBandUpperBuffer,
maxAllowed //
);
//
CleanupArray(
maBandLowerBuffer,
maxAllowed //
);
//
CleanupArray(
sarBuffer,
+113 -3
View File
@@ -83,6 +83,7 @@ input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method
input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // MA Applied To
input int maFastLength = 7; // Fast MA Length
input int maSlowLength = 20; // Slow MA Length
input int maBandLength = 7; // MA Band Length
input int zigzagDepth = 12; // ZigZag Depth
input int zigzagDeviation = 5; // ZigZag Deviation
input int zigzagBackStep = 3; // ZigZag Back Step
@@ -96,6 +97,7 @@ input bool showPV = true; // Show PV
input bool showSAR = true; // Show Sar
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 showFiboZone = true; // Show Fibo Zone
@@ -131,8 +133,8 @@ input int valeArrowCode = 159; // Vales Arrow Code
#property indicator_chart_window
//
#property indicator_buffers 27
#property indicator_plots 9
#property indicator_buffers 29
#property indicator_plots 11
//
// Plot Buffers ...
@@ -275,11 +277,39 @@ double zigzagBuffer[];
#property indicator_color9 clrYellow
#property indicator_width9 2
//
// MA Upper Boundary ...
//
#define maUpperBufferIndex 12
#define maUpperBufferPlotIndex 9
double maUpperBuffer[];
//
#property indicator_label10 "UpperMA"
#property indicator_type10 DRAW_LINE
#property indicator_color10 clrAqua
#property indicator_width10 3
//
// MA Lower Boundary ...
//
#define maLowerBufferIndex 13
#define maLowerBufferPlotIndex 10
double maLowerBuffer[];
//
#property indicator_label11 "LowerMA"
#property indicator_type11 DRAW_LINE
#property indicator_color11 clrMagenta
#property indicator_width11 3
//
// Data Buffers ...
//
#define mLastBufferIndex 11
#define mLastBufferIndex 13
//
// MA ...
@@ -392,6 +422,8 @@ ENUM_TIMEFRAMES mHCPeriod = NULL;
int sarHandler = INVALID_HANDLE;
int maFastHandler = INVALID_HANDLE;
int maSlowHandler = INVALID_HANDLE;
int maUpperHandler = INVALID_HANDLE;
int maLowerHandler = INVALID_HANDLE;
//
int limit;
@@ -503,6 +535,8 @@ void OnDeinit(const int reason)
IndicatorRelease(sarHandler);
IndicatorRelease(maFastHandler);
IndicatorRelease(maSlowHandler);
IndicatorRelease(maUpperHandler);
IndicatorRelease(maLowerHandler);
}
/**
@@ -569,6 +603,8 @@ int OnCalculate(
// MA ...
int maFastCalculatedBars = BarsCalculated(maFastHandler);
int maSlowCalculatedBars = BarsCalculated(maSlowHandler);
int maUpperCalculatedBars = BarsCalculated(maUpperHandler);
int maLowerCalculatedBars = BarsCalculated(maLowerHandler);
//
// SAR ...
@@ -580,6 +616,8 @@ int OnCalculate(
// MA ...
maFastCalculatedBars >= maxLength &&
maSlowCalculatedBars >= maxLength &&
maUpperCalculatedBars >= maxLength &&
maLowerCalculatedBars >= maxLength &&
//
// SAR ...
sarCalculatedBars >= maxLength
@@ -602,6 +640,8 @@ int OnCalculate(
// MA ...
int copiedMAFasts = CopyBuffer(maFastHandler, MAIN_LINE, 0, limit, maFastBuffer);
int copiedMASlows = CopyBuffer(maSlowHandler, MAIN_LINE, 0, limit, maSlowBuffer);
int copiedMAUppers = CopyBuffer(maUpperHandler, MAIN_LINE, 0, limit, maUpperBuffer);
int copiedMALowers = CopyBuffer(maLowerHandler, MAIN_LINE, 0, limit, maLowerBuffer);
//
// SAR ...
@@ -614,6 +654,8 @@ int OnCalculate(
// MA ...
copiedMAFasts >= limit &&
copiedMASlows >= limit &&
copiedMAUppers >= limit &&
copiedMALowers >= limit &&
//
// SAR ...
copiedSARs >= limit
@@ -675,6 +717,7 @@ bool ValidateInputs()
// MA ...
maFastLength >= 2 &&
maSlowLength >= 2 &&
maBandLength >= 2 &&
maSlowLength > maFastLength &&
//
// SAR ...
@@ -721,6 +764,7 @@ int ExtractMaxLengthOfInputs()
result = MathMax(result, mHCLength);
result = MathMax(result, maFastLength);
result = MathMax(result, maSlowLength);
result = MathMax(result, maBandLength);
//
return result;
@@ -877,6 +921,40 @@ void DefineBuffers()
PlotIndexSetInteger(zigzagBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(zigzagBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
// MA Band ...
//
ENUM_DRAW_TYPE maBandDrawType = showMABand ? DRAW_LINE : DRAW_NONE;
//
// MA Upper Band ...
//
ArraySetAsSeries(maUpperBuffer, true);
SetIndexBuffer(maUpperBufferIndex, maUpperBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(maUpperBufferPlotIndex, PLOT_SHOW_DATA, showMABand);
PlotIndexSetInteger(maUpperBufferPlotIndex, PLOT_DRAW_TYPE, maBandDrawType);
PlotIndexSetInteger(maUpperBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(maUpperBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
// MA Lower Band ...
//
ArraySetAsSeries(maLowerBuffer, true);
SetIndexBuffer(maLowerBufferIndex, maLowerBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(maLowerBufferPlotIndex, PLOT_SHOW_DATA, showMABand);
PlotIndexSetInteger(maLowerBufferPlotIndex, PLOT_DRAW_TYPE, maBandDrawType);
PlotIndexSetInteger(maLowerBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(maLowerBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
// Data Buffers ...
@@ -1097,6 +1175,38 @@ bool InitRequirements()
return result;
}
//
// MA Band Upper ...
maUpperHandler = iMA(
_Symbol,
_Period,
maBandLength,
0,
maMethod,
PRICE_HIGH //
);
result = maUpperHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
// MA Band Lower ...
maLowerHandler = iMA(
_Symbol,
_Period,
maBandLength,
0,
maMethod,
PRICE_LOW //
);
result = maLowerHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
// SAR ...
sarHandler = iSAR(
@@ -36,8 +36,8 @@ class XCXFIMAPOIDetector : public XCBase
public:
//
// Props ...
XCBarAnalyser *barAnalyser; // Bar Analyser ...
XCMarketPatternDetector *patternDetector; // Bar Analyser ...
XCBarAnalyser *barAnalyser; // Bar Analyser ...
XCMarketPatternDetector *patternDetector; // Pattern Detector ...
//
// Constructor ...
@@ -56,7 +56,198 @@ class XCXFIMAPOIDetector : public XCBase
}
//
// Implementing Parren Detector ...
// Actions and Tools ...
/**
* Get Specified Number of Recent ZigZag Points ...
*
* @param bar: XOHCL, Specified Bar for Start ...
* @param fimaHelper: XCXFIMAHelper, instance of XFIMA Helper ...
* @param zigzagPoints: XZigZagPoint, Array of Founded Points ...
* @param numberOfRequiredPoints: int, Specified Number of required ZigZag Points ...
*
* @return ( int )
*/
int GetZigZagPoint(
XOHCL &bar,
XCXFIMAHelper *&fimaHelper,
XZigZagPoint &zigzagPoints[],
int numberOfRequiredPoints = 5 //
)
{
//
int result = 0;
//
// Normalize ...
SpecifiedClean(zigzagPoints);
numberOfRequiredPoints = NormalizeInt(numberOfRequiredPoints, 3);
//
// Validate ...
result = bar.IsValid() &&
bar.symbol == fimaHelper.GetSymbol() &&
bar.period == fimaHelper.GetPeriod();
if (!result)
{
return result;
}
//
// Update Fima Helper ...
int index = bar.Index();
fimaHelper.Update(index);
//
// Start Reading ZigZag Values ...
double iZG = 0;
double iPZG = 0;
int iZGIdx = -1;
int iPZGIdx = -1;
bool has = false;
int start = index;
XZigZagPoint iZGPoint;
datetime iZGTime = NULL;
datetime iPZGTime = NULL;
int lastZGDetected = start;
ENUM_X_DIRECTION iDir = X_DIRECTION_NONE;
ENUM_X_ZIGZAG_POINT_TYPE iType = X_ZIGZAG_POINT_TYPE_NONE;
while (ArraySize(zigzagPoints) < numberOfRequiredPoints)
{
//
// Reading Last two ZigZag Value ...
//
// Detect Last ZG Value ...
has = GetZigZagValue(lastZGDetected, iZG, iZGIdx, iZGTime, fimaHelper);
if (!has)
{
//
iZG = 0;
iPZG = 0;
iZGIdx = -1;
iPZGIdx = -1;
iZGTime = NULL;
iPZGTime = NULL;
iZGPoint.Clean();
iDir = X_DIRECTION_NONE;
iType = X_ZIGZAG_POINT_TYPE_NONE;
//
start++;
lastZGDetected++;
//
continue;
}
//
// Detect Previous ZG Value ...
has = GetZigZagValue(lastZGDetected + 1, iPZG, iPZGIdx, iPZGTime, fimaHelper);
if (!has)
{
//
iZG = 0;
iPZG = 0;
iZGIdx = -1;
iPZGIdx = -1;
iZGTime = NULL;
iPZGTime = NULL;
iZGPoint.Clean();
iDir = X_DIRECTION_NONE;
iType = X_ZIGZAG_POINT_TYPE_NONE;
//
start++;
lastZGDetected++;
//
continue;
}
//
// Check Direction ...
iDir =
(iZG > iPZG)
? X_DIRECTION_BULLISH
: (iZG < iPZG)
? X_DIRECTION_BEARISH
: X_DIRECTION_NONE;
//
// Check Point Type ...
iType =
IsSpecifiedBullish(iDir)
? X_ZIGZAG_POINT_TYPE_PEAK
: IsSpecifiedBearish(iDir)
? X_ZIGZAG_POINT_TYPE_VALE
: X_ZIGZAG_POINT_TYPE_NONE;
has =
IsXValid(iType) &&
HasDirection(iDir);
if (!has)
{
//
iZG = 0;
iPZG = 0;
iZGIdx = -1;
iPZGIdx = -1;
iZGTime = NULL;
iPZGTime = NULL;
iZGPoint.Clean();
iDir = X_DIRECTION_NONE;
iType = X_ZIGZAG_POINT_TYPE_NONE;
//
start++;
lastZGDetected++;
//
continue;
}
//
// Initialize ZigZag Point ...
has = iZGPoint.Init(
iZG,
iZGTime,
bar.symbol,
iDir,
bar.period,
iType //
);
if (has)
{
//
iZGPoint.AddIfNotExists(zigzagPoints);
lastZGDetected = iZGIdx + 1;
}
//
// Reset Resources ...
iZG = 0;
iPZG = 0;
iZGIdx = -1;
iPZGIdx = -1;
iZGTime = NULL;
iPZGTime = NULL;
iZGPoint.Clean();
iDir = X_DIRECTION_NONE;
iType = X_ZIGZAG_POINT_TYPE_NONE;
//
start++;
}
//
result = ArraySize(zigzagPoints);
//
return result;
}
//
// Implementing Patrren Detector ...
/**
* Check Specified Bar is Momentum Bar or not ...
@@ -430,6 +621,106 @@ class XCXFIMAPOIDetector : public XCBase
// Protected ...
protected:
//
// Props ...
//
// Tools / Actions ...
/**
* Read Specified Value of ZigZag ...
*
* @param fromBarIndex: int, Specified Start Bar Index ...
* @param value: double, reference to Hold ZigZag Value ...
* @param index: int, reference to Hold ZigZag Value's Bar Index ...
* @param time: datetime, reference to Hold ZigZag Value's Time ...
* @param maxAllowedLoopback: int, Maximum Allowe Loopback to Detect Specified Point ...
*
* @return ( bool )
*/
bool GetZigZagValue(
int fromBarIndex,
double &value,
int &index,
datetime &time,
XCXFIMAHelper *&fimaHelper,
int maxAllowedLoopback = 100 //
)
{
//
bool result = false;
//
// Normalize ...
fromBarIndex = NormalizeInt(fromBarIndex, 0);
maxAllowedLoopback = NormalizeInt(maxAllowedLoopback, 10, 100);
//
// Prepare ...
value = 0;
index = -1;
time = NULL;
//
// Validate ...
result = fimaHelper != NULL;
if (!result)
{
return result;
}
//
int start = fromBarIndex;
int end = start + maxAllowedLoopback;
while (start < end)
{
//
fimaHelper.Update(start);
//
value = fimaHelper.GetZigZag(start);
result = value > 0 && value != EMPTY_VALUE;
if (result)
{
//
time = GetBarTime(
fimaHelper.GetSymbol(),
fimaHelper.GetPeriod(),
start //
);
//
index = start;
//
break;
}
//
value = 0;
index = -1;
time = NULL;
//
start++;
}
//
result =
value > 0 &&
IsValidIndex(index) &&
value != EMPTY_VALUE &&
IsSpecifiedValid(time);
if (!result)
{
//
value = 0;
index = -1;
time = NULL;
}
//
return result;
}
//
// Private ...
+176 -2
View File
@@ -82,7 +82,9 @@ struct XZigZagPoint
// Props ...
double value; // Value
datetime time; // Time
string symbol; // Symbol
ENUM_X_DIRECTION dir; // Direction
ENUM_TIMEFRAMES period; // Period
ENUM_X_ZIGZAG_POINT_TYPE type; // Type
//
@@ -92,6 +94,52 @@ struct XZigZagPoint
Clean();
}
//
// Init ...
/**
* Initialize Structure ...
*
* @param _value: double, value of point ...
* @param _time: datetime, time of point ...
* @param _symbol: string, Symbol ...
* @param _dir: ENUM_X_DIRECTION, direction of point ...
* @param _period: ENUM_TIMEFRAMES, period ...
* @param _type: ENUM_X_ZIGZAG_POINT_TYPE, point type ...
*
* @return ( bool )
*/
bool Init(
double _value,
datetime _time,
string _symbol,
ENUM_X_DIRECTION _dir,
ENUM_TIMEFRAMES _period,
ENUM_X_ZIGZAG_POINT_TYPE _type //
)
{
//
bool result = false;
//
dir = _dir;
time = _time;
type = _type;
value = _value;
symbol = _symbol;
period = _period;
//
result = IsValid();
if (!result)
{
Clean();
}
//
return result;
}
//
// Tools ...
@@ -103,6 +151,8 @@ struct XZigZagPoint
//
value = 0;
time = NULL;
symbol = NULL;
period = NULL;
dir = X_DIRECTION_NONE;
type = X_ZIGZAG_POINT_TYPE_NONE;
@@ -125,7 +175,9 @@ struct XZigZagPoint
value > 0 &&
IsXValid(type) &&
HasDirection(dir) &&
IsSpecifiedValid(time);
IsSpecifiedValid(time) &&
IsSpecifiedValid(symbol) &&
IsSpecifiedValid(period);
//
return result;
@@ -167,6 +219,128 @@ struct XZigZagPoint
return result;
}
/**
* Check two Struct are Same or not ...
*
* @param item: XZigZagPoint ...
*
* @return ( bool )
*/
bool IsSameAs(XZigZagPoint &item)
{
//
bool result = false;
//
result =
IsValid() &&
item.IsValid() &&
dir == item.dir &&
type == item.type &&
time == item.time &&
value == item.value &&
symbol == item.symbol &&
period == item.period;
//
return result;
}
/**
* Check Structure Exists in Specified Collection or not ...
*
* @param items: XZigZagPoint, reference Array ...
* @param index: int, reference to Holds Founded Index ...
*
* @return ( bool )
*/
bool IsExists(
XZigZagPoint &items[],
int &index //
)
{
//
bool result = false;
//
// Prepare ...
index = -1;
//
// Validate ...
result =
IsValid() &&
HasChild(items);
if (!result)
{
return result;
}
//
int count = ArraySize(items);
for (int i = 0; i < count; i++)
{
//
result = IsSameAs(items[i]);
if (result)
{
//
index = i;
//
break;
}
}
//
result =
result &&
IsValidIndex(index);
//
return result;
}
/**
* Add Structure to Specified Collection only if not Exists ...
*
* @param items: XZigZagPoint, reference Array ...
*/
void AddIfNotExists(XZigZagPoint &items[])
{
//
// Validate ...
if (!IsValid())
{
return;
}
//
if (!HasChild(items))
{
//
AddRef(
this,
items //
);
//
return;
}
//
int index = -1;
bool isExists = IsExists(items, index);
if (!isExists)
{
//
AddRef(
this,
items //
);
}
}
/**
* Extract Specified Token of Struct ...
*
@@ -179,7 +353,7 @@ struct XZigZagPoint
/**
* Represent an String Unique Identifier for Chart Objects ...
*
*
* @return ( string )
*/
string GetObjectID()