@@ -1345,8 +1345,11 @@ void CAccountProtector::CalculateDailyProfitLossAndStartingBalance()
1345
1345
FloatingProfit += PositionGetDouble (POSITION_PROFIT );
1346
1346
if (sets .CountCommSwaps ) FloatingProfit += HistoryDealGetDouble (ticket , DEAL_COMMISSION ) + PositionGetDouble (POSITION_SWAP );
1347
1347
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
+ }
1350
1353
NumberOfMarketOrders ++;
1351
1354
break ; // Position already processed - no point to process this order with other magic numbers.
1352
1355
}
@@ -1452,8 +1455,11 @@ void CAccountProtector::CalculateDailyProfitLossAndStartingBalance()
1452
1455
double deal_entry_price = HistoryDealGetDouble (entry_deal_ticket , DEAL_PRICE );
1453
1456
1454
1457
// 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
+ }
1457
1463
break ; // Move on to the next exit deal.
1458
1464
}
1459
1465
}
@@ -1467,8 +1473,6 @@ void CAccountProtector::CalculateDailyProfitLossAndStartingBalance()
1467
1473
DailyProfitLossPoints += FloatingProfitPoints ;
1468
1474
}
1469
1475
// 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);
1472
1476
DailyStartingBalance = AccountInfoDouble (ACCOUNT_BALANCE ) - realized_daily_profit_loss_units ;
1473
1477
if ((!DisableDailyProfitLossPercGE ) || (!DisableDailyProfitLossPercLE ))
1474
1478
{
@@ -5312,7 +5316,7 @@ void CAccountProtector::Logging_Condition_Is_Met()
5312
5316
}
5313
5317
ArrayResize (PositionsByProfit , market , 100 ); // Reserve extra physical memory to increase the resizing speed.
5314
5318
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 );
5316
5320
PositionsByProfit [market - 1 ][1 ] = (double )ticket ;
5317
5321
TotalVolume += PositionGetDouble (POSITION_VOLUME ); // Used to close trades, so no need to filter by P/L.
5318
5322
}
0 commit comments