Module 31: Automation
Key Takeaways
- Automation executes rules without emotion, 24/7.
- Expert Advisors run on MetaTrader; Pine Script powers TradingView.
- Automate only a strategy you’ve already tested manually.
Trading bots
A trading bot executes a coded strategy automatically — entries, exits and risk — removing emotion and reacting faster than a human. Bots are powerful but only as good as the logic behind them; a flawed strategy automated just loses money faster.
Expert Advisors
On MetaTrader 4/5, automated programs are called Expert Advisors (EAs), written in MQL4/MQL5. They can run on a VPS so they trade around the clock without your computer being on.
Pine Script basics
TradingView uses Pine Script for custom indicators and strategies. Here is a minimal strategy that buys when a fast moving average crosses above a slow one:
//@version=5
strategy("MA Cross Demo", overlay=true)
fast = ta.sma(close, 20)
slow = ta.sma(close, 50)
plot(fast, color=color.green)
plot(slow, color=color.red)
longCondition = ta.crossover(fast, slow)
shortCondition = ta.crossunder(fast, slow)
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.close("Long")Paste this into TradingView’s Pine Editor, add it to a chart, and use the Strategy Tester to backtest it. This is a learning example, not a profitable system.
Never run an automated strategy live until it has been backtested and forward-tested on demo. Automation amplifies both good and bad logic.
Frequently Asked Questions
Some basic scripting helps, but there are no-code builders too. Start by understanding the logic you want to automate.