Summary
Because theres no built in order method for a trailing stop loss, an approach was developed to address this issue, heres a quick summary of how it works
Note: This method was developed assuming a holding period of less than a day, it begins 10 minutes after the morning bell & ends 10 minutes before close. There should be no issue converting this to compensate for the time since buying the position
How it works
1. The current price is tracked
2. The time since market open is tracked to later be referenced in data.history
The get_datetime function is referenced, converted to a string, sliced to find desired fields, then split between hours and minutes
The hours and minutes are then converted to integers & adjusted to account for the time of market open (hours set to 0 at market open and multiplied by 60 to convert to minutes).. (minutes set to 0 at market open) both hours and minutes are then added
- data.history is then referenced using the time since market open in the window_length field.
This is then converted to a list and pythons max( ) function is used to find the highest price since market open - Actually the rest is explained in the algo