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

- www.mql5.com
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 :)
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. } //+------------------------------------------------------------------+

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