Skip to content

Commit 9aca84e

Browse files
committed
Began working on extended Trader.
1 parent 18941d3 commit 9aca84e

File tree

1 file changed

+46
-63
lines changed

1 file changed

+46
-63
lines changed

source/Trader.php

Lines changed: 46 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,80 +2,42 @@
22

33
namespace LupeCode\phpTraderInterface;
44

5+
/**
6+
* Class Trader
7+
*
8+
* This class extends the original extension to include friendlier names.
9+
*
10+
* @package LupeCode\phpTraderInterface
11+
*/
512
class Trader
613
{
714

8-
const TRADER_MA_TYPE_SMA = 0;
9-
const TRADER_MA_TYPE_EMA = 1;
10-
const TRADER_MA_TYPE_WMA = 2;
11-
const TRADER_MA_TYPE_DEMA = 3;
12-
const TRADER_MA_TYPE_TEMA = 4;
13-
const TRADER_MA_TYPE_TRIMA = 5;
14-
const TRADER_MA_TYPE_KAMA = 6;
15-
const TRADER_MA_TYPE_MAMA = 7;
16-
const TRADER_MA_TYPE_T3 = 8;
17-
const TRADER_REAL_MIN = -3.0000000000000002E+37;
18-
const TRADER_REAL_MAX = 3.0000000000000002E+37;
19-
const TRADER_FUNC_UNST_ADX = 0;
20-
const TRADER_FUNC_UNST_ADXR = 1;
21-
const TRADER_FUNC_UNST_ATR = 2;
22-
const TRADER_FUNC_UNST_CMO = 3;
23-
const TRADER_FUNC_UNST_DX = 4;
24-
const TRADER_FUNC_UNST_EMA = 5;
25-
const TRADER_FUNC_UNST_HT_DCPERIOD = 6;
26-
const TRADER_FUNC_UNST_HT_DCPHASE = 7;
27-
const TRADER_FUNC_UNST_HT_PHASOR = 8;
28-
const TRADER_FUNC_UNST_HT_TRENDLINE = 10;
29-
const TRADER_FUNC_UNST_HT_TRENDMODE = 11;
30-
const TRADER_FUNC_UNST_KAMA = 12;
31-
const TRADER_FUNC_UNST_MAMA = 13;
32-
const TRADER_FUNC_UNST_MFI = 14;
33-
const TRADER_FUNC_UNST_MINUS_DI = 15;
34-
const TRADER_FUNC_UNST_MINUS_DM = 16;
35-
const TRADER_FUNC_UNST_NATR = 17;
36-
const TRADER_FUNC_UNST_PLUS_DI = 18;
37-
const TRADER_FUNC_UNST_PLUS_DM = 19;
38-
const TRADER_FUNC_UNST_RSI = 20;
39-
const TRADER_FUNC_UNST_STOCHRSI = 21;
40-
const TRADER_FUNC_UNST_T3 = 22;
41-
const TRADER_FUNC_UNST_ALL = 23;
42-
const TRADER_FUNC_UNST_NONE = -1;
43-
const TRADER_COMPATIBILITY_DEFAULT = 0;
44-
const TRADER_COMPATIBILITY_METASTOCK = 1;
45-
const TRADER_ERR_SUCCESS = 0;
46-
const TRADER_ERR_LIB_NOT_INITIALIZE = 1;
47-
const TRADER_ERR_BAD_PARAM = 2;
48-
const TRADER_ERR_ALLOC_ERR = 3;
49-
const TRADER_ERR_GROUP_NOT_FOUND = 4;
50-
const TRADER_ERR_FUNC_NOT_FOUND = 5;
51-
const TRADER_ERR_INVALID_HANDLE = 6;
52-
const TRADER_ERR_INVALID_PARAM_HOLDER = 7;
53-
const TRADER_ERR_INVALID_PARAM_HOLDER_TYPE = 8;
54-
const TRADER_ERR_INVALID_PARAM_FUNCTION = 9;
55-
const TRADER_ERR_INPUT_NOT_ALL_INITIALIZE = 10;
56-
const TRADER_ERR_OUTPUT_NOT_ALL_INITIALIZE = 11;
57-
const TRADER_ERR_OUT_OF_RANGE_START_INDEX = 12;
58-
const TRADER_ERR_OUT_OF_RANGE_END_INDEX = 13;
59-
const TRADER_ERR_INVALID_LIST_TYPE = 14;
60-
const TRADER_ERR_BAD_OBJECT = 15;
61-
const TRADER_ERR_NOT_SUPPORTED = 16;
62-
const TRADER_ERR_INTERNAL_ERROR = 5000;
63-
const TRADER_ERR_UNKNOWN_ERROR = 65535;
15+
use TraderTrait;
6416

6517
/**
18+
* Vector arc cosine
6619
* Calculates the arc cosine for each value in real and returns the resulting array.
6720
*
6821
* @param array $real Array of real values.
6922
*
7023
* @return array Returns an array with calculated data or false on failure.
7124
*/
72-
public static function acos(array $real): array
25+
public static function mathArcCosine(array $real): array
7326
{
7427
return trader_acos($real);
7528
}
7629

7730
/**
78-
* Chaikin A/D Line
31+
* Chaikin Accumulation Distribution Line
32+
*
33+
* This indicator is a volume based indicator developed by Marc Chaikin which measures the cumulative flow of money into and out of an instrument.
34+
* The A/D line is calculated by multiplying the specific period’s volume with a multiplier that is based on the relationship of the closing price to the high-low range.
35+
* The A/D Line is formed by the running total of the Money Flow Volume. This indicator can be used to assert an underlying trend or to predict reversals.
36+
*
37+
* The combination of a high positive multiplier value and high volume indicates buying pressure.
38+
* So even with a downtrend in prices when there is an uptrend in the Accumulation Distribution Line there is indication for buying pressure (accumulation) that may result to a bullish reversal.
39+
*
40+
* Conversely a low negative multiplier value combined with, again, high volumes indicates selling pressure (distribution).
7941
*
8042
* @param array $high High price, array of real values.
8143
* @param array $low Low price, array of real values.
@@ -84,7 +46,7 @@ public static function acos(array $real): array
8446
*
8547
* @return array Returns an array with calculated data or false on failure.
8648
*/
87-
public static function ad(array $high, array $low, array $close, array $volume): array
49+
public static function chaikinAccumulationDistributionLine(array $high, array $low, array $close, array $volume): array
8850
{
8951
return trader_ad($high, $low, $close, $volume);
9052
}
@@ -97,13 +59,22 @@ public static function ad(array $high, array $low, array $close, array $volume):
9759
*
9860
* @return array Returns an array with calculated data or false on failure.
9961
*/
100-
public static function add(array $real0, array $real1): array
62+
public static function mathAddition(array $real0, array $real1): array
10163
{
10264
return trader_add($real0, $real1);
10365
}
10466

10567
/**
106-
* Chaikin A/D Oscillator
68+
* Chaikin Accumulation Distribution Oscillator
69+
*
70+
* Chaikin Oscillator is positive when the 3-day EMA moves higher than the 10-day EMA and vice versa.
71+
*
72+
* The Chaikin Oscillator is the continuation of the Chaikin A/D Line and is used to observe changes in the A/D Line.
73+
*
74+
* The oscillator is based on the difference between the 3-day Exponential Moving Average (EMA) of the A/D Line and the 10-day EMA of the A/D Line and hence adds momentum to the A/D Line.
75+
* It is helpful for investors to use the Oscillator in order to determine the appropriate timing of trend reversals.
76+
*
77+
* When the Chaikin Oscillator turns positive there is indication that the A/D Line will increase and hence a Bullish (buy) signal will be generated. On the other hand a move into negative territory indicates a Bearish (sell) signal.
10778
*
10879
* @param array $high High price, array of real values.
10980
* @param array $low Low price, array of real values.
@@ -114,22 +85,33 @@ public static function add(array $real0, array $real1): array
11485
*
11586
* @return array Returns an array with calculated data or false on failure.
11687
*/
117-
public static function adosc(array $high, array $low, array $close, array $volume, integer $fastPeriod = null, integer $slowPeriod = null): array
88+
public static function chaikinAccumulationDistributionOscillator(array $high, array $low, array $close, array $volume, integer $fastPeriod = null, integer $slowPeriod = null): array
11889
{
11990
return trader_adosc($high, $low, $close, $volume, $fastPeriod, $slowPeriod);
12091
}
12192

12293
/**
12394
* Average Directional Movement Index
12495
*
96+
* Developed by J. Welles Wilder and described in his book “New Concepts in Technical Trading Systems”, the Average Directional Movement Index (ADX) is a technical indicator that describes if a market or a financial instrument is trending or not.
97+
*
98+
* The ADX is a combination of two other indicators developed by Wilder, the positive directional indicator (+DI) and the negative directional indicator (-DI).
99+
*
100+
* Wilder recommends buying when +DI is higher than -DI, and selling when +DI is lower than -DI.
101+
*
102+
* The ADX indicates trend strength, not trend direction, and it is a lagging indicator.
103+
*
104+
* ADX range is between 0 and 100. Generally ADX readings below 20 indicate trend weakness, and readings above 40 indicate trend strength.
105+
* An extremely strong trend is indicated by readings above 50.
106+
*
125107
* @param array $high High price, array of real values.
126108
* @param array $low Low price, array of real values.
127109
* @param array $close Closing price, array of real values.
128110
* @param int|null $timePeriod Number of period. Valid range from 2 to 100000.
129111
*
130112
* @return array Returns an array with calculated data or false on failure.
131113
*/
132-
public static function adx(array $high, array $low, array $close, integer $timePeriod = null): array
114+
public static function averageDirectionalMovementIndex(array $high, array $low, array $close, integer $timePeriod = null): array
133115
{
134116
return trader_adx($high, $low, $close, $timePeriod);
135117
}
@@ -2388,4 +2370,5 @@ public static function wma(array $real, integer $timePeriod = null): array
23882370
return trader_wma($real, $timePeriod);
23892371
}
23902372

2373+
23912374
}

0 commit comments

Comments
 (0)