Products
Platform
Research
Market
Learn
Partner
Support
IPO
Logo_light
Module 6
Optimizing and Sustaining Your Algo
Course Index

Chapter 2 | 3 min read

Managing Risk Like a Pro

Let’s be honest — everyone focuses on returns. But what keeps an algo trader alive is not how much they earn, it’s how well they manage losses.

You can have the smartest strategy in the world — but if you risk too much on one trade, it takes only one bad day to wipe out weeks of profits.

So let’s learn how to protect your capital.

Risk only 1–2% of your capital per trade.

So if your account is ₹50,000:

  • Max loss per trade = ₹500 to ₹1,000
  • This way, even 5–6 back-to-back losses won’t damage your capital too badly

This is called position sizing — and it’s your first safety net.

No exceptions.

If you don’t set a stop-loss, the market will do it for you — and that’s usually much worse.

Types of stop-loss:

  • Fixed SL (e.g., 1.5% below entry price)
  • Indicator-based SL (e.g., below 20 EMA)
  • Time-based SL (exit after X mins if no movement)
import pandas as pd
import yfinance as yf
import time

# Download some example data
symbol = "AAPL"
df = yf.download(symbol, 
period="6mo", interval="1d")
df['EMA20'] = df['Close']
.ewm
(span=20, adjust=False)
.mean()

entry_price = 150  
# Example entry price

# 1. Fixed SL (1.5% below
 entry price)
fixed_sl = entry_price * 
(1 - 0.015)
print(f"Fixed SL: 
{fixed_sl:.2f}")

# 2. Indicator-based SL 
(below 20 EMA)
last_ema20 = df['EMA20']
.iloc[-1]
indicator_sl = last_ema20
print(f"Indicator-based SL:
{indicator_sl:.2f}")

# 3. Time-based SL 
(exit after X mins if 
no movement)
max_hold_minutes = 5
price_no_movement = True
start_time = time.time()

while True:
if time.time() - start_time 
> max_hold_minutes * 60:
if price_no_movement:
print("Time-based 
SL triggered: 
exiting trade due to 
no movement.")
break
# Here you'd check 
price updates
in real time

Also set maximum daily loss. If you lose, say, ₹2,000 in a day — stop trading. Walk away. Live to trade another day.

If you’re running your algo on just one stock or one setup, it’s risky. If that one setup stops working, you’re stuck.

Instead:

  • Run the same strategy on 3–4 stocks (non-correlated)
  • Or run 2 strategies (trend + mean reversion)
import yfinance as yf
import pandas as pd

stocks = ["AAPL", "MSFT",
"TSLA", "NFLX"] 
# Example non-correlated
 stocks

def trend_strategy(df):
 """Simple EMA crossover 
 trend-following strategy"""
df['EMA20'] = df['Close'].
ewm(span=20, adjust=False)
.mean()
df['EMA50'] = df['Close']
.ewm(span=50, adjust=False)
.mean()
df['Signal'] = df['EMA20'] 
> df['EMA50']
return df['Signal'].iloc[-1]
# Latest signal

def mean_reversion_
strategy(df):
 """Simple mean reversion: 
 buy if RSI < 30"""
 delta = df['Close'].diff()
 gain = delta.clip(lower=0)
 .rolling(14).mean()
 loss = -delta.clip(upper=0)
 .rolling(14).mean()
 rs = gain / loss
 df['RSI'] = 100 - (100
 / (1 + rs))
 return df['RSI'].iloc[-1] 
 < 30  # Buy signal 
if oversold

for stock in stocks:
df = yf.download(stock,
 period
="6mo", interval="1d")
    
trend_signal = trend_
strategy(df)
mr_signal = mean_reversion
_strategy(df)
    
print(f"{stock} | 
Trend Signal: 
{trend_signal} | 
Mean Reversion Signal
: {mr_signal}")


But don’t trade 15 symbols at once either — too messy to monitor or debug.

Algos help remove emotion — but only if you follow them strictly.

Don’t override your algo because:

  • You “feel” the market will bounce
  • You “think” it’s a breakout
  • You’re trying to recover a previous loss
    Let the system do its job. If it fails, improve it. But don’t interfere mid-trade.

Every trader — even the best — takes losses. Even with a 60% win rate, 4 out of 10 trades will still fail. The goal is not to avoid losses… but to:

  • Keep losses small
  • Stick to your plan
  • Let winners run

If you do this consistently, your algo has the best chance to make money in the long run.

Is this chapter helpful?
Previous
Tweak & Improve Your Strategy
Next
Learning from Communities

Discover our extensive knowledge center

Explore our comprehensive video library that blends expert market insights with Kotak's innovative financial solutions to support your goals.