Download MetaTrader 5

Checking if the last trade was profitable or not

To add comments, please log in or register
Diane Minshew
356
Diane Minshew  

I can check the open price

I can not get the close price to compare them.

HistoryOrderGetDouble(HistoryOrderGetTicket(HistoryOrdersTotal()-1),ORDER_PRICE_OPEN);
Alain Verleyen
Moderator
33334
Alain Verleyen  
wehsnim:

I can check the open price

I can not get the close price to compare them.

Did you select your history ?
Diane Minshew
356
Diane Minshew  
angevoyageur:
Did you select your history ?

Im breaking down the Martingale Library to understand how it works yet its not based on if a trade is loss double up. from my understanding so far

   double cl=HistoryOrderGetDouble(HistoryOrderGetTicket(HistoryOrdersTotal()-1),ORDER_PRICE_OPEN); //Double Because of ORDER_PRICE_OPEN
   double op=HistoryOrderGetDouble(HistoryOrderGetTicket(HistoryOrdersTotal()-2),ORDER_PRICE_OPEN); //Double Because of ORDER_PRICE_OPEN
            
              //Get the Properties in (Ticket History (list of order history () second from the last ), 
   long typeor=HistoryOrderGetInteger(HistoryOrderGetTicket(HistoryOrdersTotal()-2),ORDER_TYPE); // HistoryOrderGetInterger Because of OrderType
   if(typeor==ORDER_TYPE_BUY)
     {
      if(op>cl)
        {
         if(ud<DoublingCount)
           {
            lt1=HistoryOrderGetDouble(HistoryOrderGetTicket(HistoryOrdersTotal()-2),ORDER_VOLUME_INITIAL)*2; //Double Because of Order Volume Initial
            ud++;
           }
         else ud=0;
        }
      else ud=0;
     }

just if the 2nd to last order open price is greater than the last order open price.

Oh.. Let Me Switch to History Deal  I read your post and thought your where talking about

  HistorySelect(0,TimeCurrent());  // request trade history
Alain Verleyen
Moderator
33334
Alain Verleyen  
wehsnim:

Im breaking down the Martingale Library to understand how it works yet its not based on if a trade is loss double up. from my understanding so far

just if the 2nd to last order open price is greater than the last order open price.

Oh.. Let Me Switch to History Deal  I read your post and thought your where talking about

Yes I am talking about HistorySelect(). You always have to select your history before using HistoryXXX functions.
Diane Minshew
356
Diane Minshew  
angevoyageur:
Yes I am talking about HistorySelect(). You always have to select your history before using HistoryXXX functions.

It wont print the profit, thus no comparison is possible

void ScanClosedTrades()
{
  HistorySelect(0,TimeCurrent());
  
   ulong  ticket = 0;
   double profit;
   uint   dealsTotal=HistoryDealsTotal(); 
 //--- Loop for tracking wins losses and lot sizes for trading
        
         for (uint i=0; i < dealsTotal; i++)
               {
                if((ticket=HistoryDealGetTicket(i))>0)
                {
                profit=HistoryDealGetDouble(ticket,DEAL_PROFIT);
                
                }
               
                if (profit < 0)
                  {
                     Print("Profit: %f",CheckProfit);//profit);
                  }
               }
Diane Minshew
356
Diane Minshew  
Suggestion to everyone looking for this type of information read Orders Positions and Deals
To add comments, please log in or register