I've developed trading systems on other platforms for over 10 years. I had 12 years of experience working with Tradestation and I've used several other platforms.
If I backtest a system in Tradestation, I can be 99% sure that (other than slippage, fills, etc) it would have traded in realtime exactly the way it backtested. In other words if the backtest says the system performed like X, I can trust that that's the way it would have traded in realtime. I can look at a backtest report or a chart of indicators and be confident I would have seen the same thing in realtime.
I've been digging into MT4 for a few weeks. It seems that "repainting" is a constant issue with MT4, and that means you can't trust what you see on the historic chart. Having coded up a few indicators, I begin to see why. I avoided calling other indicators with iCustom because I didn't know for sure what they were doing, so I implemented it myself. Then I discovered that wasn't enough, because MT4 didn't work the way I thought. I thought it would scan through all the bars in history, and then deliver realtime ticks. I found it did this, but it also re-plots older bars seemingly at random -- sometimes just the last few bars, sometimes the whole chart. And unless you're very careful about initializing everything appropriately, the replot of the whole chart might end up re-using your values from realtime, resulting in a totally bogus result.
I've hacked together a few workarounds to try to deal with this behavior. For example I used the "history bars, then realtime ticks" assumption, but as soon as I got a realtime tick, I set a "realtime" flag and quit processing older bars. That sort of worked, except when it recalculated the whole chart and re-used my realtime values. So if it tries to replot more than, say, 10 bars, I'll say "ok, replot the whole thing from scratch." I think I've written my code so a "replot from scratch" operation will be stable and match realtime results, but I'm not 100% sure.
Surely somebody has worked this out and documented a "how to write stable code for MT4" process? Is there some document that explains how MT4 really operates and how to code reliable indicators and EAs? The MQL4 docs I've found so far, including at book.mql4.com, don't cover this, at least not in the parts I've gotten to so far.
Thanks for any pointers!
Reverse TradeCopier Follow can copy trades from an account that is running Reverse TradeCopier Source.
Copies trades from one source (master) account to multiple following (slave) accounts. Allows investor (read only) password for source (master) account. There are no complicated settings and input parameters, everything is easy. Works with different brokers. Works with different quotes symbols (EURUSD_FX, eurusd_m, etc.). Can copy orders from 4-digit quotes platform to 5-dig
Market Profile defines a number of day types that can help the trader to determine market behaviour. A key feature is the Value Area, representing the range of price action where 70% of trading took place. Understanding the Value Area can give traders valuable insight into market direction and establish the higher odds trade. It is an excellent addition to any system you may be using.
Blahtech Limited presents their Market Profile indicator for the MetaTrader community. Inspired by Jim Dalton’s
Three variables are available for every strategy, any one of them can be disabled, their period can be changed.
type_order=ORDER_FILLING _FOK - order filling type.
ReverseTrade=false — trades opens in reverse direction if true. ExitOnBar=true — trades close on each bar only. spreadcover=false — Spread you pay includes in profit trades. It's like trade with zero spread but you should remember that it can decrease exact match between tester's result and live one. It
This is the SMART BREAKOUT EA which allows you to trade HIGHs and LOWs of any hour and any day range you decide.
SMART BREAKOUT allows you to trade favourite strategies such as London Breakout, Day Breakout, US Session, Asian Session.
LONDON BREAKOUT (one of the strategies used by institutions and big players) you can set to trade range between 8-9 o'clock of London time. After 9 o'clock two pending orders are set up. Buy stop for High level and Sell limit for Low level. Once the prices reach
Cluster analysis of volumes is now available in MetaTrader 5!
The YuСlusters indicator is a professional tool for analyzing the trading volumes. The cluster graph is plotted based on tick data. For the exchange financial instruments these are the volume, type and price of a deal. For the Forex instruments - the real or tick volume (depending on the broker) and Bid price.
There are 6 criteria of cluster generation:
Time interval, the criterion is set in seconds. Price range, the criteri
This panel represents a demo account for binary options. It will catch an interest of those who start working with binary options and want to practice on a demo account. It will also spark an interest of those who use Meta Trader 5 to get signals for binary options. You can test any strategy using this panel. It supports any currencies available in your terminal. The panel is also very compact, and you can move it to any spot on your chart window.
Now you do not need to look for a broker with a
Create your own list of trading instruments Watch list* and combine it with several open charts Link **.
Using this program, a user can create fully-fledged Watch lists, create and delete trading instruments and move through the list.
A selected symbol shows charts in linked windows. Linked windows can have different periods, indicators, experts, trading panels, etc...
Moving through his/her Watch list, a trader an see the full image of his/her strategy in all windows.
A lot of traders use 1
The script is intended for automatic placing of Sell Stop pending orders, Stop Losses and Take Profits on the user specified levels. This script is not that useful as "Virtual pending buy stop", since short positions are opened as Bid price crosses the levels. Thus spread widening is not dangerous. Nevertheless, you need to have this script to prevent unwanted hitting of the Stop Loss levels.
Automation of the process of placing the Sell Stop pending orders, Stop Losses and T
Monitoring and Trend Analysis
This product shows the trend strength levels based on 16 standard indicators, time periods and currency groups.
Depending on the current trend, the indicator colors change from green to red, allowing you to see the full picture.
Whatever your trading method and strategy are, you should always know, in which direction you are trading and what the probability of the trend change is. This indicator will help you answer these questions by calculating the
The indicator is designed for easy construction of synthetic charts based on data of various financial instruments. It will be useful both arbitrage and pair trading, as well as for analysis purposes. Its main advantage is simplicity and clarity. Each chart is given as a common mathematical formula. For example, if you want to plot the spread (difference) between EURUSD and GBPUSD with coefficients 4 and 3, then set the following formula:
EURUSD * 4 - GBPUSD * 3
The resulting chart is shown in
Robust median Renko style indicator for creating custom charts resembling Median Renko, Mean Renko, Turbo Renko and Better Renko candles as well as vanilla Renko with wicks plus PointO charts. This all in one package provides all of the signals needed by day traders, scalpers and even long term traders.
The indicator is an overlay on the main chart so it is possible to utilize one-click trading and order manipulation directly on the custom charts. Visual order placement is a
This is an utility for automatic scaling of a chart and making at least 140 bars visible in it. This is necessary for a correct wave analysis according to the Bill Williams' strategy "Trading Chaos". The utility can be used on any timeframe available in МetaТrader 5.
It draws a vertical line through the first bar the calculation starts from. This line allows you to see the probable starting point of the wave sequence along with a sufficient number of bars displayed in the chart. It also makes t
This indicator extracts a trend from a price series and forecasts its further development. Algorithm is based on modern technique of Singular Spectral Analysis (SSA). SSA is used for extracting the main components (trend, seasonal and wave fluctuations), smoothing and eliminating noise. Does not require the series to be stationary, as well as the information on presence of periodic components and their periods. It can be applied both to price series and to the data of other indicators.
Patriot is a scalping Expert Advisor for trading highly liquid pairs, such as EURUSD, GBPUSD, EURJPY, USDCAD, AUDUSD. This is neither a grid, nor a martingale. It uses one standard Momentum oscillator and price movements analysis. The EA is easily adapted for current market conditions and does not require trader's interference. It has two levels of moving deals in breakeven to minimize possible losses and trailing stop to maintain open positions in order to receive the best profit.
This EA requ
The Trade Manager Pro EA is a MetaTrader Expert Advisor that performs position management for you avoiding human errors and enhancing your trading activity.
Amazingly easy to use Trade easily from the chart Trade with precise risk management, hassle free Capital preservation is top priority Let profits run without your attention Enjoy risk-free trades as soon as possible Automatic trailing stops for all opened trades Initial stop losses are placed as soon as trades are
Does not support openning multiple orders on a single symbol on MT5
MultiMTCopier MT5Source - new and improved multi-terminal positions copier for your real / demo account, works faster, requires less, flexible in managing and upgrading, new information support. This expert is designed for terminal MetaTrader5 from which the position will be copied.
The EA will copy all positions without delays Additionally integrated notification in situations requiring user attention Butt
Fast Copy MT5 allows you to copy trades between different MetaTrader 5 (netting)(hedge) and MetaTrader 4 accounts in any direction and amount, quickly and easily (without loading the system).
Any type of copying is available
MT4 → MT5 MT4 → MT4 MT5 → MT5 MT5 → MT4
* For the MetaTrader 4 terminal — Fast Copy MT4
* For the MetaTrader 5 terminal — Fast Copy MT5
** Before the purchase, you can test the program by downloading the free demo versions — Fast
All traders using VSA realize the importance of the volume. Unfortunately, tick and spot volumes are not suitable for these purposes.
I have conducted mathematical calculations and managed to trnsform the price into the volume that is close to the futures one by its ratios. Now, you do not have to wrestle with the question of where to obtain the volume data. Besides, you will be able to use the currency pairs having no futures at all. With RealVolume, you do not need to remember data on each ti
The indicator represents an additional chart window with a lower time frame where bars are combined into groups that are equivalent in time to main chart time frame. Bars are synchronized by the right hand side of the window, i.e. the time of the last bar in the main window corresponds to the time of the last bar group in the additional window. The maximum number of groups is 16; the maximum number of bars combined into groups in the additional window is 256. Limitations on the numbers are requi
Trade Controller provides multiple methods to protect and maximize your profits. This powerful weapon helps you to set the protect and trailing-stop rules on your trade automatically in many effective methods. Once it is set and turned on, you don't need to monitor your orders anymore, the software will keep watching and control your orders with your predefined rules.
It's designed to support multi-protection and trailing strategy: Protect by break-even, protect by percentage, protect by pip, p
FULL Automatic is a fully autonomous trading robot for MetaТrader 5 without configurable parameters.
It is similar to SAFE Automatic robot intended for traders having no knowledge of trading basics. It works in Low, Medium, High and Extremal trading modes.
The EA applies modified versions of well-known strategies, including Elliott waves, following a trend, half-pyramiding, scalping, speculative trading with a double deposit protection. The EA switches the strategies automati
Does not support openning multiple orders on a single symbol on MT5
MultiMTCopier MT5Receiver - new and improved multi-terminal positions copier for your real/demo account, works faster, requires less, flexible in managing and upgrading, new information support. This Expert Advisor is designed for the MetaTrader 5 terminal, trades will be copied into this terminal.
The EA will copy all positions without delays Additionally integrated notification in situations requiring user
This is the Famous Timing Indicator
You can now use the most famous Timing indicator on the planet.
Millionaire Mostafa Belkhayate earned his reputation by using this specific indicator to validate the entry signals supplied by his also famous Center of Gravity indicator on the Forex market. I spent hours, days, weeks to decrypt the formula and now it is finally available to you.
New and Unique for MetaTrader 5
Timing will give you perfect validations for your entry signals. It is the first
The script is intended for automatic placing of Buy Stop pending orders, Stop Losses and Take Profits on the user specified levels.
Avoiding unwanted entering a long position in case of false hitting the level as a result of widening of the spread by a dealing center. Avoiding unwanted triggering of a Stop Loss in case a quote pierces a significant level (fractal) without further confirmation with the close price. Setting a necessary virtual order and entering the market in
The indicator is intended for determining the spread and swap size, the distance for setting stop orders and stop losses from the current price allowed and the risk per 1 point in the deposit currency.
The indicator informs a trader about possible additional expenses and profits connected with transferring a position to the next trade session of the financial instrument. It also informs about the spread size and the distance of pending orders, stop loss and trailing from the current price. In a
How to use Pair Trading Station
Pair Trading Station is recommended for H1 time frame and you can use it for any currency pairs. To generate buy and sell signal, follow few steps below to apply Pair Trading Station to your MetaTrader terminal.
When you load Pair Trading Station on your chart, Pair Trading station will assess available historical data in your MetaTrader platforms for each currency pair. On your chart, the amount of historical data available will be displayed for each currency
This is an open interest indicator for MetaTrader 5. It fixes open interest value once per minute and writes it to the file (on your PC). The product works on any timeframe but only with exchange instruments.
This indicator is based on Bollinger Bands indicator. It helps user clearly know the Band is expand or contract.
Percent Crosshair is a powerful and easy percentage measure tool.
Measure the chart percentage very quick! Don't waste your time anymore!
Just attach the Percent Crosshair indicator in the chart, select crosshair mode at toolbars or press "Ctrl+F" and start using the crosshair as you always do! The percent measure will be next to the indicative price.
Customize your indicator the way you want!
There are 4 entry parameters:
Positive % color: set the desired color when % is positive. Negat
Tick volume is equal to amount of ticks at the unit of time. There is direct correlation between tick volume and real amount of deals. Every change of the price is a result of a real request to perform a deal. Consequently, fewer requests we have, the less price changes we get, and, as a consequence, tick volume is smaller.
In this case, when big amount of requests appear on the market, price changes happen more often. Big tick volume appears. Tick volume is an important indicator of trad
Is there a "How MT4 really works" manual? No.
It seems that "repainting" is a constant issue with MT4. Agreed, depending on how the Indicator was written.
Surely somebody has worked this out and documented a "how to write stable code for MT4" process? Talk to Rosh, JJC and SDC. They're indicator guys.
Is there some document that explains how MT4 really operates and how to code reliable indicators and EAs? No. At least not enough to satisfy everyone's opinion.
Here's links of interesting topics I've seen on this. Link1, Link2, Link3.
You didn't say if you're getting these in Back-tester or Live. Example, you start out talking about "back-test a system in Tradestation" followed by "real time" and "re-plots older bars seemingly at random". Are you referring to 0-Bar info in Back-tester or 0-Bar Info on Live charts? Or both? Is there any circumstances where it happens more often? Like hitting the Home-Key, or Refresh?
For something like this, you'll definitely need to provide Codes and a Picture.
Rosh works for Meta-Quotes. Contact him if you think its a Bug. He'll ask you for Code.
My Personal Opinions:
I don't like Indicators. Tho I have nothing against them. Their Job in my opinion is for Visual Aid. Or put another way make the Chat look pretty.
Never written one and hope I never will have to unless I wanna make my chat Pretty.
To a manual trader this is a necessity. For an EA trader spending more of his time in the back-tester they're almost Pointless in Mt4 IMO. If I'm in doubt about if a EA is doing what it's doing, I'll use objects. A trend based Indicator would give 90% the same info as another Trend based Indicator. Same for Counter-Trend etc. All one have to do is play around with the default Periods and they start to look alike. I don't see why people keep making new Indicators which are doing the same old things.
I'm sure the forex Police is going to hunt me for the above statements but thats just my Opinions.
Thanks, I will read through your linked articles.
Being a newb at MQL, I haven't yet written an EA. I started out with indicators because it seemed a simpler starting point. I've seen indicators repaint live -- e.g. a candle closes red, but later turns green, etc. What you see looking at historic bars is not what you would have seen in realtime, when you were using that indicator to make trading decisions.
I often find indicators very useful -- for debugging my systems / EAs.
Do I understand from your comments that "repainting"-like behavior is not a problem in EAs? MT4 doesn't re-evaluate bars multiple times in EAs?
Do I understand from your comments that "repainting"-like behavior is not a problem in EAs? MT4 doesn't re-evaluate bars multiple times in EAs?
Allow me to speak from the point of view of a Back-Tester because thats what I'm more familiar with. I Never-Ever use Bar-0 information (Except for Open lol...Because that does not change). When I was a Newbie looking at indicators on charts and pretending to place trades, I would see an indicator Cross.... Only to find on the next tick the Cross disappeared. If I would have placed that trade and the Cross Never materialize after the Bar-Closed. Someone else looking at that Order would wonder why I didn't stick to the system of only placing the trade when the Indicator Crossed.
This is how Indicators work in Real-Time. One would have to read about the Limitations of the Back-Tester in Detail (and also some understanding on the example above) in order to understand how to program a Back-Tester Friendly EA. Otherwise you'll be like countless people who run in here complaining about how mt4 is Soooooooooo buggy.
So Yes, what you see will not be what you get depending on how the EA is coded. Another thing about Bar-0 information is that the Back-Tester assumes the Bullish Bar went down-first.... and then went up.... and closed above Open-Price. And Vice-Versa for Bearish Bars. If in actually the price Bounced Up first and then down and then up again before it closed. Your scalping 9-Pips Stop-Loss on your Sell-Trade would have gotten hit before the 9-Pips profit. But the Back-Tester would report this as Profit getting hit first. <---- Just another example of Bar-0 issues.
If you need to test price sensitive strategies like scalping then you'll be better off using Tick-Data. There are lots of other examples. As far as your actual problem with Indicators, I think it has more to do with the Number of Bars on the Chart Changing (Outside of the normal New-Bar process). I'm not sure why it happens, the last link gives a lengthy discussion. One reason it happens is by Scrolling the History. Another suspect would be because broker updates data. If you're using IndicatorCounted() it'll try to correct itself and re-draw everything. At least thats what I've got from reading those topics.
Oh, naturally indicators on bar 0 can change, because bar 0 itself is changing.
I'm talking about bar 1 or older closed bars. They should NOT change, but indicators calculated on them sometimes do. The example I mentioned above is a trend indicator that paints candles red/green, and I've seen that indicator change multiple times on bar 1. I understand many of the MTF (multi time frame) indicators repaint farther back than that -- e.g if you're calculating an indicator on M5 - M15 - H1, the H1 indicator might repaint as many as 12 bars back because the "H1 virtual bars" contain 12 M5 bars. I believe the idea is that the H1 indicator would have the same value for the full 1 hour period = 12 M5 bars, and that "H1 bar 0" keeps changing until the hour is over. So if you had a trend indicator on the H1 indicator it might start out red, then repaint up to 12 bars green if the market turned up. I think.
Where would one read about Limitations of the Back-Tester in Detail?
MT4 may not be soooo buggy. But its design in this area seems less than ideal. In Tradestation you *can't* make the kinds of mistakes that are so common in MT4 indicators. TS just doesn't work that way. At least with the basic techniques, TS won't let you write systems/EAs that work differently in backtests than in realtime. And that's a very good thing.
TS just doesn't work that way. At least with the basic techniques, TS won't let you write systems/EAs that work differently in backtests than in realtime. And that's a very good thing.
I dis-agree strongly. Hate to be Meta-Traders greatest fan. However, we're talking more about what you're used to and how you think it should be instead of how it really is. In the newbie example I give above, I don't think even Trade-Station can avoid that. Because they're simply logical Errors. And these are what I'm talking about.
Meta-Trader won't let you write systems/EA that works differently in back-tests than real-time either. If someone's EA does not work in real-time as it did within the back-tester then they failed to consider something. It could be as simple as "slippage, fills" like you noted before, or re-prints because they're using current price as I noted.
Or it could be because they failed to acknowledge that IndicatorCounted() and #Bars on chart have a relationship in MT4. This may not be the case in Trade-Station. As both of these may have their advantages and dis-advantages. Someone going to the Trade-Station side might form the opinion that it's bad design because it doe's not re-calculate all History on "Dirty" bars.
When you have solid proof that Mt4 performs differently than Reality, I'd like to be one of the first people know.
[...] Talk to Rosh, JJC and SDC. They're indicator guys.
Er, no. I've had to write my fair share of indicators, but I'm not an expert. I've written tens, possibly hundreds, of times more lines of EA code than indicator code.
It's possible for indicators in MT4 to re-paint historically, but they don't have to. The same is true of every other trading platform I've seen (which does not include Tradestation). It's arguable that it's easier to do this by accident in MT4. The related thing which MT4 also makes dangerously easy is accidentally building an indicator which can see into the future on historic data.
A few specific issues:
* Ubzen's link3: if extra historic data is added to a chart for some reason (e.g. user scrolls back beyond the current start date), then MT4 tells the indicator to redraw its historic values, and does not itself bother to shift the existing indicator buffers/data. If the indicator does nothing, you then end up with the wrong values being shown for each historic bar.
* Multi-timeframe indicators are problematic for much the same reasons as when trying to compare multiple timeframes manually. (Every trader I know who's manually compared different timeframes has at least once accidentally given themselves the ability to see into the future.) In MT4 there is no built-in way of saying something like "give me the historic H4 moving average up to 135 minutes through the last H4 bar, i.e. the value as-at a historic time halfway through the bar". If, retrospectively, you do something like getting the H1 moving average from an M15 chart, then you see bar-end H1 values, and the data you plot for historic M15 bars ending at xx:14, xx:29, and xx:44 will be based on the H1 value in the future at xx:59. There's no such problem when working on a forward basis but, correspondingly, if the indicator has to re-paint for some reason, then the correct intra-bar values which were calculated live will be replaced by incorrect bar-end values calculated on a retrospective basis.
* The various discussions of IndicatorCounted() are more about performance than about functionality. If you're writing something normal like a moving average or RSI indicator, then it doesn't matter whether your indicator calculates/plots 1 bar or the last 1000 bars on each tick. The historic values will only "repaint", i.e. change, if the historic data somehow changes - or if there's a bug in your code. The discussions of IndicatorCounted() are mostly to do with trivial performance gains from ensuring that your indicator does not re-plot more bars than are actually necessary; they're not really dealing with any "repainting" issues.
EDIT... all this with the caveat that things like exponential moving averages are universally - not just in MT4 - dependent on the length of your data series. If you calculate an EMA once, and then add extra historic data at the beginning of the series, the EMA values for all subsequent bars change (albeit usually by trivial amounts). That's simply how things like EMAs work.
Phy is a walking encyclopaedia of MQL4 if you can reach him.
Er, no. I've had to write my fair share of indicators, but I'm not an expert. Fair enough, I'm not gonna put you out there like that next time ;).
Ok, now I'm confused about Multi-Timeframe Indicators. Last time I read about Multi-Timeframe the conventional way of using it went something like this: Lets use Macd above 0 as Up-trend and Macd below 0 as Down-Trend all other values for Macd as default. I have 3 Time-Frames which must say Up-or-Down before I place the trade. Example H1>0.00, M15>0.00 and M5>0.00 then Buy.
The current time is 12:24 pm (Mid-Day). Is someone actually looking at the H1 values for Macd beyond 12:00? Or the M15 value beyond 12:15? Or the M5 value beyond 12:20? To place that trade. If they are, then aren't they using Current Bar (Bar) information for H1, M15, or M5.
If they're not, how can this information change?
Say at 12:00 pm (Mid-Day), my Indicator drew a Green Vertical line indicating Buy. If the indicator redrew everything for whatever reason at later time.
How is it possible that the Green Vertical Line will become Red indicating Sell?
Please forgave any mis-information I have about Multi-Timeframe or Indicators in general.
There's no problem with that...
It's to do with calculating the historic values for display when an indicator loads (or is re-initialised). The same thing could potentially apply to an EA, but it's very unusual for an EA to need to do this kind of retrospective calculation.
I'll try to give you a clearer example, including some of the relevant MQL4 code. Let's say that you have an indicator on an M15 chart which wants to draw a buy signal if RSI is below 30, both on M15 and also on H1. It's currently 2:03pm, and the indicator wants to fill in the values for some historic bars as well as starting to draw itself on a forward, on-going basis.
Let's take the historic bar at 13:30-13:44, which will be bar #2 on the M15 chart (i.e. Time etc). The indicator on this M15 chart can get the historic M15 RSI for this bar simply by doing iRSI(..., 2). No problem there.
The issue is around getting the H1 RSI part-way through a historic hour at the end of an M15 bar. The M15 bar starting at 13:30 is part of the H1 bar from 13:00-13:59, which will be bar #1 on the H1 timeframe. But if the indicator does iRSI(Symbol(), PERIOD_H1, ..., 1) then it gets the RSI value at the end of that historic H1 bar, i.e. at 13:59, not the interim value at 13:44. Therefore, against a historic M15 bar running from 13:30 to 13:44, the indicator is going to plot an H1 RSI value from 13:59. In effect, the indicator can see into the future. That's why lots of people like MTF indicators: they often appear spectacularly successful when applied to historic data...
There is no easy way round this in MT4. In order to calculate the true historic RSI on the higher timeframe, you have to (a) manually build your own H1 bar data with the correct interim value for the last of the bars, and then (b) do your own RSI calculation on this special bar series.
It's very uncommon - but not impossible - for this to apply to EAs simply because they typically do a comparison between timeframes based on current data only, and don't try to do such retrospective calculations at historic bar-ends.
There's a simple rule of thumb. If you have an indicator or EA which uses iWhatever(..., PERIOD_YY, ...., N) then you need to think carefully about what data you're actually looking at if YY is higher than the chart timeframe which the EA/indicator is running on, and if N > 0.