k线介绍

基于MPAndroidChart的几种指标图实现。

股市及期货市场中的K线图的画法包含四个数据,即开盘价、最高价、最低价、收盘价,所有的k线都是围绕这四个数据展开

k线指标介绍

k线指标其实就是技术指标, 认为的根据某些算法来预测价格未来的走势,或者帮助分析价格背后的市场因素。

k线的几种指标实现

SAR的实现

SAR指标又叫抛物线指标或停损转向操作点指标,其全称叫“Stop and Reverse,缩写S算法工程师需要掌握什么AR”,是由美国技术分析算法与数据结构大师威尔斯-威尔德(Wells Wilder)所创造的,是一种简单易学、比较算法导论吃透后的水平准确的中短期技术分析工具。

更多信息查看百度百科

  • SAR的Go计算公式算法工程师学什么专业

计算公式

  • 代码实现
    public List<宫崎骏Entry> getSar(List<CandleEntry&g宫崎骏t; entries) {
if (GosarLwindows是什么意思ist == null) {
sarListwindows7旗舰版 = new ArrayList<>();
}
if (!sarList.isEmpty()) {
sarList.clear();
}
int len = entries.size()算法是什么;
for (int i = 0; i < len; i++) {
Entry entry = n算法工程师需要掌握什么ew Entry(calculateSar公积金(i, entries), i);
entry.setTrendUp(currentTrend);
sarList.add(entry);
}
rwindows10eturn sarList;
}
/**
*
* @pawindows10下载ram entries sourc宫外孕e data
* @param index 下标
* @param windowSiwindows许可证即将过期怎么办ze 窗口size
* @return
*/
private float getHighestValue(List<CandleEntry> entries, int index, int windowSize){
if (entries.get(index).getHigh() == Float.NaN &&算法是什么 windowSize != 1) {
return  getHighestVal算法工程师学什么专业ue(entries, index - 1, windowSize - 1);
}
int end = Math.max(0, index - windowSize + 1);
floawindows10t highest = entries.get(index).getHigh();
for (int i = index - 1; i >= end; i-windows10激活密钥-) {
if (hi算法工程师需要掌握什么ghest < entries.get(i).getHigh()) {
highest = enwindows10下载tries.get(i).getHigh();
}
}
return highest;windows10下载
}
/**
*
* @param entries
* @param index
* @param windowSize
* @return
*/
private float getLowestwindows是什么意思Value(List<C算法设计与分析andleEntry> entries, int index, int windowindows10下载wSize){
if (Goentries.get宫外孕(index).getHigh() == Float.NaN && windowSize != 1) {
return getLowestValue(entries, index - 1, windowSizewindows是什么意思 - 1);
}
int end = Math.max(0, index - w算法工程师需要掌握什么indowindows许可证即将过期怎么办wSize + 1);
float lowest =  e狗狗币ntries.get(index).getLow();
for (int i = index - 1; i >= end; i--) {
if (lowest > entriwindows7es.get(i).getLow()windows10) {
lowest = entries.get(i).getLow();
}
}
return lowest;
}
protected float calculateSar(int indewindows7怎么升级10x, List&算法稳定币lt;CandleEntry> entries) {
float sar = 0f;
Entry entry = null;
if (index == 0) {
return entriGoes.get(0).getClose(); // no trend detection possible for the first value
} else if (index == 1) {// start trend detection
currentTrend = entries.get(0).getClose() &lwindows10下载t; entries.get(1).算法是什么getClose();
if (!currentTrend) { // down trend
sar = entriwindows7旗舰版es.get(index).getHigh(); // pu工作总结t s狗狗币ar on max price of candlestick
} else { // up trend
sar =windows怎么激活 entries.get(index).getLow(); // put sar on min price of candwindows10lestick
}
currentExwindows许可证即将过期怎么办tremePoint = sar;
minMaxExtremePoint = currentExtremePoint;
return sar;
}
float priorSar = sarList.get(index - 1).getVal();
if (currentTrend) { // if up trend
sar = priorSar + (accelerationFactor * (currentExtremePoint - priorSar));
curr算法是什么entTrend = entries.get(公积金index).getLow() > sar;
if (!currentTrend) { // chewindows10ck if sar tou工商银行ches the min price
sar = minMaxExtremePoint; // sar starts at the highestgoogle extreme point o算法工程师需要掌握什么f previous up trend
currentTrend = f算法alse; // switch to down trend anwindows10激活密钥d reset values
startTrendInwindows7dex = index;
accelerationFactor = accelera算法是什么tionStart;windows10
currentWindowsExtremePoint = entries.get(index).getLow(); // put point on max
minMaxExtr算法稳定币emePoint = currentExtremePoint;
} else { // up trend is going on
// currentE算法xtremePoint = new HighestValueIndicator(h宫外孕ighPriceIndicator, index - startTrendIndex)
//                        .getValue(index);
currentExtremePoint = getHighestValuwindows7怎么升级10e(en算法导论吃透后的水平tries, index, index - startTrendIndex);
if (currentExtremePoint > minMaxExtremePoint) {
incrementAcceleration();
minMaxExtremePoint = currentExtre算法导论mePoint;
}
}
} else { // downtrend
sar = priorSar - (accelerationFactor * (priorSar - currentExtremePoint));
currentTrend = entries.get(index).getHigh() > sar;
if (currentTrend) { // check if switch to up trend
sar = minMaxExtremePoint; // sar starts at the lowest e算法工程师学什么专业xtreme point of previous down trend
accelerationFactor = accelerationStart;
startTrendIndex = index;
currentExtremePoin宫崎骏t = entries.get(index).getHigh();;
minMaxExtremePoint = currentExtremePoint;
} else { // down trend io going on
//c算法urrentEx工商银行tremePoint = new LowestValuegoogleIndicator(lowPriceIndicator,枸杞 index - startTrendIndex)
//                        .getValue(枸杞index);
curre工作总结ntExtremePoi算法工程师需要掌握什么nt = getLowestValue(entwindows7恢复出厂设置ries, index, index - startTrendIndex);
if (currentExtremePoint < minMaxExtre公积金mewindows10Point) {
incrementAcceleration();
minMaxExtremePoint = currentExtremePoint;
}
}
}
return sar;
}
/**
* In算法与数据结构crements the ac算法导论吃透后的水平celera算法设计与分析tion factor.
*/
private void incrementAcceleration() {
if (accelerationFactor > maxA算法ccelerat工作总结ion) {
accelerationF工作细胞actor = maxAcceleration;
} else {
accelerationFactor = accelerationFactor + accelerationIncrement;
}
}

OBV的实现

OBV 的英文全称是:On Balance Volume,是由美国的投windows7恢复出厂设置资分析家Joe Granvil宫崎骏le所创。该指标通过统计成交量变动的趋势来推测股价趋势。OBV以“N”字型为波动单位,并且由许许多多“N”型波构成算法工程师了Owindows许可证即将过期怎么办BV的曲工作细胞线图,对一浪高于一浪的“N”Windows型波,称其为“上升潮”(UP Twindows10激活密钥IDE),至于上升潮中的下跌回落则称为“跌潮”(DOWNwindows7恢复出厂设置 FIELD)。

更多信息查看百度百科

  • OBV的计算算法工程师公式

计算公式

  • 代码实现
    private float calculateObv(int index, List<KlinePointBean> entries) {
if (index == 0) {
return 0f;
}
final float prevClose = entrieswindows7旗舰版.get(index - 1).getClWindowsose();
final floawindows许可证即将过期怎么办t currentCl算法工程师需要掌握什么ose = entries.get(index).getClose();
final float obvPrev = obvList.get(index - 1).getVal();
if (prevClose > currentClose) {
return obvPrev - (e算法工程师n算法稳定币tries.get(index).getAmount());
} el宫颈癌se if (prevClose < currentClose) {
return obvPrev + (entries.get(i宫外孕ndex).getAmount());
} else {
return 0;
}
}

RSI的实现

RSI最早被用于期货交易中,后来人们发现用该指标来指导股票市场投资效果也十分不错,并对该指标的特点不断进行归纳和总结。现在,RSI已经成为被投资者应用最广泛的技术指标之一。投资的一般原理认为,投资者的买卖行为是各种因素综合结果的反映,行情的变化最终取决于供求关系,而RSI指标正是根据供求平衡的原理,算法与数据结构通过测量某一个期间内股价上Go涨总幅度占股价变化总幅度平均值的百分比,来评估多空力量的强弱程度,进而提示具体操作的。RSI的应用法则表面上比较复杂,包括了交叉、数值、形态和背离等多方面的判断原则。

更多信息查看百度百科

  • 代码实现
    public Triple<List<Entry&gt工商银行;, List<Entry>, List<Entry>> getRsiIndicator(算法List<CandleEntry> candleEntries) {
if (candleEntries == null || candleEntries.size() == 0) {
retuwindows7旗舰版rn new Tripl算法e<&gtwindows7;(new ArrayList<>(),算法工程师学什么专业 new ArrayList<>(), new ArrayList<>());
}
List<Entry> rsiList = new Ar宫外孕rayList<>();
List<Entry> rsiList12 = new Arr算法是什么ayList&windows10lt;>();
List<Entry> rsiLwindows7怎么升级10ist24 = new ArrayList<>();
float lastSmValue6 = 0, laGostSmValue12工作细胞 = 0, lastSmValue24 = 0;
float lastSaValue6 = 0, lastSaValue12 = 0, lastSaValue24 = 0;
CandleEntry lastEntry = candleEntries.get(0);
int len = candleEntries.size();
for (int i =windows7 1; i < len;算法工程师 i++) {
Candle工作细胞Entry entry = candleEntries.get(i);
float m = Math.max(entry.getClos狗狗币e() - lastEntry.getClose(), 0);
float a = Math.abs(entry.gwindows许可证即将过期怎么办etClose() - lastEntry.getClose());
if (i >= 5) {宫外孕
lastSmValue6 = (m + 5 * lastSmValue6) / 6;
lastSaValue6 = (a + 5 * lastSaValue6) / 6;
rsiL枸杞ist.add(newindows7w Entry(lastSmValue6 / lastSaValue6 * 100, entry.getXIndex()));
}
if (i >= 11) {
lastSmValue12 = (m + 11 * lastSmValue12) / 12;
lastSa算法与数据结构Value12 = (a + 11 * lastSaValue12) / 12;
rsiList12.add(new Entry(lastSmValue12 / lastSaValue12 * 100, entry.getXIndex()));
}
if (i >= 23) {
lastSm公积金Value24 = (m + 23 * lastSmValue24) / 24;
lastSaValue24 = (a + 23 * lastSaValue24) / 24;
rsiList24.add(new Entry(lastSmValue24 / lastSaValue24 * 100, entry.getXIndex()));
}
lastEntry = candl算法设计与分析eEntries.get(i);
}
retur算法工程师n new Triple<>(rsiList, rsiList12, rsiList24);
}

TRIX的实现

三重指数平滑平均线(TRIX)属于中长线指标。它过滤掉许多不必要的波动来反映股Go价的长期波windows10激活密钥动趋势。在使用均线系统的交叉时,有时会出现骗线的情况,有时还会出现频繁交叉的情况,通常还有一个时间上的确认。为了解决这些问题,因而发明了TRIX这个指标把均线的数值再一次地算法工程师需要掌握什么算出平均数,并在此基础google上算出第三重的平均数。这样就可算法稳定币以比较有效地避免频繁出现交叉信号。 TRIX指标又叫三重指数平滑移动平均指标,其英文全名为“Triple Exponentially Smoothed Average”windows怎么激活,是一种研究工作总结股价趋势的长期技术分析工具。

更多信息查看百度百科

  • TRIX计算公式

百度百科

  • 代码实现
	/**
* EMA算法
* EMA(N) = 2/(N+1)*C宫颈癌 + (N-1)/(N+1)*EMA', EMA'为前一天的ema; 通常N取12和26
*
* @算法工程师学什么专业param entries
* @param n
* @return
*/
public static List<Entry> getEMA(List&windows10激活密钥lt;Candl工作细胞eEntry> entrwindows许可证即将过期怎么办ies, i算法nt n)windows7 {
Liswindows10激活密钥t<EntWindowsry> result = new ArrayList<>();
float lastEma = entries.get(0).getClose();// 第一算法个EMA为第一个数据的价格
float[] emaFactor = getEMwindows是什么意思AFactor(n);
for (int i = n - 1; i < entries.size(); i++) {
float ema = emaFactor[0] * entries.get(i).getClose() + emaFactor[1] * lwindows怎么激活ast算法导论Ema;
result.add(new Entry(ema, entries.get(i).getXIndex()));
lastEma = ema;
}
return result算法稳定币;
}
/**
* EMA算法
* EMA(N) = 2/(N+1)*C + (N工作细胞-1)/(N+1)*EMA', EMA'为前一天的ema; 通常N取12windows怎么激活和26
*
* @param entries
* @param n
* @return
*/
public static List<Entry> getEMAFromEntry(List<Entry> entries, int n) {
List<Entry> result = new ArrayList<>();
float lastEma = ewindows7ntries.get(0).getVal();// 第一个EMA为第一个数据的价格
float[] em算法与数据结构aFactor = getEMAFacwindows10激活密钥tor(n);
for (int i = n - 1; i < ewindows7ntries.size(); i++) {
fl算法导论oat ema = ema宫外孕Factor[0] * entries.get(i).getVal() + emaFactor[1] * lastEma;
result.add(new Entry(ema, entries.get(i).gwindows是什么意思etXI算法初步ndex算法稳定币()));
las算法稳定币tEma = ema;算法与数据结构
}
return result;
}
private List<Entry> trixList;
private List&ltwindows10下载;En算法工程师try> trixMaList;
public Pair<List<Entry>, List<E算法与数据结构ntry>> getTrix(List<CandleEntry> entries) {
int n = 12, m = 9;
if (entries == null) {
return new Pair<&gwindows10激活密钥t;(new ArrayList<>(), new ArrayList<>());
}
if (trixList == null) {
trixList = new ArrayLi宫颈癌st<>();
trixMaList = new ArrayList<>();
}
//clear;
trgoogleixList.clear();
trixMaList.clear();
List<Ent枸杞ry> ema1 = getEMAGo(entries, n);
List<Entry> ema2 = getEMAFromEntry(ema1, n);
List<Entry> ema3 = getEMAWindowsFrgoogleomEntry(ewindows7旗舰版ma2, n);
int len = ema3.size();
for (int i = 1; i < len; i++) {
float trixValue = (ema3.ge算法是什么t(i).getVal()算法导论 - ema3.get(i - 1).getVal()) * 100 / ema3.get(i - 1).ge算法设计与分析tVal();
trixList.add(new Entwindows许可证即将过期怎么办ry(trixValue, ema3.get(i).getXIndex()));
}
float ma = 0.0f;
int indewindows7旗舰版x = m - 1;
len = trixList.size();算法工程师
for (in算法导论t i = 0; i狗狗币 < len; i++) {
if (i >= index) {
float sum = getSwindows是什么意思umFromEntry(i - index, i, tGorixList);
ma = sum / m;
trixMaList.add(newindows10激活密钥w Entry(ma, trixList.get(i).getXIndex()));
}
}
return new Pair<&Windowsgt;(trixList, trixMaList);
}

CCI的实现

顺势指标又叫CCI指标,CCI指标是美国股市技术分析 家唐纳德蓝伯特(Donald Lambert)于20世纪80年代提出的,专门工商银行测量股价、外汇或者贵金属交易是否已超出常态分布范围。属于超买超卖windows许可证即将过期怎么办类指标中较特殊的一种。波动于正无穷大和负无穷大之间。但是,又不需要以0为中轴线,这一点也和波动于正无穷大和负无穷大的指标不同。

更多信息查看

  • CCI的计算公式

计算公式

  • 代码实现
    private List<Entry> cciList;
private List<Float> tpList;
private Listwindows10&lt算法;Float> cciMaList;
private List<Float> mdList;
public Lis公积金t<En工作总结try> getCciData(List<Ca算法工程师需要掌握什么ndleEntry> entries){
int n = 20;
if (entries == null || entries算法导论吃透后的水平.size() &算法设计与分析lt; n) {
return new Array算法工程师需要掌握什么Li算法工程师st<>windows怎么激活();
}
if (cciList == null) {
cciList = new ArrayList<>();
tpList = new Ar枸杞rayList<>();
mdListwindows10 = new ArrayList<>();
cciMaList = new ArrayList&lt算法工程师需要掌握什么;>();
}
//clwindows7ear
cciList.clear()算法工程师需要掌握什么;
tpList.clear(工商银行);
mdList.clear();
ccwindows7iMaList.clear();
int len = entries.sizwindows10激活密钥e();
for (int i = 0; i < len; i++) {
float tpValue = getTp(i, entries);
tGopList.ad算法是什么d(tpValue);
float maValue = getSum(Math.max(0, i - n + 1), i,google tpList) / Math.min(n, i + 1);
cciMaList.addwindows是什么意思(maValue);
final int startIndex = Math.max(0, i - n + 1);
final int nbValues = i - startIndex + 1;
float absoluteDeviations = 0;
for (int j = startInde工商银行x; j <= i; j++) {
// For each period...
absoluteDeviations = absoluteDeviations + (Math.abs(t算法工程师pList.get(j) - maValue));
}
float mdValue = absoluteDeviations / nbValues;
mdList.add(mdValue);
if (mdValue == 0) {
if (i >= n - 1) {
cciList.add(new Entry(0, i));
}
} else {
if (i &gt算法初步;= n - 1) {
float cci = (tpList宫崎骏.get(i) - cciMaList.get(i)) / mdList.get(i) / 0.015f;
cciList.add(new Entry(cci, i));
}
}
}
re公积金turn cciList;
}
private float getSum(Integer start,工作细胞 Integer end, List<Float&g算法t; datas) {
float sum = 0;
for (int i = start; i <= e宫颈癌nd; i++) {
sum += datas.get(i);
}
return s算法设计与分析um;
}
pri公积金vate float getTp(int index, List<CandleEntry> entri算法是什么es){
float maxPrice = entrie工作总结s.get(index).getHigh();
float minPrice = entries.get(index).getLow();
float closePrice = entries.get(index).getCl算法与数据结构ose();
return (maxPrice + minPrice + closePrice) / 3;
}

ROC的实现

变动率指标(ROC),是以算法工程师google日的收盘价和N天前的收盘价比较,通过计算股算法导论价某一段时间内收盘价变动的比例工作总结,应用价格的移动windows许可证即将过期怎么办比较来测量价位动量,达到事先探测股价买卖供需力量的强弱,进而分析股价的趋势及其是否有转势的意愿,属于反趋势指标之一。

更多信息查看

  • ROC实现公式

实现宫崎骏公式

  • 代码实现
    private List<Entry宫外孕> rocList;
priva算法是什么te List<Entry> rocMaList;
public Pair<List<Entry>, List<Entry>> getRoc(List<CandleEntry> entrieswindows怎么激活) {
int n = 12, m = 6;
if (entries == null) {
return new Pair<>(new ArrayList<>(), new ArrayList<>());
}
iwindows是什么意思f (rocList == null) {
rocList = new ArrayList<>();
rocMaList = new ArrayList<>();
}
//cleaWindowsr;
rocList.clear();
rocMaList.clear();
int len = entries.size();
forwindows10激活密钥 (int i = n; i < len; i++) {
int nIndex = Math.max(i算法导论吃透后的水平 - n, 0);
float nPeriodsAgoValue = entries.get(n算法工程师学什么专业Index).getClose();
float currentValue = entries.get(i).getClose();
float rocValwindows7ue = (currentValue - nPeriodsAgoValue) / nPeriodsAgoValue  *Go 100;
rocList.add(new EGontry(rocValue, i));
}
len = rocList.size();
for (int i = 0;windows10激活密钥 i < len; i++) {
if (i >= m - 1) {
float狗狗币 sum = getSumFromEntry(i - m + 1, i, rocList);工作细胞
float maValue = sumWindows / m;
rocMaList.add(new Entry(maValue, rocList.get(i).getXIndex()));
}
}
return new Pair<>(rocLis算法初步t, rocMaList);
}

后续

MACD的实现 /KDJ的实现/ BOLL的实现 / WR的实现