MT4 Expert to open sell and buy for two different pairs

 

Hi all experts,

I am familiar with MT4 coding and and I have developed many simple EA in MT4 platform. For my new EA I want to open sell and buy in two different currency pairs.

The EA is attached to EURUSD chart and I want to know:

- How to get Ask and Bid and Spread for USDJPY when EA is running in EURUSD chart?

- How to open sell and buy for USDJPY when EA is running in EURUSD chart?

- How to close sell and buy for USDJPY when EA is running in EURUSD chart?

Thank you in advance for your help

 
r_f_expert:

Hi all experts,

I am familiar with MT4 coding and and I have developed many simple EA in MT4 platform. For my new EA I want to open sell and buy in two different currency pairs.

The EA is attached to EURUSD chart and I want to know:

- How to get Ask and Bid and Spread for USDJPY when EA is running in EURUSD chart?

- How to open sell and buy for USDJPY when EA is running in EURUSD chart?

- How to close sell and buy for USDJPY when EA is running in EURUSD chart?

Thank you in advance for your help

Check these pages: https://docs.mql4.com/marketinformation/marketinfohttps://docs.mql4.com/trading/ordersend and https://docs.mql4.com/trading/orderclose.

MarketInfo - Market Info - MQL4 Reference
MarketInfo - Market Info - MQL4 Reference
  • docs.mql4.com
Returns various data about securities listed in the "Market Watch" window. A part of information about the current security is stored in predefined variables.
 
r_f_expert:

Hi all experts,

I am familiar with MT4 coding and and I have developed many simple EA in MT4 platform. For my new EA I want to open sell and buy in two different currency pairs.

The EA is attached to EURUSD chart and I want to know:

- How to get Ask and Bid and Spread for USDJPY when EA is running in EURUSD chart?

- How to open sell and buy for USDJPY when EA is running in EURUSD chart?

- How to close sell and buy for USDJPY when EA is running in EURUSD chart?

Thank you in advance for your help

Use MarketInfo, as suggested.

But if you are using OnTick() to activate code on a new bar, remember that a new bar on your host chart doesn't mean a new bar has started on any other symbol. So you'll need a way to identify a new bar for each symbol. I ended up using a struct array to keep a track of each symbol and it's current bar time, might be a better way!

The open, sell, close functions you'll find are straightforward once you get your head around MarketInfo.

 
andrew:

Use MarketInfo, as suggested.

But if you are using OnTick() to activate code on a new bar, remember that a new bar on your host chart doesn't mean a new bar has started on any other symbol. So you'll need a way to identify a new bar for each symbol. I ended up using a struct array to keep a track of each symbol and it's current bar time, might be a better way!

The open, sell, close functions you'll find are straightforward once you get your head around MarketInfo.Hi 

Hi Andrew,

Thank you for your help and reply, I saw many useful Info in MarketInfo() and I am trying to use it. It seems this will help me. I am developing a small subroutine and pass the trade parameters like Symbol, SL, TP, Lot size, and more to it. it will open order and return false if fail or true if it is successful. I hope I can do this task. Thank you again for help