Strategies and Analysis Techniques are written in EasyLanguage. EasyLanguage is a programming language which allows you to calculate and/or display values as text or plots, and to enter and exit trades. EasyLanguage provides Strategy Automation, which allows strategies to be automated so that manual entry and exit of trades is not required. This does not mean that strategies should be allowed to run unattended – more on this is provided below.
EasyLanguage works differently than typical computer programs
EasyLanguage strategies and Indicators run on each bar of the chart, beginning with the left most bars (earliest dates and times) and progressing to the last bar on the right of the chart (see image below). When we say the strategies/indicators run on each bar, we mean the EasyLanguage code re-runs completely, from start to finish, on each bar, usually at the closing tick (last tick) of the bar. Variables assigned a value on a bar closing tick will carry this value forward for calculations on the next bar. On each bar the current bar’s date, time and price data, such as Open, High, Low, C
The bar the strategy/indicator is running on is called the CurrentBar. EasyLanguage can access historical data using the [N] notation, to specify how many bars before the CurrentBar to access. For example, Close means the close of the last bar before the CurrentBar. High means the High of 5 bars before the CurrentBar. Close refers to the Close of the CurrentBar. Likewise, historical data for variables is also available using the same notation. So if you created a variable called MyEntryPrice, then the value of MyEntryPrice 2 bars ago from the CurrentBar is MyEntryPrice. Note that as the strategy progresses to the next bar, the CurrentBar increases by one. Close or High are always relative to the CurrentBar. For more information see MaxBarsBack and How To Access Historical Bar Prices.
For more information see Understanding how EasyLanguage Code is Processed.
Strategies and indicators cannot see future bar data: Future data of bars to the right of the current bar are not available to the EasyLanguage code. For example, you are not allowed to use Close[-1] to see the Closing value of 1 bar ahead of the CurrentBar. This is done intentionally to prevent look-ahead bias, which can result in misleading positive results when back-testing strategies on historical data, but result in large losses when live trading. Likewise, you cannot enter/exit trades on bars before the current bar the strategy is running on, because this too can introduce “look ahead bias”.
You cannot change historical bar values of variables or prices: EasyLanguage does not allow to change the value of a variable or price field ( Open, High, Low, Close, Date, Time, Volume, Ticks ) on a historical bar ( a bar before the CurrentBar the indicator / strategy is running on ). For example, MyValue = 10 is not allowed, nor is Close = 10. If you require changing a historical bar value then first assign the historical value to a variable, which you can change, like: MyHistoricalCloseValue = Close. If you require doing calculations on modified or custom historical price series, like a simple moving average of the bar closing value only when the closing value is greater than the opening value ( simple moving average of up or green bar closing values ), then see Introduction – Developing and Implementing Strategies and Indicators -> Common Custom Functions -> CUSTOM MOVING AVERAGES.
Strategies and Indicators do NOT run on missing bars: If the chart has missing bars / empty periods ( due to no data / trades ) then strategies and indicators will not run. So indicators cannot change plot values on missing bars, and strategies cannot enter / exit positions on missing bars, or make calculations on missing bars. If a chart has multiple data streams on it, the first data stream controls where plots are generated for other data streams. So you will not see plots update on other data streams where the first data stream has missing bars. For more information see Offset Moving Average on Empty Periods and Introduction – Developing and Implementing Strategies and Indicators -> INDICATORS -> Gotchas With the Plot Command .
Strategies inserted on the same chart run synchronously through historical bars: If the chart has multiple strategies inserted on it, the strategies march together through all the historical bars. This allows strategies to cooperate and co-exist, so that you can design separate entry and exit strategies, or have multiple strategies making entries and exits. Strategies cooperate through shared Strategy Position and Performance Reserved Words, such as MarketPosition, TotalTrades, EntryPrice, ExitPrice and NetProfit.
Indicators inserted on the same chart do NOT run synchronously through historical bars: If the chart has multiple indicators inserted on it, each indicator runs through the historical bars separately, one at a time. If the chart also has strategies inserted on it, the strategies run through historical bars first, followed by the indicators.
A strategy CANNOT directly access an indicator’s plot values when both are inserted on the same chart: Part of the issue is if the strategy could directly access the indicator’s plot values, it would only be useful when real-time ticks are arriving, as it makes no sense for historical bars since strategies run to completion through history before the indicators start to run. The most common technique to allow a strategy to access an indicator’s plot values is to copy the calculation code used in the indicator to the strategy, or for the calculation code to be placed in a common function which is called by both the strategy and indicator. If you are using a protected proprietary indicator where you cannot access the code, there is no way for a strategy to access the indicator’s plot values, since the indicator’s calculation code must be copied to the strategy.
Dave Cohn EasyLanguage Engineer, EasyLanguage Consulting