Files
MQL5Data/Classes/x-saherelm.x-cobject.class.mq5
T
2025-03-12 09:08:01 +03:30

3878 lines
69 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-poi.lib.mq5"
#include "../Libraries/x-saherelm.x-trade.lib.mq5"
//
#include <ChartObjects/ChartObject.mqh>
#include <ChartObjects/ChartObjectsArrows.mqh>
#include <ChartObjects/ChartObjectsLines.mqh>
#include <ChartObjects/ChartObjectsShapes.mqh>
#include <ChartObjects/ChartObjectsFibo.mqh>
#include <ChartObjects/ChartObjectsTxtControls.mqh>
//
// Definitions ...
enum ENUM_XCHARTOBJECTS
{
//
// Global ...
X_ZONE_OBJ = 7860,
X_BOX_OBJ = 7861,
X_BAR_ARROW_OBJ = 7862,
//
X_SIGNAL_OBJ = 8860,
X_TREND_OBJ = 8861,
X_XPVPIVOT_OBJ = 8862,
X_OHCL_OBJ = 8863,
X_RR_OBJ = 8864,
//
// Structured ...
X_TRADE_DAY_OBJ = 9860,
X_MARKET_SESSION_OBJ = 9861,
X_SWING_HIGH_OBJ = 9862,
X_SWING_LOW_OBJ = 9863,
X_BULLISH_MOMENTUM_BAR_OBJ = 9864,
X_BEARISH_MOMENTUM_BAR_OBJ = 9865,
X_BULLISH_REJECTION_BAR_OBJ = 9866,
X_BEARISH_REJECTION_BAR_OBJ = 9867,
X_SUPPORT_ZONE_OBJ = 9868,
X_RESISTANCE_ZONE_OBJ = 9869,
X_SUPPLY_ZONE_OBJ = 9870,
X_DEMAND_ZONE_OBJ = 9871,
X_BULLISH_ORDERBLOCK_OBJ = 9872,
X_BEARISH_ORDERBLOCK_OBJ = 9873,
X_BULLISH_FVG_OBJ = 9874,
X_BEARISH_FVG_OBJ = 9875,
X_TICK_ZONE_OBJ = 9876,
X_TICKS_ZONE_OBJ = 9877,
X_CONSOLIDATION_ZONE_OBJ = 9878,
};
enum ENUM_X_CHART_IDS
{
X_TO,
X_FROM,
X_UPPER,
X_LOWER,
X_ENTRY,
X_TARGET,
X_SL,
X_TP,
X_BAR_H_SHW,
X_BAR_BDY,
X_BAR_L_SHW,
};
string ToString(ENUM_X_CHART_IDS value)
{
//
string result = NULL;
//
switch (value)
{
//
case X_TO:
result = "TO";
break;
//
case X_FROM:
result = "FROM";
break;
//
case X_UPPER:
result = "UPPER";
break;
//
case X_LOWER:
result = "LOWER";
break;
//
case X_ENTRY:
result = "ENTRY";
break;
//
case X_TARGET:
result = "TARGET";
break;
//
case X_SL:
result = "SL";
break;
//
case X_TP:
result = "TP";
break;
//
case X_BAR_H_SHW:
result = "HSHW";
break;
//
case X_BAR_BDY:
result = "BODY";
break;
//
case X_BAR_L_SHW:
result = "LSHW";
break;
//
}
//
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;
}
//
private:
//
//
// Props ...
string mObjName; // Object Specified Name ...
//
};
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 //
)
{
//
bool result = false;
//
result =
//
bar.IsValid() &&
IsValid(name)
//
;
if (!result)
{
return result;
}
//
datetime time = bar.time;
double price = bar.GetPrice(priceType);
//
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;
//
};
//
// Swing ...
class XCSwingObject : public XCBarArrowObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param swing: XCSwing instance ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool CreateBySwing(
long chart_id,
int window,
int arrow,
XCSwing &swing,
string prefix = NULL //
)
{
//
bool result = false;
//
result =
//
swing.IsValid()
//
;
if (!result)
{
return result;
}
//
string name = swing.GetTag();
if (IsValid(prefix))
{
name = prefix + "_" + name;
}
//
XOHCL bar;
result = swing.FillBar(bar);
if (!result)
{
return result;
}
//
ENUM_X_PRICE price = swing.IsSwingHigh()
? X_PRICE_HIGH
: X_PRICE_LOW;
//
result = CreateByBar(
chart_id,
name,
window,
arrow,
bar,
price //
);
//
if (result)
{
ObjName(name);
}
//
return result;
}
};
//
// Swing High ...
class XCSwingHighObject : public XCSwingObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param arrow: Integer, Specified Arrow Code ...
* @param swing: XCSwing instance ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
int arrow,
XCSwing &swing,
string prefix = NULL //
)
{
//
bool result = false;
//
result = swing.IsValid() &&
swing.IsSwingHigh();
if (!result)
{
return result;
}
//
result = CreateBySwing(
chart_id,
window,
arrow,
swing,
prefix //
);
//
return result;
}
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_SWING_HIGH_OBJ;
}
//
};
//
// Swing Low ...
class XCSwingLowObject : public XCSwingObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param arrow: Integer, Specified Arrow Code ...
* @param swing: XCSwing instance ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
int arrow,
XCSwing &swing,
string prefix = NULL //
)
{
//
bool result = false;
//
result = swing.IsValid() &&
swing.IsSwingLow();
if (!result)
{
return result;
}
//
result = CreateBySwing(
chart_id,
window,
arrow,
swing,
prefix //
);
//
return result;
}
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_SWING_LOW_OBJ;
}
//
};
//
// Momentum ...
class XCMomentumBarObject : public XCBarArrowObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param momentumBar: XCMomentumBar instance ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool CreateByMomentum(
long chart_id,
int window,
int arrow,
XCMomentumBar &momentumBar,
string prefix = NULL //
)
{
//
bool result = false;
//
result =
//
momentumBar.IsValid()
//
;
if (!result)
{
return result;
}
//
string name = momentumBar.GetTag();
if (IsValid(prefix))
{
name = prefix + "_" + name;
}
//
XOHCL bar;
result = momentumBar.FillBar(bar);
if (!result)
{
return result;
}
//
ENUM_X_PRICE price = momentumBar.IsBullish()
? X_PRICE_LOW
: X_PRICE_HIGH;
//
result = CreateByBar(
chart_id,
name,
window,
arrow,
bar,
price //
);
//
if (result)
{
ObjName(name);
}
//
return result;
}
};
//
// Bullish Momentum Bar ...
class XCBullishMomentumBarObject : public XCMomentumBarObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param arrow: Integer, Specified Arrow Code ...
* @param momentumBar: XCMomentumBar instance ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
int arrow,
XCMomentumBar &momentumBar,
string prefix = NULL //
)
{
//
bool result = false;
//
result = momentumBar.IsValid() &&
momentumBar.IsBullish();
if (!result)
{
return result;
}
//
result = CreateByMomentum(
chart_id,
window,
arrow,
momentumBar,
prefix //
);
//
return result;
}
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_BULLISH_MOMENTUM_BAR_OBJ;
}
//
};
//
// Bearish Momentum Bar ...
class XCBearishMomentumBarObject : public XCMomentumBarObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param arrow: Integer, Specified Arrow Code ...
* @param momentumBar: XCMomentumBar instance ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
int arrow,
XCMomentumBar &momentumBar,
string prefix = NULL //
)
{
//
bool result = false;
//
result = momentumBar.IsValid() &&
momentumBar.IsBearish();
if (!result)
{
return result;
}
//
result = CreateByMomentum(
chart_id,
window,
arrow,
momentumBar,
prefix //
);
//
return result;
}
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_BEARISH_MOMENTUM_BAR_OBJ;
}
//
};
//
// Rejection ...
class XCRejectionBarObject : public XCBarArrowObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param rejectionBar: XCRejectionBar instance ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool CreateByRejection(
long chart_id,
int window,
int arrow,
XCRejectionBar &rejectionBar,
string prefix = NULL //
)
{
//
bool result = false;
//
result =
//
rejectionBar.IsValid()
//
;
if (!result)
{
return result;
}
//
string name = rejectionBar.GetTag();
if (IsValid(prefix))
{
name = prefix + "_" + name;
}
//
XOHCL bar;
result = rejectionBar.FillBar(bar);
if (!result)
{
return result;
}
//
ENUM_X_PRICE price = rejectionBar.IsBullish()
? X_PRICE_LOW
: X_PRICE_HIGH;
//
result = CreateByBar(
chart_id,
name,
window,
arrow,
bar,
price //
);
//
if (result)
{
ObjName(name);
}
//
return result;
}
};
//
// Bullish Rejection Bar ...
class XCBullishRejectionBarObject : public XCRejectionBarObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param arrow: Integer, Specified Arrow Code ...
* @param rejectionBar: XCRejectionBar instance ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
int arrow,
XCRejectionBar &rejectionBar,
string prefix = NULL //
)
{
//
bool result = false;
//
result = rejectionBar.IsValid() &&
rejectionBar.IsBullish();
if (!result)
{
return result;
}
//
result = CreateByRejection(
chart_id,
window,
arrow,
rejectionBar,
prefix //
);
//
return result;
}
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_BULLISH_REJECTION_BAR_OBJ;
}
//
};
//
// Bearish Rejection Bar ...
class XCBearishRejectionBarObject : public XCRejectionBarObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param arrow: Integer, Specified Arrow Code ...
* @param rejectionBar: XCRejectionBar instance ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
int arrow,
XCRejectionBar &rejectionBar,
string prefix = NULL //
)
{
//
bool result = false;
//
result = rejectionBar.IsValid() &&
rejectionBar.IsBearish();
if (!result)
{
return result;
}
//
result = CreateByRejection(
chart_id,
window,
arrow,
rejectionBar,
prefix //
);
//
return result;
}
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_BEARISH_REJECTION_BAR_OBJ;
}
//
};
//
// XCZoneObject ...
class XCZoneObject : public XCBaseObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param name: String, Specified Object Identifier on Chart ...
* @param window: Integer, Specified Chart Window ID ...
* @param zone: XCZone instance ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool CreateByZone(
long chart_id,
string name,
int window,
XCZone &zone,
string prefix = NULL //
)
{
//
bool result = false;
//
bool isValidFrom = zone.IsValidFrom();
bool isValidBoundary = zone.IsValidBoundary();
//
result =
//
IsValid(name) &&
isValidFrom &&
isValidBoundary
//
;
if (!result)
{
return result;
}
//
if (IsValid(prefix))
{
name = prefix + "_" + name;
}
//
datetime from = zone.From();
datetime to = NormalizeTime(zone.To());
//
double upper = zone.Upper();
double lower = zone.Lower();
//
result = mRect.Create(
chart_id,
name,
window,
from,
upper,
to,
lower //
);
//
if (result)
{
ObjName(name);
}
//
return result;
}
//
// Virtual ...
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_ZONE_OBJ;
}
//
// 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);
}
//
private:
//
CChartObjectRectangle mRect;
//
};
//
// Support Zone ...
class XCSupportZoneObject : public XCZoneObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param zone: XCSupportZone instance ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
XCSupportZone &zone,
string prefix = NULL //
)
{
//
bool result = false;
//
result = zone.IsValid();
if (!result)
{
return result;
}
//
string name = zone.GetTag();
//
result = CreateByZone(
chart_id,
name,
window,
zone,
prefix //
);
//
return result;
}
//
// Virtual ...
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_SUPPORT_ZONE_OBJ;
}
};
//
// Resistance Zone ...
class XCResistanceZoneObject : public XCZoneObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param zone: XCResistanceZone instance ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
XCResistanceZone &zone,
string prefix = NULL //
)
{
//
bool result = false;
//
result = zone.IsValid();
if (!result)
{
return result;
}
//
string name = zone.GetTag();
//
result = CreateByZone(
chart_id,
name,
window,
zone,
prefix //
);
//
return result;
}
//
// Virtual ...
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_RESISTANCE_ZONE_OBJ;
}
};
//
// Supply Zone ...
class XCSupplyZoneObject : public XCZoneObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param zone: XCSupplyZone instance ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
XCSupplyZone &zone,
string prefix = NULL //
)
{
//
bool result = false;
//
result = zone.IsValid();
if (!result)
{
return result;
}
//
string name = zone.GetTag();
//
result = CreateByZone(
chart_id,
name,
window,
zone,
prefix //
);
//
return result;
}
//
// Virtual ...
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_SUPPLY_ZONE_OBJ;
}
};
//
// Demand Zone ...
class XCDemandZoneObject : public XCZoneObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param zone: XCDemandZone instance ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
XCDemandZone &zone,
string prefix = NULL //
)
{
//
bool result = false;
//
result = zone.IsValid();
if (!result)
{
return result;
}
//
string name = zone.GetTag();
//
result = CreateByZone(
chart_id,
name,
window,
zone,
prefix //
);
//
return result;
}
//
// Virtual ...
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_DEMAND_ZONE_OBJ;
}
};
//
// Bullish Order Block ...
class XCBullishOrderBlockObject : public XCZoneObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param zone: XCOrderBlock instance ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
XCOrderBlock &zone,
string prefix = NULL //
)
{
//
bool result = false;
//
result = zone.IsValid() &&
zone.IsBullish();
if (!result)
{
return result;
}
//
string name = zone.GetTag();
//
result = CreateByZone(
chart_id,
name,
window,
zone,
prefix //
);
//
return result;
}
//
// Virtual ...
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_BULLISH_ORDERBLOCK_OBJ;
}
};
//
// Bearish Order Block ...
class XCBearishOrderBlockObject : public XCZoneObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param zone: XCOrderBlock instance ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
XCOrderBlock &zone,
string prefix = NULL //
)
{
//
bool result = false;
//
result = zone.IsValid() &&
zone.IsBearish();
if (!result)
{
return result;
}
//
string name = zone.GetTag();
//
result = CreateByZone(
chart_id,
name,
window,
zone,
prefix //
);
//
return result;
}
//
// Virtual ...
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_BULLISH_ORDERBLOCK_OBJ;
}
};
//
// Bullish Fair Value Gaps ...
class XCBullishFairValueGapObject : public XCZoneObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param zone: XCOrderBlock instance ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
XCFVG &zone,
string prefix = NULL //
)
{
//
bool result = false;
//
result = zone.IsValid() &&
zone.IsBullish();
if (!result)
{
return result;
}
//
string name = zone.GetTag();
//
result = CreateByZone(
chart_id,
name,
window,
zone,
prefix //
);
//
return result;
}
//
// Virtual ...
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_BULLISH_FVG_OBJ;
}
};
class XCConsolidationZoneObject : public XCBaseObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param zone: XConsolidationZone instance ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
XConsolidationZone &zone,
string prefix = NULL //
)
{
//
bool result = false;
//
result = zone.IsValid();
if (!result)
{
return result;
}
//
string name = zone.GetTag();
if (IsValid(prefix))
{
name = prefix + "_" + name;
}
//
result = mRect.Create(
chart_id,
name,
window,
zone.from,
zone.upper,
zone.to,
zone.lower //
);
//
if (result)
{
ObjName(name);
}
//
return result;
}
//
// Virtual ...
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_CONSOLIDATION_ZONE_OBJ;
}
//
// 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);
}
//
private:
//
CChartObjectRectangle mRect;
//
};
//
// Bearish Fair Value Gaps ...
class XCBearishFairValueGapObject : public XCZoneObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param zone: XCOrderBlock instance ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
XCFVG &zone,
string prefix = NULL //
)
{
//
bool result = false;
//
result = zone.IsValid() &&
zone.IsBearish();
if (!result)
{
return result;
}
//
string name = zone.GetTag();
//
result = CreateByZone(
chart_id,
name,
window,
zone,
prefix //
);
//
return result;
}
//
// Virtual ...
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_BEARISH_FVG_OBJ;
}
};
//
// 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 ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
const int window,
XSignal &signal,
string prefix = NULL //
)
{
//
bool result = false;
//
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) * 2);
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) + "_" + ToString(i) + "_" + nameMD5;
CChartObjectTrend *mTargetTrend;
mTargetTrend = new CChartObjectTrend();
result = mTargetTrend.Create(
chart_id,
targetName,
window,
time1,
signal.targets[i],
time2,
signal.targets[i] //
);
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;
};
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;
};
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,
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)
{
ObjName(name);
}
//
return result;
}
//
// Getter(s) / Setter(s) ...
/**
* Set Width ...
*
* @param value: Integer ...
*/
void BoxWidth(int value)
{
//
if (value < 1)
{
value = 1;
}
//
mRect.Width(value);
}
/**
* Set Color ...
*
* @param value: Color ...
*/
void BoxColor(color value)
{
mRect.Color(value);
}
/**
* Set Style ...
*
* @param value: ENUM_LINE_STYLE member ...
*/
void BoxStyle(ENUM_LINE_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 ...
CChartObjectRectangle mRect;
};
class XCRRObject : public XCBaseObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param rr: XRR instance Reference ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
XRR &rr,
string prefix = NULL //
)
{
//
bool result = false;
//
result = rr.IsValid();
if (!result)
{
return result;
}
//
string name = rr.GetTag();
if (IsValid(prefix))
{
name = prefix + "_" + name;
}
string nameMD5 = ToMD5(name);
//
bool isLong = IsLong(rr.type);
//
double price1 = rr.entry;
double price2 = rr.sl;
//
datetime time1 = rr.time;
datetime time2 = (datetime)((int)rr.time + 5 * PeriodSeconds(rr.period));
//
result = mFibo.Create(
chart_id,
name,
window,
time1,
price1,
time2,
price2 //
);
if (!result)
{
return result;
}
//
mRR = rr;
ObjName(name);
//
int tpsCount = ArraySize(rr.tps);
int levels = tpsCount + 2;
result = mFibo.LevelsCount(levels);
if (!result)
{
return result;
}
//
// Set Fibo Levels ...
//
result = mFibo.LevelValue(0, 0);
if (!result)
{
return result;
}
result = mFibo.LevelDescription(0, "SL");
if (!result)
{
return result;
}
//
result = mFibo.LevelValue(1, 1.0);
if (!result)
{
return result;
}
result = mFibo.LevelDescription(1, "Entry");
if (!result)
{
return result;
}
//
for (int i = 0; i < tpsCount; i++)
{
//
int idx = i + 2;
double level = 1.0 + rr.tps[i];
string description = "TP " + ToString(rr.tps[i]);
//
result = mFibo.LevelValue(
idx,
level //
);
if (!result)
{
break;
}
//
result = mFibo.LevelDescription(
idx,
description //
);
if (!result)
{
break;
}
}
if (!result)
{
return result;
}
//
return result;
}
//
// Getter(s) / Setter(s) ...
//
// Virtual ...
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_RR_OBJ;
}
//
private:
//
//
// Props ...
XRR mRR;
CChartObjectFibo mFibo;
//
bool SetSLProps(
int width = 1,
color clr = clrRed,
ENUM_LINE_STYLE style = STYLE_SOLID,
string description = "" //
)
{
//
bool result = false;
//
result = SetLevelProps(
0,
width,
clr,
style,
description //
);
//
return result;
}
//
bool SetEntryProps(
int width = 1,
color clr = clrOrange,
ENUM_LINE_STYLE style = STYLE_SOLID,
string description = "" //
)
{
//
bool result = false;
//
result = SetLevelProps(
0,
width,
clr,
style,
description //
);
//
return result;
}
//
bool SetTPProps(
double tpValue,
int width = 1,
color clr = clrLime,
ENUM_LINE_STYLE style = STYLE_SOLID,
string description = "" //
)
{
//
bool result = false;
//
int tpIDX = FindIndex(
tpValue,
mRR.tps //
);
result = IsValidIndex(tpIDX);
if (!result)
{
return result;
}
//
tpIDX += 2;
//
result = SetLevelProps(
tpIDX,
width,
clr,
style,
description //
);
//
return result;
}
//
bool SetLevelProps(
int id,
int width = 1,
color clr = clrYellow,
ENUM_LINE_STYLE style = STYLE_SOLID,
string description = "" //
)
{
//
bool result = false;
//
// Color ...
result = mFibo.LevelColor(
id,
clr //
);
if (!result)
{
return result;
}
//
// Style ...
result = mFibo.LevelStyle(
id,
style //
);
if (!result)
{
return result;
}
//
// Width ...
if (width > 0)
{
//
result = mFibo.LevelWidth(
id,
width //
);
if (!result)
{
return result;
}
}
//
// Description ...
if (IsValid(description))
{
//
result = mFibo.LevelDescription(
id,
description //
);
if (!result)
{
return result;
}
}
//
return result;
}
};
class XCTrendObject : public XCBaseObject
{
//
public:
//
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param rr: XRR instance Reference ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
XPoint &swings[],
bool useMinAsStart = true,
string prefix = NULL //
)
{
//
bool result = false;
//
int count = ArraySize(swings);
result =
count >= 2 &&
IsValidSize(count);
if (!result)
{
return result;
}
//
double min = 0;
datetime minAt = NULL;
//
double max = 0;
datetime maxAt = NULL;
//
// Etract Min/Max ...
for (int i = 0; i < count; i++)
{
//
XPoint iPoint = swings[i];
//
if (!iPoint.IsValid())
{
//
iPoint.Clean();
continue;
}
//
bool canSetMin =
min == 0
? true
: min > iPoint.value;
if (canSetMin)
{
//
minAt = iPoint.at;
min = iPoint.value;
}
//
bool canSetMax =
max == 0
? true
: max < iPoint.value;
if (canSetMax)
{
//
maxAt = iPoint.at;
max = iPoint.value;
}
//
iPoint.Clean();
}
//
double first =
useMinAsStart
? min
: max;
datetime firstTime =
useMinAsStart
? minAt
: maxAt;
//
double second =
useMinAsStart
? max
: min;
datetime secondTime =
useMinAsStart
? maxAt
: minAt;
//
// Validate Points ...
result =
//
first > 0 &&
second > 0 &&
(useMinAsStart
? first <= second
: first >= second) &&
IsSpecifiedValid(firstTime) &&
IsSpecifiedValid(secondTime)
//
;
if (!result)
{
return result;
}
//
ENUM_X_DIRECTION dir =
useMinAsStart
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
//
string name = "XTRND" + ToString(dir) + "_" + ToString(first) + "_" + ToString(second);
if (IsValid(prefix))
{
name = prefix + "_" + name;
}
string nameMD5 = ToMD5(name);
//
result = mTrend.Create(
chart_id,
name,
window,
firstTime,
first,
secondTime,
second //
);
if (!result)
{
return result;
}
//
ObjName(name);
//
return result;
}
/**
* Creator ...
*
* @param chart_id: Long, Specified Chart ID ...
* @param window: Integer, Specified Chart Window ID ...
* @param rr: XRR instance Reference ...
* @param prefix: String ...
*
* @return ( bool )
*/
bool Create(
long chart_id,
int window,
XSwingPoint &swings[],
string prefix = NULL //
)
{
//
bool result = false;
//
int count = ArraySize(swings);
result =
count >= 2 &&
IsValidSize(count);
if (!result)
{
return result;
}
//
ENUM_X_SWING_TYPE type = swings[0].type;
bool isSwingLows = type == X_SWING_LOW;
//
double values[];
int valuesCount = ExtractSwings(
swings,
values //
);
result = valuesCount == count;
if (!result)
{
return result;
}
//
int firstIDX = -1;
double first = 0;
datetime firstTime = NULL;
//
int secondIDX = -1;
double second = 0;
datetime secondTime = NULL;
//
if (isSwingLows)
{
//
first = GetMin(
values,
firstIDX,
0,
0 //
);
if (IsValidIndex(firstIDX))
{
//
firstTime = swings[firstIDX].time;
//
second = FindBiggerThan(
first,
values,
true //
);
secondIDX = FindIndex(
second,
values //
);
if (IsValidIndex(secondIDX))
{
secondTime = swings[secondIDX].time;
}
}
}
else
{
//
first = GetMax(
values,
firstIDX,
0,
0 //
);
if (IsValidIndex(firstIDX))
{
//
firstTime = swings[firstIDX].time;
//
second = FindLesserThan(
first,
values,
true //
);
secondIDX = FindIndex(
second,
values //
);
if (IsValidIndex(secondIDX))
{
secondTime = swings[secondIDX].time;
}
}
}
//
// Validate Points ...
result =
//
IsValidIndex(firstIDX) &&
IsValidIndex(secondIDX) &&
//
IsSpecifiedValid(firstTime) &&
IsSpecifiedValid(secondTime) &&
//
(isSwingLows
? first < second
: first > second)
//
;
if (!result)
{
return result;
}
//
string name = ToString(type) + "_" + ToString(first) + "_" + ToString(second);
if (IsValid(prefix))
{
name = prefix + "_" + name;
}
string nameMD5 = ToMD5(name);
//
result = mTrend.Create(
chart_id,
name,
window,
firstTime,
first,
secondTime,
second //
);
if (!result)
{
return result;
}
//
ObjName(name);
//
return result;
}
//
// Getter(s) / Setter(s) ...
/**
* Set Trend Color ...
*
* @param value: Color ...
*/
void TrendColor(color value)
{
mTrend.Color(value);
}
void TrendRayLeft(bool value)
{
mTrend.RayLeft(value);
}
void TrendRayRight(bool value)
{
mTrend.RayRight(value);
}
//
// Virtual ...
/**
* Retrieve Object Type ...
*
* @return ( ENUM_XCHARTOBJECTS )
*/
virtual ENUM_XCHARTOBJECTS Type()
{
return X_TREND_OBJ;
}
//
private:
//
//
// Props ...
CChartObjectTrend mTrend;
};
//
// Zone Ticks ...
//
// Specify How to Draws Specified Levels ...
struct XTickZoneLevelSpecs
{
//
double percent; // Max Allowed Percent of Tick Zone ...
//
// Label Info ...
color labelColor;
string labelFont;
int labelFontSize;
double labelAngel;
//
// Zone Info ...
bool zoneFill;
int zoneWidth;
color zoneColor;
ENUM_LINE_STYLE zoneStyle;
//
// Constructor ...
XTickZoneLevelSpecs()
{
Default();
}
//
// Tools ...
/**
* Initialize Drawing Specs ...
*
* @param _percent: Double, Max Allowed Percent ...
* @param _labelColor: Color, Specified Label Color ...
* @param _zoneColoe: Color, Specified Zone Color ...
* @param _zoneFill: Boolean, Specified Fill Zone or not ...
* @param _zoneStyle: ENUM_LINE_STYLE member, Specified Zone Style ...
* @param _labelFontSize: Integer, Specified Label Font Size ...
* @param _labelFont: String, Specified Label Font Name ...
* @param _labelAngel: Double, Specified Label Angel ...
*
* @return ( bool )
*/
bool Init(
double _percent,
color _labelColor = clrWhite,
color _zoneColor = clrWhite,
bool _zoneFill = false,
ENUM_LINE_STYLE _zoneStyle = STYLE_DOT,
int _zoneWidth = 1,
int _labelFontSize = 12,
string _labelFont = "Arial",
double _labelAngel = 0 //
)
{
//
bool result = false;
//
Default();
//
result = _percent > 0;
if (!result)
{
return result;
}
//
percent = _percent;
labelColor = _labelColor;
zoneColor = _zoneColor;
zoneFill = _zoneFill;
zoneStyle = _zoneStyle;
//
if (_zoneWidth > 0)
{
zoneWidth = _zoneWidth;
}
//
if (_labelFontSize > 0)
{
labelFontSize = _labelFontSize;
}
//
if (IsSpecifiedValid(_labelFont))
{
labelFont = _labelFont;
}
//
if (_labelAngel >= 0)
{
labelAngel = _labelAngel;
}
//
result = IsValid();
//
return result;
}
/**
* Set Default Properties ...
*/
void Default()
{
//
percent = 0;
//
// Label ...
labelAngel = 0;
labelFontSize = 13;
labelFont = "Arial";
labelColor = clrWhite;
//
// Zone ...
zoneWidth = 1;
zoneFill = false;
zoneColor = clrWhite;
zoneStyle = STYLE_DOT;
}
/**
* Validate ...
*
* @return ( bool )
*/
bool IsValid()
{
//
bool result = false;
//
result =
//
percent > 0 &&
//
// Zone ...
zoneWidth > 0 &&
//
// Label ...
labelFontSize > 0 &&
IsSpecifiedValid(labelFont)
//
;
//
return result;
}
//
};
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;
}
//
double points = GetPoints(zone.symbol);
if (points <= 0)
{
points = 1;
}
double distance = 1 * points;
//
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;
}
//
int fromToDiff = ((int)to - (int)from);
datetime labelsDate = (datetime)((int)to - (fromToDiff / 5));
//
string lblName = "LBLT_" + name;
result = mTLabel.Create(
chart_id,
lblName,
window,
labelsDate,
zone.high - distance //
);
if (!result)
{
return result;
}
//
mTLabel.Description("T: " + ToString(zone.percent) + "%");
//
string lblVName = "LBLV_" + name;
result = mVLabel.Create(
chart_id,
lblVName,
window,
labelsDate,
zone.low + (2.5 * distance) //
);
if (!result)
{
return result;
}
//
mVLabel.Description("V: " + ToString(zone.volumePercent) + "%");
//
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)
{
//
mTLabel.Color(value);
mVLabel.Color(value);
}
/**
* Set Label Size ...
*
* @param value: Integer ...
*/
void LabelSize(int value)
{
//
mTLabel.FontSize(value);
mVLabel.FontSize(value);
}
/**
* Set Label Font ...
*
* @param value: String ...
*/
void LabelFont(string value)
{
//
mTLabel.Font(value);
mVLabel.Font(value);
}
/**
* Set Label Angle ...
*
* @param value: double ...
*/
void LabelAngle(double value)
{
//
mTLabel.Angle(value);
mVLabel.Angle(value);
}
//
private:
//
// Props ...
CChartObjectRectangle mRect;
CChartObjectLabel mTLabel;
CChartObjectLabel mVLabel;
//
};
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,
XTickZoneLevelSpecs &specs[],
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();
bool isCreated = iObj.Create(
chart_id,
window,
ToString(i) + "_" + name,
zone.From(),
zone.To(),
iZone,
prefix //
);
if (!isCreated)
{
break;
}
//
XTickZoneLevelSpecs iSpec;
bool hasSpecs = FindSpecs(
iZone,
iSpec,
specs //
);
if (hasSpecs)
{
//
// Label ...
iObj.LabelFont(iSpec.labelFont);
iObj.LabelAngle(iSpec.labelAngel);
iObj.LabelColor(iSpec.labelColor);
iObj.LabelSize(iSpec.labelFontSize);
//
// Zone ...
iObj.ZoneFill(iSpec.zoneFill);
iObj.ZoneColor(iSpec.zoneColor);
iObj.ZoneWidth(iSpec.zoneWidth);
iObj.ZoneStyle(iSpec.zoneStyle);
}
//
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 ...
/**
* Destroy Object ...
*/
void Destroy()
{
mZones.Clear();
}
/**
* Find Specified TickZone Drawing Specs ...
*
* @param zone: XCTickZone instance, reference to Search For it ...
* @param spec: XTickZoneLevelSpecs instance, reference to Result ...
* @param specs: XTickZoneLevelSpecs instance Collection for Search ...
*
* @return ( bool )
*/
bool FindSpecs(
XCTickZone *zone,
XTickZoneLevelSpecs &spec,
XTickZoneLevelSpecs &specs[] //
)
{
//
bool result = false;
//
int count = ArraySize(specs);
result =
zone.IsValid() &&
IsValidSize(count);
if (!result)
{
return result;
}
//
for (int i = 0; i < count; i++)
{
//
XTickZoneLevelSpecs iSpecs = specs[i];
//
bool isSpecValidForZone =
!spec.IsValid()
? zone.percent <= iSpecs.percent
: zone.percent <= iSpecs.percent &&
spec.percent > iSpecs.percent;
if (isSpecValidForZone)
{
spec = iSpecs;
}
}
//
result = spec.IsValid();
//
return result;
}
//
private:
//
// Props ...
CArrayObj mZones;
//
};
//