

There are global variables and contants that are predefined for you and you have make use of them and avoid naming or defining constants using any of them as that will make your script not to run or may overide some values
You can use any of the php trader extension lib such as trader_ema, trader_macd , trader_rsi or any of the native trader functions.
You can also use python trader library inbuilt functions on your script such as TA-LIB, PANDAS_TA or backtrader
You can create custom functions using the below method:
$mycustomCheck = function($price, $volume) {
return $price * $volume;
};
$vwapcheck = $mycustomCheck($price, $volume);
This variable is a must to be used in any of your conditions either buy or sell, as the is the only variable our server recognize:
// Buy condition example
if ($price < $lowerBand && $stochK < 20) {
$SIGNAL = array(
'mode' => 'BUY',
'entry' => $price,
'tp' => $price + ($price * $takeProfit),
'sl' => $price - ($price * $stopLoss),
);
}
// Sell condition example
if ($price > $highBand && $stochK > 80) {
$SIGNAL = array(
'mode' => 'SELL',
'entry' => $price,
'tp' => $price - ($price * $takeProfit),
'sl' => $price + ($price * $stopLoss),
);
}
/*
### Scalping Strategy Using PHP Trader
This strategy will:
1. Buy when the ema50 crosses above ema100.
2. Sell when the ema50 crosses below ema100.
*/
// Declare start datas
$count = count($REVERSEDCANDLES);
$ema50Data_start = $count - 50; // even though the setting is 14 it requires data like plus 14 or more
$ema100Data_start = $count - 100;
// Declare sliced datas
$close = [];
$high = [];
$low = [];
$volume = [];
$ema50Data = [];
$ema100Data = [];
//Fill the array columns with real values
foreach($REVERSEDCANDLES as $key => $row){
$closeValue = (!empty($row['close'])) ? $row['close'] : 0;
$highValue = (!empty($row['high'])) ? $row['high'] : 0;
$lowValue = (!empty($row['low'])) ? $row['low'] : 0;
$volumeValue = (!empty($row['volume'])) ? $row['volume'] : 0;
$close[] = $closeValue;
$high[] = $highValue;
$low[] = $lowValue;
$volume[] = $volumeValue;
// Create data for each data that needs slicing
if($key >= $ema50Data_start){
$ema50Data[$key] = $closeValue;
}
if($key >= $ema100Data_start){
$ema100Data[$key] = $closeValue;
}
}
// Calculate Indicators
$ema50 = trader_ema($ema50Data, 50);
$ema100 = trader_ema($ema100Data, 100);
// Get last EMA values
$lastEma50 = end($ema50);
$lastEma100 = end($ema100);
$prevEma50 = prev($ema50);
$prevEma100 = prev($ema100);
// Trading parameters
$takeProfit = 1.5 / 100;
$stopLoss = 0.50 / 100;
// BUY CONDITION
if ($prevEma50 < $prevEma100 && $lastEma50 > $lastEma100) {
$SIGNAL = array(
'mode' => 'BUY',
'entry' => $price,
'tp' => $price + ($price * $takeProfit),
'sl' => $price - ($price * $stopLoss),
);
}
// SELL CONDITION
if ($prevEma50 > $prevEma100 && $lastEma50 < $lastEma100) {
$SIGNAL = array(
'mode' => 'SELL',
'entry' => $price,
'tp' => $price - ($price * $takeProfit),
'sl' => $price + ($price * $stopLoss),
);
}
# Convert to DataFrame
df = pd.DataFrame(REVERSEDCANDLES)
# Ensure close prices are present
df["close"] = df["close"].fillna(0)
# Calculate EMA indicators
df["ema50"] = ta.trend.ema_indicator(df["close"], window=50)
df["ema100"] = ta.trend.ema_indicator(df["close"], window=100)
# Get last and previous EMA values
lastEma50 = df["ema50"].iloc[-1]
lastEma100 = df["ema100"].iloc[-1]
prevEma50 = df["ema50"].iloc[-2]
prevEma100 = df["ema100"].iloc[-2]
# Trading parameters
takeProfit = 1.5 / 100
stopLoss = 0.50 / 100
# Example price (replace with actual price)
price = df["close"].iloc[-1]
# BUY CONDITION
if prevEma50 < prevEma100 and lastEma50 > lastEma100:
SIGNAL = {
"mode": "BUY",
"entry": price,
"tp": price + (price * takeProfit),
"sl": price - (price * stopLoss),
}
# SELL CONDITION
if prevEma50 > prevEma100 and lastEma50 < lastEma100:
SIGNAL = {
"mode": "SELL",
"entry": price,
"tp": price - (price * takeProfit),
"sl": price + (price * stopLoss),
}