I know this has been asked before, but it has never been clarified to my knowledge.
The manual states that IndicatorCounted() returns the amount of bars not changed after the indicator was launched most recently.
most cases only the zero bar (current bar) is considered not to be
counted, so IndicatorCounted() returns the number of bars minus 1. (I.e.
all bars except for one is counted.)
However, there are some
cases in which a tick is lost during program execution. When the bar is
closed (its formation is done), this tick will not have been taken into
account. That's why some people want to calculate the previous bar AND
the current bar, in case the previous bar is erroneously formed due to a
A solution to this problem, which even the "MQL reference" exemplifies, goes like this:
Now the previous bar will also be considered not counted. This
solution (or a variant of it) is used in almost every custom indicator
However, the MQL Book does something completely different:
The Book's example on how to build a custom indicator does not
decrement counted_bars. In other words, the example only calculates the
zero bar (current bar) and not the previous bar as well. It justifies
this by stating that IndicatorCounted() does take into account the lost tick and therefore returns a
number that is one less than what you would normally get. (I.e. it
recognizes the previous bar as uncounted (changed) because the tick was
If you run this in a custom indicator:
counted_bars = IndicatorCounted();
bars_to_count = Bars-counted_bars;
Alert("More than one bar will be counted: " , i);
... you will be alerted once every minute (in a 1-minute timeframe), i.e. after each formation of a bar. This reinforces the view that IndicatorCounted() does not consider the previous bar to be counted right after it is finished (wants to recount it).
What's the point of decrementing counted_bars then, if IndicatorCounted() already does this for you? Please consider the image below:
Seems like you don't need to decrement counted_bars after all ...
So; what does IndicatorCounted() really do? Is the book correct, or are all the custom indicators and the MQL reference correct?
This indicator builds divergence/convergence for any selected indicator.
You can add your own indicator with its custom settings to the code for free.
The indicator has two basic line drawing methods (**):
Peak search on fractals without waiting the closure of the wave (MODE = each_bar_peak)Wave search for peaks after crossing the "ZERO line" of the indicator (e.g., "zero line" for RSI = 50.0) (MODE = WAVE_bar_peak)Basic settings include 21 standard indicators included in MT5 terminal, to whi
This Indicator is a unique, high quality and affordable trading tool because we have incorporated a number of proprietary features and a new formula. With only ONE chart you can read Currency Strength for 28 Forex pairs! Imagine how your trading will improve because you are able to pinpoint the exact trigger point of a new trend or scalping opportunity?
USER MANUAL: click here
Arrows in sub-window to show strong currency momentum GAP will guide your trading! Warning signs
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 robot does not trade at night from 10 p.m. to 4 a.m. (server time).
The robot was tested in the special tester on real ticks. Empirical e
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
FXG_Info – the most important data in one place.
MetaTrader 5 Indicator FXG_Info provides basic statistical information about a particular currency pair. So that in combination with a chart representing currency price it is easy to determine whether the current situation is good for trading. And when you open a position it will clearly show you the current data such as SL, TP, RR. You are not limited to currency. You can use any market which is provided by you broker.
The following information
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
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
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
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
Auto Trade Copier is designed to copy trades between multi MetaTrader 5 accounts/terminals with 100% accuracy.
With this tool, you can act as either a provider (source) or a receiver (destination). All trading actions will be copied from the provider to the receiver with no delay.
Note: Demo version for testing can be downloaded at: https://www.mql5.com/en/market/product/5006.
Followings are highlight features:
Switch between Provider or Receiver role within one tool.One provider can copy tr
The Number Levels indicator plots the levels of round numbers on the chart, which can be identified as the support and resistance levels.
The indicator implements the ability to set the interval between the round number levels For example, if you set HL1 = 1.00000, and HL2 = 1.05000, then the lines will be drawn every 500 points.
Important! To plot the round number levels for two or more different levels, it is necessary and sufficient to set different names to them in the indicator parameters
GoodTrade is the very first Expert Advisor purchased on the Market. On the occasion of the second anniversary of availability of the Expert Advisor on the Market, you are now looking at the second version of the Expert Advisor featuring a completely updated operating logic. GoodTrade now uses a new universal trading signal suitable for various trading instruments and working over long time periods. By default, the Expert Advisor is set to trade GBPUSD. Try it for other trading instruments. Set 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
This indicator provides tick volume delta analysis on M1 timeframe. It monitors up and down ticks and sums them up as separate volumes for buys and sells, as well as their delta volumes, and volume clusters on price scale within a specified number of bars. This indicator is similar to VolumeDeltaMT5, which uses almost the same algorithms but does not process ticks and therefore cannot work on M1. This is the reason for VolumeDeltaM1 to exist. On the other hand, VolumeDeltaMT5 can show its signal
The indicator is based on the comparison of the correlation of trading instruments following an original algorithm. It determines the difference between correlated contracts (delta). The greater the difference, the more it is likely that this Delta will return to zero.
More suited to the FORTS market.
The greater the deviation from zero, the more it is likely that the price will return to zero. Also, the indicator divergence can be applied by comparing highs and lows.
This indicator allows you to enjoy the two most popular products for analyzing request volumes and market deals at a favorable price:
Actual Depth of Market Chart Actual Tick Footprint Volume ChartThis product combines the power of both indicators and is provided as a single file.
The functionality of Actual COMBO Depth of Market AND Tick Volume Chart is fully identical to the original indicators. You will enjoy the power of these two products combined into the single super-indicator!
The economic calendar is made in the form of an Expert Advisor that downloads the data from one of the most popular Forex sites (forexfactory.com/calendar.php). The data is presented in two ways. The first (primary) is represented as icons with detailed information about the event. The second is displayed as a line with a news description. Economic Calendar downloads published news in real mode with the possibility to adjust the spacing of data validation and user-friendly customizable graphical
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
The fractal analysis of the markets is used in the indicator operation algorithm. According to the fractals theory, after the breakthrough of the fractal level confirmed by the closing price located below or above the fractal, the trend wave in the direction of the breakthrough starts to develop. Until the fractal has been passed in the opposite direction, the trend is considered to be acting even if the price is flat or moves backwards. If a bullish fractal has been previously broken through on
Envelopes or channel lines are set parallel to the Moving Average (to the slow MA if you use two MAs). The two channel lines must contain approximately 95% of all prices for the past two or three months on a daily chart, with only the extremes protruding outside. Channel lines provide attractive profit targets - sell longs near the upper line and cover shorts near the lower line.
The AutoEnvelope is a custom indicator - an original tool that automatically selects channels width by calculating a
Auto Trade Driver is an automatic powerful tool (run as Expert Advisor) that helps you to manage risk and control orders and maximize your profit in multi-protect/trailing-stop rules.
This tool is very useful for both scalpers and trend followers. It not only calculates the trade risk exactly, but also protects and maximizes your profits in real-time.
With this tool, the only thing you have to do is to enter trade by your own strategy, then it will auto-drive your position with exit strategy y
Veno EA MT5 is a safe and fully automated medium-term trading robot.
The EA does NOT use hedging, martingale, grid strategies, arbitrage, etc.
Veno Expert System MT5 automatically monitors the appearance of participants with distinct preference towards buying or selling on the market. Trades are conducted on sharp cluster and news based movements of the market. The robot analyzes the market volumes and volatility, and follows strong supply and demand movements. It smoothly sets breakeven level
Easy Order is an Expert Advisor allowing you to enter any type of trade with one click based on your RISK preferences.
You can choose to enter a trade and automatically calculate your lot size based on how much of your account you want to risk. Risk is calculated based on your Stop Loss placement. You can use a fixed lot size if you don't want to use risk based calculation of lot size. Your previous setting of risk based or fixed lot size remains saved for your next use of this Expert Advi
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
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
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
S2 Trend At Wavelet is designed to eliminate the noises on the Price Chart. A clear picture of the market flow will be seen due to the elimination of the unnecessary variations on the chart.
Capabilities of S2 Trend:
Chart End could be shifted to any desired point by Market End Line; A desired Scale could be used by selecting Scale Menu and the result will be shown on the chart; A separate diagram on the Main Chart could be shown by using Chart window's check box; Graphical representation
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
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
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
So it appears that when the first tick of a new bar appears, and gets the zero index, IndicatorCounted() is detecting both the new bar and also that something changed in the last bar. What could be changing in the last bar ?
Features of Custom Indicators Creation : https://www.mql5.com/en/articles/1497
The "IndicatorCounted" function allows to organize an economic calculation of an indicator. This function returns the amount of bars by the moment of the preceding launch of the indicator, i.e., the amount of bars having already been calculated (potentially, if there were no errors or early termination during the preceding launch) which do not need any recalculation. At reinitialization of the custom indicator or significant updating of history data, this amount will be automatically reset to 0.
Let us discuss one more example...
Author: MetaQuotes Software Corp."
Thank you for replying.
SDC: Yes, it appears so. Let's say your EA sleeps through 3 ticks and therefore does not call your custom indicator. Suddenly a new bar is formed. Then you would obviously want to recalculate the previous bar (because it finished without evaluating the 3 ticks). But the testing I did indicates that IndicatorCounted() wants to recalculate the previous bar regardless.
Ais: Yes, IndicatorCounted() returns the amount of bars that don't need recalculation. But my question is why so many indicators decrement the amount of counted bars:
What's the point of this if IndicatorCounted() always considers the newly formed bar (index 1) as not counted right after a new bar is formed? Decrementing will only cause the indicator to recalculate yet another bar (i.e. index 0, 1 and 2).
Here's an example of decrementing counted_bars (if(i>0) CountedBars--;)
Do you understand my concern?
Counting three bars doesn't make sense to me. How could the third bar (index 2) ever be wrong? (unless the EA sleeps through a whole timeframe which isn't even possible.)
"int IndicatorCounted( )
The function returns the amount of bars not changed after the indicator had been launched last. The most calculated bars do not need any recalculation. In most cases, same count of index values do not need for recalculation. The function is used to optimize calculating.
Note: The latest bar is not considered to be calculated and, in the most cases, it is necessary to recalculate only this bar. However, there occur some boundary cases where custom indicator is called from the expert at the first tick of the new bar. It is possible that the last tick of the previous bar had not been processed (because the last-but-one tick was being processed when this last tick came), the custom indicator was not called and it was not calculated because of this. To avoid indicator calculation errors in such situations, the IndicatorCounted() function returns the count of bars minus one."
The events in 04:49:19 and 17:08:26 are representing such boundary case, as stated in Documentation, the first tick of the new bar.
In this case, on first tick of bar, IndicatorCounted() returns the count of bars minus one.
On the next ticks of the same bar IndicatorCounted() returns simply the count of bars, without "minus one".
I usually do my indicator loop this way:
so I dont actually use
Ais: Thanks for replying. (I assume you meant "counted bars minus one" and "counted bars, without 'minus one'", because "the count of bars" refers to something else: the total amount of bars in the chart.)
This is how I understand it: At the first tick of a new bar, IndicatorCounted() returns the amount of counted bars minus one, not because the last tick of the previous bar had not been processed, but just in case it had not been processed. This is what my testing shows (referring to the two images I posted).
Do you understand it similarly? The documentation is obviously wrong, though, because "the count of bars minus one" is not worded correctly. It should be "the amount of counted bars minus one"
But the real question still remains: What is the point of this line:
Almost every indicator I've seen uses this or something similar to it, including the IndicatorCounted() example from the documentation. However, the MQL Book does not do this.
SDC: Thanks for sharing. Your code is exactly how I would write it. You only count the bars that IndicatorCounted() labels as "not counted". Decrementing counted_bars would cause the indicator to count yet another old bar.
From the documentation: (comments by me)
// Bars = 100
counted_bars = IndicatorCounted(); // counted_bars = 99
if(counted_bars>0) counted_bars--; // counted_bars = 98
limit = Bars-counted_bars; // limit = 2
// This will run TWICE (for Bar 0 and Bar 1)
Imagine what happens if IndicatorCounted() returns 98 instead of 99 (at the first tick of a new bar, as Ais pointed out). Then the 'for' loop would run three times; for Bar 0, Bar 1 and Bar 2. Unnecessary ... ?
"int IndicatorCounted( )
The function returns the amount of bars not changed after the indicator had been launched last."
Zero bar is always changing and always excluded from the count, and, consequently, we always have "minus one" in any case.
"int IndicatorCounted( )
However, there occur some boundary cases where custom indicator is called from the expert at the first tick of the new bar. It is possible that the last tick of the previous bar had not been processed (because the last-but-one tick was being processed when this last tick came), the custom indicator was not called and it was not calculated because of this. To avoid indicator calculation errors in such situations, the IndicatorCounted() function returns the count of bars minus one.""
In this case, on first tick of bar, IndicatorCounted() returns the count of bars minus one, that is "minus one for this boundary case" and as always "minus one for the zero bar".
Minus one and minus one is equal to minus two.
And if we use
then in "counted_bars" we will have "minus ONE MORE one", that is up to minus three on the first tick of bar.
When I tested different ways of writing the loop and decided the code above was the most convenient I let it run with an alert to display the value of i.
i remains at 0 during the formation of a bar then changes to 1 at the first tick of a new bar so at that moment it re calculates the previous bar, it then returns to zero, therefore calculating the current bar, I never saw i change to 2 ...
Ais, that is what I have been saying all along. You said: "then in "counted_bars" we will have "minus ONE MORE one", that is up to minus three on the first tick of bar."
I totally agree and I have been making this case since my first post. But why would you want "minus three"? Why would you count three bars? The third bar (index 2; third from the right) will never need to be recalculated, even if your EA sleeps through a whole bar. Only the second bar (index 1; second from the right) will need to be calculated in so-called "boundary cases". Why? As we have both pointed out countless times: IndicatorCounted() solves this problem for you. So I say you don't need to decrement counted_bars. It does it for you. Do you agree?
SDC: I'm not sure what code you are referring to. Could you please paste the code you have settled with and think is the most convenient?
counted_bars = IndicatorCounted();
bars_to_count = Bars - counted_bars;
13414, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1 ...
No decrementing needed, not matter how much your EA screws up.
"... I say you don't need to decrement counted_bars. It does it for you. Do you agree?"
And, do you want to know a secret?
I never use "IndicatorCounted()" in my programs.