$output .= ' | long SL exit'; $newTrade = $bitfinexAPI->margin_short_pos($symbol, $latestPrice, $posAmt); } //stop loss } else { if ($positionID && $position['amount'] < 0) { //if short pos open if ($latestPrice >= $stopLow) { //downtrend stop loss //close short pos $action = $trade_signal = 'Buy'; $output .= ' | short SL exit'; $newTrade = $bitfinexAPI->margin_long_pos($symbol, $latestPrice, $posAmt); } //stop loss } } if ($newTrade['is_live'] == 1) { $last_action_data = array('last_action' => strtolower($action), 'last_price' => $latestPrice, 'trade_signal' => $trade_signal, 'currency' => $currency); $sendMailBody = $action . ' ' . $tradeAmt . ' ' . $currency . ' at ' . $latestPrice . ' (' . date('h:i A', time()) . ')'; $candleData->sendMail($sendMailBody); update_last_action($last_action_data); $output .= $newline . array_debug($newTrade) . $newline; } echo $output; echo $newline . $newline . 'Active Positions: '; if ($position['id']) { array_debug($activePos); } else { echo 'None'; }