implement all LinearRegression Requirements as XPivot and XPivotAnalysis into common, enums, extensions and POI Libraries for Supporting Pivot Extractions of each Indicator we need ...
This commit is contained in:
@@ -1275,4 +1275,91 @@ string ToString(ENUM_X_MA_METHOD value)
|
||||
// END Ma Methods ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XPivots ...
|
||||
//
|
||||
|
||||
//
|
||||
enum ENUM_X_PIVOT_TYPE
|
||||
{
|
||||
X_PIVOT_TYPE_NONE = 0, // None
|
||||
X_PIVOT_TYPE_PEAK = 1, // PEAK
|
||||
X_PIVOT_TYPE_VALE = 2, // VALE
|
||||
};
|
||||
|
||||
/**
|
||||
* Validate ...
|
||||
*
|
||||
* @param value: ENUM_X_PIVOT_TYPE ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsXValid(ENUM_X_PIVOT_TYPE value)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = value != X_PIVOT_TYPE_NONE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Specified Type of Pivot is Peak or not ...
|
||||
*
|
||||
* @param value: ENUM_X_PIVOT_TYPE, Specified Type ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsXPeak(ENUM_X_PIVOT_TYPE value)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsXValid(value) &&
|
||||
value == X_PIVOT_TYPE_PEAK;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Specified Type of Pivot is Vale or not ...
|
||||
*
|
||||
* @param value: ENUM_X_PIVOT_TYPE, Specified Type ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsXVale(ENUM_X_PIVOT_TYPE value)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsXValid(value) &&
|
||||
value == X_PIVOT_TYPE_VALE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represent Specified ZigZag Point Type as String ...
|
||||
*
|
||||
* @param value: ENUM_X_PIVOT_TYPE ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string ToXString(ENUM_X_PIVOT_TYPE value)
|
||||
{
|
||||
return EnumToString(value);
|
||||
}
|
||||
|
||||
//
|
||||
// END XPivots ...
|
||||
//
|
||||
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -14,7 +14,7 @@
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright `023, SaherElm IT Center"
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
@@ -22,12 +22,536 @@
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.base.class.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include <Arrays/ArrayObj.mqh>
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
/**
|
||||
* Represent a Pivot ...
|
||||
**/
|
||||
struct XPivot
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
double value; // Value
|
||||
datetime time; // Time
|
||||
string symbol; // Symbol
|
||||
ENUM_X_DIRECTION dir; // Direction
|
||||
ENUM_TIMEFRAMES period; // Period
|
||||
ENUM_X_PIVOT_TYPE type; // Type
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XPivot()
|
||||
{
|
||||
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_PIVOT_TYPE, point type ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool Init(
|
||||
double _value,
|
||||
datetime _time,
|
||||
string _symbol,
|
||||
ENUM_X_DIRECTION _dir,
|
||||
ENUM_TIMEFRAMES _period,
|
||||
ENUM_X_PIVOT_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 ...
|
||||
|
||||
/**
|
||||
* Cleanup Model ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
value = 0;
|
||||
time = NULL;
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
dir = X_DIRECTION_NONE;
|
||||
type = X_PIVOT_TYPE_NONE;
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Model ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
value > 0 &&
|
||||
IsXValid(type) &&
|
||||
HasDirection(dir) &&
|
||||
IsSpecifiedValid(time) &&
|
||||
IsSpecifiedValid(symbol) &&
|
||||
IsSpecifiedValid(period);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Model is Peak or not ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsPeak()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
IsValid() &&
|
||||
IsXPeak(type);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Model is Vale or not ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsVale()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
IsValid() &&
|
||||
IsXVale(type);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Point is Bullish or not ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsBullish()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid() &&
|
||||
IsSpecifiedBullish(dir);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Point is Bearish or not ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsBearish()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid() &&
|
||||
IsSpecifiedBearish(dir);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check two Struct are Same or not ...
|
||||
*
|
||||
* @param item: XPivot ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsSameAs(XPivot &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: XPivot, reference Array ...
|
||||
* @param index: int, reference to Holds Founded Index ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsExists(
|
||||
XPivot &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: XPivot, reference Array ...
|
||||
*/
|
||||
void AddIfNotExists(XPivot &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 //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Pivot Age ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int GetAge()
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
if (!IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = GetBarIndex(
|
||||
symbol,
|
||||
period,
|
||||
time //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to model Has Same Symbol ...
|
||||
*
|
||||
* @param item: XPivot, dest model for Checking ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsSameSymbolAs(XPivot &item)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
IsValid() &&
|
||||
item.IsValid() &&
|
||||
symbol == item.symbol;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to model Has Same Period ...
|
||||
*
|
||||
* @param item: XPivot, dest model for Checking ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsSamePeriodAs(XPivot &item)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
IsValid() &&
|
||||
item.IsValid() &&
|
||||
period == item.period;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to model Has Same Symbol/Period ...
|
||||
*
|
||||
* @param item: XPivot, dest model for Checking ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsSameMarketAs(XPivot &item)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
IsValid() &&
|
||||
item.IsValid() &&
|
||||
IsSameSymbolAs(item) &&
|
||||
IsSamePeriodAs(item);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to model Has Same Type ...
|
||||
*
|
||||
* @param item: XPivot, dest model for Checking ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsSameTypeAs(XPivot &item)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
IsValid() &&
|
||||
item.IsValid() &&
|
||||
type == item.type;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to model Has Same Direction ...
|
||||
*
|
||||
* @param item: XPivot, dest model for Checking ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsSameDirectionAs(XPivot &item)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
IsValid() &&
|
||||
item.IsValid() &&
|
||||
dir == item.dir;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Logging Tools ...
|
||||
|
||||
/**
|
||||
* Extract Specified Token of Struct ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GetTag()
|
||||
{
|
||||
return GetToken(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Represent an String Unique Identifier for Chart Objects ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GetObjectID()
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
if (!IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = GetTag() + "_" + symbol + "_" + ToXString(period) + "_" + ToXString(dir) + "_" + ToXString(type) + "_" + ToXString(TimeToSeconds(time));
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represent a Point as String ...
|
||||
*
|
||||
* @param spacer: string, How to Represent Spaces ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GetMessage(string spacer = NULL)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
// Normalize Spacer ...
|
||||
if (!IsSpecifiedValid(spacer))
|
||||
{
|
||||
spacer = " ";
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
if (!IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
ToXString(dir) + spacer + GetTag() + ":" + spacer +
|
||||
"Symbol: " + symbol + spacer +
|
||||
"Period: " + ToXString(period) + spacer +
|
||||
"Type: " + ToXString(type) + spacer +
|
||||
"Direction: " + ToXString(dir) + spacer +
|
||||
"Value: " + ToXString(value) + spacer +
|
||||
"Time: " + ToXString(time) + spacer;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Model a Box ...
|
||||
**/
|
||||
struct XBoxZone
|
||||
{
|
||||
//
|
||||
@@ -564,7 +1088,9 @@ struct XBoxZone
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
/**
|
||||
* Model a Direction Shift ...
|
||||
**/
|
||||
struct XDirectionShift
|
||||
{
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user