last ...
This commit is contained in:
@@ -519,6 +519,656 @@ class XC121SMCCycleHelper : public XCBase
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DetectMarketStructure(
|
||||
ENUM_X_DIRECTION &dir //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
dir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
int barIndex = 0;
|
||||
|
||||
//
|
||||
string symbol = GetSymbol();
|
||||
ENUM_TIMEFRAMES period = GetPeriod();
|
||||
|
||||
//
|
||||
int highestPeakIndex = -1;
|
||||
double highestPeakVale = 0;
|
||||
double highestPeak = mX121Helper
|
||||
.GetHighestPeak(
|
||||
barIndex,
|
||||
highestPeakIndex,
|
||||
highestPeakVale //
|
||||
);
|
||||
|
||||
//
|
||||
int lowestValeIndex = -1;
|
||||
double lowestValePeak = 0;
|
||||
double lowestVale = mX121Helper
|
||||
.GetLowestVale(
|
||||
barIndex,
|
||||
lowestValeIndex,
|
||||
lowestValePeak //
|
||||
);
|
||||
|
||||
//
|
||||
result = IsValidIndex(highestPeakIndex) &&
|
||||
IsValidIndex(lowestValeIndex);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
dir =
|
||||
highestPeakIndex < lowestValeIndex
|
||||
? X_DIRECTION_BEARISH
|
||||
: highestPeakIndex > lowestValeIndex
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
result = HasDirection(dir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool isBullish = IsBullish(dir);
|
||||
|
||||
//
|
||||
// Looking for Change Of Character Proved ...
|
||||
|
||||
//
|
||||
// Bullish Bias:
|
||||
// - Price Must Break Up Lowst Vale's Peak;
|
||||
// - Create a Vale Above Lowest Vale's Peak;
|
||||
|
||||
//
|
||||
// Bearish Bias:
|
||||
// - Price Must Breake Down HighestPeak's Vale;
|
||||
// - Create a Peak Under Highest Peak's Vale;
|
||||
|
||||
//
|
||||
// Checking Peak Breake Up ...
|
||||
int lowestValePeakBreakeUpIndex = -1;
|
||||
for (int i = lowestValeIndex; i >= barIndex; i--)
|
||||
{
|
||||
//
|
||||
XOHCL iBar;
|
||||
result = GetBar(iBar, i);
|
||||
if (!result)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
bool isBreake = iBar.IsBreakeUp(lowestValePeak);
|
||||
if (isBreake)
|
||||
{
|
||||
//
|
||||
lowestValePeakBreakeUpIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
bool isValidBreakeUpLowestValePeak = IsValidIndex(lowestValePeakBreakeUpIndex) &&
|
||||
lowestValePeakBreakeUpIndex <= lowestValeIndex;
|
||||
|
||||
//
|
||||
// Checking Vale Breake Down ...
|
||||
int highestPeakValeBreakeDownIndex = -1;
|
||||
for (int i = highestPeakIndex; i >= barIndex; i--)
|
||||
{
|
||||
//
|
||||
XOHCL iBar;
|
||||
result = GetBar(iBar, i);
|
||||
if (!result)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
bool isBreake = iBar.IsBreakeDown(highestPeakVale);
|
||||
if (isBreake)
|
||||
{
|
||||
//
|
||||
highestPeakValeBreakeDownIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
bool isValidBreakeDownHighestPeakVale = IsValidIndex(highestPeakValeBreakeDownIndex) &&
|
||||
highestPeakValeBreakeDownIndex <= highestPeakIndex;
|
||||
//
|
||||
result = isBullish
|
||||
? isValidBreakeUpLowestValePeak
|
||||
: isValidBreakeDownHighestPeakVale;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Checking Create a Vale above Peak ...
|
||||
int valeAboveLowestValePeakIndex = -1;
|
||||
double valeAboveLowestValePeakPeak = 0;
|
||||
for (int i = lowestValePeakBreakeUpIndex; i >= barIndex; i--)
|
||||
{
|
||||
//
|
||||
double iVale = mX121Helper.GetVale(i);
|
||||
|
||||
//
|
||||
bool isValid =
|
||||
iVale > 0 &&
|
||||
iVale > lowestValePeak;
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
valeAboveLowestValePeakIndex = i;
|
||||
valeAboveLowestValePeakPeak = mX121Helper.GetPeak(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
bool isValidValeAboveLowestValePeak = IsValidIndex(valeAboveLowestValePeakIndex) &&
|
||||
valeAboveLowestValePeakIndex < lowestValePeakBreakeUpIndex;
|
||||
|
||||
//
|
||||
// Checking Create a Peak below Vale ...
|
||||
int peakBelowHighestPeakValeIndex = -1;
|
||||
double peakBelowHighestPeakValeVale = 0;
|
||||
for (int i = highestPeakValeBreakeDownIndex; i >= barIndex; i--)
|
||||
{
|
||||
//
|
||||
double iPeak = mX121Helper.GetPeak(i);
|
||||
|
||||
//
|
||||
bool isValid =
|
||||
iPeak > 0 &&
|
||||
iPeak < highestPeakVale;
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
peakBelowHighestPeakValeIndex = i;
|
||||
peakBelowHighestPeakValeVale = mX121Helper.GetVale(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
bool isValidPeakBelowHighestPeakVale = IsValidIndex(peakBelowHighestPeakValeIndex) &&
|
||||
peakBelowHighestPeakValeIndex < highestPeakValeBreakeDownIndex;
|
||||
|
||||
//
|
||||
result = isBullish ? isValidValeAboveLowestValePeak
|
||||
: isValidPeakBelowHighestPeakVale;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Now we Have to Detect Valid Peaks and Valid Vales Here ...
|
||||
// based on Detected Range ...
|
||||
|
||||
//
|
||||
XPVPivotPoint vales[];
|
||||
XPVPivotPoint peaks[];
|
||||
XPVPivotPoint iPeakPoint;
|
||||
XPVPivotPoint iValePoint;
|
||||
XPriceZones peakPriceZone;
|
||||
XPriceZones valePriceZone;
|
||||
XPriceZones peakPriceZones[];
|
||||
XPriceZones valePriceZones[];
|
||||
|
||||
//
|
||||
XPOIState state;
|
||||
mPOIDetector.GetState(
|
||||
state //
|
||||
);
|
||||
|
||||
//
|
||||
int minRepetition = 5; // ValidPivotRepetition();
|
||||
|
||||
//
|
||||
int from =
|
||||
isBullish
|
||||
? valeAboveLowestValePeakIndex
|
||||
: peakBelowHighestPeakValeIndex;
|
||||
for (int i = from; i >= barIndex; i--)
|
||||
{
|
||||
//
|
||||
XOHCL iBar;
|
||||
bool isInited = GetBar(iBar, i);
|
||||
|
||||
//
|
||||
double iPeak = mX121Helper.GetPeak(i);
|
||||
double iVale = mX121Helper.GetVale(i);
|
||||
|
||||
//
|
||||
bool hasPeakPriceInsideZone = CalculatePriceInsideZones(
|
||||
peakPriceZone,
|
||||
state,
|
||||
iPeak //
|
||||
);
|
||||
bool hasValePriceInsideZone = CalculatePriceInsideZones(
|
||||
valePriceZone,
|
||||
state,
|
||||
iVale //
|
||||
);
|
||||
|
||||
//
|
||||
if (hasPeakPriceInsideZone)
|
||||
{
|
||||
//
|
||||
// Peak ...
|
||||
if (!iPeakPoint.IsValid())
|
||||
{
|
||||
//
|
||||
// Initialization ...
|
||||
iPeakPoint.value = iPeak;
|
||||
iPeakPoint.repetition = 1;
|
||||
iPeakPoint.type = XPV_PEAK;
|
||||
iPeakPoint.time = iBar.time;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
if (iPeakPoint.value == iPeak)
|
||||
{
|
||||
iPeakPoint.repetition++;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
if (iPeakPoint.repetition > minRepetition)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
iPeakPoint,
|
||||
peaks //
|
||||
);
|
||||
|
||||
//
|
||||
AddRef(
|
||||
peakPriceZone,
|
||||
peakPriceZones //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
iPeakPoint.Clean();
|
||||
peakPriceZone.Clean();
|
||||
iPeakPoint.value = iPeak;
|
||||
iPeakPoint.repetition = 1;
|
||||
iPeakPoint.type = XPV_PEAK;
|
||||
iPeakPoint.time = iBar.time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (hasValePriceInsideZone)
|
||||
{
|
||||
//
|
||||
// Vale ...
|
||||
if (!iValePoint.IsValid())
|
||||
{
|
||||
//
|
||||
// Initialization ...
|
||||
iValePoint.value = iVale;
|
||||
iValePoint.repetition = 1;
|
||||
iValePoint.type = XPV_VALE;
|
||||
iValePoint.time = iBar.time;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
if (iValePoint.value == iVale)
|
||||
{
|
||||
iValePoint.repetition++;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
if (iValePoint.repetition > minRepetition)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
iValePoint,
|
||||
vales //
|
||||
);
|
||||
|
||||
//
|
||||
AddRef(
|
||||
valePriceZone,
|
||||
valePriceZones //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
iValePoint.Clean();
|
||||
valePriceZone.Clean();
|
||||
iValePoint.value = iVale;
|
||||
iValePoint.repetition = 1;
|
||||
iValePoint.type = XPV_VALE;
|
||||
iValePoint.time = iBar.time;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// in Bullish Bias we Looking for Vales Oder ...
|
||||
// in Bearish Bias we Looking for Peaks Oder ...
|
||||
|
||||
//
|
||||
// Draw ...
|
||||
XCBaseObject *drawnObjects[];
|
||||
|
||||
//
|
||||
// Bearish Bias ...
|
||||
if (isBullish)
|
||||
{
|
||||
//
|
||||
// Draw Lowest Vale Bar ...
|
||||
XOHCL lowestValeBar;
|
||||
result = GetBar(
|
||||
lowestValeBar,
|
||||
lowestValeIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
XCOHCLObject *iLowestValeBarObj;
|
||||
bool isCreated = mPOIDetector.mDrawer.CreateBar(
|
||||
lowestValeBar,
|
||||
iLowestValeBarObj,
|
||||
TimeCurrent() //
|
||||
);
|
||||
if (isCreated)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
(XCBaseObject *)iLowestValeBarObj,
|
||||
drawnObjects //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Lowest Vale Peak Breaker Bar ...
|
||||
XOHCL lowestValePeakBreakeUpBar;
|
||||
if (isValidBreakeUpLowestValePeak)
|
||||
{
|
||||
//
|
||||
result = GetBar(
|
||||
lowestValePeakBreakeUpBar,
|
||||
lowestValePeakBreakeUpIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XCOHCLObject *iObj;
|
||||
bool isCreated = mPOIDetector.mDrawer.CreateBar(
|
||||
lowestValePeakBreakeUpBar,
|
||||
iObj,
|
||||
TimeCurrent() //
|
||||
);
|
||||
if (isCreated)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
(XCBaseObject *)iObj,
|
||||
drawnObjects //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Vale Above Lowest Vale Peak ...
|
||||
XOHCL valeAboveLowestValePeakBar;
|
||||
if (isValidValeAboveLowestValePeak)
|
||||
{
|
||||
//
|
||||
result = GetBar(valeAboveLowestValePeakBar,
|
||||
valeAboveLowestValePeakIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XCOHCLObject *iObj;
|
||||
bool isCreated = mPOIDetector.mDrawer.CreateBar(
|
||||
valeAboveLowestValePeakBar,
|
||||
iObj,
|
||||
TimeCurrent() //
|
||||
);
|
||||
if (isCreated)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
(XCBaseObject *)iObj,
|
||||
drawnObjects //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Vales ...
|
||||
int valesCount = ArraySize(vales);
|
||||
if (IsValidSize(valesCount))
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < valesCount; i++)
|
||||
{
|
||||
//
|
||||
iValePoint = vales[i];
|
||||
|
||||
//
|
||||
CChartObjectTrend *iValeObj;
|
||||
iValeObj = new CChartObjectTrend();
|
||||
|
||||
//
|
||||
string iValeName = "XVALE_" + ToString(iValePoint.value);
|
||||
|
||||
//
|
||||
long chartID = mPOIDetector.mDrawer.ChartIdentification();
|
||||
int window = mPOIDetector.mDrawer.SubWindowIdentification();
|
||||
|
||||
//
|
||||
bool isCreate = iValeObj.Create(
|
||||
chartID,
|
||||
iValeName,
|
||||
window,
|
||||
iValePoint.time,
|
||||
iValePoint.value,
|
||||
TimeCurrent(),
|
||||
iValePoint.value //
|
||||
);
|
||||
if (isCreated)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Price Zone ...
|
||||
valesCount = ArraySize(valePriceZones);
|
||||
if (IsValidSize(valesCount))
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < valesCount; i++)
|
||||
{
|
||||
//
|
||||
XPriceZones iZone = valePriceZones[i];
|
||||
|
||||
//
|
||||
bool hasSupport = iZone.HasSupportZone();
|
||||
if (hasSupport)
|
||||
{
|
||||
//
|
||||
XCSupportZoneObject *iObj;
|
||||
bool isCreated = mPOIDetector.mDrawer.CreateSupportZone(
|
||||
iZone.supportZone,
|
||||
iObj //
|
||||
);
|
||||
if (isCreated)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
(XCBaseObject *)iObj,
|
||||
drawnObjects //
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Bullish Bias Drawn ...
|
||||
if (!isBullish)
|
||||
{
|
||||
//
|
||||
// Draw Highest Peak Bar ...
|
||||
XOHCL highestPeakBar;
|
||||
result = GetBar(
|
||||
highestPeakBar,
|
||||
highestPeakIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
XCOHCLObject *iHighestPeakBarObj;
|
||||
bool isCreated = mPOIDetector.mDrawer.CreateBar(
|
||||
highestPeakBar,
|
||||
iHighestPeakBarObj,
|
||||
TimeCurrent() //
|
||||
);
|
||||
if (isCreated)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
(XCBaseObject *)iHighestPeakBarObj,
|
||||
drawnObjects //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Highest Peak Vale Breaker Bar ...
|
||||
XOHCL highestPeakValeBreakeDownBar;
|
||||
if (isValidBreakeDownHighestPeakVale)
|
||||
{
|
||||
//
|
||||
result = GetBar(
|
||||
highestPeakValeBreakeDownBar,
|
||||
highestPeakValeBreakeDownIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XCOHCLObject *iObj;
|
||||
bool isCreated = mPOIDetector.mDrawer.CreateBar(
|
||||
highestPeakValeBreakeDownBar,
|
||||
iObj,
|
||||
TimeCurrent() //
|
||||
);
|
||||
if (isCreated)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
(XCBaseObject *)iObj,
|
||||
drawnObjects //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Peak Below Highest Peak Vale ...
|
||||
XOHCL peakBelowHighestPeakValeBar;
|
||||
if (isValidPeakBelowHighestPeakVale)
|
||||
{
|
||||
//
|
||||
result = GetBar(peakBelowHighestPeakValeBar,
|
||||
peakBelowHighestPeakValeIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XCOHCLObject *iObj;
|
||||
bool isCreated = mPOIDetector.mDrawer.CreateBar(
|
||||
peakBelowHighestPeakValeBar,
|
||||
iObj,
|
||||
TimeCurrent() //
|
||||
);
|
||||
if (isCreated)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
(XCBaseObject *)iObj,
|
||||
drawnObjects //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Peaks ...
|
||||
int peaksCount = ArraySize(peaks);
|
||||
if (IsValidSize(peaksCount))
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < peaksCount; i++)
|
||||
{
|
||||
//
|
||||
iPeakPoint = peaks[i];
|
||||
|
||||
//
|
||||
CChartObjectTrend *iPeakObj;
|
||||
iPeakObj = new CChartObjectTrend();
|
||||
|
||||
//
|
||||
string iPeakName = "XPEAK_" + ToString(iPeakPoint.value);
|
||||
|
||||
//
|
||||
long chartID = mPOIDetector.mDrawer.ChartIdentification();
|
||||
int window = mPOIDetector.mDrawer.SubWindowIdentification();
|
||||
|
||||
//
|
||||
bool isCreate = iPeakObj.Create(
|
||||
chartID,
|
||||
iPeakName,
|
||||
window,
|
||||
iPeakPoint.time,
|
||||
iPeakPoint.value,
|
||||
TimeCurrent(),
|
||||
iPeakPoint.value //
|
||||
);
|
||||
if (isCreated)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
@@ -3143,8 +3793,8 @@ class XC121SMCCycleHelper : public XCBase
|
||||
XValueChange mVWapStateChanges[]; // Holds Vales Changes ...
|
||||
|
||||
//
|
||||
int mConsolidationLoopback; // Consolidation Loopback Length ...
|
||||
XConsolidationZone mConsolidationZones[]; // Holds Consolidation Zones ...
|
||||
int mConsolidationLoopback; // Consolidation Loopback Length ...
|
||||
XConsolidationZone mConsolidationZones[]; // Holds Consolidation Zones ...
|
||||
XConsolidationZone mActiveConsolidationZone; // Holds Actiove Consolidation Zone ...
|
||||
// XCConsolidationZoneObject *mActiveConsolidationZoneObj;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user