Tracking entry signal for trade
Hope I am not over using my question credits here... :slight_smile:
I have a requirement to track the signal that triggered a trade entry. Wondering if there is some place to track that as part of the trade transaction.
If I enter a trade on a particular signal (market in downtrend), I want to exit around a particular set of signals applied to trades made in the downtrend.
I have cases where that trend changes while the position is open which is setting up another set of exit signals applied in the new market condition.
Is there a place to do this in the API?
addinfo()object might be a way to do what I want but could use a bit of an example of how to apply this if that is the right direction.
addinfocan help. It simply takes
**kwargsand stores then under
infois just a
But since this seems to be more
tradeoriented than order oriented, you would need to track information at
tradehistory=Truein either ´cerebro = Cerebro(**kwargs)
The trades notified in
- Record events under
list) and these events contain the order which generated then.
In most cases a trade is made up of just 2 orders:
- Opening order
- Closing order
If you add some information to the opening order with
addinfo, you can always retrieve it from the
dicthas been extended to support dot notation)
Not really elegant, because one has to keep track of the trades and there is really no advantage with regards to keeping the information in own structures.
Sorry, walking around in the debugger here and not quite connecting the dots...
I'm working in
Strategy next(), and don't see where I can get to the trade object. Needing this info where I am applying buy/sell rules. Maybe I am being thick.
setting the value for
oinfo = dict(trend=self.trend) self.order = self.sell(data=self.data0, addinfo=oinfo)
I appreciate your help here.
Strategies can receive
tradenotifications via the
notify_trade(self, trade)method, which can be overridden by end users.
tradeis notified with each
order(which is for the same
dataand has the same
tradeid). The idea:
class MyStrategy(bt.Strategy): def notify_trade(self, trade): self.mytrade = trade def next(self): # Something like this when operating on a single data source if self.position: # in the market # for sure there is an open trade - get the info that was added to the opening order info = self.trade.history.event.order.info
Information which has been stored with
addinfo. This alleviates having to keep track of which order actually was the one that opened the trade because the
tradehistorykeeps that in the index
Thank you. This is now working as you suggest.