pine_set_source
Replace the current Pine Script code in TradingView's Pine Editor with new source code, including the required version header.
Instructions
Replace the Pine Editor source code with new content.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | New Pine Script source code. Replaces the current editor contents entirely. Include `//@version=5` at the top. |
Implementation Reference
- src/tools/pine.ts:44-53 (schema)Input schema for pine_set_source: expects a 'code' string with min length 1.
export const pineSetSourceInput = z .object({ code: z .string() .min(1) .describe( 'New Pine Script source code. Replaces the current editor contents entirely. Include `//@version=5` at the top.', ), }) .strict(); - src/tools/pine.ts:55-58 (schema)Output schema for pine_set_source: returns {ok: true, bytes: number}.
export const pineSetSourceOutput = z.object({ ok: z.literal(true), bytes: z.number().int().nonnegative(), }); - src/tools/pine.ts:60-74 (handler)Handler function that calls page.setPineSource(input.code) and returns {ok: true, bytes} or throws ToolExecutionError.
export async function pineSetSource( input: z.infer<typeof pineSetSourceInput>, page: TradingViewPage, ): Promise<z.infer<typeof pineSetSourceOutput>> { try { await page.setPineSource(input.code); return { ok: true, bytes: input.code.length }; } catch (cause) { throw new ToolExecutionError( 'pine_set_source', 'Failed to set Pine source. Is the Pine Editor open?', cause, ); } } - src/tools/index.ts:33-36 (registration)Imports pineSetSource, pineSetSourceInput, pineSetSourceOutput from './pine.js'.
pineSetSource, pineSetSourceInput, pineSetSourceOutput, } from './pine.js'; - src/tools/index.ts:118-124 (registration)Registration entry: name 'pine_set_source', description, input/output schemas, and handler reference.
{ name: 'pine_set_source', description: 'Replace the Pine Editor source code with new content.', input: pineSetSourceInput, output: pineSetSourceOutput, handler: pineSetSource, },