-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapr_2026.strategy.ts
More file actions
81 lines (73 loc) · 1.83 KB
/
Copy pathapr_2026.strategy.ts
File metadata and controls
81 lines (73 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import {
addStrategySchema,
listenError,
listenActivePing,
Log,
Position,
commitClosePending,
getPositionPnlPercent,
getPositionEntryOverlap,
getPositionEntries,
commitAverageBuy,
} from "backtest-kit";
import { errorData, getErrorMessage, str } from "functools-kit";
const HARD_STOP = 25.0;
const TARGET_PROFIT = 3;
const LADDER_STEP_COST = 100;
const LADDER_UPPER_STEP = 5;
const LADDER_LOWER_STEP = 1;
const LADDER_MAX_STEPS = 10;
addStrategySchema({
strategyName: "apr_2026_strategy",
getSignal: async (symbol, when, currentPrice) => {
console.log(symbol, when.getTime())
return {
position: "long",
...Position.moonbag({
position: "long",
currentPrice,
percentStopLoss: HARD_STOP,
}),
minuteEstimatedTime: 50,
cost: LADDER_STEP_COST,
};
},
});
listenActivePing(async ({ symbol, currentPrice }) => {
const { length: steps } = await getPositionEntries(symbol);
if (steps >= LADDER_MAX_STEPS) {
return;
}
const hasOverlap = await getPositionEntryOverlap(symbol, currentPrice, {
upperPercent: LADDER_UPPER_STEP,
lowerPercent: LADDER_LOWER_STEP,
});
if (hasOverlap) {
return;
}
await commitAverageBuy(symbol, LADDER_STEP_COST);
});
listenActivePing(async ({ symbol, data, timestamp }) => {
console.log("active", symbol, timestamp)
const currentProfit = await getPositionPnlPercent(symbol);
if (currentProfit < TARGET_PROFIT) {
return;
}
Log.info("position closed due to the target pnl reached", {
symbol,
data,
});
await commitClosePending(symbol, {
id: "unknown",
note: str.newline(
"# Позиция закрыта по target pnl",
),
});
});
listenError((error) => {
console.log(error);
Log.debug("error", {
error: errorData(error),
message: getErrorMessage(error),
});
});