Learn EAsiScript User Guide

Table of Contents

EAsiScript enables you to define sophisticated trading strategies through a clear and flexible syntax. At its core, EAsiScript uses expressions combining functions, operators, and indicators to drive trade decisions - from entry and exit points to stop losses and take profits. This guide will teach you step by step how to write effective scripts, with a focus on practical examples demonstrating key concepts like the ternary operator (?:), logical AND (&&), and logical OR (||) operators.

Disclaimer

The examples provided in this document are for educational purposes only and intended to demonstrate the functionality and application of EAsiScript. They have been generated as teaching examples and have not been tested in live market conditions. Before using any trading strategy, whether manually created or AI-generated:

  • Test thoroughly in a demo environment first
  • Validate across different market conditions and timeframes
  • Set appropriate position sizing and risk management parameters
  • Consider how the strategy may behave in extreme market conditions
  • Understand that past performance does not guarantee future results
  • Monitor strategy performance and be prepared to adjust parameters

Northen Trading Labs assumes no responsibility for any financial losses or other consequences arising from the use of these examples. Traders should develop their own testing procedures and risk management rules before deploying any strategy in a live trading environment.

The examples focus on demonstrating EAsiScript syntax and capabilities. A complete trading strategy requires additional considerations including:

  • Position sizing rules
  • Risk-reward requirements
  • Maximum drawdown limits
  • Market condition filters
  • Multiple timeframe analysis
  • Entry and exit confirmation rules

Basic Examples

These examples introduce fundamental EAsiScript concepts through simple, clear trading logic. Each example focuses on one key scripting technique, proper syntax, and function usage. Starting with built-in functions and basic price conditions, they provide the building blocks for more complex strategies. While intentionally simple, they follow best practices for bar referencing and decision making.

Example 1: Bar Direction

This example demonstrates how to use the BarTrend function to identify price direction.

Long Entry Script

BarTrend(1) == Bullish ? Ask() : 0

Purpose

Opens a buy trade when the last completed bar closes higher than it opened, showing a simple price direction filter.

Component Breakdown

  • Direction Check: BarTrend(1)
    • Analyzes the last completed bar (shift=1)
    • Returns Bullish (1) if close > open
  • Comparison: == Bullish
    • Checks if bar trend matches Bullish value
    • Uses predefined Bullish constant
  • Entry Price: Ask()
    • Returns current ask price if condition is met
    • 0 if condition is not met (no trade)

Key Points

  • Shows basic function usage with proper shift value
  • Demonstrates the ternary operator (?:)
  • Uses built-in constants
  • Implements clean entry logic

Note

This basic example can be enhanced by adding consecutive bar checks or volume confirmation.

Example 2: Price Range

This example shows how to use high and low price functions to identify trading ranges.

Long Entry Script

High(1) - Low(1) < ATR1(1) ? Ask() : 0

Purpose

Opens a buy trade when the last bar’s range is smaller than the average range, identifying potential consolidation periods.

Component Breakdown

  • Range Calculation: High(1) - Low(1)
    • Finds the last bar’s total range
    • Uses proper price functions
  • Comparison: < ATR1(1)
    • Compares to average true range
    • Identifies narrower than average bars
  • Entry Price: Ask()
    • Returns current ask price if condition is met
    • 0 if condition is not met (no trade)

Key Points

  • Shows price function usage
  • Demonstrates basic mathematical operations
  • Uses ATR for dynamic comparison
  • Implements range-based logic

Note

Ensure the ATR indicator is enabled in the Indicator’s List before running this script.

Example 3: Lower Highs

This example shows how to detect lower highs using the HighestHigh function.

Long Entry Script

HighestHigh(3) < HighestHigh(6) ? Ask() : 0

Purpose

Opens a buy trade when the highest high of the last 3 bars is lower than the highest high of the previous 3 bars, identifying a potential reversal point.

Component Breakdown

  • Recent High: HighestHigh(3)
    • Finds highest high of last 3 bars
    • Shows proper function usage
  • Prior High: HighestHigh(6)
    • Finds highest high of last 6 bars
    • Used to compare with recent period
  • Comparison: <
    • Confirms lower highs pattern
    • Shows proper operator usage

Key Points

  • Demonstrates HighestHigh function with different periods
  • Shows pattern detection technique
  • Uses clear comparison logic
  • Implements simple price analysis

Note

This basic pattern recognition can be used as a building block for more complex strategies.

Example 4: Volume Analysis

This example introduces basic volume analysis using the Volume function.

Long Entry Script

Volume(1) > Volume(2) * 1.5 ? Ask() : 0

Purpose

Opens a buy trade when the last bar’s volume is significantly higher than the previous bar’s volume, identifying increased market interest.

Component Breakdown

  • Current Volume: Volume(1)
    • Gets volume of last completed bar
    • Shows proper bar reference
  • Volume Increase: Volume(2) * 1.5
    • Compares to previous bar’s volume
    • Requires 50% volume increase
  • Entry Price: Ask()
    • Returns current ask price if condition is met
    • 0 if condition is not met (no trade)

Key Points

  • Shows Volume function usage
  • Demonstrates multiplication
  • Uses proper bar references
  • Implements volume-based logic

Note

Volume comparison provides a simple way to identify increased market activity.

Example 5: Cross Above Value

This example demonstrates how to detect when price crosses above a specific value.

Long Entry Script

Close(1) > MA1(1,0) && Close(2) <= MA1(2,0) ? Ask() : 0

Purpose

Opens a buy trade when price crosses above a moving average, showing basic cross detection.

Component Breakdown

  • Current Position: Close(1) > MA1(1,0)
    • Confirms price is above MA
    • Uses last completed bar
  • Previous Position: Close(2) <= MA1(2,0)
    • Confirms price was below MA
    • Uses bar before last
  • Entry Price: Ask()
    • Returns current ask price if conditions are met
    • 0 if conditions are not met (no trade)

Key Points

  • Shows proper cross detection technique
  • Demonstrates indicator value access
  • Uses multiple bar references
  • Implements basic AND logic

Note

Ensure the MA indicator is enabled in the Indicator’s List before running this script.

Example 6: High Pivot Detection

This example shows how to detect bars with strong bullish pivot patterns.

Long Entry Script

High(PP1(1,1,0,0xFFFFF)+1) <= High(1) ? Ask() : 0

Purpose

Opens a buy trade when the current bar’s high is greater than or equal to the high of the nearest pivot bar, indicating potential bullish reversal.

Component Breakdown

  • Pivot Reference: PP1(1,1,0,0xFFFFF)
    • Gets the shift to nearest high pivot bar
    • Buffer 1 = Pivot Order 1 shift values
    • Rotation 0 for high pivot shifts
    • Mask 0xFFFFF for lower 20 bits
  • High Comparison: High(PP1(1,1,0,0xFFFFF)+1) <= High(1)
    • Compares pivot high to current bar
    • +1 needed as PP1 returns shift from offset 1
  • Entry Price: Ask()
    • Returns current ask price if condition is met
    • 0 if condition is not met (no trade)

Key Points

  • Shows proper PP1 indicator usage
  • Demonstrates buffer and bit manipulation
  • Uses correct shift value adjustment
  • Implements pivot analysis logic

Note

Ensure the PP indicator is enabled in the Indicator’s List before running this script.

Example 7: RSI Level Check

This example shows how to check an indicator’s value against a threshold.

Long Entry Script

RSI1(1) < 30 ? Ask() : 0

Purpose

Opens a buy trade when RSI moves below 30, demonstrating simple oversold level detection.

Component Breakdown

  • RSI Check: RSI1(1)
    • Gets RSI value at last completed bar
    • Shows basic indicator value access
  • Threshold: < 30
    • Compares to oversold level
    • Uses simple comparison
  • Entry Price: Ask()
    • Returns current ask price if condition is met
    • 0 if condition is not met (no trade)

Key Points

  • Shows RSI indicator usage
  • Demonstrates value comparison
  • Uses proper bar reference
  • Implements level-based logic

Note

Ensure the RSI indicator is enabled in the Indicator’s List before running this script.

Example 8: Spread Check

This example demonstrates how to filter trades based on spread size.

Long Entry Script

Spread(1) <= ATR1(1) * 0.1 ? Ask() : 0

Purpose

Opens a buy trade when the spread is reasonable compared to average price movement, showing basic cost control.

Component Breakdown

  • Spread Size: Spread(1)
    • Gets spread at last completed bar
    • Shows spread function usage
  • Comparison: <= ATR1(1) * 0.1
    • Compares to 10% of ATR
    • Shows relative size check
  • Entry Price: Ask()
    • Returns current ask price if condition is met
    • 0 if condition is not met (no trade)

Key Points

  • Shows Spread function usage
  • Demonstrates relative comparison
  • Uses ATR for context
  • Implements cost-based filter

Note

Ensure the ATR indicator is enabled in the Indicator’s List before running this script.

Example 9: Time Filter

This example shows how to filter trades based on time of day.

Long Entry Script

TimeOfDay(9,30) ? Ask() : 0

Purpose

Opens a buy trade at exactly 9:30, demonstrating basic time-based entry rules.

Component Breakdown

  • Time Check: TimeOfDay(9,30)
    • Checks if current time is 9:30
    • Shows time function usage
  • Entry Price: Ask()
    • Returns current ask price if condition is met
    • 0 if condition is not met (no trade)

Key Points

  • Shows TimeOfDay function usage
  • Demonstrates time-based logic
  • Uses simple condition
  • Implements scheduling control

Note

Times are based on your broker’s server time. Verify the correct time zone for your trading session.

Example 10: Signal Check

This example shows how to use an indicator’s built-in signals.

Long Entry Script

Signal('ST1') == Bullish ? Ask() : 0

Purpose

Opens a buy trade when the SuperTrend indicator signals a bullish move, showing basic signal detection.

Component Breakdown

  • Signal Check: Signal('ST1')
    • Gets SuperTrend signal
    • Shows signal function usage
  • Comparison: == Bullish
    • Checks for bullish signal
    • Uses predefined constant
  • Entry Price: Ask()
    • Returns current ask price if condition is met
    • 0 if condition is not met (no trade)

Key Points

  • Shows Signal function usage
  • Demonstrates indicator signals
  • Uses proper comparison
  • Implements signal-based logic

Note

Ensure the SuperTrend (ST1) indicator is enabled in the Indicator’s List before running this script.

Intermediate Examples

These examples demonstrate how to construct more sophisticated trading strategies by combining multiple components and conditions. Each example shows a complete trade management approach, using all relevant scripts (entry, stop loss, trailing stop, take profit, and breakeven). While more complex than the Basic Examples, they maintain clear logic and focus on one key trading concept at a time. By studying these examples, you’ll learn how different EAsiScript components work together to create robust trading strategies and how various scripts interact during the lifecycle of a trade. You’ll also see practical implementations of risk management concepts and how to adapt your strategy to changing market conditions.

Example 1: Moving Average Trend Strategy

This example demonstrates a trend-following strategy that combines moving average trend with price position and dynamic trade management.

Long Entry Script

Trend('MA1') == Bullish && Close(1) > MA1(1,0) && Low(1) > MA1(1,0) ? Ask() : 0

Long Initial SL Script

MA1(1,0) - ATR1(1)

Long Trailing SL Script

MA1(1,0) - ATR1(1) * 0.5

Long TP Script

OrderPrice() + (OrderPrice() - SL()) * 2

Long BE Script

OrderPrice() + ATR1(1)

Purpose

Creates a trend-following strategy that enters when price shows clear bullish momentum above the moving average, with comprehensive trade management based on market volatility.

Component Breakdown

  • Entry Conditions
    • Trend('MA1') == Bullish: Confirms overall trend direction
    • Close(1) > MA1(1,0): Price closed above MA
    • Low(1) > MA1(1,0): Full bar above MA
  • Stop Loss Management
    • Initial: One ATR below MA for trend protection
    • Trailing: Half ATR below MA for closer tracking
  • Profit Targets
    • Take Profit: 2:1 reward-risk ratio
    • Breakeven: One ATR move in favor

Key Points

  • Shows complete trade management lifecycle
  • Demonstrates trend-following principles
  • Uses dynamic volatility-based adjustments
  • Implements proper risk-reward logic

Note

Ensure both MA and ATR indicators are enabled in the Indicator’s List. The MA period affects both trend detection and trade management.

Example 2: RSI Reversal Strategy

This example shows how to trade oversold conditions with confirmation and comprehensive trade management.

Long Entry Script

RSI1(1) < 30 && RSI1(1) > RSI1(2) && Close(1) > Open(1) ? Ask() : 0

Long Initial SL Script

Low(1) - ATR1(1)

Long Trailing SL Script

Low(1) - (ATR1(1) * (RSI1(1) < 50 ? 1 : 0.5))

Long TP Script

OrderPrice() + ATR1(1) * 3

Long BE Script

RSI1(1) > 50 ? OrderPrice() : 0

Purpose

Trades bullish reversals from oversold conditions, using RSI for entry confirmation and dynamic trade management based on both RSI and volatility conditions.

Component Breakdown

  • Entry Conditions
    • RSI1(1) < 30: Oversold condition
    • RSI1(1) > RSI1(2): RSI turning up
    • Close(1) > Open(1): Bullish price action
  • Stop Loss Management
    • Initial: One ATR below recent low
    • Trailing: Adapts to RSI position
  • Profit Targets
    • Take Profit: Three ATR target
    • Breakeven: When RSI crosses above 50

Key Points

  • Shows RSI-based reversal trading
  • Demonstrates adaptive trailing stop
  • Uses condition-based breakeven
  • Implements momentum-based exits

Note

Ensure both RSI and ATR indicators are enabled in the Indicator’s List. Consider adjusting RSI levels based on the specific instrument’s characteristics.

Example 3: Volatility Breakout Strategy

Long Entry Script

Close(1) > BB1(1,1) && Volume(1) > Volume(2) * 1.5 ? Ask() : 0

Long Initial SL Script

BB1(1,0) - ATR1(1)

Long Trailing SL Script

BB1(1,0)

Long TP Script

BB1(1,1) + (BB1(1,1) - BB1(1,0))

Long BE Script

OrderPrice() + ATR1(1)

Purpose

Trades breakouts from Bollinger Bands with volume confirmation, using the bands for dynamic trade management and profit targeting.

Component Breakdown

  • Entry Conditions
    • Close(1) > BB1(1,1): Price closes above upper band
    • Volume(1) > Volume(2) * 1.5: Increased volume confirms breakout
  • Stop Loss Management
    • Initial: One ATR below middle band
    • Trailing: Follows middle band
  • Profit Targets
    • Take Profit: Projects band width above upper band
    • Breakeven: One ATR move in favor

Key Points

  • Shows breakout trading technique
  • Demonstrates band-based management
  • Uses volume confirmation
  • Implements symmetric profit targets

Note

Ensure both Bollinger Bands and ATR indicators are enabled in the Indicator’s List. The strategy’s effectiveness depends on proper band settings for your timeframe.

Example 4: Support and Resistance Strategy

Long Entry Script

HLines1(1) > 0 && Close(1) > Signal('HLines1') && Volume(1) > Volume(2) ? Ask() : 0

Long Initial SL Script

Low(1) - ATR1(1)

Long Trailing SL Script

HLines1(1,0)

Long TP Script

OrderPrice() + (OrderPrice() - SL()) * 2

Long BE Script

High(1) > OrderPrice() + ATR1(1) ? OrderPrice() : 0

Purpose

Trades breakouts from horizontal support/resistance levels with volume confirmation and level-based management.

Component Breakdown

  • Entry Conditions
    • HLines1(1) > 0: Valid resistance level exists
    • Close(1) > Signal('HLines1'): Price breaks above level
    • Volume(1) > Volume(2): Volume confirms break
  • Stop Loss Management
    • Initial: One ATR below recent low
    • Trailing: Follows nearest support level
  • Profit Targets
    • Take Profit: 2:1 reward-risk ratio
    • Breakeven: After one ATR move

Key Points

  • Shows support/resistance trading
  • Demonstrates level-based exits
  • Uses volume confirmation
  • Implements proper risk management

Note

Ensure HLines and ATR indicators are enabled in the Indicator’s List. Level quality depends on proper HLines settings.

Example 5: Multi-Timeframe Momentum Strategy

Long Entry Script

Signal('RSI1') == Bullish && Close(1) > Close(2) ? Ask() : 0

Long Initial SL Script

Low(LowestLow(3)) - ATR1(1)

Long Trailing SL Script

RSI1(1) > 70 ? High(1) - ATR1(1) * 0.5 : Low(1) - ATR1(1)

Long TP Script

OBOS('RSI1') == -1 ? Bid() : OrderPrice() + ATR1(1) * 3

Long BE Script

RSI1(1) > 60 ? OrderPrice() : 0

Purpose

Trades momentum signals with RSI, using overbought/oversold conditions for trade management.

Component Breakdown

  • Entry Conditions
    • Signal('RSI1') == Bullish: RSI momentum signal
    • Close(1) > Close(2): Price confirmation
  • Stop Loss Management
    • Initial: Below recent swing low plus ATR buffer
    • Trailing: Adapts to RSI conditions
  • Profit Targets
    • Take Profit: Dynamic based on RSI overbought
    • Breakeven: RSI above 60

Key Points

  • Shows momentum-based trading
  • Demonstrates condition-based exits
  • Uses indicator signals
  • Implements adaptive management

Note

Ensure RSI and ATR indicators are enabled in the Indicator’s List. Adjust RSI levels to suit your instrument’s characteristics.

Example 6: Fibonacci Retracement Strategy

Long Entry Script

Signal('AutoFib1') == Bullish && Ask() > FibPrice('AutoFib1',0.618) ? Ask() : 0

Long Initial SL Script

FibPrice('AutoFib1',0.382) - ATR1(1)

Long Trailing SL Script

FibPrice('AutoFib1',0.618)

Long TP Script

FibPrice('AutoFib1',1.0)

Long BE Script

FibPrice('AutoFib1',0.786)

Purpose

Trades bullish moves from Fibonacci retracement levels, using Fib levels for trade management.

Component Breakdown

  • Entry Conditions
    • Signal('AutoFib1') == Bullish: Fib pattern signal
    • Ask() > FibPrice('AutoFib1',0.618): Price above 0.618 level
  • Stop Loss Management
    • Initial: Below 0.382 level with ATR buffer
    • Trailing: Follows 0.618 level
  • Profit Targets
    • Take Profit: Full retracement (1.0 level)
    • Breakeven: After reaching 0.786 level

Key Points

  • Shows Fibonacci-based trading
  • Demonstrates level-based management
  • Uses pattern recognition
  • Implements measured moves

Note

Ensure AutoFib indicator is enabled in the Indicator’s List. Success depends on proper Fibonacci pattern identification.

Example 7: SuperTrend Early Reversal Strategy

Long Entry Script

Trend('ST1') == Bearish && Low(1) < ST1(1,0) && Close(1) > Open(1) ? Ask() : 0

Long Initial SL Script

Low(1) - ATR1(1)

Long Trailing SL Script

ST1(1,0)

Long TP Script

OrderPrice() + (OrderPrice() - SL()) * 2

Long BE Script

Trend('ST1') == Bullish ? OrderPrice() : 0

Purpose

Attempts to catch reversals by entering when price shows strength (bullish close) while still in a bearish SuperTrend, with confirmation from price testing the SuperTrend level.

Component Breakdown

  • Entry Conditions
    • Trend('ST1') == Bearish: Confirms we’re in bearish trend
    • Low(1) < ST1(1,0): Price has tested SuperTrend level
    • Close(1) > Open(1): Shows bullish pressure
  • Stop Loss Management
    • Initial: Below recent low with ATR buffer
    • Trailing: Follows SuperTrend line after entry
  • Profit Targets
    • Take Profit: 2:1 reward-risk ratio
    • Breakeven: When trend officially turns bullish

Example 8: Stochastic Cross Strategy

Long Entry Script

Stoch1(1,0) > Stoch1(1,1) && Stoch1(2,0) <= Stoch1(2,1) && Stoch1(1,0) < 30 ? Ask() : 0

Long Initial SL Script

Low(1) - ATR1(1)

Long Trailing SL Script

Low(1) - (ATR1(1) * (Stoch1(1,0) < 50 ? 1 : 0.5))

Long TP Script

OBOS('Stoch1') == -1 ? Bid() : OrderPrice() + ATR1(1) * 3

Long BE Script

Stoch1(1,0) > 50 ? OrderPrice() : 0

Purpose

Trades Stochastic crossovers in oversold territory, with adaptive trade management based on oscillator position.

Component Breakdown

  • Entry Conditions
    • Stoch1(1,0) > Stoch1(1,1): %K crosses above %D
    • Stoch1(2,0) <= Stoch1(2,1): Confirms new cross
    • Stoch1(1,0) < 30: In oversold territory
  • Stop Loss Management
    • Initial: One ATR below recent low
    • Trailing: Adapts to Stochastic position
  • Profit Targets
    • Take Profit: Exit on overbought or 3 ATR
    • Breakeven: Stochastic above centerline

Key Points

  • Shows oscillator cross trading
  • Demonstrates adaptive trailing
  • Uses oscillator zones
  • Implements momentum-based exits

Note

Ensure Stochastic and ATR indicators are enabled in the Indicator’s List.

Example 9: ADX Trend Strength Strategy

Long Entry Script

ADX1(1,0) > 25 && ADX1(1,2) > ADX1(1,1) && Close(1) > Open(1) ? Ask() : 0

Long Initial SL Script

Low(1) - (ATR1(1) * (ADX1(1,0) > 40 ? 2 : 1))

Long Trailing SL Script

Low(1) - ATR1(1) * (ADX1(1,0)/50)

Long TP Script

OrderPrice() + (ATR1(1) * (ADX1(1,0)/20))

Long BE Script

High(1) > OrderPrice() + ATR1(1) ? OrderPrice() : 0

Purpose

Trades strong trends identified by ADX, with strength-adjusted trade management.

Component Breakdown

  • Entry Conditions
    • ADX1(1,0) > 25: Strong trend exists
    • ADX1(1,2) > ADX1(1,1): Rising trend strength
    • Close(1) > Open(1): Bullish price action
  • Stop Loss Management
    • Initial: ATR-based, wider for stronger trends
    • Trailing: Dynamic based on ADX strength
  • Profit Targets
    • Take Profit: Scales with trend strength
    • Breakeven: After one ATR move

Key Points

  • Shows trend strength trading
  • Demonstrates strength-based adjustments
  • Uses dynamic scaling
  • Implements adaptive targets

Note

Ensure ADX and ATR indicators are enabled in the Indicator’s List.

Example 10: MACD Divergence Strategy

Long Entry Script

MACD1(1,0) < MACD1(3,0) && Low(1) > Low(3) && MACD1(1,0) < 0 && Close(1) > Open(1) ? Ask() : 0

Long Initial SL Script

Low(LowestLow(5)) - ATR1(1)

Long Trailing SL Script

MACD1(1,0) > 0 ? Low(1) - ATR1(1) * 0.5 : Low(2) - ATR1(1)

Long TP Script

MACD1(1,0) > MACD1(2,0) ? OrderPrice() + ATR1(1) * 3 : OrderPrice() + ATR1(1) * 2

Long BE Script

MACD1(1,0) > 0 ? OrderPrice() : 0

Purpose

Trades bullish divergence between price and MACD, with momentum-based trade management.

Component Breakdown

  • Entry Conditions
    • MACD1(1,0) < MACD1(3,0): Lower MACD low
    • Low(1) > Low(3): Higher price low
    • MACD1(1,0) < 0: Below zero line
    • Close(1) > Open(1): Bullish confirmation
  • Stop Loss Management
    • Initial: Below recent swing low with buffer
    • Trailing: Tighter when MACD positive
  • Profit Targets
    • Take Profit: Adapts to MACD momentum
    • Breakeven: When MACD crosses above zero

Key Points

  • Shows divergence detection
  • Demonstrates momentum-based management
  • Uses multiple confirmations
  • Implements adaptive profit targets

Note

Ensure MACD and ATR indicators are enabled in the Indicator’s List. Consider adjusting the lookback period (3 bars) based on your timeframe.

Advanced Examples (Complete Strategies)

These examples present fully-formed trading strategies that demonstrate how to combine multiple components into comprehensive trading systems. Each example includes complete script sets with sophisticated entry conditions, dynamic trade management, and risk controls. They show how to integrate multiple timeframes, combine various indicators, and adapt to changing market conditions. While more complex than the Intermediate Examples, they maintain clear logic and documentation to serve as templates for both manual adaptation and AI-assisted customization. These strategies also demonstrate different trading approaches including trend-following, mean reversion, breakout trading, and pattern recognition, providing a broad foundation for developing your own advanced trading systems.

Example 1: Multi-Timeframe Trend Strategy (EURUSD M15)

UserVAR Definitions

VAR0=2;1,1.5,2,2.5,3 // SL ATR multiplier VAR1=4;2,3,4,5,6 // TP ATR multiplier

Indicator Creation Strings

NTL\MA(1,50,1).ex5,0,1,2 NTL\RSI(1,14,1,70,30).ex5,0,1 NTL\RSI(:H1,1,14,1,70,30).ex5,0,1 NTL\ATR(1,14).ex5,0

Long Entry Script

TimeOfDay(8,0,17,0) == 0 && Trend('MA1') == Bullish && Close(1) > MA1(1,0) && RSI1(1) > 50 && RSI2(1) > 50 ? Ask() : 0

Long Initial SL Script

MA1(1,0) - (ATR1(1) * VAR0)

Long Trailing SL Script

MA1(1,0) - (ATR1(1) * (RSI1(1) > 70 ? 0.5 : 1))

Long TP Script

OrderPrice() + (ATR1(1) * VAR1 * (RSI2(1) > 70 ? 1 : 2))

Long BE Script

RSI1(1) > 60 && RSI2(1) > 60 ? OrderPrice() : 0

Long Exit Script

TimeOfDay(17,0) == 1 || (RSI1(1) < 40 && RSI2(1) < 40) ? Bid() : 0

Purpose

A comprehensive trend-following strategy for EURUSD that aligns M15 and H1 timeframes with momentum confirmation and time-based filters, using adaptive trade management based on market conditions.

Component Breakdown

  • Entry Conditions
    • TimeOfDay(8,0,17,0) == 0: Trading window
    • Trend('MA1') == Bullish: Current timeframe trend
    • Close(1) > MA1(1,0): Price above MA
    • RSI1(1) > 50: M15 momentum
    • RSI2(1) > 50: H1 momentum
  • Trade Management
    • Initial Stop: Variable ATR-based using VAR0
    • Trailing Stop: Adapts to overbought conditions
    • Take Profit: Scales with H1 momentum
    • Breakeven: Requires momentum on both timeframes
  • Exit Rules
    • Time-based exit at 17:00
    • Momentum-based exit when both timeframes weak

Key Points

  • Shows multi-timeframe analysis
  • Uses UserVARs for optimization
  • Implements complete risk management
  • Trading window control

Note

All indicators must be enabled (’+’ prefix) in the preset file. Strategy performs best during major session overlaps.

Example 2: Price Action Reversal Strategy (GBPUSD M30)

UserVAR Definitions

VAR0=3;1.5,2,2.5,3,3.5,4 // TP extension multiplier

Indicator Creation Strings

NTL\ATR(1,14).ex5,0 NTL\PP(1).ex5,0,1,2,3,4,5 NTL\BB(1,20,2.0).ex5,0,1,2,3

Long Entry Script

High(PP1(1,2,0,0xFFFFF)+1) < High(1) && OBOS('BB1') == 1 && Close(1) > Open(1) ? Ask() : 0

Long Initial SL Script

Low(PP1(1,2,20,0xFFFFF)+1) - ATR1(1)

Long Trailing SL Script

Low(2) - ATR1(1) * (BB1(1,0) < BB1(2,0) ? 1.5 : 1)

Long TP Script

BB1(1,1) + ATR1(1) * VAR0

Long BE Script

High(1) > OrderPrice() + ATR1(1) * 2 ? OrderPrice() : 0

Long Exit Script

OBOS('BB1') == -1 || Close(1) < BB1(1,0) ? Bid() : 0

Purpose

Identifies potential reversals in GBPUSD using pivot points and Bollinger Band oversold conditions, with adaptive trade management based on volatility.

Component Breakdown

  • Entry Conditions
    • High(PP1(1,2,0,0xFFFFF)+1) < High(1): New high above pivot point
    • OBOS('BB1') == 1: Oversold condition
    • Close(1) > Open(1): Bullish confirmation
  • Trade Management
    • Initial Stop: Below referenced pivot low
    • Trailing Stop: Adapts to Bollinger Band direction
    • Take Profit: Upper band plus ATR multiple
    • Breakeven: After significant move in favor

Key Points

  • Best performance during London session
  • Shows proper pivot point analysis
  • Demonstrates complex buffer access
  • Uses oversold conditions for entry

Note

Strategy performs best during periods of high volatility but clear price structure. Most effective in the early London session when GBPUSD typically shows strong directional moves.

Example 3: Asian Session Range Strategy (USDJPY M30)

UserVAR Definitions

VAR0=0.5;0.3,0.4,0.5,0.6,0.7 // Range size filter (in ATR) VAR1=2;1.5,2,2.5,3 // Breakout target multiplier

Indicator Creation Strings

NTL\ATR(1,14).ex5,0 NTL\ABH(1,14,3).ex5,0,1 NTL\PP(1).ex5,0,1,2,3,4,5

Long Entry Script

TimeOfDay(4,0) && (High(1) - Low(1)) < ATR1(1) * VAR0 && Volume(1) > Volume(2) ? Ask() : 0

Long Initial SL Script

Low(1) - ATR1(1)

Long Trailing SL Script

Low(2) - ATR1(1) * (ABH1(1,0) > ABH1(2,0) ? 1.5 : 1)

Long TP Script

OrderPrice() + (ATR1(1) * VAR1)

Long BE Script

High(1) > OrderPrice() + ATR1(1) ? OrderPrice() : 0

Long Exit Script

TimeOfDay(8,0) || PP1(1,0) > 0 ? Bid() : 0

Purpose

Capitalizes on USDJPY’s characteristic early Asian session consolidation followed by breakout moves, using time filters and volatility measures.

Component Breakdown

  • Entry Conditions
    • TimeOfDay(4,0): Early Asian session
    • (High(1) - Low(1)) < ATR1(1) * VAR0: Compressed range
    • Volume(1) > Volume(2): Volume confirmation
  • Trade Management
    • Initial Stop: One ATR below entry bar
    • Trailing Stop: Adapts to bar height changes
    • Take Profit: Multiple of ATR
    • Breakeven: After one ATR move
  • Exit Rules
    • Time-based exit at Tokyo lunch (8:00)
    • Pivot point formation triggers exit

Key Points

  • Specifically designed for Asian session
  • Uses volatility compression signals
  • Implements session-based timing
  • Adapts to changing volatility conditions

Note

Strategy targets the characteristic USDJPY behavior during Asian hours. Most effective during Tuesday-Thursday Asian sessions when liquidity is optimal.

Example 4: London Breakout Strategy (EURGBP H1)

UserVAR Definitions

VAR0=2.5;1.5,2.0,2.5,3.0,3.5 // Range multiplier VAR1=1.5;1.0,1.5,2.0,2.5 // Risk-reward ratio

Indicator Creation Strings

NTL\ATR(1,14).ex5,0 NTL\BB(1,20,2.0).ex5,0,1,2,3 NTL\MA(1,50,1).ex5,0,1,2

Long Entry Script

TimeOfDay(7,0) && High(1) > HighestHigh(Range(6,0,"",D1)/Point) && Trend('MA1') == Bullish ? Ask() : 0

Long Initial SL Script

Low(1) - ATR1(1) * VAR0

Long Trailing SL Script

BB1(1,0) - ATR1(1)

Long TP Script

OrderPrice() + ((OrderPrice() - SL()) * VAR1)

Long BE Script

High(1) > OrderPrice() + ((OrderPrice() - SL()) * 0.5) ? OrderPrice() : 0

Long Exit Script

TimeOfDay(16,0) || (BB1(1,1) < BB1(2,1) && Close(1) < Open(1)) ? Bid() : 0

Purpose

Takes advantage of the typical London session breakout in EURGBP, entering on breaks of the Asian range with trend confirmation.

Component Breakdown

  • Entry Conditions
    • TimeOfDay(7,0): London session open
    • High(1) > HighestHigh(Range(6,0,"",D1)/Point): Breaks Asian range
    • Trend('MA1') == Bullish: Trend confirmation
  • Trade Management
    • Initial Stop: Multiple of ATR
    • Trailing Stop: Below Bollinger middle band
    • Take Profit: Based on risk-reward ratio
    • Breakeven: After 50% move to target
  • Exit Rules
    • Time-based exit before US close
    • Exit on band contraction with bearish price

Key Points

  • Captures London session volatility
  • Uses Asian range for reference
  • Implements trend-following concept
  • Dynamic position sizing via ATR

Note

Best results during Tuesday-Thursday when both London and European markets are fully active. Avoid trading on UK and European bank holidays.

Example 5: MACD Double-Zero Strategy (USDCAD H4)

UserVAR Definitions

VAR0=2;1.5,2,2.5,3 // Initial stop multiplier VAR1=0.5;0.3,0.4,0.5,0.6,0.7 // Trailing factor

Indicator Creation Strings

NTL\MACD(1,12,26,9).ex5,0,1,2,3,4 NTL\ATR(1,14).ex5,0 NTL\RSI(1,14,1,70,30).ex5,0,1

Long Entry Script

MACD1(1,0) > 0 && MACD1(2,0) <= 0 && RSI1(1) > 50 && Mid() < Round(Mid()) + 0.01 ? Ask() : 0

Long Initial SL Script

Low(1) - ATR1(1) * VAR0

Long Trailing SL Script

Low(1) - ATR1(1) * (MACD1(1,0) > MACD1(2,0) ? VAR1 : VAR1 * 2)

Long TP Script

Round(Mid()) + 0.01 + (ATR1(1) * 2)

Long BE Script

MACD1(1,0) > MACD1(1,1) * 2 ? OrderPrice() : 0

Long Exit Script

MACD1(1,0) < 0 || RSI1(1) > 70 ? Bid() : 0

Purpose

Takes advantage of USDCAD’s tendency to react around ‘double-zero’ levels (e.g., 1.3200, 1.3300), combining it with momentum confirmation.

Component Breakdown

  • Entry Conditions
    • MACD1(1,0) > 0 && MACD1(2,0) <= 0: MACD crosses zero
    • RSI1(1) > 50: Momentum confirmation
    • Mid() < Round(Mid()) + 0.01: Near round number
  • Trade Management
    • Initial Stop: ATR-based with multiplier
    • Trailing Stop: Adapts to MACD momentum
    • Take Profit: Next round number + 2 ATR
    • Breakeven: On strong MACD expansion
  • Exit Rules
    • MACD turns negative
    • RSI overbought condition

Key Points

  • Uses psychological price levels
  • Combines momentum with price structure
  • Implements dynamic trailing stops
  • Adapts to market volatility

Note

Strategy performs best during North American session when USDCAD typically shows clearest reactions to psychological levels. Avoid during Canadian economic news releases.

Example 6: Channel Breakout Strategy (AUDUSD H1)

UserVar Definitions

VAR0=15;10,15,20,25,30 // Channel lookback period VAR1=1.5;1.0,1.5,2.0,2.5 // Risk-reward ratio

Indicator Creation Strings

NTL\ATR(1,14).ex5,0 NTL\Keltner(1,20,1,2.25).ex5,0,1,2,3

Long Entry Script

High(1) > HighestHigh(VAR0) && Volume(1) > Volume(2) * 1.5 && High(1) > Keltner1(1,1) ? Ask() : 0

Long Initial SL Script

Keltner1(1,0) - ATR1(1)

Long Trailing SL Script

Keltner1(1,0) - (ATR1(1) * 0.5)

Long TP Script

OrderPrice() + ((OrderPrice() - SL()) * VAR1)

Long BE Script

High(1) > HighestHigh(VAR0) + ATR1(1) ? OrderPrice() : 0

Long Exit Script

Close(1) < Keltner1(1,0) || Low(1) < LowestLow(5) ? Bid() : 0

Purpose

Trades breakouts from established price channels in AUDUSD, using volume confirmation and Keltner Channels for validation and management.

Component Breakdown

  • Entry Conditions
    • High(1) > HighestHigh(VAR0): Breaks channel high
    • Volume(1) > Volume(2) * 1.5: Volume surge
    • High(1) > Keltner1(1,1): Above Keltner upper band
  • Trade Management
    • Initial Stop: Below Keltner middle band
    • Trailing Stop: Half ATR below middle band
    • Take Profit: Based on risk-reward ratio
    • Breakeven: After channel extension
  • Exit Rules
    • Price below Keltner middle band
    • Breaks recent swing low

Key Points

  • Adapts to market volatility
  • Uses volume for confirmation
  • Implements channel-based management
  • Dynamic position sizing

Note

Most effective during Asian-London crossover when AUDUSD often forms and breaks clear channels. Avoid during RBA announcements and significant Chinese economic data releases.

Example 7: Opening Range Breakout Strategy (EURJPY M15)

UserVAR Definitions

VAR0=2;1.5,2,2.5,3 // ATR multiplier for targets

Indicator Creation Strings

NTL\ATR(1,14).ex5,0 NTL\ABH(1,14,3).ex5,0,1

Long Entry Script

TimeOfDay(9,0) == -1 && High(1) > HighestHigh(4) && Volume(1) > Volume(2) ? Ask() : 0

Long Initial SL Script

LowestLow(4) - ATR1(1)

Long Trailing SL Script

Low(1) - (ABH1(1,0) * (High(1) > HighestHigh(3) ? 1 : 2))

Long TP Script

OrderPrice() + (ATR1(1) * VAR0)

Long BE Script

High(1) > OrderPrice() + ATR1(1) ? OrderPrice() : 0

Long Exit Script

TimeOfDay(16,0) == 1 || Low(1) < LowestLow(3) ? Bid() : 0

Purpose

Trades breakouts from the London session opening range in EURJPY, using adaptive targets based on volatility.

Component Breakdown

  • Entry Conditions
    • TimeOfDay(9,0) == -1: After the opening range hour
    • High(1) > HighestHigh(4): Breaks opening hour’s high
    • Volume(1) > Volume(2): Volume confirmation
  • Trade Management
    • Initial Stop: Below opening hour’s low with ATR buffer
    • Trailing Stop: Based on average bar height
    • Take Profit: Multiple of ATR
    • Breakeven: After one ATR move
  • Exit Rules
    • Time-based exit at 16:00
    • Break of recent lows

Key Points

  • Uses session-specific timing
  • Adapts to daily volatility
  • Dynamic range calculation
  • Volume-based confirmation

Note

Designed for London session volatility in EURJPY. Best results Tuesday-Thursday, avoid during major Japanese holidays or during BOJ/ECB announcements.

Example 8: Pattern Break Strategy (USDCHF M30)

UserVar Definitions

VAR0=3;2,3,4,5 // Minimum pattern strength VAR1=2;1.5,2,2.5,3 // Risk multiplier

Indicator Creation Strings

NTL\ATR(1,14).ex5,0 NTL\JCP(1).ex5,0,1 NTL\BB(1,20,2.0).ex5,0,1,2,3

Long Entry Script

Signal('JCP1') == Bullish && OBOS('BB1') == 1 && High(1) > High(2) ? Ask() : 0

Long Initial SL Script

Low(1) - (ATR1(1) * VAR1)

Long Trailing SL Script

Low(1) - (ATR1(1) * (BB1(1,0) < BB1(2,0) ? 2 : 1))

Long TP Script

BB1(1,1) + ATR1(1) * 2

Long BE Script

Close(1) > BB1(1,1) ? OrderPrice() : 0

Long Exit Script

Signal('JCP1') == Bearish || Close(1) < BB1(1,0) ? Bid() : 0

Purpose

Combines Japanese candlestick patterns with Bollinger Band oversold conditions in USDCHF, focusing on pattern-based reversals.

Component Breakdown

  • Entry Conditions
    • Signal('JCP1') == Bullish: Bullish candlestick pattern
    • OBOS('BB1') == 1: Oversold condition
    • High(1) > High(2): Pattern confirmation
  • Trade Management
    • Initial Stop: ATR-based with multiplier
    • Trailing Stop: Adapts to BB slope
    • Take Profit: Upper band plus 2 ATR
    • Breakeven: On upper band break
  • Exit Rules
    • Bearish pattern forms
    • Close below middle band

Key Points

  • Uses candle pattern recognition
  • Combines with band conditions
  • Dynamic stop adjustment
  • Multiple confirmation approach

Note

Most effective during European session when USDCHF typically shows clearest pattern formations. Avoid during SNB announcements and major Swiss economic releases.

Example 9: Triple Moving Average Strategy (GBPUSD H4)

UserVAR Definitions

VAR0=1.5;1.0,1.5,2.0,2.5 // ATR multiplier for stops VAR1=2.5;2.0,2.5,3.0,3.5 // Target multiplier

Indicator Creation Strings

NTL\MA(:H4,1,10,1,20,1).ex5,0,1,2 NTL\MA(:H4,1,50,1).ex5,0,1 NTL\BB(1,20,2.0).ex5,0,1,2,3 NTL\ATR(1,14).ex5,0

Long Entry Script

MA1(1,0) > MA1(1,1) && MA1(1,1) > MA2(1,0) && Close(1) > BB1(1,1) ? Ask() : 0

Long Initial SL Script

Low(1) - (ATR1(1) * VAR0)

Long Trailing SL Script

MA1(1,1) - (ATR1(1) * (MA1(1,0) > MA1(2,0) ? 0.5 : 1))

Long TP Script

OrderPrice() + (ATR1(1) * VAR1 * (BB1(1,1) > BB1(2,1) ? 1.5 : 1))

Long BE Script

High(1) > OrderPrice() + ATR1(1) ? OrderPrice() : 0

Long Exit Script

MA1(1,0) < MA1(1,1) || Close(1) < BB1(1,0) ? Bid() : 0

Purpose

Uses three moving averages in correct alignment with Bollinger Band confirmation for trend trading in GBPUSD.

Component Breakdown

  • Entry Conditions
    • MA1(1,0) > MA1(1,1): 10-period MA above 20-period MA
    • MA1(1,1) > MA2(1,0): 20-period MA above 50-period MA
    • Close(1) > BB1(1,1): Price above upper band
  • Trade Management
    • Initial Stop: ATR-based with multiplier
    • Trailing Stop: Uses 50-period MA with ATR adjustment
    • Take Profit: Dynamic based on band expansion
    • Breakeven: After one ATR move

Key Points

  • Uses triple MA alignment
  • Implements volatility-based exits
  • Dynamic trade management
  • Multiple confirmations required

Note

Strategy works best during trending phases of GBPUSD H4. Avoid during major UK/US news releases and during periods of low volatility.

Example 10: Trading Range Strategy (NZDUSD H4)

UserVAR Definitions

VAR0=0.5;0.3,0.4,0.5,0.6,0.7 // Range comparison factor VAR1=1.5;1.0,1.5,2.0,2.5 // Risk multiple for target

Indicator Creation Strings

NTL\ATR(1,14).ex5,0 NTL\BB(1,20,2.0).ex5,0,1,2,3 NTL\HLines(1,'',800,64,'S2;R2',2,0.3,0.5,100).ex5,0,1

Long Entry Script

(High(3) - Low(3)) < ATR1(1) * VAR0 && Signal('HLines1') == Bullish && OBOS('BB1') == 1 ? Ask() : 0

Long Initial SL Script

Low(3) - ATR1(1)

Long Trailing SL Script

BB1(1,0) - (ATR1(1) * 0.5)

Long TP Script

OrderPrice() + ((OrderPrice() - SL()) * VAR1)

Long BE Script

High(1) > OrderPrice() + ATR1(1) ? OrderPrice() : 0

Long Exit Script

OBOS('BB1') == -1 || Signal('HLines1') == Bearish ? Bid() : 0

Purpose

Trades contractions in price range near support levels, combining HLines support/resistance with Bollinger Band conditions.

Component Breakdown

  • Entry Conditions
    • (High(3) - Low(3)) < ATR1(1) * VAR0: Range contraction
    • Signal('HLines1') == Bullish: Support level signal
    • OBOS('BB1') == 1: Oversold condition
  • Trade Management
    • Initial Stop: Below range low with ATR buffer
    • Trailing Stop: Below middle band
    • Take Profit: Based on risk multiple
    • Breakeven: After one ATR move

Key Points

  • Uses range contraction for entry
  • Combines multiple indicators
  • Dynamic position sizing
  • Support/resistance confirmation

Note

Best suited for NZDUSD H4 during Asian/early London hours when price tends to respect ranges more clearly. Avoid during major NZ/US news releases.

Best Practices for Writing Scripts

When writing scripts in EAsiScript, following established coding practices will help you create more reliable and maintainable trading strategies. These best practices focus on proper syntax, correct use of variables and functions, and clear logical structure. By following these guidelines, you’ll avoid common coding errors and create scripts that are easier to test and modify.

Long Entry Script

TimeOfDay(8,0) && Trend('MA1') == Bullish && Close(1) > MA1(1,0) && RSI1(1) > 50 && RSI1(1,_Symbol,H1) > 50 ? Ask() : 0

Long Initial SL Script

MA1(1,0) - (ATR1(1) * VAR0)

Long Trailing SL Script

MA1(1,0) - (ATR1(1) * (RSI1(1) > 70 ? 0.5 : 1))

Long TP Script

OrderPrice() + (ATR1(1) * VAR1 * (RSI1(1,_Symbol,H1) > 70 ? 1 : 2))

Long BE Script

RSI1(1) > 60 && RSI1(1,_Symbol,H1) > 60 ? OrderPrice() : 0

Long Exit Script

TimeOfDay(17,0) || (RSI1(1) < 40 && RSI1(1,_Symbol,H1) < 40) ? Bid() : 0

Purpose

A comprehensive trend-following strategy that aligns multiple timeframes with momentum confirmation and time-based filters, using adaptive trade management based on market conditions.

Component Breakdown

  • Entry Conditions
    • TimeOfDay(8,0): Trades after market open
    • Trend('MA1') == Bullish: Current timeframe trend
    • Close(1) > MA1(1,0): Price above MA
    • RSI1(1) > 50: Current timeframe momentum
    • RSI1(1,_Symbol,H1) > 50: H1 timeframe momentum
  • Trade Management
    • Initial Stop: Variable ATR-based using VAR0
    • Trailing Stop: Adapts to overbought conditions
    • Take Profit: Scales with H1 momentum
    • Breakeven: Requires momentum on both timeframes
  • Exit Rules
    • Time-based exit at 17:00
    • Momentum-based exit when both timeframes weak

Key Points

  • Shows multi-timeframe analysis
  • Demonstrates time-based filters
  • Uses UserVars for optimization
  • Implements complete risk management

Note

Ensure MA and RSI indicators are enabled. Optimize VAR0 (stop distance) and VAR1 (profit target) for your instrument.

Example 1: Multi-Timeframe Trend Strategy

Indicator Creation Strings

NTL\MA(1,50,1).ex5,0,1,2
NTL\RSI(1,14,1,70,30).ex5,0,1
NTL\RSI(:H1,1,14,1,70,30).ex5,0,1
NTL\ATR(1,14).ex5,0

Long Entry Script

TimeOfDay(8,0) && Trend('MA1') == Bullish && Close(1) > MA1(1,0) && RSI1(1) > 50 && RSI2(1) > 50 ? Ask() : 0

Long Initial SL Script

MA1(1,0) - (ATR1(1) * VAR0)

Long Trailing SL Script

MA1(1,0) - (ATR1(1) * (RSI1(1) > 70 ? 0.5 : 1))

Long TP Script

OrderPrice() + (ATR1(1) * VAR1 * (RSI2(1) > 70 ? 1 : 2))

Long BE Script

RSI1(1) > 60 && RSI2(1) > 60 ? OrderPrice() : 0

Long Exit Script

TimeOfDay(17,0) || (RSI1(1) < 40 && RSI2(1) < 40) ? Bid() : 0

Purpose

A comprehensive trend-following strategy that aligns multiple timeframes with momentum confirmation and time-based filters, using adaptive trade management based on market conditions.

Component Breakdown

  • Entry Conditions
    • TimeOfDay(8,0): Trades after market open
    • Trend('MA1') == Bullish: Current timeframe trend
    • Close(1) > MA1(1,0): Price above MA
    • RSI1(1) > 50: Current timeframe momentum
    • RSI2(1) > 50: H1 timeframe momentum
  • Trade Management
    • Initial Stop: Variable ATR-based using VAR0
    • Trailing Stop: Adapts to overbought conditions
    • Take Profit: Scales with H1 momentum
    • Breakeven: Requires momentum on both timeframes
  • Exit Rules
    • Time-based exit at 17:00
    • Momentum-based exit when both timeframes weak

Key Points

  • Shows multi-timeframe analysis
  • Demonstrates time-based filters
  • Uses UserVars for optimization
  • Implements complete risk management

Note

All indicators must be enabled (’+’ prefix) in the preset file. UserVars VAR0 (stop distance) and VAR1 (profit target) should be optimized for your specific instrument.

Example 1: Long Entry with RSI Confirmation

This example shows how to combine trend with momentum for a more reliable entry strategy.

Long Entry Script

Trend('MA1') == Bullish && RSI1(1) > 50 && RSI1(2) < 50 ? Ask() : 0

Purpose

Opens a buy trade when price shows bullish trend structure and RSI crosses above the centerline (50), indicating aligned trend and momentum conditions.

Component Breakdown

  • Trend Filter: Trend('MA1') == Bullish
    • Confirms overall trend is bullish
    • Uses moving average trend detection
  • RSI Cross: RSI1(1) > 50 && RSI1(2) < 50
    • RSI1(1) > 50: Current RSI above centerline
    • RSI1(2) < 50: Previous RSI below centerline
    • Identifies momentum shift to bullish
  • Entry Price: Ask()
    • Returns current ask price if conditions are met
    • 0 if conditions are not met (no trade)

Key Points

  • Combines trend and momentum indicators
  • Shows proper RSI cross detection
  • Uses multiple bar references correctly
  • Demonstrates logical operator chaining

Note

Ensure both the MA and RSI indicators are enabled in the Indicator’s List before running this script. Consider adding volume or volatility filters for additional confirmation.

Example 2: Dynamic Stop Loss with Volatility Protection

This example demonstrates how to adjust stop loss placement based on both market volatility and price structure.

Long Initial SL Script

ATR1(1) > 20 ? Low(1) - ATR1(1) * 2 : Low(1) - ATR1(1)

Purpose

Sets a stop loss distance that adapts to market conditions, placing a wider stop when volatility is high and a tighter stop when volatility is lower, while using the previous bar’s low as a reference point.

Component Breakdown

  • Volatility Check: ATR1(1) > 20
    • Measures current market volatility
    • Compares ATR to threshold of 20 points
  • High Volatility Stop: Low(1) - ATR1(1) * 2
    • Uses 2 times ATR for wider stop
    • Provides more room in volatile conditions
  • Normal Volatility Stop: Low(1) - ATR1(1)
    • Uses 1 times ATR for normal conditions
    • Maintains tighter risk control

Key Points

  • Shows proper use of ternary operator for decision logic
  • Demonstrates dynamic adjustment based on market conditions
  • Combines price structure with volatility measure
  • Uses ATR for objective volatility measurement

Note

Ensure the ATR indicator is enabled in the Indicator’s List before running this script. Consider using dynamic ATR thresholds based on historical volatility patterns.

Example 2: Volatility-Adjusted Trading Strategy

This example demonstrates a complete trading strategy that adjusts all its parameters based on market volatility.

Long Entry Script

ATR1(1) > 20 && Close(1) > Open(1) ? Ask() : 0

Long Initial SL Script

ATR1(1) > 20 ? Low(1) - ATR1(1) * 2 : Low(1) - ATR1(1)

Long Trailing SL Script

ATR1(1) > 20 ? Low(1) - ATR1(1) * 1.5 : Low(1) - ATR1(1) * 0.75

Long TP Script

ATR1(1) > 20 ? OrderPrice() + ATR1(1) * 4 : OrderPrice() + ATR1(1) * 2

Long BE Script

ATR1(1) > 20 ? OrderPrice() + ATR1(1) : OrderPrice() + ATR1(1) * 0.5

Purpose

Creates a comprehensive trading strategy that adapts all its parameters to current market volatility conditions, providing wider settings in volatile markets and tighter settings in calmer conditions.

Component Breakdown

  • Entry Condition
    • ATR1(1) > 20: Identifies high volatility environment
    • Close(1) > Open(1): Confirms bullish price action
    • Uses market buy at Ask price
  • Initial Stop Loss
    • High volatility: 2 × ATR below last low
    • Normal volatility: 1 × ATR below last low
    • Provides volatility-adjusted downside protection
  • Trailing Stop
    • High volatility: 1.5 × ATR below last low
    • Normal volatility: 0.75 × ATR below last low
    • Tighter than initial stop for better profit protection
  • Take Profit
    • High volatility: 4 × ATR above entry
    • Normal volatility: 2 × ATR above entry
    • Larger targets when volatility supports bigger moves
  • Breakeven
    • High volatility: 1 × ATR above entry
    • Normal volatility: 0.5 × ATR above entry
    • Earlier breakeven in normal conditions

Key Points

  • Shows complete trade management lifecycle
  • Demonstrates coordinated parameter adjustment
  • Uses ATR for objective volatility measurement
  • Maintains consistent risk-reward relationships

Note

Ensure the ATR indicator is enabled in the Indicator’s List before running this script. The ATR threshold of 20 should be adjusted based on your specific instrument’s characteristics.


Example 3: Short Entry with MACD Confirmation

Short Entry Script

MACD1(1) < 0 && BarTrend(1) == Bearish ? Bid() : 0

Purpose

This script enters a sell trade when the MACD indicates bearish momentum and the last bar is bearish.

Explanation

  • Condition 1: MACD1(1) < 0 confirms bearish momentum.
  • Condition 2: BarTrend(1) == Bearish ensures the last bar is bearish.
  • Action: Executes a sell trade at the current Bid price if both conditions are true.

Example 4: Dynamic Take Profit Using Moving Average

Long TP Script

MA1(1) + 10 * Point

Purpose

This script sets a take profit level dynamically based on the moving average (MA).

Explanation

  • Calculation: Adds 10 points to the current moving average value (MA1(1)) to define the take profit level.

Example 5: Trend Confirmation for Long Entry

Long Entry Script

Trend('MA1') == Bullish ? Ask() : 0

Purpose

This script enters a buy trade when a moving average confirms an upward trend.

Explanation

  • Condition: Trend('MA1') == Bullish ensures the trend is upward.
  • Action: Executes a buy trade at the current Ask price if the trend is bullish.

Advanced Examples

Example 1: Momentum-Based Trading

Long Entry Script

RSI1(1) < 30 && BarTrend(1) == Bullish ? Ask() : 0

Long Initial SL Script

Low(1) - ATR1(1) * 2

Long TP Script

OrderPrice() + ATR1(1) * 3

Long Exit Script

RSI1(1) > 70 || BarTrend(1) == Bearish ? Bid() : 0

Note

Ensure the RSI and ATR indicators are enabled in the Indicator’s List before running the script.

Purpose

This strategy enters a long trade when the RSI indicates oversold conditions and the bar trend is bullish. It uses dynamic ATR-based stop loss and take profit levels, exiting the trade when RSI is overbought or the bar trend turns bearish.

Explanation

  • Long Entry Script: Combines RSI1(1) < 30 to detect oversold conditions with BarTrend(1) == Bullish to ensure a bullish bar trend. Places the trade at the current Ask price.
  • Long Initial SL Script: Uses Low(1) minus twice the ATR value (ATR1(1)) to define a dynamic stop loss that adapts to market volatility.
  • Long TP Script: Sets a take profit level at OrderPrice() + ATR1(1) * 3, giving a reward target three times the market volatility.
  • Long Exit Script: Exits the trade if RSI1(1) > 70 indicates overbought conditions or BarTrend(1) == Bearish signals a reversal.

Example 2: Trend Following Strategy

Long Entry Script

Trend('MA1') == Bullish && BarTrend(1) == Bullish ? Ask() : 0

Long Initial SL Script

Low(1) - 15 * Point

Long TP Script

High(1) + 20 * Point

Long Exit Script

Trend('MA1') == Bearish ? Bid() : 0

Note

Ensure the Moving Averages (MA1) indicator is enabled in the Indicator’s List before running the script.

Purpose

This strategy enters a long trade when the moving average trend and bar trend are both bullish. It uses fixed stop loss and take profit levels and exits the trade when the moving average indicates a bearish trend.

Explanation

  • Long Entry Script: Combines Trend('MA1') == Bullish for confirming a bullish moving average trend with BarTrend(1) == Bullish for verifying a bullish bar. Executes the trade at the Ask price.
  • Long Initial SL Script: Sets a fixed stop loss at Low(1) - 15 * Point, providing a safety buffer below the last bar’s low.
  • Long TP Script: Sets a fixed take profit at High(1) + 20 * Point, giving a predefined profit target above the last bar’s high.
  • Long Exit Script: Closes the trade if Trend('MA1') == Bearish, indicating a shift to a bearish moving average trend.

Example 3: Volatility Breakout Strategy

Long Entry Script

High(1) > BB1(1, 1) ? Ask() : 0

Long Initial SL Script

Low(1) - ATR1(1)

Long TP Script

OrderPrice() + ATR1(1) * 2

Long Exit Script

BarTrend(1) == Bearish || High(1) < BB1(1, 1) ? Bid() : 0

Note

Ensure the Bollinger Bands (BB1) and ATR indicators are enabled in the Indicator’s List before running the script.

Purpose

This strategy enters a long trade when the price breaks above the Bollinger Band upper line, indicating a bullish breakout. It sets a dynamic stop loss and take profit based on ATR, exiting when the bar trend turns bearish or the price returns below the upper Bollinger Band.

Explanation

  • Long Entry Script: Uses High(1) > BB1(1, 1) to detect a price breakout above the Bollinger Band upper line and enters a buy trade at the Ask price.
  • Long Initial SL Script: Sets a stop loss dynamically at Low(1) - ATR1(1), using the last bar’s low and ATR for volatility adjustment.
  • Long TP Script: Sets a take profit at OrderPrice() + ATR1(1) * 2, targeting a reward twice the market volatility.
  • Long Exit Script: Closes the trade if the bar trend becomes bearish (BarTrend(1) == Bearish) or if the price falls below the upper Bollinger Band (High(1) < BB1(1, 1)).

Example 4: Mean Reversion Strategy

Short Entry Script

RSI1(1) > 70 && BarTrend(1) == Bearish ? Bid() : 0

Short Initial SL Script

High(1) + ATR1(1)

Short TP Script

OrderPrice() - ATR1(1) * 2

Short Exit Script

RSI1(1) < 30 || BarTrend(1) == Bullish ? Ask() : 0

Note

Ensure the RSI and ATR indicators are enabled in the Indicator’s List before running the script.

Purpose

This strategy enters a short trade when the RSI indicates overbought conditions and the bar trend is bearish. It uses ATR-based stop loss and take profit levels and exits when the RSI indicates oversold conditions or the bar trend turns bullish.

Explanation

  • Short Entry Script: Combines RSI1(1) > 70 to detect overbought conditions with BarTrend(1) == Bearish to confirm a bearish trend. Executes a sell trade at the current Bid price.
  • Short Initial SL Script: Places a stop loss dynamically at High(1) + ATR1(1), adjusting for volatility above the last bar’s high.
  • Short TP Script: Sets a take profit level at OrderPrice() - ATR1(1) * 2, targeting a reward twice the market volatility.
  • Short Exit Script: Closes the trade if RSI1(1) < 30 signals oversold conditions or BarTrend(1) == Bullish indicates a bullish trend reversal.

Example 5: Dual Moving Average Crossover

Long Entry Script

MA1(1) > MA2(1) && MA1(2) <= MA2(2) ? Ask() : 0

Long Initial SL Script

Low(1) - ATR1(1)

Long TP Script

OrderPrice() + ATR1(1) * 2

Long Exit Script

MA1(1) < MA2(1) ? Bid() : 0

Note

Ensure the Moving Averages (MA1 and MA2) and ATR indicators are enabled in the Indicator’s List before running the script.

Purpose

This strategy enters a long trade when a short moving average crosses above a long moving average. It uses ATR-based stop loss and take profit levels and exits the trade when the short moving average crosses back below the long moving average.

Explanation

  • Long Entry Script: Combines MA1(1) > MA2(1) to confirm the short moving average is above the long moving average and MA1(2) <= MA2(2) to verify the crossover occurred. Executes a buy trade at the Ask price.
  • Long Initial SL Script: Dynamically sets a stop loss at Low(1) - ATR1(1), adjusting for market volatility.
  • Long TP Script: Defines a take profit level at OrderPrice() + ATR1(1) * 2, targeting a reward twice the ATR value.
  • Long Exit Script: Closes the trade when MA1(1) < MA2(1), indicating a bearish crossover of the moving averages.

Example 6: Range Breakout Strategy (USDJPY M30)

Long Entry Script

TimeOfDay(4,30) && ((HighestHigh(3) - LowestLow(3)) >= Ask() * 0.002) && ((HighestHigh(3) - LowestLow(3)) <= Ask() * 0.004) ? HighestHigh(3) : 0

Long Initial SL Script

HighestHigh(3) - (HighestHigh(3) - LowestLow(3)) * 0.5

Long TP Script

OrderPrice() + (HighestHigh(3) - LowestLow(3)) * 1.5

Long Exit Script

TimeOfDay(18,0) && (IsOpen() || IsPending()) ? Bid() : 0

Short Entry Script

TimeOfDay(4,30) && ((HighestHigh(3) - LowestLow(3)) >= Ask() * 0.002) && ((HighestHigh(3) - LowestLow(3)) <= Ask() * 0.004) ? LowestLow(3) : 0

Short Initial SL Script

LowestLow(3) + (HighestHigh(3) - LowestLow(3)) * 0.5

Short TP Script

OrderPrice() - (HighestHigh(3) - LowestLow(3)) * 1.5

Short Exit Script

TimeOfDay(18,0) && (IsOpen() || IsPending()) ? Ask() : 0

Purpose

This strategy identifies breakout opportunities during a predefined time window and dynamically adjusts its stop loss and take profit levels based on the range of the past three bars. Trades are closed at the end of the trading window or if the trade status is open or pending beyond the allowable timeframe.

Explanation

  • Long Entry Script: Evaluates the time window using TimeOfDay(4,30) and checks if the range (HighestHigh(3) - LowestLow(3)) of the past three bars is within a valid range proportional to the Ask price. Places a buy trade at HighestHigh(3) if conditions are met.
  • Long Initial SL Script: Dynamically sets a stop loss at 50% of the range below HighestHigh(3).
  • Long TP Script: Targets a profit level 1.5 times the range above the entry price.
  • Long Exit Script: Closes trades at TimeOfDay(18,0) if the trade is still active, either open or pending.
  • Short Entry Script: Mirrors the long entry conditions but identifies sell opportunities, placing a trade at LowestLow(3) if conditions are met.
  • Short Initial SL Script: Sets a stop loss at 50% of the range above LowestLow(3).
  • Short TP Script: Targets a profit level 1.5 times the range below the entry price.
  • Short Exit Script: Closes trades at TimeOfDay(18,0) if the trade is still active, either open or pending.

Example 7: Fibonacci Retracement Strategy

Long Entry Script

TimeOfDay(9,0) && Close(1) > FibRetrace(LowestLow(10), HighestHigh(10), 0.618) ? Ask() : 0

Long Initial SL Script

FibRetrace(LowestLow(10), HighestHigh(10), 0.5)

Long TP Script

FibRetrace(LowestLow(10), HighestHigh(10), 1.0)

Long Exit Script

TimeOfDay(17,0) || Close(1) < FibRetrace(LowestLow(10), HighestHigh(10), 0.618) ? Bid() : 0

Short Entry Script

TimeOfDay(9,0) && Close(1) < FibRetrace(LowestLow(10), HighestHigh(10), 0.618) ? Bid() : 0

Short Initial SL Script

FibRetrace(LowestLow(10), HighestHigh(10), 0.5)

Short TP Script

FibRetrace(LowestLow(10), HighestHigh(10), 0.0)

Short Exit Script

TimeOfDay(17,0) || Close(1) > FibRetrace(LowestLow(10), HighestHigh(10), 0.618) ? Ask() : 0

Note

Ensure the Fibonacci Retracement tool is configured to calculate retracement levels based on the high and low of the last 10 bars.

Purpose

This strategy utilizes Fibonacci retracement levels to identify potential reversal points in the market. Trades are initiated near the 61.8% retracement level, with stop loss and take profit targets set at other key Fibonacci levels. Trades are exited at the end of the trading day or when the retracement level fails.

Explanation

  • Long Entry Script: Opens a long position if the current closing price (Close(1)) exceeds the 61.8% Fibonacci retracement level (FibRetrace(LowestLow(10), HighestHigh(10), 0.618)) of the last 10 bars, ensuring the trade occurs within the specified timeframe (TimeOfDay(9,0)).
  • Long Initial SL Script: Sets a stop loss at the 50% Fibonacci retracement level, providing a balance between risk and reward.
  • Long TP Script: Targets the 100% Fibonacci extension level as the take profit, maximizing potential gains.
  • Long Exit Script: Closes the trade at TimeOfDay(17,0) or if the price falls back below the 61.8% retracement level.
  • Short Entry Script: Opens a short position if the closing price falls below the 61.8% retracement level during the specified timeframe (TimeOfDay(9,0)).
  • Short Initial SL Script: Sets a stop loss at the 50% retracement level, limiting potential losses.
  • Short TP Script: Targets the 0% retracement level as the take profit, corresponding to the previous low.
  • Short Exit Script: Closes the trade at TimeOfDay(17,0) or if the price rises back above the 61.8% retracement level.

Example 8: Moving Average and Volume Confirmation Strategy

Long Entry Script

MA1(1, 1) > MA1(1, 2) && Volume(1) > 1000 ? Ask() : 0

Long Initial SL Script

Low(1) - ATR1(1)

Long TP Script

OrderPrice() + ATR1(1) * 2

Long Exit Script

MA1(1, 1) < MA1(1, 2) || Volume(1) < 800 ? Bid() : 0

Short Entry Script

MA1(1, 1) < MA1(1, 2) && Volume(1) > 1000 ? Bid() : 0

Short Initial SL Script

High(1) + ATR1(1)

Short TP Script

OrderPrice() - ATR1(1) * 2

Short Exit Script

MA1(1, 1) > MA1(1, 2) || Volume(1) < 800 ? Ask() : 0

Indicator Creation String

NTL\MA(:M30,1,10,2,50,0).ex5

Note

The MA indicator is configured with the following parameters:

  • Timeframe: M30
  • Short Moving Average: 10-period Exponential Moving Average (EMA) (method = 2)
  • Long Moving Average: 50-period Simple Moving Average (SMA) (method = 0)
    Ensure the Moving Average (MA1) and ATR indicators are enabled in the Indicator’s List before running the script.

Purpose

This strategy uses a single MA1 indicator to handle two moving averages (short and long) along with volume checks to confirm trend direction and market activity. It enters trades when the conditions align and exits when the trend reverses or volume drops below a threshold.

Explanation

  • Long Entry Script: Confirms a bullish trend by checking if the short moving average (MA1(1, 1)) is above the long moving average (MA1(1, 2)) and ensures strong market activity with Volume(1) > 1000. Places a buy trade at the Ask price.
  • Long Initial SL Script: Sets a stop loss dynamically at Low(1) - ATR1(1), providing a volatility-based safety net.
  • Long TP Script: Defines the take profit level at OrderPrice() + ATR1(1) * 2, targeting a reward twice the market volatility.
  • Long Exit Script: Closes the trade if the trend reverses (MA1(1, 1) < MA1(1, 2)) or if market activity weakens (Volume(1) < 800).
  • Short Entry Script: Confirms a bearish trend by checking if the short moving average (MA1(1, 1)) is below the long moving average (MA1(1, 2)) and ensures strong market activity with Volume(1) > 1000. Places a sell trade at the Bid price.
  • Short Initial SL Script: Sets a stop loss dynamically at High(1) + ATR1(1), based on the recent high and volatility.
  • Short TP Script: Defines the take profit level at OrderPrice() - ATR1(1) * 2, aiming for a reward twice the market volatility.
  • Short Exit Script: Closes the trade if the trend reverses (MA1(1, 1) > MA1(1, 2)) or if market activity weakens (Volume(1) < 800).

Example 9: Daily High-Low Breakout Strategy

Long Entry Script

TimeOfDay(9,0) && Ask() > High(1, "", D1) ? Ask() : 0

Long Initial SL Script

High(1, "", D1) - 20 * Point

Long TP Script

High(1, "", D1) + (High(1, "", D1) - Low(1, "", D1)) * 1.5

Long Exit Script

TimeOfDay(16,0) || Ask() < High(1, "", D1) ? Bid() : 0

Short Entry Script

TimeOfDay(9,0) && Bid() < Low(1, "", D1) ? Bid() : 0

Short Initial SL Script

Low(1, "", D1) + 20 * Point

Short TP Script

Low(1, "", D1) - (High(1, "", D1) - Low(1, "", D1)) * 1.5

Short Exit Script

TimeOfDay(16,0) || Bid() > Low(1, "", D1) ? Ask() : 0

Note

This strategy uses the High() and Low() functions with the D1 timeframe to calculate the daily high and low prices dynamically. No additional indicators are required.

Purpose

This strategy identifies breakout opportunities based on the daily high and low prices. It dynamically calculates stop loss and take profit levels relative to the day’s range and exits trades if the breakout fails or the trading session ends.

Explanation

  • Long Entry Script: Enters a long trade if the Ask price exceeds the daily high (High(1, "", D1)) and the time is after 09:00. Places the trade at the current Ask price.
  • Long Initial SL Script: Sets a fixed stop loss 20 points below the daily high.
  • Long TP Script: Targets a profit level 1.5 times the daily range (High(1, "", D1) - Low(1, "", D1)) above the daily high.
  • Long Exit Script: Closes the trade at 16:00 or if the Ask price drops below the daily high (High(1, "", D1)).
  • Short Entry Script: Enters a short trade if the Bid price falls below the daily low (Low(1, "", D1)) and the time is after 09:00. Places the trade at the current Bid price.
  • Short Initial SL Script: Sets a fixed stop loss 20 points above the daily low.
  • Short TP Script: Targets a profit level 1.5 times the daily range below the daily low.
  • Short Exit Script: Closes the trade at 16:00 or if the Bid price rises above the daily low (Low(1, "", D1)).

Example 10: Time-Based Volume Spike Strategy

Long Entry Script

TimeOfDay(10,0) && Volume(1) > Volume(2) * 2 ? Ask() : 0

Long Initial SL Script

Low(1) - 15 * Point

Long TP Script

OrderPrice() + 30 * Point

Long Exit Script

Volume(1) < Volume(2) ? Bid() : 0

Short Entry Script

TimeOfDay(10,0) && Volume(1) > Volume(2) * 2 ? Bid() : 0

Short Initial SL Script

High(1) + 15 * Point

Short TP Script

OrderPrice() - 30 * Point

Short Exit Script

Volume(1) < Volume(2) ? Ask() : 0

Note

This strategy relies on the Volume() function to identify sudden spikes in market activity compared to the previous bar. No additional indicators are required.

Purpose

This strategy identifies potential trading opportunities based on significant volume spikes, indicating heightened market activity. It uses fixed stop loss and take profit levels and exits trades when volume normalizes.

Explanation

  • Long Entry Script: Enters a long trade at 10:00 if the volume of the current bar (Volume(1)) is more than double the volume of the previous bar (Volume(2)). Places the trade at the current Ask price.
  • Long Initial SL Script: Sets a fixed stop loss 15 points below the low of the last bar.
  • Long TP Script: Targets a fixed take profit 30 points above the entry price.
  • Long Exit Script: Closes the trade if the volume of the current bar (Volume(1)) falls below the volume of the previous bar (Volume(2)).
  • Short Entry Script: Enters a short trade at 10:00 if the volume of the current bar (Volume(1)) is more than double the volume of the previous bar (Volume(2)). Places the trade at the current Bid price.
  • Short Initial SL Script: Sets a fixed stop loss 15 points above the high of the last bar.
  • Short TP Script: Targets a fixed take profit 30 points below the entry price.
  • Short Exit Script: Closes the trade if the volume of the current bar (Volume(1)) falls below the volume of the previous bar (Volume(2)).

Example 11: SuperTrend and RSI-Based Strategy

Long Entry Script

Signal('ST1') == Bullish && RSI1(1) > 50 ? Ask() : 0

Long Initial SL Script

Low(1) - ATR1(1)

Long TP Script

OrderPrice() + ATR1(1) * 3

Long Exit Script

Signal('ST1') == Bearish || RSI1(1) < 50 ? Bid() : 0

Short Entry Script

Signal('ST1') == Bearish && RSI1(1) < 50 ? Bid() : 0

Short Initial SL Script

High(1) + ATR1(1)

Short TP Script

OrderPrice() - ATR1(1) * 3

Short Exit Script

Signal('ST1') == Bullish || RSI1(1) > 50 ? Ask() : 0

Note

Ensure the SuperTrend (ST1), ATR, and RSI indicators are enabled in the Indicator’s List before running the script.

Purpose

This strategy combines the SuperTrend (ST1) indicator to determine trend direction with the RSI indicator to confirm the strength of the trend. Trades are entered when both indicators align, and trades are exited on a reversal or weakening RSI signal.

Explanation

  • Long Entry Script: Enters a long trade if the SuperTrend signal (Signal('ST1')) indicates a bullish trend and the RSI indicator (RSI1(1)) shows a value greater than 50, confirming upward momentum. Places the trade at the Ask price.
  • Long Initial SL Script: Sets a stop loss dynamically at Low(1) - ATR1(1), adjusted for market volatility.
  • Long TP Script: Targets a take profit level at OrderPrice() + ATR1(1) * 3, aiming for a reward three times the ATR value.
  • Long Exit Script: Closes the trade if the SuperTrend signal (Signal('ST1')) turns bearish or if RSI weakens (RSI1(1) < 50).
  • Short Entry Script: Enters a short trade if the SuperTrend signal (Signal('ST1')) indicates a bearish trend and the RSI indicator (RSI1(1)) shows a value less than 50, confirming downward momentum. Places the trade at the Bid price.
  • Short Initial SL Script: Sets a stop loss dynamically at High(1) + ATR1(1), adjusted for market volatility.
  • Short TP Script: Targets a take profit level at OrderPrice() - ATR1(1) * 3, aiming for a reward three times the ATR value.
  • Short Exit Script: Closes the trade if the SuperTrend signal (Signal('ST1')) turns bullish or if RSI strengthens (RSI1(1) > 50).

Best Practices for Writing Scripts

Follow these best practices to ensure your scripts are clear, consistent, and effective:

  1. Use Provided Variables:
  • Replace raw values like 1 or -1 with the predefined variables Bullish and Bearish:

    • Bullish = 1: Indicates a buy signal or bullish trend.
    • Bearish = -1: Indicates a sell signal or bearish trend.

    Example: Signal('MA1') == Bullish ? Ask() : 0

  1. Leverage the Point Variable for Scaling:

    • Always multiply numeric adjustments by Point to ensure they are scaled correctly according to the symbol’s price units.

    Example: ATR1(1) > 15 ? Low(1) - 20 * Point : Low(1) - 10 * Point

  2. Explicitly Define Shifts for Functions:

    • Functions like Close, Open, High, and Low require a shift parameter. The default is 1, but specifying it explicitly improves clarity.

    Example: Close(1) > Open(1) ? Ask() : 0

  3. Avoid Invalid Functions:

    • Use valid functions like SL() instead of invalid ones like StopLoss().
    • Valid Functions: Ask(), Bid(), SL(), Signal(), Trend().
    • Invalid Examples: StopLoss(), Price().
  4. Combine Indicators and Price Data:

    • Create powerful scripts by combining indicator signals with price conditions.

    Example: Trend('MA1') == Bullish && Close(1) > Open(1) ? Ask() : 0

Tips for Writing Scripts

Before diving into script writing, it’s helpful to understand some practical approaches that can make your development process smoother and more effective. While the Best Practices section covers the technical aspects of writing scripts, these tips focus on the development process itself, common pitfalls to avoid, and strategies for testing and implementing your trading logic. Whether you’re writing your first script or developing complex strategies, these guidelines will help you build more reliable and maintainable trading systems.

  1. Test Individual Components First
  • Write and test entry conditions separately before combining
  • Verify indicator signals independently
  • Test time filters alone before adding to strategies
  1. Common Mistakes to Avoid
  • Don’t forget to enable indicators in the Indicators List
  • Remember shift=1 means last completed bar, not current bar
  • Check you’re using Ask() for buys and Bid() for sells
  1. Debugging Tips
  • Use single conditions first, then build up with AND (&&)
  • Test time windows with simple entry conditions
  • Verify indicator buffer numbers match your settings
  1. Development Process
  • Start with entry logic
  • Add initial stop loss
  • Test basic exits
  • Add trailing stops and breakeven last
  • Fine-tune with take profit levels
  1. Risk Management
  • Always test stop loss logic independently
  • Verify SL is appropriate distance from entry
  • Test breakeven conditions thoroughly
  1. Performance Tips
  • Keep conditions as simple as needed
  • Use appropriate timeframes for indicators
  • Consider market hours for your strategy

Use AI to Create an EAsiScript Preset File

EAsiScript enables you to leverage artificial intelligence for creating preset files and developing trading strategies. By providing AI with your strategy requirements and the EAsiTrader documentation, you can generate compliant preset files that are ready for testing and optimization. This approach combines the efficiency of AI with your trading expertise, allowing you to rapidly develop and refine strategies while maintaining full control over their implementation and risk management.

The key to successful AI-assisted development is providing clear strategy requirements and ensuring the AI has access to all necessary documentation. This section will guide you through the process of preparing your requirements, working with AI to generate preset files, and properly testing the resulting strategies.

1. Prepare Your Strategy Details

Before engaging with AI, clearly define the specifics of your trading strategy:

  • Entry and Exit Rules: Conditions for opening and closing trades
  • Risk Management: Stop loss, take profit, breakeven levels, or trailing stops
  • Indicators: Specify indicators like RSI, Moving Averages, or ATR
  • Special Conditions: Add any time-based filters, multi-symbol requirements, or other specific needs

2. Upload the User Guides to AI

Provide AI with the foundational documentation:

  • EAsiTrader User Guide: Core functionality and settings
  • EAsiScript User Guide: Scripting language and functions
  • Learn EAsiScript Guide: Examples and best practices

These guides contain all the information AI needs to generate accurate scripts and ensure compliance with EAsiTrader’s requirements.

3. Ask AI to Create Your Preset

Provide your strategy requirements in a clear, structured format:

  • Specify it must comply with “Rules for Creating Main Preset Files”
  • Use Defaults.set as template
  • Request verification against the template
  • Include specific symbols and timeframes
  • Detail any optimization requirements

4. Save the Generated Content

  • Copy AI-generated output to a plain text editor
  • Save with a descriptive name and .set extension (e.g., TrendFollowing.set)
  • Verify proper formatting and section structure

5. Copy the Preset File to the EAsiTrader Folder

  • Locate your MetaTrader data folder path:
    • MQL5\Files\EAsiTrader
  • Place the .set file in this directory
  • The preset will appear in EAsiTrader’s Profile Dropdown

6. Load the Preset

  • Open EAsiTrader in MetaTrader 5
  • Select your new preset from the Profile Dropdown
  • Verify all settings loaded correctly
  • Verify required indicators are enabled

7. Test the Preset

  • Use EAsiTrader’s Tester feature
  • Start with visual backtesting
  • Verify entry/exit logic
  • Check risk management behavior
  • Test in different market conditions

8. Activate for Live Trading

  • Complete thorough testing first
  • Enable Auto Trading in EAsiTrader
  • Monitor initial trades closely
  • Keep detailed performance records

9. Iterate and Optimise

  • Review strategy performance
  • Identify areas for improvement
  • Generate new variations using AI
  • Optimise parameters using Tester

AI Prompt Examples

These examples demonstrate effective AI prompts for generating EAsiTrader preset files and trading strategies. Each example includes the exact text you should give to the AI, formatted with specific requirements and the mandatory preset file compliance instructions.

CRITICAL: INCLUDE THESE INSTRUCTIONS WITH EVERY PROMPT

When providing any of these example prompts to AI, you MUST include these exact instructions as part of your prompt:

“The preset file must strictly comply with all the ‘Rules for
Creating EAsiTrader Preset Files’. Use the Defaults.set Preset File as
a template. Verify your content by cross referencing your sections and
settings with those from the template. Any deviation or omission
will be considered a failure to complete the task
.”

⚠️ WARNING: Omitting these instructions from your prompt will likely result in invalid preset files that will not work correctly in EAsiTrader. Remember that the AI cannot see or access these instructions unless you explicitly include them in your prompt.

Each example below shows a complete prompt that you can copy and use directly with AI. Pay attention to how the required instructions are integrated with the strategy specifications in each prompt.

Example 1: Basic Strategy

Copy this complete prompt:

"Create an EAsiScript preset file for a strategy based on RSI levels.

The preset file must strictly comply with all the ‘Rules for
Creating EAsiTrader Preset Files’. Use the Defaults.set Preset File as
a template. Verify your content by cross referencing your sections and
settings with those from the template. Any deviation or omission
will be considered a failure to complete the task
.

Strategy Details

  • Entry: Go long when RSI crosses above 30, go short when RSI crosses below 70
  • Stop Loss: 2 times ATR below/above entry price for long/short trades
  • Take Profit: Fixed at 50 points for all trades
  • Exit: Close trade if the opposite RSI condition occurs
  • Execution: Runs on EURUSD on the M30 timeframe"

Example 2: Trend-Following Strategy

Copy this complete prompt:

"Please create an EAsiScript Preset File for a strategy using multiple
moving averages.

The preset file must strictly comply with all the ‘Rules for
Creating EAsiTrader Preset Files’. Use the Defaults.set Preset File as
a template. Verify your content by cross referencing your sections and
settings with those from the template. Any deviation or omission
will be considered a failure to complete the task
.

Strategy Details

  • Entry: Enter when fast MA crosses above slow MA with RSI confirmation
  • Stop Loss: Set below recent swing low with ATR buffer
  • Take Profit: Use ATR to calculate 3:1 reward:risk ratio
  • Exit: Exit if MA cross reverses or RSI conditions change
  • Execution: GBPUSD, H1 timeframe"

Example 3: Complex Multi-Timeframe Strategy

Copy this complete prompt:

"Generate an EAsiScript Preset File for a complete trading system.

The preset file must strictly comply with all the ‘Rules for
Creating EAsiTrader Preset Files’. Use the Defaults.set Preset File as
a template. Verify your content by cross referencing your sections and
settings with those from the template. Any deviation or omission
will be considered a failure to complete the task
.

Strategy Details

  • Markets: EURUSD, Primary M15, Secondary H1
  • Entry Conditions:
    • H1 trend alignment (using MA)
    • M15 momentum confirmation (using RSI)
    • Volume confirmation
  • Risk Management:
    • Dynamic ATR-based stops
    • Trailing stop after breakeven
    • Multiple take profit targets
  • Time Filters: Active during London/NY overlap
  • Position Sizing: Risk 1% per trade"

Example 4: Breakout Strategy

Copy this complete prompt:

"Generate an EAsiScript Preset File for a Bollinger Band breakout
strategy.

The preset file must strictly comply with all the ‘Rules for
Creating EAsiTrader Preset Files’. Use the Defaults.set Preset File as
a template. Verify your content by cross referencing your sections and
settings with those from the template. Any deviation or omission
will be considered a failure to complete the task
.

Strategy Details

  • Entry: Go long if price breaks above upper band with volume surge
  • Stop Loss: Use trailing stop based on 2 ATR
  • Take Profit: Use 5% of account equity as target profit
  • Exit: Close position if price re-enters the bands
  • Execution: GBPUSD, H1 timeframe, with risk of 1% per trade"

Example 5: Mean Reversion Strategy

Copy this complete prompt:

"Help me create an EAsiScript Preset File for a mean reversion
strategy.

The preset file must strictly comply with all the ‘Rules for
Creating EAsiTrader Preset Files’. Use the Defaults.set Preset File as
a template. Verify your content by cross referencing your sections and
settings with those from the template. Any deviation or omission
will be considered a failure to complete the task
.

Strategy Details

  • Entry: Enter long when RSI below 30 and returns above it
  • Stop Loss: Place at low of last 5 bars
  • Take Profit: Target twice the stop-loss distance
  • Exit: Exit on MA cross or RSI above 70
  • Execution: USDJPY, M15 timeframe"

Example 6: Asian Session Range Strategy

Copy this complete prompt:

"Create a preset for trading the Asian session range breakout.

The preset file must strictly comply with all the ‘Rules for
Creating EAsiTrader Preset Files’. Use the Defaults.set Preset File as
a template. Verify your content by cross referencing your sections and
settings with those from the template. Any deviation or omission
will be considered a failure to complete the task
.

Strategy Details

  • Symbol: USDJPY M30
  • Range Definition: 00:00-03:00 Tokyo
  • Entry: Break of range high/low after range formation
  • Filters: Minimum range size using ATR
  • Risk: Dynamic based on range size
  • Exit: Before Tokyo lunch or at 1:1 reward:risk"

Example 7: Support/Resistance Strategy

Copy this complete prompt:

"Create a preset for trading key support/resistance levels.

The preset file must strictly comply with all the ‘Rules for
Creating EAsiTrader Preset Files’. Use the Defaults.set Preset File as
a template. Verify your content by cross referencing your sections and
settings with those from the template. Any deviation or omission
will be considered a failure to complete the task
.

Strategy Details

  • Symbol: EURGBP H1
  • Indicator: HLines for dynamic S/R levels
  • Entry: Reversal candle at S/R with RSI confirmation
  • Stop Loss: Beyond the S/R level plus buffer
  • Take Profit: Distance to next S/R level
  • Filters: Minimum distance between levels using ATR
  • Time: Active during London session only"

Example 8: Double Zero Level Strategy

Copy this complete prompt:

"Generate a preset for trading psychological price levels.

The preset file must strictly comply with all the ‘Rules for
Creating EAsiTrader Preset Files’. Use the Defaults.set Preset File as
a template. Verify your content by cross referencing your sections and
settings with those from the template. Any deviation or omission
will be considered a failure to complete the task
.

Strategy Details

  • Symbol: USDCAD H4
  • Entry: Reversal at 00 levels (1.3200, 1.3300, etc.)
  • Confirmation: MACD cross and minimum volume
  • Stop Loss: ATR-based beyond the level
  • Management: Trail stop to breakeven after 20 pips
  • Risk: 1% per trade, scaled by distance to stop"

Visit the EAsiTrader Presets Page for more examples which you can download to use in EAsiTrader.

Rev:07.02.2025 10:35Trend(‘MA1’) == Bullish && Close(1) > Open(1) ? Ask() : 0

Use AI to Create an EAsiScript Preset File

Creating EAsiScript preset files using AI can greatly simplify the process of defining and managing trading strategies. AI can assist by generating preset files based on a user-provided strategy description. However, to ensure the preset files are valid and compatible with EAsiTrader, it is essential to follow the “Rules for Creating EAsiTrader Preset Files.”

1. Prepare Your Strategy Details

  • Clearly define the specifics of your trading strategy:
    • Entry and Exit Rules: Conditions for opening and closing trades.
    • Risk Management: Stop loss, take profit, breakeven levels, or trailing stops.
    • Indicators: Specify indicators like RSI, Moving Averages, or ATR.
    • Special Conditions: Add any time-based filters, multi-symbol requirements, or other specific needs.

2. Upload the User Guides to AI

  • Upload the EAsiTrader, EAsiScript, and Learn EAsiScript user guides. These definitive and up-to-date references contain all the information AI needs to generate accurate scripts.

3. Ask AI to Create Your Preset

  • Provide a detailed description of your trading strategy in your prompt. For example:

    "Create an EAsiScript preset file for a trend-following strategy:"

    • Long Entry: Buy when RSI(14) > 50 and the price is above the 20-period Moving Average.
    • Long Exit: Close the trade when RSI(14) < 50.
    • Stop Loss: Use ATR(14) to calculate a stop loss 1 ATR below the last low.
    • Take Profit: Set a target 2 times the stop loss distance.
  • Instructions you must follow:

    “The preset file must strictly comply with all the ‘Rules for Creating Main Preset Files’ as outlined in the EAsiTrader User Guide. Use the Defaults.set Preset File as a template. Verify your content by cross referencing your sections and settings with those from the template. If different then regenerate the content. Any deviation or omission will be considered a failure to complete the task. Repeatedly check the rules, compare with the template and regenerate the content until every rule is complied with.”

4. Save the Generated Content

  • Copy the AI-generated output and save it as a .set file in a plain text editor like Notepad++.
  • Use a descriptive file name, such as TrendFollowingRSI.set.

5. Copy the Preset File to the EAsiTrader Folder

  • Navigate to the EAsiTrader folder on your system, typically located at:
    MQ5\Files\EAsiTrader
  • Place the .set file in this directory.

6. Load the Preset in EAsiTrader

  • Open EAsiTrader in MetaTrader 5.
  • The Profile Dropdown, located at the top of the GUI, will automatically display the new preset file.
  • Select the preset file from the dropdown to load it.

7. Test the Preset

  • Use the Tester feature in EAsiTrader to simulate the behavior of your preset file.
  • Analyze its performance and make adjustments if necessary.

8. Activate for Live Trading

  • Once satisfied with the preset’s performance, enable Auto Trading in EAsiTrader.
  • Begin using the preset file for live trading.

9. Iterate and Optimize

  • Continue refining your strategy using AI and generating new preset files as needed.
  • Test each version thoroughly before deploying it for live trading.

Why Uploading User Guides is Essential

By uploading the user guides, you eliminate the need to manually provide additional context or formatting details in your AI prompt. The AI will reference the guides to:

  • Understand the structure and functionality of EAsiTrader and EAsiScript.
  • Generate preset files in the correct format, ensuring compatibility with EAsiTrader.

This streamlined process ensures you can focus on your strategy while leveraging AI and the comprehensive user guides to produce accurate and effective EAsiScript Preset Files.

AI Prompt Examples

Prompt Example 1: Basic Strategy

**I want to create an EAsiScript preset file for a strategy based on RSI levels. **

Strategy Details

  • Entry: Go long when RSI crosses above 30, go short when RSI crosses below 70.
  • Stop Loss: 2 times ATR below/above entry price for long/short trades.
  • Take Profit: Fixed at 50 points for all trades.
  • Exit: Close trade if the opposite RSI condition occurs.
  • Execution: Runs on EURUSD on the M30 timeframe.

Instructions

The preset file must strictly comply with all the ‘Rules for Creating EAsiTrader Preset Files’ as outlined in the EAsiTrader User Guide. Use the Defaults.set Preset File as a template. Verify your content by cross referencing your sections and settings with those from the template. If different then regenerate the content. Any deviation or omission will be considered a failure to complete the task.


Prompt Example 2: Advanced Trend-Following Strategy

"Please create an EAsiScript Preset File for a trend-following strategy using moving averages:"

  • Entry: Enter a long position when the 50-period SMA crosses above the 200-period SMA. Enter a short position when the 50-period SMA crosses below the 200-period SMA.
  • Stop Loss: Set the stop loss at the low of the previous bar for long positions and the high of the previous bar for short positions.
  • Take Profit: Use ATR to calculate take profit as 3 times the stop-loss distance.
  • Exit: Exit the trade if the SMA crossover reverses.
  • Execution: This strategy should run on the primary market, using the D1 timeframe."

Prompt Example 3: Breakout Strategy

"Generate an EAsiScript Preset File for a breakout strategy based on Bollinger Bands:"

  • Entry: Go long if the high of the previous bar breaks above the upper Bollinger Band. Go short if the low of the previous bar breaks below the lower Bollinger Band.
  • Stop Loss: Use a trailing stop based on 2 ATR.
  • Take Profit: Use 5% of account equity as a target profit.
  • Exit: Close the position if price re-enters the Bollinger Bands.
  • Execution: This should run on GBPUSD, H1 timeframe, with a risk of 1% per trade."

Prompt Example 4: Mean Reversion Strategy

"Help me create an EAsiScript Preset File for a mean reversion strategy:"

  • Entry: Enter a long position when RSI crosses below 30 and then returns above 30. Enter a short position when RSI crosses above 70 and then returns below 70.
  • Stop Loss: Place the stop loss at the low of the last 5 bars for long trades or the high of the last 5 bars for short trades.
  • Take Profit: Target twice the stop-loss distance.
  • Exit: Exit the trade if a 10-period SMA crosses in the opposite direction.
  • Execution: This strategy applies to USDJPY, M15 timeframe."

Visit the EAsiScript Presets for more examples which you can download to use in EAsiTrader.

Rev:13.12.2024 14:27# Learn EAsiScript
Fundamentals of Writing Scripts EAsiScript enables you to define trading logic using simple yet powerful expressions. These expressions, composed of functions and operators, form the backbone of your scripts, driving decisions such as entering trades, setting stop losses, or adjusting take profit levels. In this tutorial, you’ll learn the fundamentals of writing expressions for specific scripts, with a focus on the ?: (ternary), && (AND), and || (OR) operators, which are integral to building dynamic and efficient trading logic.

Writing Expressions for Scripts

Each EAsiScript performs a specific trading function, such as Long Entry, Short Entry, Stop Loss, or Take Profit. Let’s explore how expressions fit into these scripts.

Example 1: Long Entry Script

Purpose

This script places a buy trade when the closing price of the last completed bar is higher than its opening price. It’s useful for simple trend-following strategies that focus on bullish price movement.

Script

Close(1) > Open(1) ? Ask() : 0

Explanation

  1. Check if the closing price of the last completed bar is greater than its opening price [Close(1) > Open(1)].
  2. If the condition is true, the script enters a buy trade at the current Ask price [Ask()].
  3. If the condition is false, the script does nothing [0].

Notes

  • Close(1): The closing price of the last completed bar.
  • Open(1): The opening price of the last completed bar.
  • Ask(): The current Ask price, which is the price at which a buy trade is executed.

Common Mistakes

  • Using Close or Open without specifying the shift, such as Close() instead of Close(1).
  • Forgetting to set the script to 0 for “do nothing” when the condition is false.

Example 2: Stop Loss Script

Purpose

This script dynamically adjusts the stop loss level based on the average true range (ATR) of the last completed bar. It’s suitable for strategies that adapt to market volatility.

Script

ATR1(1) > 20 ? Low(1) - 10 * Point : Low(1) - 5 * Point

Explanation

  1. Check if the average true range of the last completed bar is greater than 20 [ATR1(1) > 20].
  2. If the condition is true, the script sets the stop loss 10 points below the low of the last completed bar [Low(1) - 10 * Point].
  3. If the condition is false, the script sets the stop loss 5 points below the low of the last completed bar [Low(1) - 5 * Point].

Notes

  • ATR1(1): The average true range (ATR) value of the last completed bar. Ensure the ATR indicator is enabled in the Indicator List.
  • Low(1): The lowest price of the last completed bar. The default value for the shift argument is 1.
  • Point: Converts raw numbers into points, which match the symbol’s price units.

Common Mistakes

  • Forgetting to enable the ATR indicator in the Indicator List, which is required for the ATR1 function to work.
  • Using raw numbers (e.g., 10 or 5) without multiplying by Point to ensure correct scaling.
  • Omitting the shift argument for Low, which defaults to 1 but should be explicitly included for clarity.

Example 3: Combining Conditions in a Long Entry Script

Purpose

This script places a buy trade when two conditions are met: the closing price of the last completed bar is higher than its opening price, and the relative strength index (RSI) indicates bullish momentum. It’s ideal for strategies that require confirmation from both price action and momentum indicators.

Script

Close(1) > Open(1) && RSI1(1) > 50 ? Ask() : 0

Explanation

  1. Check if the closing price of the last completed bar is greater than its opening price [Close(1) > Open(1)].
  2. Check if the relative strength index of the last completed bar is greater than 50 [RSI1(1) > 50].
  3. If both conditions are true, the script enters a buy trade at the current Ask price [Ask()].
  4. If either condition is false, the script does nothing [0].

Notes

  • Close(1): The closing price of the last completed bar.
  • Open(1): The opening price of the last completed bar.
  • RSI1(1): The RSI value of the last completed bar. Ensure the RSI indicator is enabled in the Indicator List.
  • Ask(): The current Ask price, which is the price at which a buy trade is executed.

Common Mistakes

  • Forgetting to enable the RSI indicator in the Indicator List, which is required for the RSI1 function to work.
  • Using && incorrectly, such as failing to enclose conditions in parentheses when combining multiple logical expressions.
  • Omitting the shift argument for Close or Open, which defaults to 1 but should be explicitly included for clarity.

Example 4: Short Entry Script with OR (||) Operator

Purpose

This script places a sell trade when either of two conditions is met: the closing price of the last completed bar is lower than its opening price, or the MACD indicator signals bearish momentum. It’s useful for strategies that look for multiple potential triggers for entry.

Script

Close(1) < Open(1) || MACD1(1) < 0 ? Bid() : 0

Explanation

  1. Check if the closing price of the last completed bar is less than its opening price [Close(1) < Open(1)].
  2. Check if the MACD value of the last completed bar is less than 0, indicating bearish momentum [MACD1(1) < 0].
  3. If either condition is true, the script enters a sell trade at the current Bid price [Bid()].
  4. If neither condition is true, the script does nothing [0].

Notes

  • Close(1): The closing price of the last completed bar.
  • Open(1): The opening price of the last completed bar.
  • MACD1(1): The MACD value of the last completed bar. Ensure the MACD indicator is enabled in the Indicator List.
  • Bid(): The current Bid price, which is the price at which a sell trade is executed.

Common Mistakes

  • Forgetting to enable the MACD indicator in the Indicator List, which is required for the MACD1 function to work.
  • Using || incorrectly, such as not properly separating conditions when combining multiple logical expressions.
  • Omitting the shift argument for Close or Open, which defaults to 1 but should be explicitly included for clarity.

Example 5: Long Trailing Stop Script

Purpose

This script adjusts the stop loss level dynamically for a long trade when the profit exceeds a specified threshold. It’s ideal for locking in gains while allowing the trade to run further if the price continues to move favourably.

Script

Profit() > 100 ? Bid() - 15 * Point : 0

Explanation

  1. Check if the profit of the current trade is greater than 100 [Profit() > 100].
  2. If the condition is true, the script adjusts the stop loss to 15 points below the current Bid price [Bid() - 15 * Point].
  3. If the condition is false, the script does nothing [0].

Notes

  • Profit(): The current profit of the trade in the symbol’s currency.
  • Bid(): The current Bid price, which is used as the reference for calculating the trailing stop.
  • Point: Converts raw numbers into points, ensuring the stop loss is adjusted appropriately based on the symbol’s price scale.

Common Mistakes

  • Using Profit without parentheses, which is invalid (e.g., Profit > 100 instead of Profit() > 100).
  • Forgetting to use Point for proper scaling, especially if the symbol’s price has many decimal places.
  • Not specifying the 0 return value, which means “do nothing” if the condition is not met.

Example 6: Take Profit Script with RSI and Price Action

Purpose

This script sets the take profit level when two conditions are met: the closing price of the last completed bar is higher than its opening price, and the relative strength index (RSI) indicates overbought conditions. It’s designed for strategies that aim to exit trades at optimal points during strong bullish trends.

Script

Close(1) > Open(1) && RSI1(1) > 70 ? High(1) + 10 * Point : 0

Explanation

  1. Check if the closing price of the last completed bar is greater than its opening price [Close(1) > Open(1)].
  2. Check if the relative strength index of the last completed bar is above 70, signaling overbought conditions [RSI1(1) > 70].
  3. If both conditions are true, the script sets the take profit level 10 points above the high of the last completed bar [High(1) + 10 * Point].
  4. If either condition is false, the script does nothing [0].

Notes

  • Close(1): The closing price of the last completed bar.
  • Open(1): The opening price of the last completed bar.
  • RSI1(1): The RSI value of the last completed bar. Ensure the RSI indicator is enabled in the Indicator List.
  • High(1): The highest price of the last completed bar.
  • Point: Converts raw numbers into points, ensuring proper scaling based on the symbol’s price units.

Common Mistakes

  • Forgetting to enable the RSI indicator in the Indicator List, which is required for the RSI1 function to work.
  • Using raw numbers (e.g., 10) without multiplying by Point, which may result in incorrect scaling.
  • Omitting the shift argument for Close, Open, or High, which defaults to 1 but should be explicitly included for clarity.

Example 7: Short Trailing Stop Script

Purpose

This script dynamically adjusts the stop loss level for a short trade when the profit exceeds a specified threshold. It helps secure gains while allowing the trade to remain open if the price continues moving favorably.

Script

Profit() > 50 ? Ask() + 10 * Point : 0

Explanation

  1. Check if the profit of the current trade is greater than 50 [Profit() > 50].
  2. If the condition is true, the script adjusts the stop loss to 10 points above the current Ask price [Ask() + 10 * Point].
  3. If the condition is false, the script does nothing [0].

Notes

  • Profit(): The current profit of the trade in the symbol’s currency.
  • Ask(): The current Ask price, which is used as the reference for calculating the trailing stop.
  • Point: Converts raw numbers into points, ensuring proper scaling based on the symbol’s price units.

Common Mistakes

  • Using Profit without parentheses, which is invalid (e.g., Profit > 50 instead of Profit() > 50).
  • Forgetting to use Point for proper scaling, especially for symbols with small price increments.
  • Not specifying the 0 return value, which means “do nothing” if the condition is not met.

Example 8: Long Entry Script with RSI and Moving Average

Purpose

This script places a buy trade when two conditions are met: the relative strength index (RSI) indicates bullish momentum, and the closing price is above the moving average. It’s ideal for trend-following strategies that confirm momentum with a moving average filter.

Script

RSI1(1) > 50 && Close(1) > MA1(1) ? Ask() : 0

Explanation

  1. Check if the relative strength index of the last completed bar is greater than 50 [RSI1(1) > 50], signaling bullish momentum.
  2. Check if the closing price of the last completed bar is greater than the moving average value of the last completed bar [Close(1) > MA1(1)].
  3. If both conditions are true, the script enters a buy trade at the current Ask price [Ask()].
  4. If either condition is false, the script does nothing [0].

Notes

  • RSI1(1): The RSI value of the last completed bar. Ensure the RSI indicator is enabled in the Indicator List.
  • Close(1): The closing price of the last completed bar.
  • MA1(1): The moving average value of the last completed bar. Ensure the Moving Average indicator is enabled in the Indicator List.
  • Ask(): The current Ask price, which is the price at which a buy trade is executed.

Common Mistakes

  • Forgetting to enable the RSI or Moving Average indicator in the Indicator List, which is required for the RSI1 and MA1 functions to work.
  • Omitting the shift argument for Close, which defaults to 1 but should be explicitly included for clarity.
  • Using raw numbers (e.g., 50) without understanding their significance in indicator thresholds (e.g., RSI values range from 0 to 100).

Example 9: Short Entry Script with MACD and RSI

Purpose

This script places a sell trade when two conditions are met: the MACD indicator signals bearish momentum, and the relative strength index (RSI) indicates oversold conditions. It’s suitable for strategies that rely on confirmation from both momentum and trend indicators.

Script

MACD1(1) < 0 && RSI1(1) < 30 ? Bid() : 0

Explanation

  1. Check if the MACD value of the last completed bar is less than 0 [MACD1(1) < 0], signaling bearish momentum.
  2. Check if the relative strength index of the last completed bar is less than 30 [RSI1(1) < 30], indicating oversold conditions.
  3. If both conditions are true, the script enters a sell trade at the current Bid price [Bid()].
  4. If either condition is false, the script does nothing [0].

Notes

  • MACD1(1): The MACD value of the last completed bar. Ensure the MACD indicator is enabled in the Indicator List.
  • RSI1(1): The RSI value of the last completed bar. Ensure the RSI indicator is enabled in the Indicator List.
  • Bid(): The current Bid price, which is the price at which a sell trade is executed.

Common Mistakes

  • Forgetting to enable the MACD or RSI indicator in the Indicator List, which is required for the MACD1 and RSI1 functions to work.
  • Using && incorrectly, such as not properly grouping conditions when combining multiple logical expressions.
  • Omitting the shift argument for MACD1 or RSI1, which defaults to 1 but should be explicitly included for clarity.

Example 10: Take Profit Script with Moving Average and RSI

Purpose

This script sets a take profit level when two conditions are met: the closing price is above the moving average, and the relative strength index (RSI) indicates overbought conditions. It’s useful for trend-following strategies that aim to exit trades during strong upward trends.

Script

MA1(1) > Close(1) && RSI1(1) > 70 ? High(1) + 15 * Point : 0

Explanation

  1. Check if the moving average value of the last completed bar is greater than the closing price of the last completed bar [MA1(1) > Close(1)].
  2. Check if the relative strength index of the last completed bar is above 70 [RSI1(1) > 70], signaling overbought conditions.
  3. If both conditions are true, the script sets the take profit level 15 points above the high of the last completed bar [High(1) + 15 * Point].
  4. If either condition is false, the script does nothing [0].

Notes

  • MA1(1): The moving average value of the last completed bar. Ensure the Moving Average indicator is enabled in the Indicator List.
  • Close(1): The closing price of the last completed bar.
  • RSI1(1): The RSI value of the last completed bar. Ensure the RSI indicator is enabled in the Indicator List.
  • High(1): The highest price of the last completed bar.
  • Point: Converts raw numbers into points, ensuring proper scaling based on the symbol’s price units.

Common Mistakes

  • Forgetting to enable the Moving Average or RSI indicator in the Indicator List, which is required for the MA1 and RSI1 functions to work.
  • Using raw numbers (e.g., 15) without multiplying by Point, which may result in incorrect scaling.
  • Omitting the shift argument for MA1, Close, or High, which defaults to 1 but should be explicitly included for clarity.

Example 11: Long Entry Script with Moving Average Signal

Purpose

This script places a buy trade when the MA1 indicator generates a bullish signal using its SignalFlag. It’s ideal for strategies that rely on moving averages to identify upward trends.

Script

Signal('MA1') == Bullish ? Ask() : 0

Explanation

  1. Indicator Signal Check: Signal('MA1') == Bullish
    • Retrieves the SignalFlag value from the MA1 indicator’s buffer 2 at the last completed bar (shift=1 by default).
    • Checks if the signal is bullish (Bullish = 1).
  2. If the condition is true, the script enters a buy trade at the current Ask price [Ask()].
  3. If the condition is false (no signal or bearish signal), the script does nothing [0].

Notes

  • Signal(‘MA1’): Automatically accesses buffer 2 of the MA1 indicator to retrieve the SignalFlag value. Ensure the MA1 indicator is enabled in the Indicator List.
    • Bullish (1): Buy signal.
    • Bearish (-1): Sell signal.
    • 0: No signal.
  • Ask(): The current Ask price, which is the price at which a buy trade is executed.

Common Mistakes

  • Forgetting to enable the MA1 indicator in the Indicator List.
  • Misinterpreting the signal flag values, where 0 means no signal, Bullish (1) indicates a buy, and Bearish (-1) indicates a sell.
  • Omitting the 0 return value, which ensures the script does nothing if the condition is false.

Example 12: Long Entry Script and Stop Loss Script with Moving Average and ATR

Purpose

This example combines a Long Entry Script and a Stop Loss Script to create a basic strategy:

  1. Enter a long trade when the Moving Average indicator generates a bullish signal.
  2. Set a dynamic stop loss level based on market volatility using the ATR indicator.

Long Entry Script

Signal('MA1') == Bullish ? Ask() : 0

Explanation:

  1. The script checks if the MA1 indicator generates a bullish signal [Signal(‘MA1’) == Bullish].
  2. If true, it enters a buy trade at the current Ask price [Ask()].
  3. If false, it does nothing [0].
    Notes:
  • Ensure the MA1 indicator is enabled in the Indicator List.
  • The Signal() function automatically retrieves the SignalFlag from buffer 2 of MA1.

Stop Loss Script

ATR1(1) > 15 ? Low(1) - 20 * Point : Low(1) - 10 * Point

Explanation:

  1. The script checks if the ATR value of the last completed bar is greater than 15 [ATR1(1) > 15].
  2. If true, it sets the stop loss 20 points below the low of the last completed bar [Low(1) - 20 * Point].
  3. If false, it sets the stop loss 10 points below the low of the last completed bar [Low(1) - 10 * Point].
    Notes:
  • Ensure the ATR indicator is enabled in the Indicator List.
  • The script dynamically adjusts the stop loss based on market volatility.
  • Point ensures that the numeric values are scaled correctly according to the symbol’s price.

Strategy Flow

  1. Entry Trigger:
    • The Long Entry Script evaluates the MA1 indicator.
    • If the signal is bullish, a buy trade is executed at the current Ask price.
  2. Stop Loss Adjustment:
    • After the trade is entered, the Stop Loss Script dynamically sets the stop loss based on the ATR value and the low price of the last completed bar.

Common Mistakes

  • Forgetting to enable the MA1 and ATR indicators in the Indicator List.
  • Using incorrect scaling for stop loss values (e.g., omitting Point).
  • Misinterpreting the SignalFlag or ATR values, leading to unintended results.

Practical Example 1: Trading with MA and ST Indicators

This example demonstrates a strategy using the Moving Average (MA) and Super Trend (ST) indicators. The strategy includes entry conditions, an initial stop loss, and exit conditions.

Long Entry Script

Trend('MA1') == Bullish && Signal('ST1') == Bullish ? Ask() : 0

Explanation:

  1. Checks if the trend from the Moving Average (MA1) is bullish [Trend(‘MA1’) == Bullish].
  2. Verifies that the Super Trend (ST1) indicator generates a bullish signal [Signal(‘ST1’) == Bullish].
  3. If both conditions are true, a buy trade is executed at the current Ask price.

Short Entry Script

Trend('MA1') == Bearish && Signal('ST1') == Bearish ? Bid() : 0

Explanation:

  1. Checks if the trend from the Moving Average (MA1) is bearish [Trend(‘MA1’) == Bearish].
  2. Verifies that the Super Trend (ST1) indicator generates a bearish signal [Signal(‘ST1’) == Bearish].
  3. If both conditions are true, a sell trade is executed at the current Bid price.

Long Initial SL Script

Low(1) - 20 * Point : 0

Explanation:

  1. The initial stop loss is set 20 points below the low of the last completed bar [Low(1) - 20 * Point].
  2. If the condition is false, the script does nothing [0].

Short Initial SL Script

High(1) + 20 * Point : 0

Explanation:

  1. The initial stop loss is set 20 points above the high of the last completed bar [High(1) + 20 * Point].
  2. If the condition is false, the script does nothing [0].

Exit Scripts

Long Exit Script

Trend('MA1') != Bullish ? Bid() : 0

Explanation:

  1. The script exits the long trade if the Moving Average trend is no longer bullish [Trend(‘MA1’) != Bullish].
  2. The trade is closed at the current market price using the Bid() function.

Short Exit Script

Trend('MA1') != Bearish ? Ask() : 0

Explanation:

  1. The script exits the short trade if the Moving Average trend is no longer bearish [Trend(‘MA1’) != Bearish].
  2. The trade is closed at the current market price using the Ask() function.

Trailing Stop Scripts

Long Trailing Stop Script

Profit() > 50 ? Bid() - 15 * Point : 0

Explanation:

  1. The trailing stop for the long trade is activated if the profit exceeds 50 points [Profit() > 50].
  2. The stop loss is set 15 points below the current Bid price [Bid() - 15 * Point].

Short Trailing Stop Script

Profit() > 50 ? Ask() + 15 * Point : 0

Explanation:

  1. The trailing stop for the short trade is activated if the profit exceeds 50 points [Profit() > 50].
  2. The stop loss is set 15 points above the current Ask price [Ask() + 15 * Point].

Practical Strategy Flow

  1. Entry:

    • A trade is opened when both the Moving Average and Super Trend indicators confirm a bullish or bearish trend.
    • Example:
      • For a long trade, both Trend('MA1') == Bullish and Signal('ST1') == Bullish must be true.
  2. Initial Stop Loss:

    • Once a trade is opened, the initial stop loss is set using the Super Trend indicator and price levels.
  3. Exit:

    • Trades are exited if the trend changes, as indicated by the Moving Average crossing its threshold.
    • Alternatively, a trailing stop secures profits dynamically as the price moves favorably.

Notes

  • Indicator Requirements:

    • Ensure the MA1 and ST1 indicators are enabled in the Indicator List.
    • Configure their parameters appropriately in the Indicator List.
  • Scaling with Point:

    • Always multiply numeric adjustments (e.g., stop loss distances) by Point to match the symbol’s price units.
  • Optimization:

    • Use VAR0 and VAR1 for dynamic stop loss distances during optimization.

    • Example:
      VAR0 = 10, 20
      VAR1 = 5, 15

      Signal('ST1') == Bullish ? Low(1) - VAR0 * Point : 0
      

This example demonstrates a complete trading strategy leveraging two complementary indicators, showing how to combine entry, initial stop loss, and exit logic into a robust script setup.

Practical Example 2: RangeBreakout Strategy for USDJPY

The RangeBreakout-USDJPY strategy identifies trading opportunities based on the price range of the last three bars and executes trades at predefined times. This example demonstrates how to use EAsiScript to configure entry, exit, and initial stop-loss conditions.

Objective

The strategy aims to capitalize on breakouts during a specific time window by analyzing the price range of the last three bars. Trades are entered only if the range falls within defined thresholds relative to the current price.

Configuration

Entry Scripts

  1. Long Entry:

    TimeOfDay(4,30) && ((HighestHigh(3) - LowestLow(3)) >= Ask() * 0.002) && ((HighestHigh(3) - LowestLow(3)) <= Ask() * 0.004) ? HighestHigh(3) : 0

    At 4:30, check the high (HighestHigh(3)) and low (LowestLow(3)) of the last three bars.
    If the range is between 0.2% and 0.4% of the current Ask price, enter a long trade at the high of the range (HighestHigh(3)).
    Otherwise, no trade is entered (0).

  2. Short Entry:

    TimeOfDay(4,30) && ((HighestHigh(3) - LowestLow(3)) >= Ask() * 0.002) && ((HighestHigh(3) - LowestLow(3)) <= Ask() * 0.004) ? LowestLow(3) : 0

    At 4:30, check the high (HighestHigh(3)) and low (LowestLow(3)) of the last three bars.
    If the range is between 0.2% and 0.4% of the current Ask price, enter a short trade at the low of the range (LowestLow(3)).
    Otherwise, no trade is entered (0).

Initial Stop-Loss Scripts

  1. Long Initial Stop:

    Ask(-0.005)

    Sets the stop loss 0.5% below the current Ask price.

  2. Short Initial Stop:

    Bid(0.005)

    Sets the stop loss 0.5% above the current Bid price.

Exit Scripts

  1. Long Exit:

    TimeOfDay(18,0) && (IsOpen() || IsPending())

    At 18:00, exit any open or pending long trades.

  2. Short Exit:

    TimeOfDay(18,0) && (IsOpen() || IsPending())

    At 18:00, exit any open or pending short trades.

Key Concepts

  • Time-Based Entry: The TimeOfDay function ensures trades are evaluated only at the specified time (4:30 in this case).
  • Range Validation: The difference between HighestHigh(3) and LowestLow(3) ensures the breakout conditions are met.
  • Dynamic Stop-Loss: The stop-loss values are calculated as a percentage of the current price.

Considerations

  • Ensure the Auto Trade mode is enabled in EAsiTrader to execute trades automatically based on these scripts.
  • This strategy is configured for USDJPY on a 30-minute timeframe (M30). Adjust the InpTradeTool_Market setting to align with your desired symbol and timeframe.

Example Execution Flow

  1. At 4:30, EAsiTrader evaluates the entry conditions for both long and short trades.
  2. If conditions are met, a trade is entered at the specified price (high or low of the range).
  3. Initial stop-loss values are set dynamically relative to the current price.
  4. At 18:00, any open or pending trades are closed.

This example demonstrates how EAsiScript can be used to implement a time-sensitive breakout strategy efficiently. Modify the parameters and conditions as needed to suit your trading objectives.

Practical Example 3: AutoFib Entry Signal Trading Strategy

Objective:

This strategy uses AutoFib1 to identify bullish and bearish market structures and trade based on higher highs (HighestHigh), higher lows (HL), lower highs (LH), and lower lows (LL). It is designed for semi-automated trading to send alerts and execute trades when conditions align with the strategy.

Settings:

  • Market: Major and minor currency pairs
  • Indicators Used:
    • AutoFib1: Identifies market structure and provides bullish/bearish signals.
    • MA1: Moving Average for trend alignment.
    • ATR1: Average True Range for volatility-based thresholds.

Scripts:

  1. Long Entry Script:

    Signal('AutoFib1') == Bullish && Low() <= LowestLow(15) && Close() < (MA1() + (ATR1() * 5)) && Close() > MA1() ? Ask() : 0

    Logic:
    Enter a long trade when:

    • The AutoFib1 signal is bullish.
    • The current low is at or below the 15-bar lowest low (LL).
    • The close price is below the moving average (MA1) plus 5 times the ATR, ensuring the price is within a valid range.
    • The close price is above the moving average (MA1).
    • Execute the trade at the current Ask price.
  2. Short Entry Script:

    Signal('AutoFib1') == Bearish && High() >= HighestHigh(15) && Close() < MA1() && Close() > (MA1() - (ATR1() * 5)) ? Bid() : 0

    Logic:
    Enter a short trade when:

    • The AutoFib1 signal is bearish.
    • The current high is at or above the 15-bar highest high (HighestHigh).
    • The close price is below the moving average (MA1).
    • The close price is above the moving average minus 5 times the ATR.
    • Execute the trade at the current Bid price.

Implementation Steps:

  1. Preset Configuration:

    • Name the preset file AutoFibTest.set for clarity.
    • Assign the strategy to major and minor currency pairs.
  2. Load Indicators:

    • Add AutoFib1 to identify market structures and signals.
    • Add MA1 to evaluate moving average alignment.
    • Add ATR1 with a period of 14 to assess volatility thresholds.
  3. Customize Scripts:

    • Paste the long and short entry scripts into their respective sections in the EAsiTrader GUI.
    • Leave other script fields empty unless additional logic (e.g., take profit, trailing stops) is required.
  4. Activate Auto Trade:

    • Set AutoTradeEnabled to true.
    • Use SeriesRefreshMode_EveryBar for processing on each new bar.
  5. Backtest and Optimize:

    • Run backtests on major and minor currency pairs.
    • Fine-tune ATR multipliers, moving average settings, or AutoFib parameters based on backtest performance.

Expected Outcome:

This strategy enables traders to identify and act on key bullish or bearish structures, ensuring alignment with market conditions. Semi-automation provides flexibility while leveraging the power of AutoFib1 and supporting indicators for informed decision-making.

Practical Example 4: USTECH Bollinger Band Squeeze + EMA Strategy

Objective:

This strategy focuses on buy-only trades on the USTECH 30-minute chart. It takes advantage of Bollinger Band squeezes to identify low volatility periods, coupled with price position relative to a 200 EMA to confirm bullish conditions. The stop loss is adjustable using an optimised value of VAR0.

Settings:

  • Market: USTECH, 30-minute timeframe.
  • Indicators Used:
    • BB1: Bollinger Bands to detect squeezes.
    • MA1: 200 EMA for trend confirmation.
    • ATR1: Average True Range for dynamic stop loss and volatility assessment.
  • Trade Type: Buys only.

Scripts:

  1. Long Entry Script:

    Close() > MA1(0,1) && BB1(0,1) - BB1(0,2) <= ATR1() * 2 ? Ask() : 0

    Logic:
    Enter a long trade when:

    • The current close price is above the 200 EMA.
    • The price range between the upper and lower Bollinger Bands is less than or equal to twice the ATR.
    • Execute the trade at the current Ask price.
  2. Long Initial Stop Script:

    Ask() - ATR1() * VAR0

    Logic:

    • Set the initial stop loss at the Ask price minus ATR multiplied by the optimised VAR0 value.

Implementation Steps:

  1. Preset Configuration:
    • Name the preset file BollingerBands.set.
    • Assign the strategy to the USTECH 30-minute timeframe.
  2. Enable Indicators:
    • Enable BB1 to measure Bollinger Band contractions.
    • Enable MA1 with a period of 200 for trend confirmation.
    • Enable ATR1 with a period of 14 for volatility-based thresholds.
  3. Set Trade Types:
    • Allow only buy trades by setting AllowedTradeTypes to Buys Only.
  4. Customise User Variables:
    • Define VAR0 as 4 (optimised for this strategy based on historical performance).
  5. Risk Management:
    • Limit risk per trade to 1% by setting MaxRiskPerTradeInPercent.
    • Allow only one open position for the market by setting MaxOpenPositionsMarket to 1.
  6. Backtest and Optimise:
    • Run backtests on the USTECH 30-minute chart.
    • Optimise VAR0 and Bollinger Band parameters based on historical performance.

Expected Outcome:

This strategy identifies low volatility opportunities on the USTECH 30-minute chart, confirming bullish conditions with EMA and Bollinger Bands. The combination of technical indicators and an optimised stop loss enhances trade accuracy and risk management, ensuring it aligns with semi-automated trading principles.

Best Practices for Writing Scripts

Follow these best practices to ensure your scripts are clear, consistent, and effective:

  1. Use Provided Variables:
  • Replace raw values like 1 or -1 with the predefined variables Bullish and Bearish:

    • Bullish = 1: Indicates a buy signal or bullish trend.
    • Bearish = -1: Indicates a sell signal or bearish trend.

    Example: Signal(‘MA1’) == Bullish ? Ask() : 0

  1. Leverage the Point Variable for Scaling:

    • Always multiply numeric adjustments by Point to ensure they are scaled correctly according to the symbol’s price units.

    Example: ATR1(1) > 15 ? Low(1) - 20 * Point : Low(1) - 10 * Point

  2. Explicitly Define Shifts for Functions:

    • Functions like Close, Open, High, and Low require a shift parameter. The default is 1, but specifying it explicitly improves clarity.

    Example: Close(1) > Open(1) ? Ask() : 0

  3. Avoid Invalid Functions:

    • Use valid functions like SL() instead of invalid ones like StopLoss().
    • Valid Functions: Ask(), Bid(), SL(), Signal(), Trend().
    • Invalid Examples: StopLoss(), Price().
  4. Combine Indicators and Price Data:

    • Create powerful scripts by combining indicator signals with price conditions.

    Example: Trend(‘MA1’) == Bullish && Close(1) > Open(1) ? Ask() : 0

Visit the EAsiScript Page for more examples which you can download to use in EAsiTrader.