鼎元C++期货量化/程序化技术指标公式模块【highest、lowest的计算方法及调用方法】
第一部分、头文件声明变量:[code]double lowest(string period, string inst, int bartypt, int num); //最低价lowest函数变量double highest(string period, string inst, int bartypt, int num); //最高价highest函数变量[/code]第二部分、源文件公式计算函数[code]
//最低价lowest计算公式开始,bartype(1:open ,2high,3low,4close)
double test::lowest(string period, string inst, int bartype, int num)
{
double d = 0;
int n = 0;
int bart =3;
map<string, TKVALUE>::reverse_iterator it;
for (it = mapK[period][inst].rbegin(); it != mapK[period][inst].rend(); ++it)
{
if (bartype == 1) bart = it->second.dOpen;
if (bartype == 2) bart = it->second.dHigh;
if (bartype == 3) bart = it->second.dLow;
if (bartype == 4) bart = it->second.dClose;
if (d == 0)d = bart;
if (d > bart)d = bart;
n++;
if (n >= num)break;
}
return d;
}
//最低价lowest计算公式结束,bartype(1:open ,2high,3low,4close)[/code][code]//最高价highest计算公式开始,bartype(1:open ,2high,3low,4close)
double test::highest(string period, string inst, int bartype, int num)
{
double d = 0;
int n = 0;
int bart = 2;
map<string, TKVALUE>::reverse_iterator it;
for (it = mapK[period][inst].rbegin(); it != mapK[period][inst].rend(); ++it)
{
if (bartype == 1) bart = it->second.dOpen;
if (bartype == 2) bart = it->second.dHigh;
if (bartype == 3) bart = it->second.dLow;
if (bartype == 4) bart = it->second.dClose;
if (d == 0)d = bart;
if (d < bart)d = bart;
n++;
if (n >= num)break;
}
return d;
}
//最高价highest计算公式结束,bartype(1:open ,2high,3low,4close)[/code]三、使用方法:
1、范例:[code]RsqBar(sPeriod, sInst);
lowest(sPeriod, sInst, 1,2);[/code]调用前2bar的开盘价中最低的那个值。类似MC中的[code]lowest(open,2)[/code]2、范例:[code]RsqBar(sPeriod, sInst);
highest(sPeriod, sInst, 1,2);[/code]调用前2bar的开盘价中最高的那个值。类似MC中的[code]highest(open,2)[/code] 使用说明参考:[url]http://www.qhlt.cn/thread-160007-1-1.html[/url];
页:
[1]