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:
| Date | 5-day MA | 20-day MA | Signal |
|---|---|---|---|
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.
The same strategy behaves differently depending on the timeframe:
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:
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.
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.