I want to develop a trading strategy in python, to test it with the help of backtrader.…
- User
I want to develop a trading strategy in python, to test it with the help of backtrader.
my strategy should track position loss value in points and open reverse stop position on specific threshold (for example -5000points of current position). I like the script to work on a minute chart timeframe.
I want the strategy to run intraday, within a specific timeframe (for example starting on 01:15 each day and stopping on 21:00).
On starting time the strategy should start with a loops. Aim of the loop is to open a reverse stop order with an increased lotsize (lotsize of related order * multiplier) everytime the related order hits the loss threshold.
On stopping time, the script should end up all tasks and close all active positions and go into sleep until next starting time.
The loop in detail should go like this (you already mentioned it pretty right in your previous answer) (additional info: I need to be able to change the parameters as easy as possible. Perhaps it would be best to make them accessible in a separate code file. In general I’m a very big fan of modular coding style. Everytime I use X in the following explanation I want a parameter):
on first time starting the loop it should open a market order in X Direction (BUY or SELL) with LotSize of X (default value 0.01). Than the Strategy should keep go on working like you mentioned in point 1-4 of your previous answer:
It should start tracking the loss of this position like you mentioned in point 1 of your previous answer. It should check as frequently as possible the entered Threshold of loss in points (X, default value is -5000points).
If the threshold is touched for the first time, a reverse stop market order should be opened with increased lotsize (calculated: lotsize original related order * multiplier (X = 5.0).
The old order should be closed.
The loop should restart: tracking the loss touching the threshold, closing and opening another reverse stop position with increased lotsize again.
The loop should getting repeated maximum X times (Parameter for MaxLoopCount, default value should be 5).
Do you understand or do you need more information for clarification?
- Assistant
Yes, I understand your requirements. You want to develop a trading strategy in Python using Backtrader that operates as follows:
- Timeframe: Minute chart timeframe (
1-minutedata). - Trading Window: The strategy runs intraday within a specific timeframe (e.g., starting at
01:15and stopping at21:00each day). - Initial Position: At the starting time, the strategy opens a market order in a specified direction ( or ) with an initial lot size (default ).
- Timeframe: Minute chart timeframe (