MultiCharts EasyLanguage Guide

MultiChart EasyLanguage Trading Systems Guide

Table of Contents

  1. Introduction to MultiCharts and EasyLanguage
  2. Trading System Components
  3. EasyLanguage Syntax and Programming
  4. Sample Trading Strategies
  5. Resources for Further Learning

Introduction to MultiCharts and EasyLanguage

What is MultiCharts?

MultiCharts is an award-winning trading platform designed for backtesting and algorithmic trading. It enables traders to design and execute high-performance trading strategies with advanced analytics, technical indicators, and optimization capabilities. The platform allows traders to turn their ideas into trading systems by combining programming with historical market data to test performance in real market conditions without risk.

Key features of MultiCharts include:

What is EasyLanguage?

EasyLanguage is a powerful yet easy-to-learn programming language developed by TradeStation Securities. It has been widely used in the trading industry for over 20 years and has become a standard for trading applications. The language was designed to express financial instrument trading rules in a systematic and logical way that can be executed by a computer.

EasyLanguage allows traders to:

Relationship Between MultiCharts and EasyLanguage

MultiCharts uses PowerLanguage, which is an advanced programming environment developed by MCT Limited. PowerLanguage maintains high compatibility with EasyLanguage, making it possible to use the extensive collection of existing EasyLanguage indicators and strategies.

Key points about their relationship:

PowerLanguage extends EasyLanguage functionality by allowing:

Trading System Components

Entry and Exit Signals

MultiCharts provides robust capabilities for creating and managing entry and exit signals in trading systems. These are essential components that determine when to enter or exit the market.

Entry Strategies

Entry strategies in MultiCharts are pre-designed One-Cancels-Other (OCO) order groups to enter positions. They consist of combinations of limit and/or stop orders, and if one is filled then the other one is cancelled. Key entry strategies include:

  1. Breakout Strategy: Places two stop orders at specified prices/distances - a buy stop order above the current price and a sell stop order below the current price. This strategy is designed to capture sudden and significant price movements through support and resistance levels.

  2. Fade Strategy: Places two limit orders at specified prices/distances - a buy limit order below the current price and a sell limit order above the current price. This strategy trades against the trend, buying when prices go down and selling when prices go up.

  3. Breakout Up/Fade Strategy: A combination of breakout and fade strategies used when the trader expects the price to go up. It places a buy stop above the current price and a buy limit order below the current price.

  4. Breakout Down/Fade Strategy: A combination of breakout and fade strategies used when the trader expects the price to go down. It places a sell stop below current price and sell limit above current price.

Entry strategies can be applied to charts through drag-and-drop or by right-clicking, making them easy to implement.

Exit Strategies

Exit strategies are designed to protect against sudden market movements and to exit a position in a structured and organized fashion. MultiCharts uses a 'building block' approach to construct automated exit strategies. Key exit strategies include:

  1. Stop Loss: A stop order that defines how much loss is tolerable before a position will be exited. When the specified price is reached, the order becomes a market order.

  2. Profit Target: A limit order placed to define how much profit must be attained before the position is closed. Unlike stop orders, limit orders are filled only at the specified price or better.

  3. Brackets: A One-Cancel-Other (OCO) order group with one limit order and one stop order. If one of these orders is filled, the other one will be cancelled.

  4. Breakeven: An exit strategy for exiting the market without losing money. It places a stop order that becomes active once a specified profit level is reached.

  5. Trailing Stop: A 'smart' stop order that follows the current position's profit and executes if the price goes in the opposite direction. It allows for capturing profits while limiting losses.

Exit strategies can be automatically applied to every new order placed, ensuring consistent risk management.

Position Sizing

Position sizing is a critical component of trading systems that determines how many contracts or shares to trade. MultiCharts offers various approaches to position sizing:

  1. Fixed Position Sizing: Trading a fixed number of contracts or shares regardless of account size or market conditions.

  2. Risk-Based Position Sizing: Calculating position size based on a fixed amount or percentage of risk per trade. This approach adjusts position size based on the distance to the stop loss.

  3. Equity-Based Position Sizing: Adjusting position size based on account equity, allowing for position scaling as the account grows or shrinks.

  4. Volatility-Based Position Sizing: Adjusting position size based on market volatility, typically using indicators like Average True Range (ATR).

When optimizing trading strategies, it's generally recommended to use fixed position sizing to avoid introducing starting point dependencies that can distort optimization results. In live trading, however, risk-based or equity-based position sizing is often preferred for proper risk management.

Risk Management

MultiCharts provides comprehensive risk management tools to protect trading capital:

  1. Risk Management Mode: A specialized interface that allows traders to set and visualize risk parameters for trades. It includes:

    • Controls for setting stop loss and profit target levels
    • Calculation of risk in terms of ticks, price, currency amount, and percentage of equity
    • Automatic calculation of position size based on risk parameters
    • Visual representation of risk/reward ratios
  2. Money Management: Features for controlling the amount of capital risked per trade, including:

    • Dollar risk per trade
    • Percentage risk per trade
    • Maximum drawdown controls
    • Position sizing based on volatility
  3. Portfolio-Level Risk Management: Tools for managing risk across multiple instruments and strategies, ensuring diversification and preventing overexposure to specific markets.

Backtesting Capabilities

MultiCharts offers sophisticated backtesting capabilities to evaluate trading strategies before deploying them in live markets:

  1. Realistic Backtesting: MultiCharts aims to recreate past market conditions and order execution as accurately as possible, minimizing assumptions and considering many factors that affect trading outcomes.

  2. Tick-by-Tick Simulation: The Bar Magnifier feature allows for reconstructing exact price movements within each bar, increasing precision during backtesting. This enables testing on a more granular level than the displayed chart timeframe.

  3. Comprehensive Factors: The backtesting engine considers essential factors including:

    • Liquidity and order fill probability
    • Tick-by-tick price changes
    • Ask-bid-trade price differences (spread)
    • Commission and slippage
    • Initial capital and interest rates
    • Trade size and currency conversion
  4. Advanced Order Types: The backtesting engine emulates various order types including market, stop, limit, stop-limit, and one-cancels-other (OCO) orders, as well as profit targets, stop-losses, and trailing stops.

  5. Multi-Currency Support: Base currency allows calculating profit and loss during strategy backtesting with a specified currency for Forex pairs or non-US symbols, applying currency conversion as needed.

  6. Performance Metrics: Comprehensive performance reports with metrics such as net profit, drawdown, profit factor, Sharpe ratio, and many others to evaluate strategy effectiveness.

  7. Multi-Threading Optimization: The platform uses multi-threading for strategy optimization, distributing tasks across different CPU cores for faster processing, especially beneficial when testing multiple parameter combinations.

EasyLanguage Syntax and Programming

Program Structure

EasyLanguage is a compiled language based on the Pascal programming language. Programs are evaluated from top to bottom, once for each historical bar in a chart, and then calculated tick-by-tick in real-time when markets are open.

Key structural characteristics:

Basic Syntax Elements

Variables and Data Types

EasyLanguage supports three main data types:

  1. Numeric Types:

    • Integer (int): Whole numbers from -2,147,483,648 to 2,147,483,647
    • Float (float): Signed decimal values with less precision than doubles (not recommended)
    • Double (double): Signed decimal values with highest precision (default type)
  2. Boolean (True/False):

    • Used for logical conditions
    • Can be initialized as true or false
  3. String:

    • Used for text values
    • Enclosed in quotes: "This is a string"

Variable Declaration

Variables are declared at the beginning of the code using the Variables or Vars keyword:

Variables: MyValue(0), Counter(0);

Or with specific types:

Variables: double AvgHighs(0), int LookBack(0), bool IsUptrend(false);

Arrays

Arrays allow storing multiple values under a single variable name:

  1. Fixed Arrays:

    Arrays: WeeklyHighs[52](0), WeeklyLows[52](0);
    

    This creates two arrays with 53 elements each (0-52), initialized to 0.

  2. Multi-dimensional Arrays:

    Arrays: VolumeHighs[5,20](0), VolumeLows[5,20](0);
    

    This creates two 2-dimensional arrays with 6 columns and 21 rows.

  3. Dynamic Arrays:

    Array: MyDynamicArray[](0);
    Array_SetMaxIndex(MyDynamicArray, Count);
    

    Used when the number of elements isn't known at declaration time.

Inputs

Inputs allow users to customize indicators or strategies without modifying the code:

Inputs: Length(20), Factor(0.5), UseFilter(true);

Input types include:

Historical References

EasyLanguage can reference previous bar values using square bracket notation:

Close[1]      // Close price of the previous bar
High[5]       // High price from 5 bars ago
MyValue[3]    // Value of MyValue variable 3 bars ago

The current bar can be referenced with [0] or without brackets:

Close[0]      // Same as Close

IntrabarPersist Variables

Special variables that can store and update values tick-by-tick within a bar:

Vars: IntrabarPersist TickCount(0);
TickCount = TickCount + 1;

Control Structures

Conditional Statements

If-Then-Else:

If Condition Then
   Statement1;
Else
   Statement2;

Single-line format:

If Close > Close[1] Then Value1 = 1 Else Value1 = -1;

Begin-End Blocks:

If Condition Then Begin
   Statement1;
   Statement2;
   Statement3;
End
Else Begin
   Statement4;
   Statement5;
End;

Loops

For Loop:

For Value1 = 1 To 10 Begin
   Statement1;
   Statement2;
End;

While Loop:

While Condition Begin
   Statement1;
   Statement2;
End;

Common Functions and Keywords

Price Data References

Mathematical Functions

Plotting Functions

Trading Commands

Sample Trading Strategies

Moving Average Crossover Strategy

The Moving Average Crossover strategy is one of the most popular and straightforward trading strategies. It generates buy signals when a fast moving average crosses above a slow moving average and sell signals when the fast moving average crosses below the slow moving average.

// Simple Moving Average Crossover Strategy
// This strategy generates buy signals when a fast moving average crosses above a slow moving average
// and sell signals when the fast moving average crosses below the slow moving average.

[IntrabarOrderGeneration = false]

// Input parameters that can be adjusted by the user
Inputs:
    FastLength(9),    // Length of the fast moving average
    SlowLength(20),   // Length of the slow moving average
    StopLoss(500),    // Stop loss amount in points
    ProfitTarget(1000); // Profit target amount in points

// Variables to store the moving average values
Variables:
    FastMA(0),        // Fast moving average value
    SlowMA(0),        // Slow moving average value
    FastMAprev(0),    // Previous bar's fast moving average
    SlowMArev(0);     // Previous bar's slow moving average

// Calculate the moving averages
FastMA = Average(Close, FastLength);
SlowMA = Average(Close, SlowLength);
FastMArev = FastMA[1];
SlowMArev = SlowMA[1];

// Plot the moving averages on the chart
Plot1(FastMA, "Fast MA", Blue);
Plot2(SlowMA, "Slow MA", Red);

// Entry conditions
// Buy when fast MA crosses above slow MA
If FastMA > SlowMA AND FastMArev <= SlowMArev Then
    Buy("MA Crossover") Next Bar at Market;

// Sell when fast MA crosses below slow MA
If FastMA < SlowMA AND FastMArev >= SlowMArev Then
    Sell("MA Crossover") Next Bar at Market;

// Exit conditions
// Set stop loss and profit target for long positions
If MarketPosition = 1 Then Begin
    SetStopLoss(StopLoss);
    SetProfitTarget(ProfitTarget);
End;

// Set stop loss and profit target for short positions
If MarketPosition = -1 Then Begin
    SetStopLoss(StopLoss);
    SetProfitTarget(ProfitTarget);
End;

Strategy Explanation:

  1. Inputs: The strategy has four customizable inputs:

    • FastLength: The period for the fast moving average (default: 9)
    • SlowLength: The period for the slow moving average (default: 20)
    • StopLoss: The stop loss amount in points (default: 500)
    • ProfitTarget: The profit target amount in points (default: 1000)
  2. Calculations:

    • Two moving averages are calculated: a fast one and a slow one
    • Previous bar values are stored to detect crossovers
  3. Entry Logic:

    • Buy when the fast moving average crosses above the slow moving average
    • Sell when the fast moving average crosses below the slow moving average
  4. Risk Management:

    • Stop loss and profit target are set for both long and short positions
  5. Visualization:

    • Both moving averages are plotted on the chart for visual confirmation

RSI Strategy

The Relative Strength Index (RSI) strategy is a popular mean-reversion strategy that uses the RSI indicator to identify potential overbought and oversold conditions. It generates buy signals when RSI crosses above an oversold threshold and sell signals when RSI crosses below an overbought threshold.

// RSI Strategy
// This strategy uses the Relative Strength Index (RSI) to generate buy and sell signals
// Buy when RSI crosses above oversold level, sell when RSI crosses below overbought level

[IntrabarOrderGeneration = false]

// Input parameters that can be adjusted by the user
Inputs:
    RSILength(14),     // Length for RSI calculation
    OverSold(30),      // Oversold threshold
    OverBought(70),    // Overbought threshold
    StopLoss(500),     // Stop loss amount in points
    ProfitTarget(1000); // Profit target amount in points

// Variables to store values
Variables:
    RSIValue(0),       // Current RSI value
    RSIValuePrev(0);   // Previous bar's RSI value

// Calculate RSI
RSIValue = RSI(Close, RSILength);
RSIValuePrev = RSIValue[1];

// Plot RSI on the chart
Plot1(RSIValue, "RSI", Blue);
Plot2(OverBought, "Overbought", Red);
Plot3(OverSold, "Oversold", Green);

// Entry conditions
// Buy when RSI crosses above oversold level
If RSIValue > OverSold AND RSIValuePrev <= OverSold Then
    Buy("RSI Oversold") Next Bar at Market;

// Sell when RSI crosses below overbought level
If RSIValue < OverBought AND RSIValuePrev >= OverBought Then
    Sell("RSI Overbought") Next Bar at Market;

// Exit conditions
// Set stop loss and profit target for long positions
If MarketPosition = 1 Then Begin
    SetStopLoss(StopLoss);
    SetProfitTarget(ProfitTarget);
End;

// Set stop loss and profit target for short positions
If MarketPosition = -1 Then Begin
    SetStopLoss(StopLoss);
    SetProfitTarget(ProfitTarget);
End;

Strategy Explanation:

  1. Inputs: The strategy has five customizable inputs:

    • RSILength: The period for RSI calculation (default: 14)
    • OverSold: The oversold threshold (default: 30)
    • OverBought: The overbought threshold (default: 70)
    • StopLoss: The stop loss amount in points (default: 500)
    • ProfitTarget: The profit target amount in points (default: 1000)
  2. Calculations:

    • RSI is calculated using the built-in RSI function
    • Previous bar RSI value is stored to detect crossovers
  3. Entry Logic:

    • Buy when RSI crosses above the oversold threshold
    • Sell when RSI crosses below the overbought threshold
  4. Risk Management:

    • Stop loss and profit target are set for both long and short positions
  5. Visualization:

    • RSI and threshold levels are plotted on the chart for visual confirmation

Breakout Strategy

The Breakout strategy is designed to capture significant price movements by generating buy signals when price breaks above a resistance level and sell signals when price breaks below a support level. This strategy works well in trending markets.

// Breakout Strategy
// This strategy generates buy signals when price breaks above a resistance level
// and sell signals when price breaks below a support level

[IntrabarOrderGeneration = false]

// Input parameters that can be adjusted by the user
Inputs:
    Length(20),        // Lookback period for support/resistance levels
    StopLoss(500),     // Stop loss amount in points
    ProfitTarget(1000); // Profit target amount in points

// Variables to store values
Variables:
    HighestVal(0),     // Highest high over lookback period
    LowestVal(0);      // Lowest low over lookback period

// Calculate support and resistance levels
HighestVal = Highest(High[1], Length);
LowestVal = Lowest(Low[1], Length);

// Plot support and resistance levels on the chart
Plot1(HighestVal, "Resistance", Red);
Plot2(LowestVal, "Support", Green);

// Entry conditions
// Buy when price breaks above resistance level
If Close > HighestVal Then
    Buy("Breakout") Next Bar at Market;

// Sell when price breaks below support level
If Close < LowestVal Then
    Sell("Breakdown") Next Bar at Market;

// Exit conditions
// Set stop loss and profit target for long positions
If MarketPosition = 1 Then Begin
    SetStopLoss(StopLoss);
    SetProfitTarget(ProfitTarget);
End;

// Set stop loss and profit target for short positions
If MarketPosition = -1 Then Begin
    SetStopLoss(StopLoss);
    SetProfitTarget(ProfitTarget);
End;

Strategy Explanation:

  1. Inputs: The strategy has three customizable inputs:

    • Length: The lookback period for calculating support/resistance levels (default: 20)
    • StopLoss: The stop loss amount in points (default: 500)
    • ProfitTarget: The profit target amount in points (default: 1000)
  2. Calculations:

    • Resistance level is calculated as the highest high over the lookback period
    • Support level is calculated as the lowest low over the lookback period
  3. Entry Logic:

    • Buy when price closes above the resistance level
    • Sell when price closes below the support level
  4. Risk Management:

    • Stop loss and profit target are set for both long and short positions
  5. Visualization:

    • Support and resistance levels are plotted on the chart for visual confirmation

Resources for Further Learning

Official Documentation

  1. MultiCharts Documentation

  2. EasyLanguage Manuals

Online Resources

  1. Forums and Communities

  2. Tutorials and Blogs

Books

  1. "Building Winning Trading Systems with TradeStation" by George Pruitt and John Hill

    • Comprehensive guide to developing trading systems using EasyLanguage
    • Covers strategy development, backtesting, and optimization
  2. "Trading Systems and Methods" by Perry Kaufman

    • Covers various trading systems and methods that can be implemented in EasyLanguage
    • Provides theoretical background and practical implementation details
  3. "Quantitative Trading Systems" by Howard Bandy

    • Focuses on the development and testing of quantitative trading systems
    • Includes examples that can be implemented in EasyLanguage

Video Tutorials

  1. MultiCharts YouTube Channel

  2. Third-Party Tutorials

Courses and Training

  1. MultiCharts Training

  2. Third-Party Training