last works on Position ...
This commit is contained in:
@@ -522,8 +522,9 @@ bool XUpdatePosition(
|
||||
//
|
||||
// Global Chart Objects ...
|
||||
|
||||
//
|
||||
// Bas Chart Object ...
|
||||
/**
|
||||
* Base Chart Object ...
|
||||
**/
|
||||
class XCBaseObject : public CChartObject
|
||||
{
|
||||
//
|
||||
@@ -591,8 +592,9 @@ class XCBaseObject : public CChartObject
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Bar Arrow Object ...
|
||||
/**
|
||||
* Bar Arrow Object ...
|
||||
**/
|
||||
class XCBarArrowObject : public XCBaseObject
|
||||
{
|
||||
//
|
||||
@@ -749,8 +751,9 @@ class XCBarArrowObject : public XCBaseObject
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Signal ...
|
||||
/**
|
||||
* Signal Object ...
|
||||
**/
|
||||
class XCSignalObject : public XCBaseObject
|
||||
{
|
||||
//
|
||||
@@ -1147,8 +1150,9 @@ class XCSignalObject : public XCBaseObject
|
||||
CArrayObj mTargetTrends;
|
||||
};
|
||||
|
||||
//
|
||||
// XRR Object ...
|
||||
/**
|
||||
* XRR Object ...
|
||||
**/
|
||||
class XCRRObject : public XCSignalObject
|
||||
{
|
||||
//
|
||||
@@ -1229,8 +1233,9 @@ class XCRRObject : public XCSignalObject
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// OHCL, Bar Object ...
|
||||
/**
|
||||
* XOHCL Object ...
|
||||
**/
|
||||
class XCOHCLObject : public XCBaseObject
|
||||
{
|
||||
//
|
||||
@@ -1575,8 +1580,9 @@ class XCOHCLObject : public XCBaseObject
|
||||
CChartObjectRectangle mLowShadowRect;
|
||||
};
|
||||
|
||||
//
|
||||
// Box Object ...k
|
||||
/**
|
||||
* Box Object ...
|
||||
**/
|
||||
class XCBoxObject : public XCBaseObject
|
||||
{
|
||||
//
|
||||
@@ -1786,16 +1792,35 @@ class XCBoxObject : public XCBaseObject
|
||||
CChartObjectRectangle mRect;
|
||||
};
|
||||
|
||||
/**
|
||||
* Position Object ...
|
||||
**/
|
||||
class XCPositionObject : public XCBaseObject
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
XPOIStyle riskStyle; // Risk Box Style ...
|
||||
color inProfitColor; // In Profit Price Box Color ...
|
||||
color inDrawdownColor; // In Drawdown Price Box Color ...
|
||||
XPOIStyle rewardStyle; // Reward Box Style ...
|
||||
ENUM_LINE_STYLE priceStyle; // Price Box Style ...
|
||||
|
||||
//
|
||||
// Creators ...
|
||||
|
||||
/**
|
||||
* Create a Position Object by Signal reference ...
|
||||
*
|
||||
* @param chart_id: Long, Specified Chart ID ...
|
||||
* @param window: Integer, Specified Chart Window ID ...
|
||||
* @param signal: XSignal, reference to Provided Signal ...
|
||||
* @param magic: ulong, Specified Position Magic Number ...
|
||||
* @param ticket: ulong, Specified Position Ticket ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool Create(
|
||||
long chart_id,
|
||||
int window,
|
||||
@@ -1883,14 +1908,22 @@ class XCPositionObject : public XCBaseObject
|
||||
* Update Position if Belongs to ...
|
||||
*
|
||||
* @param position: XPosition, reference to Specified Position ...
|
||||
* @param barIndex: int, Specified Bar Index ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool Update(XPosition &position)
|
||||
bool Update(
|
||||
XPosition &position,
|
||||
int barIndex = 0 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize ...
|
||||
barIndex = NormalizeInt(barIndex, 0);
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result =
|
||||
@@ -1905,14 +1938,31 @@ class XCPositionObject : public XCBaseObject
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
datetime _toTime = GetBarTime(
|
||||
position.symbol,
|
||||
position.period,
|
||||
barIndex //
|
||||
);
|
||||
|
||||
//
|
||||
// Validate Chart Info ...
|
||||
result = XUpdatePosition(position);
|
||||
result = UpdatePosition(
|
||||
position,
|
||||
_toTime //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Position if Belongs to ...
|
||||
*
|
||||
* @param barIndex: int, Specified Bar Index ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool Update(int barIndex = 0)
|
||||
{
|
||||
//
|
||||
@@ -1939,7 +1989,10 @@ class XCPositionObject : public XCBaseObject
|
||||
}
|
||||
|
||||
//
|
||||
result = Update(mPosition);
|
||||
result = Update(
|
||||
mPosition,
|
||||
barIndex //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -2056,6 +2109,66 @@ class XCPositionObject : public XCBaseObject
|
||||
//
|
||||
// Stylers ...
|
||||
|
||||
/**
|
||||
* Apply Styles based on Current Style Configurations ...
|
||||
*/
|
||||
void ApplyStyle()
|
||||
{
|
||||
//
|
||||
bool has = HasPosition();
|
||||
if (!has)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Risk Style ...
|
||||
mRiskBoxObj.BoxColor(riskStyle.clr);
|
||||
mRiskBoxObj.BoxFill(riskStyle.fill);
|
||||
mRiskBoxObj.BoxStyle(riskStyle.style);
|
||||
mRiskBoxObj.BoxWidth(riskStyle.width);
|
||||
|
||||
//
|
||||
// Reward Style ...
|
||||
mRewardBoxObj.BoxColor(rewardStyle.clr);
|
||||
mRewardBoxObj.BoxFill(rewardStyle.fill);
|
||||
mRewardBoxObj.BoxStyle(rewardStyle.style);
|
||||
mRewardBoxObj.BoxWidth(rewardStyle.width);
|
||||
|
||||
//
|
||||
// Check Position in Profit ...
|
||||
bool isInProfit = mPosition.profit > 0;
|
||||
XPOIStyle _priceStyle;
|
||||
if (isInProfit)
|
||||
{
|
||||
//
|
||||
_priceStyle = rewardStyle;
|
||||
_priceStyle.clr = inProfitColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
_priceStyle = riskStyle;
|
||||
_priceStyle.clr = inDrawdownColor;
|
||||
}
|
||||
|
||||
//
|
||||
// Apply Profit Based Styles ...
|
||||
_priceStyle.fill = true;
|
||||
_priceStyle.style = priceStyle;
|
||||
|
||||
//
|
||||
// Price Style ..
|
||||
mPriceBoxObj.BoxColor(_priceStyle.clr);
|
||||
mPriceBoxObj.BoxFill(_priceStyle.fill);
|
||||
mPriceBoxObj.BoxStyle(_priceStyle.style);
|
||||
mPriceBoxObj.BoxWidth(_priceStyle.width);
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
_priceStyle.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
void ApplyStyle(
|
||||
XPOIStyle &bullishStyle,
|
||||
@@ -2096,24 +2209,24 @@ class XCPositionObject : public XCBaseObject
|
||||
if (mPriceBox.IsValid())
|
||||
{
|
||||
//
|
||||
XPOIStyle priceStyle;
|
||||
XPOIStyle _priceStyle;
|
||||
if (mPriceBox.IsBullish())
|
||||
{
|
||||
priceStyle = bullishStyle;
|
||||
_priceStyle = bullishStyle;
|
||||
}
|
||||
else
|
||||
{
|
||||
priceStyle = bearishStyle;
|
||||
_priceStyle = bearishStyle;
|
||||
}
|
||||
|
||||
//
|
||||
mPriceBoxObj.BoxColor(priceStyle.clr);
|
||||
mPriceBoxObj.BoxFill(priceStyle.fill);
|
||||
mPriceBoxObj.BoxStyle(priceStyle.style);
|
||||
mPriceBoxObj.BoxWidth(priceStyle.width);
|
||||
mPriceBoxObj.BoxColor(_priceStyle.clr);
|
||||
mPriceBoxObj.BoxFill(_priceStyle.fill);
|
||||
mPriceBoxObj.BoxStyle(_priceStyle.style);
|
||||
mPriceBoxObj.BoxWidth(_priceStyle.width);
|
||||
|
||||
//
|
||||
priceStyle.Clean();
|
||||
_priceStyle.Clean();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2129,11 +2242,18 @@ class XCPositionObject : public XCBaseObject
|
||||
}
|
||||
|
||||
//
|
||||
bool UpdatePosition(XPosition &_position)
|
||||
bool UpdatePosition(
|
||||
XPosition &_position,
|
||||
datetime _toTime = NULL //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize ...
|
||||
_toTime = NormalizeTime(_toTime);
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = _position.IsValid() &&
|
||||
@@ -2148,18 +2268,22 @@ class XCPositionObject : public XCBaseObject
|
||||
|
||||
//
|
||||
mPosition = _position;
|
||||
result = UpdateZones();
|
||||
result = UpdateZones(_toTime);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool UpdateZones()
|
||||
bool UpdateZones(datetime _toTime = NULL)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize ...
|
||||
_toTime = NormalizeTime(_toTime);
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = HasPosition();
|
||||
@@ -2175,7 +2299,12 @@ class XCPositionObject : public XCBaseObject
|
||||
//
|
||||
datetime iAt = mPosition.openAt;
|
||||
datetime iFrom = mPosition.openAt;
|
||||
datetime iTo = iFrom + (PeriodSeconds(iPeriod) * 3);
|
||||
|
||||
//
|
||||
datetime _defaultToTime = iFrom + (PeriodSeconds(iPeriod) * 3);
|
||||
datetime iTo = _toTime <= _defaultToTime
|
||||
? _defaultToTime
|
||||
: _toTime;
|
||||
|
||||
//
|
||||
double iTP = mPosition.tp;
|
||||
@@ -2333,9 +2462,14 @@ class XCPositionObject : public XCBaseObject
|
||||
isRiskCreated &&
|
||||
isPriceCreated &&
|
||||
isRewardCreated;
|
||||
if (!result)
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
ObjName(iName);
|
||||
|
||||
//
|
||||
// Apply Styles ...
|
||||
ApplyStyle();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -3585,4 +3719,37 @@ void RemoveObjects(
|
||||
ChartRedraw();
|
||||
}
|
||||
|
||||
//
|
||||
// Color Manipulation Functions ...
|
||||
|
||||
/**
|
||||
* Apply Alph to Color ...
|
||||
*
|
||||
* @param _clr: Specified Color ...
|
||||
* @param _alpha: Specified Alpha to Apply ...
|
||||
*
|
||||
* @return ( color )
|
||||
*/
|
||||
color ApplyAlpha(
|
||||
color _clr,
|
||||
uchar _alpha = 255 //
|
||||
)
|
||||
{
|
||||
//
|
||||
color result = _clr;
|
||||
|
||||
//
|
||||
// Normalize ...
|
||||
_alpha = (uchar)NormalizeInt(_alpha, 0, 255);
|
||||
|
||||
//
|
||||
uchar alpha = _alpha / 255;
|
||||
|
||||
//
|
||||
uint uintColor = ColorToARGB(_clr, alpha);
|
||||
result = (color)uintColor;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//
|
||||
@@ -40,11 +40,16 @@ class XCPositionDrawer : public XCBase
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
int window;
|
||||
ulong chartID;
|
||||
XCTrade *trader;
|
||||
CArrayObj positionObjects;
|
||||
CArrayObj finalizedObjects;
|
||||
int window; // Window ID of Chart ...
|
||||
ulong chartID; // Chart ID ...
|
||||
XCTrade *trader; // XCTrade Instance ...
|
||||
XPOIStyle riskStyle; // Risk Box Style ...
|
||||
color inProfitColor; // In Profit Price Box Color ...
|
||||
color inDrawdownColor; // In Drawdown Price Box Color ...
|
||||
ENUM_LINE_STYLE priceStyle; // Price Box Style ...
|
||||
XPOIStyle rewardStyle; // Reward Box Style ...
|
||||
CArrayObj positionObjects; // Drawn Positions Object Instances Collection ...
|
||||
CArrayObj finalizedObjects; // Finalized Drawn Positions Object Instances Collection ...
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
@@ -72,6 +77,13 @@ class XCPositionDrawer : public XCBase
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Initialize Class Instance ...
|
||||
*
|
||||
* @param _trader: XCTrade, reference Pointer to Trader Instance Class ...
|
||||
* @param _chartID: ulong, Specified Chart ID ...
|
||||
* @param _window: int, Specified Chart Window ID ...
|
||||
*/
|
||||
void Init(
|
||||
XCTrade *_trader,
|
||||
ulong _chartID = 0,
|
||||
@@ -93,12 +105,48 @@ class XCPositionDrawer : public XCBase
|
||||
trader = _trader;
|
||||
window = _window;
|
||||
chartID = _chartID;
|
||||
|
||||
//
|
||||
// Prepare Default Styles ...
|
||||
|
||||
//
|
||||
// Risk Style ...
|
||||
riskStyle.width = 1;
|
||||
riskStyle.fill = false;
|
||||
riskStyle.clr = clrRed;
|
||||
riskStyle.style = STYLE_DASH;
|
||||
|
||||
//
|
||||
// Reward Style ...
|
||||
rewardStyle.width = 1;
|
||||
rewardStyle.fill = false;
|
||||
rewardStyle.clr = clrLime;
|
||||
rewardStyle.style = STYLE_DASH;
|
||||
|
||||
//
|
||||
// Price Style ...
|
||||
priceStyle = STYLE_SOLID;
|
||||
inProfitColor = ApplyAlpha(clrAqua, 100);
|
||||
inDrawdownColor = ApplyAlpha(clrMagenta, 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Instance ...
|
||||
*/
|
||||
void Destroy()
|
||||
{
|
||||
//
|
||||
riskStyle.Clean();
|
||||
rewardStyle.Clean();
|
||||
// positionObjects
|
||||
// finalizedObjects
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Instance ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
@@ -112,6 +160,11 @@ class XCPositionDrawer : public XCBase
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Positions ...
|
||||
*
|
||||
* @param barIndex: int, Specified Bar Index ...
|
||||
*/
|
||||
void Update(int barIndex = 0)
|
||||
{
|
||||
//
|
||||
@@ -138,6 +191,7 @@ class XCPositionDrawer : public XCBase
|
||||
has = IsValidSize(drawingsCount);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
@@ -148,7 +202,9 @@ class XCPositionDrawer : public XCBase
|
||||
has = ((XCPositionObject *)positionObjects.At(j)).IsBelong(positions[i]);
|
||||
if (has)
|
||||
{
|
||||
((XCPositionObject *)positionObjects.At(j)).Update(positions[i]);
|
||||
//
|
||||
// Update Position Object ...
|
||||
has = ((XCPositionObject *)positionObjects.At(j)).Update(positions[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -174,7 +230,7 @@ class XCPositionDrawer : public XCBase
|
||||
{
|
||||
//
|
||||
// Manully Update Position ...
|
||||
((XCPositionObject *)positionObjects.At(i)).Update(barIndex);
|
||||
has = ((XCPositionObject *)positionObjects.At(i)).Update(barIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,12 +286,26 @@ class XCPositionDrawer : public XCBase
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
XCPositionObject *iObj;
|
||||
XCPositionObject *iObj = new XCPositionObject();
|
||||
has = iObj.Create(
|
||||
chartID,
|
||||
window,
|
||||
iPosition //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Set Stylers to Position ...
|
||||
iObj.riskStyle = riskStyle;
|
||||
iObj.priceStyle = priceStyle;
|
||||
iObj.rewardStyle = rewardStyle;
|
||||
iObj.inProfitColor = inProfitColor;
|
||||
iObj.inDrawdownColor = inDrawdownColor;
|
||||
|
||||
//
|
||||
// Add to Collection ...
|
||||
positionObjects.Add(iObj);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -284,7 +354,12 @@ class XCPositionDrawer : public XCBase
|
||||
protected:
|
||||
//
|
||||
|
||||
//
|
||||
/**
|
||||
* Finalize Specified Position ...
|
||||
* Remove it From Position Objects and add it to Finalized Objects Cllection ...
|
||||
*
|
||||
* @param ticket: ulong, Specified Position Ticket ...
|
||||
*/
|
||||
void Finalize(ulong ticket)
|
||||
{
|
||||
//
|
||||
@@ -301,6 +376,13 @@ class XCPositionDrawer : public XCBase
|
||||
finalizedObjects.Add(iObj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find Specified Position Index ...
|
||||
*
|
||||
* @param ticket: ulong, Specified Position Ticket ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int FindIndex(ulong ticket)
|
||||
{
|
||||
//
|
||||
|
||||
@@ -642,14 +642,14 @@ void DestroyTimer()
|
||||
*/
|
||||
void OnSignalTriggered(XSignal &signal)
|
||||
{
|
||||
//
|
||||
// Draw Signal on Chart ...
|
||||
XCSignalObject *iSignalObj;
|
||||
bool has = fima1Signaller.poiDrawer.DrawSignal(
|
||||
signal,
|
||||
iSignalObj,
|
||||
7 //
|
||||
);
|
||||
// //
|
||||
// // Draw Signal on Chart ...
|
||||
// XCSignalObject *iSignalObj;
|
||||
// bool has = fima1Signaller.poiDrawer.DrawSignal(
|
||||
// signal,
|
||||
// iSignalObj,
|
||||
// 7 //
|
||||
// );
|
||||
|
||||
//
|
||||
eaExpert.HandleOnSignalTriggered(signal);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user