CrossTrade Docs
Basic CommandsAdvanced Commands
  • Welcome!
    • Set Up Guide
  • Getting Started
    • Installation
    • User Dashboard
      • XT Control Panel
      • Manual Trader
      • Command Builder
    • Alert History
    • TradingView Alerts
      • Dynamic Variables
      • XT Alert Builder
      • Example Indicators
      • Example Strategies
    • VPS Connection Guide
  • Webhooks
    • Overview
    • Commands
      • Place Order
      • Flat Place Order
      • Close Position
      • Reverse
      • Reverse Position
      • Flatten Positions
      • Flatten Everything
      • Cancel Order
      • Cancel Orders
      • Cancel All Orders
      • Cancel Replace
      • Change Order
      • Close Strategy
    • Advanced Options
      • Multi-Account Placement
      • Flatten First
      • Require Market Position
      • Max Positions
      • Bracket Orders
      • Percentage and Tick Prices
      • Limit Order Timeouts
      • Trading Window
      • Bypass Trade Windows
      • Delay Timer
      • Rate-Limiting
      • Alert Commenting
      • Kill Switch
      • Notes
    • Examples & Use Cases
    • Troubleshooting
  • Account Manager
    • Overview
      • How It Works
      • Dashboard
      • Global Settings
      • Frequently Asked Questions (FAQ)
    • Monitors
      • Profit/Loss Thresholds
      • Minimum Profit Drawdown
      • Trailing Drawdown
      • Advanced Usage
    • Account Settings
      • Auto-Flattening
      • Trading Windows
    • Management Logs
  • NinjaTrader
    • ATM Strategies
      • Creating ATM Template
    • Optimizing NinjaTrader Performance
    • Enabling Multi-Provider Mode
  • CrossTrade API
    • Overview
    • Authentication
    • Rate Limiting
    • Webhook Trading
    • Accounts
      • GET Accounts Summary
      • GET Accounts
      • GET Account
    • Positions
      • GET Positions
      • GET Position
      • POST Close Position
      • POST Reverse
      • POST Reverse Position
      • POST Flatten Positions
      • POST Flatten Everything
    • Orders
      • GET Orders
      • GET Order
      • GET Order Status
      • POST Cancel Order
      • POST Cancel Orders
      • POST Cancel All Orders
      • POST Place Order
      • POST Flat Place Order
      • POST Replace Order
      • PUT Change Order
    • Strategies
      • GET Strategies
      • GET Strategy
      • POST Close Strategy
    • Executions
      • GET Executions
      • GET Execution
    • Quotes
      • GET Quote
  • Changelog
    • XT Versions
    • All Updates
  • Affiliate Program
    • Media Kit
  • Social Links
    • Discord
    • TradingView
    • YouTube
    • X (Twitter)
    • Instagram
    • Facebook
    • Reddit
    • Website
    • Blog
Powered by GitBook
On this page
  • What Are Dynamic Strategy Variables?
  • How to Use Dynamic Strategy Variables in CrossTrade Alerts
  • Key Points to Remember
  1. Getting Started
  2. TradingView Alerts

Dynamic Variables

An overview of dynamic variables and how to use them

What Are Dynamic Strategy Variables?

Dynamic strategy variables in TradingView are placeholders that automatically populate with values from your TradingView strategy during execution. They are primarily used for strategies and can dynamically set parameters like:

  • Action: Whether to buy, sell, or close a position.

  • Quantity (Qty): The amount of an asset to trade.


How to Use Dynamic Strategy Variables in CrossTrade Alerts

1. Using Variables with the Alert Message Window

If your TradingView strategy generates dynamic variables for Action and Qty, you can integrate these into your CrossTrade alert. Here’s how:

  • Define the variables in your strategy.

  • In the alert's Message field, ensure that the placeholders (e.g., {{strategy.order.action}}, {{strategy.order.qty}}) are used.

  • CrossTrade will interpret these placeholders and execute the corresponding actions on your connected trading platform.

Example:

If your strategy generates an alert with the following placeholders:

action={{strategy.order.action}};
qty={{strategy.order.qty}};

CrossTrade will process the alert dynamically, replacing the placeholders with the actual action (e.g., buy, sell) and quantity values defined by your strategy. If you're trading futures, its best to use the variable {{strategy.order.contracts}}


2. Static Alerts for Indicators

Since indicators do not support dynamic variables specifically for the buy or qty fields, you must provide all required fields explicitly in the Message window. For example:

action=buy;
qty=10;

This ensures that CrossTrade receives complete and actionable instructions for your trades. You can use certain variables with indicators, such as:

  • {{close}} → The closing price of the current bar

  • {{open}} → The opening price of the current bar

  • {{high}} → The highest price of the current bar

  • {{low}} → The lowest price of the current bar

However, bear in mind that these will offer limited functionality when compared to strategy variable.


3. Customizing Alerts with Pine Script

For users with access to Pine Script, you can take full control of the alert payload by embedding the CrossTrade configuration directly into your script. This method ensures maximum flexibility and precision.

Steps:

  1. Define the full CrossTrade payload in your Pine Script:

    if longCondition
            stopLossPrice = close - stopLossTicks
            targetPrice = close + targetTicks
            alertMessage = 'key=your-secret-key;'
            alertMessage += 'command=PLACE;'
            alertMessage += 'account=sim101;'
            alertMessage += 'instrument=NQ 06-25;'
            alertMessage += 'action=BUY;'
            alertMessage += 'qty=1;'
            alertMessage += 'order_type=MARKET;'
            alertMessage += 'tif=DAY;'
            alertMessage += 'flatten_first=true;'
            alertMessage += 'take_profit=' + str.tostring(targetPrice) + ';'
            alertMessage += 'stop_loss=' + str.tostring(stopLossPrice) + ';'
            
            strategy.entry("Long", strategy.long, alert_message=alertMessage)
  2. Call the payload in your alert configuration using the {{strategy.order.alert_message}} placeholder.

Example Alert:

{{strategy.order.alert_message}}

Key Points to Remember

  1. Strategies Only: Dynamic variables are exclusively for use with strategies. They are not supported for indicators.

  2. Supported Fields: Only the Action and Qty fields can use dynamic variables in CrossTrade alerts.

  3. Static Messages for Indicators: For indicators, you must manually provide all required details in the alert's Message window.

PreviousTradingView AlertsNextXT Alert Builder

Last updated 1 month ago