Thank you about that information. I didn't catch that cerebro contain the indicator and that I can query them . This is indeed more simpler. Will update the code and may publish that code as a pytest fixture anyway.
@dongiulio said in problem with bracket orders:
maybe I could work it around (actually just diminish the bias) by backtesting with minute candles and resampling it to hour?
You would need to replay, to be able to work with the ticks of the lower timeframe whilst the higher timeframe is being built. Resampling does only tick when the higher timeframe bar is complete.
@sfkiwi Thanks for making the basis of this.
Though this thread is old, hopefully this will help anyone getting results they are not expecting.
But I think at the end of your code it looks like you have k and d calc backwards to have it match tradingview.
self.l.D = D = self.p.movav(stoch, period=self.p.period_dfast)
self.l.K = self.p.movav(D, period=self.p.period_kslow)
self.l.K = K = self.p.movav(stoch, period=self.p.period_kslow)
self.l.D = self.p.movav(K, period=self.p.period_dfast)
I was using IDLE and running the script with F5
It works OK when executed from the command line.
As a suggestion, you could add a warning on the quickstart tutorial, just saying that the optimization uses multiprocessing.
The InfluxData was a contribution by one of the users.
Wrapping a relational database (or for the sake of it, wrapping anything), simply requires:
That you override AbstractDatabase
That you translate the parameters to the data feed to a query (during __init__ or start), which may include the name of the file holding the db (for sqlite for example), and the starting and ending dates. If you were using arctic it could also use things like timeframe and compression to select specific stores
That you fill the lines (usually open, high, low, volume and maybe openinterest) during _load
See: Docs - Binary Data Feed Development
@backtrader Thanks for replying, and I am sorry this might be a noob question and also I didn't make that clear enough.
I was just trying to say that if the take profit/cut loss leg is not executed in my python, I will always hold a position in my python, and my algo will never send any new orders to Oanda ever after.
And what do you mean by "there isn't a log of prices which are being reached?" could you please clarify a little bit?
thanks a lot and happy new year.
Here is another way to plot an independent equity curve based on bokeh. I apologize for shitty code. This way, I don't have to turn off cerebro's built in
pretty plotting such as buysell observers.
# This assumes that you have added a strategy
# the value observer
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np
from matplotlib.ticker import LinearLocator, FormatStrFormatter
from matplotlib.dates import num2date
import seaborn as sns
from bokeh.io import show
from bokeh.layouts import column
from bokeh.models import ColumnDataSource, RangeTool
from bokeh.plotting import figure, output_file
for observer in strategy.getobservers():
linealias = observer.lines._getlinealias(0)
if linealias ==alias:
dates = np.array(strategy.datetime.plot())
ydata = np.array(observer.line.plot())
dates = num2date(dates)
output_file("equity.html", title="equity line")
TOOLS = "pan,wheel_zoom,box_zoom,reset,save"
source = ColumnDataSource(data=dict(date=dates, value=values))
p = figure(plot_height=300, plot_width=600, tools=TOOLS,
background_fill_color="#efefef", x_range=(dates, dates[-1]))
p.line('date', 'value', source=source)
p.yaxis.axis_label = 'value'
select = figure(title="Drag the middle and edges of the selection box to change the range above",
plot_height=130, plot_width=600, y_range=p.y_range,
tools="", toolbar_location=None, background_fill_color="#efefef")
range_rool = RangeTool(x_range=p.x_range)
range_rool.overlay.fill_color = "navy"
range_rool.overlay.fill_alpha = 0.2
select.line('date', 'value', source=source)
select.ygrid.grid_line_color = None
select.toolbar.active_multi = range_rool
@deedy said in Broker.get_value() on multiple instruments:
If you pass the complete list of data feeds, you will get the value of the complete portfolio.
If you pass an iterable with less data feeds, you will get only the value for the data feeds included in that iterable.
If you pass an iterable with one data feed, you will get only the value for the included data feed.
You then don't need a live behavior from cerebro. You need a data feed which declares its end (like any regular CSV feed does, for example). When the data is exhausted you will be then taken to the stop method of your strategy and you can decide whether what the last next triggered/calculated is of your interest or not to issue a trade.
See Docs - Strategy - the lifecycle is explained right at the beginning.
When new candles come in, you rerun the cerebro setup (i.e.: create feed, add feed, add strategy, run cerebro)