Download MetaTrader 5
To add comments, please log in or register
Take active part in the life of the community. Improve your rating!
sd2000sd
212
sd2000sd 2014.01.29 15:34 

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. 

Rodrigo Malacarne
Moderator
9604
Rodrigo Malacarne 2014.01.29 15:46  

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.

Alain Verleyen
Moderator
28651
Alain Verleyen 2014.01.29 17:09  
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.
Alain Verleyen
Moderator
28651
Alain Verleyen 2014.01.29 17:10  
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().
sd2000sd
212
sd2000sd 2014.01.29 17:40  
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?
Alain Verleyen
Moderator
28651
Alain Verleyen 2014.01.29 17:58  
sd2000sd:
how can I get the returned value of trade.BuyLimit()? can you give an example?
Seems you already do it, not ?
sd2000sd
212
sd2000sd 2014.01.29 18:00  
angevoyageur:
Seems you already do it, not ?
yes, I found it. Thanks!
/
To add comments, please log in or register