How to useTrade.mqh library in mql5?

 

#include <Trade\Trade.mqh>

CTrade trade;


I am new to mql. I have seen the code above in *** but there are parts I do not understand. 

I understand the first line. We are importing the Trade header file from the Trade.mqh library.

What does the second line mean? Are we assigning the CTrade class to a variable named 'trade' ? And

where does the CTrade value come from. Is it from the first line? If so how does the CTrade gets its value from

the first line?

When we include a library in mql how do we get to access its functions and other values?

 
Yule Msee:

#include <Trade\Trade.mqh>

CTrade trade;


I am new to mql. I have seen the code above in this tutorial but there are parts I do not understand. 

I understand the first line. We are importing the Trade header file from the Trade.mqh library.

What does the second line mean? Are we assigning the CTrade class to a variable named 'trade' ? And

where does the CTrade value come from. Is it from the first line? If so how does the CTrade gets its value from

the first line?

When we include a library in mql how do we get to access its functions and other values?

try this   https://www.mql5.com/en/articles/481

Trade Operations in MQL5 - It's Easy
Trade Operations in MQL5 - It's Easy
  • www.mql5.com
Almost all traders come to market to make money but some traders also enjoy the process itself. However, it is not only manual trading that can provide you with an exciting experience. Automated trading systems development can also be quite absorbing. Creating a trading robot can be as interesting as reading a good mystery novel. When...
 

Example:

 //+------------------------------------------------------------------+ 
 //|                                                     Open Buy.mq5 | 
 //|                              Copyright © 2018, Vladimir Karputov | 
 //+------------------------------------------------------------------+ 
 #property  copyright "Copyright © 2018, Vladimir Karputov" 
 #property  version    "1.000" 
 //--- 
 #include  <Trade\Trade.mqh>
CTrade         m_trade;                       // object of CTrade class 
 //+------------------------------------------------------------------+ 
 //| Script program start function                                    | 
 //+------------------------------------------------------------------+ 
 void OnStart ()
  {
 //--- 
   m_trade.Buy( 1.0 ); // open Buy position, volume 1.0 lot 
  }
 //+------------------------------------------------------------------+ 


We connect a trading class:

 #include  <Trade\Trade.mqh>


We declare the object ( m_trade ) of the trade class CTrade

CTrade         m_trade;                       // object of CTrade class 

after that, through the m_trade object , we get access to the public methods of the CTrade trading class (in the example below, we turn to the 1.0 Open BUY Position method)

   m_trade.Buy( 1.0 ); // open Buy position, volume 1.0 lot 
 
double CalcularAssertividade()
{
   int totalDeals = HistóricoDealsTotal();
   int ofertas vencedoras = 0;
   
   para(int i = 0; i < totalDeals; i++)
   {
      se(HistóricoDealSelect(i))
      {
         se(HistoryDealSymbol() == _Symbol && HistoryDealMagic() == MagicNumber)
         {
            se(HistóricoProfit() > 0)
            {
               ofertas vencedoras++;
            }
         }
      }
   }

   se(totalDeals == 0) retornar 0,0;

   retornar (duplo(ofertas vencedoras) / totalOfertas) * 100,0;
}
Boa tarde galera estou com dificuldade de fazer esse trecho funcionar perfeitamente e ajudar.