指标算法
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
1.WR
参数:N1:缺省值置为10范围为0~1000
N2:缺省值置为6范围为0~1000
N3:缺省值置为0范围为0~1000
下面为算法:
LL:=BARSCOUNT(CLOSE);
MMAX1:=HHV(HIGH,N1);
MMIN1:=LLV(LOW,N1);
TEMP1:=MMAX1-MMIN1;
MMAX2:=HHV(HIGH,N2);
MMIN2:=LLV(LOW,N2);
TEMP2:=MMAX2-MMIN2;
MMAX3:=HHV(HIGH,N3);
MMIN3:=LLV(LOW,N3);
TEMP3:=MMAX3-MMIN3;
IF(N1>0) THEN
IF(LL>=N1) THEN
W%R1:100.0*(MMAX1-CLOSE)/TEMP1;
IF(N2>0) THEN
IF(LL>=N2) THEN
W%R2:100.0*(MMAX2-CLOSE)/TEMP2;
IF(N3>0) THEN
IF(LL>=N2) THEN
W%R3:100.0*(MMAX3-CLOSE)/TEMP3;
下面为算法中用到的函数算法:
BARSCOUNT
求总的周期数。
用法:
BARSCOUNT(X)第一个有效数据到当前的天数
例如:BARSCOUNT(CLOSE)对于日线数据取得上市以来总交易日数,对于分笔成交取得当日成交笔数,对于1分钟线取得当日交易分钟数
HHV
求最高值。
用法:
HHV(X,N),求N周期内X最高值,N=0则从第一个有效值开始。
例如:HHV(HIGH,30)表示求30日最高价
LLV
求最低值。
用法:
LLV(X,N),求N周期内X最低值,N=0则从第一个有效值开始。
例如:LLV(LOW,0)表示求历史最低价
2.DMI
参数:N:缺省值置为7,范围为0~1000
下面为源码
bool QFormula::QMainFormulaCalc::CalculateDMI( tagCalcMethod& calM ethod, STKPTR& stkPtr, bool )
{
QFormulaResult* pRlt[4];
tagCalcData* pData;
pData = &calMethod.CalcData;
if (!pData || pData->dayData.pDayTechData == NULL)
return false;
QFormulaPara *pPara;
pPara = m_pFormula->GetPara(0);
if(pPara==NULL)
return false;
int vPara = pPara->Get().ToInt();
if(vPara<=0)
return false;
//m_pFormula->SetResultCount(4);
int j;
//TCHAR tcName[4][20] ={_T("+DI"),_T("-DI"),_T("ADX"),_T("ADXR")}; int RltNum = m_pFormula->GetResultCount();
for ( j = 0; j < RltNum; j++)
{
pRlt[j] = m_pFormula->GetResult(j);
if (!pRlt[j] || !pRlt[j]->SetResultLen(pData->DataRecords))
return false;
/*
pRlt[j]->m_Attr.wShowType = QRST_LINE;
pRlt[j]->m_Attr.wLineType = QFLT_LINE;
pRlt[j]->m_Attr.cOutputType = 1;
pRlt[j]->m_Attr.iOutId = j;
pRlt[j]->m_Attr.dwColor = 0xFFFFFFFF;//使用默认颜色
pRlt[j]->m_Attr.bDeci = 2;
_tcscpy(pRlt[j]->m_Attr.tcName,tcName[j]);
*/
}
double *tr, *pdm, *ndm, *trn, *pdmn, *ndmn;
tr = new double[pData->DataRecords];
pdm = new double[pData->DataRecords];
ndm = new double[pData->DataRecords];
trn = new double[pData->DataRecords];
pdmn = new double[pData->DataRecords];
ndmn = new double[pData->DataRecords];
if (!tr||!pdm||!ndm||!pdmn||!ndmn)
{
delete []tr;
delete []pdm;
delete []ndm;
delete []trn;
delete []pdmn;
delete []ndmn;
return FALSE;
}
int i;
for(i=0;i<pData->DataRecords;i++)
{
tr[i]= 0.0;
pdm[i] = 0.0;
ndm[i] = 0.0;
trn[i] = 0.0;
pdmn[i] = 0.0;
ndmn[i] = 0.0;
}
double trs = 0.0, pdms = 0.0, ndms = 0.0;
for(i=1;i<pData->DataRecords;i++)
{
double tr1 = fabs((pData->dayData.pDayTechData [i].High) - (pDa ta->dayData.pDayTechData [i].Low));
double tr2 = fabs((pData->dayData.pDayTechData [i].High) - (pDa ta->dayData.pDayTechData [i-1].Closing));
double tr3 = fabs((pData->dayData.pDayTechData [i].Low) - (pDat
a->dayData.pDayTechData [i-1].Closing));
tr[i] = max(max(tr1, tr2), tr3);
pdm[i] = max((pData->dayData.pDayTechData [i].High) - (pData->da yData.pDayTechData [i-1].High), 0.0);
ndm[i] = max((pData->dayData.pDayTechData [i-1].Low) - (pData->d ayData.pDayTechData [i].Low), 0.0);
if (pdm[i] > 0 && ndm[i] > 0)
{
if (pdm[i] >= ndm[i])
ndm[i] = 0;
else
pdm[i] = 0;
}
if ((int)i < vPara)
{
trs = trs + tr[i];
pdms = pdms + pdm[i];
ndms = ndms + ndm[i];
}
else if ((int)i == vPara)
{
trn[i] = trs / vPara;
pdmn[i] = pdms / vPara;
ndmn[i] = ndms / vPara;
}
else
{
trn[i] = trn[i-1]*(vPara-1)/vPara + tr[i];
pdmn[i] = pdmn[i-1]*(vPara-1)/vPara + pdm[i];
ndmn[i] = ndmn[i-1]*(vPara-1)/vPara + ndm[i];
}
}
//CalcMs( tr, trn, pData->DataRecords, vPara.ToInt(),1);
//CalcMs( pdm, pdmn, pData->DataRecords, vPara.ToInt(),1);
//CalcMs( ndm, ndmn, pData->DataRecords, vPara.ToInt(),1); delete []tr;
delete []pdm;
delete []ndm;
double dxs = 0.0; // dx sum
for(i=0;i<vPara;i++)
{
if(i<pData->DataRecords)
(*(pRlt[0]))[i] = ERROR_DATA;
(*(pRlt[1]))[i] = ERROR_DATA;
(*(pRlt[2]))[i] = ERROR_DATA;
(*(pRlt[3]))[i] = ERROR_DATA;
}
}
for(i=0;i<vPara*2-1;i++)
{
if(i<pData->DataRecords)
(*(pRlt[2]))[i] = ERROR_DATA;
}
for(i=0;i<vPara * 3 - 2;i++)
{
if(i<pData->DataRecords)
(*(pRlt[3]))[i] = ERROR_DATA;
}
for( i=vPara;i<pData->DataRecords;i++)
{
double dx;
if (!IsErrorData(pdmn[i]) && !IsErrorData(trn[i]) && !IsSmallFlo at(trn[i]))
{
(*(pRlt[0]))[i] = pdmn[i] / trn[i] * 100;
(*(pRlt[1]))[i] = ndmn[i] / trn[i] * 100;
}
else
{
(*(pRlt[0]))[i] = (*(pRlt[0]))[i-1];
(*(pRlt[1]))[i] = (*(pRlt[1]))[i-1];
}
double temp = (*(pRlt[0]))[i] + (*(pRlt[1]))[i];
if (!IsSmallFloat(temp))
dx = fabs((*(pRlt[0]))[i] - (*(pRlt[1]))[i]) /
temp * 100;
else
dx = 0.0;
if ((int)i < vPara* 2 - 1)
dxs = dxs + dx;
else if ((int)i == vPara * 2 - 1)
{
dxs = dxs + dx;
(*(pRlt[2]))[i] = dxs / vPara;
else
(*(pRlt[2]))[i] = ((*(pRlt[2]))[i-1] * (vPara - 1) + dx) / vPara;
if ((int)i >= vPara * 3 - 2)
(*(pRlt[3]))[i] = ((*(pRlt[2]))[i] + (*(pRlt[2]))[i - vPara + 1]) / 2;
}
delete []trn;
delete []pdmn;
delete []ndmn;
return TRUE;
}。