Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Adaptive dynamic double moving average Strategy in Internet

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how to achieve adaptive dynamic double average strategy in the Internet". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to achieve adaptive dynamic double average strategy in the Internet".

Kaufman average

In "Smart Trader", the author Kaufman proposed the "adaptive moving average", referred to as AMA. The moving average takes into account the rate of market price change, increases the smoothing coefficient on the basis of the general moving average, and adaptively dynamically adjusts the sensitivity of the moving average, which can adjust itself between the slow trend and the fast trend. When the market is consolidated and the trend is not obvious, AMA tends to move its average slowly. When the market fluctuates greatly, the trend is obvious, and the price moves rapidly in one direction, AMA tends to move the average line quickly.

The Kauffman moving average is essentially adjusted according to the price volatility over a period of time, and calculates the appropriate entry threshold to provide the best buying and selling point. In other words, it is divided into two parts of main logic, and the second part of logic makes another adaptation at the level of volatility. So as to reflect the real trend of the market, it is easy to quickly seize the opportunity of rising and falling trends, while avoiding the impact of market shocks back and forth.

Kaufman moving average calculation

Experienced traders are used to using fast moving averages in markets with unfolding trends and slow moving averages in volatile markets. But how to quantify this method and let the program distinguish between the two markets? Here we need to introduce the concept of "efficiency".

If the price moves in one direction and the daily closing price changes contribute to the overall operating range, it is called high efficiency; if the price rises and falls, and many changes in the closing price cancel each other out, it is called inefficiency. This is similar to the displacement in physics. If the price rises by 100 points in 10 days, we can call it high efficiency, and if the price increases by 10 points in 10 days, we can call it inefficient.

Step 1: calculate the price efficiency

Price efficiency is based on the speed and direction of market movement and the amount of noise in the market, assuming that the price efficiency is between 0: 1, 0 means that the market is not moving, only noise; 1 means that the market is only moving, there is no noise. If the price rises 100 points in 10 days and moves 10 points per day, the price efficiency is: 100 / (10 * 10) = 1; if the price rises 10 points in 10 days, but fluctuates 10 points a day, the price efficiency is: 10 / (10 * 10) = 0.1

The calculation formula is as follows: first, calculate the price change value, that is, the absolute value of the price difference between the root K line and the previous N K line; then calculate the price fluctuation value, that is, the sum of the absolute values of all price changes within the N root K line; finally, calculate the efficiency coefficient, that is, the price change value is divided by the price volatility value.

Price change = abs (price-n-day price)

Price fluctuation value = sum (abs (price-previous trading day price), n)

Efficiency coefficient = price change / price fluctuation

Thus, under the condition of a certain value of price change, the greater the market fluctuation, the smaller the efficiency coefficient, and the use of the slow moving average can better grasp the overall trend, because the slow average is not easy to be changed by the short-term fluctuation of the market; on the contrary, under the condition of a certain value of price change, the smaller the market fluctuation is, the greater the efficiency coefficient is, and the fast (short-term) moving average should be used at this time.

Step 2: calculate the smoothing coefficient

Kaufman uses a series of moving average speeds to describe the smoothing coefficient, which is similar to EMA. According to the weight of the price, the fast and slow trend speed coefficients are redefined. For example, the average of 2 days is called fast, and the average of 30 days is called slow. The fast trend coefficient is 2 / (2 + 1) = 2 / 3 = 0.66667, and the slow trend coefficient is 2 / (30 + 1) = 2 / 31 = 0.06452. The difference between them is 0.60215.

Fast trend coefficient = 2 / (N1 + 1)

Slow trend coefficient = 2 / (N2 + 1)

N1 and N2 in the above formula are the number of trading cycles, and N1 is less than N2. The default N1 is 2 and N2 is 30. Finally, the efficiency ratio is used to calculate the smoothing coefficient, that is, the efficiency coefficient * 0.60215 + 0.06452.

Smoothing coefficient = efficiency coefficient * (fast-slow) + slow speed

It can be seen that when the market fluctuates more and the trend is obvious, the smoothing coefficient tends to choose the fast trend coefficient, on the contrary, in the period of market shock consolidation and the trend is not obvious, the smoothing coefficient tends to choose the slow trend coefficient.

Step 3: calculate the AMA value

Because the transaction may be cancelled when the efficiency coefficient is too low, Kaufman recommends that the final smoothing coefficient be multiplied again before calculating the AMA value.

Coefficient = smoothing factor * smoothing coefficient

AMA = AMA + coefficient of the previous trading day * (price-AMA of the previous trading day)

Suppose yesterday's AMA value was 40 and the current price is 47, and there is a seven-point difference between them. Then in an efficient market, the AMA value increases by nearly 3. 1 points, which is almost half the difference. In an inefficient market, this difference has little effect on AMA values.

Policy logic

According to Kaufman, AMA is the equivalent of a smoothing index and should be traded immediately if its direction changes. In other words, AMA should buy when it rises and AMA should sell when it falls. However, if you rush to make a trading signal, it may cause a large number of invalid signals, so it is necessary to add a suitable filter, that is, to add another AMA moving average to send out the buying and selling signal in the form of double averages crossing.

Long opening: both AMA1 and AMA2 are upward, and AMA1 is greater than AMA2.

Short opening: both AMA1 and AMA2 are downward, and AMA1 is less than AMA2.

Long closing: both AMA1 and AMA2 are downward, or AMA1 is less than AMA2.

Short closing: both AMA1 and AMA2 are up, or AMA1 is greater than AMA2.

According to the above logic of calculating AMA, first implement it in code, the first is to calculate the price efficiency:

DIRECTION:=CLOSE-REF (CLOSE,10); VOLATILITY:=SUM (ABS ((CLOSE-REF (CLOSE,1), 10); ER:=ABS (DIRECTION/VOLATILITY)

Then calculate the smoothing factor:

FASTSC:=2/ (2: 1); SLOWSC:=2/ (30: 1); SSC:=ER* (FASTSC-SLOWSC) + SLOWSC

Finally, calculate the values of AMA1 and AMA2:

AMA1:EMA (DMA (CLOSE,CONSTANT), 2), COLORGREEN,LINETHICK3;AMA2:EMA (DMA (CLOSE,CONSTANT), 10), COLORGREEN,LINETHICK3

With AMA1 and AMA2 and values, you can easily implement the policy logic:

AMA1 > REF (AMA1, 1) & & AMA2 > REF (AMA2, 1) & & AMA1 > AMA2, BK;AMA1

< REF(AMA1, 1) && AMA2 < REF(AMA2, 1) && AMA1 < AMA2, SK;BKVOL >

1 & & AMA1

< REF(AMA1, 1) || AMA2 < REF(AMA2, 1) || AMA1 < AMA2, SP;SKVOL >

1 & & AMA1 > REF (AMA1, 1) | | AMA2 > REF (AMA2, 1) | | AMA1 > AMA2, BP |

Complete strategy

DIRECTION:=CLOSE-REF (CLOSE,10); VOLATILITY:=SUM (ABS ((CLOSE-REF (CLOSE,1), 10); ER:=ABS (DIRECTION/VOLATILITY); FASTSC:=2/ (2: 1); SLOWSC:=2/ (30: 1); SSC:=ER* (FASTSC-SLOWSC) + SLOWSC;CONSTANT:SSC*SSC;AMA1:EMA (DMA (CLOSE,CONSTANT), 1), COLORGREEN,LINETHICK3;AMA2:EMA (DMA (CLOSE,CONSTANT), 10), COLORGREEN,LINETHICK3 AMA1 > REF (AMA1, 1) & & AMA2 > REF (AMA2, 1) & & AMA1 > AMA2, BK;AMA1

< REF(AMA1, 1) && AMA2 < REF(AMA2, 1) && AMA1 < AMA2, SK;BKVOL >

1 & & AMA1

< REF(AMA1, 1) || AMA2 < REF(AMA2, 1) || AMA1 < AMA2, SP;SKVOL >

1 & & AMA1 > REF (AMA1, 1) | | AMA2 > REF (AMA2, 1) | | AMA1 > AMA2. BP;AUTOFILTER; is all the contents of the article "how to implement adaptive dynamic double average strategy in the Internet". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report