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

Q Trend No Repaint

This document outlines a trading strategy called 'Q-Trend Strategy with ADX Master' using Pine Script for TradingView. It includes inputs for trend periods, ATR calculations, ADX thresholds, and conditions for entering long positions based on price movements and the current year. The strategy also features a trailing stop mechanism and an option to display a trend line on the chart.

Uploaded by

resclub
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)
157 views2 pages

Q Trend No Repaint

This document outlines a trading strategy called 'Q-Trend Strategy with ADX Master' using Pine Script for TradingView. It includes inputs for trend periods, ATR calculations, ADX thresholds, and conditions for entering long positions based on price movements and the current year. The strategy also features a trailing stop mechanism and an option to display a trend line on the chart.

Uploaded by

resclub
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

//@version=5

strategy("Q-Trend Strategy with ADX Master", overlay=true, initial_capital=1000,


default_qty_value=100, commission_value=0.06, process_orders_on_close=true)

// Inputs
src = input(close, "Source")
p = [Link](200, "Trend period", minval=1)
atr_p = [Link](14, "ATR Period", minval=1)
mult = [Link](1.0, "ATR Multiplier", step=0.1)
mode = [Link]("Type A", "Signal mode", options=["Type A", "Type B"])
use_ema_smoother = [Link]("No", "Smooth source with EMA?", options=["Yes",
"No"])
src_ema_period = [Link](3, "EMA Smoother period")
show_tl = input(false, "Show trend line?")

// Start and End Year Inputs


from_year = input(2024, title="From Year")
to_year = input(2088, title="To Year")

// ADX Inputs
adxPeriod = [Link](14, title="ADX Period")
adxThreshold = [Link](20, title="ADX Threshold")

// Trailing Stop Inputs


Multiplier = input(2, "ATR Multiplier")
atrlength = input(14, "ATR Length")
offset = input(0.5, "Trail offset")

// Calculations
src := use_ema_smoother == "Yes" ? [Link](src, src_ema_period) : src

// Calculate the highest, lowest, and middle points based on the previous bar
h = [Link](src, p)[1]
l = [Link](src, p)[1]
d = h - l

m = (h + l) / 2
m := bar_index > p ? m[1] : m

atr = [Link](atr_p)[1]
epsilon = mult * atr

// Use closed bar data for crossover conditions


change_up = (mode == "Type B" ? [Link](src, m + epsilon) : [Link](src, m +
epsilon)) or src > m + epsilon
change_down = (mode == "Type B" ? [Link](src, m - epsilon) : [Link](src, m
- epsilon)) or src < m - epsilon

m := (change_up or change_down) and m != m[1] ? m : change_up ? m + epsilon :


change_down ? m - epsilon : nz(m[1], m)

// ADX Calculation based on previous bars


up = [Link](high[1])
down = -[Link](low[1])
trur = [Link]([Link](true)[1], adxPeriod)
plus = [Link]([Link](na(up) ? 0 : up > down ? up : 0, 0)[1], adxPeriod)
minus = [Link]([Link](na(down) ? 0 : down > up ? down : 0, 0)[1], adxPeriod)
plusDI = 100 * plus / trur
minusDI = 100 * minus / trur
dx = 100 * [Link](plusDI - minusDI) / (plusDI + minusDI)
adx = [Link](dx[1], adxPeriod)

// Long Condition with Year Filter and ADX


current_year = year(time)
longCondition = change_up and (current_year >= from_year and current_year <=
to_year) and adx > adxThreshold
if (longCondition)
[Link]("Long", [Link])

// Define trailing stop for long positions


trailStopLong = [Link](atrlength) * Multiplier
[Link]("Exit Long", "Long", trail_points=trailStopLong,
trail_offset=trailStopLong * offset)

// Plotting the trend line


plot(show_tl ? m : na, "Trend Line", color=[Link]([Link], 0), linewidth=2)

You might also like