Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
romulodl committed May 26, 2020
0 parents commit 341f185
Show file tree
Hide file tree
Showing 8 changed files with 1,854 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# editorconfig.org
root = true

[*]
indent_style = space
end_of_line = lf
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{html,twig,md}]
indent_size = 2

[*.php]
charset = utf-8
indent_style = tab
indent_size = 4

[*.md]
trim_trailing_whitespace = false
16 changes: 16 additions & 0 deletions .github/workflows/macd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Macd

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: php-actions/composer@v1
- name: run tests
run: vendor/bin/phpunit tests/* --testdox
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Moving Average Convergence/Divergence

Calculate the MACD of giving values.

![Ema](https://github.com/romulodl/macd/workflows/Macd/badge.svg)

## Instalation

```
composer require romulodl/macd
```

or add `romulodl/macd` to your `composer.json`. Please check the latest version in releases.

## Usage

```php
$macd = new Romulodl\Macd();
$macd->calculate(array $values, array $previous_values = [], int $short_period = 12, int $long_period = 26);
//returns a float value
```

For example:
```php
$macd = new Romulodl\Macd();
$macd->calculate([10, 12, 14, 20, 14, 10, 11]);
```

#### What is `$previous_values` for?

The EMA calculation (used by the MACD) is based on the previous round of calculation. So the n round depends on n - 1 results.
Then what is n - 1 for the first calculation? If `$previous_values` is not available, it uses a simple moving average
for it. With `$previous_values` set, it will start the calculation of the EMA before and the result will be more
accurate (at least closest to what Trading view shows.)

It is recommended that you use the same ammount of `$values` and `$previous_values` for more accurate results. FOr example, send the previous 26 values when calculating a default MACD(12, 26).


## Why did you do this?

The PECL Trading extension is crap and not everyone wants to install it.
I am building a trading bot and building more complex trading indicators that uses the MACD as a basic step.
22 changes: 22 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "romulodl/macd",
"description": "MACD without the PECL trader extension",
"license": "Apache-2.0",
"require-dev": {
"phpunit/phpunit": "^8.5"
},
"authors": [
{
"name": "Romulo De Lazzari",
"email": "romulodelazzari@gmail.com"
}
],
"require": {
"romulodl/ema": "^1.3"
},
"autoload": {
"psr-4": {
"Romulodl\\": "src/"
}
}
}
Loading

0 comments on commit 341f185

Please sign in to comment.