AI

How to describe a trading strategy to AI so the code does what you mean

A practical template for writing strategy prompts that produce correct Pine Script and MQL5: precise entries and exits, risk rules, filters and inputs — plus the ambiguous words to avoid.

AI code generators are very good at writing syntax and very bad at reading minds. If you write "buy when RSI is oversold and the trend is up", the model has to guess the RSI length, what "oversold" means, whether you mean crossing or simply being below, how "trend" is measured, where the stop goes and when to exit. It will guess — and the code will compile — but it may not be your strategy.

The fix is to describe the strategy the way a programmer would need it: every condition measurable, every decision explicit. Here's a structure that works.

The seven things every strategy description needs

  1. Platform and output. A TradingView indicator (signals and alerts), a TradingView strategy (backtestable orders), or a MetaTrader 5 Expert Advisor (automated trading).
  2. Market and timeframe. "EUR/USD, 1-hour chart" or "any symbol, designed for 15-minute charts".
  3. Entry conditions. Each one measurable, with lengths and thresholds.
  4. Exit conditions. Stop-loss, take-profit, trailing stop, time-based exit or opposite signal.
  5. Position sizing. Fixed lot, a fixed percentage of equity at risk, or a number of contracts.
  6. Filters. Sessions, days of the week, spread limits, volatility, maximum trades per day.
  7. Outputs and inputs. What to plot, what to alert on, and which parameters you want to be able to change.

Vague vs precise

VaguePrecise
RSI is oversoldRSI(14) on close crosses above 30
The trend is upClose is above the 200-period EMA
Buy at supportPrice trades below the lowest low of the last 20 bars, then closes back above it
Big candleCandle range greater than 1.5 × ATR(14)
Tight stopStop-loss 1 × ATR(14) below entry
Take profit at a good levelTake-profit at 2 × the stop distance
Trade the London sessionOnly open trades between 08:00 and 11:00 exchange time (broker server time for MT5)
Don't overtradeMaximum 2 trades per day, one position at a time

Notice the pattern: every precise version names an indicator, a length, a source, a comparison and a number.

A template you can copy

Platform: TradingView strategy (Pine Script v6)
Market/timeframe: any forex pair, 1-hour chart

Entry (long):
- Close is above EMA(200)
- RSI(14) crosses above 40 after being below 40 for at least 3 bars
- Only on confirmed (closed) bars

Entry (short): mirror of the long rules

Exits:
- Stop-loss at 1.5 x ATR(14) from entry, fixed at entry time
- Take-profit at 2 x the stop distance
- Close any open trade on Friday at 20:00 exchange time

Sizing: risk 1% of equity per trade
Filters: only enter between 07:00 and 16:00 exchange time; one position at a time
Inputs: EMA length, RSI length, RSI level, ATR multiplier, reward:risk, session hours
Plots: EMA(200); triangles on entries; alerts on entry signals
Costs: commission 0.05% per order, slippage 2 ticks

That's about 120 words, and it removes almost every guess.

Words that cause trouble

  • "When" — does the condition need to become true (a crossover) or just be true? Crossovers fire once; states fire on every bar.
  • "Close" — the bar's close, or closing the trade? And on a still-forming bar, the "close" is just the latest price.
  • "Daily" — the calendar day in your time zone, the exchange session, or the broker's server day?
  • "Support", "resistance", "trend", "breakout" — all need a mechanical definition before code can use them.
  • "Higher timeframe" — say which one, and say you want confirmed values only, to avoid look-ahead bias (see backtesting mistakes that inflate results).
  • "Risk 2%" — of balance or of equity? Per trade or per day?

Platform details worth mentioning

For TradingView: say whether you want an indicator() (signals, plots, alerts) or a strategy() (simulated orders and a Strategy Tester report), and whether signals must not repaint. If you're new to the language, Pine Script v6 for beginners explains the difference.

For MetaTrader 5: state the account type if you know it (hedging or netting), that the EA should manage only its own trades (it should — that's what the magic number is for), the maximum spread, and what should happen after a restart. Our MQL5 Expert Advisor risk checklist lists the safeguards worth asking for.

Iterate in small steps

Don't try to get everything into one prompt. A good sequence:

  1. Generate the core entry and exit logic.
  2. Add it to a chart and check a handful of signals by eye. Do they appear where you expected?
  3. Refine one thing at a time: "only take longs when ADX(14) is above 20", "move the stop to breakeven after 1R".
  4. Run a backtest, then forward-test on a demo account.

When something looks wrong, point to a specific bar: "on the 14:00 candle on 3 March the script entered long, but RSI was still below 40". Concrete examples get fixed much faster than "it's not working".

Check the code, not just the chart

Even if you don't program, skim the generated code for the numbers you specified: the lengths, the thresholds, the stop multiplier. If a value you didn't ask for appears, ask why it's there. Then compile it, add it to a chart and compare a few trades against your rules by hand. For installation help, see how to add a Pine Script indicator to TradingView and how to install an Expert Advisor on MT5.

Try it with Edgoro

Paste your description into Edgoro and choose TradingView or MetaTrader 5. You'll get Pine Script v6 or MQL5 code that you can refine by chatting — "add a session filter", "make the stop trail" — with every version saved in your library. Start with three free generations.

Generated code can contain mistakes; test it before relying on it. Trading involves substantial risk of loss.

Build it with Edgoro

Describe your strategy in plain English and get a TradingView indicator in Pine Script v6 or a MetaTrader 5 Expert Advisor in minutes. Three generations are free.

Start free