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:
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:
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:
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:
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:
If you do this consistently, your algo has the best chance to make money in the long run.
Disclaimer: This article is for informational purposes only and does not constitute financial advice. It is not produced by the desk of the Kotak Securities Research Team, nor is it a report published by the Kotak Securities Research Team. The information presented is compiled from several secondary sources available on the internet and may change over time. Investors should conduct their own research and consult with financial professionals before making any investment decisions. Read the full disclaimer here.
Investments in securities market are subject to market risks, read all the related documents carefully before investing. Brokerage will not exceed SEBI prescribed limit. The securities are quoted as an example and not as a recommendation. SEBI Registration No-INZ000200137 Member Id NSE-08081; BSE-673; MSE-1024, MCX-56285, NCDEX-1262.
Disclaimer: This article is for informational purposes only and does not constitute financial advice. It is not produced by the desk of the Kotak Securities Research Team, nor is it a report published by the Kotak Securities Research Team. The information presented is compiled from several secondary sources available on the internet and may change over time. Investors should conduct their own research and consult with financial professionals before making any investment decisions. Read the full disclaimer here.
Investments in securities market are subject to market risks, read all the related documents carefully before investing. Brokerage will not exceed SEBI prescribed limit. The securities are quoted as an example and not as a recommendation. SEBI Registration No-INZ000200137 Member Id NSE-08081; BSE-673; MSE-1024, MCX-56285, NCDEX-1262.
Explore our comprehensive video library that blends expert market insights with Kotak's innovative financial solutions to support your goals.