Complete Ticks Zones ...
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.base.class.mq5"
|
||||
#include <Arrays/ArrayObj.mqh>
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
@@ -36,6 +37,8 @@ enum ENUM_XPOIS
|
||||
//
|
||||
X_POI_NONE,
|
||||
//
|
||||
X_POI_TICKS_ZONES, // Ticks Zone ...
|
||||
//
|
||||
// Trading Day ...
|
||||
X_POI_TRADING_DAY, // Trading Day ...
|
||||
//
|
||||
@@ -900,7 +903,7 @@ class XCTwoBarZone : public XCZone
|
||||
From(startBar.time);
|
||||
To(endBar.time);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
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 ...
|
||||
class XCDay : public XCFromToZone
|
||||
@@ -2600,6 +3049,11 @@ string ToString(ENUM_XPOIS value)
|
||||
case X_POI_BEARISH_FVG:
|
||||
result = "XBEARFVG";
|
||||
break;
|
||||
|
||||
//
|
||||
case X_POI_TICKS_ZONES:
|
||||
result = "XTKSZ";
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user