Multiple Data Buy/Sell
-
So, I got two data set feeds to the cerebro.
And within my strategy, I want to pass the first data as buy price, the second data as sell price.
But it seems that the platform can only support buy&sell on the same data set.
It is possible to pass the buy/sell price from two different data source accordingly?
Thanks!
-
Without knowing the details I would suggest to check the following:
-
if you want just use these two datafeed as buy/sell prices (for example, for stop or limit orders) then it can be better to add them to the
bt
as an indicator -
and finally if you just want to accumulate long positions on 1st data and sort positions on 2nd data then use the common approach:
order = self.buy(data=<your data 1>, ...) order = self.sell(data=<your data 2>, ...)
-
Thank you for your reply!
@ab_trader said in Multiple Data Buy/Sell:
- and finally if you just want to accumulate long positions on 1st data and sort positions on 2nd data then use the common approach:
order = self.buy(data=<your data 1>, ...) order = self.sell(data=<your data 2>, ...)
Yeah, I tried this approach, but it will mark buy/sell on different data.
What I want to do is when I accumulate short positions, I pass the price from data_2, but not performing short on this data.- if you want just use these two datafeed as buy/sell prices (for example, for stop or limit orders) then it can be better to add them to the bt as an indicator
Can you give me an example to do so? Not sure how to pass the indicator as a price.
-
@Michael-Scofield said in Multiple Data Buy/Sell:
What I want to do is when I accumulate short positions, I pass the price from data_2, but not performing short on this data.
Sorry, but I don't understand what you are trying to achieve. If you can put more details about your trading logic (what data to buy or sell, what prices to use, what data should be skipped in what conditions etc), then I give it another try.
-
@ab_trader said in Multiple Data Buy/Sell:
docs - futures and spot compensation
You probably want to read what @ab_trader already posted above. The link again for reference:
It would seem you simply skipped that part of the answer and went for low hanging fruits.
-
@ab_trader
Again thanks for replying, glad to see this!So, here is what I want to do :
def __init__(self): self.dataopenBid = self.dnames.data_Bid.openBid[0] "<--data_Bid is my first data feed" self.dataopenAsk = self.dnames.data_Ask.openAsk[0] "<--data_Ask is my second data feed" def next(self): # Initial order will be returned if self.order: return # If now does have any order in the system, check go long or short if not self.position: if self.sma > self.dataopenBid: self.order = self.buy(data = self.dnames.data_Bid, price = self.dataopenAsk[0]) else: self.order = self.sell(data = self.dnames.data_Bid, price = self.dataopenBid[0])
But the
order.executed.price
will always be theopen
of my first data :data_Bid
.Not sure whats wrong, so now I use
Mid
data for execution price.Bid
andAsk
data for generating signal.
Now theorder.executed.price
forbuy
order will beopenMid
and thesell
order will becloseMid
, which is quit good for me.Btw, you mentioned :
- if you want just use these two datafeed as buy/sell prices (for example, for stop or limit orders) then it can be better to add them to the
bt
as an indicator
Could you give me an example to do this?
- if you want just use these two datafeed as buy/sell prices (for example, for stop or limit orders) then it can be better to add them to the
-
@Paska-Houso
Thanks for replying.
Check it later. -
Let me try. First, you are issuing market orders in your
next()
, so no price (even specified) should be taken into account.bt
will useopen
of the next bar to process the order.I believe that you can use single data feed with
bid
price asopen
andask
price asclose
. If yourask
always higher thenbid
try to usestop
order to buy atask
.self.order = self.buy(data = self.dnames.data_Bid, exectype=Order.Stop, price = self.dataopenAsk[0])
About the indicator - let try to make it without it.
-
@ab_trader I really think you nailed it with the Future and spot compensation. The functionality was probably thought with other use in mind, but it seems to perfectly fit the use case.
- Data and Bid have always a spread just like the future and the spot price
- The compensation feature in backtrader allows to link both together, so that individual actions on one of the data feeds compensates the actions of the other.
Obviously, bid and ask in this case belong to the same asset, but the concept is applicable. @Michael-Scofield should really look into that part of the documentation/blog and build upon it.
-
@Paska-Houso I didn't get deeply into that futures - spot compensation and also never used it in my trading. If it works, then cool.
-
Hey, thanks for replying again. So, I have toke a look on that document.
I think you are right, it fits what I need.Is there any update documents for this library?
It seems that the Backtrader Docs is a bit outdate.
Many improvement of this library didn't well complied into the docs. -
@Michael-Scofield: the docs have the same version as the package.
What is missing?