var account_rights=account.Info.info[ok_future_target].account_rights;//账户权益
var keep_deposit=account.Info.info[ok_future_target].keep_deposit;//保证金
var profit_real=account.Info.info[ok_future_target].profit_real;//已实现盈亏
var profit_unreal=account.Info.info[ok_future_target].profit_unreal;//未实现盈亏
var risk_rate=(keep_deposit===0?1000000:(account_rights/keep_deposit));//account.Info.info[ok_future_target].risk_rate;//保证金率 10倍杠杆,当保证金率小于等于10%,才会触发爆仓线;20倍杠杆,当保证金率小于等于20%,才会触发爆仓线。 这意味着如果您开10倍LTC合约,当您的亏损达到开仓保证金的90%时,会触发爆仓线;若开20倍杠杆的合约,当您的亏损达到开仓保证金的80%时,才会触发爆仓线。
var tw_atr = TA.ATR(tw_records, N_knumber);
var nw_atr = TA.ATR(nw_records, N_knumber);
var qt_atr = TA.ATR(qt_records, N_knumber);
if (tw_atr.length<=1 || nw_atr.length<=1 || qt_atr.length<=1){
Log("atr.length无效,跳过此次执行...");
Sleep(wait_ms);
continue;
}
var tw_N=tw_atr[tw_atr.length-1];
var nw_N=nw_atr[nw_atr.length-1];
var qt_N=tw_atr[qt_atr.length-1];
var tw_ema7=TA.EMA(tw_records,7);
var nw_ema7=TA.EMA(nw_records,7);
var qt_ema7=TA.EMA(qt_records,7);
var tw_ema30=TA.EMA(tw_records,30);
var nw_ema30=TA.EMA(nw_records,30);
var qt_ema30=TA.EMA(qt_records,30);
if (tw_ema7.length<=5||tw_ema30.length<=5||nw_ema7.length<=5||nw_ema30.length<=5||qt_ema7.length<=5||qt_ema30.length<=5){
Log("ema无效,跳过此次执行...");
Sleep(wait_ms);
continue;
}
var tw_ema_buyduo=false;
var tw_ema_sellduo=false;
if (tw_ema7[tw_ema7.length-2]>tw_ema30[tw_ema30.length-2] &&
if (tw_zuoduo_zhangshu>0 && tw_buy1>tw_buy1_highest){
tw_buy1_highest=tw_buy1;
}
if (tw_zuokong_zhangshu>0 && tw_sell1<tw_sell1_lowest){
tw_sell1_lowest=tw_sell1;
}
if (nw_zuoduo_zhangshu>0 && nw_buy1>nw_buy1_highest){
nw_buy1_highest=nw_buy1;
}
if (nw_zuokong_zhangshu>0 && nw_sell1<nw_sell1_lowest){
nw_sell1_lowest=nw_sell1;
}
if (qt_zuoduo_zhangshu>0 && qt_buy1>qt_buy1_highest){
qt_buy1_highest=qt_buy1;
}
if (qt_zuokong_zhangshu>0 && qt_sell1<qt_sell1_lowest){
qt_sell1_lowest=qt_sell1;
}
if (tw_zuoduo_zhangshu===0){
tw_buy1_highest=0;
}
if (tw_zuokong_zhangshu===0){
tw_sell1_lowest=100000;
}
if (nw_zuoduo_zhangshu===0){
nw_buy1_highest=0;
}
if (nw_zuokong_zhangshu===0){
nw_sell1_lowest=100000;
}
if (qt_zuoduo_zhangshu===0){
qt_buy1_highest=0;
}
if (qt_zuokong_zhangshu===0){
qt_sell1_lowest=100000;
}
var trade_unit=(account_rights*(10/keep_risk_rate)/trade_unit_div)*((tw_buy1+tw_sell1+nw_buy1+nw_sell1+qt_buy1+qt_sell1)/6)/contract_min[$.get_exchange_id(exchange)];
//开仓
if (tw_zuoduo_zhangshu===0 && tw_ema_buyduo && risk_rate>keep_risk_rate && account.Stocks>0){
exchange.SetContractType("this_week");
exchange.SetDirection("buy");
var dealamount=$.perform_limited_order("buy",exchange,tw_sell1,trade_unit,false,"futures","buy");
tw_buy1_highest=tw_buy1;
if (push_notification){
Log("已完成当周做多"+trade_unit+'张'+'@');
}
}
else if (tw_zuokong_zhangshu===0 && tw_ema_buykong && risk_rate>keep_risk_rate && account.Stocks>0){
exchange.SetContractType("this_week");
exchange.SetDirection("sell");
var dealamount=$.perform_limited_order("sell",exchange,tw_buy1,trade_unit,false,"futures","sell");
tw_sell1_lowest=tw_sell1;
if (push_notification){
Log("已完成当周做空"+trade_unit+'张'+'@');
}
}
else if (nw_zuoduo_zhangshu===0 && nw_ema_buyduo && risk_rate>keep_risk_rate && account.Stocks>0){
exchange.SetContractType("next_week");
exchange.SetDirection("buy");
var dealamount=$.perform_limited_order("buy",exchange,nw_sell1,trade_unit,false,"futures","buy");
nw_buy1_highest=nw_buy1;
if (push_notification){
Log("已完成次周做多"+trade_unit+'张'+'@');
}
}
else if (nw_zuokong_zhangshu===0 && nw_ema_buykong && risk_rate>keep_risk_rate && account.Stocks>0){
exchange.SetContractType("next_week");
exchange.SetDirection("sell");
var dealamount=$.perform_limited_order("sell",exchange,nw_buy1,trade_unit,false,"futures","sell");
nw_sell1_lowest=nw_sell1;
if (push_notification){
Log("已完成次周做空"+trade_unit+'张'+'@');
}
}
else if (qt_zuoduo_zhangshu===0 && qt_ema_buyduo && risk_rate>keep_risk_rate && account.Stocks>0){
exchange.SetContractType("quarter");
exchange.SetDirection("buy");
var dealamount=$.perform_limited_order("buy",exchange,qt_sell1,trade_unit,false,"futures","buy");
qt_buy1_highest=qt_buy1;
if (push_notification){
Log("已完成季度做多"+trade_unit+'张'+'@');
}
}
else if (qt_zuokong_zhangshu===0 && qt_ema_buykong && risk_rate>keep_risk_rate && account.Stocks>0){
exchange.SetContractType("quarter");
exchange.SetDirection("sell");
var dealamount=$.perform_limited_order("sell",exchange,qt_buy1,trade_unit,false,"futures","sell");
qt_sell1_lowest=qt_sell1;
if (push_notification){
Log("已完成季度做空"+trade_unit+'张'+'@');
}
}
//平仓
else if (tw_zuoduo_zhangshu>0 && (tw_buy1_highest-tw_buy1>N_mult*tw_N||tw_ema_sellduo/* ||tw_buy1-tw_zuoduo_avg_price>N_mult*tw_N */)){
exchange.SetContractType("this_week");
exchange.SetDirection("closebuy");
var dealamount=$.perform_limited_order("sell",exchange,tw_buy1,tw_zuoduo_zhangshu,true,"futures","closebuy");