

Kotak
Stockshaala
Chapter 1 | 2 min read
Setting a Simple Strategy
Every algo needs rules. Think of it like a recipe: when ingredients match, you cook; if not, you wait. In trading, those ingredients are prices, volumes, and indicators. The simplest way to start is with a moving average crossover strategy.
The Core Idea
-
Rule: Buy a stock if its short-term trend (5-day average) crosses above its long-term trend (20-day average).
-
Why: It signals that momentum is shifting upward.
-
Action: Place a buy order when this condition is met.
This isn’t a money-making shortcut. It’s just a toy example to show how a rule gets translated into algo logic. Real strategies will need more filters and risk checks, but this gives you a taste of how things work.
How the Algo Reads It
Your algo doesn’t “see” charts like you do. It only processes numbers. Here’s how it thinks:
- Collect the last 20 days of closing prices (historical data).
- Calculate the 5-day and 20-day moving averages.
- Compare them bar by bar (day by day).
- When 5-day moves above 20-day, mark it as a buy signal.
- Place an order at the next available price (usually the next day’s open).
Example in Action
Day 18 | 102 | 105 | No action |
Day 19 | 104 | 105 | No action |
Day 20 | 106 | 105 | Buy (crossover!) |
Day 21 | 108 | 106 | Order executed at open |
This way, your algo isn’t guessing. It’s following a rule-based checklist.
Timeframes Matter
The same strategy behaves differently depending on the timeframe:
- 1-minute candles → hyperactive, suited for scalping.
- 15-minute → short-term intraday moves.
- Daily → swing or positional trading.
- Weekly → longer-term trend catching.
Choose the timeframe that matches your style. A daily crossover strategy may give 2–3 signals a month, while a 5-minute version could spit out 20 signals a day.
Risk and Exit Rules
Even the cleanest crossover strategy can fail. Without exits, one bad trade can wipe gains. Always add:
- Stop-loss: Pre-decided max loss per trade.
- Target: Profit level where you lock gains.
- Time-based exit: Close position after X days if nothing happens.
Data Dependency Reminder
This strategy depends heavily on closing prices. If your feed is delayed or unreliable, the crossover will trigger late — and you’ll miss the move. Clean, timely data is non-negotiable.
Key Takeaway:
A strategy is nothing more than “If X happens, do Y.” The moving average crossover is just one way to show how your algo listens to data and takes action. Start simple, test thoroughly, and always keep risk management baked in.
Disclaimer: This article is for informational purposes only and does not constitute financial advice. It is not produced by the desk of the Kotak Neo Research Team, nor is it a report published by the Kotak Neo 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.
Recommended Courses for you
Beyond Stockshaala
Discover our extensive knowledge center
Learn, Invest, and Grow with Kotak Videos
Explore our comprehensive video library that blends expert market insights with Kotak's innovative financial solutions to support your goals.














