Free Quantitative Strategy Free Quantitative Trading Software: Kagi Charting Indicators

Introduction

 The programmatic way of creating point and figure charts is described in the article " Point and Figure Indicators " .  Point and figure charts have been known since the 19th century. But that's not the only style of drawing that has endured. Another noteworthy way of drawing early financial markets is the Kagi diagram . Hertz quantitative trading software will discuss this kind of chart in this article. 

The stock exchange was an unfamiliar financial institution to Japan in the nineteenth century, and the first stock exchange in Japan was established in May 1878 . It is now the Tokyo Stock Exchange . This event played an important role in the invention and development of the Kagi graph. Europe and the United States did not begin to know Kagi diagrams until the publication of Steve Nison 's "Beyond Candlesticks: New Japanese Charting Techniques Revealed" (New Japanese Candlestick Techniques Revealed) in 1994 .   

In Japanese, the word "Kagi" refers to an L- shaped key used in the era when the chart was invented . Also, this kind of graph has another name, " key graph " . In Steve Nison 's Japanese Candlestick Charting Technique Explained, you'll also see several aliases for this type of chart: price range, hook, triangle, or chain.

What is so special about this picture? Its main feature is that it ignores the time scale, leaving only the price scale (unlike Japanese candlestick, histogram and line charts). In this way, the chart hides minor price fluctuations and only shows the most obvious price fluctuations.

The figure shows a set of thicker positive lines and thinner negative lines, which alternate with each other as the market situation changes. As the market moves in the same direction, the lines extend to new price ranges. However, if the market retraces and reaches the pre-set volume, the Kagi line is drawn in the opposite direction in a new column. This pre-set amount is expressed in points (usually for currency pairs) or a percentage value of the current price (usually for stocks). Line thickness varies with the highest or lowest value closest to it.

1. Chart example

Let's take the historical data of EURUSD , H1 chart from October 8th to October 11th as an example.

Figure 1 shows a standard image with a reverse threshold of 15 points:

Figure 1 Kagi chart, EURUSD H1

We can see that the price started to drop from 17:00 . The downtrend continued until 21:00 . At 22:00 , the price started to rise from 1.3566 and finally closed at 1.3574 . In other words, the price covers 11 points. That wasn't enough for a reversal, but it wasn't a new low either. For the next two hours, the price trend was stable, and finally saw a strong increase at 01:00 ( October 9th ) and closed at 1.3591 points, an increase of 25 points ( 1.3591-1.3566 ). This means that the price has reversed.

The uptrend continued for another hour. The price reached 1.3599 , strengthening the thicker Yang Xian. At 03:00 , the price fell sharply and closed at 1.3578 , 21 pips below the previous high ( 1.3599-1.3578 ). That's enough for a reversal. The line started to move down, but the form (thick Yang line) did not change.

By 16:00 , the price dropped and finally broke through the nearest minimum value, changing from a thick Yang line to a thin Yin line. The previously mentioned minimum, namely 1.3566 , becomes the breakout price here. The price continued to move in the form of a negative line and turned into a positive line at 14:00 on October 10 , breaking through the nearest highest point, which was 1.3524 formed at 23:00 on October 9 . This small example shows the structure of a Kagi graph.

2. Kagi indicator drawing principle

In order to make this indicator independent of the current timeframe, it was decided to separately copy the timeframe data that was planned to be used to form the indicator and then create the indicator with the resulting data.

This allows multiple timeframes to be viewed simultaneously on the same chart, expanding the technical analysis boundaries of Kagi charts. The indicator itself is located in a separate window, but it is also possible to display data on the main chart. That is, basic information (standard style or revised style) is displayed in the indicator window. The indicator is copied to the main chart and the price and time stamps (depending on the settings) are drawn.

As mentioned earlier, the indicator plots standard and modified charts. The standard version of the chart is described above. Now let's look at the revised version.

Not sure if this is a new idea, but I haven't heard of such a version. The idea of ​​the additional filter is that it now filters not only reversal points, but every move of the chart. This means that the price should move a certain distance to form a new high or low (not to be confused with shoulder / waist). Generally speaking, no matter which way the price is going, it should move the specified distance first. Then determine whether it is a continuation of the previous trend or a reversal.

Figure 2 shows how this principle works. Revised chart styles are shown in blue and standard styles are shown in red. We can see that the revised pattern reacts more slowly to price movements, filtering most small signals.

Figure 2 Creation of revised (blue line) and standard (red line) Kagi diagrams

In addition to the Kagi chart, the indicator provides other elements in the indicator window and the main chart.

Depending on the settings, these flags can be set in the indicator window. These markers provide reversal price data. The same function can be achieved with price levels, the individual price levels within the entire price range used to form the indicator or at each chart reversal point (depending on the settings) are evenly distributed in the window. Colors can be set according to three conditions: by reversal type (up - down), line type (yin - yang), or no color change.

Reversal price markers are available on the main chart, including temporary markers. These markers (depending on the settings) may be the same color, or change color according to the color of the yin and yang lines.

The entire indicator code can be implemented with functions communicating with each other through global variables.

The code can be divided into three main functions and eleven additional functions. The main calculation tasks of the basic charting method and the filling of buffers with data and additional buffer arrays are performed by the functions of the Kagi chart in the indicator window. Two other functions are responsible for providing data: the first is responsible for copying time data, and the other is responsible for copying price data for each bar of the selected timeframe.

Other auxiliary functions are responsible for performing all charting work, including deleting objects, unloading indicators together with deleting all indicator objects, reversing parameter calculations, drawing markers in the main chart and indicator windows, creating graphical objects of the "trend line" type, on the main chart Plot Kagi , and identify the appearance of a new bar to start forming the indicator.

3. Indicator code and algorithm

The following Hertz quantitative trading software will take a closer look at the indicator code and the algorithm that forms the code. This code is very large and may be difficult for novice programmers to understand. Functions talking to each other through global variables make this code very confusing. This article will explain each function and part of the code in this part. First, I will describe the indicator settings, and then I will describe the copying of data related to the initial function, calculation of inversion parameters, formation and calculation of the main function of the Kagi chart, and other auxiliary functions.

3.1. Indicator input parameters

The code starts with declaring the indicator in a separate window, simultaneously declaring 12 buffers and 8 methods of indicator construction. First of all, let's look at the Hertz quantitative trading software to see why we choose 8 kinds of graphing methods, including two  " histograms "  and six  " line graphs " . Each " histogram " establishes its own vertical line. One of the lines is responsible for the Yin line, and the other is responsible for the Yang line.

The situation is more complicated if there are multiple lines, since each line contains three graph structures. This is because a line can be drawn by simply drawing another point adjacent to the first point. In other words, the Hertz quantitative trading software only needs to rotate two  " line " graphic structures to draw two lines adjacent to each other. However, if we need to make these lines jump over some necessary points, we need a third graph structure that rotates with the first two.
https://c.mql5.com/2/6/Kagi_eng.png

Guess you like

Origin blog.csdn.net/herzqthz/article/details/131790182