求助死循环 [开拓者 TB]
- 咨询内容: 我的用户函数:
// 简称: NthCrossUpMAHighOverBarPos
// 名称: 回溯第N个上缠绕MA顶值、收过MABar索引值
// 类别: 用户函数
// 类型: 用户函数
// 输出: 数值型
//------------------------------------------------------------------------
Params
Numeric N(0);
Numeric Length(0);
NumericRef CrossUpMAOverBarPos;
Vars
Numeric ReBarsCrossOverMA(0);
Numeric ReBarsCrossOverMAplus(0);
Numeric ReBarsCrossUnderMA(0);
Numeric i;
Numeric CrossUpMAHigh;
Begin
ReBarsCrossOverMA=NthCon(CrossOver(C,AverageFC(C,Length)),N);
ReBarsCrossOverMAplus=NthCon(CrossOver(C,AverageFC(C,Length)),N+1);
ReBarsCrossUnderMA=NthCon(CrossUnder(C,AverageFC(C,Length)),N);
If ((ReBarsCrossOverMA<ReBarsCrossUnderMA)&&((CurrentBar-ReBarsCrossOverMAplus)>(Length-1)))
{
For i=ReBarsCrossOverMAplus DownTo ReBarsCrossUnderMA
{
If (H[i] > CrossUpMAHigh)
CrossUpMAHigh = H[i];
}
CrossUpMAOverBarPos=CurrentBar-ReBarsCrossOverMAplus;
}
Return CrossUpMAHigh;
End
//------------------------------------------------------------------------
我的公式应用:
// 简称: TproNthCrossUpMAHighOverBarPos
// 名称: 验证回溯递增第N个上缠绕MA顶值、收过MABar索引值
// 类别: 公式应用
// 类型: 用户应用
// 输出:
//------------------------------------------------------------------------
Params
Numeric N(2);
Numeric Length(5);
Vars
Numeric CrossUpMAHigh;
Numeric CrossUpMAOverBarPos;
Numeric i;
Numeric j;
Numeric MyHigh;
Numeric MyBarPos;
Begin
i=2;
j=1;
CrossUpMAHigh=NthCrossUpMAHighOverBarPos(1,Length,CrossUpMAOverBarPos);
MyBarPos=CrossUpMAOverBarPos;
While ((j<N)&&(MyBarPos>0))
{MyHigh=NthCrossUpMAHighOverBarPos(i,Length,CrossUpMAOverBarPos);
MyBarPos=CrossUpMAOverBarPos;
i=i+1;
If (MyHigh>CrossUpMAHigh)
{CrossUpMAHigh=MyHigh;
j=j+1;
}
}
If (MyBarPos==0)
{CrossUpMAHigh=0;
}
Commentary("回溯递增第"+Text(N)+"个上缠绕MA顶值"+Text(CrossUpMAHigh));
Commentary("回溯递增第"+Text(N)+"个上缠绕MA收过MABar索引值"+Text(MyBarPos));
End
//------------------------------------------------------------------------
上述公式应用插入超级图表,出现死循环,请教TB老师解决办法,多谢! - TB技术人员: 应TB工程师的要求,发了上面的帖子,通了4次电话,过了4个小时,仍没有回复,TB服务太差了!如果不想解决,为何要我发帖干等?
- TB客服: 用户函数那 N的值应要大于等于1的自然数, 您初始付的值为0
- 网友回复: 本帖最后由 wwr_5817 于 2012-12-19 15:05 编辑
多谢LZ,LZ实在是高!不死循环了!可结果在N>1时恒为0,可否再指点指点? - 网友回复:
请管理员tradeblazer继续解答我的问题!
我的用户函数:
// 简称: NthCrossUpMAHighOverBarPos
// 名称: 回溯第N个上缠绕MA顶值、收过MABar索引值
// 类别: 用户函数
// 类型: 用户函数
// 输出: 数值型
//------------------------------------------------------------------------
Params
Numeric N(1);
Numeric Length(5);
NumericRef CrossUpMAOverBarPos;
Vars
Numeric ReBarsCrossOverMA(0);
Numeric ReBarsCrossOverMAplus(0);
Numeric ReBarsCrossUnderMA(0);
Numeric i;
Numeric CrossUpMAHigh;
Begin
ReBarsCrossOverMA=NthCon(CrossOver(C,AverageFC(C,Length)),N);
ReBarsCrossOverMAplus=NthCon(CrossOver(C,AverageFC(C,Length)),N+1);
ReBarsCrossUnderMA=NthCon(CrossUnder(C,AverageFC(C,Length)),N);
If ((ReBarsCrossOverMA<ReBarsCrossUnderMA)&&((CurrentBar-ReBarsCrossOverMAplus)>(Length-1)))
{
For i=ReBarsCrossOverMAplus DownTo ReBarsCrossUnderMA
{
If (H[i] > CrossUpMAHigh)
CrossUpMAHigh = H[i];
}
CrossUpMAOverBarPos=CurrentBar-ReBarsCrossOverMAplus;
}
Return CrossUpMAHigh;
End
//------------------------------------------------------------------------
我的公式应用1:
/ 简称: TproNthCrossUpMAHighOverBarPos
// 名称: 验证回溯递增第N个上缠绕MA顶值、收过MABar索引值
// 类别: 公式应用
// 类型: 用户应用
// 输出:
//------------------------------------------------------------------------
Params
Numeric N(2);
Numeric Length(5);
Vars
Numeric CrossUpMAHigh;
Numeric CrossUpMAOverBarPos;
Numeric i;
Numeric j;
Numeric MyHigh;
Numeric MyBarPos;
Begin
i=2;
j=1;
CrossUpMAHigh=NthCrossUpMAHighOverBarPos(1,Length,CrossUpMAOverBarPos);
MyBarPos=CrossUpMAOverBarPos;
Commentary("While前CrossUpMAHigh="+Text(CrossUpMAHigh));
Commentary("While前MyBarPos="+Text(MyBarPos));
Commentary("While前j="+Text(j));
Commentary("While前N="+Text(N));
While ((j<N)&&(MyBarPos>0))
{Commentary("While中调用户函数前i="+Text(i));
Commentary("While中调用户函数前j="+Text(j));
Commentary("While中调用户函数前MyBarPos="+Text(MyBarPos));
Commentary("While中调用户函数前MyHigh="+Text(MyHigh));
MyHigh=NthCrossUpMAHighOverBarPos(i,Length,CrossUpMAOverBarPos);
Commentary("While中NthCrossUpMAHighOverBarPos(i,Length,CrossUpMAOverBarPos)="+Text(NthCrossUpMAHighOverBarPos(i,Length,CrossUpMAOverBarPos)));
Commentary("While中CrossUpMAOverBarPos="+Text(CrossUpMAOverBarPos));
MyBarPos=CrossUpMAOverBarPos;
Commentary("While中i+1前i="+Text(i));
Commentary("While中i+1前MyBarPos="+Text(MyBarPos));
Commentary("While中i+1前MyHigh="+Text(MyHigh));
i=i+1;
Commentary("While中i="+Text(i));
Commentary("While中MyBarPos="+Text(MyBarPos));
Commentary("While中MyHigh="+Text(MyHigh));
Commentary("While中CrossUpMAHigh="+Text(CrossUpMAHigh));
If (MyHigh>CrossUpMAHigh)
{CrossUpMAHigh=MyHigh;
j=j+1;
Commentary("While中j="+Text(j));
Commentary("While中MyBarPos="+Text(MyBarPos));
Commentary("While中CrossUpMAHigh="+Text(CrossUpMAHigh));
}
}
If (MyBarPos==0)
{CrossUpMAHigh=0;
}
Commentary("回溯递增第"+Text(N)+"个上缠绕MA顶值"+Text(CrossUpMAHigh));
Commentary("回溯递增第"+Text(N)+"个上缠绕MA收过MABar索引值"+Text(MyBarPos));
End
//------------------------------------------------------------------------
我的公式应用2:
// 简称: TNthCrossUpMAHighOverBarPos
// 名称: 验证回溯第N个上缠绕MA顶值、收过MABar索引值
// 类别: 公式应用
// 类型: 用户应用
// 输出:
//------------------------------------------------------------------------
Params
Numeric N(2);
Numeric Length(5);
Vars
Numeric CrossUpMAHigh;
Numeric CrossUpMAOverBarPos;
Begin
CrossUpMAHigh=NthCrossUpMAHighOverBarPos(N,Length,CrossUpMAOverBarPos);
Commentary("回溯第"+Text(N)+"个上缠绕MA顶值"+Text(CrossUpMAHigh));
Commentary("回溯第"+Text(N)+"个上缠绕MA收过MABar索引值"+Text(CrossUpMAOverBarPos));
End
//------------------------------------------------------------------------
您于3楼的答复,我在1楼的公式应用不死循环了,但其结果在N=2时恒为0。用公式应用2验证,我的用户函数NthCrossUpMAHighOverBarPos(2,5,CrossUpMAOverBarPos)正确,但在1楼的公式应用中加入Commentary语句的公式应用1中While内首次调用NthCrossUpMAHighOverBarPos(2,5,CrossUpMAOverBarPos)结果为0,不知何故?公式应用1中While行后第二行插入“Commentary("While中调用户函数前j="+Text(j));”,再次陷入死循环!现在,用本层的用户函数和1楼的公式应用仍然死循环!
另外,您于3楼的答复是否表明,用户自编用户函数中调用(系统自带用户函数)时,用户自编用户函数的参数默认值须不小于(系统自带用户函数)的参数默认值?
切盼尽快指教!多谢!
有思路,想编写各种指标公式,程序化交易模型,选股公式,预警公式的朋友
可联系技术人员 QQ: 262069696 进行 有偿 编写!(不贵!点击查看价格!)
相关文章
-
没有相关内容