1分钟图形下计算30分钟ATR的程序
- 新建用户函数TransMinsData,返回值为数值型,代码如下:
Params
NumericSeries Price(1);
Numeric nMinSet(5);
Numeric MinsAgo(2);
Vars
NumericSeries barCnt;
NumericSeries MinData;
Numeric i;
Numeric j;
Numeric nIndex(0);
Begin
If(IntPart(Minute%nMinSet)==0)
{
barCnt = 1;
}Else
{
barCnt = barCnt[1] + 1;
}
MinData = Price;
If(MinsAgo == 0)
{
return MinData;
}Else
{
For i = 1 To MinsAgo
{
If( i == 1)
{
j = 0;
}Else
{
j = j + BarCnt[j];
}
If (j > CurrentBar ) Return InvalidNumeric;
nIndex = nIndex + BarCnt[j];
}
Return MinData[nIndex];
}
End
- 新建技术指标,命名为My30MinsATR,代码如下:
Params
Numeric Length(10);
Vars
NumericSeries MyClose;
NumericSeries MyHigh;
NumericSeries MyLow;
Numeric AvgTrueHigh;
Numeric AvgTrueLow;
Numeric SumValue(0);
Numeric Value1;
Numeric i;
Begin
MyClose = DataConvert(Close,"min",30,"Close");
MyHigh = DataConvert(High,"min",30,"High");
MyLow = DataConvert(Low,"min",30,"Low");
For i = Length-1 DownTo 0
{
Value1 = Max(TransMinsData(MyClose,30,i+1),TransMinData(MyHigh,30,i));
SumValue = SumValue + Value1;
}
AvgTrueHigh = SumValue/Length;
SumValue = 0;
For i = Length-1 DownTo 0
{
Value1 = Min(TransMinsData(MyClose,30,i+1),TransMinData(MyLow,30,i));
SumValue = SumValue + Value1;
}
AvgTrueLow = SumValue/Length;
PlotNumeric("My30MinATR",AvgTrueHigh-AvgTrueLow);
End
- 在使用时需根据参数设置合适数量的分钟线,另外,该函数因为用到了循环语句,如果周期参数设置太大,计算时会比较慢。
程序化交易, TradeBlazer, 跨周期,
风险提示及免责条款
市场有风险,投资需谨慎。本文不构成个人投资建议,也未考虑到个别用户特殊的投资目标、财务状况或需要。用户应考虑本文中的任何意见、观点或结论是否符合其特定状况。据此投资,责任自负。本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处。如若内容有涉嫌抄袭侵权/违法违规/事实不符,请点击 举报 进行投诉反馈!