diff --git a/Experts/x-saherelm.backtester.mq5 b/Experts/x-saherelm.backtester.mq5 index 47df2eb1..e01c1c0e 100644 --- a/Experts/x-saherelm.backtester.mq5 +++ b/Experts/x-saherelm.backtester.mq5 @@ -392,12 +392,17 @@ bool InitGUI() int startX = 5; int startY = 25; + // + int defaultGap = 5; + int defaultWidth = 100; + int defaultHeight = 30; + // // Buy ... int btnBuyStartX = startX; - int btnBuySizeX = startX + 100; + int btnBuySizeX = startX + defaultWidth; int btnBuyStartY = startY; - int btnBuySizeY = startY + 50; + int btnBuySizeY = startY + defaultHeight; string btnBuyName = objSuffix + "BTN_BUY"; result = btnBuy.Create( chartId, @@ -422,7 +427,7 @@ bool InitGUI() // // Sell ... int btnSellStartX = btnBuyStartX + btnBuySizeX; - int btnSellSizeX = btnSellStartX + 100; + int btnSellSizeX = btnSellStartX + defaultWidth; int btnSellStartY = btnBuyStartY; int btnSellSizeY = btnBuySizeY; string btnSellName = objSuffix + "BTN_SELL"; @@ -449,9 +454,9 @@ bool InitGUI() // // LABEL Position ID ... lblPositionIdStartX = btnBuyStartX; - lblPositionIdSizeX = lblPositionIdStartX + 100; - lblPositionIdStartY = btnSellSizeY + 5; - lblPositionIdSizeY = lblPositionIdStartY + 50; + lblPositionIdSizeX = lblPositionIdStartX + defaultWidth; + lblPositionIdStartY = btnSellSizeY + defaultGap; + lblPositionIdSizeY = lblPositionIdStartY + defaultHeight; string lblPositionIdName = objSuffix + "LBL_POS_ID"; result = lblPositionId.Create( chartId, @@ -475,9 +480,9 @@ bool InitGUI() // // Close ... btnCloseStartX = startX; - btnCloseSizeX = btnCloseStartX + 100; - btnCloseStartY = lblPositionIdSizeY + 5; - btnCloseSizeY = lblPositionIdSizeY + 50; + btnCloseSizeX = btnCloseStartX + defaultWidth; + btnCloseStartY = lblPositionIdSizeY + defaultGap; + btnCloseSizeY = lblPositionIdSizeY + defaultHeight; string btnCloseName = objSuffix + "BTN_CLOSE"; result = btnClose.Create( chartId, @@ -501,10 +506,10 @@ bool InitGUI() // // Close All ... - int btnCloseAllStartX = btnCloseSizeX + 5; - int btnCloseAllSizeX = btnCloseAllStartX + 100; - int btnCloseAllStartY = lblPositionIdSizeY + 5; - int btnCloseAllSizeY = lblPositionIdSizeY + 50; + int btnCloseAllStartX = btnCloseSizeX + defaultGap; + int btnCloseAllSizeX = btnCloseAllStartX + defaultWidth; + int btnCloseAllStartY = lblPositionIdSizeY + defaultGap; + int btnCloseAllSizeY = lblPositionIdSizeY + defaultHeight; string btnCloseAllName = objSuffix + "BTN_CLOSE_ALL"; result = btnCloseAll.Create( chartId, @@ -1178,7 +1183,27 @@ void UpdateGUIState() // // Read All Positions ... + double profits = 0; + XPosition positions[]; + string positionsInfo = ""; + int positionsCount = eaTrader.GetPositions(positions); + has = IsValidSize(positionsCount); + if (has) + { + // + for (int i = 0; i < positionsCount; i++) + { + profits += positions[i].profit; + } + // + if (positionsCount > 1) + { + positionsInfo = "Positions Count: " + ToXString(positionsCount) + ", Profits: " + ToXString(profits); + } + } + + // if (hasPosition) { // @@ -1195,16 +1220,67 @@ void UpdateGUIState() "Equity: " + ToXString(eaTrader.mAccount.GetEquity()); // - string posInfos[] = { - posTicket, - posType, - posSymbolPeriod, - posProfit, - posRiskToRewardRatio, - accountInfo // - }; + string posInfos[]; // + // Ticket ... + Add( + posTicket, + posInfos // + ); + + // + // Type ... + Add( + posType, + posInfos // + ); + + // + // Symbol Period ... + Add( + posSymbolPeriod, + posInfos // + ); + + // + // Profit ... + Add( + posProfit, + posInfos // + ); + + // + // Risk to Reward Ratio ... + Add( + posRiskToRewardRatio, + posInfos // + ); + + // + // Add Positions Info if Exists ... + if (IsSpecifiedValid(positionsInfo)) + { + // + Add( + positionsInfo, + posInfos // + ); + + // + // Clear Info Array ... + selectedPosInfoArr.Clear(); + } + + // + // Adding Account Info ... + Add( + accountInfo, + posInfos // + ); + + // + // Create Button If Not Exists ... if (btnSelectedPosInfo == NULL) { // @@ -1254,13 +1330,14 @@ void UpdateGUIState() // int posInfoCount = ArraySize(posInfos); int lblInfoCount = selectedPosInfoArr.Total(); - has = IsValidSize(lblInfoCount); + has = IsValidSize(lblInfoCount) && lblInfoCount == posInfoCount; // // Create info Labels ... if (!has) { // + selectedPosInfoArr.Clear(); has = IsValidSize(posInfoCount); if (has) { @@ -1272,10 +1349,11 @@ void UpdateGUIState() // int lblHeight = 25; + int lblWidth = 450; // - int startX = chartWidth - 300 - 5; - int sizeX = startX + 300; + int startX = chartWidth - lblWidth - 5; + int sizeX = startX + lblWidth; // int startY = 5; @@ -1364,6 +1442,9 @@ void UpdateGUIState() // ZeroMemory(posInfos); } + + // + SpecifiedClean(positions); } else {