0% found this document useful (0 votes)
239 views10 pages

Codigo Script Tradinglatino 27-09-21

This document contains the source code for a trading strategy that analyzes multiple technical indicators including squeeze momentum, ADX, RSI, stochastic, and divergences. It allows the user to input parameters and display options for each indicator. The code generates signals and status updates based on the combined analysis of the indicators. It can display the results on a chart and also send alerts when certain conditions are met.

Uploaded by

Felipe Au
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)
239 views10 pages

Codigo Script Tradinglatino 27-09-21

This document contains the source code for a trading strategy that analyzes multiple technical indicators including squeeze momentum, ADX, RSI, stochastic, and divergences. It allows the user to input parameters and display options for each indicator. The code generates signals and status updates based on the combined analysis of the indicators. It can display the results on a chart and also send alerts when certain conditions are met.

Uploaded by

Felipe Au
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/ 10

// This source code is subject to the terms of the Mozilla Public License 2.

0 at
https://mozilla.org/MPL/2.0/
// © Lupown
//i got the adx scale idea from @oskarGallard
//@version=4
study(shorttitle="SQZ MOM + ADX + RSI + Stoch + STATUS + DIV ", title="Squeeze
momentum + ADX + RSI + Stochastic +status + Divergencias", overlay=false)
show_Momen = input(true, title="-----------Show squeeze momentum-------")
int lengthM = input(20, title="MOM Length", minval=1, step=1)
srcM = input(close, title="MOM Source", type=input.source)
int length = input(20, title="SQZ Length", minval=1, step=1)
src = input(close, title="SQZ Source", type=input.source)

//Momentum
sz = linreg(srcM - avg(avg(highest(high, lengthM), lowest(low, lengthM)),
sma(close, lengthM)), lengthM, 0)

//Momentum Conditions
sc1 = sz >= 0
sc2 = sz < 0
sc3 = sz >= sz[1]
sc4 = sz < sz[1]

clr = sc1 and sc3 ? #00FF00 : sc1 and sc4 ? #008000 :


sc2 and sc4 ? #FF0000 : sc2 and sc3 ? #800000 : color.gray

plot(show_Momen ? sz : na, title="Squeeze Momentum", color=clr,


style=plot.style_area)

//SQUEEZE

lengths = input(20, title="BB Length")


mult = input(2.0,title="BB MultFactor")
lengthKC=input(20, title="KC Length")
multKC = input(1.5, title="KC MultFactor")

useTrueRange = true

// Calculate BB
source = close
basis = sma(source, lengths)
dev = multKC * stdev(source, lengths)
upperBB = basis + dev
lowerBB = basis - dev

// Calculate KC
ma = sma(source, lengthKC)
range = useTrueRange ? tr : (high - low)
rangema = sma(range, lengthKC)
upperKC = ma + rangema * multKC
lowerKC = ma - rangema * multKC

sqzOn = (lowerBB > lowerKC) and (upperBB < upperKC)


sqzOff = (lowerBB < lowerKC) and (upperBB > upperKC)
noSqz = (sqzOn == false) and (sqzOff == false)

scolor = noSqz ? color.blue : sqzOn ? #000000 : color.gray


//plotshape(show_Momen? true : na, color=scolor, style=shape.xcross)
plot(show_Momen ? 0 : na, title="Squeeze Zero Line", color=scolor, linewidth=2,
style=plot.style_cross, transp=0)

///// ADX

show_ADX = input(true, title = "------------Show ADX------------")


show_di = input(false, title = " Show +DI -DI")
show_aa = input(false, "Mostrar punto 23 aparte", inline="adx line")
far = input(-7, "Separacion", inline="adx line")
scale = input(75.0, title = "Scala for ADX")
adxlen = input(14, title = "ADX Smoothing")
dilen = input(14, title = "DI Length")
keyLevel = input(23, title = "Key level for ADX")

dirmov(len) =>
up = change(high)
down = -change(low)
truerange = rma(tr, len)
plus = fixnan(100 * rma(up > down and up > 0 ? up : 0, len) / truerange)
minus = fixnan(100 * rma(down > up and down > 0 ? down : 0, len) / truerange)
[plus, minus]

adx(dilen, adxlen) =>


[plus, minus] = dirmov(dilen)
sum = plus + minus
adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
[adx, plus, minus]

[adxValue, diplus, diminus] = adx(dilen, adxlen)

///////////////////////////////////////////////////////////////

//[diplus, diminus, adxValue] = dmi(dilen, adxlen)

biggest(series) =>
max = 0.0
max := nz(max[1], series)
if series > max
max := series
max

// Calculate ADX Scale


ni = biggest(sz)
far1=far* ni/scale
adx_scale = (adxValue - keyLevel) * ni/scale

adx_scale2 = (adxValue - keyLevel+far) * ni/scale

dip= (diplus - keyLevel) * ni/scale


dim= (diminus - keyLevel) * ni/scale
plot (show_di ? dip :na, color=color.green, title="DI+")
plot (show_di ? dim :na, color=color.red, title="DI+")
plot(show_aa ? far1 : na,color=color.white, title="Punto 23")
color_ADX = adxValue > adxValue[1] ? #ffffff : #a09a9a
p1 = plot(show_aa ? adx_scale2 : show_ADX ? adx_scale : na, color = color_ADX,
title = "ADX", linewidth = 2)
bgcolor(adxValue > adxValue[1] and adxValue > 23 and show_Momen ? clr : na,
transp=95)

//RSI
show_rsi = input(true, title="------------Show RSI---------")
show_RSIfondo=input(true, title="Show RSI background")
len = input(14, minval=1, title="Length")
rsi = rsi(src, len)
rsiColor = rsi <= 30 ? color.green : rsi >= 70 ? color.red : #da00ff
rsi_scale=(rsi)* ni/scale

b1s=70 * ni/scale
bm= 50 * ni/scale
b0s=30 * ni/scale

plot(show_rsi? rsi_scale : na, "RSI", color=rsiColor)

band1 = plot(show_rsi? b1s : na,color=bar_index % 2 == 0 ? color.white :


#00000000,transp=60)
bandm = plot(show_rsi? bm : na,color=bar_index % 2 == 0 ? color.white :
#00000000,transp=70)
band0 = plot(show_rsi? b0s : na,color=bar_index % 2 == 0 ? color.white :
#00000000,transp=60)
fill(band1,band0, color= show_rsi and show_RSIfondo? color.purple :
na,transp=90,title="RSI background")

/////////
/////// estocastico

show_stoch=input(false,title="-------Show Stochastic------")
periodK = input(14, title="%K Length", minval=1)
smoothK = input(1, title="%K Smoothing", minval=1)
periodD = input(3, title="%D Smoothing", minval=1)
k = sma(stoch(close, high, low, periodK), smoothK)
d = sma(k, periodD)

k1=k* ni/scale
d1=d* ni/scale
plot(show_stoch?k1:na, title="%K", color=#2962FF)
plot(show_stoch?d1:na, title="%D", color=#FF6D00)

h1s=80 * ni/scale
h0s=20 * ni/scale
plot(show_stoch? h1s : na,color=bar_index % 2 == 0 ? color.white :
#00000000,transp=60)
plot(show_stoch? h0s : na,color=bar_index % 2 == 0 ? color.white :
#00000000,transp=60)

///////

// ESTADOOO
show_status = input(true, title = "------Show STATUS----------")
dist= input(10,title="Distancia del monitor")
dashColor = input(color.new(#696969, 90), "label Color", inline="Dash Line")
dashTextColor = input(color.new(#ffffff, 0), "Text Color", inline="Dash Line")

if(adxValue > adxValue[1] and adxValue > 23)


iadx='ADX con pendiente positiva por encima punto 23'
if(adxValue > adxValue[1] and adxValue < 23)
iadx='ADX con pendiente positiva por debajo punto 23'
if(adxValue < adxValue[1] and adxValue < 23)
iadx='ADX con pendiente negativa por debajo punto 23'
if(adxValue < adxValue[1] and adxValue > 23)
iadx='ADX con pendiente negativa por encima punto 23'

a1=adxValue >= 23
a2=adxValue < 23
a3=adxValue >= adxValue[1]
a4=adxValue < adxValue[1]

iAdx = a1 and a3 ? 'Pendiente positiva ↑ 23' : a1 and a4 ? 'Pendiente negativa ↑


23' :
a2 and a4 ? 'Pendiente negativa ↓ 23' : a2 and a3 ? 'Pendiente positiva ↓ 23' :
'-'

iMom = sc1 and sc3 ? 'Direccionalidad alcista' : sc1 and sc4 ? 'Direccionalidad
bajista' :
sc2 and sc4 ? 'Direccionalidad bajista' : sc2 and sc3 ? 'Direccinalidad alcista'
: '-'

igral = a1 and a3 and sc1 and sc3 ? 'Fuerte movimiento alcista' : a1 and a3 and sc1
and sc4 ? 'Monitor muestra rango-caida pero\nel movimiento tiene fuerza':
a1 and a3 and sc2 and sc4 ? 'Fuerte movimiento bajista' : a1 and a3 and sc2 and
sc3 ? 'Monitor muestra rango-subida pero\nel movimiento tiene fuerza':
a1 and a4 and sc1 and sc3 ? 'Movimiento alcista sin fuerza' : a1 and a4 and sc1
and sc4 ? 'Monitor muestra rango-caida\n pendiente negativa en ADX (venta)':
a1 and a4 and sc2 and sc4 ? 'Movimiento bajista sin fuerza' : a1 and a4 and sc2
and sc3 ? 'Monitor muestra rango-subida con \npendiente negativa en ADX (compra)':
a2 and a4 and sc1 and sc3 ? 'Movimiento alcista sin fuerza' : a2 and a4 and sc1
and sc4 ? 'Monitor muestra rango-caida sin fuerza ':
a2 and a4 and sc2 and sc4 ? 'Movimiento bajista sin fuerza' : a2 and a4 and sc2
and sc3 ? 'Monitor muestra rango-subida sin fuerza ':
a2 and a3 and sc1 and sc3 ? 'Movimiento alcista que \n quiere agarrar fuerza' : a2
and a3 and sc1 and sc4 ? 'Monitor muestra rango-caida,\n el movimiento quiere
agarrar fuerza':
a2 and a3 and sc2 and sc4 ? 'Movimiento bajista que \n quiere agarrar fuerza' : a2
and a3 and sc2 and sc3 ? 'Monitor muestra rango-subida,\n el movimiento quiere
agarrar fuerza': '-'

s='\n'
scr_label='Info ADX: '+iAdx+s+'Info monitor: '+iMom+s+'Info general:'+s+igral
// Plot Label on the chart
// Plot Label on the chart

if show_status

lab_l = label.new(
bar_index + dist, 0, '\t Estatus segun estrategia\n\t' + scr_label,
color = dashColor,
textcolor = dashTextColor,
style = label.style_label_left,
yloc = yloc.price)
label.delete(lab_l[1])

// Send alert only if screener is not empty


if (scr_label != '')
alert('Estatus segun estrategia\n' + scr_label, freq =
alert.freq_once_per_bar_close )

//////////////////////////////////

//DIVERGENCIAS BUENNNNNNNAS
show_div=input(true,title="------Divergencias--------")
lbR = input(title="Pivot Lookback Right", defval=5)
lbL = input(title="Pivot Lookback Left", defval=5)
rangeUpper = input(title="Max of Lookback Range", defval=60)
rangeLower = input(title="Min of Lookback Range", defval=5)
plotBull = input(title="Plot Bullish", defval=true)
plotHiddenBull = input(title="Plot Hidden Bullish", defval=true)
plotBear = input(title="Plot Bearish", defval=true)
plotHiddenBear = input(title="Plot Hidden Bearish", defval=true)
plotlab= input(title="Plot label", defval=false)

bearColor = #ff0000
bullColor = #1bff00
hiddenBullColor = #a4ff99
hiddenBearColor = #ff9e9e
textColor = color.white
noneColor = color.new(color.white, 100)

//FUNCTIONS
plFound(osc) => na(pivotlow(osc, lbL, lbR)) ? false : true
phFound(osc) => na(pivothigh(osc, lbL, lbR)) ? false : true

_inRange(cond) =>
bars = barssince(cond == true)
rangeLower <= bars and bars <= rangeUpper
_findDivRB(osc)=>
// Osc: Higher Low
oscHL = osc[lbR] > valuewhen(plFound(osc), osc[lbR], 1) and
_inRange(plFound(osc)[1])

// Price: Lower Low


priceLL = low[lbR] < valuewhen(plFound(osc), low[lbR], 1)

bullCond = plotBull and priceLL and oscHL and plFound(osc)

//-----------------------------------------------------------------------------
-
// Hidden Bullish

// Osc: Lower Low


oscLL = osc[lbR] < valuewhen(plFound(osc), osc[lbR], 1) and
_inRange(plFound(osc)[1])

// Price: Higher Low


priceHL = low[lbR] > valuewhen(plFound(osc), low[lbR], 1)

hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound(osc)

//-----------------------------------------------------------------------------
-
// Regular Bearish

// Osc: Lower High


oscLH = osc[lbR] < valuewhen(phFound(osc), osc[lbR], 1) and
_inRange(phFound(osc)[1])

// Price: Higher High


priceHH = high[lbR] > valuewhen(phFound(osc), high[lbR], 1)

bearCond = plotBear and priceHH and oscLH and phFound(osc)

//-----------------------------------------------------------------------------
-
// Hidden Bearish

// Osc: Higher High


oscHH = osc[lbR] > valuewhen(phFound(osc), osc[lbR], 1) and
_inRange(phFound(osc)[1])

// Price: Lower High


priceLH = high[lbR] < valuewhen(phFound(osc), high[lbR], 1)

hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound(osc)

[bullCond,hiddenBullCond,bearCond,hiddenBearCond]
[sz_bullCond,sz_hiddenBullCond,sz_bearCond,sz_hiddenBearCond]=_findDivRB(sz)
_findDivRB(rsi_scale)

plot(
plFound(sz) and show_Momen and show_div ? sz[lbR] : na,
offset=-lbR,
title="Regular Bullish",
linewidth=2,
color=(sz_bullCond ? bullColor : noneColor),
transp=0
)

plotshape(
sz_bullCond and plotlab and show_Momen and show_div ? sz[lbR] : na,
offset=-lbR,
title="Regular Bullish Label",
text="D",
style=shape.labelup,
location=location.absolute,
color=bullColor,
textcolor=color.black,
transp=0
)

plot(
plFound(sz) and show_Momen and show_div ? sz[lbR] : na,
offset=-lbR,
title="Hidden Bullish",
linewidth=1,
color=(sz_hiddenBullCond ? hiddenBullColor : noneColor),
transp=0
)

plotshape(
sz_hiddenBullCond and plotlab and show_Momen and show_div ? sz[lbR] : na,
offset=-lbR,
title="Hidden Bullish Label",
text="H",
style=shape.labelup,
location=location.absolute,
color=bullColor,
textcolor=color.black,
transp=0
)

plot(
phFound(sz) and show_Momen and show_div ? sz[lbR] : na,
offset=-lbR,
title="Regular Bearish",
linewidth=2,
color=(sz_bearCond ? bearColor : noneColor),
transp=0
)

plotshape(
sz_bearCond and plotlab and show_Momen and show_div ? sz[lbR] : na,
offset=-lbR,
title="Regular Bearish Label",
text="D",
style=shape.labeldown,
location=location.absolute,
color=bearColor,
textcolor=textColor,
transp=0
)

plot(
phFound(sz) and show_Momen and show_div ? sz[lbR] : na,
offset=-lbR,
title="Hidden Bearish",
linewidth=1,
color=(sz_hiddenBearCond ? hiddenBearColor : noneColor),
transp=0
)

plotshape(
sz_hiddenBearCond and plotlab and show_Momen and show_div ? sz[lbR] :
na,
offset=-lbR,
title="Hidden Bearish Label",
text="H",
style=shape.labeldown,
location=location.absolute,
color=bearColor,
textcolor=textColor,
transp=0
)

////////////////////RSI DIV//////////////////

[rsi_bullCond,rsi_hiddenBullCond,rsi_bearCond,rsi_hiddenBearCond]=_findDivRB(rsi_sc
ale)

plot(
plFound(rsi_scale) and show_rsi and show_div ? rsi_scale[lbR] : na,
offset=-lbR,
title="Regular Bullish",
linewidth=2,
color=(rsi_bullCond ? bullColor : noneColor),
transp=0
)

plotshape(
rsi_bullCond and plotlab and show_rsi and show_div ? rsi_scale[lbR] :
na,
offset=-lbR,
title="Regular Bullish Label",
text="D",
style=shape.labelup,
location=location.absolute,
color=bullColor,
textcolor=color.black,
transp=0
)

plot(
plFound(rsi_scale) and show_rsi and show_div ? rsi_scale[lbR] : na,
offset=-lbR,
title="Hidden Bullish",
linewidth=1,
color=(rsi_hiddenBullCond ? hiddenBullColor : noneColor),
transp=0
)

plotshape(
rsi_hiddenBullCond and plotlab and show_rsi and show_div ?
rsi_scale[lbR] : na,
offset=-lbR,
title="Hidden Bullish Label",
text="H",
style=shape.labelup,
location=location.absolute,
color=bullColor,
textcolor=color.black,
transp=0
)

plot(
phFound(rsi_scale) and show_rsi and show_div ? rsi_scale[lbR] : na,
offset=-lbR,
title="Regular Bearish",
linewidth=2,
color=(rsi_bearCond ? bearColor : noneColor),
transp=0
)

plotshape(
rsi_bearCond and plotlab and show_rsi and show_div ? rsi_scale[lbR] : na,
offset=-lbR,
title="Regular Bearish Label",
text="D",
style=shape.labeldown,
location=location.absolute,
color=bearColor,
textcolor=textColor,
transp=0
)

plot(
phFound(rsi_scale) and show_rsi and show_div ? rsi_scale[lbR] : na,
offset=-lbR,
title="Hidden Bearish",
linewidth=1,
color=(rsi_hiddenBearCond ? hiddenBearColor : noneColor),
transp=0
)

plotshape(
rsi_hiddenBearCond and plotlab and show_rsi and show_div ?
rsi_scale[lbR] : na,
offset=-lbR,
title="Hidden Bearish Label",
text="H",
style=shape.labeldown,
location=location.absolute,
color=bearColor,
textcolor=textColor,
transp=0
)

You might also like