Articles on MQL4
The tick indicator in a separate window

The tick indicator in a separate window


for example, forex
I think most traders saw the tick indicator in the Market Watch window in the terminal MT4. It is also available when orders are placed by hand.

 
 


Many traders appreciated worthily the appearing of this type of chart in MT4 (in МТ3 it wasn’t available). But people get used to good things quickly, and for many traders this is not enough already, there were a lot of requests to add such type of charts in a separate window. We will try to create the tick chart by ourselves. It won’t be convenient to place such chart in the prices window, that’s why we will create it in the subwindow of the main chart. In order to achieve a formal resemblance we will choose the type of display in the form of lines. We launch Expert Advisor Wizard, give the name Ticks, there are no external parameters, the second step is to mark the check box «Indicator in a separate window», add an index of the type Line ( I set the Navy color ) , and press «Ready».

 
 


Our task is extremely simple: when a new tick arrives the start() function is called, in this function in the zero bar we place the value Bid. 100 ticks arrive — we have 100 filled values. The only problem is that it isn’t so easy to do this. If we launch the indicator on a 5 minute time-frame, a new bar will appear only each 5 minutes, but we need the indicator to move left each time when a new tick comes.

 
 


If for standard indicators (both for built-in and custom ones) the terminal itself executes the needed shift, for the tick chart we will have to think out the shift mechanism by ourselves. In actual fact we have an indicator array ExtMapBuffer1[], the values of which we need to move depthward, we transfer the value ExtMapBuffer1[0] in ExtMapBuffer1[1], the value ExtMapBuffer1[1] in ExtMapBuffer1[2], etc., we write the value Bid in the free index ExtMapBuffer1[0].

 
 


Thus we need some function ShiftArray(), after which we write at the zero address Bid.

 
 


We only have to write the ShiftArray() function:

 
 


We had to introduce a new global variable tickCounter, in order to know to what depth it is needed to shift the values of the array. The indicator is almost ready. But we forget that when a new bar appears the indicator array moves automatically. We will add the processing of the event «New bar» and will change the code:

 
 


The isNewBar() function is similar to the one that is used in the Expert Advisor BlackBox, we will simply copy it. But instead of the global variable expertBars I wrote myBars.

 
 


Now the indicator is perfect. It is true we didn’t use optimization possibilities, but how can we optimize this indicator? This is a rare case when there is no use of the built-in function IndicatorCounted() . But we can optimize it. Suppose, we launched the indicator 10 minutes ago, for this period of time 100 arrived, so on each new tick we shift 100 values of the array, and the number of the shifted values is increasing. A day after we will have thousands of such values. And this should bi multiplied by the number of charts to which we will attach this indicator. Perhaps the moment will come when all the computer resources will be used to shift senselessly tens of thousands values in different arrays. In order to avoid this I introduces the external parameter MaxDrawTicks=500 (maximum number of the drawn ticks) and introduced a rule: as soon as the ticks counter tickCounter reaches the value twice a large than this one the array is cut, values from MaxDrawTicks+1 to 2*MaxDrawTicks are filled with zeros. Then everything goes as usual. I proceed from the assumption that 500 values on the chart are enough to estimate the current situation, you may change this number or change the rule of cutting.

 
 


The indicator is written without mistakes, optimization is done, what else is needed for happiness? If one presses Ctrl+Y in the terminal, periods delimeters appear. We could do something like that. And we will see that charts have their own time, that doesn’t coincide with the astronomic. The trend periods, which alternate with a range or consolidation, develops also by law of the internal time. And with the help of delimeters it will be easier to understand how the price behaved inside one or another bar, how ticks changed in the flag or false breach patterns.
We can draw delimeters only with the help of objects, this object is Vertical line. Now when the «New bar» event happens we draw a vertical line with a unique name. We realize this by means of the SetDelimeter() function. The block start() finally looks like that:

 
 


The SetDelimeter() function will create an object of the type OBJ_VLINE, place it in the indicator window, set the color and style. You can set your own parameters of color and style. The problem of uniqueness of the created names is resolved simply — each new delimiter has the name delimeterDate, which contains the text format of the beginning of a new bar. Thus we always can move the mouse cursor to our delimiter and understand in what period of time the given sequence of ticks developed.

 
 


If you refer to the Help menu in ME, you will understand all the nuances of the functions used for working with the object. There is the last detail left - we created objects, now we need not to forget to move them for the same reason that the indicator array. We will extend the ShiftArray() function, now it shifts not only the indicator array, but all the vertical lines that it will find in the indicator window.

 
 


Having studied the code of this indicator you will be able to create and change easily the properties of vertical lines. At that we can put a period to the writing of the indicator. Though if you wish you may improve it and add some functionality. We launch it on the EURUSD M5 chart and watch it.

 
 


I moved the cursor to the delimiter and saw the name of the vertical line (which is given by Time[] of this period of time ).

 
 


We see that on the tick chart support and resistance lines (1.2644) are seen very well.

 
 


We see how the price broke the support line and returned upward again. 10 minutes after the price broke the support line 1.2620 . We can plot a horizontal line on our indicator.


 
 


With the help of our indicator we can study the development of the price at each moment of time, not being physically at the monitor at that moment. I think intraday traders will appreciate worthily this indicator. You may download the indicator here .
Go to article «A remarkable function».

+7 (495) 710-76-76
© 1998—2008 «Alpari»

close

Your Personal Area

For alpari.classic enter your account number (a letter and 4 figures) and the code word for the Personal Area.

For alpari.micro account: enter your login (6 figures) and the password for MT.

Open an account!Forgotten your password?