Prompt & code library
Copy-ready AI prompts and short Pine Script and Python snippets for building and reviewing your own trading tools. Every item says what it is for and whether we tested it. Replace SYMBOL with whatever you study.
Educational only. These are software templates, not trading strategies, signals or advice. Nothing here suggests what to buy or sell. Backtest results do not predict future returns; test everything yourself before relying on it.
Prompts
Turn a trading idea into exact backtest rules
Forces vague ideas into unambiguous, testable rules before any code is written.
Prompt: output depends on the AI model; always review it
You are helping me write rules for a backtest. Do not suggest trades, tickers or whether the idea is good.
My idea, in plain words: [describe the idea]
Market and timeframe: SYMBOL, [timeframe]
Rewrite it as exact rules:
1. Entry condition(s), using only data available at the bar close.
2. Exit condition(s): target, stop, time exit.
3. Position sizing rule.
4. Costs to include: commission per trade and slippage assumption.
5. Anything ambiguous in my description: list it as a question instead of guessing.
Return the rules as a numbered list, then a list of open questions. Generate Pine Script v6 with a review checklist
Gets a first Pine Script draft plus a checklist for catching common AI coding mistakes.
Prompt: output depends on the AI model; always review it
Write a TradingView Pine Script v6 script for SYMBOL that implements exactly these rules:
[paste your numbered rules]
Requirements:
- Start with //@version=6 and use input() for every number so I can change it.
- Use only confirmed bar data (no lookahead; request.security with lookahead off).
- Set commission and slippage in the strategy() declaration.
- Comment each block in plain English.
After the code, give me this review checklist filled in for your script:
[ ] Compiles without errors in the Pine Editor
[ ] Uses only data available at each bar close (no repainting)
[ ] Entry and exit match each numbered rule
[ ] Commission and slippage are set
[ ] Results checked on a period the rules were not designed on
Do not tell me whether the strategy will make money. Overfitting check for a backtest result
Asks an AI to look for the usual signs that a backtest is curve-fit.
Prompt: output depends on the AI model; always review it
Act as a skeptical reviewer of a backtest. Do not give trade advice.
Here are my rules, parameters and results for SYMBOL:
[paste rules, parameter values, number of trades, date range, metrics]
Check and report on:
1. How many parameters were tuned versus how many trades there are.
2. Whether results were judged on data not used for tuning (out-of-sample / walk-forward).
3. Sensitivity: would nearby parameter values likely give very different results?
4. Costs: are commission and slippage realistic and included?
5. Lookahead or survivorship bias risks in how the data was built.
End with a list of concrete tests I should run next. Do not predict future performance. Weekly trading journal review
Turns a week of journal notes into process feedback, not predictions.
Prompt: output depends on the AI model; always review it
Here is my trading journal for the week (one line per trade: date, setup name, planned risk, result, notes):
[paste journal]
Review my process only. Do not suggest tickers or future trades.
1. Which trades followed my written plan and which did not?
2. Patterns in mistakes (timing, size, skipped rules, emotions in the notes).
3. One rule I should write down or tighten for next week.
4. Questions I should answer before I trade again. Pine Scripts
Indicator skeleton with inputs
A minimal starting point: inputs, a moving average and a plot. Paste into the Pine Editor and build from there.
Not tested in TradingView
//@version=6
indicator("SYMBOL moving average (template)", overlay = true)
len = input.int(20, "Length", minval = 1)
src = input.source(close, "Source")
ma = ta.sma(src, len)
plot(ma, "SMA", color = color.blue) Strategy skeleton with costs set
Shows where commission, slippage and sizing go so backtests are not cost-free. Entry and exit logic is left for you to write.
Not tested in TradingView
//@version=6
strategy("SYMBOL strategy template", overlay = true,
initial_capital = 10000,
default_qty_type = strategy.percent_of_equity, default_qty_value = 10,
commission_type = strategy.commission.percent, commission_value = 0.05,
slippage = 2)
// Write your own rules here. Use only confirmed bar data.
longCondition = false // replace with your entry rule
exitCondition = false // replace with your exit rule
if longCondition
strategy.entry("Long", strategy.long)
if exitCondition
strategy.close("Long") Pythons
Total return and max drawdown from a CSV
Quick sanity numbers for a price or equity series. Standard library only.
✓ Tested: ran locally with Python 3.13.5 on a small sample file (Oct 22, 2026)
# Max drawdown and total return from a CSV with columns: date,close
# Usage: python drawdown.py SYMBOL.csv
import csv, sys
def load_closes(path):
with open(path, newline="") as f:
return [float(row["close"]) for row in csv.DictReader(f)]
def max_drawdown(closes):
peak, worst = closes[0], 0.0
for c in closes:
peak = max(peak, c)
worst = min(worst, c / peak - 1)
return worst
if __name__ == "__main__":
closes = load_closes(sys.argv[1] if len(sys.argv) > 1 else "SYMBOL.csv")
print(f"Bars: {len(closes)}")
print(f"Total return: {closes[-1] / closes[0] - 1:.2%}")
print(f"Max drawdown: {max_drawdown(closes):.2%}")
Walk-forward window generator
Splits your data into train/test windows so you judge results only on unseen data.
✓ Tested: ran locally with Python 3.13.5 on a small sample file (Oct 22, 2026)
# Walk-forward windows: tune on "train", judge only on the unseen "test" slice.
# Returns (train_start, train_end, test_start, test_end) index ranges, end exclusive.
def walk_forward(n_bars, train=500, test=100, step=None):
step = step or test
windows, start = [], 0
while start + train + test <= n_bars:
windows.append((start, start + train, start + train, start + train + test))
start += step
return windows
if __name__ == "__main__":
for w in walk_forward(1000, train=500, test=100):
print(w)
Journal stats: win rate, expectancy, profit factor
Summarizes a journal export with a pnl column. Standard library only.
✓ Tested: ran locally with Python 3.13.5 on a small sample file (Oct 22, 2026)
# Journal review stats from a CSV export with a numeric "pnl" column (one row per closed trade).
# Usage: python journal_stats.py trades.csv
import csv, sys
def stats(pnls):
wins = [p for p in pnls if p > 0]
losses = [p for p in pnls if p < 0]
gross_loss = -sum(losses)
return {
"trades": len(pnls),
"win_rate": len(wins) / len(pnls) if pnls else 0.0,
"avg_win": sum(wins) / len(wins) if wins else 0.0,
"avg_loss": sum(losses) / len(losses) if losses else 0.0,
"expectancy": sum(pnls) / len(pnls) if pnls else 0.0,
"profit_factor": sum(wins) / gross_loss if gross_loss else float("inf"),
}
if __name__ == "__main__":
with open(sys.argv[1] if len(sys.argv) > 1 else "trades.csv", newline="") as f:
pnls = [float(r["pnl"]) for r in csv.DictReader(f)]
for k, v in stats(pnls).items():
print(f"{k:>14}: {v:.2f}" if isinstance(v, float) else f"{k:>14}: {v}")
Want the full setup?
The $19 Setup Pack goes further than this free library, with complete templates and step-by-step workflows. Software education only.
Frequently asked questions
What is in the library?
Copy-ready AI prompts and short Pine Script and Python snippets for building and reviewing your own trading tools.
Have the snippets been tested?
Each item says whether we tested it. Test everything yourself before relying on it.
Are these trading strategies?
No. They are software templates, not strategies, signals or advice. Backtest results do not predict future returns.
What does SYMBOL mean in the snippets?
It is a placeholder. Replace SYMBOL with whatever instrument you study; we never suggest what to trade.
