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!
FourAverage: A Breakthrough in Trend Identification
With evolving information technology and increasing number of market participants, financial markets get less and less analyzable using good old indicators. Common technical analysis tools, such as Moving Average or Stochastic alone, are not capable of identifying the trend direction or reversal.
Can a single indicator show the right direction of the future price, without changing its parameters over 14 years' history, while at the same time
Cluster analysis is now available in MetaTrader 5!
YuСlusters indicator builds a cluster graph based on tick data. For exchange instruments it is the volume and the last deal price, for Forex instruments it is the real or tick volume (depends on broker) and selectable type of the current price: Bid, Ask or (Bid+Ask)/2.
There are 5 criteria of cluster generation: Time interval, the criterion is set in seconds. Price range, the criterion is set in points. The current cluster is closed when the
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
Pipfinite creates unique, high quality and affordable trading tools.
Our tools may or may not work for you, so we strongly suggest to try the Demo Version for MT4 first. Please test the indicator prior to purchasing to determine if it works for you.
We want your good reviews, so hurry up and test it for free...we hope you will find it useful.
Trend Laser with Volt Impulse
Strategy: Confirm impulsive signals Watch Video: (Click Here)Trend Laser with Energy Beam
Scalper with Automatic Parameter Setting
Would you like to have an Expert Advisor that could automatically calculate trade parameters and adjust to the current market situation?
We present you our new development for the Forex market. This is a tick scalper for МТ4 and МТ5 - TickSniper.
Trading with it is fully automated. Forget continuous monitoring - this Expert Advisor trades independently. Its settings have been optimized over the course of testing on our real accounts.
qAutoActivation indicator is one of the main components of Trading Chaos Expert trading expert panel. The indicator displays the current trend on the current timeframe. This is the first indicator that is attached to the chart and saved in the trading complex template. It defines what trading signals from the expert panel should be automated for market entry (bullish or bearish ones).
When the trend changes, the indicator changes the line color and, at the same time, highlights the trading pane
The indicator calculates the actual status of your position on FORTS market. Since your position is re-calculated after each clearing on FORTS and other futures markets, you can see the status of your position on the chart and in the "Profit" section only starting from the last re-opening (clearing). The indicator solves this issue by displaying the level of the very first deal opening, the actual profit, swaps, and commissions. The product is most useful for mid-term and long-term deals on FORT
Safe Automatic is a safe MetaТrader 5 trading robot working autonomously on a VPS server. The good results are achieved on EURUSD.
The EA applies modified versions of a trend-following strategy, half-pyramiding, scalping, Elliott Wave method and speculating trading with a deposit protection. The EA switches the strategies automatically. The program also takes the news calendar into account: the robot does not enter the market in a 10-minute interval before and after a news rel
VirtualTradePad is a panel for managing main orders in МetaТrader 5: Buy, Sell, Buy Stop, Buy Limit, Sell Stop, Sell Limit, Close, Delete, Modify, Trailing Stop.
This version is for informational purposes. Analyzing the main trade strategies using 10 indicators and 8 timeframes, the panel draws signal direction.
This pane is a part of the VirtualTradePad series that took 2-nd place in the Best Graphic Panel.
A free of charge demo version - VirtualTradePad Lite.
х - no s
The Turtle Trading Indicator implements the original Dennis Richards and Bill Eckhart trading system, commonly known as The Turtle Trader. This trend following system relies on breakouts of historical highs and lows to take and close trades: it is the complete opposite to the "buy low and sell high" approach. The main rule is "Trade an N-day breakout and take profits when an M-day high or low is breached (N must me above M)".
The Turtle Trader legend began with a be
The main purpose of the indicator is to determine and mark trade signals on the histogram of the Accelerator Oscillator, which were described by Bill Williams in his book "New Trading Dimensions". The list of signals:
The buy signal when the indicator histogram is below the zero line. The sell signal when the indicator histogram is below the zero line.The sell signal when the indicator histogram is above the zero line. The buy signal when the indicator histogram is above the zero line. The
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
Does not support hedging 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 Buttons for re
Active Lines - a powerful professional tool for operations with lines on charts. Active Lines provides a wide range of actions for events when the price crosses lines. For example: notify, open/modify/close a position, place/remove pending orders. With Active Lines you can assign several tasks to one line, for each of which you can set individual trigger conditions, as well as conditions for re-activations and the number of possible activations.
Active Lines helps you easily organize various tr
SafeZone is a method for setting stops on the basis of recent volatility, outside the level of market noise. It is described in "Come into my Trading Room" book.
In a downtrend, SafeZone defines noise as the portion of the current bar that extends above the high of the previous bar, against the downtrend. It averages the noise level over a period of time and multiplies it by a trader-selected factor.
For short trades, it adds the average noise level, multiplied by a factor, to the latest hig
The indicator has standard settings. The new modification of indicator provides special marking of the segment when the moving averages begin to form a cross in one direction or another. The Alligator`s cross indicates that the trend is about to change. Modified Alligator helps traders to determine a trend on a particular timeframe even if the averages are intertwined and have a shift in the future. Direction of a trend is determined by a cross of the averages with a specified marking area on th
The main purpose of the indicator is to detect and mark trade signals on the histogram of the Awesome Oscillator according to the strategies "Trading Chaos, second edition" and "New Trading Dimensions".
The indicator detects and marks the following trade signals:
"Two peaks" - Divergence. The signal "Second wise-man" - third consequent bar of the Awesome Oscillator after its color is changed. The histogram crosses the zero line. The signal "Saucer".The indicator includes a signal block th
PipTick VSA is based on the original Volume Spread Analysis method. It was designed for quick and easy recognition of VSA patterns. Even though this indicator looks very simple, it is the most sophisticated tool that we've ever made. PipTick VSA indicator is a really powerful analytical tool that generates very reliable trading signals. Because it is very user friendly and understandable, it is suitable for every type of trader, regardless of his experience.
What is VSA?
VSA - Volume Spread An
A script for opening a grid of orders
If you need to quickly open several pending orders (Buy Limit, Sell Limit, Buy Stop, Sell Stop) on a certain distance from the current price, this script will do all the routine for you! Allow AutoTrading before running the script.
Run the script on a chart.
Language of messages displayed (EN, RU, DE, FR, ES) - language of the output messages (English, Russian, German, French, Spanish). Price for open - open price. If set to
TTMM – "Time To Make Money" – Time When Traders Makes Money on the Stock Exchanges
The ТТММ trade sessions indicator displays the following information:
Trade sessions: American, European, Asian and Pacific. (Note: Sessions are displayed on the previous five days and the current day only. The number of days may change depending on the holidays - they are not displayed in the terminals. The sessions are also not displayed on Saturday and Sunday).
The main trading hours of
Purpose and functions of the indicator
The indicator determines and marks the moments of trend change on a chart based on the theory of fractal levels breakdown on any time frames. If a breakdown based on all rules is real, the horizontal lines will appear on the chart with corresponding color. If there is an up trend, the line will be blue. In the descending trend the line will be red. The blue line is a strong support level, the trader should look for buying opportunities above this line. The
Trading Chaos Expert Lite is a light version of Trading Chaos Expert. In the Lite version it is not possible to receive the table of trading signals, automatically place pending orders based on them and maintain open positions for multiple symbols at the same time in one window. Only the Current Chart mode is available. In all other features the panel is fully consistent with the basic version of the Expert Advisor.
This is, rather, a well thought out trader's assistant which is not easy to do
The Expert Advisor moves open positions to breakeven.
The EA can be launched on any chart. It tracks all open orders regardless of a symbol it is attached to. When the price moves the amount of points specified in the parameters, the order is relocated to breakeven.
The robot has only two parameters:
NonLoss - number of points to move StopLossPips - number of profit points the price should pass, after which the order is relocated to breakeven.Note! Moving to breakeven is done at the opening o
This software has no equals in the world and represents a universal trade "console" covering trading signals, automated market entry, setting of Stop Loss and Take Profit, as well as Trailing Profit for multiple trades at the same time in a single open window. Intuitive control of the Expert Advisor in "three clicks" ensures a comprehensive use of all its functions on different computers, including tablets PCs.
Interacting with additional signal indicators that mark the chart to give a real mar
The script allows users to easily close positions if their profit/loss reaches or exceeds a value specified in pips.
Please set slippage value first. Sometimes some positions do not close due to high volatility of the market. Please set larger slippage or restart the script.
Are you a swing trader? The PZ Swing Trading is the first indicator designed to detect swings in the direction of the trend and possible reversals. The indicator studies several price and time vectors to track the aggregate trend direction and finds situations in which the market is oversold or overbought and ready to correct.
Profit for market swings without getting whipsawed The indicator displays the trend direction at all times A colored price band represents the opportunity baseline C
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
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
Multi-TimeFrame version of the Super Trend (SuperTrend) indicator with filling function based on MQL4 code.
TimeFrame - used time frame:
Can be any of ENUM_TIMEFRAMES values.
TimeCorrection - use time correction:
Can be true or false (see the first screenshot with true input and a second is false).
Period - period to calculate the index:
Can be larger than 0. Multiplier - value of multiplier parameter:
Can be larger than 0. ShowFilling:
The Expert Advisor implements the classic "triangular arbitrage", which is successfully used by hedge funds.
Arbitrage refers to a class of neutral-market strategies, in which the profit or loss of open positions does not depend on the direction of the market movement as a whole.
In order to take profit, the EA exploits a weak spot of market makers - it utilizes the difficulty of combining cross rates of individual currency pairs.
The advantages of the strategy are the following:
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.