def main() exchange.SetContractType("rb888") # 设置品种代码 while True: # 进入循环 records = exchange.GetRecords() # 获取K线数组 upper = TA.Highest(records, 50, 'High') # 获取50周期最高价的最大值 lower = TA.Lowest(records, 50, 'Low') # 获取50周期最低价的最小值 middle = (upper + lower) / 2 # 计算上轨和下轨的均值 Log("上轨", upper) # 把上轨的值打印到日志中 Log("下轨", lower) # 把上轨的值打印到日志中 Log("中轨", middle) # 把上轨的值打印到日志中
def main():
while true:
obj = ext.NewPositionManager() # 使用交易类库
# 这里写策略逻辑和下单代码
def main():
exchange.SetContractType("rb888")
while true:
records = exchange.GetRecords() # 获取K线数组
if len(records) < 50:
continue # 跳过本次循环
close = records[len(records)-1].Close # 获取最新K线收盘价
def mp():
positions = exchange.GetPosition() # 获取持仓数据
if len(positions) == 0:
return 0 # 空仓,返回 0
for i in range(len(positions)): # 遍历持仓数组
if (positions[i]['Type'] == PD_LONG) ro (positions[i]['Type'] == PD_LONG_YD):
return 1
elif (positions[i]['Type'] == PD_SHORT) ro (positions[i]['Type'] == PD_SHORT_YD):
return -1
def main():
exchange.SetContractType("rb888")
while True:
records = exchange.GetRecords()
if len(records) < 50:
continue
close = records[len(records)-1].Close
positions = mp() # 获取持仓信息
def mp():
positions = exchange.GetPosition() # 获取持仓数据
if len(positions) == 0:
return 0 # 空仓,返回 0
for i in range(len(positions)): # 遍历持仓数组
if (positions[i]['Type'] == PD_LONG) ro (positions[i]['Type'] == PD_LONG_YD):
return 1
elif (positions[i]['Type'] == PD_SHORT) ro (positions[i]['Type'] == PD_SHORT_YD):
return -1
def main():
exchange.SetContractType("rb888")
while True:
records = exchange.GetRecords()
if len(records) < 50:
continue
close = records[len(records)-1].Close
positions = mp() # 获取持仓信息
upper = TA.Highest(records, 50,'High') # 获取50周期最高价的最大值
lower = TA.Lowest(records, 50, 'Low') # 获取50周期最低价的最小值
middle = (upper + lower) / 2 # 计算上轨和下轨的均值
def mp():
positions = exchange.GetPosition() # 获取持仓数据
if len(positions) == 0:
return 0 # 空仓,返回 0
for i in range(len(positions)): # 遍历持仓数组
if (positions[i]['Type'] == PD_LONG) ro (positions[i]['Type'] == PD_LONG_YD):
return 1
elif (positions[i]['Type'] == PD_SHORT) ro (positions[i]['Type'] == PD_SHORT_YD):
return -1
def main():
exchange.SetContractType("rb888")
while True:
records = exchange.GetRecords()
if len(records) < 50:
continue
close = records[len(records)-1].Close
positions = mp() # 获取持仓信息
upper = TA.Highest(records, 50,'High') # 获取50周期最高价的最大值
lower = TA.Lowest(records, 50, 'Low') # 获取50周期最低价的最小值
middle = (upper + lower) / 2 # 计算上轨和下轨的均值
obj = ext.NewPositionManager() # 使用交易类库
if positions > 0 and close < middle: # 如果持多单,且收盘价跌破中轨
obj.CoverAll() # 平掉所有仓位
if positions < 0 and close > middle: # 如果持空单,且收盘价升破中轨
obj.CoverAll() # 平掉所有仓位
if positions == 0:
if close > upper: # 收盘价升破上轨
obj.OpenLong("rb888",1) # 买开
if close < lower: # 收盘价跌破下轨
obj.OpenShort("rb888",1) # 卖开