update
This commit is contained in:
parent
dbf3b758fe
commit
e45c62215e
3 changed files with 723 additions and 35 deletions
|
|
@ -1,27 +1,54 @@
|
|||
import { EMA, MACD } from 'technicalindicators';
|
||||
import { Candle } from '../dao/candles';
|
||||
import { EMA, MACD } from "technicalindicators";
|
||||
import { Candle } from "../dao/candles";
|
||||
import { analyzeCandleSequence } from "../helpers/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');
|
||||
export class IndicatorService {
|
||||
constructor() {}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
const candleAnalysis = analyzeCandleSequence([
|
||||
candles[2],
|
||||
candles[1],
|
||||
candles[0],
|
||||
]);
|
||||
|
||||
return { ema34: ema34[0], ema200: ema200[0], macd: macd[0] };
|
||||
}
|
||||
|
||||
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