Download MetaTrader 5
To add comments, please log in or register
Learning MQL5? Start with documentation!
Raj Kumar
14
Raj Kumar 2014.02.18 16:48 

Hi All,

I am new to MT4. I have written a simple script to open a market order on GBPUSD. If I drag the script to the GBPUSD chart it works fine but if I double click the script when no charts are open it does nothing.

My aim is to add more lines to the script so it opens trades on more than one symbol (eurchf, eurjpy etc) so I don't want to have to drag it to a particular chart.

What's the solution here?


Thanks

Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.02.18 16:57  
MisterEffExx:

Hi All,

I am new to MT4. I have written a simple script to open a market order on GBPUSD. If I drag the script to the GBPUSD chart it works fine but if I double click the script when no charts are open it does nothing.

My aim is to add more lines to the script so it opens trades on more than one symbol (eurchf, eurjpy etc) so I don't want to have to drag it to a particular chart.

You don't have to drag it to a chart but it does have to run on a chart . . . if you code it right it can be any chart.
Raj Kumar
14
Raj Kumar 2014.02.18 20:30  

Hi RaptorUK, thanks for the help!

The command I am using is:

OrderSend(Symbol(),OP_BUY,0.1,Ask,3,Bid-15*Point,Bid+15*Point);

which I can drag to any chart since I haven't specified a currency.

However if I use:

OrderSend("GBPUSD",OP_BUY,0.1,Ask,3,Bid-15*Point,Bid+15*Point)

this also works but only if I drag it to the gbpusd chart. I would have thought it would work by just double clicking it since the symbol is in the command but double clicking does nothing.


Any ideas?

Thanks

Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.02.18 20:36  
MisterEffExx:

Hi RaptorUK, thanks for the help!

The command I am using is:

OrderSend(Symbol(),OP_BUY,0.1,Ask,3,Bid-15*Point,Bid+15*Point);

which I can drag to any chart since I haven't specified a currency.

However if I use:

OrderSend("GBPUSD",OP_BUY,0.1,Ask,3,Bid-15*Point,Bid+15*Point)

this also works but only if I drag it to the gbpusd chart. I would have thought it would work by just double clicking it since the symbol is in the command but double clicking does nothing.

You have specified a currency by using Ask, it is the Ask price of the symbol of the chart you are running the script on. If you use it on a USDJPY chart you get the Ask price of USDJPY, instead you have to use MarketInfo() with MODE_ASK
Raj Kumar
14
Raj Kumar 2014.02.18 20:41  

I'm afraid my scripting skills are no where near the point where I would be able to do this alone.

Would you be able to put the command together for me? :-)

Thank you!

Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.02.18 20:47  
MisterEffExx:

I'm afraid my scripting skills are no where near the point where I would be able to do this alone.

Would you be able to put the command together for me? :-)

Thank you!

There are examples in the documentation I gave links to . . . please read the documentation, have a go, post your attempt then I'll help more.
whroeder1
13627
whroeder1 2014.02.18 21:13  
OrderSend("GBPUSD",OP_BUY,0.1,Ask,3,Bid-15*Point,Bid+15*Point)
  1. Can't use Ask or Bid, or Point or any other Predefined Varaiables. Can't use OnTick() as that only calls for the current chart.
  2. Don't do it. Code your EA to trade the current pair only. Read the other pairs, if you need to. KISS
/
To add comments, please log in or register