@backtrader said in Implement stop loss:
No, under buy_price, because your are talking about stop-loss (you are in the market), people will understand the price at which you bought your asset and not the expected (and yet unknown) price at which the next order, the stop-loss one will execute.
Got this. I've declared a new variable which is store buy_price and updates it in notify order method with order.executed.price.
@scottz1 said in My Orders dont get Closed (wrong implementation of SL/TP?):
Looks ok basically. However,
remember to add logic for partial fills so the tp/sl orders will have the correct size.
remember to check existing position so as not to overwrite self.order and end up doubling your position.
One comment that I see.
I believe that we can remove the parameter on timeframe in stockkwargs so that it becomes as follows since we will be resampling the data anyway later on
stockkwargs = dict(
rtbar=False, # use RealTime 5 seconds bars
historical=True, # only historical download
qcheck=0.5, # timeout in seconds (float) to check for events
fromdate=datetime.datetime(2019, 9, 24), # get data from..
todate=datetime.datetime(2019, 9, 25), # get data from..
latethrough=False, # let late samples through
tradename=None # use a different asset as order target
No, it cannot work for me, because that doesn't read from Yahoo. It tries
@Mario-Pellegrini said in float division by zero:
It is not a random code since you also say that the ticker works
It is random, because you apparently want to read from Yahoo and apply Quandl. The code has also nothing to do with the code from the homepage (3 snippets) that directly reads data from Yahoo.
Why don't you start from one of the scripts on the home page, change the ticker to FCA.MI and then slowly modify it? The link again for your reference
One of the latest additions lets you do direct time comparisons directly to lines to generate signals. Probably nobody has used it yet. An example:
lines = ('mysignal',)
self.lines.mysignal = self.data.datetime > datetime.time(10, 30)
This generates an indicator which can be used as a signal to only execute orders when the daily time goes over 10:30.
But since you are probably looking for day, you'll need to work it out in the next method comparing the self.data.datetime.date() (maybe even getting the weekday) against something of your choosing
@Harel-Rozental said in Smart optimizations and Backtrader:
I managed to get my optimizations to run as quick as optstrategy by subclassing Cerebro and pulling out some stuff out of run() and addstrategy() into different functions (one to initialize data loading, and another which gets re-executed from outside the class for optimization).
I also manage multiprocessing from the outside.
Do you mind to share some code? Or kind of a layout of what and where was implemented in more details?
The problem is that the bricks need to be placed at a timestamp. At each timestamp you only have one output value for the lines of the data feed (in general these will be OHLC)
In summary: you cannot therefore generate multiple bricks. Generating bricks of dissimilar sizes, what you apparently have already achieved, is your only possibility.
@ab_trader - I am doing my best. I have already submitted pull requests for new Fisher Transform indicator and Simulated Order. And I am sharing all my code snippets here along with explanations whenever relevant.
When I say the framework should have this or that, I dont mean that someone should implement them but that we shall implement it for everybody's benefit.
@Laurent-Michelizza Thank you very much! when I log the position,I also find this question and use almost your way to solve it.
But in the future,I guess,we do a auto-close function when the future expires, it is more easy to use. After this four times reading the source code,I maybe try this function.