@@ -1345,8 +1345,11 @@ void CAccountProtector::CalculateDailyProfitLossAndStartingBalance()
13451345 FloatingProfit += PositionGetDouble (POSITION_PROFIT );
13461346 if (sets .CountCommSwaps ) FloatingProfit += HistoryDealGetDouble (ticket , DEAL_COMMISSION ) + PositionGetDouble (POSITION_SWAP );
13471347
1348- if (PositionGetInteger (POSITION_TYPE ) == POSITION_TYPE_BUY ) FloatingProfitPoints += (int )MathRound ((SymbolInfoDouble (PositionGetString (POSITION_SYMBOL ), SYMBOL_BID ) - PositionGetDouble (POSITION_PRICE_OPEN )) / SymbolInfoDouble (PositionGetString (POSITION_SYMBOL ), SYMBOL_POINT ));
1349- else if (PositionGetInteger (POSITION_TYPE ) == POSITION_TYPE_SELL ) FloatingProfitPoints += (int )MathRound ((PositionGetDouble (POSITION_PRICE_OPEN ) - SymbolInfoDouble (PositionGetString (POSITION_SYMBOL ), SYMBOL_ASK )) / SymbolInfoDouble (PositionGetString (POSITION_SYMBOL ), SYMBOL_POINT ));
1348+ if (SymbolInfoDouble (PositionGetString (POSITION_SYMBOL ), SYMBOL_POINT ) != 0 )
1349+ {
1350+ if (PositionGetInteger (POSITION_TYPE ) == POSITION_TYPE_BUY ) FloatingProfitPoints += (int )MathRound ((SymbolInfoDouble (PositionGetString (POSITION_SYMBOL ), SYMBOL_BID ) - PositionGetDouble (POSITION_PRICE_OPEN )) / SymbolInfoDouble (PositionGetString (POSITION_SYMBOL ), SYMBOL_POINT ));
1351+ else if (PositionGetInteger (POSITION_TYPE ) == POSITION_TYPE_SELL ) FloatingProfitPoints += (int )MathRound ((PositionGetDouble (POSITION_PRICE_OPEN ) - SymbolInfoDouble (PositionGetString (POSITION_SYMBOL ), SYMBOL_ASK )) / SymbolInfoDouble (PositionGetString (POSITION_SYMBOL ), SYMBOL_POINT ));
1352+ }
13501353 NumberOfMarketOrders ++;
13511354 break ; // Position already processed - no point to process this order with other magic numbers.
13521355 }
@@ -1452,8 +1455,11 @@ void CAccountProtector::CalculateDailyProfitLossAndStartingBalance()
14521455 double deal_entry_price = HistoryDealGetDouble (entry_deal_ticket , DEAL_PRICE );
14531456
14541457 // This is a very crude and imprecise method when used on a Netting account, but calculating points profit/loss across uninformly sized positions is crazy to start with.
1455- if (HistoryDealGetInteger (entry_deal_ticket , DEAL_TYPE ) == DEAL_TYPE_BUY ) realized_daily_profit_loss_points += (int )MathRound ((exit_deal_exit_prices [i ] - deal_entry_price ) / SymbolInfoDouble (HistoryDealGetString (entry_deal_ticket , DEAL_SYMBOL ), SYMBOL_POINT ));
1456- else if (HistoryDealGetInteger (entry_deal_ticket , DEAL_TYPE ) == DEAL_TYPE_SELL ) realized_daily_profit_loss_points += (int )MathRound ((deal_entry_price - exit_deal_exit_prices [i ]) / SymbolInfoDouble (HistoryDealGetString (entry_deal_ticket , DEAL_SYMBOL ), SYMBOL_POINT ));
1458+ if (SymbolInfoDouble (HistoryDealGetString (entry_deal_ticket , DEAL_SYMBOL ), SYMBOL_POINT ) != 0 )
1459+ {
1460+ if (HistoryDealGetInteger (entry_deal_ticket , DEAL_TYPE ) == DEAL_TYPE_BUY ) realized_daily_profit_loss_points += (int )MathRound ((exit_deal_exit_prices [i ] - deal_entry_price ) / SymbolInfoDouble (HistoryDealGetString (entry_deal_ticket , DEAL_SYMBOL ), SYMBOL_POINT ));
1461+ else if (HistoryDealGetInteger (entry_deal_ticket , DEAL_TYPE ) == DEAL_TYPE_SELL ) realized_daily_profit_loss_points += (int )MathRound ((deal_entry_price - exit_deal_exit_prices [i ]) / SymbolInfoDouble (HistoryDealGetString (entry_deal_ticket , DEAL_SYMBOL ), SYMBOL_POINT ));
1462+ }
14571463 break ; // Move on to the next exit deal.
14581464 }
14591465 }
@@ -1467,8 +1473,6 @@ void CAccountProtector::CalculateDailyProfitLossAndStartingBalance()
14671473 DailyProfitLossPoints += FloatingProfitPoints ;
14681474 }
14691475 // Percentage of balance at the start of the day calculated by subtracting the current daily profit from the current balance.
1470- //Print("daily_profit_loss_units = ", daily_profit_loss_units);
1471- //Print("prev balance = ", AccountInfoDouble(ACCOUNT_BALANCE) - realized_daily_profit_loss_units);
14721476 DailyStartingBalance = AccountInfoDouble (ACCOUNT_BALANCE ) - realized_daily_profit_loss_units ;
14731477 if ((!DisableDailyProfitLossPercGE ) || (!DisableDailyProfitLossPercLE ))
14741478 {
@@ -5312,7 +5316,7 @@ void CAccountProtector::Logging_Condition_Is_Met()
53125316 }
53135317 ArrayResize (PositionsByProfit , market , 100 ); // Reserve extra physical memory to increase the resizing speed.
53145318 if ((CloseFirst != ENUM_CLOSE_TRADES_MOST_DISTANT_FIRST ) && (CloseFirst != ENUM_CLOSE_TRADES_NEAREST_FIRST )) PositionsByProfit [market - 1 ][0 ] = position_floating_profit ; // Normal profit.
5315- else PositionsByProfit [market - 1 ][0 ] = MathAbs (PositionGetDouble (POSITION_PRICE_OPEN ) - PositionGetDouble (POSITION_PRICE_CURRENT )) / SymbolInfoDouble (PositionGetString (POSITION_SYMBOL ), SYMBOL_POINT );
5319+ else if ( SymbolInfoDouble ( PositionGetString ( POSITION_SYMBOL ), SYMBOL_POINT ) != 0 ) PositionsByProfit [market - 1 ][0 ] = MathAbs (PositionGetDouble (POSITION_PRICE_OPEN ) - PositionGetDouble (POSITION_PRICE_CURRENT )) / SymbolInfoDouble (PositionGetString (POSITION_SYMBOL ), SYMBOL_POINT );
53165320 PositionsByProfit [market - 1 ][1 ] = (double )ticket ;
53175321 TotalVolume += PositionGetDouble (POSITION_VOLUME ); // Used to close trades, so no need to filter by P/L.
53185322 }
0 commit comments