Reputation: 4154
For instance, I have 3000 dollars initial capital I want to put all the capital in every entry. And close/exit all the capital for every time.
If there is a loss, I will put the left capital to the next entry. Say if 2900 left after the close of first entry. I'll put 2900 to the next entry. Vice versa, If there is 3100 left, I'll put 3100 to the next entry.
How can I achieve this?
What I tried:
initial_capital = 3000
strategy("test", overlay=true,
default_qty_type=strategy.cash, default_qty_value=initial_capital, currency=currency.USD
initial_capital=initial_capital)
strategy.entry("Long", strategy.long, comment='01')
In this way, it seemed putting 3000 every time, which was not I want.
Due to the answer from @brokeboynomore, I tried his approach, but got a strange error:
Upvotes: 1
Views: 2144
Reputation: 1094
strategy.entry("Long", strategy.long, comment='01', qty=strategy.equity)
Whatever is your equity, it will use it as the trade quantity. default_qty_type must be set to strategy.cash since strategy.equity is in cash
Edit:
currentBalance = strategy.initial_capital + strategy.netprofit
strategy.entry("Long", strategy.long, comment='01', qty=currentBalance)
This one I think is what you're looking for. It uses 100% of your current balance as the trade quantity.
Edit: (8/15/2021)
initial_capital = 3000
strategy("test", overlay=true,
default_qty_type=strategy.fixed, currency=currency.USD
initial_capital=initial_capital)
balance = strategy.initial_capital + strategy.netprofit
balanceInContracts = balance/close
strategy.entry("Long", strategy.long, comment='01', qty=balanceInContracts)
This should fix the error. I converted balance into contracts and set default_qty_type
to strategy.fixed
.
Upvotes: 1