Exemplo n.º 1
0
//get ATH for stop loss
$queryATH = 'SELECT (MAX(' . $price_field . ')) AS ATH FROM ' . $context['pricesTable30m'] . ' where time > "' . $last_updated . '"';
$resultATH = $db->query($queryATH);
foreach ($resultATH as $row) {
    //get ATH = all time high
    $ATH = $row['ATH'];
}
//get ATL for stop loss
$queryATL = 'SELECT (MIN(' . $price_field . ')) AS ATL FROM ' . $context['pricesTable30m'] . ' where time > "' . $last_updated . '"';
$resultATL = $db->query($queryATL);
foreach ($resultATL as $row) {
    //get ATL = all time low
    $ATL = $row['ATL'];
}
//get active positions id
$active_pos = $bitfinexAPI->active_positions();
$position = $active_pos[0];
$position_id = $active_pos[0]['id'];
if ($position['id']) {
    //if there is an active position, the trade amount is the position's amount
    $tradeAmt = abs($position['amount']);
} else {
    //trade amount is the margin divided by the latestPrice
    $tradeAmt = $marginUSD / $latestPrice - 0.01;
    $tradeAmt = $tradeAmt * 0.95;
    //don't use the entire balance
    //    $tradeAmt = 0.16;
}
//echo ' '.$marginUSD/$latestPrice .' ';
if ($ma_7 > $ma_30) {
    //uptrend signal