  
- UID
- 2
- 积分
- 2937974
- 威望
- 1419023 布
- 龙e币
- 1518951 刀
- 在线时间
- 13696 小时
- 注册时间
- 2009-12-3
- 最后登录
- 2025-4-13

|
鼎元全自动C++软件【函数公式设计:统一调用模板】说明
1、鼎元C++全自动化软件使用函数或公式计算价格及其它变量可以在主程序中直接设计并计算,也可以通过调用函数公式来计算。
2、因为调用函数或公式计算,一会减少主程序的代码量,二是会比较有条理,这也是我建议大家将一些常用的函数与指标写到专门的模板里面,模块化函数指标会减少学习难度。
3、如何新建一个公式模板:
(1)、资源管理器---源文件---右键单击 ---填加---选择cpp文件 --- 取名“function.cpp”
(2)、配置一下外部引用项:- //****************************************************************外部引用文件开始(谨慎修改)
- #include "pch.h"
- #include "test.h"
- #include <vector>
- #include <windows.h>
- #include <fstream>
- #include <stdio.h>
- #include <mmsystem.h>
- #include <thread>
- #pragma comment(lib,"winmm.lib")
- #include <algorithm> // For std::min_element and std::max_element
- #include <deque>
- using namespace std;
复制代码 (3)、新建完成,新加了一个空白的公式函数专用cpp文件。可以将我设计的公式函数放进去。参考地址:http://www.qhlt.cn/thread-160230-1-1.html;
(4)、还在test.h文件中声明一下全局变量才能在后面调用。若是不声明,是没法使用的。如下:
在一个private 里面即可,声明后就可以在主程序设计区任意位置来调用它了。重要说明:这个全局的声明与上面的函数公式要对应起来,其时出现不同版本,容易导致报错- //指标公式变量声明******************************************************************test头文件指标公式变量名称模块开始(修改与编辑指标参数变量)
- double iff(bool cond1, int num, int ref);//iff函数
- double max2(double a, double b);//返回a,b中较大值
- double max3(double a, double b, double c);//返回a,b,c中最大值
- double min2(double a, double b); //返回a,b中较小值
- double min3(double a, double b, double c);//返回a,b,c中最小值
- double waverage(string period, string inst, int num);//计算Weighted Moving Average,加权移动平均线
- double average(string period, string inst, int num); //average,ma函数变量,atr计算功能
- double highest(string period, string inst, int num);//计算NUM周期最高价格
- double highestN(string period, string inst, int num, int ref);//计算REF前个bar的num周期最高价格
- double lowest(string period, string inst, int num); //计算NUM周期最低价格
- double lowestN(string period, string inst, int num, int ref);//计算ref前个bar的num周期的最低价格
- double closeN(string period, string inst, int ref);//计算ref前个bar的收盘价格
- double avgtruerange(string period, string inst, int num); //计算真实波动幅度平均值(average true range)
- double Variance(string period, string inst, int num);//计算方差公式变量
- double StandardDev(string period, string inst, int num);//计算标准差公式变量
- double Volatility(string period, string inst, int num);//计算历史波动率(CALCULATING HISTORICAL VOLATILITY)
- double bollingerbands(string period, string inst, int num, int ref); //计算boll布林带变量
- //指数移动平均返回具体数据时调用xaverage,返回数组时则用ema调用。数组形式多用于指标计算中间变量
- double xaverage(string period, string inst, int num);//计算num周期指数移动平均(Exponential Moving Average)值
- vector<double>ema(vector<double>pc, int num);//ema计算返回数组vector形式指数移动平均
- //指数移动平均返回具体数据时调用xaverage,返回数组时则用ema调用。数组形式多用于指标计算中间变量
- vector<double>EMAvectorCaL(vector<double>pc, int num);//EMA容器计算形式
- vector<double>MACDcalculate(vector<double>pc, int shortPeriod, int longPeriod);//计算MACD
- double mav(vector<double>pc, int num);//计算简单MA数组形式
- double hhv(vector<double> pc, int num);
- double llv(vector<double> pc, int num);
- double AEMA(string period, string inst, int num, int pds);//自适应移动平均线(Adaptive Exponential Moving Average, AEMA)
- vector<double>aema, highs, lows; //vector变量容器
- double a0, a1, a2, a3, a4, value2, value3, mltp1, mltp2, rate, aema1, aema2;//必要变量,自适应移动平均线
- double marketstrength(string period,string inst, int num);//marketstrength函数调用与计算
- double Momentum(string period, string inst, int num); //动量指标(Momentum Index,MTM)计算与指标调用
- //指标公式变量声明******************************************************************test头文件指标公式变量名称模块结束(修改与编辑指标参数变量)
复制代码 |
论坛官方微信、群(期货热点、量化探讨、开户与绑定实盘)
|