Complete Ticks Zones ...

This commit is contained in:
2024-11-14 20:57:29 +03:30
parent 53f3f94b75
commit b921b45eb2
4 changed files with 995 additions and 5 deletions
+326
View File
@@ -28,6 +28,7 @@
#include <ChartObjects/ChartObjectsArrows.mqh> #include <ChartObjects/ChartObjectsArrows.mqh>
#include <ChartObjects/ChartObjectsLines.mqh> #include <ChartObjects/ChartObjectsLines.mqh>
#include <ChartObjects/ChartObjectsShapes.mqh> #include <ChartObjects/ChartObjectsShapes.mqh>
#include <ChartObjects\ChartObjectsTxtControls.mqh>
// //
// Definitions ... // Definitions ...
@@ -60,6 +61,8 @@ enum ENUM_XCHARTOBJECTS
X_BEARISH_ORDERBLOCK_OBJ = 9873, X_BEARISH_ORDERBLOCK_OBJ = 9873,
X_BULLISH_FVG_OBJ = 9874, X_BULLISH_FVG_OBJ = 9874,
X_BEARISH_FVG_OBJ = 9875, X_BEARISH_FVG_OBJ = 9875,
X_TICK_ZONE_OBJ = 9876,
X_TICKS_ZONE_OBJ = 9877,
}; };
enum ENUM_X_CHART_IDS enum ENUM_X_CHART_IDS
@@ -1532,4 +1535,327 @@ class XCBearishFairValueGapObject : public XCZoneObject
} }
}; };
//
// Zone Ticks ...
class XCTickZoneObject : public XCBaseObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param name: String, Specify Chart Object Identifier ...
* @param from: Datetime ...
* @param to: Datetime ...
* @param zone: XCTickZone instance ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
string name,
datetime from,
datetime to,
XCTickZone *zone,
string prefix = NULL //
)
{
//
bool result = false;
//
result =
IsValid(name) &&
zone.IsValid() &&
IsValid(to) &&
IsValid(from);
if (!result)
{
return result;
}
//
if (IsValid(prefix))
{
name = prefix + "_" + name;
}
//
string rectName = "TKZ_" + name;
result = mRect.Create(
chart_id,
rectName,
window,
from,
zone.high,
to,
zone.low //
);
if (!result)
{
return result;
}
//
string lblName = "LBL_" + name;
result = mLabel.Create(
chart_id,
lblName,
window,
from,
zone.high //
);
if (!result)
{
return result;
}
//
mLabel.Description(ToString(zone.percent) + "%");
//
ObjName(name);
//
return result;
}
//
// Virtual ...
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_TICK_ZONE_OBJ;
}
//
// Getter(s) / Setter(s) ...
/**
* Set Zone Width ...
*
* @param value: Integer ...
*/
void ZoneWidth(int value)
{
//
if (value < 1)
{
value = 1;
}
//
mRect.Width(value);
}
/**
* Set Zone Color ...
*
* @param value: Color ...
*/
void ZoneColor(color value)
{
mRect.Color(value);
}
/**
* Set Zone Style ...
*
* @param value: ENUM_LINE_STYLE member ...
*/
void ZoneStyle(ENUM_LINE_STYLE value)
{
mRect.Style(value);
}
/**
* Set Zone Fill ...
*
* @param value: Boolean ...
*/
void ZoneFill(bool value)
{
mRect.Fill(value);
}
/**
* Set Label Color ...
*
* @param value: Color ...
*/
void LabelColor(color value)
{
mLabel.Color(value);
}
/**
* Set Label Size ...
*
* @param value: Integer ...
*/
void LabelSize(int value)
{
mLabel.FontSize(value);
}
/**
* Set Label Font ...
*
* @param value: String ...
*/
void LabelFont(string value)
{
mLabel.Font(value);
}
/**
* Set Label Angle ...
*
* @param value: double ...
*/
void LabelAngle(double value)
{
mLabel.Angle(value);
}
//
private:
//
// Props ...
CChartObjectRectangle mRect;
CChartObjectLabel mLabel;
//
};
class XCTicksZoneObject : public XCBaseObject
{
//
public:
//
//
void ~XCTicksZoneObject()
{
mZones.Clear();
}
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param zone: XCTicksZone instance ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
XCTicksZone &zone,
string prefix = NULL //
)
{
//
bool result = false;
//
result = zone.IsValid();
if (!result)
{
return result;
}
//
string name = zone.GetTag();
int levels = zone.Levels();
result = levels > 0;
if (!result)
{
return result;
}
//
for (int i = 0; i < levels; i++)
{
//
XCTickZone *iZone = zone.GetZone(i);
XCTickZoneObject *iObj;
iObj = new XCTickZoneObject();
result = iObj.Create(
chart_id,
window,
ToString(i) + "_" + name,
zone.From(),
zone.To(),
iZone,
prefix //
);
if (!result)
{
break;
}
//
mZones.Add(iObj);
}
//
if (result)
{
ObjName(name);
}
else
{
mZones.Clear();
}
//
return result;
}
//
// Virtual ...
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_TICKS_ZONE_OBJ;
}
//
// Getter(s) / Setter(s) ...
//
// Actions ...
void Destroy() {
mZones.Clear();
}
//
private:
//
// Props ...
CArrayObj mZones;
//
};
// //
+161 -4
View File
@@ -437,6 +437,63 @@ class XCPOIDetector : public XCBaseAlert
mFairValueGapsSameBars = value; mFairValueGapsSameBars = value;
} }
//
// Ticks Zone ...
/**
* Get Ticks Range Levels ...
*
* @return ( int )
*/
int TicksRangeZoneLevel()
{
return mTicksRangeZoneLevel;
}
/**
* Set Ticks Range Levels ...
*
* @param value: Integer ...
*/
void TicksRangeZoneLevel(int value)
{
//
if (value < 2)
{
value = 2;
}
//
mTicksRangeZoneLevel = value;
}
/**
* Get Ticks Range Zone Loopback Period ...
*
* @return ( int )
*/
int TicksRangeZoneRange()
{
return mTicksRangeZoneRange;
}
/**
* Set Ticks Range Zone Loopback Period ...
*
* @param value: Integer ...
*/
void TicksRangeZoneRange(int value)
{
//
if (value < 7)
{
value = 7;
}
//
mTicksRangeZoneRange = value;
}
// //
// Actions ... // Actions ...
@@ -952,6 +1009,20 @@ class XCPOIDetector : public XCBaseAlert
} }
} }
//
// Ticks Range Zone ...
int ticksLevels = TicksRangeZoneLevel();
int ticksRange = TicksRangeZoneRange();
if (ticksLevels > 0 &&
ticksRange > 0)
{
//
isDetected = DetectTicksZoneRange(cBar);
if (isDetected)
{
}
}
// //
ValidatePOIs(cBar); ValidatePOIs(cBar);
@@ -1109,6 +1180,10 @@ class XCPOIDetector : public XCBaseAlert
// //
FairValueGapsSameBars(3); FairValueGapsSameBars(3);
//
TicksRangeZoneLevel(10);
TicksRangeZoneRange(144);
} }
// //
@@ -3283,7 +3358,8 @@ class XCPOIDetector : public XCBaseAlert
// //
int sameBars = OrderBlocksSameBars(); int sameBars = OrderBlocksSameBars();
if (sameBars < 0) result = sameBars > 0;
if (!result)
{ {
return result; return result;
} }
@@ -3440,7 +3516,8 @@ class XCPOIDetector : public XCBaseAlert
// //
int sameBars = OrderBlocksSameBars(); int sameBars = OrderBlocksSameBars();
if (sameBars < 0) result = sameBars > 0;
if (!result)
{ {
return result; return result;
} }
@@ -3601,7 +3678,8 @@ class XCPOIDetector : public XCBaseAlert
// //
int sameBars = FairValueGapsSameBars(); int sameBars = FairValueGapsSameBars();
if (sameBars < 0) result = sameBars > 0;
if (!result)
{ {
return result; return result;
} }
@@ -3761,7 +3839,8 @@ class XCPOIDetector : public XCBaseAlert
// //
int sameBars = FairValueGapsSameBars(); int sameBars = FairValueGapsSameBars();
if (sameBars < 0) result = sameBars > 0;
if (!result)
{ {
return result; return result;
} }
@@ -3896,6 +3975,84 @@ class XCPOIDetector : public XCBaseAlert
return result; return result;
} }
//
// Ticks Range Zones ...
int mTicksRangeZoneLevel; // Ticks Range Levels ...
int mTicksRangeZoneRange; // Ticks Range Zone Loopback Period ...
//
XCTicksZone *mTicksZone; // Ticks Zone ...
// XCTicksZoneObject *mTicksZoneObject; // Ticks Zone Object ...
/**
* Detect Ticks Zone Range ...
*
* @param bar: XOHCL instance ...
*
* @return ( bool )
*/
bool DetectTicksZoneRange(XOHCL &bar)
{
//
bool result = false;
//
result = bar.IsValid();
if (!result)
{
return result;
}
//
int ticksLevels = TicksRangeZoneLevel();
int ticksRange = TicksRangeZoneRange();
result = ticksLevels > 0 &&
ticksRange > 0;
if (!result)
{
return result;
}
//
int startBarIndex = bar.Index() + ticksRange;
XOHCL startBar;
result = startBar.Init(
bar.symbol,
bar.period,
startBarIndex //
);
if (!result)
{
return result;
}
//
mTicksZone = new XCTicksZone();
result = mTicksZone.Init(
startBar,
bar //
);
if (!result)
{
//
mTicksZone = NULL;
return result;
}
// //
// if (mTicksZoneObject != NULL)
// {
// mTicksZoneObject.Destroy();
// }
// mDrawer.CreateTicksZone(
// mTicksZone,
// mTicksZoneObject //
// );
//
return result;
}
// //
// Liquidity Zones ... // Liquidity Zones ...
+53
View File
@@ -2268,6 +2268,59 @@ class XCPOIDrawer : public XCBase
return result; return result;
} }
//
// Ticks Zone ...
bool CreateTicksZone(
XCTicksZone &zone,
XCTicksZoneObject *&object
) {
//
bool result = false;
//
result = zone.IsValid();
if (!result)
{
return result;
}
//
string prefix = Prefix();
long chartID = ChartIdentification();
int window = SubWindowIdentification();
//
// bool fill = BearishFVGFill();
// int width = BearishFVGWidth();
// color crl = BearishFVGColor();
// ENUM_LINE_STYLE style = BearishFVGStyle();
//
object = new XCTicksZoneObject();
result = object.Create(
chartID,
window,
zone,
prefix //
);
//
if (!result)
{
return result;
}
//
// object.ZoneFill(fill);
// object.ZoneColor(crl);
// object.ZoneWidth(width);
// object.ZoneStyle(style);
//
return result;
}
// //
protected: protected:
// //
+455 -1
View File
@@ -22,6 +22,7 @@
// //
// Imports ... // Imports ...
#include "../Classes/x-saherelm.base.class.mq5" #include "../Classes/x-saherelm.base.class.mq5"
#include <Arrays/ArrayObj.mqh>
// //
// Definitions ... // Definitions ...
@@ -36,6 +37,8 @@ enum ENUM_XPOIS
// //
X_POI_NONE, X_POI_NONE,
// //
X_POI_TICKS_ZONES, // Ticks Zone ...
//
// Trading Day ... // Trading Day ...
X_POI_TRADING_DAY, // Trading Day ... X_POI_TRADING_DAY, // Trading Day ...
// //
@@ -900,7 +903,7 @@ class XCTwoBarZone : public XCZone
From(startBar.time); From(startBar.time);
To(endBar.time); To(endBar.time);
} }
// //
return result; return result;
} }
@@ -2363,6 +2366,452 @@ class XCFVG : public XCTwoBarZone
// //
}; };
//
// Ticks Zones ...
//
class XCTickZone : public CObject
{
//
// Public ...
public:
//
// Props ...
double high;
double low;
int ticks;
double percent;
//
// Compare Two Zone With Each Other ...
virtual int Compare(
const CObject *node,
const int mode = 0 //
) const
{
//
const XCTickZone *other = (XCTickZone *)node;
//
return other.ticks - ticks;
}
//
bool IsValid()
{
//
bool result = false;
//
result = high > 0 &&
low > 0 &&
high > low &&
ticks > 0 &&
percent > 0;
//
return result;
}
//
// Protected ...
protected:
//
// Private ...
private:
//
};
//
class XCTicksZone : public XCTwoBarZone
{
//
public:
//
//
// Constructor ...
void XCTicksZone()
{
Default();
}
//
// Deconstructor ...
void ~XCTicksZone()
{
}
//
// Getter(s) / Setter(s) ...
/**
* Get Number of Ticks Levels ...
*
* @return ( int )
*/
int Levels()
{
return mLevels;
}
/**
* Set Number of Ticks Levels ...
*
* @return ( int )
*/
void Levels(int value)
{
//
if (value < 2)
{
value = 2;
}
//
mLevels = value;
}
/**
* Apply Default Config ...
*/
virtual void Default()
{
//
Levels(10);
}
//
// Tools ...
/**
* Initialize POI ...
*
* @param startBar: XOHCL instance ...
* @param endBar: XOHCL instance ...
*
* @return ( bool )
*/
bool Init(
XOHCL &startBar,
XOHCL &endBar //
)
{
//
bool result = false;
//
result = endBar.IsValid() &&
startBar.IsValid();
if (!result)
{
return result;
}
//
// Calculate Start and End Time ...
datetime from = startBar.time;
datetime to = endBar.time;
ulong fromM = ((ulong)startBar.time * 1000);
ulong toM = ((ulong)endBar.time * 1000);
//
// Symbol and Period ...
string symbol = startBar.symbol;
ENUM_TIMEFRAMES period = startBar.period;
//
// Prepare Zones Array ...
mZones.Clear();
//
// Retrieve Ticks between Times ...
SpecificClean(mTicks);
CopyTicksRange(
symbol,
mTicks,
COPY_TICKS_ALL,
fromM,
toM //
);
//
// Retrieve Highs ...
SpecificClean(mHighs);
CopyHigh(
symbol,
period,
from,
to,
mHighs //
);
//
// Retrieve Lows ...
SpecificClean(mLows);
CopyLow(
symbol,
period,
from,
to,
mLows //
);
//
// Find Highest Value in Range ...
int highIDX = ArrayMaximum(mHighs);
mRangeHigh = mHighs[highIDX];
//
// Find Lowest Value in Range ...
int lowIDX = ArrayMinimum(mLows);
mRangeLow = mLows[lowIDX];
//
datetime mTimes[];
CopyTime(
symbol,
period,
from,
to,
mTimes //
);
mRangeHighTime = mTimes[highIDX];
mRangeLowTime = mTimes[lowIDX];
//
double mRangeSize = mRangeHigh - mRangeLow;
//
// Create Zones ...
for (int i = 0; i < Levels(); i++)
{
//
// Instance a New Zone ...
XCTickZone *iZone = new XCTickZone();
//
// Calculate Each Zones High / Low based on Range ...
double iH = mRangeHigh - mRangeSize * i / Levels();
double iL = mRangeHigh - mRangeSize * (i + 1) / Levels();
//
// Set Zone High Low Properties ...
iZone.low = iL;
iZone.high = iH;
//
// Add Zone to Zone Array Objects ...
mZones.Add(iZone);
}
//
// Calculate Each Zone Ticks ...
int ticksCount = ArraySize(mTicks);
for (int i = 0; i < ticksCount; i++)
{
//
// Retrieve Tick ...
MqlTick iTick = mTicks[i];
//
// Loop through Zones ...
for (int j = 0; j < Levels(); j++)
{
//
// Rejrieve j indexed Zone Object ...
XCTickZone *jZone = mZones.At(j);
//
bool isInRange = IsTickInZoneRange(
iTick,
jZone //
);
if (isInRange)
{
//
jZone.ticks++;
break;
}
}
}
//
// Calculating Zone Percents ...
for (int i = 0; i < Levels(); i++)
{
//
XCTickZone *iZone = mZones.At(i);
//
double percent = CalculateZoneTickPercent(iZone);
iZone.percent = percent;
}
//
// Sort Zones Based on Percents ...
mZones.Sort();
//
mUpper = mRangeHigh;
mLower = mRangeLow;
mType = X_POI_TICKS_ZONES;
mEndBar = endBar;
mStartBar = startBar;
From(startBar.time);
To(endBar.time);
//
result = IsValid();
//
return result;
}
//
// Getter(s) / Setter(s) ...
/**
* Retrieve Zones Count ...
*
* @return ( int )
*/
int Count()
{
return mZones.Total();
}
/**
* Retrieve Specified Sorted Zones ...
*
* @param index: Integer ...
*
* @return ( XCTickZone * )
*/
XCTickZone *GetZone(int index)
{
//
if (!IsValidIndex(index))
{
return NULL;
}
//
return mZones.At(index);
}
//
// Overrides ...
bool IsValid() override
{
//
bool result = false;
//
result =
IsValidFrom() &&
IsValidTwoBarZone() &&
Levels() > 0 &&
mZones.Total() == Levels() &&
mRangeHigh > 0 &&
mRangeLow > 0;
//
return result;
}
//
protected:
//
//
private:
//
// Props ...
//
MqlTick mTicks[];
double mHighs[];
double mLows[];
double mRangeHigh;
datetime mRangeHighTime;
double mRangeLow;
datetime mRangeLowTime;
//
int mLevels; // Number of Ticks Levels ...
//
CArrayObj mZones;
/**
* Check a Tick is in a Zone rage or not ...
*
* @param tick: MqlTick instance ...
* @param zone: XCTickZone instance ...
*
* @return ( bool )
*/
bool IsTickInZoneRange(
MqlTick &tick,
XCTickZone *zone //
)
{
//
bool result = false;
//
result =
//
tick.bid >= zone.low &&
tick.bid <= zone.high
//
;
//
return result;
}
/**
* Calculate Zone Tick Percent ...
*
* @param zone: XCTickZone instance ...
* @param normalizationDigits: Integer ...
*
* @return ( double )
*/
double CalculateZoneTickPercent(
XCTickZone *zone,
int normalizationDigits = 2 //
)
{
//
double result = 0;
//
if (normalizationDigits < 2 || normalizationDigits > 5)
{
normalizationDigits = 2;
}
//
int ticksCount = ArraySize(mTicks);
if (ticksCount <= 0)
{
return result;
}
//
result = (double)zone.ticks / ticksCount * 100;
result = NormalizeDouble(result, normalizationDigits);
//
return result;
}
//
};
// //
// Trading Day ... // Trading Day ...
class XCDay : public XCFromToZone class XCDay : public XCFromToZone
@@ -2600,6 +3049,11 @@ string ToString(ENUM_XPOIS value)
case X_POI_BEARISH_FVG: case X_POI_BEARISH_FVG:
result = "XBEARFVG"; result = "XBEARFVG";
break; break;
//
case X_POI_TICKS_ZONES:
result = "XTKSZ";
break;
} }
// //