an example for using ctrade class needed

 

Please someone give me an example of using ctrade class in buying and selling a symbol.

for example:

buying with this info:

order type: buy_limit 

price:1000

volume:2000

Stop loss: 800

Take Profit: 1200

Expiration: today

Fill policy: return

 //************************//

and for selling with this info using that ctrade class:

 order type: sell_limit

 Volume: 2000

Price: 1000

Stop Loss: 1100

Expiration: today

Fill policy: return

//********************//

thanks in advance.

I need this example code. Please someone help me.

Best Regards. 

I want to send these orders using that ctrade class. 

 

As a global variable define

//--- global variable
CTrade      trade;

Inside OnTick() you could write:

//--- inside OnTick()
if(your_condition)
     {
      trade.BuyLimit(2000,1000,_Symbol,800,1200,ORDER_TIME_DAY,0,"Write your comment here");
     }

However, keep in mind that some symbols do not accept ORDER_TIME_DAY as an input... so you could take a look here for more options. 

I hope it helps.

 
sd2000sd:

Please someone give me an example of using ctrade class in buying and selling a symbol.

...

See Moving Average EA in Codebase and this article

The Use of the MQL5 Standard Trade Class libraries in writing an Expert Advisor
The Use of the MQL5 Standard Trade Class libraries in writing an Expert Advisor
  • 2010.11.10
  • Samuel
  • www.mql5.com
This article explains how to use the major functionalities of the MQL5 Standard Library Trade Classes in writing Expert Advisors which implements position closing and modifying, pending order placing and deletion and verifying of Margin before placing a trade. We have also demonstrated how Trade classes can be used to obtain order and deal details.
 
Malacarne:

As a global variable define

Inside OnTick() you could write:

However, keep in mind that some symbols do not accept ORDER_TIME_DAY as an input... so you could take a look here for more options. 

I hope it helps.

I strongly suggest to check the returned value of trade.BuyLimit().
 
angevoyageur:
I strongly suggest to check the returned value of trade.BuyLimit().
how can I get the returned value of trade.BuyLimit()? can you give an example?
 
sd2000sd:
how can I get the returned value of trade.BuyLimit()? can you give an example?
Seems you already do it, not ?
 
angevoyageur:
Seems you already do it, not ?
yes, I found it. Thanks!
Reason: