Python or MQL5 — Code Migration - page 4

 
3195512 #: But isn't the DOM historical data the bid, ask, last, volume per each tick? This is the information shown in the Depth of Market in live trading. Or am I misunderstanding your point?

I don't trade futures and my knowledge is lacking in that area, but I am pretty confidant that it is not the DOM. As far as I know, the Depth-of-Market or the Order Book, is something completely different and represents the open liquidity available at the time, based on the number of open buy and sell orders. MetaTrader does offer that information as a separate data structure to that of the tick data, but not as historical data, as @Alain Verleyen pointed out.

 

As a follow-up I call your attention to the following ...

Depth of market

In addition to several types of up-to-date market price data (Ask/Bid/Last) and the last traded volumes are received in the terminal in the form of ticks, MetaTrader 5 supports the Depth of Market (order book), which is an array of records about the volumes of placed buy and sell orders around the current market price. Volumes are aggregated at several levels above and below the current price, with the smallest increment of price movement according to the symbol specification. As we have seen, the maximum order book size (number of price levels) is set in the SYMBOL_TICKS_BOOKDEPTH symbol property.

Terminal users know the Depth of Market feature in the interface and its operating principles. If you need further details, please see the documentation.

The order book contains extended market information which is commonly referred to as "market depth". Knowing it allows you to create more sophisticated trading systems.

Indeed, information about a tick is only a small slice of the order book. In a somewhat simplified sense, a tick is a 2-level order book with one nearest Ask price (available offer) and one nearest Bid price (available demand). Furthermore, ticks do not provide order volumes at these prices.

Depth of Market changes can occur much more frequently than ticks, since they affect not only the reaction to concluded deals but also changes in the volume of pending limit orders in the Depth of Market.


Depth of Market - Trading Operations - MetaTrader 5 Help
  • www.metatrader5.com
The Depth of Market (DOM) displays bids and asks for a particular instrument at the currently best prices (closest to the market). The Dept of...
 
3195512 #:

But isn't the DOM historical data the bid, ask, last, volume per each tick? This is the information shown in the Depth of Market in live trading.

Or am I misunderstanding your point?

That's tick data, also sometimes called Time & Sales. Tick data are 'raw' data, from them you can build Time & Sales. These data are directly available in the Tester.

DOM is something else, the Depth of Market is showing the "depth" of offer/demand prices and volumes.


 

Understood, I'll do further reading on theoretical concepts. I appreciate the help.

2 questions:

1. Given all the discussion, I would like to confirm that the backtest (using only tick data) takes into account tick values, bid, ask, last, and volume to simulate trades. Is that correct?

2. Incorporating DOM data into the backtest would likely make the results more realistic. However, do you know if the difference is significant when I'm already using tick data in a limit price based strategy (e.g., ATM)? Or is this too broad of a question to answer definitively?

Alain Verleyen #:

That's tick data, also sometimes called Time & Sales. Tick data are 'raw' data, from them you can build Time & Sales. These data are directly available in the Tester.

DOM is something else, the Depth of Market is showing the "depth" of offer/demand prices and volumes.

 

Understood. Thank you for your time!

Fernando Carreiro #:

As a follow-up I call your attention to the following ...

Depth of market

In addition to several types of up-to-date market price data (Ask/Bid/Last) and the last traded volumes are received in the terminal in the form of ticks, MetaTrader 5 supports the Depth of Market (order book), which is an array of records about the volumes of placed buy and sell orders around the current market price. Volumes are aggregated at several levels above and below the current price, with the smallest increment of price movement according to the symbol specification. As we have seen, the maximum order book size (number of price levels) is set in the SYMBOL_TICKS_BOOKDEPTH symbol property.

Terminal users know the Depth of Market feature in the interface and its operating principles. If you need further details, please see the documentation.

The order book contains extended market information which is commonly referred to as "market depth". Knowing it allows you to create more sophisticated trading systems.

Indeed, information about a tick is only a small slice of the order book. In a somewhat simplified sense, a tick is a 2-level order book with one nearest Ask price (available offer) and one nearest Bid price (available demand). Furthermore, ticks do not provide order volumes at these prices.

Depth of Market changes can occur much more frequently than ticks, since they affect not only the reaction to concluded deals but also changes in the volume of pending limit orders in the Depth of Market.


 
3195512 #:

Understood, I'll do further reading on theoretical concepts. I appreciate the help.

2 questions:

1. Given all the discussion, I would like to confirm that the backtest (using only tick data) takes into account tick values, bid, ask, last, and volume to simulate trades. Is that correct?

2. Incorporating DOM data into the backtest would likely make the results more realistic. However, do you know if the difference is significant when I'm already using tick data in a limit price based strategy (e.g., ATM)? Or is this too broad of a question to answer definitively?

1. Yes, but that also depends on your EA code. If your program is flawed, you may get some strange results and then think that it is the tester's fault, when in fact it is a coding problem. Be aware of that.

2.a. By ATM are you referring to Ninjatrader's Advanced Trade Management? If so, then that is just a naming gimmick. That does not really exist. It is just general trade management concepts which they have grouped and automated and given a fancy name. It definitely is not a strategy. In MetaTrader, those concepts have to programmed as per your trading rules. They are not pre-automated, except for the Stop-Loss and Take-Profit. All the other concepts, such as break-even, trailing-stops, chasing, reversals, etc. have to be coded yourself. There is no generalisation. They change depending on your strategy rules and the trade, risk and money management rules you want to apply.

2.b. I lack experience with Futures, but I doubt incorporating the real DOM history, will have any impact if you don't actually trade against the order book in your strategy. The fact that you were confusing the Tick Data with the DOM, tells me that your strategy does not trade the order book directly at all. So, I believe, there should be no impact in the back-tests without the historical DOM.

 

I appreciate the help.

Let me explain my strategy's components in more detail so we can reach a clear and sustainable conclusion.

First, you're right—my strategy does not use any order book (DOM) information. I simply place limit orders to enter or exit based on price, and for that, tick data is sufficient. The conditions I use for placing limit orders are not tied to DOM data either; only to price.

My main concern is whether the backtester is accounting for all the necessary information. For instance, I wouldn't be able to sell a contract at 20,000 if there's no buyer in the historical data. When a backtester only uses tick values, it might fill orders unrealistically. However, when bid, ask, and volume are considered, the results are more realistic because it would show that I couldn’t sell the contract at 20,000 if there were no matching buyers. I noticed this effect clearly in NinjaTrader's market replay.

After all this discussion, my concern boils down to how the backtester processes the data to produce realistic results. Having bid, ask, last price, and volume per tick is essential for this process, and as you've mentioned—and as I’ve seen in the documentation—the backtester does include this. However, wouldn’t incorporating DOM data make the results even more realistic? I am still assimilating the DOM concept.

Fernando Carreiro #:

1. Yes, but that also depends on your EA code. If your program is flawed, you may get some strange results and then think that it is the tester's fault, when in fact it is a coding problem. Be aware of that.

2.a. By ATM are you referring to Ninjatrader's Advanced Trade Management? If so, then that is just a naming gimmick. That does not really exist. It is just general trade management concepts which they have grouped and automated and given a fancy name. It definitely is not a strategy. In MetaTrader, those concepts have to programmed as per your strategy rules. They are not pre-automated, except for the Stop-Loss and Take-Profit. All the other concepts, such as trailing-stops, chasing, reversals, have to be coded yourself.

2.b. I lack experience with Futures, but I doubt incorporating the real DOM history, will have any impact if you don't actually trade against the order book in your strategy. The fact that you were confusing the Tick Data with the DOM, tells me that your strategy does not trade the order book directly at all. So, I believe, there should be no impact in the back-tests without the historical DOM.

 

This means that the tick data I have provides only the best price at which a contract could be bought or sold at each tick, along with the corresponding volume. This implies that I do not have access to all the bids and asks made, which represent the DOM and reflect the deepest level of supply and demand available.

Is my conclusion correct?

@Alain Verleyen #:

That's tick data, also sometimes called Time & Sales. Tick data are 'raw' data, from them you can build Time & Sales. These data are directly available in the Tester.

DOM is something else, the Depth of Market is showing the "depth" of offer/demand prices and volumes.

 

3195512 #: I appreciate the help. Let me explain my strategy's components in more detail so we can reach a clear and sustainable conclusion.

First, you're right—my strategy does not use any order book (DOM) information. I simply place limit orders to enter or exit based on price, and for that, tick data is sufficient. The conditions I use for placing limit orders are not tied to DOM data either; only to price.

My main concern is whether the backtester is accounting for all the necessary information. For instance, I wouldn't be able to sell a contract at 20,000 if there's no buyer in the historical data. When a backtester only uses tick values, it might fill orders unrealistically. However, when bid, ask, and volume are considered, the results are more realistic because it would show that I couldn’t sell the contract at 20,000 if there were no matching buyers. I noticed this effect clearly in NinjaTrader's market replay.

After all this discussion, my concern boils down to how the backtester processes the data to produce realistic results. Having bid, ask, last price, and volume per tick is essential for this process, and as you've mentioned—and as I’ve seen in the documentation—the backtester does include this. However, wouldn’t incorporating DOM data make the results even more realistic? I am still assimilating the DOM concept.

Since I lack the experience with Futures, what I am about say could be incorrect, but ... if your strategy is so "delicate" that the lack of DOM history could through your results off so much, then it is NOT a good strategy.

It would mean that the strategy is not robust enough to handle different market conditions and any little "glitch" would through it off and cause great losses.

So, as long as the back-tests can be 80-95% accurate compared to the live trading, I would consider it irrelevant if the DOM history is used or not.

What is important, is that in the back-testing, all the logic is executed accurately and correctly according to your strategy and trading rules, and that in general terms, it is sufficiently profitable, and the metrics, such profit-factor, recovery-factor, draw-down, MAE, MFE, etc. are favourable in your analysis.

After that, apply the EA on a live demo account, and compare the results. If they are within the margin of error compared to back testing, then move forward and don't focus so much on having the "perfect" back-testing conditions.

If the back-test and live trading are very different, then blame the strategy or the code. The back-testing abilities will be the least of your problems.

 
3195512 #:

This means that the tick data I have provides only the best price at which a contract could be bought or sold at each tick, along with the corresponding volume. This implies that I do not have access to all the bids and asks made, which represent the DOM and reflect the deepest level of supply and demand available.

Is my conclusion correct?

I may be misunderstanding your issue, but the tick data also provides the ask and bid quotes too, as it progresses.

However, the "proof is in the pudim"—why not just code a simple EA (or use and existing EA) , with a very simple strategy and run it o demo account and run a back-test for the same period and compare them.

Sometimes, the best way to learn, is to simply DO instead of asking.

Also, here is a question for you, that may help explain to us your line of thinking—why did you decide to make the change from Ninjatrader to MetaTrader?

Was it because of the back-testing or was it for another reason?

If the back-testing on NT was sufficiently accurate and reliable, then there should be no trouble in that aspect with MetaTrader. If however, you are switching because your back-testing with NT was not sufficiently the same as your live trading, then it is most likely a problem with the strategy or code-logic, and not with the back-testing.