-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlong_exit.txt
More file actions
37 lines (37 loc) · 2.1 KB
/
long_exit.txt
File metadata and controls
37 lines (37 loc) · 2.1 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
(* Position exit requirements are as follows. Either:
- C < n-date/time low
OR
- C < the highest open trade entry price for all positions minus 2 times TREMA
*)
let long_position_id_start = position_id_start |> int
let position_states =
[long_position_id_start..long_position_id_start+3]
(* Convert position IDs to the corresponding position states. *)
|> List.map (fun id -> system_state.position_states.[id])
(* Discard position states that do not exist for the previous date/time. *)
|> List.choose (function | Initial -> None | From_Previous_Date_Time position_state -> Some position_state)
(* If any position state did not exist for the previous date/time, return no signal. *)
if List.length position_states < 4 then None, None
else
let output =
(* Get the entry prices for all open trades for all positions. *)
match
position_states |> List.collect (fun position_state ->
position_state.open_trades |> List.map (fun trade ->
trade.entry_price
)
)
with
(* If there are no open trades, then the exit requirement is C < n-date/time low. *)
| [] ->
let result = c < low
output.Add("long_1_exit_tag", Bool result).Add("long_2_exit_tag", Bool result).Add("long_3_exit_tag", Bool result).Add("long_4_exit_tag", Bool result)
| xs ->
(* If there are open trades, get the highest open trade entry price. *)
let highest_entry_price = xs |> List.max
(* The exit requirement is either C < n-date/time low or C < the highest open trade entry price minus 2 times TREMA. *)
let result = c < low || c < highest_entry_price - (2.0 * trema)
(* The entry or exit signal tag value has type Bool. *)
output.Add("long_1_exit_tag", Bool result).Add("long_2_exit_tag", Bool result).Add("long_3_exit_tag", Bool result).Add("long_4_exit_tag", Bool result)
(* The first return value is for storing user-defined state. The second return value is the output data item. *)
None, Some output