Download MetaTrader 5

Can I run a script without opening any charts?

To add comments, please log in or register
Raj Kumar
14
Raj Kumar  

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
18019
Simon Gniadkowski  
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  

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
18019
Simon Gniadkowski  
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  

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
18019
Simon Gniadkowski  
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
15335
whroeder1  
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