931 lines
18 KiB
Plaintext
931 lines
18 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 Class Library
|
|
// --------------------------------------
|
|
// Name: XPOIDrawer
|
|
// Description: Provides Point of Interests
|
|
// Drawing Tools ...
|
|
//
|
|
// 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
|
|
|
|
//
|
|
// Imports ...
|
|
#include "../Classes/x-saherelm.base.class.mq5"
|
|
#include "../Classes/x-saherelm.x-cobject.class.mq5"
|
|
#include "../Libraries/x-saherelm.x-poi.extensions.lib.mq5"
|
|
|
|
//
|
|
// Definitions ...
|
|
|
|
//
|
|
// Extensions ...
|
|
|
|
void AddObjects(
|
|
CArrayObj *&source,
|
|
CArrayObj &dest //
|
|
)
|
|
{
|
|
//
|
|
bool has = source != NULL &&
|
|
source.Total() > 0;
|
|
if (!has)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
for (int i = 0; i < source.Total(); i++)
|
|
{
|
|
dest.Add(source.At(i));
|
|
}
|
|
}
|
|
|
|
//
|
|
// Implementations ...
|
|
class XCPOIDrawer : public XCBase
|
|
{
|
|
//
|
|
public:
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
XPOIStyle defaultBullishStyle;
|
|
XPOIStyle defaultBearishStyle;
|
|
|
|
//
|
|
XPOIStyle boxBullishStyle;
|
|
XPOIStyle boxBearishStyle;
|
|
|
|
//
|
|
// Constructor ...
|
|
void XCPOIDrawer()
|
|
{
|
|
//
|
|
Default();
|
|
}
|
|
|
|
//
|
|
// Deconstructor ...
|
|
void ~XCPOIDrawer()
|
|
{
|
|
//
|
|
boxBullishStyle.Clean();
|
|
boxBearishStyle.Clean();
|
|
defaultBullishStyle.Clean();
|
|
defaultBearishStyle.Clean();
|
|
}
|
|
|
|
//
|
|
// Setter Getter (s) ...
|
|
|
|
/**
|
|
* Get Prefix ...
|
|
*
|
|
* @return ( string )
|
|
*/
|
|
string Prefix()
|
|
{
|
|
return mPrefix;
|
|
}
|
|
|
|
/**
|
|
* Set Prifx ...
|
|
*
|
|
* @param value: String ...
|
|
*/
|
|
void Prefix(string value)
|
|
{
|
|
mPrefix = value;
|
|
}
|
|
|
|
/**
|
|
* Get Chart ID ...
|
|
*
|
|
* @return ( long )
|
|
*/
|
|
long ChartIdentification()
|
|
{
|
|
return mChartIdentification;
|
|
}
|
|
|
|
/**
|
|
* Set Chart ID ...
|
|
*
|
|
* @param value: Long ...
|
|
*/
|
|
void ChartIdentification(long value)
|
|
{
|
|
//
|
|
if (value < 0)
|
|
{
|
|
value = 0;
|
|
}
|
|
|
|
//
|
|
mChartIdentification = value;
|
|
}
|
|
|
|
/**
|
|
* Get SubWindow Id ...
|
|
*
|
|
* @return ( int )
|
|
*/
|
|
int SubWindowIdentification()
|
|
{
|
|
return mSubWindowIdentification;
|
|
}
|
|
|
|
/**
|
|
* Set SubWindow Id ...
|
|
*
|
|
* @param value: Integer ...
|
|
*/
|
|
void SubWindowIdentification(int value)
|
|
{
|
|
//
|
|
if (value < 0)
|
|
{
|
|
value = 0;
|
|
}
|
|
|
|
//
|
|
mSubWindowIdentification = value;
|
|
}
|
|
|
|
//
|
|
// XOHCL ...
|
|
|
|
/**
|
|
* Get Bar Width ...
|
|
*
|
|
* @return ( int )
|
|
*/
|
|
int BarWidth()
|
|
{
|
|
return mBarWidth;
|
|
}
|
|
|
|
/**
|
|
* Set Bar Width ...
|
|
*
|
|
* @param value: Integer ...
|
|
*/
|
|
void BarWidth(int value)
|
|
{
|
|
//
|
|
if (value < 0)
|
|
{
|
|
value = 0;
|
|
}
|
|
|
|
//
|
|
mBarWidth = value;
|
|
}
|
|
|
|
/**
|
|
* Get Bar Bullish Color ...
|
|
*
|
|
* @return ( color )
|
|
*/
|
|
color BarBullishColor()
|
|
{
|
|
return mBarBullishColor;
|
|
}
|
|
|
|
/**
|
|
* Set Bar Bullish Color ...
|
|
*
|
|
* @param value: Color ...
|
|
*/
|
|
void BarBullishColor(color value)
|
|
{
|
|
mBarBullishColor = value;
|
|
}
|
|
|
|
/**
|
|
* Get Bar Bearish Color ...
|
|
*
|
|
* @return ( color )
|
|
*/
|
|
color BarBearishColor()
|
|
{
|
|
return mBarBearishColor;
|
|
}
|
|
|
|
/**
|
|
* Set Bar Bearish Color ...
|
|
*
|
|
* @param value: Color ...
|
|
*/
|
|
void BarBearishColor(color value)
|
|
{
|
|
mBarBearishColor = value;
|
|
}
|
|
|
|
/**
|
|
* Get Fill Bar High Shadow State ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool BarFillHighShadow()
|
|
{
|
|
return mBarFillHighShadow;
|
|
}
|
|
|
|
/**
|
|
* Set Fill Bar High Shadow State ...
|
|
*
|
|
* @param value: Boolean ...
|
|
*/
|
|
void BarFillHighShadow(bool value)
|
|
{
|
|
mBarFillHighShadow = value;
|
|
}
|
|
|
|
/**
|
|
* Get Bar High Shadow Style ...
|
|
*
|
|
* @return ( ENUM_LINE_STYLE )
|
|
*/
|
|
ENUM_LINE_STYLE BarHighShadowStyle()
|
|
{
|
|
return mBarHighShadowStyle;
|
|
}
|
|
|
|
/**
|
|
* Set Bar High Shadow Style ...
|
|
*
|
|
* @param value: ENUM_LINE_STYLE member ...
|
|
*/
|
|
void BarHighShadowStyle(ENUM_LINE_STYLE value)
|
|
{
|
|
mBarHighShadowStyle = value;
|
|
}
|
|
|
|
/**
|
|
* Get Fill Bar Body State ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool BarFillBody()
|
|
{
|
|
return mBarFillBody;
|
|
}
|
|
|
|
/**
|
|
* Set Fill Bar Body State ...
|
|
*
|
|
* @param value: Boolean ...
|
|
*/
|
|
void BarFillBody(bool value)
|
|
{
|
|
mBarFillBody = value;
|
|
}
|
|
|
|
/**
|
|
* Get Bar Body Style ...
|
|
*
|
|
* @return ( ENUM_LINE_STYLE )
|
|
*/
|
|
ENUM_LINE_STYLE BarBodyStyle()
|
|
{
|
|
return mBarBodyStyle;
|
|
}
|
|
|
|
/**
|
|
* Set Bar Body Style ...
|
|
*
|
|
* @param value: ENUM_LINE_STYLE member ...
|
|
*/
|
|
void BarBodyStyle(ENUM_LINE_STYLE value)
|
|
{
|
|
mBarBodyStyle = value;
|
|
}
|
|
|
|
/**
|
|
* Get Fill Bar Low Show State ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool BarFillLowShadow()
|
|
{
|
|
return mBarFillLowShadow;
|
|
}
|
|
|
|
/**
|
|
* Set Fill Bar Low Show State ...
|
|
*
|
|
* @param value: Boolean ...
|
|
*/
|
|
void BarFillLowShadow(bool value)
|
|
{
|
|
mBarFillLowShadow = value;
|
|
}
|
|
|
|
/**
|
|
* Get Bar Low Shadow Style ...
|
|
*
|
|
* @return ( ENUM_LINE_STYLE )
|
|
*/
|
|
ENUM_LINE_STYLE BarLowShadowStyle()
|
|
{
|
|
return mBarLowShadowStyle;
|
|
}
|
|
|
|
/**
|
|
* Set Bar Low Shadow Style ...
|
|
*
|
|
* @param value: ENUM_LINE_STYLE member ...
|
|
*/
|
|
void BarLowShadowStyle(ENUM_LINE_STYLE value)
|
|
{
|
|
mBarLowShadowStyle = value;
|
|
}
|
|
|
|
//
|
|
// Virtuals ...
|
|
|
|
/**
|
|
* Apply Default Configurations ...
|
|
*/
|
|
virtual void Default()
|
|
{
|
|
//
|
|
// Apply Default Props ...
|
|
|
|
//
|
|
Prefix(NULL);
|
|
ChartIdentification(0);
|
|
SubWindowIdentification(0);
|
|
|
|
//
|
|
BarWidth(1);
|
|
BarBearishColor(clrRed);
|
|
BarBullishColor(clrLime);
|
|
BarFillBody(false);
|
|
BarFillHighShadow(false);
|
|
BarFillLowShadow(false);
|
|
BarBodyStyle(STYLE_DOT);
|
|
BarLowShadowStyle(STYLE_DOT);
|
|
BarHighShadowStyle(STYLE_DOT);
|
|
|
|
//
|
|
defaultBullishStyle.width = 1;
|
|
defaultBullishStyle.clr = clrLime;
|
|
defaultBullishStyle.style = STYLE_SOLID;
|
|
|
|
//
|
|
defaultBearishStyle.width = 1;
|
|
defaultBearishStyle.clr = clrRed;
|
|
defaultBearishStyle.style = STYLE_SOLID;
|
|
|
|
//
|
|
boxBullishStyle = defaultBullishStyle;
|
|
boxBearishStyle = defaultBearishStyle;
|
|
}
|
|
|
|
//
|
|
// Object Creators ...
|
|
|
|
/**
|
|
* Create Bar Object ...
|
|
*
|
|
* @param bar: XOHCL instance Reference ...
|
|
* @param object: XCOHCLObject pointer Reference ..
|
|
* @param to: Datetime ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool CreateBar(
|
|
XOHCL &bar,
|
|
XCOHCLObject *&object,
|
|
datetime to = NULL //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
object = NULL;
|
|
|
|
//
|
|
result = bar.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
to = NormalizeTime(to);
|
|
|
|
//
|
|
string prefix = Prefix();
|
|
long chartID = ChartIdentification();
|
|
int window = SubWindowIdentification();
|
|
|
|
//
|
|
int width = BarWidth();
|
|
|
|
//
|
|
color mBullishColor = BarBullishColor();
|
|
color mBearishColor = BarBearishColor();
|
|
|
|
//
|
|
bool fillBody = BarFillBody();
|
|
bool fillHighShadow = BarFillHighShadow();
|
|
bool fillLowShadow = BarFillLowShadow();
|
|
|
|
//
|
|
ENUM_LINE_STYLE bodyStyle = BarBodyStyle();
|
|
ENUM_LINE_STYLE highShadowStyle = BarHighShadowStyle();
|
|
ENUM_LINE_STYLE lowShadowStyle = BarLowShadowStyle();
|
|
|
|
//
|
|
object = new XCOHCLObject();
|
|
result = object.Create(
|
|
chartID,
|
|
window,
|
|
bar,
|
|
to,
|
|
prefix //
|
|
);
|
|
if (result)
|
|
{
|
|
//
|
|
// Apply Styling ...
|
|
|
|
//
|
|
object.BodyWidth(width);
|
|
object.LowShadowWidth(width);
|
|
object.HighShadowWidth(width);
|
|
|
|
//
|
|
object.BodyStyle(bodyStyle);
|
|
object.LowShadowStyle(lowShadowStyle);
|
|
object.HighShadowStyle(highShadowStyle);
|
|
|
|
//
|
|
bool isBullish = bar.IsBullish();
|
|
if (isBullish)
|
|
{
|
|
//
|
|
object.BodyColor(mBullishColor);
|
|
object.LowShadowColor(mBullishColor);
|
|
object.HighShadowColor(mBullishColor);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
object.BodyColor(mBearishColor);
|
|
object.LowShadowColor(mBearishColor);
|
|
object.HighShadowColor(mBearishColor);
|
|
}
|
|
|
|
//
|
|
object.BodyFill(fillBody);
|
|
object.HighShadowFill(fillHighShadow);
|
|
object.LowShadowFill(fillLowShadow);
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Create Bar Arrow Object ...
|
|
*
|
|
* @param bar: XOHCL instance Reference ...
|
|
* @param priceType: ENUM_X_PRICE member ...
|
|
* @param arrow: int, Arrow Code ...
|
|
* @param clr: color, Arro Color ...
|
|
* @param width: int, Arrow Width ...
|
|
* @param anchor: ENUM_ARROW_ANCHOR, anchor of Arrow ...
|
|
* @param name: string, name of Arrow ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool CreateBarArrow(
|
|
XOHCL &bar,
|
|
XCBarArrowObject *&object,
|
|
ENUM_X_PRICE priceType,
|
|
int arrow = 159,
|
|
color clr = clrYellow,
|
|
int width = 3,
|
|
ENUM_ARROW_ANCHOR anchor = ANCHOR_BOTTOM,
|
|
string name = NULL //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
object = NULL;
|
|
|
|
//
|
|
result = bar.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
string barTag = bar.GetTag(name);
|
|
|
|
//
|
|
string prefix = Prefix();
|
|
long chartID = ChartIdentification();
|
|
int window = SubWindowIdentification();
|
|
|
|
//
|
|
color mBullishColor = BarBullishColor();
|
|
color mBearishColor = BarBearishColor();
|
|
|
|
//
|
|
prefix =
|
|
(IsValid(prefix)
|
|
? prefix + "_"
|
|
: prefix) +
|
|
barTag;
|
|
|
|
//
|
|
object = new XCBarArrowObject();
|
|
result = object
|
|
.CreateByBar(
|
|
chartID,
|
|
prefix,
|
|
window,
|
|
arrow,
|
|
bar,
|
|
priceType //
|
|
);
|
|
if (result)
|
|
{
|
|
//
|
|
object.ArrowColor(clr);
|
|
object.ArrowWidth(width);
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Create Specific Box on Chart ...
|
|
*
|
|
* @param upper: Double ...
|
|
* @param lower: Double ...
|
|
* @param from: Datetime ...
|
|
* @param to: Datetime ...
|
|
* @param clr: Color ...
|
|
* @param width: Integer ...
|
|
* @param fill: Boolean ...
|
|
* @param style: ENUM_LINE_STYLE member ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool CreateBox(
|
|
XCBoxObject *&object,
|
|
string name,
|
|
double upper,
|
|
double lower,
|
|
datetime from,
|
|
datetime to,
|
|
color clr = clrYellowGreen,
|
|
int width = 1,
|
|
bool fill = false,
|
|
ENUM_LINE_STYLE style = STYLE_SOLID //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
object = NULL;
|
|
|
|
//
|
|
to = NormalizeTime(to);
|
|
|
|
//
|
|
string dateStr = ToFormatString(from) + "|" + ToFormatString(to);
|
|
string dateMD5 = ToMD5(dateStr);
|
|
if (!IsValid(name))
|
|
{
|
|
//
|
|
name = "XBox_" +
|
|
ToString(upper) + "_" +
|
|
ToString(lower) + "_" +
|
|
dateMD5;
|
|
}
|
|
|
|
//
|
|
result =
|
|
upper > 0 &&
|
|
lower > 0 &&
|
|
to > from &&
|
|
IsValid(to) &&
|
|
IsValid(name) &&
|
|
IsValid(from) &&
|
|
upper > lower;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
string prefix = Prefix();
|
|
long chartID = ChartIdentification();
|
|
int window = SubWindowIdentification();
|
|
|
|
//
|
|
object = new XCBoxObject();
|
|
result = object.Create(
|
|
chartID,
|
|
window,
|
|
name,
|
|
upper,
|
|
lower,
|
|
from,
|
|
to,
|
|
prefix //
|
|
);
|
|
|
|
//
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
object.BoxColor(clr);
|
|
object.BoxFill(fill);
|
|
object.BoxWidth(width);
|
|
object.BoxStyle(style);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Create Specific Box on Chart ...
|
|
*
|
|
* @param box: XBoxZone instance Reference ...
|
|
* @param clr: Color ...
|
|
* @param width: Integer ...
|
|
* @param fill: Boolean ...
|
|
* @param style: ENUM_LINE_STYLE member ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool DrawBox(
|
|
XBoxZone &box,
|
|
XCBoxObject *&object //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
object = NULL;
|
|
|
|
//
|
|
result = box.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int width = 1;
|
|
bool fill = false;
|
|
color clr =
|
|
box.IsBullish()
|
|
? defaultBullishStyle.clr
|
|
: defaultBearishStyle.clr;
|
|
ENUM_LINE_STYLE style = STYLE_DASHDOTDOT;
|
|
string name = box.GetTag();
|
|
|
|
//
|
|
result = CreateBox(
|
|
object,
|
|
name,
|
|
box.upper,
|
|
box.lower,
|
|
box.from,
|
|
box.to,
|
|
clr,
|
|
width,
|
|
fill,
|
|
style //
|
|
);
|
|
|
|
//
|
|
if (result)
|
|
{
|
|
//
|
|
if (box.IsBullish())
|
|
{
|
|
//
|
|
ApplyStyle(
|
|
object,
|
|
boxBullishStyle //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
ApplyStyle(
|
|
object,
|
|
boxBearishStyle //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Create Specific Box on Chart ...
|
|
*
|
|
* @param box: XBoxZone instance Reference ...
|
|
* @param clr: Color ...
|
|
* @param width: Integer ...
|
|
* @param fill: Boolean ...
|
|
* @param style: ENUM_LINE_STYLE member ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool CreateBox(
|
|
XBoxZone &box,
|
|
XCBoxObject *&object,
|
|
color clr = clrYellowGreen,
|
|
int width = 1,
|
|
bool fill = false,
|
|
ENUM_LINE_STYLE style = STYLE_SOLID //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
object = NULL;
|
|
|
|
//
|
|
result = box.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
string name = box.GetTag();
|
|
|
|
//
|
|
result = CreateBox(
|
|
object,
|
|
name,
|
|
box.upper,
|
|
box.lower,
|
|
box.from,
|
|
box.to,
|
|
clr,
|
|
width,
|
|
fill,
|
|
style //
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Draw Specified Signal ...
|
|
*
|
|
* @param signal: XSignal instance ...
|
|
*/
|
|
bool DrawSignal(
|
|
XSignal &signal,
|
|
XCSignalObject *&object,
|
|
int length = 3 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
object = NULL;
|
|
length = NormalizeInt(length, 3);
|
|
|
|
//
|
|
result = signal.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
string prefix = Prefix();
|
|
long chartID = ChartIdentification();
|
|
int window = SubWindowIdentification();
|
|
|
|
//
|
|
object = new XCSignalObject();
|
|
result = object.Create(
|
|
chartID,
|
|
window,
|
|
signal,
|
|
length,
|
|
prefix //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
object.TPWidth(1);
|
|
object.TPColor(clrGreen);
|
|
object.TPWidth(STYLE_DOT);
|
|
|
|
//
|
|
object.SLWidth(1);
|
|
object.SLColor(clrRed);
|
|
object.SLWidth(STYLE_DOT);
|
|
|
|
//
|
|
object.TargetWidth(1);
|
|
object.TargetColor(clrLightBlue);
|
|
object.TargetWidth(STYLE_DOT);
|
|
|
|
//
|
|
object.EntryWidth(1);
|
|
object.EntryColor(clrYellow);
|
|
object.EntryWidth(STYLE_DOT);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Apply Specified Style to Object ...
|
|
*/
|
|
void ApplyStyle(
|
|
XCBoxObject *&object,
|
|
XPOIStyle &style //
|
|
)
|
|
{
|
|
//
|
|
bool has = object != NULL;
|
|
if (!has)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
object.BoxColor(style.clr);
|
|
object.BoxWidth(style.width);
|
|
object.BoxStyle(style.style);
|
|
}
|
|
|
|
//
|
|
protected:
|
|
//
|
|
|
|
//
|
|
private:
|
|
//
|
|
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
string mPrefix; // Prefix of Created Objects ...
|
|
long mChartIdentification; // Chart Id ...
|
|
int mSubWindowIdentification; // Sub Window ...
|
|
|
|
//
|
|
// XOHCL ...
|
|
int mBarWidth; // Bar Width ...
|
|
color mBarBullishColor; // Bar Bullish Color ...
|
|
color mBarBearishColor; // Bar Bearish Color ...
|
|
bool mBarFillHighShadow; // Fill Bar High Shadow ...
|
|
ENUM_LINE_STYLE mBarHighShadowStyle; // Bar High Shadow Style ...
|
|
bool mBarFillBody; // Fill Bar Body ...
|
|
ENUM_LINE_STYLE mBarBodyStyle; // Bar Body Style ...
|
|
bool mBarFillLowShadow; // Fill Bar Low Show ...
|
|
ENUM_LINE_STYLE mBarLowShadowStyle; // Bar Low Shadow Style ...
|
|
|
|
//
|
|
}; |