Products
Platform
Research
Market
Learn
Partner
Support
IPO
Logo_light
Module 3
Building your First Algo
Course Index

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.

  • 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.

Your algo doesn’t “see” charts like you do. It only processes numbers. Here’s how it thinks:

  1. Collect the last 20 days of closing prices (historical data).
  2. Calculate the 5-day and 20-day moving averages.
  3. Compare them bar by bar (day by day).
  4. When 5-day moves above 20-day, mark it as a buy signal.
  5. Place an order at the next available price (usually the next day’s open).

This way, your algo isn’t guessing. It’s following a rule-based checklist.

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.

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.

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.

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.

Is this chapter helpful?
Previous
Platforms You Can Use to Run Your Algo
Next
Testing Your Strategy (Backtesting)

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.