삼평선 시스템 엑소더스

저자:에콰도르, 2021-07-26 14:09:40
태그:

이 시스템은 양방향 계약 전략으로, 조건이 충족되는 경우 더하거나 공백을 하려면 단위 단위가 계약의 수, 비트코인을 사용할 때 단위 단위가 몇 BTC, 토큰을 사용할 때 단위 단위는 이다. 7-31 업데이트 이 정책의 매개 변수는 1시간 수준에서 실행될 수 있지만, 시간 수준에서 열기 단위가 너무 적어서 분 수준을 업데이트합니다. 그러나 분 수준에서는 매개 변수를 수동으로 변경해야 합니다.

아래의 재검토 결과는 시간 주기입니다. 4-27에서 7-25까지 자본금 300, 단금 0.04btcimg**** 1-1에서 7-25까지 자본 300, 0.03btc, 0.04의 기본 금액이 부족합니다. 본인의 실제 디스크를 사용하려면 다음 주문량을 결정하기 위해 재검토하십시오.img

만약 돈을 벌 수 있다면 저자를 지원해 주세요.img


/*backtest
start: 2021-04-27 00:00:00
end: 2021-07-25 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":300}]
args: [["afterEmaCrossTime",4],["buyVolume",0.04],["winLossRate",5]]
*/

function GetCrossStatus(a, lastA, b, lastB) {
    let lastStatus = lastA < lastB;
    let curStatus = a < b;
    let crosssStaus = 0; //0表示没有交叉,1表示金叉,2表示死叉
    //判断金叉还是死叉,同时判断此刻大于0轴或者小于0轴,因为在此系统中要求金叉时macd>0才有意义,死叉时macd<0才有意义
    if (curStatus != lastStatus) //状态不同时表示金叉或者死叉了
    {
        if (a > b) {
            crosssStaus = 1; //金叉
        }
        if (a < b)
            crosssStaus = 2; //死叉
    }
    return crosssStaus;
}
var lastOpenTime;

function GetCurRecord(records) {
    return records[records.length - 1];
}

function GetCurTime(records) {
    return GetCurRecord(records).Time;
}

function GetCurPrice(records) {
    return GetCurRecord(records).Close;
}

function Open(direction) {
    let pos = exchange.GetPosition()[0];

    if (pos != null) {
        return;
    }
    let amount = buyVolume;
    if (direction == 1) { //做多
        Log("做多", amount);
        exchange.SetDirection("buy");
        exchange.Buy(-1, amount);
    }
    if (direction == 2) { //做空
        Log("做空", amount);
        exchange.SetDirection("sell");
        exchange.Sell(-1, amount);
    }
    
}

function Close(ticker,fastLine,midLine) {
    let pos = exchange.GetPosition()[0];

    if (pos == null) {
        return;
    }
    
    if (pos.Type == PD_LONG) {
        if (ticker.Last < pos.Price*(1- stopLossRate/100) || ticker.Last > pos.Price*(1+(stopLossRate*winLossRate)/100)) {
            Log("平多,开仓价为:",pos.Price,"本次盈利:",pos.Profit);
            exchange.SetDirection("closebuy");
            exchange.Sell(-1, pos.Amount);
            
        }
    }
    if (pos.Type == PD_SHORT) {
        if (ticker.Last > pos.Price*(1+ stopLossRate/100) || ticker.Last < pos.Price*(1-(stopLossRate*winLossRate)/100) ) {
            Log("平空,开仓价为:",pos.Price,"本次盈利:",pos.Profit);
            exchange.SetDirection("closesell");
            exchange.Buy(-1, pos.Amount);
        }
    }
}




var lastEmaCrossTime = 0;
var lastMacdCrossTime = 0;

function NearMacdCross(time) {
    //Log("MACD",time,lastMacdCrossTime,time - lastMacdCrossTime);
    return time - lastMacdCrossTime <= afterEmaCrossTime * 1000 * 3600;
}

function NearEmaCross(time) {
    //Log("EMA",time,lastMacdCrossTime,time - lastMacdCrossTime);
    return time - lastEmaCrossTime <= afterEmaCrossTime * 1000 * 3600;
}


var emaMeet = 0; //0表示不满足,1满足做多条件,2满足做空条件
var macdMeet = 0; //判断macd是否满足条件,0表示不满足,1表示做多条件满足,2表示做空条件满足
function main() {
    exchange.SetContractType("swap");
    while (1) {
        let r = exchange.GetRecords(PERIOD_M1*period);

        //************均线EMA****************
        let emaChart8 = TA.EMA(r, EMA1);
        let emaChart34 = TA.EMA(r, EMA2);
        let emaChart89 = TA.EMA(r, EMA3);

        let ema8 = emaChart8;
        let curEma8 = ema8[emaChart8.length - 1];
        let lastEma8 = ema8[emaChart8.length - 2];

        let ema34 = emaChart34;
        let curEma34 = ema34[emaChart34.length - 1];
        let lastEma34 = ema34[emaChart34.length - 2];

        let ema89 = emaChart89;
        let curEma89 = ema89[emaChart89.length - 1];
        let lastEma89 = ema89[emaChart89.length - 2];

        //判断8均线和34均线的死叉和金叉,当金叉时如果当前实体在ema89均线以上做多,当死叉时如果实体在ema89以下时做空      
        let ticker = exchange.GetTicker();
        let low = ticker.Low;
        let high = ticker.High;
        let close = ticker.Close;

        Close(ticker,curEma8,curEma34);

        let crossStatus1 = GetCrossStatus(curEma8, lastEma8, curEma34, lastEma34);

        if (crossStatus1 != emaMeet) { //状态变化时更新状态
            if (crossStatus1 == 1) {
                emaMeet = 1;
                Log("ema金叉,时间:", GetCurTime(r),talib.LINEARREG_SLOPE(ema8));
                lastEmaCrossTime = r[r.length - 1].Time;
            }
            if (crossStatus1 == 2) {
                emaMeet = 2;
                //Log("ema死叉,时间:", GetCurTime(r));
                lastEmaCrossTime = r[r.length - 1].Time;
                //Log("Ema 2");
            }
        }

        //***************Macd*************
        let macdChart = TA.MACD(r, MACD1, MACD2, MACD3);

        let macd = macdChart[2]; //动能柱
        let curMacd = macd[r.length - 1]; //当前动能柱
        let lastMacd = macd[r.length - 2]; //上一根动能柱,直接根据动能柱的正反来判断macd的金叉和死叉
        //auto lastMacd = macd[r.size() - 2]; //上一根动能柱

        //判断金叉还是死叉
        let dif = macdChart[0];
        let curDif = dif[r.length - 1];
        let lastDif = dif[r.length - 2];


        //判断金叉还是死叉,同时判断此刻大于0轴或者小于0轴,因为在此系统中要求金叉时macd>0才有意义,死叉时macd<0才有意义

        //Macd形成金叉或者死叉的瞬间
        if (curMacd < 0 != lastMacd < 0) {

            if (curMacd > 0) {
                macdMeet = 1;
                //Log("macd金叉", lastMacd, curMacd);
                lastMacdCrossTime = GetCurTime(r);
            }
            if (curMacd < 0) {
                macdMeet = 2;
                //Log("macd死叉", lastMacd, curMacd);
                lastMacdCrossTime = GetCurTime(r);

            }
        }


        let Account = exchange.GetAccount();
        let curBalance = exchange.GetAccount().Balance; //余额
        let curStock = exchange.GetAccount().Stocks; //币量

        //均线系统
        var curTime = GetCurTime(r);
       
        if (NearEmaCross(curTime) && NearMacdCross(curTime)) {
            
            if (emaMeet == 1 && macdMeet == 1 && curDif >= 0) {
                Open(1);
            }
           
            if (emaMeet == 2 && macdMeet == 2 && curDif < 0) {
                Open(2);
            }
        }
        



        var myDate = new Date();
        var myDataM = myDate.getMinutes();
        var myDateS = myDate.getSeconds() * 1000;
        var myDateMs = myDate.getMilliseconds(); //获取到毫秒以减少误差
        Sleep(Math.abs(period - myDataM % period) * 60000 - myDateS - myDateMs);


    }


}

더 많은

마이케오정말 멋지네요!

이 세상엔 나뿐이야.적어도 1년 동안 리테스트를 해야 합니다. 올해의 황금시장은 리테스트를 하지 말라는 것이 좋습니다.

오100011K선 주기를 바꿀 수 있을까요? 마치 시계처럼요.

와징곤어떻게 연락할 수 있나요?

이 세상엔 나뿐이야.하지만, 이 모든 것들은 단지 크기와 방향이 다르기 때문입니다.

에콰도르누가 곰 시장에서 트렌드 전략을 사용합니까?

에콰도르K선 주기를 변경하는 기능이 추가되었습니다.

에콰도르이 전략은 1시간 주기로 실행하는 것이 좋습니다. 수익을 변경하면 거의 감소합니다.

에콰도르위키백과 17863938515