History deals

 

Hello. I want to get the number of consecutive losses from the history but I want to filter the deals by comment" ". So I noticed that the DEAL_ENTRY_IN has different comment from DEAL_ENTRY_OUT. So how do I retrieve the information? Code below 


int MaxConsecutiveLosses(){

    HistorySelect(0,TimeCurrent());
    
    int max_losses = 0;
    int current_losses = 0;
    
    // Get the total number of closed trades
    int total_trades = HistoryDealsTotal();
    
    for(int i = 0; i < total_trades; i++){
        // Get the ticket number of the trade
        ulong ticket = HistoryDealGetTicket(i);       
        // Get the profit of the trade
        if(HistoryDealGetString(DEAL_COMMENT) == COMMENT){
           double profit = HistoryDealGetDouble(ticket,DEAL_PROFIT);        
           if(profit < 0){
               // If the trade is a loss, increment the current loss count
               current_losses++;           
               // Update the maximum losses if the current sequence is longer
               if(current_losses > max_losses){
                  max_losses = current_losses;
               }
           }
           else
           {
               // If the trade is not a loss, reset the current loss count
               current_losses = 0;
           }
        }
    }
    
    return max_losses;
}
 
Kekeletso Mofokeng:

Hello. I want to get the number of consecutive losses from the history but I want to filter the deals by comment" ". So I noticed that the DEAL_ENTRY_IN has different comment from DEAL_ENTRY_OUT. So how do I retrieve the information? Code below 


HistoryDealGetInteger( ticket, DEAL_ENTRY );

 
trampampam #:

HistoryDealGetInteger( ticket, DEAL_ENTRY );

Please explain

 
Kekeletso Mofokeng #:

Please explain

I thought you can't get DEAL_ENTRY status of a deal, can you? If not than what do you want to get?

Actually, obtaining max consecutive losses through a deal comment isn't a best decision. Get a deal profit, a deal commission, a deal fee, a deal swap and sum those values.

 
trampampam #:

I thought you can't get DEAL_ENTRY status of a deal, can you? If not than what do you want to get?

Actually, obtaining max consecutive losses through a deal comment isn't a best decision. Get a deal profit, a deal commission, a deal fee, a deal swap and sum those values.

I'm mainly interested in the number of losses rather than the amount loss. I want to know how many positions were losers but consecutively 

 
Kekeletso Mofokeng #:

I'm mainly interested in the number of losses rather than the amount loss. I want to know how many positions were losers but consecutively 

You have to find DEAL_ENTRY_OUT/DEAL_ENTRY_INOUT deal and check profit of a deal. When profit < 0.0 increase the currentLosses counter.