Files
MQL5Data/Classes/x-saherelm.x-cobject.class.mq5
T
2025-09-23 23:47:18 +03:30

2188 lines
39 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XChartObjects
// Description: provides all require Chart Objects ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
#include "../Libraries/x-saherelm.x-pivot.analysis.lib.mq5"
#include "../Libraries/x-saherelm.x-poi.lib.mq5"
#include "../Libraries/x-saherelm.x-trade.lib.mq5"
//
#include <ChartObjects/ChartObject.mqh>
#include <ChartObjects/ChartObjectsArrows.mqh>
#include <ChartObjects/ChartObjectsFibo.mqh>
#include <ChartObjects/ChartObjectsLines.mqh>
#include <ChartObjects/ChartObjectsShapes.mqh>
#include <ChartObjects/ChartObjectsTxtControls.mqh>
//
// Definitions ...
enum ENUM_XCHARTOBJECTS
{
//
// Global ...
X_BOX_OBJ = 7861,
X_BAR_ARROW_OBJ = 7862,
//
X_SIGNAL_OBJ = 8860,
X_OHCL_OBJ = 8863,
X_RR_OBJ = 8864,
X_PIVOT_OBJ = 8865,
//
// 9860 Custom Object ...
};
enum ENUM_X_CHART_IDS
{
X_AT, // AT
X_TO, // TO
X_FROM, // FROM
X_UPPER, // UPPER
X_LOWER, // LOWER
X_ENTRY, // ENTRY
X_TARGET, // TARGET
X_SL, // SL
X_TP, // TP
X_BAR_H_SHW, // HSHW
X_BAR_BDY, // BODY
X_BAR_L_SHW, // LSHW
};
string ToString(ENUM_X_CHART_IDS value)
{
//
string result = NULL;
//
result = EnumToString(value);
//
return result;
}
struct XPOIStyle
{
//
// Properties ...
int width; // Width ...
color clr; // Color ...
bool fill; // Fill, Use in Rectangles ...
ENUM_LINE_STYLE style; // Line Style ...
//
// Constructor ...
XPOIStyle()
{
Default();
}
//
// Tools ...
//
// Cleanup Model ...
void Clean()
{
//
width = 1;
fill = false;
clr = CLR_NONE;
style = STYLE_SOLID;
//
ZeroMemory(this);
}
//
// Default Props ...
void Default()
{
//
width = 1;
fill = false;
clr = CLR_NONE;
style = STYLE_SOLID;
}
};
//
// Extensions ...
/**
* Converts a XBoxZone struct to XSignal instance ...
*
* @param box: XBoxZone instance reference, provide source info ...
* @param signal: XSignal instance reference, holds prepared converted signal ...
*
* @return ( bool )
*/
bool ToSignal(
XBoxZone &box,
XSignal &signal,
double &rewardRatios[],
double additionalSL = 0 //
)
{
//
bool result = false;
//
signal.Clean();
//
result = box.IsValid() &&
HasChild(rewardRatios);
if (!result)
{
return result;
}
//
XOHCL entryBar;
int entryIDX = box.ToIndex();
if (entryIDX > 0)
{
entryIDX--;
}
result = entryBar.Init(
box.symbol,
box.period,
entryIDX //
);
if (!result)
{
//
entryBar.Clean();
//
return result;
}
//
bool isBullish = box.IsBullish();
bool isBearish = box.IsBearish();
//
ENUM_POSITION_TYPE iType =
isBullish
? POSITION_TYPE_BUY
: POSITION_TYPE_SELL;
ENUM_X_POSITION_TYPES iXType =
isBullish
? X_POSITION_TYPE_LONG
: X_POSITION_TYPE_SHORT;
//
double points = GetPoints(box.symbol);
//
double entry =
isBullish
? box.upper
: box.lower;
entry = entryBar.open;
//
double sl =
isBullish
? box.lower
: box.upper;
if (additionalSL > 0)
{
//
sl =
isBullish
? sl - additionalSL
: sl + additionalSL;
}
//
double risk = MathAbs(entry - sl);
//
double tp = 0;
//
// Calculate Target ...
XTarget targets[];
//
double tmp[];
int idx = -1;
XTarget iTarget;
bool has = false;
double iRatio = 0;
double iReward = 0;
double iRewardPrice = 0;
Copy(
rewardRatios,
tmp //
);
while (HasChild(tmp))
{
//
idx = -1;
iRatio = GetMaxWidthIndex(
tmp,
idx //
);
//
has = IsValidIndex(idx);
if (!has)
{
break;
}
//
has = iRatio > 0;
//
ArrayRemove(
tmp,
idx,
1 //
);
//
bool canSetTP = tp <= 0;
//
iReward = iRatio * risk;
//
iRewardPrice =
isBullish
? entry + iReward
: entry - iReward;
if (canSetTP)
{
tp = iRewardPrice;
}
else
{
//
iTarget.target = iRewardPrice;
AddRef(
iTarget,
targets //
);
//
iTarget.Clean();
}
}
Clean(tmp);
//
// Filling Signal ...
signal.tp = tp;
signal.sl = sl;
signal.type = iType;
signal.comment = "";
signal.entry = entry;
signal.time = box.to;
signal.volume = 0.01;
signal.provider = box.type;
signal.symbol = box.symbol;
signal.period = box.period;
signal.mode = X_ORDER_MODE_MARKET;
//
if (HasChild(targets))
{
//
Copy(
targets,
signal.targets //
);
}
//
result = signal.IsValid();
//
// Cleanup Resources ...
//
if (!result)
{
signal.Clean();
}
//
Clean(tmp);
Clean(targets);
iTarget.Clean();
entryBar.Clean();
//
return result;
}
//
// Implementation ...
//
// Global Chart Objects ...
//
// Bas Chart Object ...
class XCBaseObject : public CChartObject
{
//
public:
//
//
// Getter(s) / Setter(s) ...
/**
* Get Object Specified Name ...
*
* @return ( string )
*/
string ObjName()
{
return mObjName;
}
/**
* Set Object Specified Name ...
*
* @param value: String ...
*/
void ObjName(string value)
{
mObjName = value;
}
/**
* Destroy ...
*/
void virtual Destroy()
{
//
Detach();
Delete();
}
//
private:
//
//
// Props ...
string mObjName; // Object Specified Name ...
//
};
//
// Bar Arrow Object ...
class XCBarArrowObject : public XCBaseObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param name: String, Specified Object ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param swing: XCSwing instance ...
*
* @return ( bool )
*/
bool CreateByBar(
long chart_id,
string name,
int window,
int arrow,
XOHCL &bar,
ENUM_X_PRICE priceType,
double threshold = 5 //
)
{
//
bool result = false;
//
result =
//
bar.IsValid() &&
IsValid(name)
//
;
if (!result)
{
return result;
}
//
datetime time = bar.time;
double price = bar.GetPrice(priceType);
//
if (threshold > 0)
{
//
double thresholdPrice = threshold * GetPoints(bar.symbol);
if (priceType == X_PRICE_HIGH)
{
price += thresholdPrice;
}
else if (priceType == X_PRICE_LOW)
{
price -= thresholdPrice;
}
}
//
result = mArrow.Create(
chart_id,
name,
window,
time,
price,
(char)arrow //
);
//
if (result)
{
ObjName(name);
}
//
return result;
}
//
// Virtual ...
//
// Setter(s) ...
/**
* Set Arrow Anchor ...
*
* @param value: ENUM_ARROW_ANCHOR member ...
*/
void ArrowAnchor(ENUM_ARROW_ANCHOR value)
{
mArrow.Anchor(value);
}
/**
* Set Arrow Color ...
*
* @param value: Color ...
*/
void ArrowColor(color value)
{
mArrow.Color(value);
}
/**
* Set Arrow Width ...
*
* @param value: Integer ...
*/
void ArrowWidth(int value)
{
mArrow.Width(value);
}
//
private:
//
CChartObjectArrow mArrow;
//
};
//
// Signal ...
class XCSignalObject : public XCBaseObject
{
//
public:
//
//
// Constructor ...
void XCSignalObject()
{
}
//
// Deconstructor ...
void ~XCSignalObject()
{
}
/**
* Create a Signal Object on Chart ...
*
* @param chart_id: Long ...
* @param name: String ...
* @param window: Integer ...
* @param signal: XSignal instance ...
* @param length: int, Specified Length of Signal ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
const int window,
XSignal &signal,
int length = 3,
string prefix = NULL //
)
{
//
bool result = false;
//
length = NormalizeInt(length, 3);
//
result = signal.IsValid();
if (!result)
{
return result;
}
//
string name = signal.GetTag();
if (IsValid(prefix))
{
name = prefix + "_" + name;
}
string nameMD5 = ToMD5(name);
//
int delay = (PeriodSeconds(signal.period) * length);
datetime time1 = (datetime)((int)signal.time - delay);
datetime time2 = (datetime)((int)signal.time + delay);
//
// TP ...
string tpName = ToString(X_TP) + "_" + nameMD5;
result = mTPTrend.Create(
chart_id,
tpName,
window,
time1,
signal.tp,
time2,
signal.tp //
);
if (!result)
{
return result;
}
//
// SL ...
string slName = ToString(X_SL) + "_" + nameMD5;
result = mSLTrend.Create(
chart_id,
slName,
window,
time1,
signal.sl,
time2,
signal.sl //
);
if (!result)
{
//
mTPTrend.Delete();
return result;
}
//
// TARGET ...
bool hasTargets = HasChild(signal.targets);
if (hasTargets)
{
//
int targetsCount = ArraySize(signal.targets);
for (int i = 0; i < targetsCount; i++)
{
//
string targetName = ToString(X_TARGET) + "_" + ToXString(i) + "_" + nameMD5;
CChartObjectTrend *mTargetTrend;
mTargetTrend = new CChartObjectTrend();
result = mTargetTrend.Create(
chart_id,
targetName,
window,
time1,
signal.targets[i].target,
time2,
signal.targets[i].target //
);
if (!result)
{
//
mTPTrend.Delete();
mSLTrend.Delete();
break;
}
//
mTargetTrends.Add(mTargetTrend);
}
}
//
// ENTRY ...
string entrName = ToString(X_ENTRY) + "_" + nameMD5;
result = mEntryTrend.Create(
chart_id,
entrName,
window,
time1,
signal.entry,
time2,
signal.entry //
);
if (!result)
{
//
mTPTrend.Delete();
mSLTrend.Delete();
mTargetTrends.Clear();
return result;
}
//
// Set Object Name ...
ObjName(name);
//
return result;
}
//
// Setter(s) ...
//
// TP ...
/**
* Set TP Width ...
*
* @param value: Integer ...
*/
void TPWidth(int value)
{
//
if (value < 1)
{
value = 1;
}
//
mTPTrend.Width(value);
}
/**
* Set TP Color ...
*
* @param value: Color ...
*/
void TPColor(color value)
{
mTPTrend.Color(value);
}
/**
* Set TP Style ...
*
* @param value: ENUM_LINE_STYLE ...
*/
void TPStyle(ENUM_LINE_STYLE value)
{
mTPTrend.Style(value);
}
//
// SL ...
/**
* Set SL Width ...
*
* @param value: Integer ...
*/
void SLWidth(int value)
{
//
if (value < 1)
{
value = 1;
}
//
mSLTrend.Width(value);
}
/**
* Set SL Color ...
*
* @param value: Color ...
*/
void SLColor(color value)
{
mSLTrend.Color(value);
}
/**
* Set SL Style ...
*
* @param value: ENUM_LINE_STYLE ...
*/
void SLStyle(ENUM_LINE_STYLE value)
{
mSLTrend.Style(value);
}
//
// TARGET ...
/**
* Set Target Width ...
*
* @param value: Integer ...
*/
void TargetWidth(int value)
{
//
if (value < 1)
{
value = 1;
}
//
for (int i = 0; i < mTargetTrends.Total(); i++)
{
//
CChartObjectTrend *iTrend = (CChartObjectTrend *)mTargetTrends.At(i);
iTrend.Width(value);
}
}
/**
* Set Target Color ...
*
* @param value: Color ...
*/
void TargetColor(color value)
{
//
for (int i = 0; i < mTargetTrends.Total(); i++)
{
//
CChartObjectTrend *iTrend = (CChartObjectTrend *)mTargetTrends.At(i);
iTrend.Color(value);
}
}
/**
* Set Target Style ...
*
* @param value: ENUM_LINE_STYLE ...
*/
void TargetStyle(ENUM_LINE_STYLE value)
{
//
for (int i = 0; i < mTargetTrends.Total(); i++)
{
//
CChartObjectTrend *iTrend = (CChartObjectTrend *)mTargetTrends.At(i);
iTrend.Style(value);
}
}
//
// ENTRY ...
/**
* Set Entry Width ...
*
* @param value: Integer ...
*/
void EntryWidth(int value)
{
//
if (value < 1)
{
value = 1;
}
//
mEntryTrend.Width(value);
}
/**
* Set Entry Color ...
*
* @param value: Color ...
*/
void EntryColor(color value)
{
mEntryTrend.Color(value);
}
/**
* Set Entry Style ...
*
* @param value: ENUM_LINE_STYLE ...
*/
void EntryStyle(ENUM_LINE_STYLE value)
{
mEntryTrend.Style(value);
}
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_SIGNAL_OBJ;
}
//
private:
//
//
CChartObjectTrend mTPTrend;
CChartObjectTrend mSLTrend;
CChartObjectTrend mEntryTrend;
CArrayObj mTargetTrends;
};
//
// XRR Object ...
class XCRRObject : public XCSignalObject
{
//
// Public ...
public:
//
// Constructor ...
bool CreateBoxRR(
long chart_id,
const int window,
XBoxZone &box,
double &rewardRatios[],
int length = 3,
string prefix = NULL //
)
{
//
bool result = false;
//
length = NormalizeInt(length, 3);
//
result = box.IsValid();
if (!result)
{
return result;
}
//
XSignal signal;
result = ToSignal(
box,
signal,
rewardRatios //
);
if (!result)
{
//
signal.Clean();
//
return result;
}
//
result = Create(
chart_id,
window,
signal,
length,
prefix //
);
//
signal.Clean();
//
return result;
}
};
//
// OHCL, Bar Object ...
class XCOHCLObject : public XCBaseObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param pivot: XPVPivot instance ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
XOHCL &bar,
datetime to,
string prefix = NULL //
)
{
//
bool result = false;
//
result = bar.IsValid() &&
IsValid(to);
if (!result)
{
return result;
}
//
string name = bar.GetTag();
if (IsValid(prefix))
{
name = prefix + "_" + name;
}
string nameMD5 = ToMD5(name);
//
// High Shadow ...
string hShadowName = ToString(X_BAR_H_SHW) + "_" + nameMD5;
//
result = mHighShadowRect.Create(
chart_id,
hShadowName,
window,
bar.time,
bar.high,
to,
bar.GetUp() //
);
if (!result)
{
return result;
}
//
// Body ...
string bodyName = ToString(X_BAR_BDY) + "_" + nameMD5;
//
result = mBodyRect.Create(
chart_id,
bodyName,
window,
bar.time,
bar.GetUp(),
to,
bar.GetDown() //
);
if (!result)
{
//
mHighShadowRect.Delete();
mHighShadowRect.Detach();
return result;
}
//
// Low Shadow ...
string lShadowName = ToString(X_BAR_L_SHW) + "_" + nameMD5;
//
result = mLowShadowRect.Create(
chart_id,
lShadowName,
window,
bar.time,
bar.GetDown(),
to,
bar.low //
);
if (!result)
{
//
mBodyRect.Delete();
mBodyRect.Detach();
mHighShadowRect.Delete();
mHighShadowRect.Detach();
return result;
}
//
if (result)
{
ObjName(name);
}
//
return result;
}
//
// Getter(s) / Setter(s) ...
/**
* Set High Shadow Width ...
*
* @param value: Integer ...
*/
void HighShadowWidth(int value)
{
//
if (value < 1)
{
value = 1;
}
//
mHighShadowRect.Width(value);
}
/**
* Set High Shadow Color ...
*
* @param value: Color ...
*/
void HighShadowColor(color value)
{
mHighShadowRect.Color(value);
}
/**
* Set High Shadow Style ...
*
* @param value: ENUM_LINE_STYLE member ...
*/
void HighShadowStyle(ENUM_LINE_STYLE value)
{
mHighShadowRect.Style(value);
}
/**
* Set High Shadow Fill ...
*
* @param value: Boolean ...
*/
void HighShadowFill(bool value)
{
mHighShadowRect.Fill(value);
}
/**
* Set Body Width ...
*
* @param value: Integer ...
*/
void BodyWidth(int value)
{
//
if (value < 1)
{
value = 1;
}
//
mBodyRect.Width(value);
}
/**
* Set Body Color ...
*
* @param value: Color ...
*/
void BodyColor(color value)
{
mBodyRect.Color(value);
}
/**
* Set Body Style ...
*
* @param value: ENUM_LINE_STYLE member ...
*/
void BodyStyle(ENUM_LINE_STYLE value)
{
mBodyRect.Style(value);
}
/**
* Set Body Fill ...
*
* @param value: Boolean ...
*/
void BodyFill(bool value)
{
mBodyRect.Fill(value);
}
/**
* Set Low Shadow Width ...
*
* @param value: Integer ...
*/
void LowShadowWidth(int value)
{
//
if (value < 1)
{
value = 1;
}
//
mLowShadowRect.Width(value);
}
/**
* Set Low Shadow Color ...
*
* @param value: Color ...
*/
void LowShadowColor(color value)
{
mLowShadowRect.Color(value);
}
/**
* Set Low Shadow Style ...
*
* @param value: ENUM_LINE_STYLE member ...
*/
void LowShadowStyle(ENUM_LINE_STYLE value)
{
mLowShadowRect.Style(value);
}
/**
* Set Low Shadow Fill ...
*
* @param value: Boolean ...
*/
void LowShadowFill(bool value)
{
mLowShadowRect.Fill(value);
}
void BarSpes(
int width = 1,
color clr = clrNONE,
ENUM_LINE_STYLE style = STYLE_SOLID,
bool fill = false //
)
{
//
BodyWidth(width);
LowShadowWidth(width);
HighShadowWidth(width);
//
BodyColor(clr);
LowShadowColor(clr);
HighShadowColor(clr);
//
BodyStyle(style);
LowShadowStyle(style);
HighShadowStyle(style);
//
BodyFill(fill);
LowShadowFill(fill);
HighShadowFill(fill);
}
//
// Virtual ...
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_OHCL_OBJ;
}
//
private:
//
//
// Props ...
CChartObjectRectangle mHighShadowRect;
CChartObjectRectangle mBodyRect;
CChartObjectRectangle mLowShadowRect;
};
//
// Box Object ...k
class XCBoxObject : public XCBaseObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param pivot: XPVPivot instance ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
string name,
double upper,
double lower,
datetime from,
datetime to,
datetime at = NULL,
string prefix = NULL //
)
{
//
bool result = false;
//
result =
upper > 0 &&
lower > 0 &&
to > from &&
IsValid(to) &&
IsValid(name) &&
IsValid(from) &&
upper > lower;
if (!result)
{
return result;
}
//
if (IsValid(prefix))
{
name = prefix + "_" + name;
}
string nameMD5 = ToMD5(name);
//
result = mRect.Create(
chart_id,
name,
window,
from,
upper,
to,
lower //
);
if (!result)
{
return result;
}
//
if (result)
{
//
if (IsValid(at))
{
//
result = mAt.Create(
chart_id,
name + ToString(X_AT),
window,
at //
);
}
//
if (!result)
{
//
mAt.Detach();
mAt.Delete();
//
mRect.Detach();
mRect.Delete();
}
}
//
if (result)
{
ObjName(name);
}
//
return result;
}
//
// Getter(s) / Setter(s) ...
/**
* Set Width ...
*
* @param value: Integer ...
*/
void BoxWidth(int value)
{
//
if (value < 1)
{
value = 1;
}
//
mAt.Width(value);
mRect.Width(value);
}
/**
* Set Color ...
*
* @param value: Color ...
*/
void BoxColor(color value)
{
//
mAt.Color(value);
mRect.Color(value);
}
/**
* Set Style ...
*
* @param value: ENUM_LINE_STYLE member ...
*/
void BoxStyle(ENUM_LINE_STYLE value)
{
//
mAt.Style(value);
mRect.Style(value);
}
/**
* Set Fill ...
*
* @param value: Boolean ...
*/
void BoxFill(bool value)
{
mRect.Fill(value);
}
//
// Virtual ...
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_BOX_OBJ;
}
//
private:
//
//
// Props ...
CChartObjectVLine mAt;
CChartObjectRectangle mRect;
};
/**
* XPivotAnalysis Chart Object ...
**/
class XCPivotAnalysisObject : public XCBaseObject
{
//
public:
//
/**
* Create Object ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param model: XPivotAnalysis, reference model ...
* @param drawPivots: Specified to Draw Pivots or not ...
* @param peakArrow: int, Specified Arrow Code for Peak Pivots ...
* @param valeArrow: int, Specified Arrow Code for Vale Pivots ...
* @param threshold: int, distance between price and arrow in Point ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
XPivotAnalysis &model,
bool drawPivots = true,
int peakArrow = 159,
int valeArrow = 159,
int threshold = 5 //
)
{
//
bool result = false;
//
bool has = false;
//
// Validate ...
result = model.IsValid();
if (!result)
{
return result;
}
//
// Generate Object ID ...
string objID = model.GetObjectID();
string upperName = model.GetUpperObjectID();
string lowerName = model.GetLowerObjectID();
//
// Extract Recent Pivots ...
//
// Creating Upper ...
result = mUpper.Create(
chart_id,
upperName,
window,
model.fromTime,
model.peakFrom,
model.toTime,
model.peakTo //
);
if (!result)
{
return result;
}
//
// Create Lower ...
result = mLower.Create(
chart_id,
lowerName,
window,
model.fromTime,
model.valeFrom,
model.toTime,
model.valeTo //
);
if (!result)
{
//
mUpper.Detach();
mUpper.Delete();
//
return result;
}
//
// Support ...
XBoxZone tmpBox;
mSupportBox = NULL;
has = model.HasSupportBox(tmpBox);
if (has)
{
//
datetime to = TimeCurrent();
string name = model.GetSupportBoxObjectID();
mSupportBox = new XCBoxObject();
has = mSupportBox.Create(
chart_id,
window,
name,
tmpBox.upper,
tmpBox.lower,
tmpBox.from,
to //
);
}
//
// Resistance ...
tmpBox.Clean();
mResistanceBox = NULL;
has = model.HasResistanceBox(tmpBox);
if (has)
{
//
datetime to = TimeCurrent();
string name = model.GetResistanceBoxObjectID();
mResistanceBox = new XCBoxObject();
has = mResistanceBox.Create(
chart_id,
window,
name,
tmpBox.upper,
tmpBox.lower,
tmpBox.from,
to //
);
}
//
// Draw Pivots ...
if (drawPivots &&
model.HasPivots())
{
//
XOHCL iBar;
int arrow = 0;
string name = NULL;
XCBarArrowObject *iObj;
ENUM_X_PRICE type = X_PRICE_NONE;
int pivotsCount = ArraySize(model.pivots);
for (int i = 0; i < pivotsCount; i++)
{
//
has = model.pivots[i].GetBar(iBar);
if (!has)
{
continue;
}
//
arrow = model.pivots[i].IsPeak()
? peakArrow
: valeArrow;
name = model.pivots[i].GetObjectID();
type = model.pivots[i].IsPeak()
? X_PRICE_HIGH
: X_PRICE_LOW;
iObj = new XCBarArrowObject();
has = iObj.CreateByBar(
chart_id,
name,
window,
arrow,
iBar,
type,
threshold //
);
if (has)
{
//
if (model.pivots[i].IsPeak())
{
mPeaks.Add(iObj);
}
else
{
mVales.Add(iObj);
}
}
//
iBar.Clean();
ZeroMemory(iObj);
}
//
// Cleanup Resources ...
iBar.Clean();
ZeroMemory(iObj);
}
//
// Setting Object Name ...
if (result)
{
ObjName(objID);
}
//
return result;
}
//
// Virtuals ...
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_PIVOT_OBJ;
}
/**
* Destroy ...
*/
void virtual Destroy()
{
//
Detach();
Delete();
//
DestroyObject(mSupportBox);
DestroyObject(mResistanceBox);
}
//
// Styling ...
/**
* Set Width ...
*
* @param value: Integer ...
*/
void UpperWidth(int value)
{
//
if (value < 1)
{
value = 1;
}
//
mUpper.Width(value);
}
/**
* Set Color ...
*
* @param value: Color ...
*/
void UpperColor(color value)
{
//
mUpper.Color(value);
}
/**
* Set Style ...
*
* @param value: ENUM_LINE_STYLE member ...
*/
void UpperStyle(ENUM_LINE_STYLE value)
{
//
mUpper.Style(value);
}
/**
* Specified Upper Ray to Left or not ...
*
* @param value: bool
*/
void UpperRayLeft(bool value)
{
mUpper.RayLeft(value);
}
/**
* Specified Upper Ray to Right or not ...
*
* @param value: bool
*/
void UpperRayRight(bool value)
{
mUpper.RayRight(value);
}
/**
* Set Width ...
*
* @param value: Integer ...
*/
void LowerWidth(int value)
{
//
if (value < 1)
{
value = 1;
}
//
mLower.Width(value);
}
/**
* Set Color ...
*
* @param value: Color ...
*/
void LowerColor(color value)
{
//
mLower.Color(value);
}
/**
* Set Style ...
*
* @param value: ENUM_LINE_STYLE member ...
*/
void LowerStyle(ENUM_LINE_STYLE value)
{
//
mLower.Style(value);
}
/**
* Specified Lower Ray to Left or not ...
*
* @param value: bool
*/
void LowerRayLeft(bool value)
{
mLower.RayLeft(value);
}
/**
* Specified Lower Ray to Right or not ...
*
* @param value: bool
*/
void LowerRayRight(bool value)
{
mLower.RayRight(value);
}
/**
* Set Width ...
*
* @param value: Integer ...
*/
void SupportWidth(int value)
{
//
if (value < 1)
{
value = 1;
}
//
if (mSupportBox == NULL)
{
return;
}
//
mSupportBox.BoxWidth(value);
}
/**
* Set Color ...
*
* @param value: Color ...
*/
void SupportColor(color value)
{
//
if (mSupportBox == NULL)
{
return;
}
//
mSupportBox.BoxColor(value);
}
/**
* Set Style ...
*
* @param value: ENUM_LINE_STYLE member ...
*/
void SupportStyle(ENUM_LINE_STYLE value)
{
//
if (mSupportBox == NULL)
{
return;
}
//
mSupportBox.BoxStyle(value);
}
/**
* Set Width ...
*
* @param value: Integer ...
*/
void ResistanceWidth(int value)
{
//
if (value < 1)
{
value = 1;
}
//
if (mResistanceBox == NULL)
{
return;
}
//
mResistanceBox.BoxWidth(value);
}
/**
* Set Color ...
*
* @param value: Color ...
*/
void ResistanceColor(color value)
{
//
if (mResistanceBox == NULL)
{
return;
}
//
mResistanceBox.BoxColor(value);
}
/**
* Set Style ...
*
* @param value: ENUM_LINE_STYLE member ...
*/
void ResistanceStyle(ENUM_LINE_STYLE value)
{
//
if (mResistanceBox == NULL)
{
return;
}
//
mResistanceBox.BoxStyle(value);
}
/**
* Set Width ...
*
* @param value: Integer ...
*/
void PeaksWidth(int value)
{
//
// Normalize ...
value = NormalizeInt(value, 1);
//
// Validate ...
int count = mPeaks.Total();
bool has = IsValidSize(count);
if (!has)
{
return;
}
//
XCBarArrowObject *iPeak;
for (int i = 0; i < count; i++)
{
//
iPeak = (XCBarArrowObject *)mPeaks.At(i);
iPeak.ArrowWidth(value);
ZeroMemory(iPeak);
}
}
/**
* Set Color ...
*
* @param value: Color ...
*/
void PeaksColor(color value)
{
//
// Validate ...
int count = mPeaks.Total();
bool has = IsValidSize(count);
if (!has)
{
return;
}
//
XCBarArrowObject *iPeak;
for (int i = 0; i < count; i++)
{
//
iPeak = (XCBarArrowObject *)mPeaks.At(i);
iPeak.ArrowColor(value);
ZeroMemory(iPeak);
}
}
/**
* Set Arrow Anchor ...
*
* @param value: ENUM_ARROW_ANCHOR member ...
*/
void PeaksAnchor(ENUM_ARROW_ANCHOR value)
{
//
// Validate ...
int count = mPeaks.Total();
bool has = IsValidSize(count);
if (!has)
{
return;
}
//
XCBarArrowObject *iPeak;
for (int i = 0; i < count; i++)
{
//
iPeak = (XCBarArrowObject *)mPeaks.At(i);
iPeak.ArrowAnchor(value);
ZeroMemory(iPeak);
}
}
/**
* Set Width ...
*
* @param value: Integer ...
*/
void ValesWidth(int value)
{
//
// Normalize ...
value = NormalizeInt(value, 1);
//
// Validate ...
int count = mVales.Total();
bool has = IsValidSize(count);
if (!has)
{
return;
}
//
XCBarArrowObject *iVale;
for (int i = 0; i < count; i++)
{
//
iVale = (XCBarArrowObject *)mVales.At(i);
iVale.ArrowWidth(value);
ZeroMemory(iVale);
}
}
/**
* Set Color ...
*
* @param value: Color ...
*/
void ValesColor(color value)
{
//
// Validate ...
int count = mVales.Total();
bool has = IsValidSize(count);
if (!has)
{
return;
}
//
XCBarArrowObject *iVale;
for (int i = 0; i < count; i++)
{
//
iVale = (XCBarArrowObject *)mVales.At(i);
iVale.ArrowColor(value);
ZeroMemory(iVale);
}
}
/**
* Set Arrow Anchor ...
*
* @param value: ENUM_ARROW_ANCHOR member ...
*/
void ValesAnchor(ENUM_ARROW_ANCHOR value)
{
//
// Validate ...
int count = mVales.Total();
bool has = IsValidSize(count);
if (!has)
{
return;
}
//
XCBarArrowObject *iVale;
for (int i = 0; i < count; i++)
{
//
iVale = (XCBarArrowObject *)mVales.At(i);
iVale.ArrowAnchor(value);
ZeroMemory(iVale);
}
}
//
private:
//
CArrayObj mPeaks;
CArrayObj mVales;
CChartObjectTrend mUpper;
CChartObjectTrend mLower;
XCBoxObject *mSupportBox;
XCBoxObject *mResistanceBox;
};
//
// Extensions ...
/**
* Add all Items of Specified CArrayObj into another ...
*
* @param source: CArrayObj, pointer refrence Specified Data Source ...
* @param dest: CArrayObj, pointer refrence Specified Destination of Adding ...
*/
void AddObjects(
CArrayObj *&source,
CArrayObj &dest //
)
{
//
bool has = source != NULL &&
source.Total() > 0;
if (!has)
{
return;
}
//
for (int i = 0; i < source.Total(); i++)
{
dest.Add(source.At(i));
}
}
/**
* Destroy Object if Exists ...
*
* @param object: pointer refrence to Destroy ...
*/
void DestroyObject(XCBoxObject *&object) {
//
// Validate ...
bool has = object != NULL;
if (!has) {
return;
}
//
object.Destroy();
//
object.Detach();
object.Delete();
//
delete object;
ZeroMemory(object);
}
/**
* Destroy Object if Exists ...
*
* @param object: pointer refrence to Destroy ...
*/
void DestroyObject(XCPivotAnalysisObject *&object) {
//
// Validate ...
bool has = object != NULL;
if (!has) {
return;
}
//
object.Destroy();
//
object.Detach();
object.Delete();
//
delete object;
ZeroMemory(object);
}
//