### Setup Development Environment Source: https://github.com/lupecode/phptradernative/blob/master/README.md Commands to clone the repository and install development dependencies. ```bash git checkout git@github.com:LupeCode/phpTraderNative.git cd phpTraderNative composer install --dev ``` -------------------------------- ### Install PHP Trader Native via Composer Source: https://github.com/lupecode/phptradernative/blob/master/README.md Use this command to add the library to your project dependencies. ```bash composer require lupecode/php-trader-native ``` -------------------------------- ### Run PHPUnit Tests Source: https://github.com/lupecode/phptradernative/blob/master/README.md Execute the test suite using the provided configuration file. ```bash php -dxdebug.coverage_enable=0 ./vendor/phpunit/phpunit/phpunit --configuration ./phpunit.xml ./tests ``` -------------------------------- ### Configure Compatibility Mode Source: https://context7.com/lupecode/phptradernative/llms.txt Use the set_compat method to switch between TA-LIB and Metastock modes. The get_compat method retrieves the currently active setting. ```php use LupeCode\phpTraderNative\Trader; use LupeCode\phpTraderNative\TALib\Enum\Compatibility; // Set to Metastock compatibility Trader::set_compat(Compatibility::Metastock->value); // Get current compatibility mode $compat = Trader::get_compat(); echo "Compatibility mode: " . $compat; ``` -------------------------------- ### Run Code Coverage Analysis Source: https://github.com/lupecode/phptradernative/blob/master/README.md Execute tests with code coverage enabled using the specific coverage configuration file. ```bash php -dxdebug.coverage_enable=1 ./vendor/phpunit/phpunit/phpunit --configuration ./phpunit_coverage.xml ./tests ``` -------------------------------- ### Calculate On Balance Volume (OBV) Source: https://context7.com/lupecode/phptradernative/llms.txt Computes the cumulative volume indicator based on price changes. Requires arrays of closing prices and volumes. ```php use LupeCode\phpTraderNative\Trader; $close = [10.0, 10.5, 10.3, 10.8, 11.0, 10.7, 11.2, 11.5, 11.3, 11.8]; $volume = [100000, 150000, 120000, 180000, 200000, 130000, 170000, 190000, 140000, 210000]; // Calculate On Balance Volume $obv = Trader::obv($close, $volume); print_r($obv); ``` -------------------------------- ### Use Friendly-Named Functions Source: https://github.com/lupecode/phptradernative/blob/master/README.md Access technical analysis functions using descriptive names instead of the standard short-form aliases. ```php TraderFriendly::chaikinAccumulationDistributionOscillator($high, $low, $close, $volume, $fastPeriod, $slowPeriod) ``` -------------------------------- ### Calculate Kaufman Adaptive Moving Average (KAMA) Source: https://context7.com/lupecode/phptradernative/llms.txt Adapts to market volatility, following prices closely during trends and smoothing during consolidation. Useful for dynamic trend following. ```php use LupeCode\phpTraderNative\Trader; $prices = [100.0, 101.5, 102.0, 101.8, 103.0, 104.5, 103.8, 105.0, 106.5, 107.0, 106.5, 108.0, 109.0, 108.5, 110.0, 111.5, 112.0, 111.5, 113.0, 114.0]; // Calculate 10-period KAMA $kama = Trader::kama($prices, 10); print_r($kama); ``` -------------------------------- ### Friendly-Named API for Technical Indicators Source: https://context7.com/lupecode/phptradernative/llms.txt Utilizes the TraderFriendly class for more readable method names when calculating common technical indicators like SMA, EMA, RSI, Bollinger Bands, and MACD. Ensure correct parameters for each indicator. ```php use LupeCode\phpTraderNative\TraderFriendly; use LupeCode\phpTraderNative\TALib\Enum\MovingAverageType; $prices = [44.34, 44.09, 44.15, 43.61, 44.33, 44.83, 45.10, 45.42, 45.84, 46.08, 45.89, 46.03, 45.61, 46.28, 46.28, 46.00, 46.03, 46.41, 46.22, 45.64]; // Instead of Trader::sma(), use: $sma = TraderFriendly::simpleMovingAverage($prices, 10); // Instead of Trader::ema(), use: $ema = TraderFriendly::exponentialMovingAverage($prices, 10); // Instead of Trader::rsi(), use: $rsi = TraderFriendly::relativeStrengthIndex($prices, 14); // Instead of Trader::bbands(), use: $bbands = TraderFriendly::bollingerBands($prices, 20, 2.0, 2.0, MovingAverageType::SMA->value); // Instead of Trader::macd(), use: $macd = TraderFriendly::movingAverageConvergenceDivergence($prices, 12, 26, 9); print_r($sma); print_r($rsi); ``` -------------------------------- ### Calculate Parabolic SAR Source: https://context7.com/lupecode/phptradernative/llms.txt Computes stop and reverse points. Requires acceleration and maximum parameters. ```php use LupeCode\phpTraderNative\Trader; $high = [35.00, 35.50, 36.00, 35.80, 36.50, 37.00, 36.80, 37.50, 38.00, 37.80]; $low = [34.00, 34.50, 35.00, 34.80, 35.50, 36.00, 35.80, 36.50, 37.00, 36.80]; // Calculate Parabolic SAR $sar = Trader::sar($high, $low, 0.02, 0.2); // acceleration=0.02, maximum=0.2 print_r($sar); ``` -------------------------------- ### Calculate Money Flow Index (MFI) Source: https://context7.com/lupecode/phptradernative/llms.txt Calculates the 14-period volume-weighted RSI. Requires high, low, close, and volume arrays. ```php use LupeCode\phpTraderNative\Trader; $high = [24.63, 24.69, 24.99, 25.36, 25.20, 25.07, 25.47, 25.48, 25.35, 25.61, 25.50, 25.43, 25.47, 25.53, 25.75, 25.61, 25.65, 25.46, 25.28, 25.17]; $low = [24.29, 24.27, 24.46, 24.79, 24.88, 24.77, 25.06, 25.02, 25.03, 25.16, 25.07, 25.19, 25.15, 25.15, 25.29, 25.24, 25.23, 25.03, 24.83, 24.80]; $close = [24.53, 24.42, 24.97, 25.12, 24.96, 24.93, 25.46, 25.28, 25.23, 25.52, 25.14, 25.36, 25.41, 25.18, 25.69, 25.46, 25.48, 25.19, 24.85, 24.94]; $volume = [18730144, 12272104, 24691248, 18358384, 22964720, 15919648, 16067024, 16568352, 16019344, 9773040, 22572176, 12986544, 10906832, 5799072, 7395296, 5765872, 7793008, 4355952, 7467072, 11237504]; // Calculate 14-period MFI $mfi = Trader::mfi($high, $low, $close, $volume, 14); print_r($mfi); ``` -------------------------------- ### Statistical Calculations Source: https://context7.com/lupecode/phptradernative/llms.txt Computes standard deviation, variance, linear regression, slope, and Pearson correlation coefficient for price data. Specify the period and deviation parameters as needed. ```php use LupeCode\phpTraderNative\Trader; $prices = [22.27, 22.19, 22.08, 22.17, 22.18, 22.13, 22.23, 22.43, 22.24, 22.29]; // Standard Deviation (10 period, 1 deviation) $stddev = Trader::stddev($prices, 10, 1.0); // Variance $variance = Trader::var($prices, 5, 1.0); // Linear Regression $linearReg = Trader::linearreg($prices, 5); // Linear Regression Slope $slope = Trader::linearreg_slope($prices, 5); // Pearson Correlation Coefficient $prices2 = [21.50, 21.75, 22.00, 22.25, 22.50, 22.75, 23.00, 23.25, 23.50, 23.75]; $correlation = Trader::correl($prices, $prices2, 5); print_r($stddev); print_r($variance); print_r($linearReg); print_r($slope); print_r($correlation); ``` -------------------------------- ### Calculate Exponential Moving Average (EMA) Source: https://context7.com/lupecode/phptradernative/llms.txt Gives more weight to recent prices, making it more responsive to new information than SMA. Use this for indicators that need to react quickly to price changes. ```php use LupeCode\phpTraderNative\Trader; $closePrices = [22.27, 22.19, 22.08, 22.17, 22.18, 22.13, 22.23, 22.43, 22.24, 22.29, 22.15, 22.39, 22.38, 22.61, 23.36, 24.05, 23.75, 23.83, 23.95, 23.63]; // Calculate 10-period Exponential Moving Average $ema = Trader::ema($closePrices, 10); // Result: Array with EMA values starting from index 9 print_r($ema); ``` -------------------------------- ### Calculate Moving Average Convergence Divergence (MACD) Source: https://context7.com/lupecode/phptradernative/llms.txt Calculates the MACD line, signal line, and histogram using provided closing prices. Default periods are 12 for the fast EMA, 26 for the slow EMA, and 9 for the signal line EMA. ```php use LupeCode\phpTraderNative\Trader; $closePrices = [26.0, 26.5, 27.0, 26.8, 27.5, 28.0, 27.8, 28.5, 29.0, 28.8, 29.5, 30.0, 29.8, 30.5, 31.0, 30.8, 31.5, 32.0, 31.8, 32.5, 33.0, 32.8, 33.5, 34.0, 33.8, 34.5, 35.0, 34.8, 35.5, 36.0]; // Calculate MACD with default periods (12, 26, 9) $macd = Trader::macd($closePrices, 12, 26, 9); // Returns array with three components: // 'MACD' - The MACD line (12-period EMA minus 26-period EMA) // 'MACDSignal' - 9-period EMA of MACD line // 'MACDHist' - Difference between MACD and Signal (histogram) print_r($macd['MACD']); print_r($macd['MACDSignal']); print_r($macd['MACDHist']); ``` -------------------------------- ### Calculate Simple Moving Average (SMA) Source: https://context7.com/lupecode/phptradernative/llms.txt Calculates the unweighted mean of the previous n data points. Use this to identify trend direction and support/resistance levels. ```php use LupeCode\phpTraderNative\Trader; // Sample closing prices $closePrices = [44.34, 44.09, 44.15, 43.61, 44.33, 44.83, 45.10, 45.42, 45.84, 46.08, 45.89, 46.03, 45.61, 46.28, 46.28, 46.00, 46.03, 46.41, 46.22, 45.64]; // Calculate 10-period Simple Moving Average $sma = Trader::sma($closePrices, 10); // Result: Array starting at index 9 with SMA values // [9 => 45.279, 10 => 45.343, 11 => 45.494, ...] print_r($sma); ``` -------------------------------- ### Calculate Weighted Moving Average (WMA) Source: https://context7.com/lupecode/phptradernative/llms.txt Assigns linearly increasing weights to more recent data points. Use this when recent price action should have a greater impact on the average. ```php use LupeCode\phpTraderNative\Trader; $prices = [10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 14.0, 13.0, 12.0, 11.0]; // Calculate 5-period WMA $wma = Trader::wma($prices, 5); print_r($wma); ``` -------------------------------- ### Detect Morning Star Candlestick Pattern Source: https://context7.com/lupecode/phptradernative/llms.txt Identifies a three-candle bullish reversal pattern. Requires a penetration factor parameter. ```php use LupeCode\phpTraderNative\Trader; $open = [100.0, 99.0, 97.0, 98.0, 100.5, 102.0, 103.5, 105.0, 104.5, 106.0]; $high = [101.0, 100.0, 98.0, 99.5, 103.0, 104.0, 105.5, 107.0, 106.5, 108.0]; $low = [98.5, 96.5, 96.0, 96.5, 99.5, 101.0, 102.5, 104.0, 103.5, 105.0]; $close = [99.5, 97.0, 97.5, 99.0, 102.5, 103.5, 105.0, 106.5, 106.0, 107.5]; // Detect Morning Star patterns (penetration factor = 0.3) $morningStar = Trader::cdlmorningstar($open, $high, $low, $close, 0.3); print_r($morningStar); ``` -------------------------------- ### Calculate Chaikin A/D Oscillator Source: https://context7.com/lupecode/phptradernative/llms.txt Measures momentum of the Accumulation/Distribution Line using MACD formula. Use this to identify shifts in buying and selling pressure. ```php use LupeCode\phpTraderNative\Trader; $high = [62.34, 62.05, 62.27, 60.79, 59.93, 61.75, 60.00, 59.00, 59.07, 59.22, 58.75, 58.65, 58.47, 58.25, 58.35, 59.86, 59.53, 62.10, 62.16, 62.67]; $low = [61.37, 60.69, 60.10, 58.61, 58.71, 59.86, 57.97, 58.02, 57.48, 58.30, 57.83, 57.86, 57.91, 57.83, 57.10, 58.31, 58.70, 58.53, 60.25, 62.10]; $close = [62.15, 60.81, 60.45, 59.18, 59.24, 60.20, 58.48, 58.24, 58.69, 58.65, 58.47, 58.02, 58.17, 58.07, 58.13, 59.27, 59.32, 61.29, 61.68, 62.30]; $volume = [7849025, 11692075, 10575307, 13059128, 20733508, 17039414, 18321607, 11591151, 12944893, 10074238, 9945291, 14216786, 13542863, 15044738, 16722107, 12566568, 13106009, 21452856, 18693743, 22784818]; // Calculate A/D Oscillator (default: fast=3, slow=10) $adosc = Trader::adosc($high, $low, $close, $volume, 3, 10); print_r($adosc); ``` -------------------------------- ### Detect Doji Candlestick Pattern Source: https://context7.com/lupecode/phptradernative/llms.txt Identifies Doji patterns where open and close prices are nearly identical. Returns 100 for bullish, -100 for bearish, or 0. ```php use LupeCode\phpTraderNative\Trader; $open = [100.0, 101.0, 100.5, 99.0, 100.0, 102.0, 101.5, 100.8, 101.0, 100.0]; $high = [102.0, 103.0, 101.5, 100.0, 101.0, 103.5, 102.0, 102.0, 102.5, 101.0]; $low = [99.0, 100.5, 99.5, 98.0, 99.0, 101.0, 100.5, 99.5, 100.0, 99.0]; $close = [101.5, 102.5, 100.5, 99.5, 100.5, 103.0, 101.5, 100.7, 101.5, 100.0]; // Detect Doji patterns // Returns: 0 = No pattern, 100 = Bullish, -100 = Bearish $doji = Trader::cdldoji($open, $high, $low, $close); print_r($doji); ``` -------------------------------- ### Calculate Bollinger Bands Source: https://context7.com/lupecode/phptradernative/llms.txt Plots bands at standard deviation levels above and below a moving average to identify volatility. Use this to gauge price extremes and potential reversals. ```php use LupeCode\phpTraderNative\Trader; use LupeCode\phpTraderNative\TALib\Enum\MovingAverageType; $closePrices = [86.16, 89.09, 88.78, 90.32, 89.07, 91.15, 89.44, 89.18, 86.93, 87.68, 86.96, 89.43, 89.32, 88.72, 87.45, 87.26, 89.50, 87.90, 89.13, 90.70]; // Calculate 20-period Bollinger Bands with 2 standard deviations $bbands = Trader::bbands( $closePrices, 20, // Time period 2.0, // Deviations for upper band 2.0, // Deviations for lower band MovingAverageType::SMA->value ); // Returns three arrays: // UpperBand - Upper boundary (sell signal when price touches) // MiddleBand - Moving average (trend indicator) // LowerBand - Lower boundary (buy signal when price touches) print_r($bbands['UpperBand']); print_r($bbands['MiddleBand']); print_r($bbands['LowerBand']); ``` -------------------------------- ### Calculate Normalized Average True Range (NATR) Source: https://context7.com/lupecode/phptradernative/llms.txt ATR expressed as a percentage of the closing price for easier cross-security comparison. Use this to compare volatility across different assets. ```php use LupeCode\phpTraderNative\Trader; $high = [48.70, 48.72, 48.90, 48.87, 48.82, 49.05, 49.20, 49.35, 49.92, 50.19, 50.12, 49.66, 49.88, 50.19, 50.36, 50.57, 50.65, 50.43, 49.63, 50.33]; $low = [47.79, 48.14, 48.39, 48.37, 48.24, 48.64, 48.94, 48.86, 49.50, 49.87, 49.20, 48.90, 49.43, 49.73, 49.26, 50.09, 50.30, 49.21, 48.98, 49.61]; $close = [48.16, 48.61, 48.75, 48.63, 48.74, 49.03, 49.07, 49.32, 49.91, 50.13, 49.53, 49.50, 49.75, 50.03, 50.31, 50.52, 50.41, 49.34, 49.37, 50.23]; // Calculate 14-period NATR $natr = Trader::natr($high, $low, $close, 14); print_r($natr); ``` -------------------------------- ### Detect Hammer Candlestick Pattern Source: https://context7.com/lupecode/phptradernative/llms.txt Identifies bullish reversal patterns characterized by long lower shadows. ```php use LupeCode\phpTraderNative\Trader; $open = [100.0, 101.0, 100.5, 99.0, 100.0, 102.0, 101.5, 100.8, 101.0, 100.0]; $high = [102.0, 103.0, 101.5, 100.0, 101.0, 103.5, 102.0, 102.0, 102.5, 101.0]; $low = [99.0, 100.5, 99.5, 95.0, 99.0, 101.0, 100.5, 99.5, 100.0, 97.0]; $close = [101.5, 102.5, 100.5, 99.8, 100.5, 103.0, 101.5, 100.7, 101.5, 99.9]; // Detect Hammer patterns $hammer = Trader::cdlhammer($open, $high, $low, $close); print_r($hammer); ``` -------------------------------- ### Calculate Double Exponential Moving Average (DEMA) Source: https://context7.com/lupecode/phptradernative/llms.txt Reduces lag compared to traditional EMA by applying exponential smoothing twice. Useful when a faster-reacting moving average is needed. ```php use LupeCode\phpTraderNative\Trader; $prices = [25.0, 26.5, 27.0, 26.8, 27.5, 28.0, 27.8, 28.5, 29.0, 28.8, 29.5, 30.0]; // Calculate 5-period DEMA $dema = Trader::dema($prices, 5); print_r($dema); ``` -------------------------------- ### Calculate Chaikin A/D Line Source: https://context7.com/lupecode/phptradernative/llms.txt Uses volume flow to measure buying and selling pressure. This indicator helps identify accumulation and distribution trends. ```php use LupeCode\phpTraderNative\Trader; $high = [62.34, 62.05, 62.27, 60.79, 59.93, 61.75, 60.00, 59.00, 59.07, 59.22]; $low = [61.37, 60.69, 60.10, 58.61, 58.71, 59.86, 57.97, 58.02, 57.48, 58.30]; $close = [62.15, 60.81, 60.45, 59.18, 59.24, 60.20, 58.48, 58.24, 58.69, 58.65]; $volume = [7849025, 11692075, 10575307, 13059128, 20733508, 17039414, 18321607, 11591151, 12944893, 10074238]; // Calculate Accumulation/Distribution Line $ad = Trader::ad($high, $low, $close, $volume); print_r($ad); ``` -------------------------------- ### Moving Average Convergence Divergence (MACD) Source: https://context7.com/lupecode/phptradernative/llms.txt Calculates the MACD line, Signal line, and histogram based on provided closing prices and periods. Useful for identifying trend changes. ```APIDOC ## MACD Calculation ### Description Calculates the Moving Average Convergence Divergence (MACD) indicator, which shows the relationship between two Exponential Moving Averages (EMAs) of prices. It returns the MACD line, the MACD Signal line, and the MACD Histogram. ### Method `Trader::macd(array $closePrices, int $shortPeriod = 12, int $longPeriod = 26, int $signalPeriod = 9): array` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **closePrices** (array) - Required - An array of closing prices. - **shortPeriod** (int) - Optional - The period for the short-term EMA (default: 12). - **longPeriod** (int) - Optional - The period for the long-term EMA (default: 26). - **signalPeriod** (int) - Optional - The period for the MACD signal line EMA (default: 9). ### Request Example ```php use LupeCode\phpTraderNative\Trader; $closePrices = [26.0, 26.5, 27.0, 26.8, 27.5, 28.0, 27.8, 28.5, 29.0, 28.8, 29.5, 30.0, 29.8, 30.5, 31.0, 30.8, 31.5, 32.0, 31.8, 32.5, 33.0, 32.8, 33.5, 34.0, 33.8, 34.5, 35.0, 34.8, 35.5, 36.0]; $macd = Trader::macd($closePrices, 12, 26, 9); ``` ### Response #### Success Response (200) - **MACD** (array) - The MACD line. - **MACDSignal** (array) - The MACD Signal line. - **MACDHist** (array) - The MACD Histogram. #### Response Example ```json { "MACD": [ ... ], "MACDSignal": [ ... ], "MACDHist": [ ... ] } ``` ``` -------------------------------- ### Calculate Relative Strength Index (RSI) Source: https://context7.com/lupecode/phptradernative/llms.txt Measures the speed and magnitude of price movements on a 0-100 scale. Values above 70 indicate overbought, below 30 indicate oversold conditions. ```php use LupeCode\phpTraderNative\Trader; $closePrices = [44.34, 44.09, 44.15, 43.61, 44.33, 44.83, 45.10, 45.42, 45.84, 46.08, 45.89, 46.03, 45.61, 46.28, 46.28, 46.00, 46.03, 46.41, 46.22, 45.64, 46.21, 46.25, 45.71, 46.45, 45.78, 46.23, 46.23, 46.01, 45.46, 45.31]; // Calculate 14-period RSI (default) $rsi = Trader::rsi($closePrices, 14); // RSI values range from 0-100 // > 70: Overbought // < 30: Oversold print_r($rsi); ``` -------------------------------- ### Detect Three Black Crows Pattern Source: https://context7.com/lupecode/phptradernative/llms.txt Detects the 'Three Black Crows' bearish reversal pattern using historical price data. Requires open, high, low, and close prices as input arrays. ```php use LupeCode\phpTraderNative\Trader; $open = [100.0, 101.0, 102.0, 101.5, 100.5, 99.5, 98.0, 97.0, 96.0, 95.0]; $high = [102.0, 103.0, 103.0, 102.0, 101.0, 100.0, 98.5, 97.5, 96.5, 95.5]; $low = [99.0, 100.0, 101.0, 99.5, 98.5, 97.5, 96.5, 95.5, 94.5, 93.5]; $close = [101.5, 102.0, 101.0, 100.0, 99.0, 98.0, 97.0, 96.0, 95.0, 94.0]; // Detect Three Black Crows $crows = Trader::cdl3blackcrows($open, $high, $low, $close); print_r($crows); ``` -------------------------------- ### Calculate Momentum (MOM) Source: https://context7.com/lupecode/phptradernative/llms.txt Calculates the Momentum indicator, which measures the rate of price change over a specified period. This helps in identifying the speed of price movements. ```php use LupeCode\phpTraderNative\Trader; $closePrices = [11.0, 11.5, 12.0, 11.8, 12.5, 13.0, 12.8, 13.5, 14.0, 13.8, 14.5, 15.0]; // Calculate 10-period Momentum $mom = Trader::mom($closePrices, 10); print_r($mom); ``` -------------------------------- ### Calculate Rate of Change (ROC) Source: https://context7.com/lupecode/phptradernative/llms.txt Calculates the Rate of Change (ROC) indicator, which represents the percentage change between the current price and the price from 'n' periods ago. Useful for gauging price velocity. ```php use LupeCode\phpTraderNative\Trader; $closePrices = [100.0, 102.0, 104.0, 103.0, 105.0, 107.0, 106.0, 108.0, 110.0, 109.0, 111.0, 113.0]; // Calculate 10-period Rate of Change (percentage) $roc = Trader::roc($closePrices, 10); print_r($roc); ``` -------------------------------- ### Calculate Average True Range (ATR) Source: https://context7.com/lupecode/phptradernative/llms.txt Measures market volatility by decomposing the entire range of an asset price for a period. Useful for setting stop-loss levels. ```php use LupeCode\phpTraderNative\Trader; $high = [48.70, 48.72, 48.90, 48.87, 48.82, 49.05, 49.20, 49.35, 49.92, 50.19, 50.12, 49.66, 49.88, 50.19, 50.36, 50.57, 50.65, 50.43, 49.63, 50.33]; $low = [47.79, 48.14, 48.39, 48.37, 48.24, 48.64, 48.94, 48.86, 49.50, 49.87, 49.20, 48.90, 49.43, 49.73, 49.26, 50.09, 50.30, 49.21, 48.98, 49.61]; $close = [48.16, 48.61, 48.75, 48.63, 48.74, 49.03, 49.07, 49.32, 49.91, 50.13, 49.53, 49.50, 49.75, 50.03, 50.31, 50.52, 50.41, 49.34, 49.37, 50.23]; // Calculate 14-period ATR $atr = Trader::atr($high, $low, $close, 14); print_r($atr); ``` -------------------------------- ### Calculate Triple Exponential Moving Average (TEMA) Source: https://context7.com/lupecode/phptradernative/llms.txt Combines single, double, and triple EMA to produce a smoother moving average with minimal lag. Suitable for trend identification with reduced noise. ```php use LupeCode\phpTraderNative\Trader; $prices = [45.0, 45.5, 46.0, 45.8, 46.5, 47.0, 46.8, 47.5, 48.0, 47.8, 48.5, 49.0]; // Calculate 5-period TEMA $tema = Trader::tema($prices, 5); print_r($tema); ``` -------------------------------- ### Configure Unstable Period for EMAs Source: https://context7.com/lupecode/phptradernative/llms.txt Sets and retrieves the unstable period for functions utilizing exponential moving averages, such as RSI. This configuration affects the initial calculation phase of these indicators. ```php use LupeCode\phpTraderNative\Trader; use LupeCode\phpTraderNative\TALib\Enum\UnstablePeriodFunctionID; // Set unstable period for RSI function Trader::set_unstable_period(UnstablePeriodFunctionID::RSI->value, 10); // Get current unstable period $period = Trader::get_unstable_period(UnstablePeriodFunctionID::RSI->value); echo "RSI unstable period: " . $period; ``` -------------------------------- ### Detect Engulfing Candlestick Pattern Source: https://context7.com/lupecode/phptradernative/llms.txt Identifies patterns where the current candle engulfs the previous one. Returns 100 for bullish or -100 for bearish. ```php use LupeCode\phpTraderNative\Trader; $open = [100.0, 101.0, 100.5, 99.0, 100.0, 102.0, 101.5, 100.8, 101.0, 98.0]; $high = [102.0, 103.0, 101.5, 100.0, 101.0, 103.5, 102.0, 102.0, 102.5, 103.0]; $low = [99.0, 100.5, 99.5, 98.0, 99.0, 101.0, 100.5, 99.5, 100.0, 97.5]; $close = [101.5, 102.5, 100.5, 99.5, 100.5, 103.0, 101.5, 100.7, 99.0, 102.5]; // Detect Engulfing patterns // Returns: 100 = Bullish Engulfing, -100 = Bearish Engulfing $engulfing = Trader::cdlengulfing($open, $high, $low, $close); print_r($engulfing); ``` -------------------------------- ### Rolling Min/Max Calculation Source: https://context7.com/lupecode/phptradernative/llms.txt Calculates the rolling minimum and maximum values for a given price series over a specified period. The 'minmax' function returns both in a single call. ```php use LupeCode\phpTraderNative\Trader; $prices = [10.0, 12.0, 8.0, 15.0, 11.0, 9.0, 14.0, 13.0, 7.0, 16.0]; // Find rolling maximum over 5 periods $max = Trader::max($prices, 5); // Find rolling minimum over 5 periods $min = Trader::min($prices, 5); // Get both min and max together $minmax = Trader::minmax($prices, 5); print_r($max); print_r($min); print_r($minmax['Min']); print_r($minmax['Max']); ``` -------------------------------- ### Rate of Change (ROC) Source: https://context7.com/lupecode/phptradernative/llms.txt Calculates the Rate of Change (ROC) indicator, which measures the percentage change in price between the current period and a previous period. ```APIDOC ## Rate of Change (ROC) Calculation ### Description Calculates the Rate of Change (ROC) indicator. This indicator measures the percentage change in price between the current period and a specified number of periods ago. It helps in understanding the velocity of price changes. ### Method `Trader::roc(array $closePrices, int $period = 10): float` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **closePrices** (array) - Required - An array of closing prices. - **period** (int) - Optional - The period for the Rate of Change calculation (default: 10). ### Request Example ```php use LupeCode\phpTraderNative\Trader; $closePrices = [100.0, 102.0, 104.0, 103.0, 105.0, 107.0, 106.0, 108.0, 110.0, 109.0, 111.0, 113.0]; $roc = Trader::roc($closePrices, 10); ``` ### Response #### Success Response (200) - **ROC** (float) - The calculated Rate of Change value (as a percentage). #### Response Example ```json 13.0 ``` ``` -------------------------------- ### Calculate Average Directional Index (ADX) Source: https://context7.com/lupecode/phptradernative/llms.txt Calculates the Average Directional Index (ADX) to measure trend strength. Values above 25 generally indicate a strong trend, with higher values signifying stronger trends. ```php use LupeCode\phpTraderNative\Trader; $high = [30.20, 30.28, 30.45, 29.35, 29.35, 29.29, 28.83, 28.73, 28.67, 28.85, 28.64, 27.68, 27.21, 26.87, 27.41, 26.94, 26.52, 26.52, 27.09, 27.69]; $low = [29.41, 29.32, 29.96, 28.74, 28.56, 28.41, 28.08, 27.43, 27.66, 27.83, 27.40, 27.09, 26.18, 26.13, 26.63, 26.13, 25.43, 25.35, 25.88, 26.96]; $close = [29.87, 30.24, 30.10, 28.90, 28.92, 28.48, 28.56, 27.56, 28.47, 28.28, 27.49, 27.23, 26.35, 26.33, 27.03, 26.22, 26.01, 26.36, 27.03, 27.45]; // Calculate 14-period ADX $adx = Trader::adx($high, $low, $close, 14); // ADX values: // 0-25: Weak trend or no trend // 25-50: Strong trend // 50-75: Very strong trend // 75-100: Extremely strong trend print_r($adx); ``` -------------------------------- ### Stochastic Oscillator Source: https://context7.com/lupecode/phptradernative/llms.txt Calculates the Stochastic Oscillator, which compares a security's closing price to its price range over a given period. Useful for identifying overbought and oversold conditions. ```APIDOC ## Stochastic Oscillator Calculation ### Description Calculates the Stochastic Oscillator, which compares a security's closing price to its price range over a given period. It returns the SlowK and SlowD lines. Values above 80 typically indicate overbought conditions, while values below 20 indicate oversold conditions. ### Method `Trader::stoch(array $high, array $low, array $close, int $kPeriod = 14, int $kSmoothing = 3, int $kMAType = 0, int $dSmoothing = 3, int $dMAType = 0): array` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **high** (array) - Required - An array of high prices. - **low** (array) - Required - An array of low prices. - **close** (array) - Required - An array of closing prices. - **kPeriod** (int) - Optional - The period for the Fast-K calculation (default: 14). - **kSmoothing** (int) - Optional - The smoothing period for the Slow-K line (default: 3). - **kMAType** (int) - Optional - The Moving Average type for Slow-K smoothing (default: 0 for SMA). - **dSmoothing** (int) - Optional - The smoothing period for the Slow-D line (default: 3). - **dMAType** (int) - Optional - The Moving Average type for Slow-D smoothing (default: 0 for SMA). ### Request Example ```php use LupeCode\phpTraderNative\Trader; use LupeCode\phpTraderNative\TALib\Enum\MovingAverageType; $high = [127.01, 127.62, 126.59, 127.35, 128.17, 128.43, 127.37, 126.42, 126.90, 126.85]; $low = [125.36, 126.16, 124.93, 126.09, 126.82, 126.48, 126.03, 124.83, 126.39, 125.72]; $close = [126.90, 126.74, 125.40, 127.10, 128.08, 127.08, 126.62, 125.06, 126.53, 126.32]; $stoch = Trader::stoch($high, $low, $close, 14, 3, MovingAverageType::SMA->value, 3, MovingAverageType::SMA->value); ``` ### Response #### Success Response (200) - **SlowK** (array) - The Slow-K line values. - **SlowD** (array) - The Slow-D line values. #### Response Example ```json { "SlowK": [ ... ], "SlowD": [ ... ] } ``` ``` -------------------------------- ### Momentum (MOM) Source: https://context7.com/lupecode/phptradernative/llms.txt Calculates the Momentum indicator, which measures the rate of price change over a specified period. It indicates the speed at which prices are changing. ```APIDOC ## Momentum (MOM) Calculation ### Description Calculates the Momentum (MOM) indicator. This indicator measures the rate of price change over a specified number of periods. It helps in identifying the speed of price movements. ### Method `Trader::mom(array $closePrices, int $period = 10): float` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **closePrices** (array) - Required - An array of closing prices. - **period** (int) - Optional - The period for the Momentum calculation (default: 10). ### Request Example ```php use LupeCode\phpTraderNative\Trader; $closePrices = [11.0, 11.5, 12.0, 11.8, 12.5, 13.0, 12.8, 13.5, 14.0, 13.8, 14.5, 15.0]; $mom = Trader::mom($closePrices, 10); ``` ### Response #### Success Response (200) - **MOM** (float) - The calculated Momentum value. #### Response Example ```json 4.0 ``` ```