problem with retrieving concesutive losses

 

Hi,

I found a lot of code for consecutive loss but not works. Also I try only to get all from history trades. Always I got 0. What code I need to get all losses?

int consecutiveLosses = 0;         // Global variable to track consecutive losses
ulong lastDealTicket = 0;          // To track the last processed deal ticket

void CheckClosedOrders() {
    // Get the total number of historical deals
    int totalDeals = HistoryDealsTotal();

   Comment(totalDeals);

   
    
}
 
Dejan Krapez:

Hi,

I found a lot of code for consecutive loss but not works. Also I try only to get all from history trades. Always I got 0. What code I need to get all losses?

use the search feature of this website.

 

You need to do HistorySelect first of all, then you should cycle DEALS, considering only DEAL_ENTRY_OUT backwards from the last one.

Surely there are planty of examples into the codebase.

Be aware that if you just need the maximum consecutive losses after a backtest, you can simply use the TesterStatistic, you don't need to calculate it manually.

STAT_MAX_CONLOSS_TRADES

The number of trades in the longest series of losing trades STAT_MAX_CONLOSSES

int

 

Hi

You need to call HistorySelect function beforegetting the number of deals. No history functions will work if you don’t specify what orders you want to retrieve

*(from and to chosen dates)

 If you need whole history data just use 

HistorySelect(0, TimeCurrent());

Have a nice day👍📊