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?
The PZ Day Trading indicator detects reversals in a zig-zag fashion, without repainting or backpainting. Based on breakouts of variable lengths, the indicator uses only price action to pick trades and reacts to the market very fast. The positional accuracy of its signals offers huge opportunity for profits, easily up to 80% winners.
Amazingly easy to tradeChart statistics will help you to optimize your tradingIt works on every single timeframe without fine tuningThe indicator analyzes its own q
Pivot Points MT5 is a universal color multicurrency/multisymbol indicator of the Pivot Points levels systems. You can select one of its three versions: Standard Old, Standard New and Fibo. It plots pivot levels for financial instruments in a separate window.
The system will automatically calculate the Pivot Point on the basis of market data for the previous day (PERIOD_D1) and the system of support and resistance levels, three in each.
A user can choose colors for the indicator lines.
Who will be interested in this product:
those who are used to diversify the portfolio with a large number of pairs. those who work with a large number of orders those who trade news using pending orders (see the "Grid request" tab).The panel is designed to make managing a large number of orders as easy as managing one.
The currency pairs and order types for opening are formed here. The prices and stop levels are set.
User can define the price valu
Trade Channel Indicator DCMV
The DCMV Indicator calculates the following Channel characteristics:
Channel Bounds (for TP and SL). It's assumed that price will never go outside the channel.Center Line of the Channel.Settlement price (with probability 90% the price will return to this line).Reference line (used for detection of trend).Upper and Lower breakborder. Used for generation of trade signals: channel breakout (trend strategies), false breakouts (flat strategies).Usage:
The indicator pro
Fast Copy MT5 allows 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
MT5 —> MT5 MT5 —> MT4 MT4 —> MT5 MT4 —> MT4
* For any interaction with the MT4, it is necessary to additionally install Fast Copy MT4
One tool for sending and receiving transactions: [master] > [slave] operation mode can be selected in
The most profitable trend traders are the ones who know how to recognize not only the market trend, but also the trading opportunities that arise once a trend has been established. The Pz Trend Trading indicator has been designed to profit has much as possible from trends taking place in the maket.
Established trends offer dozens of trading opportunities, but most trend trading indicators neglect them completely, and leave the trader completely uninformed about what the market is doing during a
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
The script creates account summary report in a separate window.
The report can be created for all deals and on deals for selected financial instruments.
It is possible to specify a time interval of calculation and save report to htm-file.
The script creates account summary report in a separate window.
The report can be created for all deals and for deals of the selected financial instruments.
It is possible to specify a time interval of calculation and save report to htm-file.
This indicator gives full information about the market state: strength and direction of a trend, volatility and price movement channel. It has two graphical components:
Histogram: the size and the color of a bar show the strength and direction of a trend. Positive values show an ascending trend and negative values - a descending trend. Green bar is for up motion, red one - for down motion, and the yellow one means no trend. Signal line is the value of the histogram (you can enable divergence
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.
We present you an effective software solution for arbitrage between brokers.
The Arbitrage on the market became widespread due to decentralization. There are many liquidity providers, whose quotes differ for various reasons. By tracking the dynamics of changes in the quotes of different brokers, it is possible to determine the delayed and leading brokers, thereby predicting the future prices of the delayed broker for a short time. Knowing these prices and using efficient built-in software filte
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 Expert Advisor implements the classic "triangular arbitrage", which is successfully used by hedge funds.
"Triangular" 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 balancing cross rates of all currency pairs.
The advantages of the strategy are the following:
The indicator determines and marks the short-term lows and highs of the market on the chart according to Larry Williams` book "Long-term secrets to short-term trading".
"Any time there is a daily low with higher lows on both sides of it, that low will be a short-term low. We know this because a study of market action will show that prices descended in the low day, then failed to make a new low, and thus turned up, marking that ultimate low as a short-term point. A short-term market high is just
Unique "scalping" trend indicator with the feature of multi-layered smoothing of the resulting lines and a wide selection of parameters. It helps determine a probable change in the trend or a correction virtually near the very beginning of the movement. The toggled intersection arrows are fixed and appear at the opening of a new bar, but, with enough experience, it is possible to look for entry opportunities as soon as the indicator lines intersect at the unfinished bar. The signal appearance li
Main Pivots is an indicator which looks for pivots points on preset intervals (days, weeks, months, years, etc.). Then all extreme points are checked for splice and consistent support and resistance lines are formed. These lines are useful for detecting the best pivot points.
It finds a pair of pivot lines for each interval which correspond to Low (support line) and High (resistance line) of the price movement on the interval. Difference between these lines represemt the price movement for the
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
AIIV EURUSD - Active Index Inflection Values EURUSD
The Indicator Shows:
The intensity and the direction of the movement of USD. The intensity and the direction of the movement of EUR. The inflection value of EURUSD.This indicator allows determining a state of inflection on the market with a delay of one-two candlesticks and a 60% precision (precision depends on the chart timeframe - the higher the timeframe, the more precise is the forecast).
AIIV is a series of indicators of inflection
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
DCMV Trade Channel Oscillator
The indicator calculates the values of DCMV trade channel oscillator:
Trade channel width. The value of trade channel depends on the trend (it increases at start of the trend and has the maximum values at end of the trend). The value of trade channel decreases at flat movement. The lowest values of channel width indicates the high probability of the very strong price movement.
The +DC line shows the "bulls" power. The -DC line shows the "bears" power. Th
MultiRSI indicator is a combined RSI indicator for several currencies allowing users to analyze their group movement.
Like all indicators of that kind, it helps identify the currency that is currently the most deviated from the market's general movement, as well as the most oversold or overbought currency in the cluster analyzed by RSI oscillator.
For example, the screenshots display the cluster of 7 currencies with Euro as a base one: EURUSD, EURGBP, EURCHF, EURAUD, EURCAD, EURJPY and EURNZD.
The Trend Strength is now available for the MetaTrader 5.
This indicator determines the strength of a short-term trend using the tick history that is stores during its operation.
The indicator is based on two principles of trend technical analysis:
The current trend is more likely to continue than change its direction. The trend will move in the same direction until it weakens.The indicator works on the M30, H1, H4 and D1 timeframes.
It is easy to work with this indicator both in manu
The indicator is based on readings of two oscillators: Bulls Power and Bears Power. It clearly shows the balance of buyers and sellers power. A signal for entering a deal is crossing the zero line and/or a divergence. When the volume filter is enabled, yellow histogram bar shows low trading volume (below average for 50 previous bars).
Period - calculation period, 13 on default; CalculatedBar - number of bars for displaying a divergence, 300 on default; Filter by volume -
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
This is a classical trading strategy, which falls into the category of breakout systems. They form support and resistance levels, which temporarily limit further price movement. When the price breaks down the support level or breaks up the resistance level, there emerges a strong momentum in the breakout direction, which allows to make profit on strong price movements with moderate risk.
To create the strategy, we used historical data with the quality of history of 99.9%.
It uses filtration o
Energy line is calculated similar to kinetic energy in physics: E = (mv^2)/2. Tick volumes (money stock) are used as mass, while price rate of change (ROC) is used as velocity.
Energy direction (positive or negative) is defined by ROC direction.
Chaikin Volatility (CHV) indicator is additionally used. Since the volatility starts increasing before the price actually moves, CHV notifies of the increased market activity in advance. Calculations result in the energy release, which usually occurs b
This Expert Advisor trades news on any timeframe.
The news are downloaded from the Forex Factory website. Make sure to add the URL to the terminal settings.
The EA is launched on a single chart and defines all necessary pairs for trading on its own.
The robot works with pending orders setting two Buy stop and Sell stop orders before a news release.
It determines the time zones of the calendar and terminal automatically. Make sure to add the time.is URL to the terminal settings.
The EA can b
The indicator generates early signals basing on ADX reading data combined with elements of price patterns.
Works on all symbols and timeframes.
The indicator does not redraw its signals. You see the same things on history and in real time.
For better visual perception signals are displayed as arrows (in order not to overload the chart).
The indicator is a complete analogues of the Trend Monitor indicator for MetaTrader 4
The best results are obtained when the indicator works o
The indicator is based on the digital window-sinc filter with an excellent frequency division. Due to this property you can get a very smooth indicator line.
The indicator has three lines: the central line indicates the main trend direction and the "fair" price, the other two lines show the price range. When the central line is read, it is recommended to buy from the bottom line and close a position above the central line. When the line is blue, do the opposite - sell from the upper line and cl
The TrendX is a technical indicator which allows to determine not only the movement direction of the market, but also to identify the flat areas.
It is based on the CCI indicator and a combination of price patterns.
The indicator works on all symbols and timeframes.
Two parameters allow to customize the indicator as needed, PERIOD is the period of CCI and T_Value is the significance of the trend.
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.