void toString(QString& buffer)
{
QRegExp rx("(\\\\u[0-9a-fA-F]{4})");
int pos = 0;
while ((pos = rx.indexIn(buffer, pos)) != -1) {
buffer.replace(pos++, 6, QChar(rx.cap(1).right(4).toUShort(0, 16)));
}
}
class KDJ:
history = []
code = ''
min = 99999.99
max = 0.0
k = 0.0
d = 0.0
rsv = 0.0
def __init__(self,code):
self.code = code
def checkMinAndMax(self,n):
min = 99999.9
max = 0.0
for item in self.history:
if item[3] < min:
min = item[3]
if item[4] > max:
max = item[4]
return [min,max]
def update(self,date,start,close,low,high,n):
self.history.append([date,start,close,low,high])
if len(self.history) < n:
self.min = min(self.min,low)
self.max = max(self.max,high)
return [date,self.k,self.d,0,start,close,low,high]
else:
if len(self.history) > n:
del self.history[0]
p = self.checkMinAndMax(n)
rsv = (close - p[0])/(p[1]-p[0])*100.0
oldk = self.k
oldd = self.d
self.k = (rsv + 2*oldk)/3.0
self.d = (self.k + 2*oldd)/3.0
self.k = min(100,max(self.k,0))
self.d = min(100,max(self.d,0))
j = 3*self.k - 2*self.d
j = min(100,max(j,0))
return [date,self.k,self.d,j,start,close,low,high]
常规无法做到,使用setCellWidget(i,j,new QLabel(text));即可
setAlternatingRowColors ( bool enable );
以前还真没用到过
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
int main()
{
int arr[] = {2,3,4,5,8,2,9};
std::priority_queue<int> data(arr,arr+7);
std::cout<<"count:"<<data.size()<<std::endl;
while(!data.empty())
{
std::cout<<data.top()<<" ";
data.pop();
}
return 0;
}
#include <iostream>
#include <algorithm>
using namespace std;
template<class I,class F>
I get(I from,I to,F f)
{
I ret = to;
std::sort(from,to,f);
while(from != to)
{
if(*from != *(from+1))
{
ret = from+1;
break;
}
from ++;
}
return ret;
}
template<class T>
bool isLessThen(T a,T b)
{
return a < b;
}
int main()
{
int arr[] = {2,3,4,5,8,2,9};
int* itr = get(arr,arr+7,isLessThen<int>);
cout <<*itr<< endl;
return 0;
}
QTextCursor cursor = textCursor();
cursor.movePosition(QTextCursor::Start);
setTextCursor(cursor);
如下:
foreach(QCPAxis* axis,mMacdRect->rangeDragAxes(Qt::Horizontal))
connect(mCustomPlot->xAxis,SIGNAL(rangeChanged(QCPRange)),axis,SLOT(setRange(QCPRange)));
很简单
MACD计算代码
参数设置为12,23.9
struct Macd
{
Macd():m12(0.0f),m26(0.0f),diff(0.0f),dea(0.0f),bar(0.0f),index(-1){}
float m12;
float m26;
float diff;
float dea;
float bar;
int index;
void update(float value)
{
index ++;
if(index == 0)
{
m12 = value;
m26 = value;
}
else
{
m12 = m12 + (value - m12) * 2.0f/13.0f;
m26 = m26 + (value - m26) * 2.0f/27.0f;
diff = m12 - m26;
if(index == 1)
dea = 0.2*diff;
else
dea = dea*0.8 + diff*0.2;
bar = 2 * (-dea + diff);
std::cout<<diff<<" "<<dea<<" "<<bar<<std::endl;
}
}
};
炒股的同学可以加入蜗牛选股群:297919841 验证码为来自博客园