PROBLEM with Standard Library !!!

 

Hi there , 

I'm using Trade.mqh but I'm not able to refer and Initialize the declared class structures . Does anybody know how to define them in a separate file ? I tried to call the constructor but I just get compiling errors. Thank you very much indeed.

//+------------------------------------------------------------------+
//|                                                    Sketching.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

#include <Trade\Trade.mqh>

CTrade trade;
void OnStart()
  {

  }
//+------------------------------------------------------------------+
class CTrade : public CObject
  {
protected:
   MqlTradeRequest   m_request;              // request data
   MqlTradeResult    m_result;               // result data
   MqlTradeCheckResult m_check_result;       // result check data
   bool              m_async_mode;           // trade mode
   ulong             m_magic;                // expert magic number
   ulong             m_deviation;            // deviation default
   ENUM_ORDER_TYPE_FILLING m_type_filling;
   ENUM_ACCOUNT_MARGIN_MODE m_margin_mode;
   //---
   ENUM_LOG_LEVELS   m_log_level;

public:
                     CTrade(void);
                    ~CTrade(void);
Create your own Market Watch using the Standard Library Classes
Create your own Market Watch using the Standard Library Classes
  • www.mql5.com
The main objective of the task was to develop a user-friendly and extensible tool for the output of arbitrary textual information on the chart of the MetaTrader 5 client terminal. For example, the current settings of the Expert Advisor, or the results of its work during a specified interval, presented as a table, the price values or a table of...
 
claudio.zeccolella :

Hi there , 

I'm using Trade.mqh but I'm not able to refer and Initialize the declared class structures . Does anybody know how to define them in a separate file ? I tried to call the constructor but I just get compiling errors. Thank you very much indeed.

The main question is: "Why" ??? You just need to use CTrade. You just need to use the methods of the CTrade class.

 
claudio.zeccolella:

Hi there , 

I'm using Trade.mqh but I'm not able to refer and Initialize the declared class structures . Does anybody know how to define them in a separate file ? I tried to call the constructor but I just get compiling errors. Thank you very much indeed.

your code example does not run the constructor which, you shouldn't do anyway because it gets called automatically when an instance of the class is created.  

CTrade trade    just creates an instance of the CTrade class called "trade"   

thereafter you can call the methods of the class buy prefixing with trade  so  trade.BUY(parameters here)  for example..


https://www.mql5.com/en/docs/standardlibrary/tradeclasses/ctrade

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...
 

Hey guys thank you for your prompt answer.

I was trying to use CheckResultMargin( ) but If I print the result it always get 0 because it seams to not referring to nothing. While everything works fine using OrderCheck( ) and then printing the margin field of MqlTradeCheckResult. All other methods ( buy , sell , postionopen , positionclose etc...) work fine. 

Basically if i do :

CTrade trade; 

trade.Request()

trade.CheckResult()

trade.CheckResultMargin( )  

The output is 0 , it's like not reading anything.


That's where i'm getting crazy :) 

 
claudio.zeccolella:

Hey guys thank you for your prompt answer.

I was trying to use CheckResultMargin( ) but If I print the result it always get 0 because it seams to not referring to nothing. While everything works fine using OrderCheck( ) and then printing the margin field of MqlTradeCheckResult. All other methods ( buy , sell , postionopen , positionclose etc...) work fine. 

Basically if i do :

CTrade trade; 

trade.Request()

trade.CheckResult()

trade.CheckResultMargin( )  

The output is 0 , it's like not reading anything.


That's where i'm getting crazy :) 

you need to show your code otherwise people will just be guessing...

 

My apologies Paul. That's the code I've been trying to run.

Creating new structures CTrade methods return 0 values , that's why i was trying to understand how to define CTrade declared structures. I'm looking for a way to link CheckResultMargin() to class structures

//+------------------------------------------------------------------+
//|                                                    Sketching.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

#include <Trade\Trade.mqh>


CTrade trade;





//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
  {

   MqlTradeRequest     trade_request = {0};
   MqlTradeCheckResult check_result  = {0};
   MqlTradeResult      trade_result  = {0};

//MqlTradeRquest
   trade_request.action    = TRADE_ACTION_DEAL;
   trade_request.type      = ORDER_TYPE_BUY;
   trade_request.price     = SymbolInfoDouble(Symbol(), SYMBOL_ASK);
   trade_request.volume    = 0.1;
   trade_request.deviation = 0;
   trade_request.symbol    = Symbol();

//Functions Option 1
   if(!OrderCheck(trade_request, check_result))
     {
      Print("Error : ", GetLastError());
     }
   else
     {
      Print("Margin Required is : ", check_result.margin);  // Output = Margin Required is : 20.0
     }


//CTrade methods Option 2

   trade.Request(trade_request);
   trade.Result(trade_result);
   trade.CheckResult(check_result);
   Print(trade.CheckResultMargin());     // Output = 0.0
   //double CheckResultMargin()
   //The value of the margin field (margin required for the trade operation) of MqlTradeCheckResult type filled while checking the request correctness.


  }

//+------------------------------------------------------------------+
 
Any Idea ? 
 
claudio.zeccolella:
Any Idea ? 
You don't seem to understand the library at all. Go through examples in the codebase. You're doing everything wrong, except the 'CTrade trade' declaration.
Reason: