Articles by: David Williams

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.

Get a MetaTrader Indicator Value for ANY Timeframe or Period

Get a MetaTrader Indicator Value for ANY Timeframe or Period

The VTS Wizards are great for getting started, but the true power of VTS lies in its unrestricted, free-range drawing.

You can drag and drop Elements anywhere on the Drawing Pad and connect them in any manner.

Don’t know what an Element is? Read about it here: VTS-Help ELEMENTS

One useful Element is the Technical Indicator.

The MetaTrader (MT) platform offers all of the popular technical indicators, such as Moving Averages, Bollinger Bands, ADX, RSI … the list goes on and on.

To get the value of an indicator in MQL, you call the indicator by its name and define a value for each of its parameters. (The parameters are the values in the parenthesis).

It might look something like this:

   iRSI( Symbol(), 0, 14, PRICE_CLOSE, 0 ); 

So, you need to know the position and possible value for each parameter. This is tedious, so I made it easier.

To do this in VTS, you drag the iRSI function from the Indicators menu onto the Drawing Pad. The configuration dialog displays the appropriate values for each parameter – you pick one, select OK and you’re done.

VTS will generate the correct MQL code for the indicator.

Even I, a seasoned MQL programmer, find these entry-screens extremely helpful.

The best part? Even if you don’t explicitly assign values for each parameter, VTS assigns a sensible default value.

One parameter, named Timeframe, is available for all MT indicators.

This parameter allows you to define the timeframe that the indicator is calculated on. The values can be from 1 minute up to 1 month. Again, in VTS, the possible values are presented on a user-friendly pick-list.

Drag, drop, configure. Using VTS, you can define indicator values for multiple timeframes very quickly.

You can learn a lot more about VTS functions here: VTS-Help Functions

The MetaTrader MQL documentation is a great resource for learning about each indicator and its parameters. Learn how to access the MQL help here: VTS-Help MQL Help