55//+------------------------------------------------------------------+
66#property copyright " www.EarnForex.com, 2025"
77#property link " https://www.earnforex.com/indicators/Equity-Line/"
8- #property version " 1.00 "
8+ #property version " 1.01 "
99#property indicator_chart_window
1010#property indicator_plots 0
1111
@@ -18,7 +18,6 @@ input color LineColor = clrDodgerBlue; // Projection line color
1818input int LineWidth = 2 ; // Projection line width
1919input ENUM_LINE_STYLE LineStyle = STYLE_SOLID ; // Projection line style
2020input bool ShowLabel = true ; // Show equity label
21- input string EquityLabelPrefix = " EQUITY: " ; // Equity label prefix
2221input color LabelPositiveChangeColor = clrGreen ; // Equity label color (positive change)
2322input color LabelNegativeChangeColor = clrRed ; // Equity label color (negative change)
2423input int InitialPriceOffset = 50 ; // Initial price offset in points
@@ -28,6 +27,7 @@ string LineObjectName = "EquityProjectionLine";
2827string EquityLabelObjectName = " EquityProjectionLabel" ;
2928double ProjectionPrice = 0 ;
3029double ProjectedEquity = 0 ;
30+ double totalFloatingProfit = 0 ;
3131
3232void OnInit ()
3333{
@@ -136,6 +136,8 @@ void CalculateProjectedEquity()
136136 // Calculate total P&L change for positions in current symbol.
137137 double totalPLChange = 0 ;
138138
139+ double floatingProfit = 0 ;
140+
139141 // Scan all positions.
140142 int totalPositions = PositionsTotal ();
141143 for (int i = 0 ; i < totalPositions ; i ++)
@@ -167,18 +169,46 @@ void CalculateProjectedEquity()
167169 if (priceDiff < 0 ) projectedPL = priceDiff * point_value_reward * posLots ;
168170 else projectedPL = priceDiff * point_value_risk * posLots ;
169171 }
172+ floatingProfit += PositionGetDouble (POSITION_PROFIT ) + PositionGetDouble (POSITION_SWAP ) + CalculateCommission ();
170173 totalPLChange += projectedPL ;
171174 }
172175 }
173176 }
174177
175178 // Calculate projected equity.
176179 ProjectedEquity = currentEquity + totalPLChange ;
177-
180+
181+ // For output.
182+ totalFloatingProfit = totalPLChange + floatingProfit ;
183+
178184 // Update display.
179185 UpdateLabel ();
180186}
181187
188+ double CalculateCommission ()
189+ {
190+ double commission_sum = 0 ;
191+ if (!HistorySelectByPosition (PositionGetInteger (POSITION_IDENTIFIER )))
192+ {
193+ Print (" HistorySelectByPosition failed: " , GetLastError ());
194+ return 0 ;
195+ }
196+ int deals_total = HistoryDealsTotal ();
197+ for (int i = 0 ; i < deals_total ; i ++)
198+ {
199+ ulong deal_ticket = HistoryDealGetTicket (i );
200+ if (deal_ticket == 0 )
201+ {
202+ Print (" HistoryDealGetTicket failed: " , GetLastError ());
203+ continue ;
204+ }
205+ if ((HistoryDealGetInteger (deal_ticket , DEAL_TYPE ) != DEAL_TYPE_BUY ) && (HistoryDealGetInteger (deal_ticket , DEAL_TYPE ) != DEAL_TYPE_SELL )) continue ; // Wrong kinds of deals.
206+ if (HistoryDealGetInteger (deal_ticket , DEAL_ENTRY ) != DEAL_ENTRY_IN ) continue ; // Only entry deals.
207+ commission_sum += HistoryDealGetDouble (deal_ticket , DEAL_COMMISSION );
208+ }
209+ return commission_sum ;
210+ }
211+
182212// Draw projection line on chart.
183213void DrawProjectionLine ()
184214{
@@ -216,7 +246,7 @@ void UpdateLabel()
216246 // Get the leftmost and rightmost visible bars.
217247 int firstVisibleBar = (int )ChartGetInteger (ChartID (), CHART_FIRST_VISIBLE_BAR );
218248
219- string equityText = EquityLabelPrefix + DoubleToString (ProjectedEquity , (int )AccountInfoInteger (ACCOUNT_CURRENCY_DIGITS ));
249+ string equityText = " Equity: " + FormatDouble ( DoubleToString (ProjectedEquity , (int )AccountInfoInteger (ACCOUNT_CURRENCY_DIGITS )), ( int ) AccountInfoInteger ( ACCOUNT_CURRENCY_DIGITS )) + " " + AccCurrency + " (Floating profit: " + FormatDouble ( DoubleToString ( totalFloatingProfit , ( int ) AccountInfoInteger ( ACCOUNT_CURRENCY_DIGITS )), ( int ) AccountInfoInteger ( ACCOUNT_CURRENCY_DIGITS )) + " " + AccCurrency + " ) " ;
220250
221251 // Calculate color based on equity change.
222252 double currentEquity = AccountInfoDouble (ACCOUNT_EQUITY );
@@ -405,4 +435,35 @@ double GetCurrencyCorrectionCoefficient(MqlTick &tick, const mode_of_operation m
405435 }
406436 return -1 ;
407437}
438+
439+ //+---------------------------------------------------------------------------+
440+ //| Formats double with thousands separator for so many digits after the dot. |
441+ //+---------------------------------------------------------------------------+
442+ string FormatDouble (const string number , const int digits = 2 )
443+ {
444+ // Find "." position.
445+ int pos = StringFind (number , " ." );
446+ string integer = number ;
447+ string decimal = " " ;
448+ if (pos > -1 )
449+ {
450+ integer = StringSubstr (number , 0 , pos );
451+ decimal = StringSubstr (number , pos , digits + 1 );
452+ }
453+ string formatted = " " ;
454+ string comma = " " ;
455+
456+ while (StringLen (integer ) > 3 )
457+ {
458+ int length = StringLen (integer );
459+ string group = StringSubstr (integer , length - 3 );
460+ formatted = group + comma + formatted ;
461+ comma = " ," ;
462+ integer = StringSubstr (integer , 0 , length - 3 );
463+ }
464+ if (integer == " -" ) comma = " " ;
465+ if (integer != " " ) formatted = integer + comma + formatted ;
466+
467+ return (formatted + decimal );
468+ }
408469//+------------------------------------------------------------------+
0 commit comments