Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recomendation: commission and lot size by risk% inside self.sell() and self.buy() #628

Closed
samueltg92 opened this issue Apr 6, 2022 · 3 comments
Labels
duplicate This issue or pull request already exists

Comments

@samueltg92
Copy link

samueltg92 commented Apr 6, 2022

Probably this could be implemented when one define to open a sell or buy position:

  • Let the user to set a fixed commission in usd per lot traded, example: let the user set 4 usd per lot traded
  • Let the user to call the current balance inside the "size" parameter so we can calculate our LOT_SIZE (Larry William's formula) using a risk% and the StopLoss used, example: size = (balance*riskpct)/(slatr*contractsize)

Example:

    if self.data.Close >= self.ema and self.rsi <= 10:
        sl1 = price - slatr
        tp1 = price + slatr*TPSLRatio 
        riskpct = 0.01
        fixedcommission = 4
        contractsize = 100000

        self.buy(sl=sl1, tp=tp1, size = (balance*riskpct)/(slatr*contractsize), commission = fixedcommission)
        

    if self.data.Close <= self.ema and self.rsi >= 90:
        sl2 = price + slatr
        tp2 = price - slatr*TPSLRatio
        riskpct = 0.01
        fixedcommission = 4
        contractsize = 100000            

        self.sell(sl=sl2, tp=tp2, size = (balance*riskpct)/(slatr*contractsize), commission = fixedcommission)
@samueltg92
Copy link
Author

It could be also helpful if it can plot the return distribution and the trades lot distribution (to see how the risk management is working)

image

@kernc
Copy link
Owner

kernc commented Apr 7, 2022

Sure, share the plot, but leave out any meaningful code. 😝

If you take Strategy.equity for balance, you can compute appropriate size= yourself.

Other than that, I see this issue is a duplicate of #623.

Welcome to use Discussions to address broader topics/ideas.

@kernc kernc closed this as completed Apr 7, 2022
@kernc kernc added the duplicate This issue or pull request already exists label Apr 7, 2022
@samueltg92
Copy link
Author

Lol sorry, I'm learning coding for not so long ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants