Tags: Trade-aided

AHR999 Mean Reversion Strategy AHR999, AHR999X, 调和平均数, 对数价格, 净值

####Overview This strategy is based on the AHR999 and AHR999X indicators. By comparing the current price with the harmonic mean price and logarithmic price, it determines whether Bitcoin is overbought or oversold, and accordingly conducts fixed investment and bottom-fishing operations. Meanwhile, the strategy also sets a take-profit condition to partially sell when the AHR999X indicator is below a certain threshold.

####Strategy Principle

- Calculate the harmonic mean of Bitcoin’s historical prices as a reference for the long-term equilibrium price.
- Calculate the corresponding logarithmic price based on the number of days since Bitcoin’s birth as a reference for the long-term trend price.
- Calculate the current AHR999 indicator, which is the product of the ratio of the current price to the harmonic mean price and the logarithmic price.
- Calculate the current AHR999X indicator, which is 3 times the ratio of the harmonic mean price to the current price multiplied by the ratio of the logarithmic price to the current price.
- Based on the value of the AHR999 indicator, determine whether to conduct fixed investment or bottom-fishing. Fixed investment is made when AHR999 is within a set range, and bottom-fishing is made when it is below the lower limit.
- Based on the value of the AHR999X indicator, determine whether to take profit. When AHR999X is below a set threshold, sell a certain proportion of the position.

####Advantage Analysis

- The strategy is based on Bitcoin’s long-term equilibrium price and trend price, with a certain theoretical basis and interpretability.
- The introduction of the harmonic mean reduces the impact of short-term fluctuations, making the judgment more robust.
- By combining the AHR999 and AHR999X indicators, it can better capture Bitcoin’s overbought and oversold status and the timing of profit-taking.
- Fixed investment and bottom-fishing are combined to gradually build positions when prices are relatively undervalued, resulting in relatively low costs.
- The take-profit operation is set to obtain certain returns when prices are relatively overvalued while retaining most of the positions for long-term appreciation.

####Risk Analysis

- The strategy relies on the AHR999 and AHR999X indicators. If the future price movement of Bitcoin changes significantly, causing these two indicators to fail, the strategy may face greater risks.
- The harmonic mean is sensitive to the length of historical prices. If the selected historical price interval is not reasonable enough, it may affect the performance of the strategy.
- The calculation of the logarithmic price is based on the number of days since Bitcoin’s birth. If the long-term growth trend of Bitcoin changes, the logarithmic price may lose its reference significance.
- The strategy may face the risk of insufficient funds for bottom-fishing when prices are relatively high, leading to the inability to build positions in a timely manner.
- The take-profit operation may cause the strategy to miss some gains if prices continue to rise.

####Optimization Direction

- Optimize the thresholds of the AHR999 and AHR999X indicators to find the most suitable intervals for fixed investment, bottom-fishing, and profit-taking.
- Introduce more indicators, such as trading volume and volatility, to assist in judging trends and overbought/oversold states.
- Optimize the calculation method of the harmonic mean, such as appropriately adjusting the weights of historical prices to reduce dependence on distant historical prices.
- Dynamically adjust the amount of fixed investment and bottom-fishing, increasing investment when prices are lower and reducing investment when prices are higher.
- Optimize the take-profit operation, such as dynamically adjusting based on price trends and position costs to balance returns and risks.

####Summary The AHR999 Mean Reversion Strategy determines Bitcoin’s overbought and oversold status by comparing the current price with the historical equilibrium price and trend price, and conducts fixed investment, bottom-fishing, and take-profit operations. This strategy has a certain theoretical basis and interpretability. By combining two indicators, it can better capture the price fluctuation patterns of Bitcoin. However, the strategy also faces risks in terms of indicator failure, parameter selection, and fund management, requiring continuous optimization and improvement in practice. Overall, the AHR999 Mean Reversion Strategy provides a feasible idea for long-term value investment in Bitcoin.

/*backtest start: 2018-04-14 00:00:00 end: 2021-07-18 00:00:00 period: 1d basePeriod: 1d exchanges: [{"eid":"Binance","currency":"BTC_USDT","balance":1000000,"stocks":0}] */ /* * @Project: * @Version: * @Author: RedSword <coo@fmz.com> * @Description: * @Date: 2021-07-19 11:02:43 * @LastEditors: RedSword * @LastEditTime: 2021-07-19 15:55:16 * @Copyright:: Copyright © 2020 FMZ Quant * 感谢ahr999大神,后续完善可以加入一些理财,币和钱都闲着,收益会低一点,也可以放到bitfinex放借贷,年化也有十几的收益,还可以放大资金,买了币以后,就去交割合约做多,暂时想到这么多,希望大家多多交流 * 参考: * https://github.com/who3m1/ahr999-mixin * https://btctom.com/ahr999 * https://btctom.com/ahr999x */ function harmonicMean(x) { if (x.length === 0) { return undefined; } var reciprocalSum = 0; for (var i = 0; i < x.length; i++) { if (x[i] <= 0) { return undefined; } reciprocalSum += 1 / x[i]; } return x.length / reciprocalSum; } function GetNowPrice() { var ticker = exchange.GetTicker(); return ticker.Last; } function GetPrices() { var records = exchange.GetRecords(PERIOD_D1); var prices = []; for (let i = 0; i < records.length; i++) { const record = records[i]; // Log(record); prices.push(record.Close); } return prices; } function CalcAHR999() { var now = parseInt(Unix()); var prices = GetPrices(); var avgPrice = harmonicMean(prices); var nowPrice = GetNowPrice(); var birthday = (now - 1230940800) / (24 * 60 * 60); var logPrice = Math.pow(10, 5.84 * Math.log10(parseInt(birthday)) - 17.01); //2020-4-16 13:16 以后使用新的指标 //https://weibo.com/5034063086/IDzPWyN8Z?from=page_1005055034063086_profile&wvr=6&mod=weibotime if (now > 1587014160) { logPrice = Math.pow(10, 5.8 * Math.log10(parseInt(birthday)) - 16.88); } var ahr999 = Math.round((nowPrice / avgPrice) * (nowPrice / logPrice) * 1000) / 1000; var ahr999x = Math.round((avgPrice / nowPrice) * (logPrice / nowPrice) * 3 * 1000) / 1000; return { ahr999: ahr999, ahr999x: ahr999x, }; } function init() { exchange.SetMaxBarLen(200); if (exchange.GetCurrency().indexOf("BTC_USD") == -1) { throw "只支持BTC交易对"; } } function UpdateStatus(account, nowPrice) { var table = { type: "table", title: "持仓信息", cols: ["定投币种", "初始净值", "当前净值", "定投次数", "持仓数量", "持仓均价", "当前价格", "累计定投", "可用资金", "盈利率%"], rows: [], }; var netValue = account.Balance + account.Stocks * nowPrice; table.rows.push([ exchange.GetCurrency(), InitMoney, _N(netValue, 2), Global.number, _N(account.Stocks, 6), _N((InitMoney - account.Balance) / account.Stocks, 2), nowPrice, _N(Global.number * Money, 2), _N(account.Balance, 2), _N((netValue / InitMoney) * 100), ]); LogStatus("`" + JSON.stringify(table) + "`"); } var Global = { upTime: 0, //循环间隔 number: 0, //定投次数 multipleNumber: 0, //抄底次数 }; function main() { while (true) { var now = parseInt(Unix()); if (now > Global.upTime) { var price = GetNowPrice(); var account = exchange.GetAccount(); var ahr999 = CalcAHR999(); Global.upTime = now + 3600 * Interval; if (ahr999.ahr999 >= Bottom && ahr999.ahr999 < Top) { if (Money > account.Balance) continue; Log("开始定投"); exchange.Buy(-1, Money); Global.number++; } else if (ahr999.ahr999 < Bottom) { if (Money * Multiple > account.Balance) continue; Log("开始抄底"); exchange.Buy(-1, Money * Multiple); Global.number += Multiple; } if (TakeProfit & (ahr999.ahr999x < TakeProfitLine)) { Log("开始顶逃"); var sell = Global.number * TakeProfitRate * Money; var coinNumber = sell / price; exchange.Sell(-1, coinNumber); } UpdateStatus(account, price); } Sleep(1000); } }

- 数字货币合约简易跟单机器人
- 【定投】【新手入门】每周100USDT左右-定期不定额 (100USDT Invested Every Week - Regular Variable Investment)
- 简易数字货币现货跟单机器人策略
- 定投策略
- TradingViewWebHook信号执行策略（教学）
- 轮询价格买入卖出
- 交易所上新币第一时间挂单机器人
- Simple Iceberg order to sell (Copy)
- Simple Iceberg order to buy (Copy)
- Python版冰山委托 - 卖出

- OKEX V5 WS接口账户持仓推送例子
- Keltner通道突破止损加盈利10%即长期持有策略-v2.3-dev-多周期
- 测试-关于使用kdj与vol量筛选可能会涨的币种
- 网格变形策略之单边网格 （注释）
- 爬取币安公告永续新上币和下架币
- My语言仓位变化推送通知
- 不同计价币的现货对冲策略 Ver1.1
- 三均线系统【Exodus】
- TradingView下单机器人1.1
- WR 突破马丁
- 发明者APP图表测试策略
- 不同计价币的现货对冲策略（教学）
- Python版多图表范例 (Copy)
- 干货-下单量精度和价格精度-适用各个交易所
- 数字货币期货类马丁策略
- 马丁变种原始版
- 双向合约网格交易v1.0.2
- grid
- 海龟策略btc现货版
- 马丁策略-V0.0.1