0% found this document useful (0 votes)
23 views2 pages

Message

The document is a Pine Script strategy called 'Zero Lag Trend Signals' designed for trading with specific entry and exit signals based on a zero lag exponential moving average (ZLEMA) and volatility bands. It includes customizable parameters for length, band multiplier, timeframes, and date range, and implements a risk management system with stop-loss and take-profit levels. The strategy visualizes trends and positions on a chart, allowing users to track their trades effectively.

Uploaded by

turubg5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

Message

The document is a Pine Script strategy called 'Zero Lag Trend Signals' designed for trading with specific entry and exit signals based on a zero lag exponential moving average (ZLEMA) and volatility bands. It includes customizable parameters for length, band multiplier, timeframes, and date range, and implements a risk management system with stop-loss and take-profit levels. The strategy visualizes trends and positions on a chart, allowing users to track their trades effectively.

Uploaded by

turubg5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

//@version=6

strategy("Zero Lag Trend Signals", overlay=true, calc_on_every_tick=false,


initial_capital=1000, default_qty_type=strategy.percent_of_equity,
default_qty_value=100, commission_type=strategy.commission.percent,
commission_value=0.1, slippage=3, pyramiding=0, margin_long=0, margin_short=0,
fill_orders_on_standard_ohlc=true)

// Input parameters
length = input.int(200, "Length", group="Main Calculations")
mult = input.float(1.2, "Band Multiplier", group="Main Calculations")
t1 = input.timeframe("5", "Time frame 1", group="Extra Timeframes")
t2 = input.timeframe("15", "Time frame 2", group="Extra Timeframes")
t3 = input.timeframe("60", "Time frame 3", group="Extra Timeframes")
t4 = input.timeframe("240", "Time frame 4", group="Extra Timeframes")
t5 = input.timeframe("1D", "Time frame 5", group="Extra Timeframes")
green = input.color(#00ffbb, "Bullish Color", group="Appearance")
red = input.color(#ff1100, "Bearish Color", group="Appearance")
startDate = input.time(timestamp("2018-01-01"), "Start Date", group="Date Range")
endDate = input.time(timestamp("2069-12-31"), "End Date", group="Date Range")

// Date filter
inDateRange = time >= startDate and time <= endDate

// Indicator calculations
src = close
lag = math.floor((length - 1) / 2)
zlema = ta.ema(src + (src - src[lag]), length)
volatility = ta.highest(ta.atr(length), length * 3) * mult

// Trend detection
var int trend = 0
if ta.crossover(close, zlema + volatility)
trend := 1
if ta.crossunder(close, zlema - volatility)
trend := -1

// Entry signals
bullEntry = (trend == 1) and (trend[1] != 1)
bearEntry = (trend == -1) and (trend[1] != -1)

// Position tracking
var bool longOpen = false
var bool shortOpen = false
var float entryPrice = na
var float slLevel = na
var float tpLevel = na

// Calculate SL/TP when entry occurs


if bullEntry and not longOpen
// Set SL at lower band
slLevel := zlema - volatility

// Calculate TP as 3x risk from entry


risk = close - slLevel
tpLevel := close + (risk * 1)

// Store entry price


entryPrice := close
if bearEntry and not shortOpen
// Set SL at upper band
slLevel := zlema + volatility

// Calculate TP as 3x risk from entry


risk = slLevel - close
tpLevel := close - (risk * 1)

// Store entry price


entryPrice := close

// Strategy execution
if inDateRange
// Long entry with fixed SL/TP
if bullEntry and not longOpen
strategy.entry("Long", strategy.long)
strategy.exit("Long Exit", "Long", stop=slLevel, limit=tpLevel)
longOpen := true
shortOpen := false

// Short entry with fixed SL/TP


if bearEntry and not shortOpen
strategy.entry("Short", strategy.short)
strategy.exit("Short Exit", "Short", stop=slLevel, limit=tpLevel)
shortOpen := true
longOpen := false

// Reset position status when closed


if strategy.closedtrades > strategy.closedtrades[1]
longOpen := false
shortOpen := false
slLevel := na
tpLevel := na
entryPrice := na

// Visualization
zlemaColor = trend == 1 ? color.new(green, 70) : color.new(red, 70)
m = plot(zlema, title="Zero Lag Basis", linewidth=2, color=zlemaColor, offset=0)
upper = plot(trend == -1 ? zlema + volatility : na, style=plot.style_linebr,
color=color.new(red, 90), title="Upper Deviation Band", offset=0)
lower = plot(trend == 1 ? zlema - volatility : na, style=plot.style_linebr,
color=color.new(green, 90), title="Lower Deviation Band", offset=0)

fill(m, upper, color=color.new(red, 90))


fill(m, lower, color=color.new(green, 90))

// Plot fixed SL/TP levels


plot(longOpen ? slLevel : na, "SL Long", color=color.red, style=plot.style_linebr,
linewidth=2)
plot(longOpen ? tpLevel : na, "TP Long", color=color.green,
style=plot.style_linebr, linewidth=2)
plot(shortOpen ? slLevel : na, "SL Short", color=color.red,
style=plot.style_linebr, linewidth=2)
plot(shortOpen ? tpLevel : na, "TP Short", color=color.green,
style=plot.style_linebr, linewidth=2)

// ... [MTF Table and other visualizations remain unchanged] ...

You might also like