Anatomy of a Trading Strategy: Reading Adamcator v7
Most people meet trading strategies as a black box: a script you paste into TradingView that spits out green and red arrows. This post opens the box. We will read a real, working strategy - Adamcator v7, written in Pine Script v5 - and explain what every part is doing and, more importantly, *why*.
You do not need to write Pine to get value from this. The ideas - trend filters, risk-based position sizing, volatility-scaled stops - are exactly the things you can practice by hand right here on tradegame.org.
What kind of strategy is this?
At heart it is a trend-following EMA crossover. Three moving averages, one volatility measure, and a set of rules for getting in, sizing the bet, and getting out.
- ▸
fastLen = 13,slowLen = 21- two exponential moving averages. When the fast one crosses above the slow one, momentum is turning up. - ▸
trendLen = 200- a slow EMA used only as a filter: only take longs when price is above it, shorts when below. This keeps you trading *with* the larger trend. - ▸
atrLen = 14- Average True Range, a measure of how much the instrument typically moves. Everything about risk is scaled to this.
The entry signal
fastMA = ta.ema(close, fastLen)
slowMA = ta.ema(close, slowLen)
trendMA = ta.ema(close, trendLen)
trendOkLong = not useTrendFilter or close > trendMA
warmedUp = not na(trendMA) and not na(atr)
longCond = warmedUp and ta.crossover(fastMA, slowMA) and trendOkLong and inSessionThree things have to be true to go long: the fast EMA just crossed above the slow one, price is on the right side of the 200-EMA, and we are inside the allowed session. The warmedUp check is a small but important detail - it refuses to trade until the slowest average has real data, so the first 200 bars do not generate garbage signals.
The idea that matters most: size by risk, not by size
This is the part beginners skip and professionals obsess over.
riskPerUnit = atr * atrMultSL
qty = riskPerUnit > 0 ? (strategy.equity * riskPct / 100) / riskPerUnit : naInstead of buying a fixed number of units, the strategy works backwards from how much it is willing to lose. With riskPct = 1.0, every trade risks exactly 1% of the account. A volatile instrument gets a smaller position; a calm one gets a larger position. The dollar risk is the same either way.
This is why professionals talk in R - one R is one unit of risk. A trade that makes twice what it risked is +2R, whether that was 20 dollars or 2,000. It makes every trade comparable.
The exit: volatility-scaled stop and target
risk = entryAtr * atrMultSL
entry = strategy.position_avg_price
initSL = entry - risk // stop: 2 ATR below entry
curTP = entry + entryAtr * atrMultTP // target: 3 ATR above entry
strategy.exit("Exit Long", from_entry="Long", stop=curSL, limit=curTP)The stop sits atrMultSL (2) ATRs below entry; the target sits atrMultTP (3) ATRs above. That 3:2 reward-to-risk ratio has a consequence we will come back to in part two: it sets the win rate you need just to break even.
Notice entryAtr rather than the live atr. The strategy freezes the ATR at the moment of the fill:
if newTrade
entryAtr := nz(atr[1], atr) // ATR as of the signal bar, not the current oneIf it used the live ATR, the stop and target would drift every bar as volatility changed - your risk would be a moving target. Freezing it is the difference between a strategy you can reason about and one you cannot.
Breakeven: the feature you should be suspicious of
if useBreakeven and high >= entry + risk * breakevenRR
beArmed := true
curSL := beArmed ? math.max(initSL, entry + risk * beOffsetR) : initSLOnce price moves 1R in your favour, the stop is pulled up to (just above) the entry, so the trade "cannot lose". It feels like free protection. It usually is not. We will test that intuition properly in the next post - the short version is that it removes some winners and does nothing for your worst losses.
What you can take to the tables here
You cannot run Pine on tradegame.org - but you can practice the *thinking*:
- ▸Trade with the trend. Before you buy, ask which way the longer trend points. That is the 200-EMA filter, done by eye.
- ▸Decide your risk before your size. Choose how much of your 100,000 you are willing to lose on a trade first, then size accordingly.
- ▸Let winners run to a plan. A fixed reward-to-risk target beats closing trades on feeling.
Practising these with virtual money is exactly what the simulator is for. When you are ready to see whether a strategy like this actually holds up, read part two.
Next: How to Optimise a Trading Strategy Without Fooling Yourself - why a great backtest is usually a lie, and how to build one that is not.
*Nothing here is financial advice. This is methodology for understanding trading systems, not a claim that any system will make money.*