Last works ...
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1393,6 +1393,15 @@ class XCXFIMAHelper : public XCBaseHelper
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for Fibo Push Exists or not ...
|
||||
*
|
||||
* @param dir: ENUM_X_DIRECTION, reference to hold result ...
|
||||
* @param barIndex: int, Specified Bar Index ...
|
||||
* @param validationLength: int, Validation Length ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HasFiboPush(
|
||||
ENUM_X_DIRECTION &dir,
|
||||
int barIndex = 0,
|
||||
@@ -2946,6 +2955,236 @@ class XCXFIMAHelper : public XCBaseHelper
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect Zones (Support / Resistance) based on XFIMA Validators ...
|
||||
*
|
||||
* @param zones: XBoxZone, reference to Collection for holding Detected Zones ...
|
||||
* @param barIndex: int, Specified Start Looking Bar Index ...
|
||||
* @param requiredNumberOfZones: int, Specified how many zones looking for ...
|
||||
* @param shadowMultiplier: double, a valid zone's Shadow side multiplier ...
|
||||
* @param maxAllowedLoopbackLength: int, Specified Max Allowed Looping back trhough Bars for Detection ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int DetectXFIMAZones(
|
||||
XBoxZone &zones[],
|
||||
int barIndex = 0,
|
||||
bool onlyValidZones = false,
|
||||
int requiredNumberOfZones = 50,
|
||||
double shadowMultiplier = 4,
|
||||
int validationLength = 7,
|
||||
int maxAllowedLoopbackLength = 1500 //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Prepare ...
|
||||
XClean(zones);
|
||||
|
||||
//
|
||||
// Normalize ...
|
||||
barIndex = NormalizeBarIndex(barIndex);
|
||||
validationLength = NormalizeInt(validationLength, 3);
|
||||
shadowMultiplier = NormalizeDouble(shadowMultiplier, 2);
|
||||
requiredNumberOfZones = NormalizeInt(requiredNumberOfZones, 5);
|
||||
maxAllowedLoopbackLength = NormalizeInt(maxAllowedLoopbackLength, 50);
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
XOHCL bar;
|
||||
bool has = IsValid() &&
|
||||
bar.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
barIndex + 1 //
|
||||
);
|
||||
if (!has)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Requirements ...
|
||||
XOHCL iBar;
|
||||
XBoxZone iBox;
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
double iUpper = EMPTY_VALUE;
|
||||
double iLower = EMPTY_VALUE;
|
||||
double iHKUpper = EMPTY_VALUE;
|
||||
double iHKLower = EMPTY_VALUE;
|
||||
double iMAUpper = EMPTY_VALUE;
|
||||
double iMALower = EMPTY_VALUE;
|
||||
ENUM_X_DIRECTION iDir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
// Create a Loop to Detect Zones ...
|
||||
int start = barIndex;
|
||||
int idx = start - 1;
|
||||
int end = start + maxAllowedLoopbackLength;
|
||||
while (ArraySize(zones) < requiredNumberOfZones && idx < end)
|
||||
{
|
||||
//
|
||||
idx++;
|
||||
|
||||
//
|
||||
// Initialize Indexed Bar ...
|
||||
has = bar.BarAt(idx, iBar);
|
||||
if (!has)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Bars ...
|
||||
iMAUpper = GetMABondUpper(idx);
|
||||
iMALower = GetMABondLower(idx);
|
||||
iHKUpper = GetHKBondUpper(idx);
|
||||
iHKLower = GetHKBondLower(idx);
|
||||
|
||||
//
|
||||
iUpper = MathMax(iMAUpper, iHKUpper);
|
||||
iLower = MathMin(iMALower, iHKLower);
|
||||
|
||||
//
|
||||
// Check Bar State ...
|
||||
has =
|
||||
NotEmptyZero(iUpper) &&
|
||||
NotEmptyZero(iLower);
|
||||
if (!has)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Direction of Zone ...
|
||||
isBullish = iBar.low < iLower;
|
||||
isBearish = iBar.high > iUpper;
|
||||
has = (isBullish && !isBearish) ||
|
||||
(isBearish && !isBullish);
|
||||
if (!has)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Price Based on Bar ...
|
||||
// Validate Shadow Multiplier ...
|
||||
has =
|
||||
isBullish
|
||||
? iBar.low < bar.low
|
||||
: iBar.high > bar.high;
|
||||
has =
|
||||
has &&
|
||||
(isBullish
|
||||
? iBar.GetLowShadow() > iBar.GetHighShadow() * shadowMultiplier
|
||||
: iBar.GetHighShadow() > iBar.GetLowShadow() * shadowMultiplier);
|
||||
if (!has)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
iDir = isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
// Fill Bax ...
|
||||
iBox.dir = iDir;
|
||||
iBox.symbol = mSymbol;
|
||||
iBox.period = mPeriod;
|
||||
iBox.upper =
|
||||
isBullish
|
||||
? iBar.GetDown()
|
||||
: iBar.high;
|
||||
iBox.lower =
|
||||
isBullish
|
||||
? iBar.low
|
||||
: iBar.GetUp();
|
||||
iBox.type =
|
||||
(isBullish ? "XFIMSup" : "XFIMARes") + "_" +
|
||||
ToXString(NormalizePrice(iBox.upper, iBox.symbol)) + "_" +
|
||||
ToXString(NormalizePrice(iBox.lower, iBox.symbol));
|
||||
|
||||
//
|
||||
iBox.at = iBar.time;
|
||||
iBox.to = bar.time;
|
||||
|
||||
//
|
||||
// Loopback to Detect From Time ...
|
||||
XOHCL pBar;
|
||||
datetime fromTime = NULL;
|
||||
has = iBar.GetPreviousBar(pBar);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
while (!IsXValid(fromTime))
|
||||
{
|
||||
//
|
||||
// Check Price Inside ...
|
||||
has =
|
||||
isBullish
|
||||
? pBar.GetDown() < iBox.lower
|
||||
: pBar.GetUp() > iBox.upper;
|
||||
if (has)
|
||||
{
|
||||
fromTime = pBar.time;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve PrevBar ...
|
||||
has = pBar.GetPreviousBar(pBar);
|
||||
if (!has)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
has = IsXValid(fromTime);
|
||||
if (has)
|
||||
{
|
||||
iBox.from = fromTime;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Zone Length ...
|
||||
has = iBox.IsValid() &&
|
||||
(iBox.FromIndex() - iBox.AtIndex() >= validationLength);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
AddIfNotExists(
|
||||
iBox,
|
||||
zones //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
iBar.Clean();
|
||||
pBar.Clean();
|
||||
iBox.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
result = ArraySize(zones);
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
if (!result)
|
||||
{
|
||||
XClean(zones);
|
||||
}
|
||||
iBar.Clean();
|
||||
iBox.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Values Retrievers ...
|
||||
|
||||
|
||||
+194
-57
@@ -83,7 +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 = 21; // Slow MA Length
|
||||
input int maBandLength = 21; // MA Bond Length
|
||||
input int maBondLength = 21; // MA Bond Length
|
||||
input int zigzagDepth = 12; // ZigZag Depth
|
||||
input int zigzagDeviation = 5; // ZigZag Deviation
|
||||
input int zigzagBackStep = 3; // ZigZag Back Step
|
||||
@@ -101,7 +101,7 @@ input bool showHK = true; // Show HK
|
||||
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 Bond
|
||||
input bool showMABond = true; // Show MA Bond
|
||||
input bool showHKBond = true; // Show HK Bond
|
||||
input bool showZigZag = true; // Show ZigZag
|
||||
input bool showFiboZone = true; // Show Fibo Zone
|
||||
@@ -138,8 +138,8 @@ input int valeArrowCode = 159; // Vales Arrow Code
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 40
|
||||
#property indicator_plots 14
|
||||
#property indicator_buffers 44
|
||||
#property indicator_plots 16
|
||||
|
||||
//
|
||||
// Plot Buffers ...
|
||||
@@ -286,9 +286,9 @@ double zigzagBuffer[];
|
||||
// MA Upper ...
|
||||
|
||||
//
|
||||
#define maUpperBufferIndex 12
|
||||
#define maUpperBufferPlotIndex 9
|
||||
double maUpperBuffer[];
|
||||
#define maBondUpperBufferIndex 12
|
||||
#define maBondUpperBufferPlotIndex 9
|
||||
double maBondUpperBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label10 "UpperMA"
|
||||
@@ -300,9 +300,9 @@ double maUpperBuffer[];
|
||||
// MA Lower ...
|
||||
|
||||
//
|
||||
#define maLowerBufferIndex 13
|
||||
#define maLowerBufferPlotIndex 10
|
||||
double maLowerBuffer[];
|
||||
#define maBondLowerBufferIndex 13
|
||||
#define maBondLowerBufferPlotIndex 10
|
||||
double maBondLowerBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label11 "LowerMA"
|
||||
@@ -361,11 +361,39 @@ double hkBondLowerBuffer[];
|
||||
#property indicator_color14 clrMagenta
|
||||
#property indicator_width14 3
|
||||
|
||||
//
|
||||
// PB Upper ...
|
||||
|
||||
//
|
||||
#define pbBondUpperBufferIndex 21
|
||||
double pbBondUpperBuffer[];
|
||||
|
||||
//
|
||||
#define pbBondUpperBufferPlotIndex 14
|
||||
#property indicator_label15 "UpperPB"
|
||||
#property indicator_type15 DRAW_LINE
|
||||
#property indicator_color15 clrRoyalBlue
|
||||
#property indicator_width15 3
|
||||
|
||||
//
|
||||
// PB Lower ...
|
||||
|
||||
//
|
||||
#define pbBondLowerBufferIndex 22
|
||||
double pbBondLowerBuffer[];
|
||||
|
||||
//
|
||||
#define pbBondLowerBufferPlotIndex 15
|
||||
#property indicator_label16 "LowerPB"
|
||||
#property indicator_type16 DRAW_LINE
|
||||
#property indicator_color16 clrOrangeRed
|
||||
#property indicator_width16 3
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
#define mLastBufferIndex 20
|
||||
#define mLastBufferIndex 22
|
||||
|
||||
//
|
||||
// MA ...
|
||||
@@ -470,6 +498,17 @@ double hkRawLowBuffer[];
|
||||
#define hkRawCloseBufferIndex mLastBufferIndex + 19
|
||||
double hkRawCloseBuffer[];
|
||||
|
||||
//
|
||||
// XPB Data ...
|
||||
|
||||
//
|
||||
#define pbBondRawUpperBufferIndex mLastBufferIndex + 20
|
||||
double pbBondRawUpperBuffer[];
|
||||
|
||||
//
|
||||
#define pbBondRawLowerBufferIndex mLastBufferIndex + 21
|
||||
double pbBondRawLowerBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
@@ -529,6 +568,9 @@ datetime lastZigZagPeakTime = NULL;
|
||||
double lastZigZagVale = 0;
|
||||
datetime lastZigZagValeTime = NULL;
|
||||
|
||||
//
|
||||
ENUM_X_MA_METHOD iPBMethod = X_MA_MODE_NONE;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
@@ -550,6 +592,10 @@ int OnInit()
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Price Buffer Smoothing Method ...
|
||||
iPBMethod = ToXMaMethod(maMethod);
|
||||
|
||||
//
|
||||
has = InitCycles();
|
||||
if (!has)
|
||||
@@ -723,8 +769,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);
|
||||
int copiedMAUppers = CopyBuffer(maUpperHandler, MAIN_LINE, 0, limit, maBondUpperBuffer);
|
||||
int copiedMALowers = CopyBuffer(maLowerHandler, MAIN_LINE, 0, limit, maBondLowerBuffer);
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
@@ -800,7 +846,7 @@ bool ValidateInputs()
|
||||
// MA ...
|
||||
maFastLength >= 2 &&
|
||||
maSlowLength >= 2 &&
|
||||
maBandLength >= 2 &&
|
||||
maBondLength >= 2 &&
|
||||
maSlowLength > maFastLength &&
|
||||
//
|
||||
// SAR ...
|
||||
@@ -847,7 +893,7 @@ int ExtractMaxLengthOfInputs()
|
||||
result = MathMax(result, mHCLength);
|
||||
result = MathMax(result, maFastLength);
|
||||
result = MathMax(result, maSlowLength);
|
||||
result = MathMax(result, maBandLength);
|
||||
result = MathMax(result, maBondLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -873,10 +919,6 @@ void DefineBuffers()
|
||||
ArraySetAsSeries(maFastColorBuffer, true);
|
||||
SetIndexBuffer(maFastColorBufferIndex, maFastColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(maFastStateBuffer, true);
|
||||
SetIndexBuffer(maFastStateBufferIndex, maFastStateBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Slow MA ...
|
||||
|
||||
@@ -892,10 +934,6 @@ void DefineBuffers()
|
||||
ArraySetAsSeries(maSlowColorBuffer, true);
|
||||
SetIndexBuffer(maSlowColorBufferIndex, maSlowColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(maSlowStateBuffer, true);
|
||||
SetIndexBuffer(maSlowStateBufferIndex, maSlowStateBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
|
||||
@@ -912,10 +950,6 @@ void DefineBuffers()
|
||||
ArraySetAsSeries(sarColorBuffer, true);
|
||||
SetIndexBuffer(sarColorBufferIndex, sarColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(sarStateBuffer, true);
|
||||
SetIndexBuffer(sarStateBufferIndex, sarStateBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// PEAK / VALE ...
|
||||
|
||||
@@ -1008,35 +1042,60 @@ void DefineBuffers()
|
||||
// MA Bond ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE maBandDrawType = showMABand ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE maBondDrawType = showMABond ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
// MA Upper Bond ...
|
||||
// Upper Bond ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(maUpperBuffer, true);
|
||||
SetIndexBuffer(maUpperBufferIndex, maUpperBuffer, INDICATOR_DATA);
|
||||
ArraySetAsSeries(maBondUpperBuffer, true);
|
||||
SetIndexBuffer(maBondUpperBufferIndex, maBondUpperBuffer, 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);
|
||||
PlotIndexSetInteger(maBondUpperBufferPlotIndex, PLOT_SHOW_DATA, showMABond);
|
||||
PlotIndexSetInteger(maBondUpperBufferPlotIndex, PLOT_DRAW_TYPE, maBondDrawType);
|
||||
PlotIndexSetInteger(maBondUpperBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetDouble(maBondUpperBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
// MA Lower Bond ...
|
||||
// Lower Bond ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(maLowerBuffer, true);
|
||||
SetIndexBuffer(maLowerBufferIndex, maLowerBuffer, INDICATOR_DATA);
|
||||
ArraySetAsSeries(maBondLowerBuffer, true);
|
||||
SetIndexBuffer(maBondLowerBufferIndex, maBondLowerBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(maLowerBufferPlotIndex, PLOT_SHOW_DATA, showMABand);
|
||||
PlotIndexSetInteger(maLowerBufferPlotIndex, PLOT_DRAW_TYPE, maBandDrawType);
|
||||
PlotIndexSetInteger(maBondLowerBufferPlotIndex, PLOT_SHOW_DATA, showMABond);
|
||||
PlotIndexSetInteger(maBondLowerBufferPlotIndex, PLOT_DRAW_TYPE, maBondDrawType);
|
||||
PlotIndexSetInteger(maBondLowerBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetDouble(maBondLowerBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
PlotIndexSetInteger(maLowerBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetDouble(maLowerBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
//
|
||||
// XPB Bond ...
|
||||
|
||||
//
|
||||
// Upper Bond ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(pbBondUpperBuffer, true);
|
||||
SetIndexBuffer(pbBondUpperBufferIndex, pbBondUpperBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(pbBondUpperBufferPlotIndex, PLOT_SHOW_DATA, showMABond);
|
||||
PlotIndexSetInteger(pbBondUpperBufferPlotIndex, PLOT_DRAW_TYPE, maBondDrawType);
|
||||
PlotIndexSetDouble(pbBondUpperBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
|
||||
//
|
||||
// Lower Bond ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(pbBondLowerBuffer, true);
|
||||
SetIndexBuffer(pbBondLowerBufferIndex, pbBondLowerBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(pbBondLowerBufferPlotIndex, PLOT_SHOW_DATA, showMABond);
|
||||
PlotIndexSetInteger(pbBondLowerBufferPlotIndex, PLOT_DRAW_TYPE, maBondDrawType);
|
||||
PlotIndexSetDouble(pbBondLowerBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
|
||||
//
|
||||
// XHK ...
|
||||
@@ -1073,20 +1132,44 @@ void DefineBuffers()
|
||||
|
||||
//
|
||||
// XHK Bond ...
|
||||
//
|
||||
ENUM_DRAW_TYPE hkBondDrawType = showHKBond ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Upper ...
|
||||
ArraySetAsSeries(hkBondUpperBuffer, true);
|
||||
SetIndexBuffer(hkBondUpperBufferIndex, hkBondUpperBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(hkBondUpperBufferPlotIndex, PLOT_SHOW_DATA, showHKBond);
|
||||
PlotIndexSetInteger(hkBondUpperBufferPlotIndex, PLOT_DRAW_TYPE, hkBondDrawType);
|
||||
PlotIndexSetDouble(hkBondUpperBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
|
||||
//
|
||||
// Lower ...
|
||||
ArraySetAsSeries(hkBondLowerBuffer, true);
|
||||
SetIndexBuffer(hkBondLowerBufferIndex, hkBondLowerBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(hkBondLowerBufferPlotIndex, PLOT_SHOW_DATA, showHKBond);
|
||||
PlotIndexSetInteger(hkBondLowerBufferPlotIndex, PLOT_DRAW_TYPE, hkBondDrawType);
|
||||
PlotIndexSetDouble(hkBondLowerBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(maFastStateBuffer, true);
|
||||
SetIndexBuffer(maFastStateBufferIndex, maFastStateBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(maSlowStateBuffer, true);
|
||||
SetIndexBuffer(maSlowStateBufferIndex, maSlowStateBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(sarStateBuffer, true);
|
||||
SetIndexBuffer(sarStateBufferIndex, sarStateBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// CYCLES ...
|
||||
|
||||
@@ -1095,44 +1178,44 @@ void DefineBuffers()
|
||||
|
||||
//
|
||||
ArraySetAsSeries(sHHBuffer, true);
|
||||
SetIndexBuffer(sHHBufferIndex, sHHBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(sHHBufferIndex, sHHBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(sLLBuffer, true);
|
||||
SetIndexBuffer(sLLBufferIndex, sLLBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(sLLBufferIndex, sLLBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// MC ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(mHHBuffer, true);
|
||||
SetIndexBuffer(mHHBufferIndex, mHHBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(mHHBufferIndex, mHHBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(mLLBuffer, true);
|
||||
SetIndexBuffer(mLLBufferIndex, mLLBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(mLLBufferIndex, mLLBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// LC ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(lHHBuffer, true);
|
||||
SetIndexBuffer(lHHBufferIndex, lHHBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(lHHBufferIndex, lHHBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(lLLBuffer, true);
|
||||
SetIndexBuffer(lLLBufferIndex, lLLBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(lLLBufferIndex, lLLBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// HC ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(hHHBuffer, true);
|
||||
SetIndexBuffer(hHHBufferIndex, hHHBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(hHHBufferIndex, hHHBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(hLLBuffer, true);
|
||||
SetIndexBuffer(hLLBufferIndex, hLLBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(hLLBufferIndex, hLLBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Highs ...
|
||||
@@ -1149,19 +1232,30 @@ void DefineBuffers()
|
||||
|
||||
//
|
||||
ArraySetAsSeries(hkRawHighBuffer, true);
|
||||
SetIndexBuffer(hkRawHighBufferIndex, hkRawHighBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(hkRawHighBufferIndex, hkRawHighBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(hkRawOpenBuffer, true);
|
||||
SetIndexBuffer(hkRawOpenBufferIndex, hkRawOpenBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(hkRawOpenBufferIndex, hkRawOpenBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(hkRawLowBuffer, true);
|
||||
SetIndexBuffer(hkRawLowBufferIndex, hkRawLowBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(hkRawLowBufferIndex, hkRawLowBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(hkRawCloseBuffer, true);
|
||||
SetIndexBuffer(hkRawCloseBufferIndex, hkRawCloseBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(hkRawCloseBufferIndex, hkRawCloseBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// XPB Data ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(pbBondRawUpperBuffer, true);
|
||||
SetIndexBuffer(pbBondRawUpperBufferIndex, pbBondRawUpperBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(pbBondRawLowerBuffer, true);
|
||||
SetIndexBuffer(pbBondRawLowerBufferIndex, pbBondRawLowerBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
}
|
||||
@@ -1328,7 +1422,7 @@ bool InitRequirements()
|
||||
maUpperHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
maBandLength,
|
||||
maBondLength,
|
||||
0,
|
||||
maMethod,
|
||||
PRICE_HIGH //
|
||||
@@ -1344,7 +1438,7 @@ bool InitRequirements()
|
||||
maLowerHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
maBandLength,
|
||||
maBondLength,
|
||||
0,
|
||||
maMethod,
|
||||
PRICE_LOW //
|
||||
@@ -1615,6 +1709,49 @@ void CalculateValues(
|
||||
fiboUpperBuffer[barIndex] = iFiboUp;
|
||||
fiboMiddleBuffer[barIndex] = iFiboMid;
|
||||
fiboLowerBuffer[barIndex] = iFiboLo;
|
||||
|
||||
//
|
||||
// XPB ...
|
||||
|
||||
//
|
||||
double iPBUpper = MathMax(close[barIndex], open[barIndex]);
|
||||
double iPBLower = MathMin(close[barIndex], open[barIndex]);
|
||||
|
||||
//
|
||||
pbBondUpperBuffer[barIndex] = iPBUpper;
|
||||
pbBondRawUpperBuffer[barIndex] = iPBUpper;
|
||||
|
||||
//
|
||||
pbBondLowerBuffer[barIndex] = iPBLower;
|
||||
pbBondRawLowerBuffer[barIndex] = iPBLower;
|
||||
|
||||
//
|
||||
if (IsXValid(iPBMethod) && maBondLength > 0)
|
||||
{
|
||||
//
|
||||
// XPB Upper ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
barIndex,
|
||||
maBondLength,
|
||||
pbBondRawUpperBuffer,
|
||||
pbBondUpperBuffer,
|
||||
iPBMethod //
|
||||
);
|
||||
|
||||
//
|
||||
// XPB Lower ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
barIndex,
|
||||
maBondLength,
|
||||
pbBondRawLowerBuffer,
|
||||
pbBondLowerBuffer,
|
||||
iPBMethod //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -1361,6 +1361,80 @@ string ToXString(ENUM_X_MA_METHOD value)
|
||||
return ToString(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts MA Method ...
|
||||
**/
|
||||
ENUM_MA_METHOD ToXMaMethod(ENUM_X_MA_METHOD value)
|
||||
{
|
||||
//
|
||||
ENUM_MA_METHOD result = MODE_SMA;
|
||||
|
||||
//
|
||||
if (!IsXValid(value))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
switch (value)
|
||||
{
|
||||
//
|
||||
case X_MA_MODE_EMA:
|
||||
result = MODE_EMA;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_MA_MODE_SMA:
|
||||
result = MODE_SMA;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_MA_MODE_LWMA:
|
||||
result = MODE_LWMA;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_MA_MODE_SMMA:
|
||||
result = MODE_SMMA;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
ENUM_X_MA_METHOD ToXMaMethod(ENUM_MA_METHOD value)
|
||||
{
|
||||
//
|
||||
ENUM_X_MA_METHOD result = X_MA_MODE_NONE;
|
||||
|
||||
//
|
||||
switch (value)
|
||||
{
|
||||
//
|
||||
case MODE_EMA:
|
||||
result = X_MA_MODE_EMA;
|
||||
break;
|
||||
|
||||
//
|
||||
case MODE_SMA:
|
||||
result = X_MA_MODE_SMA;
|
||||
break;
|
||||
|
||||
//
|
||||
case MODE_LWMA:
|
||||
result = X_MA_MODE_LWMA;
|
||||
break;
|
||||
|
||||
//
|
||||
case MODE_SMMA:
|
||||
result = X_MA_MODE_SMMA;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Ma Methods ...
|
||||
//
|
||||
|
||||
@@ -946,6 +946,77 @@ struct XBoxZone
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* At Bar Index ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int AtIndex(
|
||||
ENUM_TIMEFRAMES forPeriod = NULL //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
if (!IsValid() || !IsXValid(at))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (!IsSpecifiedValid(forPeriod))
|
||||
{
|
||||
forPeriod = period;
|
||||
}
|
||||
|
||||
//
|
||||
result = GetBarIndex(
|
||||
symbol,
|
||||
forPeriod,
|
||||
at //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve At Bar ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool AtBar(XOHCL &bar)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bar.Clean();
|
||||
|
||||
//
|
||||
int idx = AtIndex();
|
||||
|
||||
//
|
||||
result =
|
||||
IsValid() &&
|
||||
IsValidIndex(idx);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = bar.Init(
|
||||
symbol,
|
||||
period,
|
||||
idx //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* From Bar Index ...
|
||||
*
|
||||
|
||||
@@ -639,20 +639,49 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
||||
//
|
||||
// Detecte Fibo Section Changes ...
|
||||
|
||||
//
|
||||
has = fimaHelper.IsFiboSectionChanged(iDir, iBar.Index());
|
||||
has = has &&
|
||||
IsXBullish(iDir) &&
|
||||
fimaHelper.IsValeOverLast(iBar.Index());
|
||||
// //
|
||||
// has = fimaHelper.IsFiboSectionChanged(iDir, iBar.Index());
|
||||
// has = has &&
|
||||
// IsXBullish(iDir) &&
|
||||
// fimaHelper.IsValeOverLast(iBar.Index());
|
||||
|
||||
// //
|
||||
// has = fimaHelper.IsFiboSectionChanged(iDir, iBar.Index());
|
||||
// has = has &&
|
||||
// IsXBearish(iDir) &&
|
||||
// fimaHelper.IsPeakUnderLast(iBar.Index());
|
||||
|
||||
// //
|
||||
// has = fimaHelper.HasFiboPush(iDir, iBar.Index(), 5);
|
||||
|
||||
//
|
||||
has = fimaHelper.IsFiboSectionChanged(iDir, iBar.Index());
|
||||
has = has &&
|
||||
IsXBearish(iDir) &&
|
||||
fimaHelper.IsPeakUnderLast(iBar.Index());
|
||||
|
||||
//
|
||||
has = fimaHelper.HasFiboPush(iDir, iBar.Index(), 5);
|
||||
XBoxZone fimaZones[];
|
||||
int fimaZonesCount = fimaHelper.DetectXFIMAZones(
|
||||
fimaZones,
|
||||
iBar.Index(),
|
||||
true, // Only Valid Zones ...
|
||||
50, // Number of Zones ...
|
||||
5, // Shadow Multiplier ...
|
||||
500 // Loopback
|
||||
);
|
||||
has = IsValidSize(fimaZonesCount);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Draw Detected Zones ...
|
||||
CArrayObj zoneObjects;
|
||||
for (int i = 0; i < fimaZonesCount; i++)
|
||||
{
|
||||
//
|
||||
XCBoxObject *iObj;
|
||||
has = poiDrawer.DrawBox(
|
||||
fimaZones[i],
|
||||
iObj,
|
||||
false, // Ignore At ...
|
||||
fimaZones[i].type // Specified Name ...
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (has)
|
||||
|
||||
@@ -476,138 +476,6 @@ class XCXFIMAPOIDetector : public XCMarketPatternDetector
|
||||
return result;
|
||||
}
|
||||
|
||||
int ExtractXFIMAZones(
|
||||
XBoxZone &zones[],
|
||||
int barIndex = 0,
|
||||
int requiredNumberOfZones = 50,
|
||||
double shadowMultiplier = 4,
|
||||
int maxAllowedLoopbackLength = 1500 //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Prepare ...
|
||||
XClean(zones);
|
||||
|
||||
//
|
||||
// Normalize ...
|
||||
barIndex = NormalizeInt(barIndex, 0);
|
||||
shadowMultiplier = NormalizeDouble(shadowMultiplier, 2);
|
||||
requiredNumberOfZones = NormalizeInt(requiredNumberOfZones, 5);
|
||||
maxAllowedLoopbackLength = NormalizeInt(maxAllowedLoopbackLength, 50);
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool has =
|
||||
fimaHelper != NULL &&
|
||||
fimaHelper.IsValid();
|
||||
if (!has)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Create a Loop ...
|
||||
XOHCL iBar;
|
||||
XBoxZone iBox;
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
double iUpper = EMPTY_VALUE;
|
||||
double iLower = EMPTY_VALUE;
|
||||
double iHKUpper = EMPTY_VALUE;
|
||||
double iHKLower = EMPTY_VALUE;
|
||||
double iMAUpper = EMPTY_VALUE;
|
||||
double iMALower = EMPTY_VALUE;
|
||||
string symbol = fimaHelper.GetSymbol();
|
||||
ENUM_X_DIRECTION iDir = X_DIRECTION_NONE;
|
||||
ENUM_TIMEFRAMES period = fimaHelper.GetPeriod();
|
||||
|
||||
//
|
||||
int start = barIndex;
|
||||
int idx = start - 1;
|
||||
int end = start + maxAllowedLoopbackLength;
|
||||
while (ArraySize(zones) < requiredNumberOfZones && idx < end)
|
||||
{
|
||||
//
|
||||
idx++;
|
||||
|
||||
//
|
||||
// Initialize Indexed Bar ...
|
||||
has = iBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
idx //
|
||||
);
|
||||
if (!has)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Bars ...
|
||||
iMAUpper = fimaHelper.GetMABondUpper(idx);
|
||||
iMALower = fimaHelper.GetMABondLower(idx);
|
||||
iHKUpper = fimaHelper.GetHKBondUpper(idx);
|
||||
iHKLower = fimaHelper.GetHKBondLower(idx);
|
||||
|
||||
//
|
||||
iUpper = MathMax(iMAUpper, iHKUpper);
|
||||
iLower = MathMin(iMALower, iHKLower);
|
||||
|
||||
//
|
||||
// Check Bar State ...
|
||||
has =
|
||||
NotEmptyZero(iUpper) &&
|
||||
NotEmptyZero(iLower);
|
||||
if (!has)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Direction of Zone ...
|
||||
isBullish = iBar.low < iLower;
|
||||
isBearish = iBar.high > iUpper;
|
||||
has = (isBullish && !isBearish) ||
|
||||
(isBearish && !isBullish);
|
||||
if (!has)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Shadow Multiplier ...
|
||||
has =
|
||||
isBullish
|
||||
? iBar.GetLowShadow() > iBar.GetHighShadow() * shadowMultiplier
|
||||
: iBar.GetHighShadow() > iBar.GetLowShadow() * shadowMultiplier;
|
||||
if (!has)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
iDir = isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
iBar.Clean();
|
||||
iBox.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
result = ArraySize(zones);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy ...
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user