(window.webpackJsonp=window.webpackJsonp||[]).push([[3],{XqPw:function(e,t,n){"use strict";n.r(t),n.d(t,"_frontmatter",(function(){return o})),n.d(t,"default",(function(){return m}));var a=n("Fcif"),l=n("dV/x"),b=(n("mXGw"),n("/FXl")),r=n("TjRS"),i=n("wCAC");n("l1C2");const c=["components"],o={};void 0!==o&&o&&o===Object(o)&&Object.isExtensible(o)&&!Object.prototype.hasOwnProperty.call(o,"__filemeta")&&Object.defineProperty(o,"__filemeta",{configurable:!0,value:{name:"_frontmatter",filename:"src/components/ja/Scripting.mdx"}});const p={_frontmatter:o},d=r.a;function m(e){let{components:t}=e,n=Object(l.a)(e,c);return Object(b.b)(d,Object(a.a)({},p,n,{components:t,mdxType:"MDXLayout"}),Object(b.b)("h1",{id:"カスタムインジケーターapi"},"カスタムインジケーターAPI"),Object(b.b)(i.e,{mdxType:"Lead"},"JavaScriptで独自のインジケーターを作成し、チャートの横の安全なサンドボックスで実行して、他のユーザーと共有できます。APIは市場データ(ローソク足、オーダーブック、クラスター、清算、デリバティブデータ)、描画プリミティブ、テクニカル分析ヘルパー、アラートを提供します。"),Object(b.b)("h2",{id:"aiでインジケーターを生成する"},"AIでインジケーターを生成する"),Object(b.b)("p",null,"API全体は、言語モデル向けの1つのテキストファイルとしても利用できます: ",Object(b.b)("a",{parentName:"p",href:"../../public/AI-scripting.txt"},"AI-scripting.txt"),"。ChatGPT、Claude、Gemini などのLLMに添付し、作りたいインジケーターを説明してください。"),Object(b.b)("p",null,"プロンプトの例:"),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-text"},"Read the attached [AI-scripting.txt] https://mobchart.com/docs/public/AI-scripting.txt file and use it as the only reference for the MobChart scripting API.\n\nCreate a custom indicator that plots a 20-period EMA and a 50-period EMA on the chart. Color the candles green when EMA20 is above EMA50 and red otherwise.\n\nUse only the documented API. Do not invent functions. Return the complete indicator code.\n")),Object(b.b)("h2",{id:"サンドボックスと制限"},"サンドボックスと制限"),Object(b.b)(i.b,{type:"warning",title:"現在の制限",mdxType:"Callout"},Object(b.b)("ul",null,Object(b.b)("li",{parentName:"ul"},"スクリプトは安全なJavaScriptサンドボックス内で実行されます。"),Object(b.b)("li",{parentName:"ul"},"スクリプトの実行時間の上限は ",Object(b.b)("inlineCode",{parentName:"li"},"1500ms")," です。"),Object(b.b)("li",{parentName:"ul"},"返されるデータ配列は ",Object(b.b)("strong",{parentName:"li"},"5000")," 要素までに制限されているため、インジケーターは ",Object(b.b)("strong",{parentName:"li"},"5000本のローソク足")," より前を参照できません。"),Object(b.b)("li",{parentName:"ul"},"1つのインジケーター内で許可される ",Object(b.b)("strong",{parentName:"li"},"データソースリクエストは最大8回")," です。"),Object(b.b)("li",{parentName:"ul"},"1回の実行で許可される ",Object(b.b)("strong",{parentName:"li"},"HTTPリクエスト"),"(",Object(b.b)("inlineCode",{parentName:"li"},"http.get")," / ",Object(b.b)("inlineCode",{parentName:"li"},"http.post"),")は ",Object(b.b)("strong",{parentName:"li"},"最大3回")," です。",Object(b.b)("strong",{parentName:"li"},"HTTPリクエスト")," を参照してください。"))),Object(b.b)("h2",{id:"インジケーターの開発"},"インジケーターの開発"),Object(b.b)("p",null,"インジケーターの開発は専用のウィジェットで行います。このウィジェットは、インジケーターを有効にするチャートの横に配置できます。"),Object(b.b)(i.f,{src:"../../public/chart_code.png",mdxType:"Screenshot"}),Object(b.b)("h2",{id:"インジケーターの作成"},"インジケーターの作成"),Object(b.b)("h3",{id:"definetitle-description-type-ispublic-ispubliccode-options"},Object(b.b)("inlineCode",{parentName:"h3"},"define(title, description, type, isPublic, isPublicCode, options)")),Object(b.b)("p",null,"インジケーターをシステムに登録します。"),Object(b.b)("table",null,Object(b.b)("thead",{parentName:"table"},Object(b.b)("tr",{parentName:"thead"},Object(b.b)("th",{parentName:"tr",align:null},"パラメーター"),Object(b.b)("th",{parentName:"tr",align:null},"型"),Object(b.b)("th",{parentName:"tr",align:null},"説明"))),Object(b.b)("tbody",{parentName:"table"},Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"title")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"string")," ","|"," ",Object(b.b)("inlineCode",{parentName:"td"},"object")),Object(b.b)("td",{parentName:"tr",align:null},"インジケーター名、または言語マップ(「ローカライズ」を参照)")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"description")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"string")," ","|"," ",Object(b.b)("inlineCode",{parentName:"td"},"object")),Object(b.b)("td",{parentName:"tr",align:null},"短い説明、または言語マップ(「ローカライズ」を参照)")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"type")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"'onchart'")," ","|"," ",Object(b.b)("inlineCode",{parentName:"td"},"'offchart'")," ","|"," ",Object(b.b)("inlineCode",{parentName:"td"},"'widget'")),Object(b.b)("td",{parentName:"tr",align:null},"インジケーターの配置(チャート上、または別パネル)")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"isPublic")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"true")," ","|"," ",Object(b.b)("inlineCode",{parentName:"td"},"false")),Object(b.b)("td",{parentName:"tr",align:null},"インジケーターを公開するかどうか")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"isPublicCode")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"true")," ","|"," ",Object(b.b)("inlineCode",{parentName:"td"},"false")),Object(b.b)("td",{parentName:"tr",align:null},"ソースコードを公開するかどうか")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"options")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"object"),"(任意)"),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"{ fullRange, warmup }"),"、下記参照")))),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"例:")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'define("My Indicator", "Shows EMA line", "onchart", true, false);\n')),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"計算範囲。")," デフォルトでは、スクリプトはチャートのうち計算が必要な部分だけを計算します。つまり、過去へスクロールして読み込まれたバー、または更新時の最新のバーに加えて、その前にある ",Object(b.b)("strong",{parentName:"p"},Object(b.b)("inlineCode",{parentName:"strong"},"warmup"))," 本の履歴バー(デフォルト500)です。これらの履歴バーは計算には必要ですが、結果としては返されません。インジケーターに必要な履歴がこれより多い、または少ない場合は ",Object(b.b)("inlineCode",{parentName:"p"},"warmup")," を宣言してください。例えば EMA(200) なら ",Object(b.b)("inlineCode",{parentName:"p"},"{ warmup: 200 }")," です。値や図形が ",Object(b.b)("strong",{parentName:"p"},"表示範囲全体")," に依存するスクリプト(最初の表示ローソク足からの VWAP、累積デルタ、表示範囲の最大値に置くラベル、チャート全体に引くレベルなど)は ",Object(b.b)("inlineCode",{parentName:"p"},"{ fullRange: true }")," を宣言する必要があります。そうしないと、さらに履歴を読み込んだ後に結果が正しくなくなります。モードはスクリプトを保存するたびに ",Object(b.b)("inlineCode",{parentName:"p"},"define()")," から読み取られます。",Object(b.b)("inlineCode",{parentName:"p"},"fullRange")," なしで保存されたスクリプトは部分的に計算されるため、既存の累積型スクリプトを編集するときはこのフラグを追加してください。部分計算のスクリプトは分割して読み込まれます。長い履歴の上でスクリプトを有効にすると、チャートはまず最新の500本のローソク足(",Object(b.b)("inlineCode",{parentName:"p"},"warmup")," の方が多い場合は ",Object(b.b)("inlineCode",{parentName:"p"},"warmup")," 本)をリクエストし、古い部分は1リクエストずつ続けて読み込まれるため、表示部分はすぐに表示されます。",Object(b.b)("inlineCode",{parentName:"p"},"fullRange")," のスクリプトは常に範囲全体を1回のリクエストで計算します。"),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'define("Window max", "Label at the highest visible high", "onchart", true, true, { fullRange: true });\n')),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"onchart")," と ",Object(b.b)("strong",{parentName:"p"},"offchart")," のインジケーター配置:"),Object(b.b)(i.f,{src:"../../public/onchart_offchart.png",mdxType:"Screenshot"}),Object(b.b)("h2",{id:"入力パラメーター"},"入力パラメーター"),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},Object(b.b)("inlineCode",{parentName:"strong"},"input"))," クラスと ",Object(b.b)("strong",{parentName:"p"},Object(b.b)("inlineCode",{parentName:"strong"},"style"))," クラスを使うと、ユーザーが変更できる設定を作成できます(PineScript の ",Object(b.b)("inlineCode",{parentName:"p"},"input()")," に相当します)。"),Object(b.b)("table",null,Object(b.b)("thead",{parentName:"table"},Object(b.b)("tr",{parentName:"thead"},Object(b.b)("th",{parentName:"tr",align:null},"メソッド"),Object(b.b)("th",{parentName:"tr",align:null},"説明"))),Object(b.b)("tbody",{parentName:"table"},Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"number(title, defaultValue, min, max, step)")),Object(b.b)("td",{parentName:"tr",align:null},"数値入力")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"range(title, defaultValue, min, max, step)")),Object(b.b)("td",{parentName:"tr",align:null},"範囲入力")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"select(title, defaultValue, values)")),Object(b.b)("td",{parentName:"tr",align:null},"ドロップダウン選択")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"color(title, defaultValue)")),Object(b.b)("td",{parentName:"tr",align:null},"カラーピッカー")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"boolean(title, defaultValue)")),Object(b.b)("td",{parentName:"tr",align:null},"真偽値入力")))),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"主なパラメーター用の例(input):")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'const length = input.number("Period", 14, 1, 100, 1);\nconst type = input.select("Type", \'sma\', [\'sma\', \'ema\']);\nconst color = input.color("Line Color", "#FF0000");\n')),Object(b.b)("p",null,Object(b.b)("inlineCode",{parentName:"p"},"select")," の ",Object(b.b)("inlineCode",{parentName:"p"},"values")," には単純な値と ",Object(b.b)("inlineCode",{parentName:"p"},"{ title, value }")," 形式の項目を混在できます。ドロップダウンには ",Object(b.b)("inlineCode",{parentName:"p"},"title")," が表示され、スクリプトは ",Object(b.b)("inlineCode",{parentName:"p"},"value")," を受け取ります。単純な値はそのまま表示されます。"),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'const sessionReset = input.select("Session Reset", "none", [\n { title: "No reset", value: "none" },\n { title: "Every day", value: "daily" },\n "weekly",\n]);\n')),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"または表示用パラメーターには(style):")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'const length = style.number("Size", 14, 1, 100, 1);\nconst color = style.select("Background Color", \'#FF0000\', ["#FF0000", "#AA0000", "#BB0000"]);\nconst color = style.color("Background Color", "#FF0000");\n')),Object(b.b)(i.f,{src:"../../public/input_style.png",mdxType:"Screenshot"}),Object(b.b)("h2",{id:"ローカライズ"},"ローカライズ"),Object(b.b)("p",null,"スクリプトはユーザーの言語で話せます。グローバル変数 ",Object(b.b)("strong",{parentName:"p"},Object(b.b)("inlineCode",{parentName:"strong"},"userLocale"))," は、スクリプトを実行しているユーザーのインターフェース言語です:",Object(b.b)("inlineCode",{parentName:"p"},"en"),"、",Object(b.b)("inlineCode",{parentName:"p"},"ru"),"、",Object(b.b)("inlineCode",{parentName:"p"},"uk"),"、",Object(b.b)("inlineCode",{parentName:"p"},"de"),"、",Object(b.b)("inlineCode",{parentName:"p"},"fr"),"、",Object(b.b)("inlineCode",{parentName:"p"},"zh"),"、",Object(b.b)("inlineCode",{parentName:"p"},"es"),"、",Object(b.b)("inlineCode",{parentName:"p"},"tr"),"、",Object(b.b)("inlineCode",{parentName:"p"},"ko"),"、",Object(b.b)("inlineCode",{parentName:"p"},"ja"),"(不明な場合は ",Object(b.b)("inlineCode",{parentName:"p"},"en"),"。アラートと AI エージェントの実行では、ユーザーがアプリで最後に使った言語が使われます)。"),Object(b.b)("p",null,"スクリプトが人に見せるテキストを指定する場所では、文字列の代わりに",Object(b.b)("strong",{parentName:"p"},"言語マップ"),"を渡せます:",Object(b.b)("inlineCode",{parentName:"p"},'{ en: "Key levels", ja: "主要レベル" }'),"。ユーザーには自分の言語、なければ ",Object(b.b)("inlineCode",{parentName:"p"},"en"),"、それもなければマップの最初の言語が表示されます。マップを受け付けるもの:"),Object(b.b)("ul",null,Object(b.b)("li",{parentName:"ul"},Object(b.b)("inlineCode",{parentName:"li"},"define()")," の ",Object(b.b)("inlineCode",{parentName:"li"},"title")," と ",Object(b.b)("inlineCode",{parentName:"li"},"description"),":スクリプト一覧、検索、凡例はユーザーの言語で表示され、検索はどの言語のタイトルでもスクリプトを見つけます;"),Object(b.b)("li",{parentName:"ul"},Object(b.b)("inlineCode",{parentName:"li"},"input.*"),"、",Object(b.b)("inlineCode",{parentName:"li"},"style.*"),"、",Object(b.b)("inlineCode",{parentName:"li"},"alertInput.*")," の設定ラベルと ",Object(b.b)("inlineCode",{parentName:"li"},"select")," の選択肢の ",Object(b.b)("inlineCode",{parentName:"li"},"title"),"。設定は変数名で対応付けられるため、翻訳したラベルでも保存済みの値はそのまま使われます。")),Object(b.b)("p",null,"それ以外のテキスト(テーブルの列、シリーズのタイトル、ラベル、ログ、アラートのメッセージ)には ",Object(b.b)("strong",{parentName:"p"},Object(b.b)("inlineCode",{parentName:"strong"},"localize(map)"))," を使います:マップのテキストをユーザーの言語で返します(文字列はそのまま返します)。"),Object(b.b)("p",null,"マップはコードに直接書いてください(呼び出しの中か ",Object(b.b)("inlineCode",{parentName:"p"},"const")," で):タイトルと説明はスクリプトの保存時に ",Object(b.b)("inlineCode",{parentName:"p"},"define()")," から読み取られます。"),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"例:")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'const title = { en: "Key levels", ru: "Ключевые уровни" };\nconst description = {\n en: "Dynamic Daily / Prev Day / Weekly / Monthly / Prev Month OHLC levels",\n ru: "Динамические уровни OHLC: день, прошлый день, неделя, месяц, прошлый месяц",\n};\ndefine(title, description, "onchart", true, true, { fullRange: true });\n\n// visibility toggles: the settings keep their values whatever the language (matched by the variable name)\nconst showDaily = input.boolean({ en: "Show Daily Levels", ru: "Показать дневные уровни" }, true);\nconst showWeekly = input.boolean({ en: "Show Weekly Levels", ru: "Показать недельные уровни" }, true);\nconst priceSource = input.select({ en: "Price", ru: "Цена" }, "close", [\n { title: { en: "Close", ru: "Закрытие" }, value: "close" },\n { title: { en: "Open", ru: "Открытие" }, value: "open" },\n]);\n// colors\nconst colorDaily = style.color({ en: "Daily Levels", ru: "Дневные уровни" }, "#00C8FF");\nconst colorWeekly = style.color({ en: "Weekly Levels", ru: "Недельные уровни" }, "#4CAF50");\n\n// any other text: localize()\nlogger.log(localize({ en: "Language:", ru: "Язык:" }), userLocale);\n')),Object(b.b)("h2",{id:"データソース"},"データソース"),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},Object(b.b)("inlineCode",{parentName:"strong"},"source"))," クラスはサーバーから市場データを取得します。ローソク足ベースのメソッドは同じパラメーターを受け取ります。2つのライブスナップショットは異なり、",Object(b.b)("inlineCode",{parentName:"p"},"orderbook()")," は取引所とティッカーを、",Object(b.b)("inlineCode",{parentName:"p"},"levels()")," は取引所と設定オブジェクトを受け取ります。"),Object(b.b)("table",null,Object(b.b)("thead",{parentName:"table"},Object(b.b)("tr",{parentName:"thead"},Object(b.b)("th",{parentName:"tr",align:null},"パラメーター"),Object(b.b)("th",{parentName:"tr",align:null},"説明"))),Object(b.b)("tbody",{parentName:"table"},Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"exchange"),", ",Object(b.b)("inlineCode",{parentName:"td"},"ticker"),", ",Object(b.b)("inlineCode",{parentName:"td"},"timeframe")),Object(b.b)("td",{parentName:"tr",align:null},"デフォルトはインジケーターを開いているチャートの値です。別の市場のデータを取得するには、別の値を渡します。")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"lookback")),Object(b.b)("td",{parentName:"tr",align:null},"現在の日付からの履歴バーの本数。",Object(b.b)("strong",{parentName:"td"},"5000以下")," です。")))),Object(b.b)(i.b,{type:"note",title:"データはチャートのローソク足に揃えられます",mdxType:"Callout"},Object(b.b)("p",null,"チャートの時間足の ",Object(b.b)("inlineCode",{parentName:"p"},"ohlcv()"),"、",Object(b.b)("inlineCode",{parentName:"p"},"depths()"),"、",Object(b.b)("inlineCode",{parentName:"p"},"clusters()"),"、",Object(b.b)("inlineCode",{parentName:"p"},"liquidations()"),"、",Object(b.b)("inlineCode",{parentName:"p"},"moreData()")," は ",Object(b.b)("strong",{parentName:"p"},"チャートのローソク足1本につき1つのエントリー")," を返します。",Object(b.b)("inlineCode",{parentName:"p"},"depths()[i]")," は ",Object(b.b)("inlineCode",{parentName:"p"},"ohlcv()[i]")," のオーダーブック、",Object(b.b)("inlineCode",{parentName:"p"},"moreData()[i]")," はそのデリバティブデータ、という対応です。あるローソク足についてソースに記録がない場合(例えばオーダーブックの履歴がローソク足の履歴より短い場合)、エントリーは ",Object(b.b)("strong",{parentName:"p"},Object(b.b)("inlineCode",{parentName:"strong"},"null"))," になるため、必ずチェックしてください。",Object(b.b)("inlineCode",{parentName:"p"},"lookback")," で、または別の時間足でリクエストしたデータはそのまま返されるため、",Object(b.b)("strong",{parentName:"p"},Object(b.b)("inlineCode",{parentName:"strong"},"startTime"))," で対応付ける必要があります。チャートの市場の ",Object(b.b)("inlineCode",{parentName:"p"},"ohlcv()")," にはサーバーがすでに読み込んだローソク足だけが含まれ、",Object(b.b)("inlineCode",{parentName:"p"},"null")," になることはありません。古い履歴の読み込み中は、インジケーターは自動的に再計算されます。")),Object(b.b)("h3",{id:"ohlcvexchange-ticker-timeframe-lookback"},Object(b.b)("inlineCode",{parentName:"h3"},"ohlcv(exchange, ticker, timeframe, lookback?)")),Object(b.b)("p",null,"ローソク足データ。"),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'[\n {\n "open": 115886.17,\n "high": 115911.96,\n "low": 115764.27,\n "close": 115815.16,\n "volume": 228.41528,\n "startTime": 1757699100000\n },\n {...},\n ...\n] \n')),Object(b.b)("h3",{id:"depthsexchange-ticker-timeframe-lookback"},Object(b.b)("inlineCode",{parentName:"h3"},"depths(exchange, ticker, timeframe, lookback?)")),Object(b.b)("p",null,"ローソク足ごとに1つの、過去のオーダーブックのスナップショット。最大の指値注文だけが保存されています(ヒートマップの元になるデータです)。"),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'[\n {\n "data": {\n "asks": {\n "109425": 5.467,\n "109495": 3.564,\n ...\n },\n "bids": {\n "33000": 3.746,\n "35000": 16.49,\n ...\n }\n },\n "startTime": 1757699100000\n },\n {...},\n ...\n]\n\n')),Object(b.b)("h3",{id:"clustersexchange-ticker-timeframe-lookback"},Object(b.b)("inlineCode",{parentName:"h3"},"clusters(exchange, ticker, timeframe, lookback?)")),Object(b.b)("p",null,"クラスター(フットプリント)データ: ローソク足の各価格レベルにおける買いと売りの出来高。"),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'[\n {\n "data": {\n "totalBuy": 16053385,\n "totalSell": 20490989,\n "0.8654": { "buy": 286845, "sell": 336689 },\n "0.8653": { "buy": 271848, "sell": 259167 },\n "0.8652": { "buy": 318814, "sell": 373497 },\n ...\n },\n "startTime": 1757699100000\n },\n {...},\n ...\n]\n\n')),Object(b.b)("h3",{id:"liquidationsexchange-ticker-timeframe-lookback"},Object(b.b)("inlineCode",{parentName:"h3"},"liquidations(exchange, ticker, timeframe, lookback?)")),Object(b.b)("p",null,"ローソク足の各価格レベルにおける清算出来高(先物市場のみ)。形式は ",Object(b.b)("inlineCode",{parentName:"p"},"clusters()")," と同じです。"),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'[\n {\n "data": {\n "totalBuy": 16053385,\n "totalSell": 20490989,\n "0.8654": { "buy": 286845, "sell": 336689 },\n "0.8653": { "buy": 271848, "sell": 259167 },\n "0.8652": { "buy": 318814, "sell": 373497 },\n ...\n },\n "startTime": 1757699100000\n },\n {...},\n ...\n]\n\n')),Object(b.b)("h3",{id:"moredataexchange-ticker-timeframe-lookback"},Object(b.b)("inlineCode",{parentName:"h3"},"moreData(exchange, ticker, timeframe, lookback?)")),Object(b.b)("p",null,"ローソク足ごとのデリバティブデータ: 資金調達率、建玉 (OI) のローソク足、ロング/ショート比率(先物市場のみ)。"),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'[\n { \n "data": {\n "FR": 0.00003777, // 資金調達率\n "OI": { // 建玉 (OI) のローソク足\n "open": 85645.708,\n "close": 83496.225,\n "high": 85801.04,\n "low": 83397.918\n },\n "LS": { "l": 0.5426, "s": 0.4574 }, // ロング/ショート比率\n "taLS": { "l": 0.552, "s": 0.448 }, // トップトレーダーのアカウント比率\n "tpLS": { "l": 0.5996, "s": 0.4004 } // トップトレーダーのポジション比率\n },\n "startTime": 1757699100000\n },\n {...},\n ...\n]\n\n')),Object(b.b)("h3",{id:"orderbookexchange-ticker"},Object(b.b)("inlineCode",{parentName:"h3"},"orderbook(exchange, ticker)")),Object(b.b)("p",null,"ライブのオーダーブックのスナップショット: ローソク足に紐付かない、現在の完全な板です。"),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'{\n "asks": {\n "109425": 5.467,\n "109495": 3.564,\n ...\n },\n "bids": {\n "109400": 1.2,\n "109390": 0.8,\n ...\n }\n}\n\n')),Object(b.b)("p",null,"レベルはソートされていません。板を扱うには ",Object(b.b)("inlineCode",{parentName:"p"},"ta")," のオーダーブックヘルパー(",Object(b.b)("inlineCode",{parentName:"p"},"ta.bestBid"),"、",Object(b.b)("inlineCode",{parentName:"p"},"ta.sumBids")," など)を使用してください。\nローソク足ごとの過去の板は ",Object(b.b)("inlineCode",{parentName:"p"},"depths()")," から取得できます。",Object(b.b)("inlineCode",{parentName:"p"},"depths()[i].data")," は同じ形式ですが、そこには最大の指値注文だけが保存されています。"),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"例:")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},"const candles = source.ohlcv(); // exchange、ticker、timeframe パラメーターのデフォルトは現在のチャートです。\nconst closes = candles.map(c => c.close);\n")),Object(b.b)("h3",{id:"levelsexchange-settings"},Object(b.b)("inlineCode",{parentName:"h3"},"levels(exchange, settings?)")),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"流動性スクリーナー")," のレベル: 取引所の大口の指値注文を、スクリーナーページと同じ設定でフィルタリングしたものです。ローソク足に紐付かないライブデータです。プランなしでは、近さは1%、存続時間は60分、結果は200レベルに制限されます。プランがあれば最大2000レベルまで取得できます。最大の注文が先頭に来ます。データソースリクエスト1回としてカウントされます。"),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'{\n "BTCUSDT": {\n "asks": {\n "109500": {\n "price": 109500,\n "quantity": 42.5, // 基軸通貨でのサイズ\n "quantityUSDT": 4653750, // 決済通貨でのサイズ\n "distance": 0.62, // 現在価格からの距離、パーセント\n "duration": 184, // 注文が置かれている分数\n "touches": 2,\n "currentTouches": 1,\n "filledPercent": 12.4,\n "strength": 95.5, // パーセント、スクリーナーを参照\n "diversity": 11,\n "isContinuous": true,\n "date": "2026-10-10T06:12:03.000Z"\n },\n ...\n },\n "bids": { ... },\n "volume1hTotal": 183000000\n },\n ...\n}\n')),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"設定"),"(すべて任意):"),Object(b.b)("table",null,Object(b.b)("thead",{parentName:"table"},Object(b.b)("tr",{parentName:"thead"},Object(b.b)("th",{parentName:"tr",align:null},"設定"),Object(b.b)("th",{parentName:"tr",align:null},"デフォルト"),Object(b.b)("th",{parentName:"tr",align:null},"説明"))),Object(b.b)("tbody",{parentName:"table"},Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"tickers")),Object(b.b)("td",{parentName:"tr",align:null},"すべてのティッカー"),Object(b.b)("td",{parentName:"tr",align:null},"取引所のこれらのティッカーのみ")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"exclude")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"[]")),Object(b.b)("td",{parentName:"tr",align:null},"スキップするティッカー")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"type")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},'"all"')),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},'"all"'),"、",Object(b.b)("inlineCode",{parentName:"td"},'"bids"')," または ",Object(b.b)("inlineCode",{parentName:"td"},'"asks"'))),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"nearness")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"5")),Object(b.b)("td",{parentName:"tr",align:null},"現在価格からの最大距離、パーセント")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"size")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"100000")),Object(b.b)("td",{parentName:"tr",align:null},"決済通貨での最小注文サイズ")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"lifespan")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"0")),Object(b.b)("td",{parentName:"tr",align:null},"注文が置かれている最小の分数")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"touches"),", ",Object(b.b)("inlineCode",{parentName:"td"},"currentTouches")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"0")),Object(b.b)("td",{parentName:"tr",align:null},"レベル / 現在の注文の最小タッチ数")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"filled")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"0")),Object(b.b)("td",{parentName:"tr",align:null},"注文の約定済み部分の最小値、パーセント")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"strength"),", ",Object(b.b)("inlineCode",{parentName:"td"},"diversity")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"0")),Object(b.b)("td",{parentName:"tr",align:null},"最小の強さ(パーセント)と多様性、スクリーナーと同じ")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"continuousOnly")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"false")),Object(b.b)("td",{parentName:"tr",align:null},"消えて再び現れた注文をスキップする")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"volume1h")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"0")),Object(b.b)("td",{parentName:"tr",align:null},"決済通貨でのティッカーの最小1時間出来高")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"spotAndFutures")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"false")),Object(b.b)("td",{parentName:"tr",align:null},"現物市場と先物市場の両方に存在するティッカーのみ")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"limit")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"500")),Object(b.b)("td",{parentName:"tr",align:null},"レベルの最大数、大きい順(最大2000)")))),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"例:")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'// チャートの市場の価格付近の大口注文を水平線で表示し、サイズと継続時間のラベルを付ける\nconst candles = await source.ohlcv();\nconst lastDate = candles.at(-1).startTime;\nconst levels = await source.levels(currentExchange, { tickers: [currentTicker], nearness: 3, size: 300000, lifespan: 30 });\nconst own = levels[currentTicker] || { asks: {}, bids: {} };\nfor (const [type, color] of [["asks", "#ef5350"], ["bids", "#26a69a"]]) {\n for (const [price, level] of Object.entries(own[type])) {\n plot.horizontalLine(`${type} ${price}`, +price, color, 0.8, Math.min(4, 1 + level.quantityUSDT / 1e6));\n plot.text(`${type} ${price} label`, `${(level.quantityUSDT / 1e6).toFixed(2)}M · ${level.duration}m`, lastDate, +price, 10, color);\n }\n}\n')),Object(b.b)("h3",{id:"marketsexchange"},Object(b.b)("inlineCode",{parentName:"h3"},"markets(exchange)")),Object(b.b)("p",null,"取引所の",Object(b.b)("strong",{parentName:"p"},"全ティッカー"),"のライブスナップショット:価格、価格変化率(%)、USD建ての出来高(",Object(b.b)("inlineCode",{parentName:"p"},"buy"),"、",Object(b.b)("inlineCode",{parentName:"p"},"sell"),"、",Object(b.b)("inlineCode",{parentName:"p"},"delta"),"、",Object(b.b)("inlineCode",{parentName:"p"},"total"),")を ",Object(b.b)("inlineCode",{parentName:"p"},"1m"),"、",Object(b.b)("inlineCode",{parentName:"p"},"5m"),"、",Object(b.b)("inlineCode",{parentName:"p"},"15m"),"、",Object(b.b)("inlineCode",{parentName:"p"},"30m"),"、",Object(b.b)("inlineCode",{parentName:"p"},"1h"),"、",Object(b.b)("inlineCode",{parentName:"p"},"4h"),"、",Object(b.b)("inlineCode",{parentName:"p"},"1d")," ごとに返します。リスト全体で",Object(b.b)("strong",{parentName:"p"},"1回"),"のデータソースリクエストとして数えられるため、表スクリプトで取引所全体をランキングできます。ローソク足には紐づかず、チャートのリプレイ中も同じライブ値を返します。"),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'[\n {\n "ticker": "BTCUSDT",\n "price": 60810.1,\n "change": { "1m": 0.02, "5m": 0.11, "15m": 0.3, "30m": 0.4, "1h": 0.8, "4h": 1.2, "1d": 3.1 },\n "volume": {\n "1h": { "buy": 41200000, "sell": 39800000, "delta": 1400000, "total": 81000000 },\n ...\n }\n },\n ...\n]\n')),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"例:")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'const gainers = source.markets(currentExchange).filter((m) => m.change["1d"] > 5);\n')),Object(b.b)("h2",{id:"httpリクエスト"},"HTTPリクエスト"),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},Object(b.b)("inlineCode",{parentName:"strong"},"http"))," クラスは外部のHTTP APIにリクエストを送信してレスポンスを返します。これにより、インジケーターは ",Object(b.b)("inlineCode",{parentName:"p"},"source")," では取得できないデータ(自分のサーバー、公開REST API、オンチェーン指標プロバイダーなど)を利用できます。\n",Object(b.b)("inlineCode",{parentName:"p"},"source.*")," と同様に、呼び出しは同期関数として記述し、",Object(b.b)("inlineCode",{parentName:"p"},"await")," は不要です。"),Object(b.b)("table",null,Object(b.b)("thead",{parentName:"table"},Object(b.b)("tr",{parentName:"thead"},Object(b.b)("th",{parentName:"tr",align:null},"メソッド"),Object(b.b)("th",{parentName:"tr",align:null},"説明"))),Object(b.b)("tbody",{parentName:"table"},Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"get(url, options?)")),Object(b.b)("td",{parentName:"tr",align:null},"GETリクエスト")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"post(url, body?, options?)")),Object(b.b)("td",{parentName:"tr",align:null},"POSTリクエスト。オブジェクトまたは配列の ",Object(b.b)("inlineCode",{parentName:"td"},"body")," はJSON(",Object(b.b)("inlineCode",{parentName:"td"},"Content-Type: application/json"),")として送信され、文字列はそのまま送信されます")))),Object(b.b)("p",null,Object(b.b)("inlineCode",{parentName:"p"},"options")," は ",Object(b.b)("inlineCode",{parentName:"p"},"{ headers: { name: value } }")," です。カスタムヘッダーは ",Object(b.b)("strong",{parentName:"p"},"10個")," まで指定できます(例えば ",Object(b.b)("inlineCode",{parentName:"p"},"Authorization")," や ",Object(b.b)("inlineCode",{parentName:"p"},"x-api-key"),")。"),Object(b.b)("p",null,"どちらのメソッドも同じレスポンスオブジェクトを返し、",Object(b.b)("strong",{parentName:"p"},"例外を投げることはありません"),":"),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'{\n ok: true, // ステータス 200–299\n status: 200, // HTTPステータス、リクエストが送信されなかった場合は 0\n headers: { "content-type": "application/json", ... },\n data: { ... }, // JSONとして解析したレスポンス本文、本文がJSONでない場合は null\n text: "...", // 生のレスポンス本文\n error: null // リクエストが失敗した理由: "timeout", "url not allowed", "too many requests", ...\n}\n')),Object(b.b)(i.b,{type:"warning",title:"制限と安全性",mdxType:"Callout"},Object(b.b)("ul",null,Object(b.b)("li",{parentName:"ul"},"スクリプトの1回の実行につき ",Object(b.b)("strong",{parentName:"li"},"最大3リクエスト"),"、ユーザーごとに ",Object(b.b)("strong",{parentName:"li"},"1分あたり60リクエスト")," まで。"),Object(b.b)("li",{parentName:"ul"},"公開されている ",Object(b.b)("inlineCode",{parentName:"li"},"http://")," / ",Object(b.b)("inlineCode",{parentName:"li"},"https://")," のURLのみ。",Object(b.b)("inlineCode",{parentName:"li"},"localhost"),"、プライベートネットワーク、クラウドのメタデータアドレスへのリクエストは拒否され、リダイレクトは ",Object(b.b)("strong",{parentName:"li"},"追跡されません"),"(",Object(b.b)("inlineCode",{parentName:"li"},"3xx")," レスポンスはそのまま返されます)。"),Object(b.b)("li",{parentName:"ul"},"リクエストは MobChart のプロキシサーバーから送信されます。対象のAPIにはプロキシのアドレスが見え、あなたのIPが見えることはありません。"),Object(b.b)("li",{parentName:"ul"},"タイムアウトは ",Object(b.b)("strong",{parentName:"li"},"5秒"),"、リクエスト本文は ",Object(b.b)("strong",{parentName:"li"},"64 KB")," まで、レスポンスは ",Object(b.b)("strong",{parentName:"li"},"512 KB")," まで(それより大きいレスポンスは ",Object(b.b)("inlineCode",{parentName:"li"},"response too large")," で失敗します)。"),Object(b.b)("li",{parentName:"ul"},Object(b.b)("inlineCode",{parentName:"li"},"Host"),"、",Object(b.b)("inlineCode",{parentName:"li"},"Cookie"),"、",Object(b.b)("inlineCode",{parentName:"li"},"Proxy-*"),"、",Object(b.b)("inlineCode",{parentName:"li"},"X-Forwarded-*")," などの接続ヘッダーは設定できず、",Object(b.b)("inlineCode",{parentName:"li"},"Set-Cookie")," が返されることはありません。"),Object(b.b)("li",{parentName:"ul"},"アラートのチェックはサーバー上で定期的にスクリプトを実行します。チェックのたびにAPIが呼び出されるため、対象APIのレート制限に注意してください。"),Object(b.b)("li",{parentName:"ul"},"公開インジケーター(",Object(b.b)("inlineCode",{parentName:"li"},"isPublicCode = true"),")のコードは誰でも閲覧できます。APIキーを公開コードに含めないでください。"))),Object(b.b)("p",null,Object(b.b)("inlineCode",{parentName:"p"},"error")," に入りうる値: ",Object(b.b)("inlineCode",{parentName:"p"},"invalid url"),"、",Object(b.b)("inlineCode",{parentName:"p"},"url not allowed"),"、",Object(b.b)("inlineCode",{parentName:"p"},"invalid headers"),"、",Object(b.b)("inlineCode",{parentName:"p"},"invalid body"),"、",Object(b.b)("inlineCode",{parentName:"p"},"body too large"),"、",Object(b.b)("inlineCode",{parentName:"p"},"response too large"),"、",Object(b.b)("inlineCode",{parentName:"p"},"timeout"),"、",Object(b.b)("inlineCode",{parentName:"p"},"too many requests"),"、",Object(b.b)("inlineCode",{parentName:"p"},"rate limit"),"、",Object(b.b)("inlineCode",{parentName:"p"},"busy"),"、",Object(b.b)("inlineCode",{parentName:"p"},"proxy unavailable"),"、",Object(b.b)("inlineCode",{parentName:"p"},"network error"),"。"),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"例(GET):")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'define("Fear & Greed", "Crypto Fear & Greed index", "offchart", true, true);\n\nconst res = http.get("https://api.alternative.me/fng/?limit=30");\nif (!res.ok) logger.log("request failed:", res.status, res.error);\n\n// res.data = { data: [{ value: "71", timestamp: "1757635200" }, ...] }\nconst byDay = {};\n(res.data?.data || []).forEach((row) => { byDay[Number(row.timestamp) * 1000] = Number(row.value); });\n\nconst candles = source.ohlcv();\nconst values = candles.map((c) => c ? byDay[c.startTime - (c.startTime % 86400000)] ?? null : null);\nplot.lineSeries("Fear & Greed", values, "#00C8FF");\n')),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"例(POST):")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'const candles = source.ohlcv();\nconst last = candles.at(-1);\n\nconst res = http.post(\n "https://example.com/api/signals",\n { exchange: currentExchange, ticker: currentTicker, close: last.close },\n { headers: { "x-api-key": "YOUR_KEY" } } // 非公開コードのみ\n);\nlogger.log("signal sent:", res.ok, res.status, res.data);\n')),Object(b.b)("h2",{id:"グローバル変数"},"グローバル変数"),Object(b.b)("table",null,Object(b.b)("thead",{parentName:"table"},Object(b.b)("tr",{parentName:"thead"},Object(b.b)("th",{parentName:"tr",align:null},"変数"),Object(b.b)("th",{parentName:"tr",align:null},"説明"),Object(b.b)("th",{parentName:"tr",align:null},"例"))),Object(b.b)("tbody",{parentName:"table"},Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"currentExchange")),Object(b.b)("td",{parentName:"tr",align:null},"チャートの現在の取引所"),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"binance"),", ",Object(b.b)("inlineCode",{parentName:"td"},"binanceFutures"),", ",Object(b.b)("inlineCode",{parentName:"td"},"coinbase"),", ...")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"currentTicker")),Object(b.b)("td",{parentName:"tr",align:null},"チャートの現在のティッカー(形式は取引所によって異なります)"),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"BTCUSDT"),", ",Object(b.b)("inlineCode",{parentName:"td"},"ADA-USD"),", ",Object(b.b)("inlineCode",{parentName:"td"},"BTC/USDC"),", ...")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"currentTimeframe")),Object(b.b)("td",{parentName:"tr",align:null},"チャートの現在の時間足"),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"1m"),", ",Object(b.b)("inlineCode",{parentName:"td"},"5m"),", ",Object(b.b)("inlineCode",{parentName:"td"},"15m"),", ...")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"userLocale")),Object(b.b)("td",{parentName:"tr",align:null},"スクリプトを実行しているユーザーのインターフェース言語(不明な場合は ",Object(b.b)("inlineCode",{parentName:"td"},"en"),"):ラベル、テーブルの文字、アラートメッセージをその言語で書くために使います"),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"en"),", ",Object(b.b)("inlineCode",{parentName:"td"},"ru"),", ",Object(b.b)("inlineCode",{parentName:"td"},"uk"),", ",Object(b.b)("inlineCode",{parentName:"td"},"de"),", ",Object(b.b)("inlineCode",{parentName:"td"},"fr"),", ",Object(b.b)("inlineCode",{parentName:"td"},"zh"),", ",Object(b.b)("inlineCode",{parentName:"td"},"es"),", ",Object(b.b)("inlineCode",{parentName:"td"},"tr"),", ",Object(b.b)("inlineCode",{parentName:"td"},"ko"),", ",Object(b.b)("inlineCode",{parentName:"td"},"ja"))),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"exchanges")),Object(b.b)("td",{parentName:"tr",align:null},"すべての取引所の ID(凍結された配列)"),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},'["binance", "binanceFutures", ...]'))),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"exchangesNames")),Object(b.b)("td",{parentName:"tr",align:null},"取引所の表示名。",Object(b.b)("inlineCode",{parentName:"td"},"exchangesNames[i]")," は ",Object(b.b)("inlineCode",{parentName:"td"},"exchanges[i]")," に対応(凍結された配列)"),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},'["Binance SPOT", "Binance FUTURES", ...]'))))),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"例:")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'const candles = source.ohlcv(currentExchange, currentTicker, currentTimeframe);\nconst closes = candles.map(c => c.close);\n\n// a label in the user\'s interface language, English for the others\nconst closeLabel = { en: "Close", ru: "Закрытие", de: "Schluss", es: "Cierre" };\nlogger.log(closeLabel[userLocale] || closeLabel.en, closes[closes.length - 1]);\n')),Object(b.b)("h2",{id:"ログ出力"},"ログ出力"),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},Object(b.b)("inlineCode",{parentName:"strong"},"logger"))," クラスは情報の出力とデバッグに使用します。"),Object(b.b)("table",null,Object(b.b)("thead",{parentName:"table"},Object(b.b)("tr",{parentName:"thead"},Object(b.b)("th",{parentName:"tr",align:null},"メソッド"),Object(b.b)("th",{parentName:"tr",align:null},"説明"))),Object(b.b)("tbody",{parentName:"table"},Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"log(...args)")),Object(b.b)("td",{parentName:"tr",align:null},"ログにエントリーを追加します(長さと件数に制限があります)")))),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"例:")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'const candles = source.ohlcv();\nlogger.log("First candle:", candles?.[0]);\n')),Object(b.b)(i.f,{src:"../../public/code_editor_log.png",mdxType:"Screenshot"}),Object(b.b)("h2",{id:"可視化"},"可視化"),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},Object(b.b)("inlineCode",{parentName:"strong"},"plot"))," クラスはグラフィック要素とデータ系列の描画を担当します。"),Object(b.b)("h3",{id:"図形"},"図形"),Object(b.b)("table",null,Object(b.b)("thead",{parentName:"table"},Object(b.b)("tr",{parentName:"thead"},Object(b.b)("th",{parentName:"tr",align:null},"メソッド"),Object(b.b)("th",{parentName:"tr",align:null},"説明"))),Object(b.b)("tbody",{parentName:"table"},Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"box(title, date1, price1, date2, price2, fill, opacity, stroke, strokeOpacity, strokeWidth)")),Object(b.b)("td",{parentName:"tr",align:null},"長方形")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"square(title, date1, price1, size, fill, opacity, stroke, strokeOpacity, strokeWidth)")),Object(b.b)("td",{parentName:"tr",align:null},"正方形")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"diamond(title, date1, price1, size, fill, opacity, stroke, strokeOpacity, strokeWidth)")),Object(b.b)("td",{parentName:"tr",align:null},"ひし形")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"triangle(title, date1, price1, size, fill, opacity, stroke, strokeOpacity, strokeWidth)")),Object(b.b)("td",{parentName:"tr",align:null},"三角形")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"circle(title, date1, price1, radius = 10, fill, opacity, stroke, strokeOpacity, strokeWidth)")),Object(b.b)("td",{parentName:"tr",align:null},"円")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"text(title, value, date1, price1, fontSize, fill, opacity)")),Object(b.b)("td",{parentName:"tr",align:null},"チャート上のテキスト")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"table(title, rows, options)")),Object(b.b)("td",{parentName:"tr",align:null},"チャートの隅に固定されるテーブル。",Object(b.b)("a",{parentName:"td",href:"#%E3%83%86%E3%83%BC%E3%83%96%E3%83%AB"},"テーブル")," を参照")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"straightLine(title, date1, price1, date2, price2, stroke, strokeOpacity, strokeWidth, strokeDasharray)")),Object(b.b)("td",{parentName:"tr",align:null},"直線")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"horizontalLine(title, price1, stroke, strokeOpacity, strokeWidth, strokeDasharray)")),Object(b.b)("td",{parentName:"tr",align:null},"チャート全体を横切る水平線")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"verticalLine(title, date1, stroke, strokeOpacity, strokeWidth, strokeDasharray)")),Object(b.b)("td",{parentName:"tr",align:null},"チャート全体を縦に貫く垂直線")))),Object(b.b)("table",null,Object(b.b)("thead",{parentName:"table"},Object(b.b)("tr",{parentName:"thead"},Object(b.b)("th",{parentName:"tr",align:null},"パラメーター"),Object(b.b)("th",{parentName:"tr",align:null},"データ型"),Object(b.b)("th",{parentName:"tr",align:null},"説明"))),Object(b.b)("tbody",{parentName:"table"},Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"title")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"string")),Object(b.b)("td",{parentName:"tr",align:null},"要素名(チャート上の一意な識別子)")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"date1")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"number"),"(タイムスタンプ、ms)"),Object(b.b)("td",{parentName:"tr",align:null},"開始タイムスタンプ")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"price1")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"number")),Object(b.b)("td",{parentName:"tr",align:null},"開始価格(Y軸の座標)")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"date2")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"number"),"(タイムスタンプ、ms)"),Object(b.b)("td",{parentName:"tr",align:null},"終了タイムスタンプ(線と長方形用)")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"price2")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"number")),Object(b.b)("td",{parentName:"tr",align:null},"終了価格(線と長方形用)")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"size")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"number")),Object(b.b)("td",{parentName:"tr",align:null},"図形のサイズ(ピクセル)")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"radius")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"number")),Object(b.b)("td",{parentName:"tr",align:null},"円の半径(デフォルト 10)")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"fill")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"string"),"(hex、例: ",Object(b.b)("inlineCode",{parentName:"td"},'"#FF0000"'),")"),Object(b.b)("td",{parentName:"tr",align:null},"図形の塗りつぶし色")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"opacity")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"number"),"(0–1)"),Object(b.b)("td",{parentName:"tr",align:null},"塗りつぶしの不透明度")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"stroke")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"string"),"(hex、例: ",Object(b.b)("inlineCode",{parentName:"td"},'"#000000"'),")"),Object(b.b)("td",{parentName:"tr",align:null},"線の色")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"strokeOpacity")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"number"),"(0–1)"),Object(b.b)("td",{parentName:"tr",align:null},"線の不透明度")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"strokeWidth")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"number")),Object(b.b)("td",{parentName:"tr",align:null},"線の太さ(ピクセル)")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"strokeDasharray")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"array"),"(例: ",Object(b.b)("inlineCode",{parentName:"td"},"[5,5]"),")"),Object(b.b)("td",{parentName:"tr",align:null},"破線のスタイル")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"fontSize")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"number")),Object(b.b)("td",{parentName:"tr",align:null},"テキストのサイズ(ピクセル)")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"value")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"string")),Object(b.b)("td",{parentName:"tr",align:null},"テキストの値(",Object(b.b)("inlineCode",{parentName:"td"},"text")," メソッド用)")))),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"例:")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'plot.text("Text object", "Hello world!", 1757699100000, 115000, 10, "#00C8FF", 0.5);\nplot.straightLine(`${namePrefix} Open`, level.timeStart, level.open, level.timeEnd, level.open, color);\nplot.circle(`${namePrefix} High`, level.timeStart, level.high, 3, color);\n')),Object(b.b)("p",null,"チャートに表示できる図形は ",Object(b.b)("strong",{parentName:"p"},Object(b.b)("inlineCode",{parentName:"strong"},"3000"))," 個までです。"),Object(b.b)("h3",{id:"データ系列"},"データ系列"),Object(b.b)("table",null,Object(b.b)("thead",{parentName:"table"},Object(b.b)("tr",{parentName:"thead"},Object(b.b)("th",{parentName:"tr",align:null},"メソッド"),Object(b.b)("th",{parentName:"tr",align:null},"説明"))),Object(b.b)("tbody",{parentName:"table"},Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"lineSeries(title, values, stroke, strokeOpacity, strokeWidth, strokeDasharray)")),Object(b.b)("td",{parentName:"tr",align:null},"折れ線グラフ")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"barSeries(title, values, fill, opacity)")),Object(b.b)("td",{parentName:"tr",align:null},"棒グラフ")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"candleSeries(title, openValues, closeValues, highValues, lowValues, fill, opacity)")),Object(b.b)("td",{parentName:"tr",align:null},"ローソク足")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"areaSeries(title, values, fill, opacity, stroke, strokeOpacity, strokeWidth, base)")),Object(b.b)("td",{parentName:"tr",align:null},"線と ",Object(b.b)("inlineCode",{parentName:"td"},"base"),"(デフォルト: チャートの下端)の間を塗りつぶしたエリア")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"bandSeries(title, upperValues, lowerValues, fill, opacity, stroke, strokeOpacity, strokeWidth, step)")),Object(b.b)("td",{parentName:"tr",align:null},"2つの系列の間を塗りつぶしたバンド。ローソク足ごとに独自の色と不透明度を持ちます")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"profile(title, values, options)")),Object(b.b)("td",{parentName:"tr",align:null},"表示中のローソク足の出来高プロファイル風ヒストグラム。",Object(b.b)("a",{parentName:"td",href:"#%E3%83%97%E3%83%AD%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB"},"プロファイル")," を参照")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"histogram(title, rows, options)")),Object(b.b)("td",{parentName:"tr",align:null},"完成した価格マップをプロファイルとして描画。",Object(b.b)("a",{parentName:"td",href:"#%E3%83%92%E3%82%B9%E3%83%88%E3%82%B0%E3%83%A9%E3%83%A0"},"ヒストグラム")," を参照")))),Object(b.b)("table",null,Object(b.b)("thead",{parentName:"table"},Object(b.b)("tr",{parentName:"thead"},Object(b.b)("th",{parentName:"tr",align:null},"パラメーター"),Object(b.b)("th",{parentName:"tr",align:null},"データ型"),Object(b.b)("th",{parentName:"tr",align:null},"説明"))),Object(b.b)("tbody",{parentName:"table"},Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"values"),", ",Object(b.b)("inlineCode",{parentName:"td"},"upperValues"),", ",Object(b.b)("inlineCode",{parentName:"td"},"lowerValues")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"(number \\| null)[]")),Object(b.b)("td",{parentName:"tr",align:null},"ローソク足1本につき1つの値。",Object(b.b)("inlineCode",{parentName:"td"},"null")," はそのローソク足を非表示にします")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"fill"),", ",Object(b.b)("inlineCode",{parentName:"td"},"stroke")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"string"),"(hex)または ",Object(b.b)("inlineCode",{parentName:"td"},"function")),Object(b.b)("td",{parentName:"tr",align:null},"色、またはローソク足の色を返す関数: ",Object(b.b)("inlineCode",{parentName:"td"},"lineSeries"),"、",Object(b.b)("inlineCode",{parentName:"td"},"barSeries"),"、",Object(b.b)("inlineCode",{parentName:"td"},"candleSeries"),"、",Object(b.b)("inlineCode",{parentName:"td"},"areaSeries")," では ",Object(b.b)("inlineCode",{parentName:"td"},"(value, i)"),"、",Object(b.b)("inlineCode",{parentName:"td"},"bandSeries")," では ",Object(b.b)("inlineCode",{parentName:"td"},"(upper, lower, i)"))),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"opacity")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"number"),"(0–1)または ",Object(b.b)("inlineCode",{parentName:"td"},"function")),Object(b.b)("td",{parentName:"tr",align:null},"塗りつぶしの不透明度。",Object(b.b)("inlineCode",{parentName:"td"},"areaSeries")," / ",Object(b.b)("inlineCode",{parentName:"td"},"bandSeries")," では関数 ",Object(b.b)("inlineCode",{parentName:"td"},"(value, i)")," / ",Object(b.b)("inlineCode",{parentName:"td"},"(upper, lower, i)")," も可")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"base")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"number")," ","|"," ",Object(b.b)("inlineCode",{parentName:"td"},"null")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"areaSeries")," の基準レベル。",Object(b.b)("inlineCode",{parentName:"td"},"null")," = チャートの下端")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"step")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"boolean")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"bandSeries")," のスタイル: ",Object(b.b)("inlineCode",{parentName:"td"},"true")," = ローソク足ごとに1列(デフォルト)、",Object(b.b)("inlineCode",{parentName:"td"},"false")," = 連続した多角形")))),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"例:")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'plot.lineSeries("EMA", ta.ema(closes, 20), "#00C8FF");\n// ローソク足ごとに独自の色: 終値がEMAより上なら緑、下なら赤\nplot.lineSeries("Close", closes, (v, i) => v > ema[i] ? colorBuy : colorSell);\nplot.barSeries("Premium %", premiumPercents, ((d) => d > 0 ? color1 : color2), 1);\nplot.candleSeries(\n "Candles",\n opens, closes, highs, lows,\n (v, i) => {\n return opens?.[i] > closes?.[i] ? colorBuy : colorSell\n }\n);\nplot.areaSeries("Volume", volumes, "#00C8FF", 0.3);\n// ローソク足ごとに色付けしたエリア。大きいローソク足ほど不透明\nplot.areaSeries("Delta", deltas, (v, i) => v >= 0 ? colorBuy : colorSell, (v, i) => Math.min(1, Math.abs(v) / maxDelta));\n\n// 終値とその1%下の間の圧力バンド。ローソク足のインバランス比率で色と濃さを決める\nplot.bandSeries(\n "Bid pressure",\n closes,\n closes.map(c => c * 0.99),\n (upper, lower, i) => ratios[i] > 0 ? bidColor : askColor,\n (upper, lower, i) => Math.abs(ratios[i]) / 100\n);\n')),Object(b.b)("p",null,"チャートに表示できるデータ系列は ",Object(b.b)("strong",{parentName:"p"},Object(b.b)("inlineCode",{parentName:"strong"},"20"))," 個までです。"),Object(b.b)("h3",{id:"プロファイル"},"プロファイル"),Object(b.b)("p",null,Object(b.b)("inlineCode",{parentName:"p"},"plot.profile(title, values, options?)")," は、組み込みの出来高プロファイルのように価格別のヒストグラムを描画します。",Object(b.b)("inlineCode",{parentName:"p"},"values[i]")," は ",Object(b.b)("inlineCode",{parentName:"p"},"ohlcv()")," のローソク足 ",Object(b.b)("inlineCode",{parentName:"p"},"i")," の価格マップで、",Object(b.b)("inlineCode",{parentName:"p"},"{ price: value }")," または ",Object(b.b)("inlineCode",{parentName:"p"},"{ price: { buy, sell } }"),"(",Object(b.b)("inlineCode",{parentName:"p"},"clusters()")," や ",Object(b.b)("inlineCode",{parentName:"p"},"liquidations()")," のレコードの ",Object(b.b)("inlineCode",{parentName:"p"},"data")," をそのまま渡せます)、行のないローソク足では ",Object(b.b)("inlineCode",{parentName:"p"},"null")," です。",Object(b.b)("strong",{parentName:"p"},"チャート上に表示されている")," ローソク足の行はチャート側で価格ステップごとに合計されるため、プロファイルは再実行なしでパン、ズーム、追加読み込みに追従します。単一の値は1色で描画され(負の値は ",Object(b.b)("inlineCode",{parentName:"p"},"fill2")," になります)、ペアの場合はバーが買いと売りの部分に分かれ、デルタモードを使用できます。",Object(b.b)("inlineCode",{parentName:"p"},"profile()")," はアラートハンドルを返しません。"),Object(b.b)("table",null,Object(b.b)("thead",{parentName:"table"},Object(b.b)("tr",{parentName:"thead"},Object(b.b)("th",{parentName:"tr",align:null},"オプション"),Object(b.b)("th",{parentName:"tr",align:null},"デフォルト"),Object(b.b)("th",{parentName:"tr",align:null},"説明"))),Object(b.b)("tbody",{parentName:"table"},Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"step")),Object(b.b)("td",{parentName:"tr",align:null},"チャートのティックサイズ"),Object(b.b)("td",{parentName:"tr",align:null},"価格単位での行の高さ。価格はこの値に切り捨てられます")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"orient")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},'"right"')),Object(b.b)("td",{parentName:"tr",align:null},"バーが伸びる側の端。",Object(b.b)("inlineCode",{parentName:"td"},'"right"')," または ",Object(b.b)("inlineCode",{parentName:"td"},'"left"'))),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"width")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"30")),Object(b.b)("td",{parentName:"tr",align:null},"最も幅の広い行の幅、チャート幅に対するパーセント")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"fill")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},'"#26a69a"')),Object(b.b)("td",{parentName:"tr",align:null},"値、または買い部分の色")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"fill2")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},'"#ef5350"')),Object(b.b)("td",{parentName:"tr",align:null},"売り部分の色")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"opacity")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"0.6")),Object(b.b)("td",{parentName:"tr",align:null},"バーの不透明度")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"delta")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"false")),Object(b.b)("td",{parentName:"tr",align:null},"合計の代わりに ",Object(b.b)("inlineCode",{parentName:"td"},"buy - sell")," を描画(ペアのみ)")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"poc")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"true")),Object(b.b)("td",{parentName:"tr",align:null},"値が最大の行に引く線")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"valueArea")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"70")),Object(b.b)("td",{parentName:"tr",align:null},"POC周辺で完全な不透明度で描画する合計のパーセント。",Object(b.b)("inlineCode",{parentName:"td"},"false")," で無効")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"valueAreaOpacity")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"0.3")),Object(b.b)("td",{parentName:"tr",align:null},"バリューエリア外の行の不透明度")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"labels")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"true")),Object(b.b)("td",{parentName:"tr",align:null},"スペースがあればバー上に行の合計を表示")))),Object(b.b)("p",null,"制限: 1回の実行につきプロファイルは ",Object(b.b)("strong",{parentName:"p"},"3")," 個、ローソク足1本につき ",Object(b.b)("strong",{parentName:"p"},"300")," 行、プロファイル1つにつき ",Object(b.b)("strong",{parentName:"p"},"200000")," 行まで。制限を超えた行は破棄され、実行ログに注記が出力されます。"),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"例:")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'// チャートの出来高プロファイル。組み込みツールと同じ表示\nconst rows = await source.clusters();\nplot.profile("Volume", rows.map((r) => r?.data ?? null), { step: 5 });\n\n// 大口約定のみ、デルタで色分けし、左端に表示\nconst minSize = input.number("Min trade size", 50, 0, 100000, 1);\nconst big = rows.map((r) => {\n if (!r?.data) return null;\n const out = {};\n for (const [price, c] of Object.entries(r.data)) {\n if (price === "totalBuy" || price === "totalSell") continue;\n if (c.buy + c.sell >= minSize) out[price] = { buy: c.buy, sell: c.sell };\n }\n return out;\n});\nplot.profile("Large trades", big, { step: 5, delta: true, orient: "left" });\n')),Object(b.b)("h3",{id:"ヒストグラム"},"ヒストグラム"),Object(b.b)("p",null,Object(b.b)("inlineCode",{parentName:"p"},"plot.histogram(title, rows, options?)")," は、すでに作成済みのヒストグラムを描画します: ",Object(b.b)("strong",{parentName:"p"},"チャート全体で1つの価格マップ")," で、ローソク足からの合計は行われません。行がローソク足に属し、表示が表示範囲に追従すべき場合は ",Object(b.b)("inlineCode",{parentName:"p"},"profile()")," を、行が確定している場合(オーダーブックのスナップショット、スクリプトが計算したレベル、別の市場のデータ)は ",Object(b.b)("inlineCode",{parentName:"p"},"histogram()")," を使用してください。"),Object(b.b)("p",null,Object(b.b)("inlineCode",{parentName:"p"},"rows")," は ",Object(b.b)("inlineCode",{parentName:"p"},"profile()")," のローソク足エントリーと同じ形式です: ",Object(b.b)("inlineCode",{parentName:"p"},"{ price: value }"),"、",Object(b.b)("inlineCode",{parentName:"p"},"{ price: { buy, sell } }"),"、または ",Object(b.b)("inlineCode",{parentName:"p"},"[price, buy, sell]")," 行のリスト。単一の値は1色で描画され(負の値は ",Object(b.b)("inlineCode",{parentName:"p"},"fill2")," になります)、ペアの場合はバーが買いと売りの部分に分かれ、デルタモードを使用できます。オプションは ",Object(b.b)("inlineCode",{parentName:"p"},"profile()")," と同じです。上の表を参照してください。"),Object(b.b)("p",null,"ヒストグラムには実行の最後のローソク足の日付が付けられ、チャートはタイトルごとに ",Object(b.b)("strong",{parentName:"p"},"最新の")," ヒストグラムを保持します。そのため、古いローソク足に対する部分実行(履歴の読み込み)が現在のヒストグラムを置き換えることはありません。スクリプトが更新されるたびに再描画されるため、オーダーブックのヒストグラムはライブの板に追従します。",Object(b.b)("inlineCode",{parentName:"p"},"histogram()")," はアラートハンドルを返しません。"),Object(b.b)("p",null,"制限: 1回の実行につきヒストグラムは ",Object(b.b)("strong",{parentName:"p"},"3")," 個、",Object(b.b)("strong",{parentName:"p"},"5000")," 行まで。制限を超えた行は破棄され、実行ログに注記が出力されます。"),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"例: オーダーブック:")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'// ライブのオーダーブックを右端にプロファイルとして表示: 買いは買いの色、売りは売りの色\nconst book = await source.orderbook();\nconst rows = {};\nfor (const [price, qty] of Object.entries(book.bids)) rows[price] = { buy: qty };\nfor (const [price, qty] of Object.entries(book.asks)) rows[price] = { sell: qty };\nplot.histogram("Order book", rows, { step: 5, width: 25, valueArea: false, poc: false });\n')),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"例: 独自のレベル:")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'// 独自のヒストグラム: 直近100本のローソク足のクラスター出来高。新しいローソク足ほど重みが大きい\nconst rows = await source.clusters();\nconst weighted = {};\nrows.slice(-100).forEach((r, i, arr) => {\n if (!r?.data) return;\n const weight = (i + 1) / arr.length;\n for (const [price, c] of Object.entries(r.data)) {\n if (price === "totalBuy" || price === "totalSell") continue;\n const cell = weighted[price] || (weighted[price] = { buy: 0, sell: 0 });\n cell.buy += (c.buy || 0) * weight;\n cell.sell += (c.sell || 0) * weight;\n }\n});\nplot.histogram("Weighted volume", weighted, { step: 5, orient: "left", delta: true });\n')),Object(b.b)("h3",{id:"テーブル"},"テーブル"),Object(b.b)("p",null,Object(b.b)("inlineCode",{parentName:"p"},"plot.table(title, rows, options?)")," は、チャートペインの隅に固定される小さなグリッドを描画します: マルチ時間足のサマリー、読み込み範囲の統計、シグナルダッシュボードなどに使えます。",Object(b.b)("inlineCode",{parentName:"p"},"rows")," は行の配列で、行はセルの配列、セルは文字列、数値、または ",Object(b.b)("inlineCode",{parentName:"p"},"{ text, color, bg, align, bold }")," です。同じ隅のテーブルは順番に積み重ねられます。テーブルには実行の最後のローソク足の日付が付けられ、チャートはタイトルごとに ",Object(b.b)("strong",{parentName:"p"},"最新の")," テーブルを保持します。そのため、古いローソク足に対する部分実行(履歴の読み込み)が現在のテーブルを置き換えることはありません。幅が500 px未満のチャートにはテーブルは描画されません。テーブルはマウスでドラッグできます。位置はワークスペースと一緒に保存され、スクリプトが ",Object(b.b)("inlineCode",{parentName:"p"},"position")," オプションを変更するとリセットされます。",Object(b.b)("inlineCode",{parentName:"p"},"table()")," はアラートハンドルを返しません。"),Object(b.b)("table",null,Object(b.b)("thead",{parentName:"table"},Object(b.b)("tr",{parentName:"thead"},Object(b.b)("th",{parentName:"tr",align:null},"オプション"),Object(b.b)("th",{parentName:"tr",align:null},"デフォルト"),Object(b.b)("th",{parentName:"tr",align:null},"説明"))),Object(b.b)("tbody",{parentName:"table"},Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"position")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},'"top-right"')),Object(b.b)("td",{parentName:"tr",align:null},"ペインの隅: ",Object(b.b)("inlineCode",{parentName:"td"},'"top-right"'),"、",Object(b.b)("inlineCode",{parentName:"td"},'"top-left"'),"、",Object(b.b)("inlineCode",{parentName:"td"},'"bottom-right"'),"、",Object(b.b)("inlineCode",{parentName:"td"},'"bottom-left"'))),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"header")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"false")),Object(b.b)("td",{parentName:"tr",align:null},"最初の行を網掛けの帯の上に太字で描画")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"fontSize")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"11")),Object(b.b)("td",{parentName:"tr",align:null},"テキストサイズ(px)、8〜16")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"color"),", ",Object(b.b)("inlineCode",{parentName:"td"},"bg"),", ",Object(b.b)("inlineCode",{parentName:"td"},"border")),Object(b.b)("td",{parentName:"tr",align:null},"テーマに従う"),Object(b.b)("td",{parentName:"tr",align:null},"デフォルトのテキスト、パネル、グリッドの色。セルで ",Object(b.b)("inlineCode",{parentName:"td"},"color")," と ",Object(b.b)("inlineCode",{parentName:"td"},"bg")," を上書きできます")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"opacity")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"0.85")),Object(b.b)("td",{parentName:"tr",align:null},"パネルの不透明度")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"align")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},'"left"')),Object(b.b)("td",{parentName:"tr",align:null},"セルのデフォルトの配置。",Object(b.b)("inlineCode",{parentName:"td"},'"left"'),"、",Object(b.b)("inlineCode",{parentName:"td"},'"center"')," または ",Object(b.b)("inlineCode",{parentName:"td"},'"right"'))))),Object(b.b)("p",null,"制限: 1回の実行につきテーブルは ",Object(b.b)("strong",{parentName:"p"},"3")," 個、",Object(b.b)("strong",{parentName:"p"},"50")," 行、",Object(b.b)("strong",{parentName:"p"},"10")," 列、セル1つにつき ",Object(b.b)("strong",{parentName:"p"},"100")," 文字まで。長いテキストは省略記号で切り詰められ、1列はチャート幅の最大30%までです。"),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"例:")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'const candles = await source.ohlcv();\nconst closes = candles.map((c) => c.close);\nconst rsi = ta.rsi(closes, 14);\nconst last = rsi.at(-1);\nconst change = (closes.at(-1) / closes.at(-25) - 1) * 100;\n\nplot.table("Stats", [\n ["Metric", "Value"],\n ["RSI 14", { text: last.toFixed(1), color: last > 70 ? "#ef5350" : last < 30 ? "#26a69a" : undefined }],\n ["Change 24 bars", { text: change.toFixed(2) + "%", align: "right" }],\n ["Volume", candles.slice(-24).reduce((s, c) => s + c.volume, 0).toFixed(0)],\n], { position: "top-right", header: true });\n')),Object(b.b)("h3",{id:"凡例テキスト"},"凡例テキスト"),Object(b.b)("p",null,Object(b.b)("inlineCode",{parentName:"p"},"plot.tooltipPrefix(text, color?)")," はスクリプトの凡例(スクリプト名とカーソル位置の系列値を表示するチップ)のタイトル直後にテキストを追加します。",Object(b.b)("inlineCode",{parentName:"p"},"plot.tooltipSuffix(text, color?)")," は値の後ろ、末尾に追加します。複数回呼び出すと、呼び出し順に複数のテキストが追加されます。",Object(b.b)("inlineCode",{parentName:"p"},"color")," の既定値は凡例タイトルの色です。テキストはカーソルに追従しません。凡例には",Object(b.b)("strong",{parentName:"p"},"最新"),"の実行のテキストが表示されるため、最後のローソク足から計算してください。どちらも戻り値はありません。"),Object(b.b)("p",null,"制限: 1 回の実行につき片側 ",Object(b.b)("strong",{parentName:"p"},"5")," 件まで、1 テキスト ",Object(b.b)("strong",{parentName:"p"},"100")," 文字まで。超過した呼び出しはスキップされ、実行ログに通知が記録されます。"),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"例:")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'const candles = await source.ohlcv();\nconst closes = candles.map((c) => c.close);\nconst ema = ta.ema(closes, 50);\nconst up = closes.at(-1) > ema.at(-1);\n\nplot.lineSeries("EMA 50", ema, "#2196f3");\nplot.tooltipPrefix(up ? "▲ above" : "▼ below", up ? "#26a69a" : "#ef5350");\nplot.tooltipSuffix(`${((closes.at(-1) / ema.at(-1) - 1) * 100).toFixed(2)}%`);\n')),Object(b.b)("h2",{id:"スクリプトウィジェット"},"スクリプトウィジェット"),Object(b.b)("p",null,Object(b.b)("inlineCode",{parentName:"p"},'define(title, description, "widget")')," で宣言したスクリプトは",Object(b.b)("strong",{parentName:"p"},"スクリプトウィジェット"),"です(",Object(b.b)("inlineCode",{parentName:"p"},'"table"')," は以前の名前で、引き続き使えます)。チャートに描画する代わりに、ワークスペースの",Object(b.b)("strong",{parentName:"p"},"スクリプトウィジェット"),"に表、チャート、またはその両方(チャートが上)を表示します。ウィジェットは ",Object(b.b)("strong",{parentName:"p"},"+")," タイルから追加するか、エディタで ",Object(b.b)("strong",{parentName:"p"},"Run")," を押します(ウィジェットのないウィジェットスクリプトには自動で1つ追加されます)。ウィジェットのヘッダーでスクリプトを選びます。ウィジェットをチャートの",Object(b.b)("strong",{parentName:"p"},"同期グループ"),"(色付きの点)に入れると、スクリプトはそのチャートの銘柄で実行されます。",Object(b.b)("inlineCode",{parentName:"p"},"currentExchange"),"、",Object(b.b)("inlineCode",{parentName:"p"},"currentTicker"),"、",Object(b.b)("inlineCode",{parentName:"p"},"currentTimeframe")," はチャートのものになり、",Object(b.b)("inlineCode",{parentName:"p"},"source.ohlcv()")," は直近500本のローソク足を返します。同期したチャートがない場合、この3つは ",Object(b.b)("inlineCode",{parentName:"p"},"null")," です。ソースには銘柄を明示的に渡し、ユーザーが ",Object(b.b)("inlineCode",{parentName:"p"},"input.*")," 設定(取引所、ティッカー、時間足、本数)で選べるようにしてください。その場合、",Object(b.b)("inlineCode",{parentName:"p"},"lookback")," のないソース呼び出しは直近500本を返します。ウィジェットは",Object(b.b)("strong",{parentName:"p"},"30秒"),"ごとに更新され、歯車アイコンでスクリプトの ",Object(b.b)("inlineCode",{parentName:"p"},"input")," / ",Object(b.b)("inlineCode",{parentName:"p"},"style")," 設定を開けます。ウィジェットスクリプトはエディタのスクリプト一覧の",Object(b.b)("strong",{parentName:"p"},"ウィジェット"),"タブに表示されます。"),Object(b.b)("h3",{id:"widgettable-columns-rows-options-"},Object(b.b)("inlineCode",{parentName:"h3"},"widget.table({ columns, rows, options })")),Object(b.b)("table",null,Object(b.b)("thead",{parentName:"table"},Object(b.b)("tr",{parentName:"thead"},Object(b.b)("th",{parentName:"tr",align:null},"フィールド"),Object(b.b)("th",{parentName:"tr",align:null},"説明"))),Object(b.b)("tbody",{parentName:"table"},Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"columns")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"[{ key, title, type, align, width, decimals, sort, syncTicker, syncExchange }]"),"。",Object(b.b)("inlineCode",{parentName:"td"},"type"),":",Object(b.b)("inlineCode",{parentName:"td"},'"text"'),"(既定)、",Object(b.b)("inlineCode",{parentName:"td"},'"number"'),"、",Object(b.b)("inlineCode",{parentName:"td"},'"percent"'),"(2.5 → ",Object(b.b)("inlineCode",{parentName:"td"},"+2.50%"),")、",Object(b.b)("inlineCode",{parentName:"td"},'"price"'),"、",Object(b.b)("inlineCode",{parentName:"td"},'"date"'),"(ミリ秒のタイムスタンプ)。",Object(b.b)("inlineCode",{parentName:"td"},'sort: "asc"')," / ",Object(b.b)("inlineCode",{parentName:"td"},'"desc"')," で既定の並び順を設定します。ユーザーはヘッダーをクリックして並べ替えられます")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"rows")),Object(b.b)("td",{parentName:"tr",align:null},"列の ",Object(b.b)("inlineCode",{parentName:"td"},"key")," をキーとするオブジェクト、または列順の配列。セルは値、または ",Object(b.b)("inlineCode",{parentName:"td"},"{ value, text, color, bg, bold }"),":",Object(b.b)("inlineCode",{parentName:"td"},"value")," は並べ替えに使われ、",Object(b.b)("inlineCode",{parentName:"td"},"text")," は整形された値の代わりに表示されます")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"syncTicker"),", ",Object(b.b)("inlineCode",{parentName:"td"},"syncExchange")),Object(b.b)("td",{parentName:"tr",align:null},"クリックできるセル: クリックするとウィジェットと同期中のチャートがその行のマーケットに切り替わり(時間足はそのまま)、ウィジェットはそのマーケットで再計算されます。各値は ",Object(b.b)("inlineCode",{parentName:"td"},"true"),"(セル自身の値)、行のフィールド名(そのフィールドがない行はチャートの値を使用)、または値そのもの(",Object(b.b)("inlineCode",{parentName:"td"},"syncExchange: exchange"),")です。",Object(b.b)("inlineCode",{parentName:"td"},"syncExchange")," がなければチャートの取引所、",Object(b.b)("inlineCode",{parentName:"td"},"syncTicker")," がなければチャートのティッカーを使います。取引所とティッカーはスクリプト実行時に検証され、不明な値の行は通常のテキストのままです(ログ1行)。クリックできるのはウィジェットがチャートと同期している間だけで、チャートの現在のマーケットは強調表示されます")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"options")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"{ title, emptyText, fontSize }"),"(フォントサイズ 9〜14 px)")))),Object(b.b)("p",null,"1回の実行あたりの制限:表は",Object(b.b)("strong",{parentName:"p"},"1"),"つ、",Object(b.b)("strong",{parentName:"p"},"500"),"行、",Object(b.b)("strong",{parentName:"p"},"20"),"列、セルあたり",Object(b.b)("strong",{parentName:"p"},"100"),"文字。色は16進、",Object(b.b)("inlineCode",{parentName:"p"},"rgb()")," / ",Object(b.b)("inlineCode",{parentName:"p"},"hsl()"),"、または色名で指定します。",Object(b.b)("inlineCode",{parentName:"p"},"onchart")," / ",Object(b.b)("inlineCode",{parentName:"p"},"offchart")," スクリプトでは ",Object(b.b)("inlineCode",{parentName:"p"},"widget.table()")," はログを残して無視されます。"),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"例:")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'define("Top movers", "Biggest 24h changes", "widget", true, true);\n// a synced chart decides the exchange, otherwise the user picks it in the widget settings\n// (declare every input as const name = input.xxx(...) on its own: settings are matched by that name)\nconst exchangeInput = input.select("Exchange", "binanceFutures", exchanges.map((e, i) => ({ title: exchangesNames[i], value: e })));\nconst exchange = currentExchange || exchangeInput;\nconst minVolume = input.number("Min 24h volume, $M", 10, 0, 1000);\n// column titles in the user\'s interface language (userLocale), English for the others\nconst texts = {\n en: { ticker: "Ticker", price: "Price", volume: "Volume 24h" },\n ru: { ticker: "Тикер", price: "Цена", volume: "Объём 24ч" },\n de: { ticker: "Ticker", price: "Preis", volume: "Volumen 24h" },\n};\nconst t = texts[userLocale] || texts.en;\n\nconst rows = source.markets(exchange)\n .filter((m) => (m.volume["1d"]?.total || 0) >= minVolume * 1e6)\n .map((m) => ({\n ticker: m.ticker,\n price: m.price,\n change: { value: m.change["1d"], color: m.change["1d"] >= 0 ? "#26a69a" : "#ef5350", bold: true },\n volume: m.volume["1d"]?.total ?? null,\n }));\n\nwidget.table({\n columns: [\n { key: "ticker", title: t.ticker, syncTicker: true, syncExchange: exchange }, // click: the synced chart opens it\n { key: "price", title: t.price, type: "price", align: "right" },\n { key: "change", title: "24h %", type: "percent", align: "right", sort: "desc" },\n { key: "volume", title: t.volume, type: "number", decimals: 0, align: "right" },\n ],\n rows,\n});\n')),Object(b.b)("h3",{id:"widgetchart-x-panes-series-options-"},Object(b.b)("inlineCode",{parentName:"h3"},"widget.chart({ x, panes, series, options })")),Object(b.b)("p",null,Object(b.b)("inlineCode",{parentName:"p"},"widget.chart(spec)")," はチャートを描画します:時系列、ティッカー別の棒グラフ、散布図など。各シリーズは x の値ごとに1つの値を持ち、",Object(b.b)("inlineCode",{parentName:"p"},"null")," は空白になります。時間軸と数値軸ではマウスホイールでズーム、ドラッグで移動でき、ホバーすると全シリーズの値が表示されます。ウィジェットはこれらの数値だけからチャートを描画し、スクリプトのコードがブラウザで実行されることはありません。"),Object(b.b)("table",null,Object(b.b)("thead",{parentName:"table"},Object(b.b)("tr",{parentName:"thead"},Object(b.b)("th",{parentName:"tr",align:null},"フィールド"),Object(b.b)("th",{parentName:"tr",align:null},"説明"))),Object(b.b)("tbody",{parentName:"table"},Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"x")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"{ type, values }"),"。",Object(b.b)("inlineCode",{parentName:"td"},"type"),":",Object(b.b)("inlineCode",{parentName:"td"},'"time"'),"(ミリ秒のタイムスタンプ)、",Object(b.b)("inlineCode",{parentName:"td"},'"category"'),"(ラベル、例:ティッカー)、",Object(b.b)("inlineCode",{parentName:"td"},'"number"'),"(数値の x、例:散布図)。最大 ",Object(b.b)("strong",{parentName:"td"},"5000")," 個")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"panes")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"[{ height }]"),":上から下へ最大 ",Object(b.b)("strong",{parentName:"td"},"3")," つのペイン、",Object(b.b)("inlineCode",{parentName:"td"},"height")," は相対的な比率(1〜10)。既定:1ペイン")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"series")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"[{ type, pane, title, values, color, opacity, width, size, labels }]"),"、最大 ",Object(b.b)("strong",{parentName:"td"},"10")," 個。",Object(b.b)("inlineCode",{parentName:"td"},"type"),":",Object(b.b)("inlineCode",{parentName:"td"},'"line"'),"、",Object(b.b)("inlineCode",{parentName:"td"},'"area"'),"、",Object(b.b)("inlineCode",{parentName:"td"},'"bar"'),"、",Object(b.b)("inlineCode",{parentName:"td"},'"scatter"'),"、",Object(b.b)("inlineCode",{parentName:"td"},'"band"'),"(",Object(b.b)("inlineCode",{parentName:"td"},"values")," の代わりに ",Object(b.b)("inlineCode",{parentName:"td"},"upper")," / ",Object(b.b)("inlineCode",{parentName:"td"},"lower"),")、",Object(b.b)("inlineCode",{parentName:"td"},'"candles"'),"(",Object(b.b)("inlineCode",{parentName:"td"},"[open, high, low, close]")," の ",Object(b.b)("inlineCode",{parentName:"td"},"values"),")。",Object(b.b)("inlineCode",{parentName:"td"},"color")," は1色、または ",Object(b.b)("inlineCode",{parentName:"td"},"bar")," と ",Object(b.b)("inlineCode",{parentName:"td"},"scatter")," では点ごとの色;",Object(b.b)("inlineCode",{parentName:"td"},"width")," は線の太さ 1〜4、",Object(b.b)("inlineCode",{parentName:"td"},"size")," は散布図の点 1〜12、",Object(b.b)("inlineCode",{parentName:"td"},"labels")," はホバー時の点の名前")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"options")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"{ title, yFormat, decimals, height }"),"。",Object(b.b)("inlineCode",{parentName:"td"},"yFormat"),":",Object(b.b)("inlineCode",{parentName:"td"},'"number"'),"(既定、1.2K / 3.4M)、",Object(b.b)("inlineCode",{parentName:"td"},'"percent"'),"、",Object(b.b)("inlineCode",{parentName:"td"},'"price"'),";",Object(b.b)("inlineCode",{parentName:"td"},"height"),":下に表があるときにチャートが占める割合(0.2〜0.9、既定 0.6)")))),Object(b.b)("p",null,"1回の実行あたりの制限:チャートは ",Object(b.b)("strong",{parentName:"p"},"1")," つ、x の値 ",Object(b.b)("strong",{parentName:"p"},"5000")," 個、シリーズ ",Object(b.b)("strong",{parentName:"p"},"10")," 個、ペイン ",Object(b.b)("strong",{parentName:"p"},"3")," つ、全シリーズ合計 ",Object(b.b)("strong",{parentName:"p"},"30 000")," ポイント。色は表と同様にチェックされ、有限の数値でない値は空白になります。仕様のどこにも関数は使えません。"),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"例:")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'define("BTC vs ETH", "Both coins from the same start, and their ratio", "widget", true, true);\n// a synced chart decides the timeframe, otherwise the setting\nconst timeframeInput = input.select("Timeframe", "1h", ["15m", "1h", "4h", "1d"]);\nconst bars = input.number("Bars", 200, 20, 1000);\nconst timeframe = currentTimeframe || timeframeInput;\n\nconst btc = source.ohlcv("binanceFutures", "BTCUSDT", timeframe, bars);\nconst eth = source.ohlcv("binanceFutures", "ETHUSDT", timeframe, bars);\n// match the candles by time: the two lists may miss different bars\nconst ethByTime = new Map(eth.map((c) => [c.startTime, c]));\nconst common = btc.filter((c) => ethByTime.has(c.startTime));\nconst btcCloses = common.map((c) => c.close);\nconst ethCloses = common.map((c) => ethByTime.get(c.startTime).close);\nconst fromStart = (list) => list.map((v) => (v / list[0] - 1) * 100);\n// the ratio title in the user\'s interface language (userLocale), English for the others\nconst ratioTitle = { en: "ETH / BTC ratio x1000", ru: "Отношение ETH / BTC x1000", de: "Verhältnis ETH / BTC x1000" };\n\nwidget.chart({\n x: { type: "time", values: common.map((c) => c.startTime) },\n panes: [{ height: 3 }, { height: 1 }],\n series: [\n { type: "line", title: "BTC %", values: fromStart(btcCloses), color: "#f7931a", width: 2 },\n { type: "line", title: "ETH %", values: fromStart(ethCloses), color: "#627eea", width: 2 },\n { type: "line", pane: 1, title: ratioTitle[userLocale] || ratioTitle.en, values: ethCloses.map((v, i) => (v / btcCloses[i]) * 1000), color: "#26a69a", width: 2 },\n ],\n options: { decimals: 2 },\n});\n')),Object(b.b)("h2",{id:"テクニカル分析"},"テクニカル分析"),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},Object(b.b)("inlineCode",{parentName:"strong"},"ta"))," クラスは PineScript v5 の ",Object(b.b)("inlineCode",{parentName:"p"},"ta.*")," 関数を実装しています。Pine はバーごとに処理しますが、ここではすべての関数が系列全体(配列、ローソク足1本につき1つの値、古い順)を受け取り、同じ長さの系列を返すため、そのまま描画できます。期間が満たされるまでの値は ",Object(b.b)("inlineCode",{parentName:"p"},"null")," で、",Object(b.b)("inlineCode",{parentName:"p"},"null")," の入力は Pine の ",Object(b.b)("inlineCode",{parentName:"p"},"na")," と同様に伝播します。",Object(b.b)("inlineCode",{parentName:"p"},"high"),"、",Object(b.b)("inlineCode",{parentName:"p"},"low"),"、",Object(b.b)("inlineCode",{parentName:"p"},"close"),"、",Object(b.b)("inlineCode",{parentName:"p"},"volume")," を暗黙的に読み取る Pine の関数は、それらの配列を引数として受け取ります。"),Object(b.b)("p",null,"複数の系列を返す関数(",Object(b.b)("inlineCode",{parentName:"p"},"bb"),"、",Object(b.b)("inlineCode",{parentName:"p"},"kc"),"、",Object(b.b)("inlineCode",{parentName:"p"},"macd"),"、",Object(b.b)("inlineCode",{parentName:"p"},"stoch"),"、",Object(b.b)("inlineCode",{parentName:"p"},"dmi"),"、",Object(b.b)("inlineCode",{parentName:"p"},"supertrend"),")は、名前付きプロパティも持つ配列を返します: ",Object(b.b)("inlineCode",{parentName:"p"},"const [middle, upper, lower] = ta.bb(closes, 20, 2)")," または ",Object(b.b)("inlineCode",{parentName:"p"},"ta.bb(closes, 20, 2).upper"),"。"),Object(b.b)("h3",{id:"ヘルパー関数"},"ヘルパー関数"),Object(b.b)("table",null,Object(b.b)("thead",{parentName:"table"},Object(b.b)("tr",{parentName:"thead"},Object(b.b)("th",{parentName:"tr",align:null},"メソッド"),Object(b.b)("th",{parentName:"tr",align:null},"説明"))),Object(b.b)("tbody",{parentName:"table"},Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"highest(values, length)")," / ",Object(b.b)("inlineCode",{parentName:"td"},"lowest(values, length)")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"length")," 本のバーにおける最高値 / 最安値")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"highestbars(values, length)")," / ",Object(b.b)("inlineCode",{parentName:"td"},"lowestbars(values, length)")),Object(b.b)("td",{parentName:"tr",align:null},"最高値 / 最安値のバーまでのオフセット(0 または負の値)")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"max(values)")," / ",Object(b.b)("inlineCode",{parentName:"td"},"min(values)")),Object(b.b)("td",{parentName:"tr",align:null},"各バーまでの全期間の最高値 / 最安値")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"range(values, length)")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"highest - lowest"))),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"change(values, length = 1)")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"values[i] - values[i - length]"))),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"mom(values, length)")),Object(b.b)("td",{parentName:"tr",align:null},"モメンタム")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"roc(values, length)")),Object(b.b)("td",{parentName:"tr",align:null},"変化率、%")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"cum(values)")),Object(b.b)("td",{parentName:"tr",align:null},"累計")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"rising(values, length)")," / ",Object(b.b)("inlineCode",{parentName:"td"},"falling(values, length)")),Object(b.b)("td",{parentName:"tr",align:null},"値が直前の ",Object(b.b)("inlineCode",{parentName:"td"},"length")," 個の値のそれぞれより上 / 下である")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"variance(values, length, biased = true)")),Object(b.b)("td",{parentName:"tr",align:null},"分散")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"stdev(values, length, biased = true)")),Object(b.b)("td",{parentName:"tr",align:null},"標準偏差")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"dev(values, length)")),Object(b.b)("td",{parentName:"tr",align:null},"平均絶対偏差")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"median(values, length)")),Object(b.b)("td",{parentName:"tr",align:null},"中央値")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"mode(values, length)")),Object(b.b)("td",{parentName:"tr",align:null},"最頻値(同数の場合は最小の値)")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"percentile_linear_interpolation(values, length, percentage)")),Object(b.b)("td",{parentName:"tr",align:null},"パーセンタイル、最も近い2つの順位間の線形補間")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"percentile_nearest_rank(values, length, percentage)")),Object(b.b)("td",{parentName:"tr",align:null},"パーセンタイル、最近順位法")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"percentrank(values, length)")),Object(b.b)("td",{parentName:"tr",align:null},"直前の ",Object(b.b)("inlineCode",{parentName:"td"},"length")," 個の値のうち、現在の値以下であるものの割合(%)")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"correlation(series1, series2, length)")),Object(b.b)("td",{parentName:"tr",align:null},"相関係数")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"crossover(series1, series2)")),Object(b.b)("td",{parentName:"tr",align:null},"上向きのクロス(どちらの引数も数値にできます: ",Object(b.b)("inlineCode",{parentName:"td"},"ta.crossover(rsi, 70)"),")")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"crossunder(series1, series2)")),Object(b.b)("td",{parentName:"tr",align:null},"下向きのクロス")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"cross(series1, series2)")),Object(b.b)("td",{parentName:"tr",align:null},"いずれかの方向のクロス")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"barssince(condition)")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"condition"),"(真偽値の配列)が最後に true だったときからのバー数")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"valuewhen(condition, values, occurrence = 0)")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"condition")," が ",Object(b.b)("inlineCode",{parentName:"td"},"occurrence")," 回前に true だったときの ",Object(b.b)("inlineCode",{parentName:"td"},"values")," の値")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"pivothigh(values, leftbars, rightbars)")," / ",Object(b.b)("inlineCode",{parentName:"td"},"pivotlow(...)")),Object(b.b)("td",{parentName:"tr",align:null},"確定バー上のピボット値。ピボット自体は ",Object(b.b)("inlineCode",{parentName:"td"},"rightbars")," 本前のバーです")))),Object(b.b)("h3",{id:"移動平均"},"移動平均"),Object(b.b)("table",null,Object(b.b)("thead",{parentName:"table"},Object(b.b)("tr",{parentName:"thead"},Object(b.b)("th",{parentName:"tr",align:null},"メソッド"),Object(b.b)("th",{parentName:"tr",align:null},"説明"))),Object(b.b)("tbody",{parentName:"table"},Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"sma(values, length)")),Object(b.b)("td",{parentName:"tr",align:null},"単純移動平均")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"ema(values, length)")),Object(b.b)("td",{parentName:"tr",align:null},"指数移動平均")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"rma(values, length)")),Object(b.b)("td",{parentName:"tr",align:null},"ワイルダーの移動平均(RSI / ATR で使用)")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"wma(values, length)")),Object(b.b)("td",{parentName:"tr",align:null},"加重移動平均")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"hma(values, length)")),Object(b.b)("td",{parentName:"tr",align:null},"ハル移動平均")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"alma(values, length, offset = 0.85, sigma = 6, floor = false)")),Object(b.b)("td",{parentName:"tr",align:null},"アルノー・ルグー移動平均")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"swma(values)")),Object(b.b)("td",{parentName:"tr",align:null},"4本のバーにわたる対称加重移動平均")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"vwma(values, volumes, length)")),Object(b.b)("td",{parentName:"tr",align:null},"出来高加重移動平均")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"linreg(values, length, offset = 0)")),Object(b.b)("td",{parentName:"tr",align:null},"線形回帰曲線")))),Object(b.b)("h3",{id:"オシレーター"},"オシレーター"),Object(b.b)("table",null,Object(b.b)("thead",{parentName:"table"},Object(b.b)("tr",{parentName:"thead"},Object(b.b)("th",{parentName:"tr",align:null},"メソッド"),Object(b.b)("th",{parentName:"tr",align:null},"説明"))),Object(b.b)("tbody",{parentName:"table"},Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"rsi(values, length)")),Object(b.b)("td",{parentName:"tr",align:null},"相対力指数(RSI)")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"cmo(values, length)")),Object(b.b)("td",{parentName:"tr",align:null},"シャンデ・モメンタム・オシレーター")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"cog(values, length)")),Object(b.b)("td",{parentName:"tr",align:null},"重心(Center of Gravity)")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"mfi(values, volumes, length)")),Object(b.b)("td",{parentName:"tr",align:null},"マネーフローインデックス(",Object(b.b)("inlineCode",{parentName:"td"},"values")," は通常 hlc3)")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"tsi(values, shortLength, longLength)")),Object(b.b)("td",{parentName:"tr",align:null},"トゥルー・ストレングス・インデックス、-1..1")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"wpr(highs, lows, closes, length)")),Object(b.b)("td",{parentName:"tr",align:null},"ウィリアムズ %R")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"stoch(highs, lows, closes, period = 14, smoothK = 3, smoothD = 3)")),Object(b.b)("td",{parentName:"tr",align:null},"ストキャスティクス ",Object(b.b)("inlineCode",{parentName:"td"},"[k, d]"),"、",Object(b.b)("inlineCode",{parentName:"td"},"smoothK = 1")," で生の値")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"cci(values, length)")," / ",Object(b.b)("inlineCode",{parentName:"td"},"cci(highs, lows, closes, length)")),Object(b.b)("td",{parentName:"tr",align:null},"商品チャネル指数(2番目の形式では典型価格に対して計算)")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"macd(values, fast = 12, slow = 26, signalPeriod = 9)")),Object(b.b)("td",{parentName:"tr",align:null},"MACD ",Object(b.b)("inlineCode",{parentName:"td"},"[macd, signal, histogram]"))))),Object(b.b)("h3",{id:"バンドとチャネル"},"バンドとチャネル"),Object(b.b)("table",null,Object(b.b)("thead",{parentName:"table"},Object(b.b)("tr",{parentName:"thead"},Object(b.b)("th",{parentName:"tr",align:null},"メソッド"),Object(b.b)("th",{parentName:"tr",align:null},"説明"))),Object(b.b)("tbody",{parentName:"table"},Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"bb(values, length = 20, mult = 2)")," / ",Object(b.b)("inlineCode",{parentName:"td"},"bollinger(...)")),Object(b.b)("td",{parentName:"tr",align:null},"ボリンジャーバンド ",Object(b.b)("inlineCode",{parentName:"td"},"[middle, upper, lower]"))),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"bbw(values, length, mult)")),Object(b.b)("td",{parentName:"tr",align:null},"ボリンジャーバンド幅 ",Object(b.b)("inlineCode",{parentName:"td"},"(upper - lower) / middle"))),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"kc(values, highs, lows, closes, length = 20, mult = 2, useTrueRange = true)")),Object(b.b)("td",{parentName:"tr",align:null},"ケルトナーチャネル ",Object(b.b)("inlineCode",{parentName:"td"},"[middle, upper, lower]"))),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"kcw(values, highs, lows, closes, length, mult, useTrueRange)")),Object(b.b)("td",{parentName:"tr",align:null},"ケルトナーチャネル幅 ",Object(b.b)("inlineCode",{parentName:"td"},"(upper - lower) / middle"))))),Object(b.b)("h3",{id:"トレンドとボラティリティ"},"トレンドとボラティリティ"),Object(b.b)("table",null,Object(b.b)("thead",{parentName:"table"},Object(b.b)("tr",{parentName:"thead"},Object(b.b)("th",{parentName:"tr",align:null},"メソッド"),Object(b.b)("th",{parentName:"tr",align:null},"説明"))),Object(b.b)("tbody",{parentName:"table"},Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"tr(highs, lows, closes, handleNa = false)")),Object(b.b)("td",{parentName:"tr",align:null},"トゥルーレンジ(",Object(b.b)("inlineCode",{parentName:"td"},"handleNa = true")," で最初のバーは ",Object(b.b)("inlineCode",{parentName:"td"},"high - low"),")")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"atr(highs, lows, closes, period = 14)")),Object(b.b)("td",{parentName:"tr",align:null},"アベレージ・トゥルー・レンジ(ATR)")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"dmi(highs, lows, closes, diLength = 14, adxSmoothing = 14)")),Object(b.b)("td",{parentName:"tr",align:null},"方向性指数 ",Object(b.b)("inlineCode",{parentName:"td"},"[plus, minus, adx]"))),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"adx(highs, lows, closes, period = 14)")),Object(b.b)("td",{parentName:"tr",align:null},"アベレージ・ディレクショナル・インデックス")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"sar(highs, lows, closes, start = 0.02, inc = 0.02, max = 0.2)")),Object(b.b)("td",{parentName:"tr",align:null},"パラボリックSAR")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"supertrend(highs, lows, closes, factor = 3, atrPeriod = 10)")),Object(b.b)("td",{parentName:"tr",align:null},"スーパートレンド ",Object(b.b)("inlineCode",{parentName:"td"},"[supertrend, direction]"),"、direction ",Object(b.b)("inlineCode",{parentName:"td"},"-1")," = 上昇トレンド、",Object(b.b)("inlineCode",{parentName:"td"},"1")," = 下降トレンド")))),Object(b.b)("h3",{id:"出来高"},"出来高"),Object(b.b)("table",null,Object(b.b)("thead",{parentName:"table"},Object(b.b)("tr",{parentName:"thead"},Object(b.b)("th",{parentName:"tr",align:null},"メソッド"),Object(b.b)("th",{parentName:"tr",align:null},"説明"))),Object(b.b)("tbody",{parentName:"table"},Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"vwap(values, volumes, anchor?)")," / ",Object(b.b)("inlineCode",{parentName:"td"},"vwap(highs, lows, closes, volumes, anchor?)")),Object(b.b)("td",{parentName:"tr",align:null},"累積 VWAP(2番目の形式では典型価格に対して計算)。",Object(b.b)("inlineCode",{parentName:"td"},"anchor"),"(真偽値の配列)が true のバーでリセットされます")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"obv(closes, volumes)")),Object(b.b)("td",{parentName:"tr",align:null},"オン・バランス・ボリューム")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"accdist(highs, lows, closes, volumes)")),Object(b.b)("td",{parentName:"tr",align:null},"累積 / 分散(Accumulation / Distribution)")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"iii(highs, lows, closes, volumes)")),Object(b.b)("td",{parentName:"tr",align:null},"イントラデイ・インテンシティ・インデックス")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"pvt(closes, volumes)")),Object(b.b)("td",{parentName:"tr",align:null},"プライス・ボリューム・トレンド")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"nvi(closes, volumes)")," / ",Object(b.b)("inlineCode",{parentName:"td"},"pvi(closes, volumes)")),Object(b.b)("td",{parentName:"tr",align:null},"ネガティブ / ポジティブ・ボリューム・インデックス")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"wad(highs, lows, closes)")),Object(b.b)("td",{parentName:"tr",align:null},"ウィリアムズ累積 / 分散")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"wvad(opens, highs, lows, closes, volumes)")),Object(b.b)("td",{parentName:"tr",align:null},"ウィリアムズ可変累積 / 分散")))),Object(b.b)("h3",{id:"オーダーブックヘルパー"},"オーダーブックヘルパー"),Object(b.b)("p",null,Object(b.b)("inlineCode",{parentName:"p"},"orderbook")," は ",Object(b.b)("inlineCode",{parentName:"p"},"source.orderbook()")," または ",Object(b.b)("inlineCode",{parentName:"p"},"source.depths()[i].data")," です: ",Object(b.b)("inlineCode",{parentName:"p"},"{asks: {price: quantity}, bids: {price: quantity}}"),"。"),Object(b.b)("table",null,Object(b.b)("thead",{parentName:"table"},Object(b.b)("tr",{parentName:"thead"},Object(b.b)("th",{parentName:"tr",align:null},"メソッド"),Object(b.b)("th",{parentName:"tr",align:null},"説明"))),Object(b.b)("tbody",{parentName:"table"},Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"orderbookSide(orderbook, side)")),Object(b.b)("td",{parentName:"tr",align:null},"片側(",Object(b.b)("inlineCode",{parentName:"td"},"'bids'")," / ",Object(b.b)("inlineCode",{parentName:"td"},"'asks'"),")を、最良価格から順にソートした ",Object(b.b)("inlineCode",{parentName:"td"},"[[price, quantity], ...]")," として返します")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"bestBid(orderbook)")," / ",Object(b.b)("inlineCode",{parentName:"td"},"bestAsk(orderbook)")),Object(b.b)("td",{parentName:"tr",align:null},"最良の買い / 売り価格(空の板では ",Object(b.b)("inlineCode",{parentName:"td"},"null"),")")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"sumBids(orderbook, percent, price, inQuote)")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"price"),"(デフォルト: 最良買い値)から ",Object(b.b)("inlineCode",{parentName:"td"},"price * (1 - percent / 100)")," までの買い数量の累計。",Object(b.b)("inlineCode",{parentName:"td"},"inQuote = true")," で ",Object(b.b)("inlineCode",{parentName:"td"},"price * quantity")," を合計します")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"sumAsks(orderbook, percent, price, inQuote)")),Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"price"),"(デフォルト: 最良売り値)から ",Object(b.b)("inlineCode",{parentName:"td"},"price * (1 + percent / 100)")," までの売り数量の累計")))),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"例:")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'const candles = source.ohlcv();\nconst closes = candles.map(c => c.close);\nconst rsiValues = ta.rsi(closes, 14);\nplot.lineSeries("RSI", rsiValues, "#00C8FF");\n')),Object(b.b)("h2",{id:"アラート"},"アラート"),Object(b.b)("p",null,"ユーザーは、チャート上のインジケーター設定の ",Object(b.b)("strong",{parentName:"p"},"アラート")," タブから、あなたのインジケーターのアラートを作成できます。\nアラートはサーバー側で定期的にチェックされ、通知は ",Object(b.b)("strong",{parentName:"p"},"Telegram")," および/またはユーザーが指定した ",Object(b.b)("strong",{parentName:"p"},"Webhook URL")," に送信されます。"),Object(b.b)("h3",{id:"アラート設定--alertinput"},"アラート設定 — ",Object(b.b)("inlineCode",{parentName:"h3"},"alertInput")),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},Object(b.b)("inlineCode",{parentName:"strong"},"alertInput"))," クラスはアラートの設定を宣言します。",Object(b.b)("inlineCode",{parentName:"p"},"input")," とまったく同じように動作しますが、フィールドは ",Object(b.b)("strong",{parentName:"p"},"アラート")," タブに表示され、各ユーザーが自分のアラート用に独自の値を設定します。"),Object(b.b)("p",null,Object(b.b)("inlineCode",{parentName:"p"},"alertInput")," の宣言がないスクリプトはアラートに使用できません。"),Object(b.b)("table",null,Object(b.b)("thead",{parentName:"table"},Object(b.b)("tr",{parentName:"thead"},Object(b.b)("th",{parentName:"tr",align:null},"メソッド"),Object(b.b)("th",{parentName:"tr",align:null},"説明"))),Object(b.b)("tbody",{parentName:"table"},Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"number(title, defaultValue, min, max, step)")),Object(b.b)("td",{parentName:"tr",align:null},"数値入力")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"range(title, defaultValue, min, max, step)")),Object(b.b)("td",{parentName:"tr",align:null},"範囲入力")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"select(title, defaultValue, values)")),Object(b.b)("td",{parentName:"tr",align:null},"ドロップダウン選択")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"color(title, defaultValue)")),Object(b.b)("td",{parentName:"tr",align:null},"カラーピッカー")),Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"boolean(title, defaultValue)")),Object(b.b)("td",{parentName:"tr",align:null},"真偽値入力")))),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"例:")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'const alertVolumeThreshold = alertInput.number("Volume threshold", 1000, 0, 10000000, 1);\n')),Object(b.b)("h3",{id:"アラートの発火--alertfire"},"アラートの発火 — ",Object(b.b)("inlineCode",{parentName:"h3"},"alert.fire")),Object(b.b)("table",null,Object(b.b)("thead",{parentName:"table"},Object(b.b)("tr",{parentName:"thead"},Object(b.b)("th",{parentName:"tr",align:null},"メソッド"),Object(b.b)("th",{parentName:"tr",align:null},"説明"))),Object(b.b)("tbody",{parentName:"table"},Object(b.b)("tr",{parentName:"tbody"},Object(b.b)("td",{parentName:"tr",align:null},Object(b.b)("inlineCode",{parentName:"td"},"fire(title, message, date)")),Object(b.b)("td",{parentName:"tr",align:null},"アラート通知を発火します")))),Object(b.b)("ul",null,Object(b.b)("li",{parentName:"ul"},"3つのパラメーターはすべて ",Object(b.b)("strong",{parentName:"li"},"必須")," です。",Object(b.b)("inlineCode",{parentName:"li"},"title"),"、",Object(b.b)("inlineCode",{parentName:"li"},"message"),"、",Object(b.b)("inlineCode",{parentName:"li"},"date")," のいずれかが欠けた呼び出しはスキップされます(ログに警告が書き込まれます)。"),Object(b.b)("li",{parentName:"ul"},"アラートの ",Object(b.b)("strong",{parentName:"li"},"タイトルは固定")," にし、一意なタイトルを生成しないでください。各タイトルは1回の実行につき1度だけ発火します(1回の実行につき最大 ",Object(b.b)("strong",{parentName:"li"},"20")," タイトル)。"),Object(b.b)("li",{parentName:"ul"},Object(b.b)("inlineCode",{parentName:"li"},"date")," はシグナルが属するローソク足の ",Object(b.b)("inlineCode",{parentName:"li"},"startTime")," です。同じタイトルは、",Object(b.b)("strong",{parentName:"li"},"より新しい")," ローソク足で発火した場合にのみ再度通知されます。ユーザーがアラートを作成した時点より古いローソク足からのシグナルは無視されます(スパム防止)。")),Object(b.b)("p",null,Object(b.b)("strong",{parentName:"p"},"例:")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'if (candle.volume > alertVolumeThreshold) {\n alert.fire("High volume", `vol ${candle.volume}`, candle.startTime);\n}\n')),Object(b.b)("h3",{id:"図形アラート--plotshapealert"},"図形アラート — ",Object(b.b)("inlineCode",{parentName:"h3"},"plot.(...).alert(...)")),Object(b.b)("p",null,"すべての図形(",Object(b.b)("inlineCode",{parentName:"p"},"box"),"、",Object(b.b)("inlineCode",{parentName:"p"},"square"),"、",Object(b.b)("inlineCode",{parentName:"p"},"diamond"),"、",Object(b.b)("inlineCode",{parentName:"p"},"triangle"),"、",Object(b.b)("inlineCode",{parentName:"p"},"circle"),"、",Object(b.b)("inlineCode",{parentName:"p"},"straightLine"),"、",Object(b.b)("inlineCode",{parentName:"p"},"horizontalLine"),"、",Object(b.b)("inlineCode",{parentName:"p"},"verticalLine"),"、",Object(b.b)("inlineCode",{parentName:"p"},"text"),")は ",Object(b.b)("inlineCode",{parentName:"p"},".alert()")," メソッドを持つハンドルを返します。\nアラートは図形の ",Object(b.b)("inlineCode",{parentName:"p"},"date1")," で自動的に発火するため、追加のコードなしでスパム防止ロジックが機能します。ローソク足ごとのシグナルにはこの方法を推奨します。"),Object(b.b)("p",null,"2つの形式:"),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'// シンプル: 新しい日付で図形が描画されるたびに発火\nplot.box(...).alert("High volume", `vol ${candle.volume}`);\n\n// コールバック: スキップするには何も返さず、発火するには [title, message] を返す\nplot.box(...).alert((shape) => {\n if (candle.volume > alertVolumeThreshold)\n alert.fire("High volume", `vol ${candle.volume}`, candle.startTime);\n});\n')),Object(b.b)("p",null,"コールバックは図形のデータ(",Object(b.b)("inlineCode",{parentName:"p"},"date1"),"、",Object(b.b)("inlineCode",{parentName:"p"},"price1"),"、",Object(b.b)("inlineCode",{parentName:"p"},"date2"),"、",Object(b.b)("inlineCode",{parentName:"p"},"price2")," など)を受け取ります。"),Object(b.b)("h3",{id:"系列アラート--plotseriesalert"},"系列アラート — ",Object(b.b)("inlineCode",{parentName:"h3"},"plot.(...).alert(...)")),Object(b.b)("p",null,"データ系列(",Object(b.b)("inlineCode",{parentName:"p"},"lineSeries"),"、",Object(b.b)("inlineCode",{parentName:"p"},"barSeries"),"、",Object(b.b)("inlineCode",{parentName:"p"},"candleSeries"),"、",Object(b.b)("inlineCode",{parentName:"p"},"areaSeries"),"、",Object(b.b)("inlineCode",{parentName:"p"},"bandSeries"),")も ",Object(b.b)("inlineCode",{parentName:"p"},".alert()")," ハンドルを返します。\nコールバックは ",Object(b.b)("strong",{parentName:"p"},"最新のデータポイント")," と最新のローソク足の日付を受け取り、アラートはその日付で発火します。"),Object(b.b)("ul",null,Object(b.b)("li",{parentName:"ul"},Object(b.b)("inlineCode",{parentName:"li"},"lineSeries")," / ",Object(b.b)("inlineCode",{parentName:"li"},"barSeries")," / ",Object(b.b)("inlineCode",{parentName:"li"},"areaSeries")," — コールバックは最後の ",Object(b.b)("strong",{parentName:"li"},"値"),"(数値)を受け取ります"),Object(b.b)("li",{parentName:"ul"},Object(b.b)("inlineCode",{parentName:"li"},"candleSeries")," — コールバックは最後のローソク足 ",Object(b.b)("inlineCode",{parentName:"li"},"{open, close, high, low}")," を受け取ります"),Object(b.b)("li",{parentName:"ul"},Object(b.b)("inlineCode",{parentName:"li"},"bandSeries")," — コールバックは最後の ",Object(b.b)("inlineCode",{parentName:"li"},"{upper, lower}")," を受け取ります")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'plot.lineSeries("RSI", rsiValues, color).alert((rsi, date) => {\n if (rsi > alertRsiThreshold) alert.fire("RSI high", `RSI ${rsi.toFixed(1)}`, latestCandle.startTime);\n});\n')),Object(b.b)("p",null,"true のままの条件は、",Object(b.b)("strong",{parentName:"p"},"新しいローソク足")," ごとに1回通知されます。一度きりのシグナルには、クロス型の条件(",Object(b.b)("inlineCode",{parentName:"p"},"ta.crossover"),")を使用してください。"),Object(b.b)("h3",{id:"完全な例"},"完全な例"),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'const title = "Volume alerts";\nconst description = "Shows boxes on high-volume candles";\ndefine(title, description, "onchart", true, true);\n\nconst color = style.color("Color", "#00C8FF");\nconst volumeThreshold = input.number("Volume threshold", 1000, 0, 10000000, 1);\nconst alertVolumeThreshold = alertInput.number("Alert volume threshold", 5000, 0, 10000000, 1);\nconst alertCloseThreshold = alertInput.number("Alert close threshold", 100000, 0, 10000000, 1);\n\nconst candles = source.ohlcv();\nconst latestCandle = candles.at(-1);\nconst closes = candles.map(c => c.close);\n\n// 系列アラート: 最新の終値をチェック\nplot.lineSeries("Closes", closes, color).alert((close, date) => {\n if (close > alertCloseThreshold) alert.fire("Close above threshold", `close ${close}`, latestCandle.startTime);\n});\n\nfor (let i = 0; i < candles.length; i++) {\n const candle = candles[i];\n\n if (candle.volume > volumeThreshold) {\n const right = i < candles.length - 1 ? candles[i + 1].startTime : candle.startTime + 60000;\n\n // 図形アラート: ユーザーのアラートしきい値と比較\n plot.box(`Volume ${i}`, candle.startTime, candle.high, right, candle.low, "#00C8FF", 0.3)\n .alert(() => {\n if (candle.volume > alertVolumeThreshold)\n alert.fire("High volume", `vol ${candle.volume}`, candle.startTime);\n });\n }\n}\n')),Object(b.b)("h2",{id:"インジケーターの例"},"インジケーターの例"),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'const title = "Your first indicator";\nconst description = "Shows closes lines on the chart";\nconst indicatorType = "onchart";\n\ndefine(title, description, indicatorType, true, true);\n\nconst color = input.color("Line Color", "#00C8FF");\nconst candles = source.ohlcv();\nconst closes = candles.map(c => c.close);\nplot.lineSeries("Closes", closes, color);\n\n')),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'define("Example Indicator", "Demonstrates basic plotting", "onchart", true, true);\n\nconst color = input.color("Line Color", "#00FF99");\nconst candles = source.ohlcv();\nconst closes = candles.map(c => c.close);\n\nconst ema20 = ta.ema(closes, 20);\nplot.lineSeries("EMA 20", ema20, color);\n\n')),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'const title = "Colored Volume Bars"; \nconst description = "Volumes colored based on candle direction."; \nconst indicatorType = "onchart"; \nconst isPublic = true; \nconst isPublicCode = true; \n\ndefine(title, description, indicatorType, isPublic, isPublicCode); \n\n// OHLC ローソク足を取得\nconst candles = source.ohlcv(); \n\nconst colorUp = style.color("Color 1", "#2BB462"); // 上昇時の緑系の色\nconst colorDown = style.color("Color 2", "#FB4C51"); // 下落時の赤系の色\nconst volumes = candles.map(candle => candle.volume); \n\nplot.barSeries("Volume", volumes, (value, index) => {\n const currentCandle = candles[index]; \n return currentCandle.close >= currentCandle.open ? colorUp : colorDown; \n});\n\n')),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},"define('Coinbase Premium Index', 'Coinbase Premium Index', 'offchart', true, false);\n\nconst color1 = style.color(\"Color 1\", \"#2BB462\");\nconst color2 = style.color(\"Color 2\", \"#FB4C51\");\n\n// OHLC ローソク足を取得\nconst cbCandles = source.ohlcv('coinbase', 'BTC-USD');\nconst binanceCandles = source.ohlcv('binance', 'BTCUSDT');\n\n// 終値を抽出\nconst cbCloses = cbCandles.map(c => c.close);\nconst binanceCloses = binanceCandles.map(c => c.close);\n\n// --- Coinbase プレミアムインデックスの計算 ---\nconst premiumPercent = cbCloses.map((cb, i) => {\n const b = binanceCloses[i];\n return ((cb - b) / b) * 100;\n});\n\n// プレミアムインデックスを描画\nplot.barSeries(\"Premium %\", premiumPercent, ((d) => d > 0 ? color1 : color2)) // パーセントでの差\n\n")),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'const title = "Candles";\nconst description = "Simple candles draw";\nconst indicatorType = "offchart";\nconst isPublic = true;\nconst isPublicCode = true;\ndefine(title, description, indicatorType, isPublic, isPublicCode);\n\nconst colorBuy = style.color("Buy Color", "#2BB462");\nconst colorSell = style.color("Sell Color", "#7a3d3f");\nconst candles = source.ohlcv();\nconst closes = candles.map(c => c.close);\nconst opens = candles.map(c => c.open);\nconst highs = candles.map(c => c.high);\nconst lows = candles.map(c => c.low);\nplot.candleSeries(\n "Candles",\n opens, closes, highs, lows,\n (v, i) => {\n return opens?.[i] > closes?.[i] ? colorBuy : colorSell\n }\n);\n\n')),Object(b.b)("p",null,"Order Book Pressure(価格周辺の買い / 売りの板の厚みのインバランスバンド。トレーディングターミナルの「Order Book Pressure」オーバーレイに似たもの):"),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'const title = "Order Book Pressure";\nconst description = "Bid / ask depth imbalance bands around the price";\ndefine(title, description, "onchart", true, true);\n\nconst minBidRatio = input.number("Min bid ratio %", 20, 0, 100, 1);\nconst minAskRatio = input.number("Min ask ratio %", 20, 0, 100, 1);\nconst depthFrom = input.select("Depth from", "0%", ["0%", "1%", "2.5%", "5%"]);\nconst depthTo = input.select("Depth to", "5%", ["1%", "2.5%", "5%", "10%"]);\n\nconst bidColor = style.color("Bid fill color", "#a5d6a7");\nconst askColor = style.color("Ask fill color", "#f1627e");\nconst extremeColor = style.color("Extreme color", "#ffff00");\nconst highlight = style.boolean("Highlight extremes", true);\nconst showRef = style.boolean("Show reference lines", true);\n\nconst alertMinRatio = alertInput.number("Alert min |ratio| %", 40, 0, 100, 1);\n\nconst bounds = [1, 2.5, 5, 10]; // 終値からの%で表した板の深さのバンド\nconst from = parseFloat(depthFrom);\nconst to = parseFloat(depthTo);\n\nconst candles = source.ohlcv();\nconst depths = source.depths();\nconst liveBook = source.orderbook();\n\n// ローソク足ごとのオーダーブック: depths()[i] は candles[i] のスナップショット(最大の指値注文)、最新のローソク足はライブの板を使用\nconst lastIndex = candles.length - 1;\nconst books = candles.map((c, i) => {\n if (!c) return null;\n if (i === lastIndex && ta.bestBid(liveBook)) return liveBook;\n return depths[i]?.data || null;\n});\nconst closes = candles.map(c => c ? c.close : null);\n\n// 各バンドのインバランス比率(%)(正 = 買いが優勢、負 = 売りが優勢)\nconst ratios = bounds.map((upper, b) => {\n const lower = b === 0 ? 0 : bounds[b - 1];\n return candles.map((c, i) => {\n const book = books[i];\n if (!c || !book) return null;\n const bid = ta.sumBids(book, upper, c.close) - ta.sumBids(book, lower, c.close);\n const ask = ta.sumAsks(book, upper, c.close) - ta.sumAsks(book, lower, c.close);\n const total = bid + ask;\n return total > 0 ? ((bid - ask) / total) * 100 : 0;\n });\n});\n\n// 比率が強いほどバンドを不透明にし、極端な比率には極端値の色を使う\nconst bandOpacity = (ratio) => Math.min(0.95, Math.abs(ratio || 0) / 70 * 0.95);\nconst bandColor = (ratio) => highlight && Math.abs(ratio || 0) >= 63 ? extremeColor : (ratio >= 0 ? bidColor : askColor);\n\nbounds.forEach((upper, b) => {\n const lower = b === 0 ? 0 : bounds[b - 1];\n if (from > lower || upper > to) return; // バンドが選択した深さの範囲外\n\n const bidUpper = closes.map(c => c != null ? c * (1 - lower / 100) : null);\n const bidLower = closes.map(c => c != null ? c * (1 - upper / 100) : null);\n const askLower = closes.map(c => c != null ? c * (1 + lower / 100) : null);\n const askUpper = closes.map(c => c != null ? c * (1 + upper / 100) : null);\n\n if (showRef) {\n plot.lineSeries(`Bid ${upper}%`, bidLower, bidColor, 0.4);\n plot.lineSeries(`Ask ${upper}%`, askUpper, askColor, 0.4);\n }\n\n // 買い圧力: 買いが最小比率を超えて優勢なローソク足だけバンドを塗りつぶす\n plot.bandSeries(\n `Bid pressure ${lower}-${upper}%`,\n bidUpper.map((v, i) => ratios[b][i] >= minBidRatio ? v : null),\n bidLower,\n (upper, lower, i) => bandColor(ratios[b][i]),\n (upper, lower, i) => bandOpacity(ratios[b][i])\n );\n\n // 売り圧力\n plot.bandSeries(\n `Ask pressure ${lower}-${upper}%`,\n askUpper.map((v, i) => ratios[b][i] <= -minAskRatio ? v : null),\n askLower,\n (upper, lower, i) => bandColor(ratios[b][i]),\n (upper, lower, i) => bandOpacity(ratios[b][i])\n );\n\n // 最新のローソク足でアラート\n const latestRatio = ratios[b][lastIndex];\n if (latestRatio != null && Math.abs(latestRatio) >= alertMinRatio) {\n alert.fire(`Pressure ${lower}-${upper}%`, `ratio ${latestRatio.toFixed(1)}%`, candles[lastIndex].startTime);\n }\n});\n\n')),Object(b.b)("p",null,"Top movers with RSI(スクリプトウィジェット:取引所で大きく動いた銘柄を RSI と EMA トレンド付きで表示。チャートと同期するとそのチャートの取引所と時間足に従います。「スクリプトウィジェット」を参照):"),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'const title = "Top movers with RSI";\nconst description = "Biggest movers of an exchange with RSI and EMA trend on a timeframe";\ndefine(title, description, "widget", true, true);\n\n// settings for a widget that is not synced with a chart\n// (declare every input on its own line: the settings are matched by the variable name)\nconst exchangeInput = input.select("Exchange", "binanceFutures", exchanges.map((e, i) => ({ title: exchangesNames[i], value: e })));\nconst timeframeInput = input.select("Timeframe", "1h", ["15m", "1h", "4h", "1d"]);\nconst changePeriod = input.select("Change over", "1d", ["1h", "4h", "1d"]);\nconst minVolume = input.number("Min volume, $M", 5, 0, 1000);\nconst rowsCount = input.number("Rows", 6, 1, 7); // one data request per row: 8 per run, markets() takes one\nconst bars = input.number("Bars", 200, 50, 1000);\n\n// a synced chart decides the exchange and the timeframe\nconst exchange = currentExchange || exchangeInput;\nconst timeframe = currentTimeframe || timeframeInput;\n\n// table texts in the user\'s interface language (userLocale), English for the others\nconst texts = {\n en: { ticker: "Ticker", price: "Price", volume: "Volume", trend: "Trend", above: "▲ above EMA 50", below: "▼ below EMA 50", empty: "Nothing moved enough: lower the minimum volume" },\n ru: { ticker: "Тикер", price: "Цена", volume: "Объём", trend: "Тренд", above: "▲ выше EMA 50", below: "▼ ниже EMA 50", empty: "Сильных движений нет: уменьшите минимальный объём" },\n de: { ticker: "Ticker", price: "Preis", volume: "Volumen", trend: "Trend", above: "▲ über EMA 50", below: "▼ unter EMA 50", empty: "Keine starken Bewegungen: Mindestvolumen senken" },\n};\nconst t = texts[userLocale] || texts.en;\n\n// one request for every ticker of the exchange\nconst movers = source.markets(exchange)\n .filter((m) => m.change[changePeriod] != null && (m.volume[changePeriod]?.total || 0) >= minVolume * 1e6)\n .sort((a, b) => Math.abs(b.change[changePeriod]) - Math.abs(a.change[changePeriod]))\n .slice(0, rowsCount);\n\n// source calls go in a plain loop, not inside .map() / .forEach() callbacks\nconst rows = [];\nfor (const m of movers) {\n const candles = source.ohlcv(exchange, m.ticker, timeframe, bars);\n const closes = candles.map((c) => c.close);\n const rsi = ta.rsi(closes, 14).at(-1);\n const ema = ta.ema(closes, 50).at(-1);\n const change = m.change[changePeriod];\n\n rows.push({\n ticker: m.ticker === currentTicker ? { value: m.ticker, bold: true } : m.ticker,\n price: m.price,\n change: { value: change, color: change >= 0 ? "#26a69a" : "#ef5350", bold: true },\n volume: m.volume[changePeriod]?.total ?? null,\n rsi: rsi == null ? null : { value: rsi, color: rsi >= 70 ? "#ef5350" : rsi <= 30 ? "#26a69a" : null },\n trend: ema == null ? null : closes.at(-1) > ema\n ? { value: 1, text: t.above, color: "#26a69a" }\n : { value: -1, text: t.below, color: "#ef5350" },\n });\n}\n\nwidget.table({\n columns: [\n { key: "ticker", title: t.ticker, syncTicker: true, syncExchange: exchange }, // click: the synced chart opens it\n { key: "price", title: t.price, type: "price", align: "right" },\n { key: "change", title: `${changePeriod} %`, type: "percent", align: "right", sort: "desc" },\n { key: "volume", title: `${t.volume} ${changePeriod}`, type: "number", decimals: 0, align: "right" },\n { key: "rsi", title: `RSI ${timeframe}`, type: "number", decimals: 1, align: "right" },\n { key: "trend", title: t.trend, align: "center" },\n ],\n rows,\n options: { emptyText: t.empty },\n});\n')),Object(b.b)("p",null,"Movers chart(スクリプトウィジェット:取引所で24時間に大きく動いた銘柄の棒グラフ。チャートと同期するとそのチャートの取引所に従います。「スクリプトウィジェット」を参照):"),Object(b.b)("pre",null,Object(b.b)("code",{parentName:"pre",className:"language-js"},'const title = "Movers chart";\nconst description = "24h change of the biggest movers of an exchange as bars";\ndefine(title, description, "widget", true, true);\n\n// a synced chart decides the exchange, otherwise the setting\nconst exchangeInput = input.select("Exchange", "binanceFutures", exchanges.map((e, i) => ({ title: exchangesNames[i], value: e })));\nconst count = input.number("Tickers", 15, 3, 50);\nconst exchange = currentExchange || exchangeInput;\n// the series title in the user\'s interface language (userLocale), English for the others\nconst seriesTitle = { en: "24h change", ru: "Изменение за 24ч", de: "Änderung 24h" };\n\n// one request for every ticker of the exchange\nconst movers = source.markets(exchange)\n .filter((m) => m.change["1d"] != null)\n .sort((a, b) => Math.abs(b.change["1d"]) - Math.abs(a.change["1d"]))\n .slice(0, count)\n .sort((a, b) => b.change["1d"] - a.change["1d"]);\n\nwidget.chart({\n x: { type: "category", values: movers.map((m) => m.ticker) },\n series: [{\n type: "bar",\n title: seriesTitle[userLocale] || seriesTitle.en,\n values: movers.map((m) => m.change["1d"]),\n color: movers.map((m) => (m.change["1d"] >= 0 ? "#26a69a" : "#ef5350")),\n }],\n options: { yFormat: "percent" },\n});\n')))}void 0!==m&&m&&m===Object(m)&&Object.isExtensible(m)&&!Object.prototype.hasOwnProperty.call(m,"__filemeta")&&Object.defineProperty(m,"__filemeta",{configurable:!0,value:{name:"MDXContent",filename:"src/components/ja/Scripting.mdx"}}),m.isMDXComponent=!0}}]); //# sourceMappingURL=1f0a3292-64e6b22f597590db081e.js.map