Tomoru 投資×AI
AI活用事例2026-07-30

ClaudeでPine Script戦略を自動作成 トレンドフォロー例

ClaudeでPine Script戦略を自動作成 トレンドフォロー例

元AIトレーディングボット開発者のDavidd Tech氏(@DaviddDotTech)のX投稿が参考になりそうでしたので紹介します。投稿ではClaudeに具体的な指示を与えてTradingViewのPine Script v6コードを生成させる方法が示されています。

動画を再生

Davidd Tech氏のプロンプト例

Davidd Tech氏は次のプロンプト例を提示しています。

Build a trend-following strategy for [pair] on the [timeframe]
Use 1 indicator for trend direction, 2 non-correlated indicators for confirmation, 1 volatility filter, stop loss on the ATR bands, take profit set by risk-to-reward
Every rule computable, zero discretion. No multi-timeframe take profits, they repaint and inflate the backtest. Include commission and slippage
Write it as TradingView Pine Script v6, ready to paste into the Pine Editor

(訳)[pair]の[timeframe]でトレンドフォロー戦略を構築せよ。トレンド方向に1つの指標、確認に相関のない2つの指標、ボラティリティフィルターを1つ使い、ATRバンドでストップロス、リスクリワードでテイクプロフィットを設定せよ。すべてのルールは計算可能で裁量ゼロにせよ。マルチタイムフレームのテイクプロフィットは使わず、再描画とバックテストの誇張を避けよ。手数料とスリッページを含め、TradingView Pine Script v6で記述し、Pineエディタに貼り付け可能にせよ。

投稿本文にはこれ以外の詳細は触れられていません。氏によると、このプロンプトで数分で完全な戦略コードが出力され、バックテスト→フォワードテスト→少額取引の3ステップをクリアすれば大多数のトレーダーより優位に立てる可能性があるとしています。

この設計が効果的な理由

プロンプトのポイントは「1指標+確認指標2つ+ボラフィルター+ATRストップ+RRベースTP」という具体的な構成にあります。すべてのルールを計算可能に指定することで、AIが出力するコードに裁量が入りにくくなります。マルチタイムフレームのTPを避ける点も、再描画によるバックテストの過大評価を防ぐ工夫です。

いわば、料理のレシピを「材料・分量・手順・火加減」まで細かく指定してAIに作らせるようなものです。曖昧な指示だと一般論的なコードしか出ませんが、このように条件を積み重ねると実用的な戦略コードが得られやすいと考えられます。

日本市場での応用可能性

TradingViewは日本株(例: 7203.T)や為替(USDJPY)にも対応しています。海外の株価指数ペアだけでなく、東証上場銘柄の日足や60分足で同じロジックを試せます。TradingViewのチャートデータを使えば日本市場の動きに合わせた戦略生成が可能です。

日本株の場合、PERや出来高を追加で考慮した確認指標を指定するなど、現地の取引ルールに寄せたプロンプト調整が有効でしょう。

試すための手順

1. TradingViewアカウントにログインし、Pineエディタを開く。

2. Claude(claude.ai)に以下のプロンプトをコピーして貼り付け、[pair]と[timeframe]を置き換える。

3. 生成されたコードをPineエディタに貼り付け、保存してチャートに適用する。

4. バックテストを実行し、結果を確認する。

5. 問題があればプロンプトを調整して再生成する。

そのままコピーして使えるプロンプト例を3つ用意しました。日本株・為替向けに調整しています。

Build a trend-following strategy for 7203.T on the Daily
Use 1 indicator for trend direction, 2 non-correlated indicators for confirmation, 1 volatility filter, stop loss on the ATR bands, take profit set by risk-to-reward
Every rule computable, zero discretion. No multi-timeframe take profits, they repaint and inflate the backtest. Include commission and slippage
Write it as TradingView Pine Script v6, ready to paste into the Pine Editor
Build a trend-following strategy for USDJPY on the 60 minute
Use 1 indicator for trend direction, 2 non-correlated indicators for confirmation, 1 volatility filter, stop loss on the ATR bands, take profit set by risk-to-reward
Every rule computable, zero discretion. No multi-timeframe take profits, they repaint and inflate the backtest. Include commission and slippage
Write it as TradingView Pine Script v6, ready to paste into the Pine Editor
Build a trend-following strategy for 9983.T on the Daily
Use 1 indicator for trend direction, 2 non-correlated indicators for confirmation, 1 volatility filter, stop loss on the ATR bands, take profit set by risk-to-reward
Every rule computable, zero discretion. No multi-timeframe take profits, they repaint and inflate the backtest. Include commission and slippage
Write it as TradingView Pine Script v6, ready to paste into the Pine Editor

最初に試す題材は、流動性の高い日本株(例: トヨタ自動車7203.T)や主要為替ペアをおすすめします。出力が浅い場合は「non-correlated indicatorsの例としてRSIとMACDを避け、ボリュームとADXを指定」など具体的に指示を追加してください。

注意点

この手法はAI生成コードの品質に依存します。生成された戦略は必ず自分でバックテストとフォワードテストを行い、少額から検証してください。個人の投稿のため、成果の検証は限定的です。AIの出力は参考情報として扱い、最終判断はご自身で行うことをおすすめします。

本記事のポイント

AIに「何を・どう設計して・何を避けるか」を具体的に指示すれば、短時間で実用的な取引戦略コードが手に入る可能性があります。日本市場でもTradingViewのデータを使えば同じアプローチが試せます。まずは1つのプロンプトをコピーしてClaudeで試してみるのが近道でしょう。

ぼちぼち積み上げていきましょう。また明日、別の事例を紹介します。

※本記事は情報提供・教育目的で作成しています。投資助言ではありません。特定のサービス・銘柄の利用や売買を推奨するものではなく、過去の成果は将来を保証するものではありません。

出典

X @DaviddDotTech

https://x.com/DaviddDotTech/status/2082504638108987678

Tomoru(灯)/株式会社ボストーク — 情報提供・分析であり、投資助言ではありません。
← 記事一覧へ