Post Tagged with: "mql"

Trade Frustration! Using the MQL function OrderSend

Using the MQL function OrderSend

Have you ever been frustrated and felt like the universe was trying to make your life difficult?
I have. I think it’s most profound when you’re trying to do something you think is simple and you just can’t get it right.

Like opening a trade on a trading platform. That should be pretty darn easy, shouldn’t it?

Well, turns out it’s not.

OrderSend is a pain in the neck.

OrderSend is the MQL function used to open a trade.

Every  MQL programming language I’ve worked with has a few of these. Unwieldy functions that are difficult to work with – and in hindsight seem like they were poorly written.

There are 3 secrets you have to know to use OrderSend correctly:

  • The stoploss and takeprofit values are price values, like 1.2345, not offsets like 20 or -50.
  •  If it’s a Buy order, the price value must be Ask. And if it’s a Sell order, the price value must be Bid.
  •  When OrderSend fails, it writes an error code to the Journal tab of the MT platform.

OrderSend has a lot parameters, and if any of them are wrong, the trade will not open. It’s so difficult that I had to create a special entry-screen for its parameters.

I actually created a new function named fnOpenOrder. It’s available in the VTS Toolbox, under the Trade menu. (You can read more about the Toolbox here: VTS-Help-Toolbox  )

The fnOpenOrder dialog makes it a little easier to open a trade. Hopefully it helps you avoid the frustration most traders experience when they work with OrderSend.

You can read all about fnOpenOrder here: VTS-Help-fnOpenOrder

Also you can see it in action at the 5:52 mark in the EA Wizard Video.

Getting Started with the VTS Expert Advisor Builder

The VTS Expert Advisor Builder is super-powerful.

But to realize the full power, you need to learn how to use it.

While I highly recommend reading the entire Help document, I realize many traders will not do that.

(Are you different? Click here to read the Help: VTS-Help )

Also, I realize that we learn better by doing – not just by reading.

So I created some Wizards to help you. Before I get to the Wizards, since I’m not sure where you are in your quest to build an Expert Advisor, I’ve posed some questions.

If you don’t know the answer to any of these, just click the question for a full description.

Right now, there are two Wizards: The Test Wizard and the EA Wizard.

The Test Wizard

I created the Test Wizard to help you learn about your MetaTrader (MT) platform.

VTS generates MQL code from your drawings. Then it builds an Expert Advisor from that MQL code.

There’s nothing special about an EA built by VTS. It’s just like any other EA that you run on your MT platform.

For example, some MT platforms will not allow your EA to open a trade unless the stoploss and takeprofit values are zero.

But other MT platforms enforce the exact opposite rule: they’ll only allow an EA to open a trade if the stoploss and takeprofit are not zero! (We introduced the ECN input parameter just to solve this one issue – more on that below.)

So, among other things, the Test Wizard is designed to open and close trades on a demo account so you can find out what works, and what does not work on your platform.

Once you are confident how an EA opens and closes trades, then you can implement more complex logic in a real trading EA.

Here is a link to a video showing how to use the Test Wizard:

Watch the Test Wizard Video

The EA Wizard

I created the EA Wizard so you could build your first trading EA easily & quickly. The EA wizard also serves as a tutorial in a way, because as you complete each step of the wizard, VTS actually creates a drawing of your system!

When you are finished with the EA wizard, you can change the mode in VTS from wizard to drawing and edit and rebuild your EA if you like.

I show how it’s done in this video: EA Wizard Video

NOTE. ECN brokers require that trades opened by an EA have a zero stoploss and takeprofit value. All EA’s built by VTS have a true/false ECN input.

If your broker is an ECN broker, set ECN to true and VTS will automatically open trades with zero stops and then immediately (on the next tick) change the stoploss and takeprofit to your non-zero values. You can use the EA Wizard  to determine of your broker is ECN, or you could just ask your broker.  Click here for more info: VTS-Help-ECN