-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrade_insertion.sql
More file actions
67 lines (66 loc) · 2.31 KB
/
Copy pathtrade_insertion.sql
File metadata and controls
67 lines (66 loc) · 2.31 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
-- SQL Insert Statement for Trade Data based on Specific Conditions
-- Author: Ruslana Kruk
INSERT INTO Trades
(Level_Type,
Level_Description,
Level_Information,
Ticker,
Level_Interval,
Level_Time,
Level_Cost,
Time_Start,
Work_Interval,
Work_Max_Day,
Entry_Point,
Stop_Loss,
Take_Profit)
SELECT
'LOW BSU+BPU1+BPU2' AS Level_Type,
'SL 0.01 $, TP - 0.09 $' AS Level_Description,
TO_CHAR(MIN(Bpu_2.Row_Num_Asc) - MIN(Bsu.Row_Num_Asc) + 1) || ' - BSU Distance' AS Level_Information,
Bsu.Ticker,
Bsu.Interval,
MIN(Bpu_2.Interval_Date_Time) AS Level_Time,
Bsu.Low,
MIN(Bpu_2.Interval_Date_Time) + 1 / 24 / 2 + 1 / 24 / 12 AS Time_Start,
'5m' AS Work_Interval,
TRUNC(MIN(Bpu_2.Interval_Date_Time)) + 1 - 1 / 24 AS Work_Max_Day,
-- Calculating Entry Point, Stop Loss, and Take Profit
Bsu.Low + 0.0 AS Entry_Point,
Bsu.Low - 0.05 AS Stop_Loss,
Bsu.Low + 0.1 AS Take_Profit
FROM
Intraday Bsu
JOIN
Tickers t ON t.Ticker = Bsu.Ticker
AND NVL(t.Ticker_Type, 'NOT') <> 'CRYPTO'
JOIN
Intraday Bpu_1 ON Bpu_1.Ticker = Bsu.Ticker
AND Bpu_1.Interval = Bsu.Interval
AND TRUNC(Bpu_1.Interval_Date_Time) = TRUNC(Bsu.Interval_Date_Time)
AND Bpu_1.Row_Num_Asc = Bsu.Row_Num_Asc + 1
AND Bpu_1.Low = Bsu.Low
JOIN
Intraday Bpu_2 ON Bpu_2.Ticker = Bpu_1.Ticker
AND Bpu_2.Interval = Bpu_1.Interval
AND TRUNC(Bpu_2.Interval_Date_Time) = TRUNC(Bpu_1.Interval_Date_Time)
AND Bpu_2.Row_Num_Asc = Bpu_1.Row_Num_Asc + 1
AND Bpu_2.Low = Bpu_1.Low
JOIN
Intraday Bpu_3 ON Bpu_3.Ticker = Bpu_2.Ticker
AND Bpu_3.Interval = Bpu_2.Interval
AND TRUNC(Bpu_3.Interval_Date_Time) = TRUNC(Bpu_2.Interval_Date_Time)
AND Bpu_3.Row_Num_Asc = Bpu_2.Row_Num_Asc + 1
AND Bpu_3.Low = Bpu_2.Low
WHERE
1 = 1 -- Placeholder for additional conditions
AND Bsu.Interval_Date_Time >= TRUNC(SYSDATE - 2)
AND Bsu.Interval = '30m'
GROUP BY
Bsu.Ticker,
Bsu.Interval,
Bsu.Low
ORDER BY
MIN(Bpu_2.Interval_Date_Time) DESC,
1;
COMMIT;