last works on Position ...

This commit is contained in:
2025-10-06 22:39:33 +03:30
parent 8cc1ca21da
commit b9a53670ee
4 changed files with 833 additions and 567 deletions
+195 -28
View File
@@ -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;
}
//