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 ... // Global Chart Objects ...
// /**
// Bas Chart Object ... * Base Chart Object ...
**/
class XCBaseObject : public CChartObject class XCBaseObject : public CChartObject
{ {
// //
@@ -591,8 +592,9 @@ class XCBaseObject : public CChartObject
// //
}; };
// /**
// Bar Arrow Object ... * Bar Arrow Object ...
**/
class XCBarArrowObject : public XCBaseObject class XCBarArrowObject : public XCBaseObject
{ {
// //
@@ -749,8 +751,9 @@ class XCBarArrowObject : public XCBaseObject
// //
}; };
// /**
// Signal ... * Signal Object ...
**/
class XCSignalObject : public XCBaseObject class XCSignalObject : public XCBaseObject
{ {
// //
@@ -1147,8 +1150,9 @@ class XCSignalObject : public XCBaseObject
CArrayObj mTargetTrends; CArrayObj mTargetTrends;
}; };
// /**
// XRR Object ... * XRR Object ...
**/
class XCRRObject : public XCSignalObject class XCRRObject : public XCSignalObject
{ {
// //
@@ -1229,8 +1233,9 @@ class XCRRObject : public XCSignalObject
} }
}; };
// /**
// OHCL, Bar Object ... * XOHCL Object ...
**/
class XCOHCLObject : public XCBaseObject class XCOHCLObject : public XCBaseObject
{ {
// //
@@ -1575,8 +1580,9 @@ class XCOHCLObject : public XCBaseObject
CChartObjectRectangle mLowShadowRect; CChartObjectRectangle mLowShadowRect;
}; };
// /**
// Box Object ...k * Box Object ...
**/
class XCBoxObject : public XCBaseObject class XCBoxObject : public XCBaseObject
{ {
// //
@@ -1786,16 +1792,35 @@ class XCBoxObject : public XCBaseObject
CChartObjectRectangle mRect; CChartObjectRectangle mRect;
}; };
/**
* Position Object ...
**/
class XCPositionObject : public XCBaseObject class XCPositionObject : public XCBaseObject
{ {
// //
// Public ... // Public ...
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 ... // 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( bool Create(
long chart_id, long chart_id,
int window, int window,
@@ -1883,14 +1908,22 @@ class XCPositionObject : public XCBaseObject
* Update Position if Belongs to ... * Update Position if Belongs to ...
* *
* @param position: XPosition, reference to Specified Position ... * @param position: XPosition, reference to Specified Position ...
* @param barIndex: int, Specified Bar Index ...
* *
* @return ( bool ) * @return ( bool )
*/ */
bool Update(XPosition &position) bool Update(
XPosition &position,
int barIndex = 0 //
)
{ {
// //
bool result = false; bool result = false;
//
// Normalize ...
barIndex = NormalizeInt(barIndex, 0);
// //
// Validate ... // Validate ...
result = result =
@@ -1905,14 +1938,31 @@ class XCPositionObject : public XCBaseObject
return result; return result;
} }
//
datetime _toTime = GetBarTime(
position.symbol,
position.period,
barIndex //
);
// //
// Validate Chart Info ... // Validate Chart Info ...
result = XUpdatePosition(position); result = UpdatePosition(
position,
_toTime //
);
// //
return result; return result;
} }
/**
* Update Position if Belongs to ...
*
* @param barIndex: int, Specified Bar Index ...
*
* @return ( bool )
*/
bool Update(int barIndex = 0) bool Update(int barIndex = 0)
{ {
// //
@@ -1939,7 +1989,10 @@ class XCPositionObject : public XCBaseObject
} }
// //
result = Update(mPosition); result = Update(
mPosition,
barIndex //
);
// //
return result; return result;
@@ -2056,6 +2109,66 @@ class XCPositionObject : public XCBaseObject
// //
// Stylers ... // 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( void ApplyStyle(
XPOIStyle &bullishStyle, XPOIStyle &bullishStyle,
@@ -2096,24 +2209,24 @@ class XCPositionObject : public XCBaseObject
if (mPriceBox.IsValid()) if (mPriceBox.IsValid())
{ {
// //
XPOIStyle priceStyle; XPOIStyle _priceStyle;
if (mPriceBox.IsBullish()) if (mPriceBox.IsBullish())
{ {
priceStyle = bullishStyle; _priceStyle = bullishStyle;
} }
else else
{ {
priceStyle = bearishStyle; _priceStyle = bearishStyle;
} }
// //
mPriceBoxObj.BoxColor(priceStyle.clr); mPriceBoxObj.BoxColor(_priceStyle.clr);
mPriceBoxObj.BoxFill(priceStyle.fill); mPriceBoxObj.BoxFill(_priceStyle.fill);
mPriceBoxObj.BoxStyle(priceStyle.style); mPriceBoxObj.BoxStyle(_priceStyle.style);
mPriceBoxObj.BoxWidth(priceStyle.width); 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; bool result = false;
//
// Normalize ...
_toTime = NormalizeTime(_toTime);
// //
// Validate ... // Validate ...
result = _position.IsValid() && result = _position.IsValid() &&
@@ -2148,18 +2268,22 @@ class XCPositionObject : public XCBaseObject
// //
mPosition = _position; mPosition = _position;
result = UpdateZones(); result = UpdateZones(_toTime);
// //
return result; return result;
} }
// //
bool UpdateZones() bool UpdateZones(datetime _toTime = NULL)
{ {
// //
bool result = false; bool result = false;
//
// Normalize ...
_toTime = NormalizeTime(_toTime);
// //
// Validate ... // Validate ...
result = HasPosition(); result = HasPosition();
@@ -2175,7 +2299,12 @@ class XCPositionObject : public XCBaseObject
// //
datetime iAt = mPosition.openAt; datetime iAt = mPosition.openAt;
datetime iFrom = 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; double iTP = mPosition.tp;
@@ -2333,9 +2462,14 @@ class XCPositionObject : public XCBaseObject
isRiskCreated && isRiskCreated &&
isPriceCreated && isPriceCreated &&
isRewardCreated; isRewardCreated;
if (!result) if (result)
{ {
//
ObjName(iName); ObjName(iName);
//
// Apply Styles ...
ApplyStyle();
} }
// //
@@ -3586,3 +3720,36 @@ void RemoveObjects(
} }
// //
// 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;
}
//
+91 -9
View File
@@ -40,11 +40,16 @@ class XCPositionDrawer : public XCBase
public: public:
// //
// Props ... // Props ...
int window; int window; // Window ID of Chart ...
ulong chartID; ulong chartID; // Chart ID ...
XCTrade *trader; XCTrade *trader; // XCTrade Instance ...
CArrayObj positionObjects; XPOIStyle riskStyle; // Risk Box Style ...
CArrayObj finalizedObjects; 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 ... // Constructor ...
@@ -72,6 +77,13 @@ class XCPositionDrawer : public XCBase
// //
// Tools ... // 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( void Init(
XCTrade *_trader, XCTrade *_trader,
ulong _chartID = 0, ulong _chartID = 0,
@@ -93,12 +105,48 @@ class XCPositionDrawer : public XCBase
trader = _trader; trader = _trader;
window = _window; window = _window;
chartID = _chartID; 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() void Destroy()
{ {
//
riskStyle.Clean();
rewardStyle.Clean();
// positionObjects
// finalizedObjects
} }
/**
* Validate Instance ...
*
* @return ( bool )
*/
bool IsValid() bool IsValid()
{ {
// //
@@ -112,6 +160,11 @@ class XCPositionDrawer : public XCBase
return result; return result;
} }
/**
* Update Positions ...
*
* @param barIndex: int, Specified Bar Index ...
*/
void Update(int barIndex = 0) void Update(int barIndex = 0)
{ {
// //
@@ -138,6 +191,7 @@ class XCPositionDrawer : public XCBase
has = IsValidSize(drawingsCount); has = IsValidSize(drawingsCount);
if (has) if (has)
{ {
//
for (int i = 0; i < positionsCount; i++) for (int i = 0; i < positionsCount; i++)
{ {
// //
@@ -148,7 +202,9 @@ class XCPositionDrawer : public XCBase
has = ((XCPositionObject *)positionObjects.At(j)).IsBelong(positions[i]); has = ((XCPositionObject *)positionObjects.At(j)).IsBelong(positions[i]);
if (has) 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 ... // 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) if (has)
{ {
// //
XCPositionObject *iObj; XCPositionObject *iObj = new XCPositionObject();
has = iObj.Create( has = iObj.Create(
chartID, chartID,
window, window,
iPosition // 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: 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) void Finalize(ulong ticket)
{ {
// //
@@ -301,6 +376,13 @@ class XCPositionDrawer : public XCBase
finalizedObjects.Add(iObj); finalizedObjects.Add(iObj);
} }
/**
* Find Specified Position Index ...
*
* @param ticket: ulong, Specified Position Ticket ...
*
* @return ( int )
*/
int FindIndex(ulong ticket) int FindIndex(ulong ticket)
{ {
// //
+8 -8
View File
@@ -642,14 +642,14 @@ void DestroyTimer()
*/ */
void OnSignalTriggered(XSignal &signal) void OnSignalTriggered(XSignal &signal)
{ {
// // //
// Draw Signal on Chart ... // // Draw Signal on Chart ...
XCSignalObject *iSignalObj; // XCSignalObject *iSignalObj;
bool has = fima1Signaller.poiDrawer.DrawSignal( // bool has = fima1Signaller.poiDrawer.DrawSignal(
signal, // signal,
iSignalObj, // iSignalObj,
7 // // 7 //
); // );
// //
eaExpert.HandleOnSignalTriggered(signal); eaExpert.HandleOnSignalTriggered(signal);
File diff suppressed because it is too large Load Diff