全部 智大领峰 TBQuant功能 TBL语言 TB开户 问答专区 高手圈 其他
图表开仓信号大于1时,实际下单只有1手,不知道问题在哪里,比如4月25日21点45分,信号是2手,结果只开了一手。附件是记录的日志文件
2023-04-26 10:13

Defs

//此处添加公式函数

Bool my_CrossUnder(Numeric grid_price) //定义下穿函数

{

If(C[1]> grid_price And L<grid_price)//上一周期收盘价大于网格,当前周期最低价小于网格

Return True;

Else

Return False;

}

Bool my_CrossOver(Numeric grid_price)//定义上穿函数

{

If(C[1]< grid_price And H>grid_price)//上一周期收盘价小于网格,当前周期最高价大于网格

Return True;

Else

Return False;

}

Events

//此处实现事件函数

//初始化事件函数,策略运行期间,首先运行且只有一次

OnInit()

{

path =\"C:\\\\For_tbQuant\";

filename = \"//\"+FormulaName+\"-\"+DateToString(CurrentDate)+\".txt\"; //生成文件名称

FileDelete(path+filename); //清空原文件

//FileAppend(path+filename,\"日期:\"+text(CurrentDate)+\",时间:\"+text(CurrentTime)); //将当前策略应用商品的每张合约包含的基本单位数量写入文件

//LogFile(\"【OnInit】\"+fu_name2);

SetInitCapital(60000000); //设置初始资金为1000万

SubscribeBar(fu_name,my_time_div,my_begin_date);

for i = 0 to 20000

{

arr[i]= mid_price -(i-1)*per_jump; //从开仓价开始逐渐计算每格网格的开仓点位,数组为从大到小排列

id[i] = i*hands ;//每个开仓位置所对应的仓位手数

if (arr[i]<=E_L_price)  //当价格小于等于落地价的时候停止循环

{Break;}

}

total_hands = GetArraySize(arr)*hands;//落地预计总开仓手数

grid_count = GetArraySize(arr); //网格数量

Print(\"落地预计总开仓手数为:\"+text(total_hands));

Print(\"落地预计总网格数量为:\"+text(grid_count));

}

OnReady()

{

price_perJump = MinMove()*PriceScale(); //计算每跳的价格

Print(\"每跳价格为:\"+text(price_perJump));

}


//Bar更新事件函数,参数indexs表示变化的数据源图层ID数组

OnBar(ArrayRef<Integer> indexs)

{

 //具体业务逻辑

KValue_forKDJ=cx_GetKvalue_KDJ;

//Commentary(\"仓位为:\"+TextArray(id));//网格较大时关闭,否则显示内容过长//////////////////////////////////////////////////////

//Commentary(\"数组为:\"+TextArray(arr));//网格较大时关闭,否则显示内容过长//////////////////////////////////////////////////////

Commentary(\"数组长度为:\"+text(GetArraySize(arr)));

Commentary(\"当前K值为:\"+text(KValue_forKDJ));


for i = 0 to GetArraySize(arr)-1  //对数组进行逆序排列

{

arr_re[i] = arr[GetArraySize(arr)-1-i];//数组为从小到大排列

id_re[i ]= id[GetArraySize(id)-1-i];

}

//Commentary(\"逆序仓位为:\"+TextArray(id_re));//网格较大时关闭,否则显示内容过长//////////////////////////////////////////////////////

//Commentary(\"逆序数组为:\"+TextArray(arr_re));//网格较大时关闭,否则显示内容过长//////////////////////////////////////////////////////

for i = 0 to GetArraySize(arr_re)-1 //头寸处理

{

//if(my_CrossUnder(arr_re[i]) And KValue_forKDJ<My_Kvalue_s )//如果下穿网格且K值小于阈值//////////////////////////////////////////////////////////

if(my_CrossUnder(arr_re[i]) )  //如果下穿网格 //////////////////////////////////////////////////////////

{

my_plt.icon(\"icon1\",L-0.5,\"xiaolian\");

my_hold = id_re[i];

Commentary(\"----下破:\"+Text(arr_re[i])+\"。理论仓位应为:\"+text(id_re[i]));//判断头寸并处理头寸

//Buy(1,Max(O,arr_re[i]);

open_hands = id_re[i]-CurrentContracts();

If(CurrentContracts()==id_re[i]  Or open_hands<=0 )  //如果仓位无需调整终止循环

{

Break;

}

Else

{

FileAppend(path+filename,\"开仓前@@@日期:\"+text(CurrentDate)+\",时间:\"+text(CurrentTime)+\",拟开仓手数为:\"+text(open_hands)+\"网格对应仓位为:\"+text(id_re[i])+\"当前净持仓为:\"+text(CurrentContracts())); //将当前策略应用商品的每张合约包含的基本单位数量写入文件

Buy(open_hands,min(O,arr_re[i])+price_perJump); //以开盘价和网格价中的最高价开仓

FileAppend(path+filename,\"开仓后***日期:\"+text(CurrentDate)+\",时间:\"+text(CurrentTime)+\",拟开仓手数为:\"+text(open_hands)+\"网格对应仓位为:\"+text(id_re[i])+\"当前净持仓为:\"+text(CurrentContracts())); //将当前策略应用商品的每张合约包含的基本单位数量写入文件

Print(text(Date)+Text(Time)+\"开仓手数为:\"+text(open_hands)+\"网格对应仓位为:\"+text(id_re[i])+\"当前净持仓为:\"+text(CurrentContracts()));

Commentary(\"Debug,开仓手数为:\"+text(open_hands));

Commentary(\"Debug,网格对应仓位为:\"+text(id_re[i]));

Commentary(\"Debug,当前净持仓为:\"+text(CurrentContracts()));

Break;

}

}

    //if(my_CrossOver(arr_re[i])And (BarsSinceLastEntry>0) And KValue_forKDJ>(100 -My_Kvalue_s) )//如果上穿网格且为非开仓bar且K值满足条件///////////////////////////////////

if(my_CrossOver(arr_re[i])And (BarsSinceLastEntry>0))//如果上穿网格且为非开仓bar且K值满足条件///////////////////////////////////

{

my_plt.icon(\"icon2\",H+0.5,\"kulian\");

my_hold = id_re[i];

Commentary(\"----上破:\"+Text(arr_re[i])+\"。理论仓位应为:\"+text(id_re[i]));//判断头寸并处理头寸

//Buy(1,Max(O,arr_re[i]);

If(CurrentContracts()==id_re[i])

{

Break;

}

Else

{

open_hands = CurrentContracts()-id_re[i];

Sell(open_hands,Max(O,arr_re[i])-price_perJump); //以开盘价和网格价中的最小价开仓

Break;

}

}

}

Commentary(\"当前持仓为:\"+text(CurrentContracts()));

Commentary(\"当前可用资金:\"+text(Portfolio_CurrentCapital()));


}

wangkaiming

根据自己的日志,逐步调试

比如你说图表2手 ,实际一手

你先要证明你是对的

2023-04-27 09:01
changsin2000
@wangkaiming

你说了等于没有说

2023-04-27 11:19
wangkaiming
@changsin2000

如果需要帮助调试,请提供更详细的设置内容

也可以说明具体执行到哪里有问题

2023-04-27 13:25
您未登录,请先 登录注册 后发表评论
顶部