- 策略广场
- 均线突破法
均线突破法
Author:
量价时空, Date: 2020-07-09 20:39:37
Tags:
突破
/*backtest
start: 2020-06-18 09:00:00
end: 2020-07-08 15:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES","balance":200000}]
*/
void main() {
Sleep(10000);
Log(exchange.GetAccount());
while (1) {
if (exchange.IO("status") == 1) {
exchange.SetContractType(Symbol);
auto r = exchange.GetRecords(60);
auto ma = TA.MA(r, 20);
// Log(ma[ma.size() - 1]);
auto records = exchange.GetRecords(60 * 3);
auto ticker = exchange.GetTicker();
auto position = exchange.GetPosition();
auto orders = exchange.GetOrders();
if (position.size() > 0 && !(orders.size() > 0)) {
if (!position[0].Type) {
if (position[0].Profit > z || position[0].Profit < -k) {
exchange.SetContractType(Symbol);
exchange.SetDirection("closebuy_today");
exchange.Sell(ticker.Buy - 100, 1);
Sleep(500);
}
}
if (position[0].Type) {
if (position[0].Profit > z || position[0].Profit < -k) {
exchange.SetContractType(Symbol);
exchange.SetDirection("closesell_today");
exchange.Buy(ticker.Sell + 100, 1);
Sleep(500);
}
}
} else {
auto r = exchange.GetRecords(60*q);
auto ma = TA.MA(r, 20);
auto a = ma[ma.size() - 1];
auto r1 = exchange.GetRecords(60*q);
auto ma1 = TA.MA(r1, 120);
auto c = ma1[ma1.size() - 1];
if (a < c && records[records.size() - 1].High > ma[ma.size() - 1] && ticker.Buy < ma[ma.size() - 1]) {
exchange.SetContractType(Symbol);
exchange.SetDirection("sell");
exchange.Sell((ticker.Sell - 1000), 1);
Sleep(500);
}else if (a > c && records[records.size() - 1].Low < ma[ma.size() - 1] && ticker.Sell > ma[ma.size() - 1]) {
exchange.SetContractType(Symbol);
exchange.SetDirection("buy");
exchange.Buy((ticker.Buy + 1000), 1);
Sleep(500);
}
}
} else {
LogStatus(_D(), "未连接CTP !");
Sleep(1000);
}
Sleep(500);
}
}
相关内容
更多内容