Pick the MQL4 program type before writing logic
Program type determines which events the terminal sends. Expert Advisors can receive NewTick and Timer events. Custom indicators calculate buffers through OnCalculate. Scripts run OnStart once for a bounded chart task.
Using the wrong handler is not a style issue. OnTick is not generated for indicators or scripts, and OnCalculate belongs to custom indicators. Decide the runtime first, then write the handler signature exactly as documented.
| Program | Primary handler | Typical job |
|---|---|---|
| Expert Advisor | OnTick | Monitor conditions and manage orders |
| Custom indicator | OnCalculate | Calculate and draw chart values |
| Script | OnStart | Run one bounded task on demand |
