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 { supabase } from "./supabaseService";
|
||||||
import { Wave } from "../dao/wave";
|
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 {
|
export interface EventHandler {
|
||||||
onBuy: (candle: Order, reason: string) => void;
|
onBuy: (candle: Order, reason: string) => void;
|
||||||
onSell: (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 {
|
export class IndicatorService {
|
||||||
|
|
@ -233,7 +244,7 @@ export class IndicatorService {
|
||||||
candles: Candle[],
|
candles: Candle[],
|
||||||
side: "buy" | "sell"
|
side: "buy" | "sell"
|
||||||
): Order {
|
): Order {
|
||||||
const last10Candles = candles.slice(0, 12);
|
const last10Candles = candles.slice(0, 5);
|
||||||
const lowestPrice = last10Candles.reduce(
|
const lowestPrice = last10Candles.reduce(
|
||||||
(min, c) => Math.min(min, c.low),
|
(min, c) => Math.min(min, c.low),
|
||||||
Number.MAX_SAFE_INTEGER
|
Number.MAX_SAFE_INTEGER
|
||||||
|
|
@ -244,19 +255,29 @@ export class IndicatorService {
|
||||||
);
|
);
|
||||||
let entry = candles[0].close;
|
let entry = candles[0].close;
|
||||||
if (side === "buy") {
|
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;
|
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;
|
entry = analysis.currentBB.lower;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (side === "sell") {
|
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;
|
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;
|
entry = analysis.currentBB.upper;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -277,12 +298,18 @@ export class IndicatorService {
|
||||||
candles: Candle[],
|
candles: Candle[],
|
||||||
eventHandler: EventHandler
|
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");
|
const order = this.makeOrder(analysis, candles, "buy");
|
||||||
eventHandler.onBuy(order, "Follow trend EMA Touch 200");
|
eventHandler.onBuy(order, "Follow trend EMA Touch 200");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((analysis.isTouch200 || analysis.isReverse200) && analysis.emaDirection === "Bearish") {
|
if (
|
||||||
|
(analysis.isTouch200 || analysis.isReverse200) &&
|
||||||
|
analysis.emaDirection === "Bearish"
|
||||||
|
) {
|
||||||
const order = this.makeOrder(analysis, candles, "sell");
|
const order = this.makeOrder(analysis, candles, "sell");
|
||||||
eventHandler.onSell(order, "Follow trend EMA Touch 200");
|
eventHandler.onSell(order, "Follow trend EMA Touch 200");
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue