{
  "name": "Rope Calculator",
  "url": "https://primefoldtrading.com/tools/rope-calculator",
  "what": "Position size from account size, risk per trade, entry and stop. Information, not advice.",
  "inputs": {
    "account": "account size, > 0",
    "risk_pct": "percent of account accepted as loss at the stop, 0 < x <= 100",
    "entry": "entry price, > 0",
    "stop": "stop price, > 0, not equal to entry. Used when stop_method is \"price\"",
    "decimals": "0 for whole shares, 6 for fractional units",
    "stop_method": "\"price\" (default), \"atr\" or \"pct\"",
    "side": "\"long\" or \"short\". Used by the atr and pct methods",
    "atr": "ATR value in price units, > 0. Used when stop_method is \"atr\"",
    "mult": "ATR multiple, > 0, default 2. Used when stop_method is \"atr\"",
    "stop_pct": "percent from entry, > 0; below 100 for a long. Used when stop_method is \"pct\"",
    "daily_limit": "optional daily loss limit, > 0",
    "daily_limit_is_pct": "true if daily_limit is a percent of account, false if it is an amount"
  },
  "formula": {
    "stop_atr": "entry - atr * mult (long) or entry + atr * mult (short); must be > 0",
    "stop_pct": "entry * (1 - stop_pct / 100) (long) or entry * (1 + stop_pct / 100) (short)",
    "rope": "account * risk_pct / 100",
    "stop_distance": "abs(entry - stop)",
    "size": "floor(rope / stop_distance) at the chosen decimals; never rounds up",
    "side": "long if stop < entry, else short",
    "target_nR": "entry + n * stop_distance (long) or entry - n * stop_distance (short), n = 1, 2, 3",
    "daily_limit_amount": "daily_limit, or account * daily_limit / 100 when daily_limit_is_pct",
    "stop_outs_left": "floor(daily_limit_amount / loss_at_stop)",
    "daily_limit_warning": "stop_outs_left <= 1. 1: one more stop-out hits the limit. 0: this trade alone breaks it"
  },
  "excludes": [
    "fees",
    "slippage",
    "gaps past the stop"
  ],
  "example": {
    "account": 10000,
    "risk_pct": 1,
    "entry": 102.5,
    "stop": 98,
    "decimals": 0,
    "rope": 100,
    "size": 22,
    "loss_at_stop": 99,
    "position_value": 2255,
    "targets": [
      107,
      111.5,
      116
    ]
  },
  "examples": {
    "price": {
      "account": 10000,
      "risk_pct": 1,
      "decimals": 0,
      "stop_method": "price",
      "entry": 102.5,
      "stop": 98,
      "rope": 100,
      "size": 22,
      "loss_at_stop": 99,
      "position_value": 2255,
      "targets": [
        107,
        111.5,
        116
      ]
    },
    "atr_long": {
      "account": 10000,
      "risk_pct": 1,
      "decimals": 0,
      "stop_method": "atr",
      "entry": 100,
      "atr": 2,
      "mult": 2,
      "side": "long",
      "stop": 96,
      "rope": 100,
      "size": 25,
      "loss_at_stop": 100,
      "position_value": 2500,
      "targets": [
        104,
        108,
        112
      ]
    },
    "atr_short": {
      "account": 10000,
      "risk_pct": 1,
      "decimals": 0,
      "stop_method": "atr",
      "entry": 100,
      "atr": 2,
      "mult": 2,
      "side": "short",
      "stop": 104,
      "rope": 100,
      "size": 25,
      "loss_at_stop": 100,
      "position_value": 2500,
      "targets": [
        96,
        92,
        88
      ]
    },
    "pct_long": {
      "account": 10000,
      "risk_pct": 1,
      "decimals": 0,
      "stop_method": "pct",
      "entry": 50,
      "stop_pct": 5,
      "side": "long",
      "stop": 47.5,
      "rope": 100,
      "size": 40,
      "loss_at_stop": 100,
      "position_value": 2000,
      "targets": [
        52.5,
        55,
        57.5
      ]
    },
    "pct_short": {
      "account": 10000,
      "risk_pct": 1,
      "decimals": 0,
      "stop_method": "pct",
      "entry": 50,
      "stop_pct": 5,
      "side": "short",
      "stop": 52.5,
      "rope": 100,
      "size": 40,
      "loss_at_stop": 100,
      "position_value": 2000,
      "targets": [
        47.5,
        45,
        42.5
      ]
    },
    "daily_limit": {
      "account": 10000,
      "daily_limit": 1,
      "daily_limit_is_pct": true,
      "loss_at_stop": 100,
      "daily_limit_amount": 100,
      "stop_outs_left": 1,
      "warn": true
    }
  }
}
