$tradeAmt = $marginUSD / $latestPrice * 0.95;
        //use the remaining balance
    }
} else {
    //No positions active
    $position['pl'] = 0;
    //make sure pl is defined
}
if ($positionID) {
    //if there is an active position
    //if profiting, trade the rest of the balance
    if ($position['pl'] > 0.05) {
        $output .= ' | green zone | ';
        if ($position['amount'] < 0) {
            //short
            $newTrade = $bitfinexAPI->margin_short_pos($symbol, $latestPrice, $tradeAmt);
            $action = 'Sell';
        } else {
            //long
            $newTrade = $bitfinexAPI->margin_long_pos($symbol, $latestPrice, $tradeAmt);
            $action = 'Buy';
        }
    }
}
//set the stop losses for different trends
if ($percentDiff > $pumpPercent) {
    //during a pump, the stop loss is the ema-21 line
    $stopHigh = $ema21;
    $stopLow = $ema21;
    $SLType = 'EMA-21';
} else {