- 精华
- 0
- 在线时间
- 113 小时
- UID
- 208212
- 积分
- 2006
- 帖子
- 103
- 阅读权限
- 70
- 注册时间
- 2015-5-2
- 最后登录
- 2019-6-18
- 精华
- 0
- UID
- 208212
- 积分
- 2006
- 帖子
- 103
- 主题
- 24
- 阅读权限
- 70
- 注册时间
- 2015-5-2
- 最后登录
- 2019-6-18
|
本帖最后由 china_lizhi 于 2016-11-17 23:29 编辑
//------------------------------------------------------------------------
// 简称: Test_NthCon
// 名称: NthCon函数测试
// 类别: 公式应用
// 类型: 用户应用
// 输出: Void
//------------------------------------------------------------------------
Params
Numeric N(20);
Vars
Bool Con(false);
NumericSeries PreConIndex;
NumericSeries BarNums;
Numeric i(0);
Numeric ReBars(0);
Numeric HIF;
Begin
Con = H[1]<=H[2]; //设定逻辑条件H[1]<=H[2],这里Con由默认值(false)变为条件为真
If(Con)//条件为真
{
HIF = 1;//赋值为1,表示条件为真
BarNums = 0;//赋值BarNums为0
PreConIndex = BarNums[1] + 1;//回溯BarNums的前一个值 + 1
//一直为If(Con),则If(Con)的值一直为1
//If(Con)为假之后又变为真时,则PreConIndex的值等于条件为假的累计次数 + 1
FileAppend("E:\Test_NthCon1.Log"," Date= "+Text(Date) +" H= "+Text(H)+" H[1]= "+Text(H[1])+" H[2]= "+TEXT(H[2])+" HIF= "+Text(HIF)+" BarNums= "+Text(BarNums)+" BarNums[1]= "+Text(BarNums[1]) + " PreConIndex= "+Text(PreConIndex)+" PreConIndex[ReBars]= "+Text(PreConIndex[ReBars]));
Commentary("真"+" 《HIF = "+Text(HIF)+" 》《BarNums = 0为:"+text(BarNums) +" 》《BarNums[1]为:"+Text(BarNums[1])+" 》《PreConIndex= BarNums[1] + 1为:"+Text(PreConIndex)+"》");
}Else//条件为假
{
HIF = -1;//赋值为-1,表示条件为假
BarNums = BarNums + 1;//计算条件为假的累计次数
PreConIndex = BarNums;//将计算出来的条件为假的累计次数赋值给PreConIndex
FileAppend("E:\Test_NthCon2.Log"," Date= "+Text(Date) +" H= "+Text(H)+" H[1]= "+Text(H[1])+" H[2]= "+TEXT(H[2])+" HIF= "+Text(HIF)+" BarNums= "+Text(BarNums)+" PreConIndex= "+Text(PreConIndex));
Commentary("假"+" 《HIF = "+Text(HIF)+"》 《BarNums = BarNums + 1为:"+text(BarNums) +" 》《PreConIndex= BarNums为:"+Text(PreConIndex)+"》");
}
ReBars = BarNums;//将BarNums的值赋值给ReBars
FileAppend("E:\Test_NthCon3.Log","Date= "+Text(Date) + " ReBars="+Text(BarNums) );
Commentary("ReBars = BarNums为:"+Text(BarNums));
For i = 2 To N//在每一根Bar上都从“i = 2 To N” 计算 “ReBars = ReBars + PreConIndex[ReBars]”的值
{
FileAppend("E:\Test_NthCon4.Log","Date= "+Text(Date) + " i="+Text(i) );
ReBars = ReBars + PreConIndex[ReBars];
//条件不存在时,初始值为ReBars=N-1
//PreConIndex[ReBars]总是等于1
//条件为假时,回溯值累加1
//条件为真是,回溯值累加0
FileAppend("E:\Test_NthCon5.Log","Date= "+Text(Date) + " ReBars="+Text(BarNums));
//Commentary("PreConIndex[ReBars]为:"+Text(PreConIndex[ReBars]));
//Commentary(" ReBars= ReBars + PreConIndex[ReBars]为:"+Text(BarNums));
}
Commentary("Return ReBars 为:"+Text(ReBars));
FileAppend("E:\Test_NthCon6.Log","Date= "+Text(Date) +" H= "+Text(H)+" H[1]= "+Text(H[1])+" H[2]= "+TEXT(H[2])+" HIF= "+Text(HIF)+" BarNums= "+Text(BarNums)+" PreConIndex= "+Text(PreConIndex) + " PreConIndex[ReBars]= "+Text(PreConIndex[ReBars])+" ReBars= "+Text(ReBars));
Commentary("NthCon(Con,1)="+Text(NthCon(Con,1)));
Commentary("NthCon(Con,2)="+Text(NthCon(Con,2)));
Commentary("NthCon(Con,3)="+Text(NthCon(Con,3)));
Commentary("NthCon(Con,4)="+Text(NthCon(Con,4)));
Commentary("NthCon(Con,5)="+Text(NthCon(Con,5)));
End |
|