结单方式

    public static function get_closetype($closeprice, $takeprofit, $stoploss, $trend) {
        //返回结果1为手动结单2为止盈结单3为止损结单
        if ($trend == 0) {
            if ($takeprofit == 0 && $stoploss == 0) {
                return 1;
            } elseif ($takeprofit == 0) {
                if ($closeprice > $stoploss) {
                    return 1;
                } else {
                    return 3;
                }
            } elseif ($stoploss == 0) {
                if ($closeprice < $takeprofit) {
                    return 1;
                } else {
                    return 2;
                }
            } else {
                if ($closeprice < $takeprofit && $closeprice > $stoploss) {
                    return 1;
                } elseif ($closeprice <= $stoploss) {
                    return 3;
                } else {
                    return 2;
                }
            }
        } else {
            if ($takeprofit == 0 && $stoploss == 0) {
                return 1;
            } elseif ($takeprofit == 0) {
                if ($closeprice < $stoploss) {
                    return 1;
                } else {
                    return 3;
                }
            } elseif ($stoploss == 0) {
                if ($closeprice > $takeprofit) {
                    return 1;
                } else {
                    return 2;
                }
            } else {
                if ($closeprice < $stoploss && $closeprice > $takeprofit) {
                    return 1;
                } elseif ($closeprice >= $stoploss) {
                    return 3;
                } else {
                    return 2;
                }
            }
        }
    }

你可能感兴趣的:(结单方式)