#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

- www.mql5.com
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 ; }
Good afternoon everyone, I'm having trouble making this section work perfectly and help.
I Can some1 please assist me with the corrections...
//+------------------------------------------------------------------+ //| CoDaC ZigZag EA | //| Integrates with CoDaC ZigZag Arrows Duplex MT5 Indicator | //+------------------------------------------------------------------+ #include <Trade/Trade.mqh> CTrade trade; // Indicator handles int zigzagHandle; // Buffers double slowZigzagBuffer[]; double fastZigzagBuffer[]; // Indicator Parameters input string IndicatorName = "CoDaC ZigZag Arrows Duplex MT5"; input int IndicatorSlowBuffer = 0; input int IndicatorFastBuffer = 1; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { Print("Initializing EA..."); zigzagHandle = iCustom(Symbol(), PERIOD_CURRENT, IndicatorName); if (zigzagHandle == INVALID_HANDLE) { Print("Error loading indicator: ", IndicatorName); return INIT_FAILED; } else { Print("Indicator successfully loaded: ", IndicatorName); } return INIT_SUCCEEDED; } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { Print("Deinitializing EA..."); IndicatorRelease(zigzagHandle); } //+------------------------------------------------------------------+ //| Function to close all trades | //+------------------------------------------------------------------+ void closeAllTrades() { for (int i = PositionsTotal() - 1; i >= 0; i--) { #include <Trade.mqh> CTrade trade; int OnInit() { Print("Initializing EA..."); return INIT_SUCCEEDED; } void OnTick() { for(int i = PositionsTotal() - 1; i >= 0; i--) { if(PositionSelect(i)) // Corrected from PositionSelectByIndex { long ticket = PositionGetInteger(POSITION_TICKET); // Corrected from PositionGetTicket(index) Print("Position Ticket: ", ticket); } } }
void closeAllTrades() { for (int i = PositionsTotal() - 1; i >= 0; i--) { #include <Trade.mqh> CTrade trade; int OnInit() { Print("Initializing EA..."); return INIT_SUCCEEDED; }
void closeAllTrades() { for (int i = PositionsTotal() - 1; i >= 0; i--) { #include <Trade.mqh> CTrade trade; int OnInit() { Print("Initializing EA..."); return INIT_SUCCEEDED; }
can't you see the problems here...?
I use PositionSelectByTicket to directly modify the open positions
https://www.mql5.com/en/docs/trading/positionselectbyticket
if(PositionSelectByTicket( PositionGetTicket(i) )){ // }
PositionSelect takes a symbol name, not an index
https://www.mql5.com/en/docs/trading/positionselect
Maybe you should study the reference and read articles on building EAs

- www.mql5.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
#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?