Test an EMA crossover strategy in Excel with MarketXLS India. Start with a defined fast and slow average, run the supported crossover conditions, and inspect the resulting trades.
Try it in your own spreadsheet
Get the free MarketXLS sample workbook (.xlsx).
No account needed. MarketXLS live data requires a paid plan. Preview workbook
Get MarketXLS India: plans and subscription · See the India Excel add-in
Start with this formula
After connecting the required broker in the India add-in, enter:
=MXLSIN.Backtest("INFY", "CROSSABOVE(EMA(9), EMA(21))", "CROSSBELOW(EMA(9), EMA(21))", "day")
Use the example as a starting point and replace its instrument, date range or cell references with your own inputs. Historical dates in examples are sample periods; expiry-specific symbols must refer to a valid contract.
Set up the worksheet
- Open Excel and install MarketXLS India from the add-in marketplace.
- Sign in with your MarketXLS India account. For broker data, connect Zerodha or Angel One using the add-in panel. Use the broker named by a broker-specific formula.
- Enter the formula in an empty area. Leave adjacent cells clear for any table or multi-cell output.
- Confirm the instrument and settings before extending the worksheet.
Use the 9/21 EMA example below as a reproducible starting rule, not a recommended strategy. Keep the same symbol, interval and dates in the summary and trade-list requests. Check the first few trades against the corresponding candle history.
Build the working example
Repeat the same rule over a different period without changing the parameters. Look for repeated losses during sideways markets and compare how much the result depends on a small number of trades. Record each experiment so a successful setting is not mistaken for the only setting you tested.
Functions and syntax
These examples use the India namespace, MXLSIN.. Square brackets in a syntax line indicate optional arguments; do not type the brackets into Excel. Keep text arguments in quotation marks and use cell references when you want editable inputs.
Backtest
Backtests a rule-based strategy on broker history and returns a statistics table. Signals use candle closes and fill at the next open.
Syntax:
MXLSIN.Backtest(symbol, entry, [exit], [interval], [from], [to], [options], [broker])
Example:
=MXLSIN.Backtest("INFY", "CROSSABOVE(EMA(9), EMA(21))", "CROSSBELOW(EMA(9), EMA(21))", "day")
Backtest_Trades
Returns the trade-by-trade list for a backtest. Takes the same arguments as Backtest.
Syntax:
MXLSIN.Backtest_Trades(symbol, entry, [exit], [interval], [from], [to], [options], [broker])
Example:
=MXLSIN.Backtest_Trades("INFY", "CROSSABOVE(EMA(9), EMA(21))", "CROSSBELOW(EMA(9), EMA(21))", "day")
Crossover
Detects a crossover of two values on the latest candle: +1 when the first crosses above the second, -1 when it crosses below, 0 otherwise.
Syntax:
MXLSIN.Crossover(symbol, fast, slow, [interval], [output], [mode], [broker])
Example:
=MXLSIN.Crossover("INFY", "EMA(9)", "EMA(21)", "15m")
Check the result
Next-open fills can differ materially from the signal candle's close. Small parameter changes and costs can also change results. Keep out-of-sample evaluation separate from the period used to select the rule.
If Excel reports #NAME?, confirm the India add-in is loaded and the function name is spelled correctly. If a table reports #SPILL!, clear the cells in its output area. For missing broker data, check the connection in the add-in panel, verify the symbol, and test one request before expanding the sheet. Do not replace an error with zero when zero would change your analysis.
Can I use the crossover in a live watchlist too?
Yes. Crossover evaluates a current candle-based condition, while Backtest evaluates a historical sequence. Compare their intervals and settings before assuming their observations are identical.
Get this working in your Excel
Choose a MarketXLS India subscription, install the India add-in, and follow the steps above. The pricing page lists the current subscription options; broker access requirements are separate from the spreadsheet formulas.
Use the India function library for the complete parameter reference, or contact the India team with the formula, instrument and error message if you need setup help. Never send broker passwords or access tokens.
Continue with the India Excel workflow series for related guides.
