A Strategy That Compiled Perfectly and Still Lost Money
A session range break strategy that built with zero errors and finished at 0.939 profit factor. The code was fine and the exit rule was not.
Key Takeaways
- Compiling proves syntax is valid, not that the idea has an edge.
- A time-based exit caps winners while leaving losers at full risk distance.
- Profit factor below 1.0 means the sample lost money regardless of win rate.
- Read exit reasons in the trade list to separate a code bug from a rule problem.
- Position sizing assumes a reward the exit rule has to actually allow.
The script built with zero errors. Every order call was correctly formed. Risk was sized off account equity and the stop distance. The table rendered, the levels drew where they should, the markers landed on the right bars.
It finished with a profit factor of 0.939.
That is a useful result to look at closely, because nothing about it was a coding failure. This is what a correctly implemented bad idea looks like.
The strategy
A session range break with risk-based sizing:
- track the high and low of a defined session
- arm a long above the range high and a short below the range low
- enter on the break, place a stop the other side of the range, set a target at a fixed multiple
- close anything still open at the session close
That last rule is the whole story, though it does not look like much when you write it.
What the backtest returned
Over the sample:
| Metric | Result |
|---|---|
| Trades | 19 |
| Net P&L | −3,030.28 (−0.30%) |
| Max drawdown | 28,267.78 (2.80%) |
| Win rate | 36.84% (7 of 19) |
| Profit factor | 0.939 |
A 36.84% win rate is not the problem on its own. Plenty of profitable strategies win a third of the time, because the wins are large enough to carry the losses. Profit factor is where it breaks: 0.939 means the strategy earned 93.9 for every 100 it gave back.
Where the money went
The trade list explains it, and this is the part worth learning to read. The exit reasons were not evenly distributed. Several winners closed with the comment Session end at values like +119.2 and +135.4 — a fraction of what the target would have paid.
The losers had no equivalent brake. A stop is a price, and price reaches it whenever it reaches it. So the rule set was asymmetric in the worst direction:
- losers ran the full planned risk distance
- winners were interrupted by the clock
Position sizing made this sharper rather than softer. Risk was sized on the assumption of a reward multiple that the exit rule frequently did not permit. Every trade was sized for a payoff it was not allowed to collect.
How to tell this apart from a code bug
Read the exit reasons before you touch the source.
If trades are closing for reasons you deliberately wrote — session end, time stop, opposite signal — the code is doing its job and the rules need work. If trades close for reasons you never wrote, or at prices that do not correspond to any level you defined, then look at the code.
That distinction saves a lot of wasted effort. It is very common to rewrite working logic because a backtest disappointed, when the honest problem was the rule set all along.
What would actually help this strategy
Not a refactor. Options that change the distribution rather than the syntax:
- Let the session-end rule apply only to losing positions, so the clock stops losses but does not cap wins.
- Move the stop to break-even once price travels a defined distance, so the interrupted trades exit flat instead of small.
- Size from the realistic payoff rather than the target, if the exit rule genuinely has to stay. If most winners close at 0.6R, size for 0.6R.
- Test whether the session boundary matters at all. Sometimes the constraint is inherited from a habit rather than from the market.
Each of those is a change to the idea. That is the point.
The part the compiler cannot check
There are three separate questions, and passing one says nothing about the next:
- Does it build?
- Does it do what I described?
- Is what I described worth doing?
A validator can answer the first. Careful reading of the source and the plotted output answers the second. Only exposure to bars you have not already studied answers the third — and that is judgement, built by making calls before you know the outcome and finding out where your reasoning was wrong.
Review checklist
Reading a backtest honestly
- Check profit factor before win rate: a high win rate can still lose money
- Group the exits by reason and see which rule is closing your winners
- Compare the average win to the risk you sized for, not to the target
- Ask whether every constraint in the rules is there for a reason you can state
- Judge the idea on charts you have not already optimised against
Next step
Replay strategy code setups inside SkillCandle
Move from reading about the setup to actually practicing it with a partial chart, replay reveal, and tracked review notes.
FAQ
Questions traders ask about this topic
What does a profit factor of 0.939 mean?
Gross profit divided by gross loss. At 0.939 the strategy made 93.9 units for every 100 it lost, so it was slightly worse than breaking even before costs. Anything below 1.0 loses money over the sample.
Can a strategy be coded correctly and still be unprofitable?
Yes, and it is the normal case. Compiling proves the syntax is valid and the orders are well formed. It says nothing about whether the rules have an edge. Most losing strategies are correctly implemented bad ideas.
Why is a time-based exit risky?
Because it caps winners without capping losers. A stop still sits the full risk distance away, but a time exit can close a trade before it reaches target, so the reward side of the ratio you sized for never arrives.
How do I tell a code bug from a rule problem?
Read the exit reasons in the trade list. If trades are closing for the reason you intended, the code works and the rules are the problem. If they close for reasons you never wrote, look at the code.
Related Reads
Keep building the cluster
Pine Script v6 Errors That Stop Your Script Compiling
The Pine v6 mistakes that actually break a TradingView build, what each error means, and the ones that compile cleanly and still draw nothing on your chart.
Break-Even Win Rate Calculator for Risk Reward [Free Tool]
See how reward-to-risk changes the win rate your setup needs just to break even, with worked examples for 1R, 2R and 3R ideas.
ATR Stop Placement for Replay Traders
Use ATR as a stop-placement reference in replay practice so stops reflect volatility rather than a random distance, combined with structure and sizing.