Skip to Content
NeurotraderDocs
Concepts

Margin and leverage

Borrowing on a simulated account: the margin terms you set, loans and interest, the margin level, margin calls, liquidation and the account journal.

Some strategies need more than the account holds. A leveraged long borrows money to buy more, and a short borrows an asset to sell it first and buy it back later. A simulated account can do both when you give it margin terms. This page explains what you set, what the account then does on its own, and how to read the outcome.

Multiplied losses

Leverage makes losses larger as well as gains, and a margin account can lose everything it started with. A simulation shows this without risk. Read the lowest margin level and the liquidations of a run as carefully as its return.

Spot and margin accounts

A simulated account is one of two kinds, and you choose when you create the simulation.

  • Spot is the default. The account trades only what it holds. It cannot sell an asset it does not have, it borrows nothing, and it cannot lose more than it started with.
  • Margin lets the account borrow to fund an order. It can buy more than its cash covers and sell an asset it does not hold. It pays interest on what it owes, and it is judged by its margin level.

The model is the cross margin of a spot exchange: the account borrows an asset, the whole account stands behind every loan, and there are no futures contracts.

Margin terms

You turn margin on with the Margin switch on the Details step of the new simulation wizard. The fields below it hold the terms.

Screenshot
The Margin group on the Details step of the new simulation wizard with the switch on, Leverage levels offered set to 2, 3, the three margin level fields at 1.3, 1.5 and 1.1, Interest at 0.001 percent per hour and Liquidation fee at 2 percent
FieldMeaningDefault
Leverage levels offeredThe leverage levels an order may ask for, such as 2, 3. Each is above 1, in rising order, eight at most.2x and 3x
Margin call atThe margin level at which a margin call is raised.1.3
Call clears aboveThe margin level above which a margin call ends.1.5
Liquidation atThe margin level at which the account is liquidated.1.1
Interest (% per hour)The interest charged on what is borrowed, per hour of market time.0.001
Liquidation fee (%)An extra fee on the orders that close a liquidated account.2

The defaults are the levels Binance publishes for cross margin, so turning the switch on gives a coherent account without further work.

The wizard checks that the terms fit together. The liquidation level must be below the margin call level, and that below the level at which a call clears. The highest leverage level must leave the account above the margin call level when it is used in full. For example, 5x opens an account at a margin level of 1.25, which is already below a margin call at 1.3, so 5x needs lower levels of its own.

The margin terms are fixed when the simulation is created. The Account card shows them in the Margin row with a lock, or Spot for a spot account. They are locked for the same reason as the primary quote asset: every run of the simulation is judged under them.

Leverage per order

The simulation offers leverage levels. The algorithm chooses one of them for each order. You do not set "the leverage of the account".

  • An order that asks for no leverage is a spot order, and that is always accepted.
  • An order that asks for a level the simulation does not offer is rejected with the cause Leverage not offered.

An algorithm has to be written to use margin. Of the built-in algorithms, SMA Long/Short does: it takes the leverage as a parameter, goes long and short, and reads the state of its account before each order. An algorithm that never asks for leverage behaves on a margin account exactly as it does on a spot account.

Loans

A loan is never taken on its own. It happens as part of an order, and only when the order needs it.

  • An order borrows only its shortfall. A buy that the cash balance covers borrows nothing, at any leverage. A buy that needs more borrows the difference in the quote asset. A sell of more than the account holds borrows the missing amount of the base asset, which is how a short begins.
  • Leverage limits the loan. At leverage L, the account may owe up to L minus 1 times its equity. At 2x it may owe as much as its equity, and at 3x twice as much. A loan beyond that is refused, and the order is rejected with the cause Insufficient margin.
  • Repayment is automatic. Whenever the account comes to hold an asset it owes, from a sale, a buy-back or a cancelled order, the loan in that asset is repaid at once, interest first. The account never pays interest on money it has available to repay with.

There is no borrow button and no repay button, for you or for the algorithm.

Interest

A loan costs interest at the hourly rate you set, charged on the amount borrowed. Interest follows market time, not the number of candles: a loan held for one day costs the same on minute candles as on daily candles.

Interest is owed in the borrowed asset and is paid first when the account repays. It is not itself charged interest. A run's results state the interest paid, per asset.

Margin level

The margin level is the one figure the account is judged by: total assets divided by total liabilities.

Both sides are valued in the primary quote asset. Total assets is everything the account holds. Total liabilities is everything it owes, interest included. The difference between them is the account's equity, and on a margin account the equity is the net worth that the return and the drawdown are measured on.

An account that owes nothing has no margin level, and the app shows "nothing owed". The more the account borrows, or the more the market moves against it, the lower the level falls. A position opened at 3x begins at 1.5, and one opened at 2x begins at 2.

Margin calls

When the margin level falls to the margin call level, the account raises a margin call.

A margin call is a warning and nothing more. No order is cancelled and no balance changes. Neurotrader does not close positions on the strategy's behalf, because what a strategy does under a margin call is part of the strategy. The algorithm is told that a call stands, and it decides: SMA Long/Short, for example, closes its position.

The call is raised once and stays until the margin level recovers above the clearing level. Between the two levels nothing new is reported, so an account hovering around the call level does not raise a call on every candle.

While a simulation runs, a Margin call badge appears beside its status.

Liquidation

When the margin level falls to the liquidation level, the account is liquidated.

  1. Every open order of the account is cancelled, with the cause Liquidated.
  2. The account sells what it holds and buys back what it owes, with market orders of its own. These orders carry the cause Liquidation unwind in the journal, so a forced sale is never mistaken for a decision of the algorithm.
  3. Each of these orders pays the taker fee plus the liquidation fee.

The check is strict on purpose. Within a candle, the account is valued at the prices worst for it: what it holds at the candle's low, what it owes at the candle's high. The closing orders fill at those same prices. A simulation that judged margin kindly would show strategies surviving moves that would have ended them, and that is the more dangerous mistake.

If one candle reaches both the liquidation level and one of the account's own waiting orders, such as a stop loss, the data cannot say which came first. Neurotrader settles it with the same fair draw it uses for a bracket. See Execution journal.

After a liquidation the account goes on, with what is left, and the algorithm can trade again. The run shows a Liquidated badge.

Bankruptcy

If the closing orders do not bring in enough to repay the loans, the account is bankrupt. The shortfall is recorded and written off, the account is emptied, and the algorithm stops trading for the rest of the run. In a comparison the other algorithms continue. A run in which every account is bankrupt ends there, as a completed run.

The run shows a Bankrupt badge beside its outcome.

Accounts in a comparison

In a comparison or an instrument sweep, every algorithm has its own margin account under the same terms. Each is judged on its own. One algorithm's assets never support another's loans, and a liquidation of one leaves the others untouched.

Margin in a run's results

A run on a margin account adds to the results:

  • Lowest margin level: the lowest level the account touched, with the peak leverage it reached beneath it, or "never borrowed". The figure turns amber when it touched the margin call level and red when it touched the liquidation level. It tells you how close the run came.
  • Margin calls: how many calls were raised, with the number of liquidations beneath it.

The net worth chart can also draw what the account owed (Owed) and its margin level (Level) over the run. In the journal's Orders view, the Leverage column shows the level each order asked for.

Account journal

The Account view of the journal lists what happened to the account itself, one row per event.

Screenshot
The Account view of the journal on a margin run, with rows for Borrowed, Interest charged, Margin call, Margin call cleared and Repaid, each with the asset, the amount and the equity, liabilities and margin level after the event
EventMeaning
BorrowedAn order took a loan.
RepaidA loan, or part of it, was repaid.
Interest chargedInterest was added to what the account owes.
Margin callThe margin level fell to the margin call level.
Margin call clearedThe margin level recovered above the clearing level.
LiquidatedThe account was liquidated.
BankruptThe liquidation did not cover the loans.

Each row shows the time, the asset and the amount, the order that caused the event where there is one, and the account's Equity, Liabilities and Margin level after the event. Interest is charged on every candle while a loan is open, so use the event filter to leave those rows out when you look for the calls and the liquidations.

A spot run has no account events, and the view says so.

Limits of the model

The margin account does not include futures, perpetual contracts or options, and it has no isolated margin: the account is one pool. A liquidation closes the whole account, not part of it.

Margin terms apply to simulated accounts, in Simulation and Live Simulation. In Live Paper Trade and Real Trade the broker holds the account and applies its own rules.

On this page