等级: 新手上路
- 注册:
- 2024-6-4
- 曾用名:
|
交易代码要求;1,采用15分钟图表,用10日均线为参考,k线在10日均线上方做多,在10日均线下方做空。2,初始买入2手,止盈止损5跳。3,当止赢后,同时继续买入2手,继续止赢继续买入2手,当止损后就同时买入3手,如果连续止损,就继续买入3手,当从止损那一手开始计算到每次买如3手结束,胜率需达到50%,然后又从2手开始买入。试例[+2+2+2(-2-3-3+3+3-3+3+3计算胜率需达到50%)+2]。4,每次买入前都需平掉全部仓位。
average_price := 0;
ss := 2;
// 获取 15 分钟图表的 10 日均线
ma10 := MA(C, 10);
// 定义模拟 len 功能的函数
function len(listVariable) {
let count = 0; // 初始化计数变量为 0
for (let item of listVariable) {
count++; // 每遍历一个元素,计数加一
}
return count; // 返回列表中元素的数量
}
// 平空止盈
IF (average_price - C > 5 * MINDIFF) AND HOLDING < 0 THEN
BEGIN
SELLSHORT(2, HOLDING, marketr);
ss := 2;
average_price := 0;
END
// 平空止损
IF (C - average_price > 4 * MINDIFF) AND HOLDING < 0 THEN
BEGIN
SELLSHORT(2, HOLDING, marketr);
ss := 2;
average_price := 0;
END
// 平多止盈
IF (C - average_price > 5 * MINDIFF) AND HOLDING > 0 THEN
BEGIN
SELL(2, HOLDING, marketr);
ss := 2;
average_price := 0;
END
// 平多止损
IF (average_price - C > 4 * MINDIFF) AND HOLDING > 0 THEN
BEGIN
SELL(2, HOLDING, marketr);
ss := 2;
average_price := 0;
END
// 做多条件及操作
IF C > ma10 THEN
BEGIN
// 如果有空仓,则先平空
IF HOLDING < 0 THEN
BEGIN
SELLSHORT(abs(HOLDING), HOLDING, marketr);
ss := 2;
average_price := 0;
END
// 买入开仓
BUY(2, ss, marketr);
average_price := C;
IF ss = 3 AND HOLDING > 0 THEN
ss := 2;
END
// 做空条件及操作
IF C < ma10 THEN
BEGIN
// 如果有多仓,则先平多
IF HOLDING > 0 THEN
BEGIN
SELL(HOLDING, HOLDING, marketr);
ss := 2;
average_price := 0;
END
// 卖空开仓
BUYSHORT(2, ss, marketr);
average_price := C;
IF ss = 3 AND HOLDING < 0 THEN
ss := 2;
END
// 胜率计算及手数调整
// 假设 winning_trades 和 losing_trades 是记录盈利和亏损交易的全局变量
total_trades := len(winning_trades) + len(losing_trades);
IF total_trades > 0 AND len(winning_trades) / total_trades < 0.5 AND HOLDING < 0 THEN
BEGIN
IF ss = 2 THEN
ss := 3;
END
IF total_trades > 0 AND len(winning_trades) / total_trades >= 0.5 AND HOLDING < 0 THEN
BEGIN
ss := 2;
END
IF total_trades > 0 AND len(winning_trades) / total_trades < 0.5 AND HOLDING > 0 THEN
BEGIN
IF ss = 2 THEN
ss := 3;
END
IF total_trades > 0 AND len(winning_trades) / total_trades >= 0.5 AND HOLDING > 0 THEN
BEGIN
ss := 2;
END
|
|