0% found this document useful (0 votes)
361 views

Source - Price Action Explorer

The document defines a price action trading strategy using a moving average and price channel indicators. It calculates signals when the close crosses the upper or lower channel bands, and tracks peak profits by looking for highs/lows after entry. Labels are plotted to annotate peak profits and suggested sell/buy points. Colors are used to highlight bars within the channel.

Uploaded by

vesin.leo
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)
361 views

Source - Price Action Explorer

The document defines a price action trading strategy using a moving average and price channel indicators. It calculates signals when the close crosses the upper or lower channel bands, and tracks peak profits by looking for highs/lows after entry. Labels are plotted to annotate peak profits and suggested sell/buy points. Colors are used to highlight bars within the channel.

Uploaded by

vesin.leo
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/ 5

//@version=5

indicator("Price Action Explorer", overlay=true)

//leverage = input.float(defval=1.0, title='Leverage')


leverage = 1
ma_type = input.string(defval='EMA', title='Type', options=['SMA', 'EMA', 'WMA',
'VWMA', 'SMMA', 'DEMA', 'TEMA', 'LAGMA', 'SWMA', 'HullMA', 'ZEMA', 'TMA', 'SSMA'])
ma_len = input.int(defval=20, title='Length', minval=1)
gamma = input(defval=0.77, title='Lagma')
ma_src = input(close, title='Source')
pac_type = input.string(defval='HILO', title='Channel Type', options=['HILO',
'ATR', 'PIP', 'KC', 'STDEV'])
mult_factor_ = input.float(defval=1.0, title='Channel Length', minval=0, step=0.1)
mult_factor = pac_type == 'PIP' and mult_factor_ < 1 ? 1 : mult_factor_
sBars = input(true, title='Bar Color')
uGrabClr = input(false, title='Gradient Colors')

rngfilt(x, r) =>
rngfilt = x
rngfilt := x > nz(rngfilt[1]) ? x - r < nz(rngfilt[1]) ? nz(rngfilt[1]) : x - r
: x + r > nz(rngfilt[1]) ? nz(rngfilt[1]) : x + r

smoothrng(x, t, m) =>
wper = t * 2 - 1
avrng = ta.ema(math.abs(x - x[1]), t)
smoothrng = ta.ema(avrng, wper) * m

green100 = #008000FF
lime100 = #00FF00FF
red100 = #FF0000FF
blue100 = #0000FFFF
aqua100 = #00FFFFFF
darkred100 = #8B0000FF
gray100 = #808080FF
purple100 = #8a27b1

pip = syminfo.mintick * 10

variant_supersmoother(src, len) =>


a1 = math.exp(-1.414 * 3.14159 / len)
b1 = 2 * a1 * math.cos(1.414 * 3.14159 / len)
c2 = b1
c3 = -a1 * a1
c1 = 1 - c2 - c3
v9 = 0.0
v9 := c1 * (src + nz(src[1])) / 2 + c2 * nz(v9[1]) + c3 * nz(v9[2])
v9

variant_smoothed(src, len) =>


v5 = 0.0
sma_1 = ta.sma(src, len)
v5 := na(v5[1]) ? sma_1 : (v5[1] * (len - 1) + src) / len
v5

variant_zerolagema(src, len) =>


ema1 = ta.ema(src, len)
ema2 = ta.ema(ema1, len)
v10 = ema1 + ema1 - ema2
v10
variant_doubleema(src, len) =>
v2 = ta.ema(src, len)
v6 = 2 * v2 - ta.ema(v2, len)
v6

variant_tripleema(src, len) =>


v2 = ta.ema(src, len)
v7 = 3 * (v2 - ta.ema(v2, len)) + ta.ema(ta.ema(v2, len), len)
v7

variant_lag(p, g) =>
L0 = 0.0
L1 = 0.0
L2 = 0.0
L3 = 0.0
L0 := (1 - g) * p + g * nz(L0[1])
L1 := -g * L0 + nz(L0[1]) + g * nz(L1[1])
L2 := -g * L1 + nz(L1[1]) + g * nz(L2[1])
L3 := -g * L2 + nz(L2[1]) + g * nz(L3[1])
f = (L0 + 2 * L1 + 2 * L2 + L3) / 6
f

variant(type, src, len, g) =>


ema_1 = ta.ema(src, len)
wma_1 = ta.wma(src, len)
vwma_1 = ta.vwma(src, len)
variant_smoothed__1 = variant_smoothed(src, len)
variant_doubleema__1 = variant_doubleema(src, len)
variant_tripleema__1 = variant_tripleema(src, len)
variant_lag__1 = variant_lag(src, g)
wma_2 = ta.wma(src, len / 2)
wma_3 = ta.wma(src, len)
wma_4 = ta.wma(2 * wma_2 - wma_3, math.round(math.sqrt(len)))
variant_supersmoother__1 = variant_supersmoother(src, len)
swma_1 = ta.swma(src)
variant_zerolagema__1 = variant_zerolagema(src, len)
sma_1 = ta.sma(src, len)
sma_2 = ta.sma(sma_1, len)
sma_3 = ta.sma(src, len)
type == 'EMA' ? ema_1 : type == 'WMA' ? wma_1 : type == 'VWMA' ? vwma_1 : type
== 'SMMA' ? variant_smoothed__1 : type == 'DEMA' ? variant_doubleema__1 : type ==
'TEMA' ? variant_tripleema__1 : type == 'LAGMA' ? variant_lag__1 : type == 'HullMA'
? wma_4 : type == 'SSMA' ? variant_supersmoother__1 : type == 'SWMA' ? swma_1 :
type == 'ZEMA' ? variant_zerolagema__1 : type == 'TMA' ? sma_2 : sma_3

atrUpper(C, M, L) =>
ATR = ta.atr(L)
x = C + M * ATR
x

atrLower(C, M, L) =>
ATR = ta.atr(L)
x = C - M * ATR
x

pipUpper(C, M, L) =>
x = C + M * pip
x
pipLower(C, M, L) =>
x = C - M * pip
x

stdUpper(S, C, M, L) =>
y = ta.stdev(S, L)
x = C + M * y
x

stdLower(S, C, M, L) =>
y = ta.stdev(S, L)
x = C - M * y
x

hiloUpper(T, C, M, L, g) =>
y = variant(T, high, L, g)
y

hiloLower(T, C, M, L, g) =>
y = variant(T, low, L, g)
y

kcUpper(T, C, M, L, g) =>
y = variant(T, ta.tr, L, g)
x = C + y * M
x

kcLower(T, C, M, L, g) =>
y = variant(T, ta.tr, L, g)
x = C - y * M
x

channel(type, T, S, C, M, L, g) =>
atrUpper__1 = atrUpper(C, M, L)
stdUpper__1 = stdUpper(S, C, M, L)
pipUpper__1 = pipUpper(C, M, L)
kcUpper__1 = kcUpper(T, C, M, L, g)
hiloUpper__1 = hiloUpper(T, C, M, L, g)
Upr = type == 'ATR' ? atrUpper__1 : type == 'STDEV' ? stdUpper__1 : type ==
'PIP' ? pipUpper__1 : type == 'KC' ? kcUpper__1 : hiloUpper__1
atrLower__1 = atrLower(C, M, L)
stdLower__1 = stdLower(S, C, M, L)
pipLower__1 = pipLower(C, M, L)
kcLower__1 = kcLower(T, C, M, L, g)
hiloLower__1 = hiloLower(T, C, M, L, g)
Lwr = type == 'ATR' ? atrLower__1 : type == 'STDEV' ? stdLower__1 : type ==
'PIP' ? pipLower__1 : type == 'KC' ? kcLower__1 : hiloLower__1
[Upr, Lwr]

peakProfit(trend, high, low, signal) =>


isBuySignal = ta.crossover(trend, high) and ta.barssince(ta.crossunder(trend,
low)) > 1 and not signal
isSellSignal = ta.crossunder(trend, low) and ta.barssince(ta.crossover(trend,
high)) > 1 and signal
buyPrice = isBuySignal ? high : na
sellPrice = isSellSignal ? low : na
var float entryPrice = na
var float peakProfit = na
if not na(entryPrice)
if high > entryPrice and high > peakProfit
peakProfit := high
if low < entryPrice and low < peakProfit
peakProfit := low
if not na(buyPrice)
entryPrice := buyPrice
peakProfit := buyPrice
if not na(sellPrice)
entryPrice := sellPrice
peakProfit := sellPrice
percentProfit = (peakProfit - entryPrice) / entryPrice * 100 * leverage
[percentProfit, isBuySignal or isSellSignal]

pacC = variant(ma_type, ma_src, ma_len, gamma)


[pacU, pacL] = channel(pac_type, ma_type, ma_src, pacC, mult_factor, ma_len, gamma)

plot(pacC, color=color.new(color.red, 20), linewidth=2, title='Center')


L = plot(pacL, color=color.new(color.blue, 20), linewidth=1, title='Lower')
U = plot(pacU, color=color.new(color.blue, 20), linewidth=1, title='Upper')
fill(L, U, color=color.new(color.blue, 95))

grabcol = uGrabClr ? close >= open ? close > pacL and close > pacU ? lime100 :
close < pacL and close < pacU ? red100 : aqua100 : close > pacL and close > pacU ?
green100 : close < pacL and close < pacU ? darkred100 : blue100 : na
stdcol = uGrabClr ? na : close > pacL and close > pacU ? lime100 : close < pacL and
close < pacU ? red100 : purple100
barcolor(sBars ? uGrabClr ? grabcol : stdcol : na, title='Colors')

var bool previousBuySignal = false


var bool previousSellSignal = false
var bool signal = false
var float entryPrice = na
var float peakProfit = na
var float trendHigh = na
var float trendLow = na
var int trendDirection = na
var int lastPeakBarIndex = na
var int lastPeakDirection = na

buySignal = ta.crossover(close, pacU) and ta.barssince(ta.crossunder(close, pacL))


> 1 and not previousBuySignal
sellSignal = ta.crossunder(close, pacL) and ta.barssince(ta.crossover(close, pacU))
> 1 and not previousSellSignal

if buySignal
signal := true
entryPrice := high
peakProfit := high
trendDirection := 1
trendHigh := high
trendLow := low
if sellSignal
signal := false
entryPrice := low
peakProfit := low
trendDirection := -1
trendHigh := high
trendLow := low
if not na(entryPrice)
if trendDirection == 1 and high > trendHigh
trendHigh := high
if bar_index > lastPeakBarIndex
peakProfit := high
lastPeakBarIndex := bar_index
lastPeakDirection := trendDirection
if trendDirection == -1 and low < trendLow
trendLow := low
if bar_index > lastPeakBarIndex
peakProfit := low
lastPeakBarIndex := bar_index
lastPeakDirection := trendDirection

percentProfit = (peakProfit - entryPrice) / entryPrice * 100

if not na(trendDirection) and barstate.isconfirmed and (trendDirection == 1 and


high == trendHigh or trendDirection == -1 and low == trendLow) and bar_index ==
lastPeakBarIndex
labelText = 'Peak Profit ' + str.tostring(percentProfit, format='.2f') + '%'
if trendDirection == 1
label.new(bar_index, trendHigh, text=labelText, color=color.black,
style=label.style_label_up, size=size.normal, textcolor=color.white,
yloc=yloc.belowbar)
else if trendDirection == -1
label.new(bar_index, trendLow, text=labelText, color=color.black,
style=label.style_label_down, size=size.normal, textcolor=color.white,
yloc=yloc.abovebar)

if not na(lastPeakDirection) and (lastPeakDirection == 1 and close < peakProfit or


lastPeakDirection == -1 and close > peakProfit)
if lastPeakDirection == 1
labelText = 'PP Sell ' + str.tostring(peakProfit, format='#.#####') + ' ('
+ str.tostring(percentProfit, format='.2f') + '%)'
label.new(bar_index, peakProfit, text=labelText, color=color.white,
style=label.style_label_down, size=size.normal, textcolor=color.red,
yloc=yloc.abovebar)
else if lastPeakDirection == -1
labelText = 'PP Buy ' + str.tostring(peakProfit, format='#.#####') + ' (' +
str.tostring(percentProfit, format='.2f') + '%)'
label.new(bar_index, peakProfit, text=labelText, color=color.white,
style=label.style_label_up, size=size.normal, textcolor=color.green,
yloc=yloc.belowbar)

if buySignal
previousBuySignal := true
previousSellSignal := false

if sellSignal
previousBuySignal := false
previousSellSignal := true

plotshape(buySignal, color=color.green, style=shape.labelup,


location=location.belowbar, text='B', title='Buy Signal', size=size.normal,
textcolor=color.white)
plotshape(sellSignal, color=color.red, style=shape.labeldown,
location=location.abovebar, text='S', title='Sell Signal', size=size.normal,
textcolor=color.white)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy