- 精华
- 0
- 在线时间
- 19 小时
- UID
- 243793
- 积分
- 13
- 帖子
- 9
- 阅读权限
- 10
- 注册时间
- 2016-11-28
- 最后登录
- 2017-11-30
- 精华
- 0
- UID
- 243793
- 积分
- 13
- 帖子
- 9
- 主题
- 4
- 阅读权限
- 10
- 注册时间
- 2016-11-28
- 最后登录
- 2017-11-30
|
Params
Numeric Para1(15);
Numeric Para2(5);
Vars
NumericSeries ma15;
NumericSeries ma5;
NumericSeries x(0);
Bool Condition1;
Bool Condition2;
Bool BuySign;
Numeric SignLength;
NumericSeries My_Sign(10000); // 买入信号 0 无信号 1有信号
NumericSeries My_Price(10000); // 买入价格 0 无价 >0 有价
NumericSeries My_Index(10000); // Bar索引
NumericSeries My_State(10000); // 买入状态 0 初始化 1 挂单 2 成交
// 数组测试 - 无数据
//NumericArray My_Sign[10000]; // 买入信号 0 无信号 1有信号
//NumericArray My_Price[10000]; // 买入价格 0 无价 >0 有价
//NumericArray My_Index[10000]; // Bar索引
//NumericArray My_State[10000]; // 买入状态 0 初始化 1 挂单 2 成交
Numeric iCount;
Numeric i;
Numeric j;
String DisplayMsg;
Begin
BuySign = false;
SignLength = 10000;
ma15 = Average(o,para1);
ma5 = Average(o,para2);
Condition1 = CrossOver(ma5,ma15);
Condition2 = CrossUnder(ma5,ma15);
if (Condition1)
{
Buy(1,Open);
x = x + 1;
BuySign = true;
}
if (Condition2)
{
Sell(1,Open);
}
if (CurrentBar == 0)
{
x = -1;
for i=0 to SignLength-1
{
My_Sign[i] = 0;
My_Price[i] = 0;
My_State[i] = 0;
My_Index[i] = -1;
PlotString("CurBars", "开始");
}
}
Else
{
if (BuySign)
{
BuySign = False;
DisplayMsg = " 买入信号次数= [ " + Text(x) + " ]" +
" 买入价格: [ " + Text(low) + " ], ";
// 不用CurrentBar
My_Sign[x] = 1;
My_State[x] = 1;
My_Index[x] = CurrentBar;
My_Price[x] = low;
PlotString("CurBar", Text(CurrentBar));
DisplayMsg = "买入信号:[ " + Text(x) + " ]" +
"My_Sign= [ " + Text(My_Sign[x]) + " ]" +
"My_State= [ " + Text(My_State[x]) + " ]" +
"My_Price= [ " + Text(My_Price[x]) + " ]" +
"My_Index= [ " + Text(My_Index[x]) + " ]" +
"CurrentBar= [ " + Text(CurrentBar) + " ]";
}
}
// 刷单成交
if (BarStatus == 2)
{
for i=0 To CurrentBar
{
if ( (My_Sign[i] == 1) And (My_State[i] == 1) and (My_Index[i]>0) )
{
My_State[i] = 2;
DisplayMsg = "信号I合乎要求:[ " + Text(i) + " ]" +
"原始索引= [ " + Text(My_Index[i]) + " ]";
FileAppend("J:\\Formula.log", DisplayMsg);
}
}
}
Commentary(DisplayMsg);
End
My_Index[i]值飘乎不定, 而且不同的TB版本, 编译出来结果都不同. 这么大的BUG,都没有发现?
|
|