Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Can't find a Trades which connected with Orders #554

Answered by kernc
JuriPro asked this question in Q&A
Discussion options

Hello guys, thank you for wonderful tool!

In my strategy I want to close trades by achievement certain conditions or modify "tp", "sl" into specific trade.
But every time in "next()" function in the list of trades I see only one single trade....
I expect to see "One order -> one Trade".

For demonstration, I take the sample from "backtesting.py" and print Orders and Trades:

def next(self):
 
 if self.position:
 print('Orders: ', [order for order in self.orders])
 print('Trades: ', [trade for trade in self.trades])
 print('----------------------------------------')
 
 if crossover(self.sma1, self.sma2):
 self.buy() # Order 1 - expect trade 1
 self.buy(sl=self.data.Low[-1]) # Order 2 - expect trade 2
 self.buy(stop=self.data.High[-1])` # Order 3 - expect trade 3

The output:

Orders: [<Order size=1.0, stop=181.06, contingent=0>]
Trades: [<Trade size=55 time=75- price=179.48826- pl=-176>]
----------------------------------------
Orders: [<Order size=1.0, stop=181.06, contingent=0>]
Trades: [<Trade size=55 time=75- price=179.48826- pl=-443>]
----------------------------------------
Orders: [<Order size=1.0, stop=181.06, contingent=0>]
Trades: [<Trade size=55 time=75- price=179.48826- pl=-523>]

Q: How can I obtain access to each trade?

You must be logged in to vote

By default, order size is ~1.0 meaning 100% of equity. Reduce size to 10% (self.buy(size=.1, ...)) or 10 units (self.buy(size=10, ...)) and you should see three trades.

Replies: 1 comment 1 reply

Comment options

By default, order size is ~1.0 meaning 100% of equity. Reduce size to 10% (self.buy(size=.1, ...)) or 10 units (self.buy(size=10, ...)) and you should see three trades.

You must be logged in to vote
1 reply
Comment options

Thank You so much kernc!
Yes, you are right - my bad...

Answer selected by JuriPro
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /