CTrade vs MqlTradeRequest which one is the best and effective

 

Hi,

I am just learning mql5 where I can see CTrade and MqlTradeRequest to open orders. I am bit confused which one of them should I use in my learning and codding?

which one of them can be considered effective in terms of codding and execution??


Any feedback will be highly appreciated.


Thanking you!

 
Deep Raj:

Hi,

I am just learning mql5 where I can see CTrade and MqlTradeRequest to open orders. I am bit confused which one of them should I use in my learning and codding?

which one of them can be considered effective in terms of codding and execution??


Any feedback will be highly appreciated.


Thanking you!

Well, the documentation for CTrade says, "CTrade is a class for easy access to the trade functions." That doesn't quite answer your question.

So, take a look at the actual code for CTrade, which is in ./Include/Trade/Trade.mqh

You will see that CTrade is a handy class that encapsulates MqlTradeRequest (among other things).

That should answer your question.

 
Anthony Garot:

Well, the documentation for CTrade says, "CTrade is a class for easy access to the trade functions." That doesn't quite answer your question.

So, take a look at the actual code for CTrade, which is in ./Include/Trade/Trade.mqh

You will see that CTrade is a handy class that encapsulates MqlTradeRequest (among other things).

That should answer your question.

Thank you for responding to my post!

That means we can use any of them and result will be the same right!!!

 

Yes the result can be the same but personally i do not like CTrade.

If you code everything yourself i believe that going all the way will result in a better overall understanding.

So it boils down to your preferences.

 

@Marco vd Heijden 

CTrade seems to be simpler and easy to me but I was concerning on efficiency! 

could you please explain what makes MqlTradeRequest better than CTrade in your preference??

Thanking you!

 

Well i wont say better but im just used to write everything myself.

That's why i said personal preference because maybe you just want a quick robot and then it can work fro you.

The traderequest is more like coding to the bone it provides insight into all the separate elements that go into the process of working with the position.

So if you are planning to create a quick robot then CTrade is for you but if you plan on extending your work later on and think that it can become complex then the more bare bone technique can make it easier along the way.

Its just a matter of personal preference. i like to stay in control over the software as much as possible this means as many elements as possible and my goal is flexibility so not really user friendliness.

 
Marco vd Heijden:

Well i wont say better but im just used to write everything myself.

That's why i said personal preference because maybe you just want a quick robot and then it can work fro you.

The traderequest is more like coding to the bone it provides insight into all the separate elements that go into the process of working with the position.

So if you are planning to create a quick robot then CTrade is for you but if you plan on extending your work later on and think that it can become complex then the more bare bone technique can make it easier along the way.

Its just a matter of personal preference. i like to stay in control over the software as much as possible this means as many elements as possible and my goal is flexibility so not really user friendliness.

Thank you so much Marco!

Its more clear to me now!

 

I create wrapper functions around all the methods in CTrade that I use.

In the wrapper functions, I check for stops levels, freeze levels, margin required, and do error handling, and dump relevant values to log files.

I started with CTrade because it was simpler, but I agree with like @Marco vd Heijden's answer.

Because I have wrapper functions, I can scalpel out the CTrade call and readily convert to MqlTradeRequest code, all in one location.

 

Got problem with MqlTradeRequest!

I am backtesting with IC Markets Demo Account but the  ORDER_FILLING_FOK is not going through! however ORDER_FILLING_IOC

is ok.

I am wondering whether the problem is due to broker restriction or backtesting or my codding??? below is my buy order function!!


Pls Help!!!



void OpenBuyOrder()

   {

      MqlTradeRequest myrequest;

      MqlTradeResult myresult;

      ZeroMemory(myrequest);


     myrequest.action = TRADE_ACTION_DEAL;

      myrequest.type = ORDER_TYPE_BUY;

      myrequest.symbol = _Symbol;

      myrequest.volume = 0.10;

      myrequest.type_filling = ORDER_FILLING_FOK;

      myrequest.price = SymbolInfoDouble(_Symbol,SYMBOL_ASK);

      myrequest.tp = 0;

      myrequest.sl = 0 ;

      myrequest.deviation =50;

      OrderSend (myrequest,myresult);

      }


 

Forum on trading, automated trading systems and testing trading strategies

When you post code please use the CODE button (Alt-S)!

Use the CODE button

Thank you.


 
What is wrong in this fuction that it doese not open any position??? but if I use myrequest.type_filling = ORDER_FILLING_IOC then it is working.

Pls Help!!!

void
OpenBuyOrder()    {       MqlTradeRequest myrequest;       MqlTradeResult myresult;       ZeroMemory(myrequest);      myrequest.action = TRADE_ACTION_DEAL;       myrequest.type = ORDER_TYPE_BUY;       myrequest.symbol = _Symbol;       myrequest.volume = 0.10;       myrequest.type_filling = ORDER_FILLING_FOK;       myrequest.price = SymbolInfoDouble(_Symbol,SYMBOL_ASK);       myrequest.tp = 0;       myrequest.sl = 0 ;       myrequest.deviation =50;       OrderSend (myrequest,myresult);       }
Reason: