update refactor
This commit is contained in:
parent
01abc7e446
commit
55ad0607f3
39 changed files with 4304 additions and 584 deletions
27
src/services/indicatorService.ts
Normal file
27
src/services/indicatorService.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { EMA, MACD } from 'technicalindicators';
|
||||
import { Candle } from '../dao/candles';
|
||||
|
||||
export function analyze(candles: Candle[]): { ema34: number; ema200: number; macd: any } {
|
||||
let close = candles.map(c => c.close);
|
||||
const ema34 = EMA.calculate({ period: 34, values: close, reversedInput: true });
|
||||
const ema200 = EMA.calculate({ period: 200, values: close, reversedInput: true });
|
||||
const macd = MACD.calculate({
|
||||
values: close,
|
||||
fastPeriod: 45,
|
||||
slowPeriod: 90,
|
||||
signalPeriod: 9,
|
||||
SimpleMAOscillator: false,
|
||||
SimpleMASignal: false,
|
||||
reversedInput: true
|
||||
});
|
||||
const candle = candles[0];
|
||||
if (candle.low < ema200[0] && candle.high > ema200[0] && candle.close > ema200[0]) {
|
||||
console.log('Buy');
|
||||
}
|
||||
|
||||
if (candle.high > ema200[0] && candle.low < ema200[0] && candle.close < ema200[0]) {
|
||||
console.log('Sell');
|
||||
}
|
||||
|
||||
return { ema34: ema34[0], ema200: ema200[0], macd: macd[0] };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue