update
This commit is contained in:
parent
a43f4b77dc
commit
8354aa5acd
1 changed files with 37 additions and 10 deletions
|
|
@ -11,12 +11,23 @@ import { Order } from "../dao/order";
|
|||
import { supabase } from "./supabaseService";
|
||||
import { Wave } from "../dao/wave";
|
||||
|
||||
export type EventType = "HighVolatility" | "PinBar" | "EmaCross" | "MacdCross" | "MacdCrossUp" | "MacdCrossDown" | "Touch200" | "Reverse200";
|
||||
export type EventType =
|
||||
| "HighVolatility"
|
||||
| "PinBar"
|
||||
| "EmaCross"
|
||||
| "MacdCross"
|
||||
| "MacdCrossUp"
|
||||
| "MacdCrossDown"
|
||||
| "Touch200"
|
||||
| "Reverse200";
|
||||
|
||||
export interface EventHandler {
|
||||
onBuy: (candle: Order, reason: string) => void;
|
||||
onSell: (candle: Order, reason: string) => void;
|
||||
onEvent: (eventType: EventType, {candle, analysis}: {candle: Candle, analysis: Analysis}) => void;
|
||||
onEvent: (
|
||||
eventType: EventType,
|
||||
{ candle, analysis }: { candle: Candle; analysis: Analysis }
|
||||
) => void;
|
||||
}
|
||||
|
||||
export class IndicatorService {
|
||||
|
|
@ -233,7 +244,7 @@ export class IndicatorService {
|
|||
candles: Candle[],
|
||||
side: "buy" | "sell"
|
||||
): Order {
|
||||
const last10Candles = candles.slice(0, 12);
|
||||
const last10Candles = candles.slice(0, 5);
|
||||
const lowestPrice = last10Candles.reduce(
|
||||
(min, c) => Math.min(min, c.low),
|
||||
Number.MAX_SAFE_INTEGER
|
||||
|
|
@ -244,19 +255,29 @@ export class IndicatorService {
|
|||
);
|
||||
let entry = candles[0].close;
|
||||
if (side === "buy") {
|
||||
if (analysis.currentBB.upper < Math.max(candles[0].close, candles[0].open)) {
|
||||
if (
|
||||
analysis.currentBB.upper < Math.max(candles[0].close, candles[0].open)
|
||||
) {
|
||||
entry = analysis.currentBB.upper;
|
||||
}
|
||||
if (analysis.currentBB.lower < candles[0].open && analysis.currentBB.lower > candles[0].close) {
|
||||
if (
|
||||
analysis.currentBB.lower < candles[0].open &&
|
||||
analysis.currentBB.lower > candles[0].close
|
||||
) {
|
||||
entry = analysis.currentBB.lower;
|
||||
}
|
||||
}
|
||||
|
||||
if (side === "sell") {
|
||||
if (analysis.currentBB.lower > Math.min(candles[0].close, candles[0].open)) {
|
||||
if (
|
||||
analysis.currentBB.lower > Math.min(candles[0].close, candles[0].open)
|
||||
) {
|
||||
entry = analysis.currentBB.lower;
|
||||
}
|
||||
if (analysis.currentBB.upper > candles[0].open && analysis.currentBB.upper < candles[0].close) {
|
||||
if (
|
||||
analysis.currentBB.upper > candles[0].open &&
|
||||
analysis.currentBB.upper < candles[0].close
|
||||
) {
|
||||
entry = analysis.currentBB.upper;
|
||||
}
|
||||
}
|
||||
|
|
@ -277,12 +298,18 @@ export class IndicatorService {
|
|||
candles: Candle[],
|
||||
eventHandler: EventHandler
|
||||
) {
|
||||
if ((analysis.isTouch200 || analysis.isReverse200) && analysis.emaDirection === "Bullish") {
|
||||
if (
|
||||
(analysis.isTouch200 || analysis.isReverse200) &&
|
||||
analysis.emaDirection === "Bullish"
|
||||
) {
|
||||
const order = this.makeOrder(analysis, candles, "buy");
|
||||
eventHandler.onBuy(order, "Follow trend EMA Touch 200");
|
||||
return;
|
||||
}
|
||||
if ((analysis.isTouch200 || analysis.isReverse200) && analysis.emaDirection === "Bearish") {
|
||||
if (
|
||||
(analysis.isTouch200 || analysis.isReverse200) &&
|
||||
analysis.emaDirection === "Bearish"
|
||||
) {
|
||||
const order = this.makeOrder(analysis, candles, "sell");
|
||||
eventHandler.onSell(order, "Follow trend EMA Touch 200");
|
||||
return;
|
||||
|
|
@ -316,7 +343,7 @@ export class IndicatorService {
|
|||
}
|
||||
|
||||
if (analysis.isHighVolatility) {
|
||||
eventHandler.onEvent("HighVolatility", {candle: candles[0], analysis});
|
||||
eventHandler.onEvent("HighVolatility", { candle: candles[0], analysis });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue