Loading ...

如何定时开多单。开仓后,实时监控每一笔交易,自动止损止盈。

Author: lsgab123, Created: 2019-08-23 17:39:12, Updated:

想在每天下午14:59开多单rb2001。开仓后,实时监控交易行情,30个点止盈,15个点止损。怎么编程,请指教,谢谢!


More

lsgab123 谢谢,对于初学者很有帮助!

小小梦 ``` // 想在每天下午14:59开多单rb2001。开仓后,实时监控交易行情,30个点止盈,15个点止损。怎么编程,请指教,谢谢! var symbol = "rb2001" var IDLE = 0 var LONG = 1 var State = IDLE var HoldPrice = 0 var p = $.NewPositionManager() function main(){ while(true){ if(exchange.IO("status")){ if (!$.IsTrading(symbol)) { Sleep(1000) continue } exchange.SetContractType(symbol) var ticker = exchange.GetTicker() LogStatus(_D(), "已经连接CTP !", " State:", State, " HoldPrice:", HoldPrice) var time = new Date() var hours = time.getHours() // 0~23 var minute = time.getMinutes() // 0~59 if (State == IDLE && hours == 14 && minute == 59) { var ret = p.OpenLong(symbol, 1) HoldPrice = ret.price State = LONG } if (State == LONG && (ticker.Last > HoldPrice + 30 || ticker.Last < HoldPrice - 15)) { p.CoverAll(symbol) State = IDLE HoldPrice = 0 } } else { LogStatus(_D(), "未连接CTP !") } Sleep(1000) } } ``` 需要勾选上 「商品期货交易类库」

小小梦 这个用JS编写比较简单,就监控时间就可以,开仓了监控价格。