鼎元C++量化程式码指标与函数模块系列之【highest、lowest的计算方法及调用方法】
  
- UID
- 2
- 积分
- 2914403
- 威望
- 1407234 布
- 龙e币
- 1507169 刀
- 在线时间
- 13521 小时
- 注册时间
- 2009-12-3
- 最后登录
- 2025-3-3

|
鼎元C++量化程式码指标与函数模块系列之【highest、lowest的计算方法及调用方法】
第一部分、头文件声明变量:- double highest(string period, string inst, int num); //获取num周期内所有bar的最高价
- double lowest(string period, string inst, int num);//获取num周期内所有bar中最低价
复制代码 第二部分、源文件公式计算函数- // 计算num周期内bar最高价格
- double test::highest(string period, string inst, int num)
- {
- double hiprice = 0;
- int key = 0;
- map<string, TKVALUE>::reverse_iterator it;
- for (it = mapK[period][inst].rbegin(); it != mapK[period][inst].rend(); ++it)
- {
- if (hiprice < it->second.dHigh)hiprice = it->second.dHigh;
- key++;
- if (key >= num)break;
- }
- return hiprice;
- }//计算num周期内bar最低价格
- double test::lowest(string period, string inst, int num)
- {
- double lowprice = 0;
- int key = 0;
- map<string, TKVALUE>::reverse_iterator it;
- for (it = mapK[period][inst].rbegin(); it != mapK[period][inst].rend(); ++it)
- {
- if (lowprice == 0)lowprice = it->second.dLow;
- if (lowprice > it->second.dLow)lowprice = it->second.dLow;
- key++;
- if (key >= num)break;
- }
- return lowprice;
- }
复制代码 三、使用方法:
1、范例:- RsqBar(sPeriod, sInst);
- lowest(sPeriod, sInst, 20);
复制代码 调用前20中bar的开盘价中最低价。 |
论坛官方微信、群(期货热点、量化探讨、开户与绑定实盘)
|
|
|
|
|
|
  
- UID
- 2
- 积分
- 2914403
- 威望
- 1407234 布
- 龙e币
- 1507169 刀
- 在线时间
- 13521 小时
- 注册时间
- 2009-12-3
- 最后登录
- 2025-3-3

|
|
|
|
|
|
|
  
- UID
- 2
- 积分
- 2914403
- 威望
- 1407234 布
- 龙e币
- 1507169 刀
- 在线时间
- 13521 小时
- 注册时间
- 2009-12-3
- 最后登录
- 2025-3-3

|
|
|
|
|
|
|