Skip to content
TradeLayout Blog
Trading Strategies

Your EMA Lines Crossed. Is That Enough to Automate a Trade?

Use a familiar EMA 9 and EMA 21 idea to understand the difference between a chart observation and a complete strategy.

The fast EMA moves above the slow one. You recognise the crossing on the chart and think, “That is my entry.”

Now write the instruction: “Enter when EMA 9 is above EMA 21.” Have you described the crossing you noticed, or a condition that might stay true for several candles?

Two schematic EMA lines cross, then the fast line remains above without a second crossover.
Schematic EMA comparison, not market data. A fresh crossing and a continuing state are different rules.

That wording difference is worth settling before you build. This article uses EMA 9 and EMA 21 only to explain the logic, not to recommend the settings or suggest they produce profitable trades.

What happened between the two observations?

In this hypothetical example, the earlier completed observation has EMA 9 at or below EMA 21. In the latest completed observation, EMA 9 is above EMA 21.

The relationship changed. Under that definition, an upward crossover occurred between the two observations.

Now consider another pair where EMA 9 is already above EMA 21 and remains above. The “above” condition is true, but there is no fresh upward crossing between those points.

A trader can recognise that distinction without thinking much about the wording. A strategy needs the distinction expressed in its actual comparison.

Write down how equality should be handled too. “At or below, then above” gives you a definition to check; “a nice crossover” leaves the meaning open.

For this exercise, both observations are completed candles. A rule evaluated while a candle is forming asks a different question, so check the timeframe and the values referenced by your expression.

That choice does not make the example profitable. It makes the intended behaviour clear enough to investigate.

A signal still leaves a position to define

If you watch NIFTY and intend to trade an option, the index signal has not selected a contract. You still need to decide the instrument, expiry, strike selection, side and quantity.

Exits need the same separation. An index reversing and an option position losing value are different measurements, even if both matter to your thinking.

Ask which measurement each exit uses. Then describe whether another entry is permitted after closing a position and what ends the session.

Real TradeLayout Entry configuration with instrument, quantity, order and option settings.
Real product capture from the documentation. This separate, unfinished example shows Entry settings and validation warnings; it is not the EMA strategy in this article. Settings shown are not recommendations.

This real product capture shows the Entry configuration in a separate, unfinished example. Notice the position settings on the right and the warning that an exit still needs attention; it is not a completed EMA strategy.

In TradeLayout, configure the required indicators in Strategy Setup before writing the relevant condition. The condition guide explains the expression controls and plain-English preview.

Read the preview against your own definition of the crossover. Then follow the connection into Entry and through the exit branches using the builder guide where needed.

Test the case that looks almost right

A fresh crossover is the obvious example to inspect. The less obvious one is a sequence where the fast line was already above and remains there.

Write down whether that second case should allow another entry under your rules. Compare the expectation with the saved condition and, where available, the recorded behaviour in a backtest.

Inspect the exits and repeated attempts as well. A trigger doing what you intended does not establish that the rest of the flow is correct or that the strategy has a market advantage.

Adding RSI, MACD and another timeframe immediately may leave you with more settings and less understanding of why a trade happened. Keep the first investigation small enough to explain.

Before automating a familiar chart setup, finish the sentence precisely: “The relationship was ___, and now it is ___.” Then check whether the rule you built says the same thing.

Put this strategy to work

Build it with AI or visually, backtest it on years of data, then automate it. No code needed.

Try TradeLayout