def mp(): positions = exchange.Getposition() if len(positions) == 0: return 0 for i in range(len(positions)): if (positions[i][‘Type’] == PD_LONG) or (positions[i][‘Type’] == PD_LONG_YD): return 1 elif (positions[i][‘Type’] == PD_SHORT) or (positions[i][‘Type’] == PD_SHORT_YD): return -1 def main(): exchange.SetContractType(“MA109”) while True: records=exchange.GetRecords() if len(records) < 50: continue close = records[len(records) - 1].close positions = mp() upper = TA.Highest(records, 50, ‘High’) lower = TA.Lowest(records, 50, ‘Low’) 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.0penlong(“MA109”,1) elif close < lower: obj.0penshort(“MA109”,1)
小草 托管者所在服务器需要安装python