3478 lines
61 KiB
Plaintext
3478 lines
61 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/ChartObjectsFibo.mqh>
|
|
#include <ChartObjects/ChartObjectsLines.mqh>
|
|
#include <ChartObjects/ChartObjectsShapes.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;
|
|
}
|
|
|
|
//
|
|
// 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;
|
|
}
|
|
|
|
//
|
|
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,
|
|
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;
|
|
|
|
//
|
|
};
|
|
|
|
//
|
|
// 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 ...
|
|
* @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) + "_" + ToString(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;
|
|
}
|
|
};
|
|
|
|
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;
|
|
};
|
|
|
|
//
|
|
// 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;
|
|
|
|
//
|
|
};
|
|
|
|
// |