Problem with Cerebro engine
Hello! I am new in python and especcially in backtrader. I run example and get error
It's shame for me to ask such stupid question, but I do only first steps.
Pasting images, even if you may think is visually attractive, is not really helpful, because quoting isn't possible.
I suggest you have a look at the error trace ... far away from the arrow ... and close to the bottom where it says: "No such file or directory", which means you need to place the file in the place where you are telling the data feed it should be.
Thank you for an answer.
But I really thought it should download data from Yahoo Server and I dont need to save candles in file.
You are using a data feed named:
YahooFinanceCSVDatawhich loads the data from a CSV file. File to which you are pointing in the
If you want to go online, you can use the example from the homepage: https://www.backtrader.com where
YahooFinanceDatais used (the sources contain also multiple examples)
@backtrader thank you, but it doesn't help.
pip install requests
solved the problem
Let me ask another question.
I started the script posted on your main page as example. I didn't change any line.
But it ignored very important signal as you can see on my picture.
Cross of movings was ignored. Why this happened?
You log no information at all and that's the reason you cannot even start seeing why and provide info on the topic. If you want to algotrade, you should produce lots of debugging/logging info.
It was probably an accident waiting to happen.
The definition of a
upcross = data0(-1) < data1(-1) and data0(0) > data1(0)
downcross = data0(-1) > data1(-1) and data0(0) < data1(0)
crossover = upcross - downcross
Although it seems comprehensive a crossing to the upside, for example, it will fail if
data0(-1) < data1(-1)happens to be
0, even if
data0(0) > data1(0). All the values before the index
-1may have granted a crossing upwards, but at time
-1, the difference is nullified and the definition loses sense.
Because Yahoo adjusts the data after dividends and splits, the point yo mark as "In" is one in which both Simple Moving Averages have the same value before the crossing upwards, which as explained above makes the definition fail.
Before Yahoo adjusted the prices, this went unnoticed and because Yahoo will again adjust the prices it could have gone unnoticed forever.
This be fixed by redefining
CrossOverto take into account what happened before the 2 input sources (in the example two moving averages) happened to be the same.
To be included in a release tomorrow.
@backtrader thank you for your answer, but I am not so stupid as you think about me (joke). On your image on backtrader main page these deals WERE MADE:
Regardless of the joke, you seem to completely miss the point, because you post the chart from the main page. To what purpose, unknown.
If you do something and the results are not the expected ones ... a chart IS NOT the answer. Any attempt at being profitable at algotrading will require producing lots of information.
How do you think that I quickly identified the problem and why the actual data delivered by
Yahoodoesn't match what is displayed as an example on the main page?
0242,2011-12-15,21.44,21.57,21.29,21.30,smas,21.31,21.39,crossover,0.00 0243,2011-12-16,21.40,21.81,21.36,21.67,smas,21.38,21.38,crossover,0.00 0244,2011-12-19,21.69,21.77,21.22,21.28,smas,21.36,21.36,crossover,0.00 0245,2011-12-20,21.55,21.75,21.51,21.70,smas,21.39,21.35,crossover,0.00
As you may see the first thing was producing output to understand that the moving averages were converging during two days to have exactly the same values
21.36. That's why the original definition of the
CrossOverindicator is not able to cope with the scenario, because when
sma1 > sma2, the condition for the previous day isn't met (it was
sma1 < sma2), because the moving averages had exactly the same value.
Hence the need to change the definition and make the crossover formula consider the last non-zero-difference between the input data feeds, which as shown in the data is -0.08 from
2011-12-15where the values are
You have to consider additionally that the input data will keep on changing, fact which you apparently ignore because you seem fixed on the chart from the main pge, because the prices will be adjusted for dividends and splits. In one year, the prices from MSFT may be halved or doubled and bear no apparent relationship to the chart from the main page.
This adjustment is what actually created the no-difference conundrum which shows that the simple formula to define a crossover (present in the documentation) was too simple and needed to be extended.