Adaptive Zero Lag EMA Strategy
The script you've provided is based on the Adaptive Zero Lag EMA (AZLEMA) strategy. This script uses the principles of John Ehlers' signal processing research and a method known as Cosine Instantaneous Frequency Measurement (IFM) for determining the dominant cycle period, i.e., the length of time between two identical points in successive cycles in your trading data.
Here's a brief overview of what the trading script does:
-
Initially, it sets up the strategy using a configuration of default inputs like period, adaptive mode, gain limit, threshold, stop loss points and take profit points. The currency is set to USD and the initial capital to 1000.
-
It then sets up calculations for the adaptive mode using a combination of differential equations and Ehlers' method (used when the 'Adaptive?' setting is set to true).
-
It calculates the average value (EMA) of the selected source of data over the selected period.
-
It performs a loop operation to find the Gain and Error Correlation (EC) values that minimize the absolute Error.
-
Using these values, it calculates the final EC value and plots the value of EC and EMA on the chart.
-
It creates potential buy and sell conditions based on the crossover and crossunder of EC and EMA above a certain defined threshold.
-
It sets up rules for entering and exiting long and short positions based on the buy and sell conditions determined earlier. For each position, it calculates the lot size and enters a position when the respective condition (buy/sell) is true. It sets a stop loss and a trailing take profit for each position.
This script seems quite comprehensive and versatile as it allows you to change multiple parameters to adapt to different trading styles and market conditions. As always, it's recommended to backtest this strategy using historical data before using it in live trading.
/*backtest
start: 2023-08-08 00:00:00
end: 2023-09-07 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
strategy(title="Adaptive Zero Lag EMA", shorttitle="AZLEMA", overlay = true, initial_capital=1000, currency="USD", commission_type=strategy.commission.cash_per_contract, commission_value=0.000005, slippage = 5, pyramiding=1, calc_on_every_tick=true)
src = input(title="Source", defval=close)- 1
