diff --git a/Classes/x-saherelm.x-backtester.expert.class.mq5 b/Classes/x-saherelm.x-backtester.expert.class.mq5 index d773d788..f9e1d24e 100644 --- a/Classes/x-saherelm.x-backtester.expert.class.mq5 +++ b/Classes/x-saherelm.x-backtester.expert.class.mq5 @@ -564,6 +564,12 @@ class XCBackTesterEA : public XCBase const string comment // ) { + // + eaPositionDrawer.HandleOnPositionModified( + ticket, + profit, + comment // + ); } /** diff --git a/Classes/x-saherelm.x-cobject.class.mq5 b/Classes/x-saherelm.x-cobject.class.mq5 index ba1c8f0e..e2e7bc1b 100644 --- a/Classes/x-saherelm.x-cobject.class.mq5 +++ b/Classes/x-saherelm.x-cobject.class.mq5 @@ -523,7 +523,7 @@ bool XUpdatePosition( // Global Chart Objects ... /** - * Base Chart Object ... + * Base Chart Object ... **/ class XCBaseObject : public CChartObject { @@ -1151,7 +1151,7 @@ class XCSignalObject : public XCBaseObject }; /** - * XRR Object ... + * XRR Object ... **/ class XCRRObject : public XCSignalObject { @@ -2115,28 +2115,20 @@ class XCPositionObject : public XCBaseObject void ApplyStyle() { // + // Validate ... 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 isLong = IsLong(mPosition.type); + bool isRiskFreed = + isLong + ? mPosition.sl > mPosition.entry + : mPosition.sl < mPosition.entry; bool isInProfit = mPosition.profit > 0; XPOIStyle _priceStyle; if (isInProfit) @@ -2157,6 +2149,28 @@ class XCPositionObject : public XCBaseObject _priceStyle.fill = true; _priceStyle.style = priceStyle; + // + // Change Risk Style if Risk Freed Position ... + if (isRiskFreed) { + // + riskStyle.fill = true; + riskStyle.clr = rewardStyle.clr; + } + + // + // 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); + // // Price Style .. mPriceBoxObj.BoxColor(_priceStyle.clr); @@ -2323,6 +2337,10 @@ class XCPositionObject : public XCBaseObject // bool isInProfit = mPosition.profit > 0; + bool isRiskFreed = + isLong + ? mPosition.sl > mPosition.entry + : mPosition.sl < mPosition.entry; ENUM_X_DIRECTION iPriceDir = isInProfit ? X_DIRECTION_BULLISH : X_DIRECTION_BEARISH; @@ -2342,17 +2360,27 @@ class XCPositionObject : public XCBaseObject mRiskBox.at = iAt; mRiskBox.lower = isLong + ? isRiskFreed + ? iEntry + : iSL + : isRiskFreed ? iSL : iEntry; mRiskBox.upper = isLong + ? isRiskFreed + ? iSL + : iEntry + : isRiskFreed ? iEntry : iSL; mRiskBox.from = iFrom; mRiskBox.symbol = iSymbol; mRiskBox.period = iPeriod; mRiskBox.type = iRiskName; - mRiskBox.dir = X_DIRECTION_BEARISH; + mRiskBox.dir = isRiskFreed + ? X_DIRECTION_BEARISH + : X_DIRECTION_BULLISH; // // Reward Box ... @@ -2379,10 +2407,14 @@ class XCPositionObject : public XCBaseObject mPriceBox.lower = isLong ? isInProfit - ? iEntry + ? isRiskFreed + ? iSL + : iEntry : iPrice : isInProfit - ? iPrice + ? isRiskFreed + ? iSL + : iPrice : iEntry; mPriceBox.upper = isLong diff --git a/Classes/x-saherelm.x-position.drawer.class.mq5 b/Classes/x-saherelm.x-position.drawer.class.mq5 index 0ceddd3f..5e229d9c 100644 --- a/Classes/x-saherelm.x-position.drawer.class.mq5 +++ b/Classes/x-saherelm.x-position.drawer.class.mq5 @@ -126,8 +126,8 @@ class XCPositionDrawer : public XCBase // // Price Style ... priceStyle = STYLE_SOLID; - inProfitColor = ApplyAlpha(clrAqua, 100); - inDrawdownColor = ApplyAlpha(clrMagenta, 100); + inProfitColor = clrAqua; // ApplyAlpha(clrAqua, 100); + inDrawdownColor = clrMagenta; // ApplyAlpha(clrMagenta, 100); } /** @@ -320,6 +320,7 @@ class XCPositionDrawer : public XCBase */ void HandleStopLossTriggered(const XDeal &deal) { + // Finalize(deal.positionId); } @@ -349,6 +350,53 @@ class XCPositionDrawer : public XCBase Finalize(ticket); } + /** + * Handle Position Modified Event ... + * + * @param ticket: ulong, triggered Positions ticket ... + * @param profit: double, Position Profit ... + * @param comment: string, Comment ... + */ + void HandleOnPositionModified( + const ulong ticket, + const double profit, + const string comment // + ) + { + // + // Detect Position Index ... + int index = FindIndex(ticket); + bool has = IsValidIndex(index); + if (!has) + { + return; + } + + // + // Get Position of Objects ... + XPosition _position; + has = ((XCPositionObject *)positionObjects.At(index)).GetPosition(_position); + if (has) + { + // + // Get Position of Trader Instance ... + has = trader.GetPosition( + ticket, + _position // + ); + if (has) + { + // + // Update Position ... + ((XCPositionObject *)positionObjects.At(index)).Update(_position); + } + } + + // + // Cleanup Resources ... + _position.Clean(); + } + // // Protected ... protected: @@ -371,9 +419,9 @@ class XCPositionDrawer : public XCBase } // - XCPositionObject *iObj = positionObjects.At(index); - positionObjects.Delete(index); - finalizedObjects.Add(iObj); + // XCPositionObject *iObj = positionObjects.At(index); + // positionObjects.Delete(index); + // finalizedObjects.Add(iObj); } /**