All indicators

Alert(), alertcondition() or strategy alerts?

Jul 20, 2021

Static chart image
SignalsOscillatorsMoney ManagementPivot Based (Retrospective)

The Alert(), alertcondition() or strategy alerts? indicator provides a comprehensive educational framework for understanding and implementing various alert methods in Pine Script, specifically demonstrating how to manage entry, exit, and cancellation logic for automated trading.

Usage

This script serves as a technical template for developers and traders looking to automate their strategies using dynamic alerts. It demonstrates how to:

  • Trigger Entries: The script uses Stochastic crossovers to identify potential long and short entries.
  • Dynamic Stop-Loss & Take-Profit: It calculates stop-loss levels based on recent pivot highs and lows, adjusting them dynamically.
  • Order Cancellation: A key feature is the inclusion of logic to cancel pending stop orders if price breaches the stop-loss level before the entry is triggered.
  • Custom Alert Messages: It utilizes the modern alert() function to pass specific parameters (like offset, stop-loss price, and take-profit distance) within a single string, suitable for third-party execution bridges.

Details

The tool highlights the evolution of alerting in Pine Script by comparing three main methods:

  1. alertcondition(): The original method, limited primarily to "Study" scripts and less flexible for dynamic data.
  2. Strategy Alerts: Built-in alerts that trigger automatically based on the Strategy Tester's order execution. While convenient, they can be restrictive regarding the data sent in the message.
  3. alert(): The most versatile method, allowing developers to trigger alerts from within "Strategy" scripts at any logical event. This method is recommended for live trading as it allows for the transmission of dynamic variables and specific instructions (like order cancellations) that "Strategy Alerts" might miss.

Settings

  • Take Profit Level: Sets the distance for the take-profit target in ticks/pips.
  • Entry distance for stop orders: Determines the offset from the current price at which stop-entry orders are placed.

FAQ

How do I use the different alert types?

You can choose between built-in strategy alerts via the Strategy Tester or use the script's hardcoded alert() function calls which send dynamic data strings.

Can I use this for live trading?

While this is an educational script, it is designed with live automation logic in mind, specifically for users sending alerts to execution bridges.

How do I access Alert(), alertcondition() or strategy alerts??

You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.

Free indicator

Get free access to this indicator on the platforms below.

TradingView
NinjaTrader
MetaTrader 4/5

Unlock the entire LuxAlgo Library

Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.