Advertisement IC Markets

Local LLMs for Pine Script v6: Gemma 4 (12B vs. 26B MoE vs. 31B)

Share, develop, and backtest custom MQL4/MQL5 Expert Advisors, Python data-scraping scripts, trading bots, and automated market alert systems.
LondonNewsTrader
Posts: 421
Joined: Mon Sep 21, 2026 9:30 am

Re: Local LLMs for Pine Script v6: Gemma 4 (12B vs. 26B MoE vs. 31B)

Post by LondonNewsTrader »

PTScalper wrote: This prompt is deliberately structured to bait the LLM into making three of the most common repainting errors: multi-timeframe (MTF) lookahead bias, intrabar signal flickering, and drifting stop-losses.
Good test design. I'd score one more thing: whether the model pushes back on requirement 2. "Backtest results must perfectly match live execution" can't be met by any strategy, because live fills include spread changes and slippage that the tester doesn't model. A model that claims to satisfy it without comment is telling you something about how much to trust the rest of the answer.

For marking the MTF part, the answer I'd expect is the daily values taken with the previous-bar offset, close[1] and the ATR of the prior day, requested with lookahead switched on. That returns only completed daily data on both historical and live bars. Models often get it backwards and use lookahead without the offset, which looks perfect in the backtest.

The drifting stop is the one I see most in human code as well. The ATR has to be captured once at entry and stored in a var, otherwise the stop moves every day as the daily ATR changes, and it moves a lot after a big release.
Recommended broker for automated trading & scalping IC Markets
FXS Prop Desk
Posts: 1689
Joined: Wed Oct 07, 2026 9:52 am

Re: Local LLMs for Pine Script v6: Gemma 4 (12B vs. 26B MoE vs. 31B)

Post by FXS Prop Desk »

For readers, the key lesson is that the higher-timeframe call with lookahead disabled still needs the [1] offset on the expression for higher-timeframe values to be safe in backtests. A simple way to check any generated script is to compare its live alerts with what the backtest shows for the same bars over a few days.

For anyone using local models, giving the model a short list of known pitfalls (lookahead, repainting, unconfirmed bars) in the prompt often improves the output noticeably.
FXS Official Team | The Idea Lab & Strategy
Post Reply