Skip to content
ChartTailor
WorkServicesPricingField NotesAbout Start a build
← Pine Discoveries

Automation work should start with the alert contract

Before a Pine script can drive a bot or webhook, the signal states and failure cases need to be written down.

The fastest way to make Pine automation messy is to start with the chart. That feels backwards because the chart is the visible part. But if the script is going to send messages to a bot, copier, bridge, or execution workflow, the chart is not the only product. The alert contract is part of the product too.

This one matters because automation requests often arrive as “make this indicator trade automatically.” That sentence hides most of the important details. Does the user want entries only, or exits too? Should the bot scale out? Should a new opposite signal close first or reverse immediately? What happens if the same alert fires twice?

Why this catches people

Pine can generate the message, but it cannot decide the business rules after the fact. If the receiver expects a clean order instruction and the script sends a vague setup name, the problem is not a missing line of code. It is an undefined interface. That interface needs to include signal type, side, quantity model, risk state, symbol, timeframe, and whether the message is provisional or confirmed.

The other easy mistake is treating backtest logic as automation logic. A strategy can look organized in the Strategy Tester and still be unsuitable for a bot. The tester has a broker emulator, historical OHLC assumptions, and position accounting rules. A webhook receiver has its own state, latency, duplicate handling, and error recovery.

The Pine bit

The first artifact I want is a simple event table. Not a full software spec, just a list of the events the script is allowed to send. For example: entry_long_confirmed, entry_short_confirmed, exit_partial, exit_full, cancel_setup, and heartbeat if the receiver needs one. Each event should have a payload shape and a rule for when it is allowed to fire.

Once that exists, the Pine code gets simpler. Conditions can feed named states. Alert messages can be generated from those states. The receiver can be tested against stable examples before anyone worries about colors or label placement.

event = longSignal ? "entry_long_confirmed" :
        shortSignal ? "entry_short_confirmed" :
        exitSignal ? "exit_full" : ""

canSend = event != "" and barstate.isconfirmed

How I handle it in builds

For a nontechnical client, I do not expose all of this as jargon. I translate it into plain questions: what should happen first, what should happen if the signal changes its mind, and what should never happen twice? Those answers become the automation requirements. Pine then becomes the implementation, not the place where the requirements are improvised.

This also keeps the indicator useful if the user later changes bridge providers. A well-designed alert contract can be adapted. A pile of one-off strings embedded in conditions usually has to be rediscovered from scratch.

Where this shows up

The event table does not have to be elaborate. For most projects, one page is enough: event name, when it fires, required payload keys, whether it can repeat, and what cancels it. That one page catches the questions that otherwise appear during live testing, when every change feels urgent.

I especially care about idempotency. If the same webhook arrives twice, should the receiver ignore the second one, update an existing order, or treat it as a new instruction? Pine can include a bar time, event ID, setup ID, or position state to help the receiver decide. Without that, duplicate handling gets pushed into hope.

The client does not need to know the word idempotency. They need the practical question: “If this alert fires twice, what should happen?” Getting that answer before coding is what makes the automation feel professional.

How I test it

I test automation logic with event examples before connecting anything live. For each event, I want one sample payload, one duplicate example, and one cancellation or failure case. If those examples cannot be written clearly, the Pine code is not the blocker. The event design is still unfinished.

Checks before I trust it

  • List the events before building the alert payloads.
  • Separate setup alerts from execution instructions.
  • Define duplicate handling before live testing.
  • Include enough context for the receiver to validate symbol, timeframe, and state.
  • Treat Strategy Tester output as evidence, not as an automation spec.

The point I keep coming back to is that automation is mostly agreement before it is code. Once the alert contract is written down, the Pine work becomes cleaner and the external tool has less room to invent meaning.