我试了两种exit的方式,一种是直接在开单时挂进去,代码如下,回测图一
if strategy.position_size >= 0 and Trend < 0 and TCI_bear
strategy.entry("SHORT", strategy.short, qty= rolling == true ? roll_size : size, comment='OP-S@')
strategy.exit("CL-S", "SHORT", xxxxxx)
state := -1
trading_1:=0
另一种是入场后采用查找订单的方式exit,代码如下(奇怪的是用这种方式exit直接不起作用了(回测图二),查找订单的函数是直接从文章里复制的)
if barstate.isrealtime and findOrderIdx("SHORT") >= 0 and state == -1
state := 0
strategy.exit("CL-S", "SHORT", xxxxxx) /upload/asset/1656cda7ac73bb62bc54e.png /upload/asset/16596c76416af7cde208b.png
还有一点,不知道为什么同一信号连续开了3次,代码如下
if trading_1 == 0 and Trend == -1 and TCI_bear and strategy.position_size < 0
strategy.entry("IP-S1", strategy.short, qty=size)
trading_1 := -1
梦总帮忙看一下是怎么回事
2022-12-07 15:25:11
发明者量化-小小梦
这个和具体策略设计有关,要看策略具体分析。
2022-12-07 13:15:15
Issac
Futures_OP 4: 400: {"code":"50000","data":[],"msg":"Body can not be empty."} 显示下单异常是什么意思啊 看了教程感觉设置的对啊
2022-11-28 22:05:32
发明者量化-小小梦
您好,这个具体是哪个交易所,IO调用的代码,可以把具体场景发一下工单。
2022-11-29 09:05:38
xaifer48
py 支持sympy库这个么?好像用不了@小小梦
2022-11-03 20:56:11
xaifer48
好滴,谢谢
2022-11-04 15:00:03
发明者量化-小小梦
建议使用私有托管者,在自己的设备上安装需要用的python库。
2022-11-04 13:49:16
xaifer48
公用托管者可以么?我试了好像不支持sympy这个库,是直接写import sympy这样吧?
2022-11-04 11:56:05
发明者量化-小小梦
您好,任何python库都可以导入的,需要在托管者所在设备系统的python环境安装这个库。
2022-11-04 09:27:24
xowox
充值
2022-09-14 16:58:17
发明者量化-小小梦
您好,这个具体问题是?
2022-09-14 17:03:56
yingjun
Buy(-1, 6): 400: {"code":-2022,"msg":"ReduceOnly Order is rejected."} 这是什么错误
2022-03-30 16:08:33
发明者量化-小小梦
可能是下单方向不对,检查一下SetDirection()函数的参数设置。
2022-03-30 16:20:54
DXM
time out
2022-03-24 08:17:09
发明者量化-小小梦
It`s a problem with your device network. Try to change other device such as VPS in Singapore or England.
Traceback (most recent call last): File "<string>", line 1615, in Run File "<string>", line 146, in <module> File "<string>", line 138, in main File "<string>", line 115, in trace KeyError: 43999.96000000001
不行啊,访问出来的只有多仓的数据,没有空仓的数据,源码
var n = 0.005 //初始下单数
var MarginLevel = 20 //合约杠杆
function main() {
exchange.SetContractType("swap")
exchange.SetMarginLevel(MarginLevel)
var position = []
while (true) {
var account = exchange.GetAccount()
position = exchange.GetPosition()
if (position.length == 0) {
exchange.SetDirection("sell")
exchange.Sell(-1, n, "开空", "倍率参数:", q = 1, "账户总额:", account.Balance)
exchange.SetDirection("buy")
exchange.Buy(-1, n, "开多", "倍率参数:", x = 1, "账户总额:", account.Balance)
}
if (position.length > 0) {
Log(position[0])
Sleep(12000)
}
}
}