Skip to content

Run an end-of-day risk check

Before you walk away from the desk, the three questions that matter are: how much of my equity is committed, are my positions protected, and what is losing more than I am willing to accept. This guide walks through the four commands that answer them and shows how to act on the answer.

Tip

Define your credentials in shell variables once. Every interactive command below reuses them, so the steps stay short and the script stays portable.

export CTID=1234567
export ACC=7654321
export PWD_FILE=$HOME/.ctrader/pwd

1. Check how much margin is committed

account-stats returns balance, equity, margin and free margin. Compare free margin against equity to see how exposed the account is.

ctrader-cli account-stats --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q

If free margin is low relative to equity, the account is already overcommitted and the next steps matter more.

2. List every open position

positions prints every open position with its entry price, volume, stop loss, take profit and unrealised profit. Save the output to a file so you can scan it line by line.

ctrader-cli positions --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q > positions.json

Scan for two warning signs: positions without a stop loss, and positions losing more than your threshold. The next steps handle each.

3. Add stop losses to any unprotected position

For each position whose stop loss is missing or too tight, position modify adds or moves the stop without changing the volume.

ctrader-cli position modify --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q \
    --position=11223344 --sl=1.1000

Pass only --sl to leave the take profit untouched. Repeat for every unprotected position.

4. Close the positions that breach your threshold

For positions losing more than your rule allows, position close exits at the next available price.

ctrader-cli position close --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q \
    --position=55667788

If you want to keep the position but reduce the size, use position close-partial with --volume.

ctrader-cli position close-partial --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q \
    --position=55667788 --volume=500

5. Verify the account is back in shape

Re-run account-stats and positions to confirm margin has eased and the problematic positions are gone.

ctrader-cli account-stats --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q
ctrader-cli positions    --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q

6. Combine into a risk-check script

Save the full sequence as risk-check.sh. The script saves the position list, so you can review what changed.

#!/usr/bin/env bash
set -euo pipefail

CTID=1234567
ACC=7654321
PWD_FILE=$HOME/.ctrader/pwd
LOSS_LIMIT=300
PROTECT_POS=(11223344 55667788)
CLOSE_POS=(55667788)

ctrader-cli account-stats --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q
ctrader-cli positions    --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q > positions.json

for POS in "${PROTECT_POS[@]}"; do
    ctrader-cli position modify --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q \
        --position=$POS --sl=1.1000
done

for POS in "${CLOSE_POS[@]}"; do
    ctrader-cli position close --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q \
        --position=$POS
done

ctrader-cli account-stats --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q
ctrader-cli positions    --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q

Edit the position arrays at the top with the identifiers you find in step 2. Run the script after every session before you close the laptop.

The CLI references lists all available options for the commands used in this workflow.

Warning

cTrader CLI is a tool for trading and automation. It does not provide financial, investment, legal or tax advice. Commands that place or change orders can trigger real trades and result in losses. Verify every command before you run it, test on a demo account first and protect your credentials.