K线指标线计算方法
指标线计算方法
l dataDR = Kdata(原始数据)/dr(除权) //除权数据等于原始数据除以DR(除权) 其中,日K数据 需要本地进行除权处理。周K和月K的旧数据部分由服务器进行处理,新数据部分是需要本地进行处理的。使用DR数据时需要检查是否需要去掉预先给的DR数据。
l K线MA5 : 5天收盘价平均值
l K线MA10: 10天收盘价平均值
l K线MA20: 20天收盘价平均值
l K线MA60: 60天收盘价平均值
l 成交量MA5 : 5天成交量平均值
l 成交量MA10: 10天成交量平均值
l 成交量MA20: 20天成交量平均值
l 成交量MA60: 60天成交量平均值
l MACD: 需要使用数据:dataDR
定义参数:SHORT = 12, MID = 9, LONG = 26;
MACD_LARGER = 100; // 缩放因子
变量:DI, EMA_DI_SHORT, EMA_DI_LONG, DEA
len = KData.length //数据的长度
计算:
//计算每个数据的DIF,DEA,BAR三条线的数值
for(int i= 0 ;i<len;i++)
{
DI = MACD_LARGER * (dataDR[high]+ dataDR[low]+ dataDR[close]*2*0.25);
If(i==0)
{
EMA_DI_SHORT = DI;
EMA_DI_LONG = DI;
}
Else
{
EMA_DI_SHORT = EMA_DI_SHORT + (DI - EMA_DI_SHORT) * shortRate;
EMA_DI_LONG = EMA_DI_LONG + (DI - EMA_DI_LONG) * longRate;
}
DIF值= ((EMA_DI_SHORT - EMA_DI_LONG) / EMA_DI_LONG) * MACD_LARGER;
if (i == 0) {
DEA值 =DIF值;
} else {
DEA 值= DEA值 + (DIF值- DEA值) * (2.0 / MID);
}
BAR值= DIF值-DEA值;
}
l KDJ: 需要使用数据:dataDR KData (原始数据)
定义参数:RSVCyc = 9, KCyc = 3, DCyc = 3;
highWindow 数组, lowWindow 数组;
maxValue, minValue;
RSV, K, KB, D, DB, J, JB;
curClosePrice;
len = KData.length //数据的长度
计算://计算每个数据K 、D、 J值
//初始化
for (int i = 0; i < RSVCyc; i++) {
highWindow[i] = data[high] [0](第0个元素);
lowWindow[i] = data [low][0] (第0个元素);
}
KB = 50;
DB = 50;
JB = 50;
//计算
for(int i= 1;i< len;i++)
{
curClosePrice = dataDR [close];
if(curClosePrice<=0)
{
K值=50;
D 值= 50;
J值=50;
}
else
{
highWindow[i % RSVCyc] = dataDR [high];
lowWindow[i % RSVCyc] = dataDR [low];
maxValue = highWindow中最大值;
minValue = lowWindow 中最小值;
if(maxValue> minValue)
{
RSV = (curClosePrice - minValue) / (maxValue - minValue) * 100.0;
K值 = KB * (KCyc - 1) / KCyc + RSV / KCyc;
D 值= DB * (DCyc - 1) / DCyc + K / DCyc;
J 值= K * DCyc - D * (DCyc - 1);
KB= K值;
DB= D值;
JB= J值;
}
else
{
K值 =50;
D 值=50;
J 值=50;
}
}
}
l RSI: 需要使用数据:dataDR
定义参数:closeArray数组 = dataDR[close];
cyc(取值6和12 : 6天或者12天);
curClosePrice, lastClosePrice;
RA, DA, RD;
len = KData.length //数据的长度
计算://计算出一条RSI线的各个数据值
RSI值 = 50 //初始化
RA = 0.1;
DA = 0.1;
for (int i = 1; i < len; i++) {
curClosePrice = closeArray[i];
lastClosePrice = closeArray[i - 1];
if (curClosePrice <= 0) {
RSI值 = 50;
} else {
if (curClosePrice > lastClosePrice) {
RD = curClosePrice / lastClosePrice - 1.0;
RA = RA * (cyc - 1.0) / cyc + RD / cyc;
DA = DA * (cyc - 1.0) / cyc;
} else {
RD = 1.0 - curClosePrice / lastClosePrice;
RA = RA * (cyc - 1.0) / cyc;
DA = DA * (cyc - 1.0) / cyc + RD / cyc;
}
RSI值= RA / (RA + DA) * 100.0;
}
}
l BIAS: 需要使用数据:dataDR
定义参数:closeArray数组 = dataDR[close];
cyc(取值5/10/20 :三条线);
closeMaArray;
len = KData.length //数据的长度
计算://计算一条bias线的各个值
closeMaArray = closeArray的每cyc个数据的平均值构成的数组;
for (i = 0; i < len; i++) {
bias值 = (closeArray[i] - closeMaArray[i]) / closeMaArray[i] * 100.0;
}
l CCI: 需要使用数据:dataDR
定义参数:Cyc = 14;
len = KData.length //数据的长度
TYPArray, maTYPArray, aveDevArray
计算:
for (int i = 0; i < len; i++) {
TYPArray [i] = (dataDR[high] + dataDR [low]+ dataDR[close]) / 3.0
}
maTYPArray = TYPArray的每cyc个数据的平均值构成的数组;
aveDevArray = 先求TYPArray和maTYPArray的每个数据之差的绝对值,然后每cyc个绝对值的平均值构成的数组。
for (int i = 1; i < len; i++) {
CCI值= (TYPArray [i] - maTYPArray [i]) / (0.015 * aveDevArray [i]);
}
l ROC: 需要使用数据:dataDR
定义参数:closeArray数组 = dataDR[close];
cyc1=12,cyc2 =6; (两条线);
rocArray(第一条线值的数组)
len = KData.length //数据的长度
计算:
第一条线:
rocArray前cyc1个数据赋值为0;
for (int i=cyc1; i < len; i++) {
rocArray[i] = ((closeArray[i] - closeArray[i – cyc1]) / closeArray[i – cyc1] * 100);
}
第二条线:
rocMArray = rocArray的每cyc2个数据的平均值构成的数组;
l ASI: 需要使用数据:dataDR
定义参数:lastClosePrice;
AA, BB, CC, DD, R, X, SI;
- openArr, highArr, lowArr, closeArr
len = KData.length //数据的长度
计算:
openArr = dataDR[open]数据构成的数组
highArr = dataDR[high]数据构成的数组
lowArr = dataDR[low]数据构成的数组
closeArr = dataDR[close]数据构成的数组
ASI值[0] = 0;
for (int i = 1; i < len; i++) {
lastClosePrice = closeArr[i - 1];
AA = (highArr[i] - lastClosePrice)的绝对值;
BB = (lowArr[i] - lastClosePrice) 的绝对值;
CC = (highArr[i] - lowArr[i - 1]) 的绝对值;
DD = (lastClosePrice - openArr[i - 1]) 的绝对值;
R = (AA > BB && AA > CC) ? (AA + BB / 2 + DD / 4) : (BB > CC && BB > AA ? (BB + AA / 2 + DD / 4) : (CC + DD / 4));
X = closeArr[i] + (closeArr[i] - openArr[i]) / 2 - openArr[i - 1];
if (R == 0.0) {
SI[i]=0;
} else {
SI[i]=(16 * X / R * max(AA, BB));
}
ASI值 = ASI值[i-1]+ SI[i];
}
l PSY: 需要使用数据:dataDR
定义参数:cyc = 12;
closeArr = dataDR[close]数据构成的数组
count
len = KData.length //数据的长度
计算:
for (int i = 1; i < cyc && i < len; i++) {
if (closeArr[i] > closeArr[i - 1]) {
count++;
}
PSY值= count / cyc * 100.0;
}
for (int i=cyc; i < len; i++) {
if (closeArr[i - cyc] > closeArr[i - cyc - 1]) {
count--;
}
if (closeArr[i] > closeArr[i - 1]) {
count++;
}
PSY值= count / cyc * 100.0;
}
#import "EzMakeLineData.h" @implementation EzMakeLineData +(NSMutableArray *)getLineData:(NSMutableArray *)data type:(int)type { NSMutableArray *lineDataArr = nil; switch (type) { case 0: lineDataArr = [self getVolData:data]; break; case 1: lineDataArr = [self getMACDData:data]; break; case 2: lineDataArr = [self getKDJData:data]; break; case 3: lineDataArr = [self getRSIData:data]; break; case 4: lineDataArr = [self getBIASData:data]; break; case 5: lineDataArr = [self getCCIData:data]; break; case 6: lineDataArr = [self getROCData:data]; break; case 7: lineDataArr = [self getASIData:data]; break; case 8: lineDataArr = [self getPSYData:data]; break; default: break; } return lineDataArr; } #pragma mark - 成交量 +(NSMutableArray *)getVolData:(NSMutableArray *)data { return data; } #pragma mark - MACD +(NSMutableArray *)getMACDData:(NSMutableArray *)data { //定义参数 CGFloat SHORT = 12; CGFloat MID = 9; CGFloat LONG = 26; CGFloat MACD_LARGER = 100; //缩放因子 CGFloat DI; CGFloat EMA_DI_SHORT = 0.0; CGFloat EMA_DI_LONG = 0.0; CGFloat DEA = 0.0; CGFloat DIF; CGFloat BAR; CGFloat shortRate; CGFloat longRate; NSMutableArray *arr = [[NSMutableArray alloc] initWithCapacity:0]; if (SHORT == 12) { shortRate = 0.1538; } else { shortRate = 2.0 / (SHORT + 1); } if (LONG == 26) { longRate = 0.0741; } else { longRate = 2.0 / (LONG + 1); } //计算每个数据的DIF,DEA,BAR三条线的数值 for(int i= 0 ;i<data.count;i++) { NSMutableArray *subArr = data[i]; DI = MACD_LARGER * ([subArr[1] floatValue]+ [subArr[2] floatValue]+ [subArr[3] floatValue]*2)*0.25; if(i==0) { EMA_DI_SHORT = DI; EMA_DI_LONG = DI; } else { EMA_DI_SHORT = EMA_DI_SHORT + (DI - EMA_DI_SHORT) * shortRate; EMA_DI_LONG = EMA_DI_LONG + (DI - EMA_DI_LONG) * longRate; } DIF= ((EMA_DI_SHORT - EMA_DI_LONG) / EMA_DI_LONG) * MACD_LARGER; if (i == 0) { DEA =DIF; } else { DEA= DEA + (DIF- DEA) * (2.0 / MID); } BAR= DIF-DEA; [subArr addObject:[NSNumber numberWithDouble:DIF]]; [subArr addObject:[NSNumber numberWithDouble:DEA]]; [subArr addObject:[NSNumber numberWithDouble:BAR]]; [arr addObject:subArr]; } return arr; } #pragma mark - KDJ +(NSMutableArray *)getKDJData:(NSMutableArray *)data { //定义参数 CGFloat RSVCyc = 9; CGFloat KCyc = 3; CGFloat DCyc = 3; NSMutableArray *highWindow; NSMutableArray *lowWindow ; CGFloat maxValue; CGFloat minValue; CGFloat RSV, K, KB, D, DB, J, JB; CGFloat curClosePrice; NSMutableArray *arr = [[NSMutableArray alloc] initWithCapacity:0]; //计算每个数据K 、D、 J值 //初始化 highWindow = [[NSMutableArray alloc] initWithCapacity:0]; lowWindow = [[NSMutableArray alloc] initWithCapacity:0]; if (data.count>0) { for (int i = 0; i < RSVCyc; i++) { highWindow[i] = [data[0] objectAtIndex:1]; //第0个元素的high lowWindow[i] = [data[0] objectAtIndex:2]; //第0个元素的low } KB = 50; DB = 50; JB = 50; NSMutableArray *subArr = data[0]; [subArr addObject:[NSNumber numberWithDouble:50]]; [subArr addObject:[NSNumber numberWithDouble:50]]; [subArr addObject:[NSNumber numberWithDouble:50]]; [arr addObject:subArr]; if (data.count>1) { //计算 for(int i= 1;i<data.count;i++) { subArr = data[i]; curClosePrice = [subArr[3] floatValue]; if(curClosePrice<=0) { K=50; D= 50; J=50; } else { highWindow[(int)fmod(i, RSVCyc)] = subArr[1]; lowWindow[(int)fmod(i, RSVCyc)] = subArr[2]; maxValue = [[highWindow valueForKeyPath:@"@max.floatValue"] floatValue]; minValue = [[lowWindow valueForKeyPath:@"@min.floatValue"] floatValue]; if(maxValue> minValue) { RSV = (curClosePrice - minValue) / (maxValue - minValue) * 100.0; K = KB * (KCyc - 1) / KCyc + RSV / KCyc; D = DB * (DCyc - 1) / DCyc + K / DCyc; J = K * DCyc - D * (DCyc - 1); KB= K; DB= D; JB= J; } else { K =50; D =50; J =50; } } [subArr addObject:[NSNumber numberWithDouble:K]]; [subArr addObject:[NSNumber numberWithDouble:D]]; [subArr addObject:[NSNumber numberWithDouble:J]]; [arr addObject:subArr]; } } } return arr; } #pragma mark - RSI +(NSMutableArray *)getRSIData:(NSMutableArray *)data { //定义参数 NSMutableArray *closeArray; CGFloat cyc6 = 6; CGFloat cyc12 = 12; //计算出一条RSI线的各个数据值 closeArray = [[NSMutableArray alloc] initWithCapacity:0]; for(int i = 0; i < data.count; i++) { [closeArray addObject:[data[i] objectAtIndex:3]] ;//第i个元素的close } //RSI6 NSMutableArray *arr = [self makeRSI:data closeArray:closeArray cyc:cyc6]; //RSI12 arr = [self makeRSI:arr closeArray:closeArray cyc:cyc12]; return arr; } +(NSMutableArray *)makeRSI:(NSMutableArray *)data closeArray:(NSMutableArray *)closeArray cyc:(CGFloat)cyc { CGFloat curClosePrice; CGFloat lastClosePrice; CGFloat RA,DA,RD,RSI; RSI = 50; RA = 0.1; DA = 0.1; NSMutableArray *arr = [[NSMutableArray alloc] initWithCapacity:0]; if (data.count>0) { NSMutableArray *subArr = data[0]; [subArr addObject:[NSNumber numberWithDouble:RSI]]; [arr addObject:subArr]; for(int i = 1;i<data.count;i++) { subArr = data[i]; curClosePrice = [closeArray[i] floatValue]; lastClosePrice = [closeArray[i - 1] floatValue]; if (curClosePrice <= 0) { RSI = 50; } else { if (curClosePrice > lastClosePrice) { RD = curClosePrice / lastClosePrice - 1.0; RA = RA * (cyc - 1.0) / cyc + RD / cyc; DA = DA * (cyc - 1.0) / cyc; } else { RD = 1.0 - curClosePrice / lastClosePrice; RA = RA * (cyc - 1.0) / cyc; DA = DA * (cyc - 1.0) / cyc + RD / cyc; } RSI= RA / (RA + DA) * 100.0; } [subArr addObject:[NSNumber numberWithDouble:RSI]]; [arr addObject:subArr]; } } return arr; } #pragma mark - BIAS +(NSMutableArray *)getBIASData:(NSMutableArray *)data { //定义参数 NSMutableArray *closeArray; CGFloat cyc5 = 5; CGFloat cyc10 = 10; CGFloat cyc20 = 20; closeArray = [[NSMutableArray alloc] initWithCapacity:0]; for(int i = 0; i < data.count; i++) { [closeArray addObject:[data[i] objectAtIndex:3]] ; //第i个元素的close } //5 NSMutableArray *arr = [self makeBIAS:data closeArray:closeArray cyc:cyc5]; //10 arr = [self makeBIAS:arr closeArray:closeArray cyc:cyc10]; //20 arr = [self makeBIAS:arr closeArray:closeArray cyc:cyc20]; return arr; } +(NSMutableArray *)makeBIAS:(NSMutableArray *)data closeArray:(NSMutableArray *)closeArray cyc:(CGFloat)cyc { NSMutableArray *closeMaArray; //计算一条bias线的各个值 closeMaArray = [self moveAvgArr:closeArray cyc:cyc]; NSMutableArray *arr = [[NSMutableArray alloc] initWithCapacity:0]; for (int i = 0; i < data.count;i++) { NSMutableArray *subArr = data[i]; CGFloat bias = ([closeArray[i] floatValue]-[closeMaArray[i] floatValue]) / [closeMaArray[i] floatValue] * 100.0; [subArr addObject:[NSNumber numberWithDouble:bias]]; [arr addObject:subArr]; } return arr; } //计算滑动平均值 +(NSMutableArray *)moveAvgArr:(NSMutableArray *)Array cyc:(CGFloat)cyc { NSMutableArray *AvgArray; NSMutableArray *littleArr; //计算一条bias线的各个值 AvgArray = [[NSMutableArray alloc] initWithCapacity:0]; littleArr = [[NSMutableArray alloc] initWithCapacity:0]; //计算获取滑动平均值数组 int num=0; for (int i = 0; i<Array.count; i++) { if (i<=cyc-1) { num++; [littleArr addObject:Array[i]]; CGFloat avg = [[littleArr valueForKeyPath:@"@sum.floatValue"] floatValue]/num; [AvgArray addObject:[NSNumber numberWithFloat:avg]]; } else { [littleArr removeObjectAtIndex:0]; [littleArr addObject:Array[i]]; CGFloat avg = [[littleArr valueForKeyPath:@"@sum.floatValue"] floatValue]/num; [AvgArray addObject:[NSNumber numberWithFloat:avg]]; } } return AvgArray; } #pragma mark - CCI +(NSMutableArray *)getCCIData:(NSMutableArray *)data { //定义参数 NSMutableArray *TYPArray,*maTYPArray,*aveDevArray; CGFloat cyc14 = 14; NSMutableArray *arr = [[NSMutableArray alloc] initWithCapacity:0]; TYPArray = [[NSMutableArray alloc] initWithCapacity:0]; maTYPArray = [[NSMutableArray alloc] initWithCapacity:0]; aveDevArray = [[NSMutableArray alloc] initWithCapacity:0]; for (int i = 0; i < data.count; i++) { CGFloat typ =([[data[i] objectAtIndex:1] floatValue] + [[data[i] objectAtIndex:2] floatValue]+ [[data[i] objectAtIndex:3] floatValue])/3.0; [TYPArray addObject:[NSNumber numberWithFloat:typ]]; } maTYPArray = [self moveAvgArr:TYPArray cyc:cyc14]; aveDevArray = [self aveDevArr:TYPArray arr2:maTYPArray cyc:cyc14]; if (data.count>0) { NSMutableArray *subArr = data[0]; [subArr addObject:[NSNumber numberWithDouble:0]]; [arr addObject:subArr]; if (data.count>1) { for (int i = 1; i < data.count; i++) { subArr = data[i]; CGFloat CCI= ([TYPArray [i] floatValue] - [maTYPArray [i] floatValue]) / (0.015 * [aveDevArray [i] floatValue]); [subArr addObject:[NSNumber numberWithDouble:CCI]]; [arr addObject:subArr]; } } } return arr; } //Make aveDevArray +(NSMutableArray *)aveDevArr:(NSMutableArray *)Array arr2:(NSMutableArray *)arr2 cyc:(CGFloat)cyc { NSMutableArray *AvgArray; CGFloat windowSum; int j; AvgArray = [[NSMutableArray alloc] initWithCapacity:0]; for (int i = 0; i< Array.count; i++) { windowSum =0; for (j=i; j>i-cyc&&j>0; j--) { windowSum = windowSum+ fabs([Array[j] floatValue]-[arr2[i] floatValue]); } if (j==i-cyc) { [AvgArray addObject:[NSNumber numberWithFloat:(windowSum/cyc)]]; } else { [AvgArray addObject:[NSNumber numberWithFloat:(windowSum/(i-j+1))]]; } } return AvgArray; } #pragma mark - ROC +(NSMutableArray *)getROCData:(NSMutableArray *)data { //定义参数 NSMutableArray *closeArray; int cyc6 = 6; int cyc12 = 12; closeArray = [[NSMutableArray alloc] initWithCapacity:0]; for(int i = 0; i < data.count; i++) { [closeArray addObject:[data[i] objectAtIndex:3]] ; //第i个元素的close } NSMutableArray *arr = [[NSMutableArray alloc] initWithCapacity:0]; NSMutableArray *subArr; NSMutableArray *ROCarr = [[NSMutableArray alloc] initWithCapacity:0]; if (data.count<cyc12) { cyc12= (int)data.count; } //12 for (int i = 0; i<cyc12; i++) { subArr = data[i]; [subArr addObject:[NSNumber numberWithDouble:0]]; [ROCarr addObject:[NSNumber numberWithDouble:0]]; } for (int i= cyc12; i<data.count; i++) { subArr = data[i]; CGFloat ROC = ([closeArray[i] floatValue] - [closeArray[i-cyc12] floatValue])/[closeArray[i-cyc12] floatValue]*100; [subArr addObject:[NSNumber numberWithDouble:ROC]]; [ROCarr addObject:[NSNumber numberWithDouble:ROC]]; } //6 ROCarr = [self moveAvgArr:ROCarr cyc:cyc6]; for (int i = 0 ; i<data.count; i++) { subArr = data[i]; [subArr addObject:[NSNumber numberWithDouble:[ROCarr[i] floatValue]]]; [arr addObject:subArr]; } return arr; } #pragma mark - ASI +(NSMutableArray *)getASIData:(NSMutableArray *)data { //定义参数 NSMutableArray *openArr, *highArr, *lowArr, *closeArr,*SI; CGFloat lastClosePrice; CGFloat AA, BB, CC, DD, R, X; openArr = [[NSMutableArray alloc] initWithCapacity:0]; highArr = [[NSMutableArray alloc] initWithCapacity:0]; lowArr = [[NSMutableArray alloc] initWithCapacity:0]; closeArr = [[NSMutableArray alloc] initWithCapacity:0]; SI = [[NSMutableArray alloc] initWithCapacity:0]; for(int i = 0; i < data.count; i++) { [openArr addObject:[data[i] objectAtIndex:0]]; [highArr addObject:[data[i] objectAtIndex:1]]; [lowArr addObject:[data[i] objectAtIndex:2]]; [closeArr addObject:[data[i] objectAtIndex:3]]; //第i个元素的close } NSMutableArray *arr = [[NSMutableArray alloc] initWithCapacity:0]; NSMutableArray *subArr; if (data.count>0) { subArr=data[0]; [subArr addObject:[NSNumber numberWithFloat:0]]; [arr addObject:subArr]; [SI addObject:[NSNumber numberWithFloat:0]]; if (data.count>1) { for (int i = 1; i < data.count; i++) { subArr = data[i]; lastClosePrice = [closeArr[i - 1] floatValue]; AA = fabs([highArr[i] floatValue] - lastClosePrice); BB = fabs([lowArr[i] floatValue] - lastClosePrice); CC = fabs([highArr[i] floatValue] - [lowArr[i - 1] floatValue]); DD = fabs(lastClosePrice - [openArr[i - 1] floatValue]); R = (AA > BB && AA > CC) ? (AA + BB / 2 + DD / 4) : (BB > CC && BB > AA ? (BB + AA / 2 + DD / 4) : (CC + DD / 4)); X = [closeArr[i] floatValue] + ([closeArr[i] floatValue] - [openArr[i] floatValue]) / 2 - [openArr[i - 1] floatValue]; if (R == 0) { [SI addObject:[NSNumber numberWithFloat:0]]; } else { [SI addObject:[NSNumber numberWithFloat:(16 * X / R * (AA>BB?AA:BB))]]; } NSMutableArray *subArr11; subArr11 = data[i-1]; CGFloat ASI= [[subArr11 lastObject] floatValue]+ [SI[i] floatValue]; [subArr addObject:[NSNumber numberWithFloat:ASI]]; [arr addObject:subArr]; } } } return arr; } #pragma mark - PSY +(NSMutableArray *)getPSYData:(NSMutableArray *)data { //定义参数 NSMutableArray *closeArr; int cyc12=12; CGFloat count = 0; closeArr = [[NSMutableArray alloc] initWithCapacity:0]; for(int i = 0; i < data.count; i++) { [closeArr addObject:[data[i] objectAtIndex:3]]; //第i个元素的close } NSMutableArray *arr = [[NSMutableArray alloc] initWithCapacity:0]; if (data.count>0) { NSMutableArray *subArr; subArr = data[0]; [subArr addObject:[NSNumber numberWithFloat:100]]; [arr addObject:subArr]; if (data.count>1) { if (data.count<cyc12) { cyc12= (int)data.count; } for (int i = 1; i < cyc12 && i < data.count; i++) { subArr = data[i]; if ([closeArr[i] floatValue] > [closeArr[i-1] floatValue]) { count++; } CGFloat PSY= count / cyc12 * 100.0; [subArr addObject:[NSNumber numberWithFloat:PSY]]; [arr addObject:subArr]; } for (int i=cyc12; i < data.count; i++) { subArr = data[i]; if (i==cyc12) { } else { if ([closeArr[i - cyc12] floatValue] > [closeArr[i - cyc12 - 1] floatValue]) { count--; } } if ([closeArr[i] floatValue] > [closeArr[i-1] floatValue]) { count++; } CGFloat PSY= count / cyc12 * 100.0; [subArr addObject:[NSNumber numberWithFloat:PSY]]; [arr addObject:subArr]; } } } return arr; } @end