- 精华
- 0
- 在线时间
- 12 小时
- UID
- 289823
- 积分
- 3
- 帖子
- 2
- 阅读权限
- 10
- 注册时间
- 2020-3-17
- 最后登录
- 2021-5-18
- 精华
- 0
- UID
- 289823
- 积分
- 3
- 帖子
- 2
- 主题
- 1
- 阅读权限
- 10
- 注册时间
- 2020-3-17
- 最后登录
- 2021-5-18
|
Params
//此处添加参数
String sym("rb2110.SHFE"); // 交易品种
Numeric gridstartprice(5600);// 网格起始价格
Integer gridstep(10); // 网格大小
Integer gridlength(10); // 网格格数
Integer bs(1); // 交易方向 ,1 多,-1 空
Vars
//此处添加变量
Numeric avg;
Global Integer timerId;
Series <Numeric> i;
Series <Numeric> flag;
Series <Numeric> curgridprice;
Series <Numeric> tpprice;
Series <Numeric> reprice;
Array<Integer> orderIds;
Events
//此处实现事件函数
//Bar更新事件函数,参数indexs表示变化的数据源图层ID数组
OnBar(ArrayRef<Integer> indexs)
{
If(AccountDataExist() And IsTradingTime(SystemDateTime) And flag==0 And A_BuyPosition<11)
{
Commentary("flag="+Text(flag));
For i = 1 To gridlength
{
curgridprice = gridstartprice-(i-1)*gridstep;
If(A_SendOrderEx(Enum_Buy,Enum_Entry,1,curgridprice,orderIDs))
{
flag=1;
//FileAppend
}
}
}
}
//成交更新事件函数,参数ordFill表示更新的成交结构体
OnFill(FillRef ordFill)
{
// 如果开仓挂单成交了,则挂止盈单
If(ordFill.combOffset==Enum_Entry)
{
tpprice= ordfill.price + gridstep;
A_SendOrderEx(ordFill.symbol,Enum_Sell,Enum_Exit,1,tpprice,orderIds);
}
Else
{
reprice=ordfill.price - gridstep; // 止盈单成交,继续按照原价挂单
A_SendOrderEx(ordFill.symbol,Enum_Buy,Enum_Entry,1,reprice,orderIDs);
}
}
|
|