[EXAMPLE] Position sizing based on pre-determined (acceptable) loss & stop-loss size

0 234 Views No Comments 1 month ago
HTS CLOUDSTABLE
  • Hey fellas!

    Here is an example code snippet to demonstrate how you can calculate your position size based on acceptable loss amount and your stop-loss size. You can test this code by running a backtest on the market of your choice, it will run 2 updates and output the calculated values and the actual loss amount.

    The code works “both ways”, meaning that you can use this for COIN/USDT and COIN/BTC markets (or whatever the underlying asset is). The code also works in both SPOT and FUTURES.

    ~~May the profits be with you~~

    CC available here: https://www.haasscripts.com/t/pshaicmd-get-dynamic-trade-amount/

    Example results on BAT/BTC (SPOT) using 0.01 BTC acceptable loss and 2% stop-loss size:

    Losses: -0.0099999216 BTC
    Sell order finished. 114678 BAT @ 0.0000042728 BTC (70382447-e3fe-4249-8a6d-553ebafd7fc5) (Simulated Order)
    Buy order finished. 114678 BAT @ 0.00000436 BTC (72ebc12d-5911-4bd8-b8b3-2b7711cfe268) (Simulated Order)
    Entry Price: 0.00000436 BTC
    Stop-Loss: 0.00000427 BTC
    Investment Size (margin): 0.5 BTC
    Notional Size: 0.5 BTC
    Position Size: 114679 BAT
    

    Example results on MANA/USDT (Perpetual) using 100 USDT acceptable loss and 2% stop-loss size,

    1x leverage (or spot):

    Losses: -99.999984 USDT
    ExitLong order finished. 8364.0 MANA @ 0.585844 USDT (f1efa9d7-48ea-43fe-9eeb-249bce51384f) (Simulated Order)
    GoLong order finished. 8364.0 MANA @ 0.5978 USDT (1a3675d4-dee9-446c-82e3-765d3d001534) (Simulated Order)
    Entry Price: 0.5978 USDT
    Stop-Loss: 0.5858 USDT
    Investment Size (margin): 5000 USDT
    Notional Size: 5000 USDT
    Position Size: 8364 MANA

    20x leverage:

    Losses: -99.999984 USDT
    ExitLong order finished. 8364.0 MANA @ 0.585844 USDT (5b6fa71c-0b81-4313-8429-06d5f05b15f4) (Simulated Order)
    GoLong order finished. 8364.0 MANA @ 0.5978 USDT (904dce38-f294-46fd-8149-f4b9fca84a86) (Simulated Order)
    Entry Price: 0.5978 USDT
    Stop-Loss: 0.5858 USDT
    Investment Size (margin): 250 USDT
    Notional Size: 5000 USDT
    Position Size: 8364 MANA
    HaasScript Code
    Sign in or Register to download for free
  • Phemex x HaasOnline Promotion Type: contest Expires: May 31, 2024 Exclusive
    Receive up to 1,200 USDT! The more you trade, the more you earn.
Login or Register to Comment

Unlock your crypto trading potential

Create a free account and enjoy everything we have to offer.

Join for Free